/* ============================================================= *
 *  base.css — design tokens, page shell, sidebar + tree,
 *  login gate, mode toggle. Loaded FIRST (link order = cascade
 *  order; keep base → card → notes → admin).
 * ============================================================= */

:root {
  /* dark mode — warm Claude-style greys, light text */
  --bg: #1f1e1d;            /* main viewer background */
  --sidebar-bg: #1a1917;    /* sidebar, a touch darker */
  --panel: #2a2927;         /* cards + buttons, a touch lighter than bg */
  --panel-alt: #242321;     /* card back side */
  --ink: #ececea;           /* primary text (near white) */
  --muted: #a3a299;
  --faint: #75736d;
  --leaf-ink: #cbcac3;      /* deck (leaf) labels */
  --line: rgba(255,255,255,.08);
  --line-strong: rgba(255,255,255,.16);
  --hover: rgba(255,255,255,.06);
  --active: rgba(255,255,255,.10);
  --active-ink: #ffffff;
  --shit: #e5484d;
  --shit-hover: #d23b40;
  --shit-on: #7f1d1d;
  --approve: #2dbd6e;          /* green CTA — matches app accentGreenBright */
  --approve-hover: #27a862;
  --approved: #245a40;         /* muted confirmed green */
  --approved-hover: #2c6b4c;
  --undo: #c77d33;             /* amber — deliberate un-approve warning */
  --undo-hover: #b46e29;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 30px rgba(0,0,0,.45);

  /* ---- app design tokens (A-26) ----
     One source of truth mirroring lib/theme/app_colors.dart + app_spacing.dart,
     so new admin surfaces (the card editor) read radii/spacing from the SAME
     values the Flutter app compiles. Hex/px equal the Dart tokens exactly. The
     review tool itself stays dark (its palette above is unchanged); the editor
     reuses the dark vars for colour and these for radius/spacing. */
  --accent-green: #22B35F;          /* app_colors.accentGreen */
  --page-bg: #FAF9F6;               /* app_colors.pageBg */
  --progress-learning: #F0A522;     /* app_colors.progressLearning */
  --progress-mastered: var(--accent-green);
  --progress-not-studied: #ECECEC;  /* app_colors.progressNotStudied */
  --radius-card: 16px;              /* AppRadius.card */
  --radius-card-lg: 20px;           /* AppRadius.cardLarge */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;  --sp-4: 16px;   /* app_spacing base-4 */
  --sp-5: 20px; --sp-6: 24px; --sp-7: 28px; --sp-8: 32px;

  font-synthesis: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-columns: 400px 1fr;
  /* Fix the single row to the viewport so #viewer has a definite height and can
     scroll its own overflow instead of growing the page. */
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
}

/* ---------- sidebar ---------- */
#sidebar {
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--sidebar-bg);
}

.side-head {
  padding: 18px 20px 13px;
  display: flex;
  align-items: baseline;
  gap: 9px;
  border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; letter-spacing: .14em; font-size: 15px; }
.sub { color: var(--faint); font-size: 14px; }

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 9px 7px 14px;
  font-size: 16px;
}

.row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.row:hover { background: var(--hover); }
.row .caret {
  width: 16px;
  color: var(--faint);
  flex: 0 0 auto;
  transition: transform .12s ease;
  font-size: 12px;
  text-align: center;
}
.row.collapsed .caret { transform: rotate(-90deg); }
.row .ic {
  flex: 0 0 auto;
  opacity: .9;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px;
}
.row .ic .ico { width: 18px; height: 18px; display: block; }
/* deck stack is taller than wide → hold height, let width follow its aspect */
.row .ic .ico-deck { width: auto; height: 18px; }
/* subject folder: open glyph when expanded (default), closed when collapsed */
.row .ic-folder .fld-closed,
.row.collapsed .ic-folder .fld-open { display: none; }
.row .ic-folder .fld-open,
.row.collapsed .ic-folder .fld-closed { display: inline-flex; }
.row .label {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}
.row .count {
  color: var(--faint);
  font-size: 14px;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.row.folder .label { color: var(--ink); font-weight: 550; }
.row.area .label { color: var(--ink); font-weight: 500; opacity: .9; }
.row.area .ic { opacity: .8; }
.row.leaf .label { color: var(--leaf-ink); }
.row.leaf .ic { color: var(--leaf-ink); }
.row.leaf.active { background: var(--active); }
.row.leaf.active .label { color: var(--active-ink); font-weight: 600; }
.row.leaf.active .count { color: var(--ink); }

/* Tree icon colours encode TYPE, not state: subjects = folder yellow, areas =
   file orange, decks = card-stack violet. Chapter super-folders use the folder
   glyph, so they take the subject colour. Full opacity so the exact hues read on
   the dark tree. Glyphs are stroke=currentColor, so `color` drives the stroke. */
.row.folder .ic { color: #72cffb; opacity: 1; }
.row.area .ic { color: #e9e9e9; opacity: 1; }
.row.area.chapter .ic { color: #72cffb; }
.row.leaf .ic { color: #FFE64D; opacity: 1; }

/* Approved roll-up moved OFF the icon and ONTO the counts/pill: a fully-approved
   deck or area (or chapter) greens its card count; a fully-approved subject swaps
   its x/n pill for an APPROVED label (see pill() in js/features/tree.js). Green =
   var(--approve), the same green as the approve buttons. */
.row.area.approved .count,
.row.leaf.approved .count { color: var(--approve); font-weight: 600; }

/* κεφάλαιο super-folder rows (title-convention grouping, see CHAPTER_SEP in
   js/core/catalog.js): reads as a folder-of-folders, one shade stronger than areas */
.row.chapter .label { font-weight: 550; opacity: 1; }
.row.chapter .ic { opacity: .9; }

/* subject progress pill: approved decks / total decks; greens when complete */
.row .pill {
  flex: 0 0 auto;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--hover);
  border-radius: 999px;
  padding: 1px 8px;
}
/* Fully-approved subject: an APPROVED label replaces the x/n pill (no grey pill
   background, just the green label). Same green as the approve buttons. */
.row .pill.pill-approved {
  color: var(--approve);
  background: transparent;
  font-weight: 700;
  letter-spacing: .07em;
  padding: 1px 4px;
}

.children { margin-left: 13px; border-left: 1px solid var(--line); }
.children.hidden { display: none; }

/* ---- drag-to-reorder (SortableJS — js/admin/reorder.js) ----
   .drag-chosen = the held row popping out of its slot; .drag-active = the
   clone following the pointer (fallbackOnBody → it sits on <body>, so it
   needs its own solid sidebar background); .drag-ghost = the gap left
   behind, which the siblings animate around. */
.drag-chosen {
  background: var(--sidebar-bg);
  border-radius: 8px;
  cursor: grabbing;
}
.drag-active {
  background: var(--sidebar-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: .95 !important;   /* Sortable inlines its own fallback opacity */
  transform: scale(1.02);
}
.drag-ghost { opacity: .35; }

.bad-summary {
  border-top: 1px solid var(--line);
  padding: 13px 20px;
  font-size: 14px;
  color: var(--muted);
}
.bad-summary b { color: var(--shit); }

/* ---------- login gate ---------- */
.login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  width: 320px;
  max-width: calc(100vw - 40px);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 30px 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-logo { font-weight: 700; letter-spacing: .14em; font-size: 17px; }
.login-sub { color: var(--faint); font-size: 13px; margin-top: -10px; }
.login-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-field select,
.login-field input {
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--panel-alt);
  color: var(--ink);
  font-size: 15px;
  font-family: inherit;
}
.login-field select:focus,
.login-field input:focus { outline: 2px solid #6f8cff; outline-offset: 1px; }
.login-go {
  height: 44px;
  margin-top: 4px;
  border: none;
  border-radius: 10px;
  background: #6f8cff;
  color: #fff;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  transition: filter .12s ease;
}
.login-go:hover { filter: brightness(1.08); }
.login-err { color: var(--shit); font-size: 13px; min-height: 16px; text-align: center; }
.login-card.shake { animation: shake .32s ease; }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ---------- sidebar head: mode toggle + footer ---------- */
.side-head { flex-direction: column; align-items: stretch; gap: 12px; }
.side-head-top { display: flex; align-items: baseline; gap: 9px; }
.modes {
  display: flex;
  gap: 4px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}
.mode {
  flex: 1;
  height: 32px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.mode:hover { color: var(--ink); }
.mode.active { background: var(--active); color: var(--active-ink); }

.side-foot {
  border-top: 1px solid var(--line);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.whoami { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signout {
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.signout:hover { color: var(--ink); background: var(--hover); }

/* notes-mode scope rows in the tree */
.row.scope.active { background: var(--active); }
.row.scope.active .label { color: var(--active-ink); font-weight: 600; }
.row.note-all .label { color: var(--ink); font-weight: 600; }
