/* ------------------------------------------------------------------ *
 * Problem-database browser, notes, and save/description dialogs.
 * Additive stylesheet: style.css is untouched; these rules style only
 * the new components (#dbModal, #notesModal, ...) using the same theme vars.
 * ------------------------------------------------------------------ */

/* --------------------------------------------------- modal shell --- */
.db-modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(2px);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 20px;
}
.db-dialog {
  width: min(980px, 100%);
  height: min(720px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}
.db-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.db-title { font-weight: 700; font-size: 14px; }
.db-count { color: var(--muted-2); font-size: 12px; }
.db-close { margin-left: auto; }

/* ------------------------------------------------------ filters ---- */
.db-filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel-2);
}
.db-search {
  flex: 1 1 220px;
  min-width: 180px;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
}
.db-search:focus { outline: none; border-color: var(--accent-line); }
.db-select {
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  max-width: 200px;
}
.db-solved-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
}

/* --------------------------------------------------------- list ---- */
.db-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.db-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.db-row:hover { background: var(--panel-3); border-color: var(--border-soft); }
.db-row + .db-row { margin-top: 2px; }
.db-row-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.db-row-tags {
  color: var(--muted-2);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}
.db-pill {
  flex: none;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  border-radius: 20px;
  padding: 2px 8px;
  border: 1px solid var(--cell-border);
  color: var(--muted);
  background: var(--cell);
}
.db-pill.easy { color: var(--ok); border-color: rgba(63, 185, 80, 0.4); }
.db-pill.medium { color: var(--c-decorator); border-color: rgba(240, 184, 73, 0.4); }
.db-pill.hard { color: var(--danger); border-color: rgba(248, 81, 73, 0.4); }
.db-pill.ds { text-transform: none; letter-spacing: 0; }
.db-sols { flex: none; color: var(--muted-2); font-size: 11px; width: 64px; text-align: right; }
.db-empty { color: var(--muted-2); text-align: center; padding: 40px 0; font-size: 13px; }

/* ------------------------------------------------------- footer ---- */
.db-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-soft);
  background: var(--panel-2);
}
.db-page { color: var(--muted); font-size: 12px; min-width: 110px; text-align: center; }
.db-status { color: var(--muted-2); font-size: 12px; }
.db-foot .spacer { flex: 1; }

/* ------------------------------------------------- 3-pane layout ---- */
/* Additive layout rules: the description pane joins the flex workspace;
   the editor pane (style.css .left-pane) becomes the center column. */
.desc-pane { flex: 0 0 24%; min-width: 0; min-height: 0; display: flex; }
.workspace .left-pane { flex: 0 0 36%; }
.desc-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }

/* Collapsed state: the pane shrinks to a vertical "Description" tab rail
   (LeetCode style). Drag the divider fully left, or use the collapse button;
   click the rail to expand again. */
.desc-pane.collapsed { flex: 0 0 40px !important; }
.desc-pane.collapsed .desc-panel { display: none; }
.desc-rail { display: none; }
.desc-pane.collapsed .desc-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
}
.desc-rail:hover { border-color: var(--accent-line); color: var(--text); }
.desc-rail .desc-ic { flex: none; }
.desc-rail-label {
  writing-mode: vertical-rl;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.desc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
}
.desc-ic { width: 14px; height: 14px; fill: var(--accent); }
.desc-head .spacer { flex: 1; }
.desc-scroll { flex: 1; overflow-y: auto; padding: 12px; min-height: 0; }
.desc-title { margin: 0 0 8px; font-size: 16.5px; line-height: 1.35; }
.desc-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.desc-tag {
  font-size: 10.5px;
  color: var(--muted);
  background: var(--cell);
  border: 1px solid var(--cell-border);
  border-radius: 20px;
  padding: 2px 8px;
}
@media (max-width: 1100px) {
  .desc-pane { display: none; }
}

/* --------------------------------------- formatted problem statement */
.problem-statement { font-size: 13px; line-height: 1.6; color: var(--text); }
.problem-statement p { margin: 0 0 10px; }
.problem-statement h4 {
  margin: 14px 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
}
.problem-statement pre {
  margin: 6px 0 10px;
  padding: 8px 10px;
  background: var(--panel-3);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  font-size: 12px;
  line-height: 1.55;
  overflow-x: auto;
  white-space: pre-wrap;
}
.problem-statement code {
  background: var(--cell);
  border: 1px solid var(--cell-border);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 12px;
}
.problem-statement ul { margin: 4px 0 10px; padding-left: 20px; }
.problem-statement li { margin: 3px 0; color: var(--muted); }
.problem-statement .io-label { color: var(--c-decorator); font-weight: 700; }

/* ------------------------------------------------- notes (overlay) -- */
.notes-dialog { width: min(900px, 100%); height: min(620px, 100%); }
.notes-dialog .desc-ic { fill: var(--ok); }
.notes-hint { font-size: 11px; color: var(--muted-2); }
.notes-status { margin-left: auto; font-size: 11px; color: var(--muted-2); padding-right: 4px; }
.notes-modal-area {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.65;
  padding: 14px 16px;
  min-height: 0;
}

/* Multi-note layout: a list of notes on the left, the editor on the right. */
.notes-layout { flex: 1; display: flex; min-height: 0; }
.notes-sidebar { flex: 0 0 210px; display: flex; flex-direction: column; border-right: 1px solid var(--border-soft); background: var(--panel-2); min-height: 0; }
.notes-new { margin: 10px; padding: 8px 10px; border: 1px dashed var(--border); border-radius: 8px; background: transparent; color: var(--muted); font: 600 12.5px inherit; cursor: pointer; }
.notes-new:hover { color: var(--text); border-color: var(--accent-line); background: var(--panel-3); }
.notes-list { flex: 1; overflow-y: auto; padding: 0 6px 8px; }
.notes-item { position: relative; padding: 8px 26px 8px 10px; border-radius: 8px; cursor: pointer; margin-bottom: 2px; }
.notes-item:hover { background: var(--panel-3); }
.notes-item.active { background: var(--accent-soft); }
.notes-item-title { font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notes-item-meta { font-size: 10.5px; color: var(--muted-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notes-item-del { position: absolute; top: 6px; right: 6px; width: 18px; height: 18px; border: none; background: transparent; color: var(--muted-2); cursor: pointer; opacity: 0; font-size: 14px; line-height: 1; border-radius: 4px; }
.notes-item:hover .notes-item-del, .notes-item.active .notes-item-del { opacity: 1; }
.notes-item-del:hover { color: #e5534b; background: var(--panel); }
.notes-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.notes-main-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border-soft); }
.notes-title-input { flex: 1; padding: 6px 8px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--text); font: 700 14px inherit; }
.notes-title-input:hover { border-color: var(--border-soft); }
.notes-title-input:focus { outline: none; border-color: var(--accent-line); background: var(--bg); }
.notes-empty { padding: 30px 20px; color: var(--muted-2); font-size: 13px; text-align: center; }

/* ----------------------------------- solution picker (editor header) */
.sol-picker {
  margin-left: 10px;
  max-width: 300px;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-3);
  color: var(--accent);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.sol-picker:hover { border-color: var(--accent-line); }
.sol-picker:focus { outline: none; border-color: var(--accent-line); }

/* --------------------------------------------------- cheatsheet ----- */
.cheat-dialog { width: min(1180px, 100%); height: min(780px, 100%); }
.cheat-ic { fill: var(--c-decorator); }
.cheat-search { flex: 0 1 260px; min-width: 140px; margin-left: auto; }
.cheat-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--panel-2);
  flex-wrap: wrap;
}
.cheat-tab {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.cheat-tab:hover { color: var(--text); border-color: var(--accent-line); }
.cheat-tab.active {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.cheat-body { flex: 1; overflow-y: auto; padding: 12px 14px; min-height: 0; }
.cheat-grid { columns: 2 380px; column-gap: 12px; }
.cheat-card {
  break-inside: avoid;
  margin: 0 0 12px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  background: var(--panel-2);
  padding: 10px 12px;
}
.cheat-card-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--c-decorator);
  margin-bottom: 7px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.cheat-card-sec {
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--muted-2);
}
.cheat-card p { margin: 7px 0 0; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.cheat-card b { color: var(--text); }
.cheat-card code {
  background: var(--cell);
  border: 1px solid var(--cell-border);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 11px;
}
.cheat-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.cheat-table th {
  text-align: left;
  color: var(--muted-2);
  font-weight: 600;
  padding: 3px 8px 3px 0;
  border-bottom: 1px solid var(--border-soft);
}
.cheat-table td {
  padding: 3.5px 8px 3.5px 0;
  border-bottom: 1px solid var(--border-soft);
  color: var(--muted);
  vertical-align: top;
}
.cheat-table tr:last-child td { border-bottom: none; }
.cheat-table td:first-child { color: var(--text); white-space: nowrap; }
.cheat-code {
  margin: 0;
  padding: 8px 10px;
  background: var(--panel-3);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  font-size: 11px;
  line-height: 1.55;
  overflow-x: auto;
  color: var(--text);
}
.cheat-list { margin: 0; padding-left: 18px; }
.cheat-list li { font-size: 11.5px; color: var(--muted); margin: 4px 0; line-height: 1.5; }

/* ------------------------------------------------ CodeJar editor ---- */
/* The editor is now a contenteditable <pre> (CodeJar) that renders its own
   syntax colors in place, replacing the transparent-textarea + overlay
   trick. Same .code-textarea class keeps every metric (font, line-height,
   padding) identical so gutter/band math is unchanged. */
pre.code-jar {
  color: var(--text);              /* textarea version was transparent */
  z-index: 2;
  cursor: text;
}
pre.code-jar:empty::before {
  content: "# write Python here\u2026";
  color: var(--muted-2);
}
pre.code-jar ::selection { background: rgba(76, 141, 255, 0.30); }
pre.code-jar::selection { background: rgba(76, 141, 255, 0.30); }

/* Prism token classes mapped onto the app's existing syntax palette
   (editor only; the legacy .tok-* classes remain for other surfaces). */
pre.code-jar .token.comment { color: var(--c-comment); font-style: italic; }
pre.code-jar .token.string,
pre.code-jar .token.triple-quoted-string,
pre.code-jar .token.char { color: var(--c-string); }
pre.code-jar .token.keyword { color: var(--c-keyword); }
pre.code-jar .token.builtin,
pre.code-jar .token.class-name { color: var(--c-builtin); }
pre.code-jar .token.function { color: var(--c-func); }
pre.code-jar .token.number,
pre.code-jar .token.boolean { color: var(--c-number); }
pre.code-jar .token.decorator,
pre.code-jar .token.annotation { color: var(--c-decorator); }
pre.code-jar .token.operator,
pre.code-jar .token.punctuation { color: var(--text); }
pre.code-jar .token.string-interpolation .token.interpolation { color: var(--text); }
pre.code-jar .token.string-interpolation .token.interpolation .token.string { color: var(--c-string); }

/* -------------------------------- collapsible editor / viz panes ---- */
/* Same rail pattern as the Description pane: a pane collapses to a slim
   vertical tab; click the tab to expand. !important beats the inline flex
   width left behind by splitter drags (and restores it on expand). */
.pane-rail { display: none; }
.rail-ic { width: 14px; height: 14px; fill: var(--accent); flex: none; }
.rail-label {
  writing-mode: vertical-rl;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.left-pane.pane-collapsed,
.right-pane.pane-collapsed { flex: 0 0 40px !important; min-width: 40px; }
.right-pane.pane-collapsed { display: flex; overflow: hidden; }
.left-pane.pane-collapsed > *:not(.pane-rail),
.right-pane.pane-collapsed > *:not(.pane-rail) { display: none !important; }
.left-pane.pane-collapsed > .pane-rail,
.right-pane.pane-collapsed > .pane-rail {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  color: var(--muted);
}
.left-pane.pane-collapsed > .pane-rail:hover,
.right-pane.pane-collapsed > .pane-rail:hover { border-color: var(--accent-line); color: var(--text); }
/* Hide the editor/viz divider when either side is a rail, and let the
   remaining expanded pane absorb the space. */
.workspace.center-collapsed #colSplitter,
.workspace.right-collapsed #colSplitter { display: none; }
.workspace.right-collapsed:not(.center-collapsed) .left-pane { flex: 1 1 auto !important; }
/* Code AND Visualization both collapsed: the description takes the room
   (its inline flex-basis from splitter drags must not win) — and its
   own splitter disappears since there is nothing left to trade with. */
.workspace.center-collapsed.right-collapsed .desc-pane:not(.collapsed) {
  flex: 1 1 auto !important;
}
.workspace.center-collapsed.right-collapsed #descSplitter { display: none; }

/* --------------------------------- notes: Write | Preview + markdown -- */
.notes-tabs { display: flex; gap: 2px; margin-left: 10px; background: var(--panel-3); border-radius: 8px; padding: 2px; }
.notes-tab {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 12px; font-weight: 600; font-family: inherit;
  padding: 4px 12px; border-radius: 6px;
}
.notes-tab.active { background: var(--panel); color: var(--text); }
.notes-tab:hover:not(.active) { color: var(--text); }
.notes-preview { flex: 1; overflow-y: auto; padding: 16px 20px; background: var(--panel-2); }

/* Scoped markdown rendering (notes preview, my-problem descriptions). */
.md-body { font-size: 13.5px; line-height: 1.55; color: var(--text); }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 { margin: 14px 0 6px; line-height: 1.25; }
.md-body h1 { font-size: 19px; } .md-body h2 { font-size: 16px; }
.md-body h3 { font-size: 14px; } .md-body h4 { font-size: 13px; color: var(--muted); }
.md-body p { margin: 6px 0; }
.md-body ul, .md-body ol { margin: 6px 0; padding-left: 22px; }
.md-body li { margin: 2px 0; }
.md-body code {
  background: var(--panel-3); border: 1px solid var(--border-soft); border-radius: 4px;
  padding: 1px 5px; font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px;
}
.md-body pre.md-pre {
  background: var(--panel-3); border: 1px solid var(--border-soft); border-radius: 8px;
  padding: 10px 12px; overflow-x: auto; margin: 8px 0;
}
.md-body pre.md-pre code { background: none; border: none; padding: 0; font-size: 12.5px; }
.md-body blockquote {
  margin: 8px 0; padding: 4px 12px; border-left: 3px solid var(--accent);
  color: var(--muted); background: var(--panel-3); border-radius: 0 6px 6px 0;
}
.md-body hr { border: none; border-top: 1px solid var(--border-soft); margin: 12px 0; }
.md-body a { color: var(--accent); }
.md-body del { color: var(--muted); }

/* ------------------------------------------- my problems (tabs + list) -- */
.db-tabs {
  display: flex; gap: 2px; padding: 8px 14px 0;
  border-bottom: 1px solid var(--border-soft);
}
.db-tab {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: inherit;
  padding: 8px 14px; border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.db-tab.active { color: var(--text); border-bottom-color: var(--accent); }
.db-tab:hover:not(.active) { color: var(--text); }

.my-row { position: relative; text-align: left; cursor: pointer; }
.my-row .my-act {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 6px;
  opacity: 0.55;
}
.my-row .my-act:hover { opacity: 1; background: var(--panel-3); }
.my-row .my-del:hover svg { fill: #e5534b; }
.db-pill.mine { background: rgba(45, 212, 191, 0.15); color: #2dd4bf; }

/* Save dialog */
.savemy-dialog { width: min(560px, 100%); height: auto; max-height: min(640px, 100%); }
.savemy-body { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px 16px; overflow-y: auto; }
.savemy-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-top: 6px; }
.savemy-desc {
  min-height: 180px; resize: vertical;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border-soft); border-radius: 8px;
  padding: 10px 12px; font-family: inherit; font-size: 13px; line-height: 1.5;
  outline: none;
}
.savemy-desc:focus { border-color: var(--accent); }
.savemy-err { color: #e5534b; font-size: 12.5px; padding: 4px 2px; }
.savemy-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.savemy-actions .notes-hint { margin-right: auto; }
.savemy-primary {
  border: none; border-radius: 8px; background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 600; font-family: inherit;
  padding: 8px 18px; cursor: pointer;
}
.savemy-primary:hover { filter: brightness(1.1); }
.savemy-primary:disabled { opacity: 0.6; cursor: default; }
/* The title is a single line: don't let .db-search's flex-grow (meant for the
   horizontal filter bar) stretch it into a tall box in this column layout. */
.savemy-body .db-search { flex: 0 0 auto; }

/* Markdown toolbar shared by the note editor and the problem description. */
.md-toolbar { display: flex; flex-wrap: wrap; gap: 3px; padding: 6px 8px; background: var(--panel-3); border-bottom: 1px solid var(--border-soft); }
.md-btn { min-width: 28px; height: 26px; padding: 0 8px; border: 1px solid var(--border-soft); border-radius: 6px; background: var(--panel); color: var(--muted); font: 600 12px "SF Mono", Menlo, Consolas, monospace; cursor: pointer; }
.md-btn:hover { color: var(--text); border-color: var(--accent-line); }
/* In the save/description dialog the toolbar sits directly on top of the box. */
.savemy-body .md-toolbar { border: 1px solid var(--border-soft); border-bottom: none; border-radius: 8px 8px 0 0; margin-top: 6px; }
.savemy-body .md-toolbar + .savemy-desc { border-top: none; border-top-left-radius: 0; border-top-right-radius: 0; }
