/* ============================================================
   RANZCR Pathology — study checklist
   ============================================================ */

:root {
  color-scheme: light;
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f2f1ed;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --line:         #e1e0d9;
  --line-strong:  #c3c2b7;
  --accent:       #2a78d6;
  --accent-ink:   #ffffff;
  --accent-soft:  rgba(42,120,214,0.10);

  /* Category tiers. C1 blue and C2 magenta are validated palette slots; C3 is
     deliberately neutral — it is the least-important tier, and every remaining
     hue collided with either the green "covered" tick or the amber "revisit"
     marker, which are reserved status colours. */
  --cat-1: #2a78d6;
  --cat-2: #e87ba4;
  --cat-ink: #0b0b0b;

  /* progress states carry an icon + label, never colour alone */
  --done:     #0ca30c;
  --shaky:    #fab219;
  --critical: #d03b3b;

  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(11,11,11,0.05), 0 8px 24px rgba(11,11,11,0.06);
  --ring: rgba(11,11,11,0.10);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:       #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #232322;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --line:        #2c2c2a;
    --line-strong: #383835;
    --accent:      #3987e5;
    --accent-soft: rgba(57,135,229,0.16);
    --cat-1: #3987e5;
    --cat-2: #e87ba4;
    --cat-ink: #0b0b0b;
    --ring: rgba(255,255,255,0.10);
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 28px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:       #0d0d0d;
  --surface:     #1a1a19;
  --surface-2:   #232322;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --muted:       #898781;
  --line:        #2c2c2a;
  --line-strong: #383835;
  --accent:      #3987e5;
  --accent-soft: rgba(57,135,229,0.16);
  --cat-1: #3987e5;
  --cat-2: #e87ba4;
  --cat-ink: #0b0b0b;
  --ring: rgba(255,255,255,0.10);
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 28px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
/* Any rule that sets `display` outranks the UA rule for [hidden]; this app has
   several. Make the attribute authoritative once, rather than per component. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--plane);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ───────────────────────────────────────────── topbar */
.topbar {
  position: sticky; top: 0; z-index: 45;
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0 1.25rem; height: 56px;
  background: color-mix(in srgb, var(--plane) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.6rem; flex-shrink: 0; }
.logo {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(140deg, var(--done), var(--accent));
  box-shadow: inset 0 0 0 1px var(--ring);
}
.brand-name { font-size: 0.95rem; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.brand-name b { color: var(--ink); font-weight: 650; }

.tabs { display: flex; gap: 0.15rem; margin-left: auto; margin-right: auto; }
.tab {
  border: 0; background: transparent; color: var(--ink-2);
  padding: 0.4rem 0.85rem; border-radius: 999px; cursor: pointer;
  font-size: 0.9rem; font-weight: 500; transition: background .12s, color .12s;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.active { background: var(--ink); color: var(--plane); }

.topbar-right { display: flex; gap: 0.3rem; flex-shrink: 0; }
.icon-btn {
  border: 0; background: transparent; color: var(--ink-2);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
  display: grid; place-items: center;
  transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ───────────────────────────────────────────── layout */
.view { display: none; }
.view.active { display: block; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 1.5rem 1.25rem 5rem; }
.wrap.tight { padding: 0.85rem 1.25rem; }

/* ───────────────────────────────────────────── sticky progress + filters */
.stickybar {
  position: sticky; top: 56px; z-index: 40;
  background: color-mix(in srgb, var(--plane) 94%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.overall { margin-bottom: 0.75rem; }
.overall-text {
  display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap;
  margin-bottom: 0.45rem;
}
.overall-text strong { font-size: 1.05rem; font-weight: 650; letter-spacing: -0.01em; }
.overall-text span { font-size: 0.85rem; color: var(--muted); }
.overall-track, .gbar, .covtrack {
  display: flex; gap: 2px; background: var(--surface-2);
  border-radius: 5px; overflow: hidden;
}
.overall-track { height: 8px; }
.sg { display: block; height: 100%; }
.sg.done  { background: var(--done); }
.sg.shaky { background: var(--shaky); }

.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.search { position: relative; flex: 1; min-width: 200px; }
.search input {
  width: 100%; padding: 0.45rem 2.4rem 0.45rem 2.1rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); color: var(--ink);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.search-icon { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search kbd {
  position: absolute; right: 0.55rem; top: 50%; transform: translateY(-50%);
  font-size: 0.7rem; color: var(--muted); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 0.3rem; background: var(--surface-2);
}

.seg { display: flex; background: var(--surface-2); border-radius: var(--radius); padding: 2px; }
.seg-btn {
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer;
  padding: 0.32rem 0.65rem; border-radius: 8px; font-size: 0.84rem;
  font-weight: 500; white-space: nowrap;
}
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg-n { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

.select {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.4rem 0.55rem; color: var(--ink);
  max-width: 250px;
}
.chips { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 0.28rem 0.65rem; font-size: 0.82rem; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--ink); color: var(--plane); border-color: var(--ink); }
.result-n { font-size: 0.82rem; color: var(--muted); margin-left: auto; font-variant-numeric: tabular-nums; }

/* ───────────────────────────────────────────── legend */
.legend {
  display: flex; flex-wrap: wrap; gap: 0.9rem; align-items: center;
  font-size: 0.8rem; color: var(--muted); margin: 0 0 1rem;
}
.lg { display: inline-flex; align-items: center; gap: 0.35rem; }

/* ───────────────────────────────────────────── marker */
.mk {
  width: 22px; height: 22px; flex-shrink: 0; padding: 0;
  border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 0.78rem; font-weight: 700; line-height: 1;
  border: 1.5px solid var(--line-strong); background: transparent; color: transparent;
  transition: border-color .12s, background .12s, color .12s;
}
button.mk { cursor: pointer; }
button.mk:hover { border-color: var(--ink-2); }
.mk.done  { background: var(--done);  border-color: var(--done);  color: #fff; }
.mk.shaky { background: var(--shaky); border-color: var(--shaky); color: #241a00; }
.mk:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.legend .mk { width: 16px; height: 16px; font-size: 0.6rem; border-width: 1.25px; }

/* ───────────────────────────────────────────── groups + rows */
.list { display: flex; flex-direction: column; gap: 1.5rem; }
.group { scroll-margin-top: 190px; }

.ghead {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 0.5rem; flex-wrap: wrap;
}
.ghead h2 { font-size: 0.95rem; font-weight: 620; }
.ghead-right { display: flex; align-items: center; gap: 0.7rem; }
.gcount { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.gbar { width: 110px; height: 6px; }
.gpct { font-size: 0.8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 4ch; text-align: right; }
.ghead-btn {
  border: 1px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.75rem; cursor: pointer;
  transition: background .12s, color .12s;
}
.ghead-btn:hover { background: var(--surface-2); color: var(--ink); }

.rows { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.row {
  display: grid; grid-template-columns: auto 1fr auto auto;
  gap: 0.8rem; align-items: center;
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--line);
  transition: background .1s;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row.s1 .row-name { color: var(--ink-2); }
.row-main { min-width: 0; display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.row-name { font-size: 0.9rem; }
.row-sub { font-size: 0.75rem; color: var(--muted); }
.row-tags { display: flex; gap: 0.28rem; }

.tag {
  font-size: 0.67rem; font-weight: 700; letter-spacing: 0.04em;
  padding: 0.12rem 0.4rem; border-radius: 5px;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
/* Category tiers get their own hue. Filled rather than tinted so the hue stays
   at its validated value and the C1/C2/C3 text keeps >4.5:1 against it — the
   label is always present, so colour is a second channel, never the only one. */
.tag.c1, .tag.c2 { color: var(--cat-ink); border-color: transparent; }
.tag.c1 { background: var(--cat-1); }
.tag.c2 { background: var(--cat-2); }
/* c3 keeps the neutral chip: least emphasis for the least common tier */

.rowlinks { display: flex; gap: 0.3rem; align-items: center; }
.link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.4rem; padding: 0.2rem 0.45rem; border-radius: 6px;
  text-decoration: none; font-size: 0.76rem; font-weight: 550;
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: background .12s, color .12s, border-color .12s;
}
.link:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }
.link.book { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.link.book:hover { background: var(--accent-soft); }
.link.off { opacity: .4; cursor: default; }
.link.off:hover { background: transparent; color: var(--muted); border-color: var(--line); }

mark { background: color-mix(in srgb, var(--shaky) 40%, transparent); color: inherit; border-radius: 3px; }
.empty { text-align: center; padding: 3.5rem 1rem; color: var(--muted); }

/* ───────────────────────────────────────────── progress view */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem; margin-bottom: 1.25rem;
}
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.tile .k { font-size: 0.75rem; color: var(--muted); font-weight: 550; }
.tile .v { font-size: 1.75rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.25; }
.tile .s { font-size: 0.78rem; color: var(--ink-2); }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 1.25rem 1.4rem 1.4rem; margin-bottom: 1.25rem;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap;
}
.panel-head h2 { font-size: 1rem; }
.panel-note { font-size: 0.8rem; color: var(--muted); }
.head-controls { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

.syscov { display: flex; flex-direction: column; gap: 0.55rem; }
.covrow {
  display: grid; grid-template-columns: minmax(120px, 230px) 1fr auto;
  gap: 0.9rem; align-items: center; font-size: 0.85rem;
}
.covrow .lbl { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.covtrack { height: 10px; }
.covrow .num { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.8rem; min-width: 7ch; text-align: right; }

/* ───────────────────────────────────────────── modal + toast */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(0,0,0,.5); padding: 1rem; }
.modal-card {
  background: var(--plane); border: 1px solid var(--line); border-radius: var(--radius-lg);
  width: min(520px, 100%); max-height: 88vh; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 1.05rem; }
.modal-body { padding: 1.25rem; overflow-y: auto; }
.btn {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 0.45rem 0.9rem; border-radius: var(--radius); cursor: pointer;
  font-weight: 550; font-size: 0.88rem;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.danger-ghost { background: transparent; border-color: var(--line); color: var(--critical); }
.btn.danger-ghost:hover { background: color-mix(in srgb, var(--critical) 10%, transparent); }
.field-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.fine { font-size: 0.78rem; color: var(--muted); margin: 0; }
.shortcuts { margin-top: 1.4rem; border-top: 1px solid var(--line); padding-top: 1.1rem; }
.shortcuts h3 { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 0.5rem; }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--plane); padding: 0.55rem 1.05rem;
  border-radius: 999px; font-size: 0.86rem; z-index: 70; box-shadow: var(--shadow);
  pointer-events: none;      /* never let a toast swallow a click on the list */
}

/* ───────────────────────────────────────────── responsive */
@media (max-width: 820px) {
  .brand-name { display: none; }
  .tabs { margin-left: 0; }
  .row { grid-template-columns: auto 1fr auto; row-gap: 0.35rem; }
  .row-tags { display: none; }
  .gbar { width: 70px; }
  .covrow { grid-template-columns: 120px 1fr auto; }
  .stickybar { position: static; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ───────────────────────────────────────────── account & sync */
.account-btn {
  display: flex; align-items: center; gap: 0.45rem;
  border: 1px solid var(--line); background: transparent; color: var(--ink-2);
  border-radius: 999px; padding: 0.3rem 0.75rem 0.3rem 0.6rem;
  font-size: 0.84rem; cursor: pointer; max-width: 190px;
  transition: background .12s, color .12s, border-color .12s;
}
.account-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }
.account-btn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sync-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--line-strong);
}
.sync-dot.ok     { background: var(--done); }
.sync-dot.saving { background: var(--shaky); }
.sync-dot.error  { background: var(--critical); }

.stack { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.stack > span { font-size: 0.8rem; color: var(--ink-2); font-weight: 550; }
.stack input {
  padding: 0.5rem 0.7rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.stack input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.wide { width: 100%; margin-top: 0.3rem; }

.auth-error {
  margin: 0 0 0.7rem; font-size: 0.83rem; color: var(--critical);
  background: color-mix(in srgb, var(--critical) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--critical) 30%, transparent);
  border-radius: 8px; padding: 0.5rem 0.7rem;
}
.auth-switch { margin-top: 0.9rem; }
.linkish {
  border: 0; background: none; color: var(--accent); cursor: pointer;
  padding: 0; font-size: inherit; text-decoration: underline;
}
.signed-as { margin: 0 0 0.4rem; font-size: 0.95rem; }

/* page number shown without the book linked (deployed site) — click to pick
   a local PDF and jump straight to the page */
.link.page { color: var(--muted); border-style: dashed; cursor: pointer; }
.link.page:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }

/* AI prompt button + local-textbook settings */
.link.ai { color: var(--cat-2); border-color: color-mix(in srgb, var(--cat-2) 35%, var(--line)); }
.link.ai:hover { background: color-mix(in srgb, var(--cat-2) 12%, transparent); color: var(--cat-2); }
.snippet {
  margin: 0 0 0.9rem; padding: 0.6rem 0.75rem; overflow-x: auto;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.76rem;
  color: var(--ink-2); line-height: 1.5;
}
