/* pydataviz: the page. Four panes a student can resize or fold (the code, the
   charts, the data, the console), a dark theme for a screen and a light one
   for a projector. Sizes live in CSS variables that js/layout.js sets;
   folding is a class on body. The tokens are pysims', so the two pages look
   like one suite. */

:root {
  --bg: #0b0e11;
  --panel: #12171c;
  --panel-2: #0e1216;
  --edge: #27313b;
  --text: #d8dee6;
  --dim: #8a97a6;
  --ok: #7fd38a;
  --bad: #f08a7a;
  --busy: #e8c56a;
  --accent: #5aa9ff;
  --button: #1d2630;
  --button-edge: #36424f;
  --primary: #214a78;
  --primary-edge: #2f6cb0;
  --surface: #0f1317;
  --select: #243242;
  --row-edge: #1b2229;
  --kw: #c792ea; --num: #f78c6c; --str: #c3e88d; --cmt: #5f6b78; --builtin: #82aaff; --op: #89ddff;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f3f1ea;
  --panel: #faf8f2;
  --panel-2: #efece3;
  --edge: #d6d1c4;
  --text: #22262b;
  --dim: #6b7380;
  --ok: #2e7d32;
  --bad: #b3261e;
  --busy: #8a6d00;
  --accent: #2f6cb0;
  --button: #ffffff;
  --button-edge: #c9c4b6;
  --primary: #2f6cb0;
  --primary-edge: #245a94;
  --surface: #ffffff;
  --select: #dce7f5;
  --row-edge: #e6e3da;
  --kw: #7c3aed; --num: #b45309; --str: #15803d; --cmt: #8a8f98; --builtin: #1d4ed8; --op: #0e7490;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
/* hidden wins over any display a class sets */
[hidden] { display: none !important; }

body {
  --code-w: 460px;
  --side-w: 420px;
  --console-h: 160px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 6px var(--console-h);
  grid-template-columns: var(--code-w) 6px minmax(280px, 1fr) 6px var(--side-w);
  grid-template-areas:
    "bar bar bar bar bar"
    "code split1 charts split2 side"
    "split3 split3 split3 split3 split3"
    "console console console console console";
  height: 100vh;
  overflow: hidden;
}

body.no-code { grid-template-columns: 0 0 minmax(280px, 1fr) 6px var(--side-w); }
body.no-side { grid-template-columns: var(--code-w) 6px minmax(280px, 1fr) 0 0; }
body.no-code.no-side { grid-template-columns: 0 0 minmax(280px, 1fr) 0 0; }
body.no-code .code, body.no-code #split-code { display: none; }
body.no-side .side, body.no-side #split-side { display: none; }
body.console-closed { grid-template-rows: auto minmax(0, 1fr) 0 28px; }
body.console-closed #split-console { display: none; }
body.console-closed #console { display: none; }
body.dragging { cursor: col-resize; user-select: none; }
body.dragging * { cursor: inherit !important; }

/* ----- the bar ----- */

.bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--edge);
  background: var(--panel);
  min-height: 42px;
}
.group { display: flex; align-items: center; gap: 8px; }
.group.right { margin-left: auto; }
.bar h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: 0.02em; }
.filename { color: var(--dim); font-size: 13px; }

button {
  font: inherit;
  padding: 5px 13px;
  background: var(--button);
  color: var(--text);
  border: 1px solid var(--button-edge);
  border-radius: 4px;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary-edge); color: #fff; }
button.small { padding: 2px 8px; font-size: 12px; }
button.icon { padding: 5px 9px; line-height: 0; }
button.icon svg { width: 15px; height: 15px; display: block; fill: currentColor; }
button.icon.primary svg { fill: #fff; }

.status { color: var(--dim); font-size: 13px; max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.status.busy { color: var(--busy); }

/* the View and Help menus: native details elements styled as dropdowns */
.menu { position: relative; font-size: 13px; }
.menu summary { list-style: none; cursor: pointer; padding: 5px 10px; border: 1px solid var(--button-edge); border-radius: 4px; background: var(--button); }
.menu summary::-webkit-details-marker { display: none; }
.menu[open] summary { border-color: var(--accent); }
.menu-body { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 280px; background: var(--panel); border: 1px solid var(--edge); border-radius: 6px; padding: 8px 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.35); }
.menu-body label { display: block; padding: 4px 2px; cursor: pointer; }
.menu-body .keys { color: var(--dim); font-size: 12px; line-height: 1.6; }
.menu-note { color: var(--dim); font-size: 12px; line-height: 1.5; padding: 6px 2px 2px; border-top: 1px solid var(--edge); margin-top: 6px; }
#helpmenu .menu-body { min-width: 380px; }
#helpmenu .menu-note { border-top: none; margin-top: 0; padding-top: 2px; }
.menu-link { display: block; padding: 6px 2px 8px; color: var(--accent); text-decoration: none; }
.menu-link:hover { text-decoration: underline; }
.font-row { color: var(--dim); font-size: 12px; padding: 6px 2px 2px; display: flex; align-items: center; gap: 6px; }
.font-row span { min-width: 2em; text-align: center; font-variant-numeric: tabular-nums; }
kbd { font: 11px system-ui, sans-serif; background: var(--button); border: 1px solid var(--button-edge); border-bottom-width: 2px; border-radius: 3px; padding: 0 5px; }

/* ----- the panes ----- */

.splitter { background: transparent; }
.splitter.v { grid-area: split1; cursor: col-resize; }
#split-side { grid-area: split2; }
.splitter.h { grid-area: split3; cursor: row-resize; }
.splitter:hover { background: var(--accent); opacity: 0.5; }

.code { grid-area: code; min-height: 0; min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--edge); }
.code .CodeMirror { flex: 1; height: auto; font: 14px/1.45 ui-monospace, Consolas, "Cascadia Mono", monospace; background: var(--panel); color: var(--text); }
.code .CodeMirror-gutters { background: var(--panel-2); border-right: 1px solid var(--edge); }
.code .CodeMirror-linenumber { color: var(--dim); opacity: 0.7; }
.code .CodeMirror-activeline-background { background: rgba(90, 169, 255, 0.07); }
.code .CodeMirror-cursor { border-left: 2px solid var(--accent); }
.code .CodeMirror-selected { background: var(--select); }
.code .cm-keyword { color: var(--kw); }
.code .cm-number { color: var(--num); }
.code .cm-string, .code .cm-string-2 { color: var(--str); }
.code .cm-comment { color: var(--cmt); font-style: italic; }
.code .cm-builtin, .code .cm-variable-2 { color: var(--builtin); }
.code .cm-operator { color: var(--op); }
.code .cm-def { color: var(--accent); }
.code .cm-trailingspace { background: rgba(240, 138, 122, 0.25); }
.code .cm-matchhighlight { background: rgba(90, 169, 255, 0.18); }
.code .search-match { background: rgba(232, 197, 106, 0.3); }
.code .search-match-current { background: rgba(232, 197, 106, 0.7); color: #111; }
/* the traceback's line, marked until the next run */
.code .line-error { background: rgba(240, 138, 122, 0.18); }
.code .CodeMirror-dialog { background: var(--panel); color: var(--text); border-bottom: 1px solid var(--edge); font-size: 13px; }
.code .CodeMirror-dialog input { background: var(--panel-2); color: var(--text); border: 1px solid var(--button-edge); }

/* find and replace: a panel at the top of the editor that stays */
.find-panel { background: var(--panel); border-bottom: 1px solid var(--edge); padding: 4px 6px; font-size: 12px; }
.find-row, .replace-row { display: flex; align-items: center; gap: 4px; }
.replace-row { margin-top: 4px; }
.find-panel input[type=text] { flex: 1; min-width: 80px; font: 13px ui-monospace, Consolas, monospace; background: var(--panel-2); color: var(--text); border: 1px solid var(--button-edge); border-radius: 3px; padding: 3px 6px; }
.find-panel input.bad { border-color: var(--bad); }
.find-panel button { padding: 2px 6px; font-size: 12px; }
.find-panel .opt { font-family: ui-monospace, Consolas, monospace; min-width: 28px; }
.find-panel .opt.active { border-color: var(--accent); color: var(--accent); }
.find-panel .find-count { color: var(--dim); min-width: 5em; text-align: center; font-variant-numeric: tabular-nums; }

.charts { grid-area: charts; min-height: 0; min-width: 0; overflow: auto; background: var(--surface); padding: 12px; }

.side { grid-area: side; min-height: 0; min-width: 0; display: flex; flex-direction: column; border-left: 1px solid var(--edge); background: var(--panel); }

/* the four doors, along the top */
.doors { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--edge); flex-wrap: wrap; }
.filecount { margin-left: auto; color: var(--dim); font-size: 12px; }

/* the folder */
.filelist { max-height: 45%; overflow: auto; }
.filelist:empty { display: none; }
.file { display: flex; align-items: center; border-bottom: 1px solid var(--row-edge); }
.file.selected { background: var(--select); }
.file-open { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; text-align: left; background: none; border: none; border-radius: 0; padding: 6px 4px 6px 10px; color: var(--text); }
.file-open:hover { border: none; color: var(--accent); }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 13px ui-monospace, Consolas, monospace; }
.file-meta { color: var(--dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.file-tools { display: flex; gap: 2px; padding-right: 6px; opacity: 0; }
.file:hover .file-tools, .file.selected .file-tools { opacity: 1; }
button.ghost { background: none; border-color: transparent; color: var(--dim); }
button.ghost:hover:not(:disabled) { color: var(--accent); border-color: var(--button-edge); }

.viewer { flex: 1; min-height: 0; overflow: auto; }

/* a file dragged anywhere over the page */
body.dropping::after { content: "Drop to add the file to your folder"; position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(90, 169, 255, 0.12); border: 3px dashed var(--accent); color: var(--text); font-size: 18px; pointer-events: none; }

/* ----- the door dialogs ----- */

dialog.sheet { width: min(560px, 92vw); background: var(--panel); color: var(--text); border: 1px solid var(--edge); border-radius: 8px; padding: 16px 18px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
dialog.sheet.wide { width: min(760px, 94vw); }
dialog.sheet::backdrop { background: rgba(0,0,0,0.5); }
dialog.sheet h2 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
dialog.sheet .note { margin: 0 0 10px; }
dialog.sheet textarea { width: 100%; resize: vertical; font: 12.5px/1.45 ui-monospace, Consolas, monospace; background: var(--panel-2); color: var(--text); border: 1px solid var(--button-edge); border-radius: 4px; padding: 8px; }
dialog.sheet input[type=text] { flex: 1; min-width: 0; font: 13px ui-monospace, Consolas, monospace; background: var(--panel-2); color: var(--text); border: 1px solid var(--button-edge); border-radius: 4px; padding: 5px 8px; }
.sheet-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.sheet-row label { color: var(--dim); font-size: 13px; min-width: 5em; }
.sheet-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.note.sniff { margin: 8px 0 0; min-height: 1.4em; color: var(--dim); }
.note.sniff.bad { color: var(--bad); }

.dataset-list { max-height: 50vh; overflow: auto; border: 1px solid var(--edge); border-radius: 6px; }
.dataset { display: block; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--row-edge); border-radius: 0; padding: 9px 12px; color: var(--text); }
.dataset:last-child { border-bottom: none; }
.dataset:hover { background: var(--select); border: none; border-bottom: 1px solid var(--row-edge); }
.dataset .dataset-title { font-weight: 600; font-size: 13px; }
.dataset .dataset-file { color: var(--dim); font: 11px ui-monospace, Consolas, monospace; margin-left: 8px; }
.dataset .dataset-about { display: block; color: var(--dim); font-size: 12px; line-height: 1.45; margin-top: 2px; }

.note { color: var(--dim); font-size: 13px; line-height: 1.5; margin: 0; }
.note.empty { padding: 14px 16px; }
.note code { font-family: ui-monospace, Consolas, monospace; color: var(--text); }

/* ----- the console ----- */

.consolewrap { grid-area: console; min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--edge); background: var(--panel-2); }
.console-head { display: flex; align-items: center; gap: 10px; padding: 3px 10px; min-height: 28px; }
.console-head .console-last { flex: 1; color: var(--dim); font: 12px/1.3 ui-monospace, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.console-head .console-last.err { color: var(--bad); }
.console-head .console-count { color: var(--bad); font-size: 12px; }
.console { flex: 1; min-height: 0; overflow: auto; padding: 4px 10px 10px; font: 12.5px/1.45 ui-monospace, Consolas, "Cascadia Mono", monospace; white-space: pre-wrap; }
.console .line { min-height: 1.45em; }
.console .err { color: var(--bad); }
.console .say { color: var(--busy); }
.console .note { color: var(--dim); font-size: inherit; }

/* ----- narrow ----- */

@media (max-width: 768px) {
  body {
    grid-template-rows: auto minmax(0, 1fr) 6px var(--console-h);
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "bar" "charts" "split3" "console";
  }
  .code, .side, #split-code, #split-side { display: none; }
}
