/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #dfe3e9;
  --border-strong: #c3cad4;
  --text: #16202c;
  --muted: #5d6b7c;
  --faint: #8b97a6;
  --accent: #0b6e99;
  --accent-soft: #e2f1f8;
  --ok: #107a4d;
  --ok-soft: #e0f4ea;
  --warn: #9a5b00;
  --warn-soft: #fdf0dc;
  --danger: #a3302a;
  --danger-soft: #fbe6e4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,32,44,.06), 0 4px 14px rgba(16,32,44,.05);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --surface: #171d24; --surface-2: #1f262f;
    --border: #2b343e; --border-strong: #3c4854;
    --text: #e6ebf1; --muted: #9aa7b5; --faint: #71808f;
    --accent: #4bb3dd; --accent-soft: #15323f;
    --ok: #4ec38c; --ok-soft: #12301f;
    --warn: #e0a24a; --warn-soft: #332514;
    --danger: #e87a73; --danger-soft: #341a19;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--sans);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3 { line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }
small, .small { font-size: .8125rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem;
}
.topbar .brand { font-weight: 650; letter-spacing: -.02em; color: var(--text); display: flex; gap: .45rem; align-items: center; }
.topbar .brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: .25rem; margin-left: auto; align-items: center; flex-wrap: wrap; }
.topbar nav a {
  padding: .35rem .6rem; border-radius: 7px; color: var(--muted); font-size: .875rem; font-weight: 500;
}
.topbar nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1240px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.narrow { max-width: 620px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }

/* ── Controls ───────────────────────────────────────────────────────────── */
label { display: block; font-size: .8125rem; font-weight: 550; color: var(--muted); margin-bottom: .2rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=number], input[type=date], select, textarea {
  width: 100%; padding: .45rem .6rem; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { min-height: 4.5rem; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer;
  padding: .45rem .8rem; border-radius: 8px; font-size: .875rem; font-weight: 550;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { padding: .2rem .45rem; font-size: .78rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .1rem .45rem; border-radius: 999px; font-size: .72rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.flash { padding: .6rem .8rem; border-radius: 8px; margin-bottom: 1rem; font-size: .875rem; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--danger-soft); color: var(--danger); }
.flash.info { background: var(--accent-soft); color: var(--accent); }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .875rem; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); font-weight: 600; }
td input, td select { padding: .3rem .4rem; font-size: .84rem; }
tbody tr:last-child td { border-bottom: none; }

/* ── Planner board ──────────────────────────────────────────────────────── */
.board { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 940px) {
  /* Calendar first on a phone; the module library is a reference below it. */
  .board { grid-template-columns: 1fr; }
  .board > section { order: 1; }
  .board > .palette { order: 2; }
}

/* The notice spans both board columns and pushes nothing around. */
.board-notice { grid-column: 1 / -1; margin: 0 0 .25rem; }

.week-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .85rem; }
.week-head .phase { font-weight: 600; }

.days { display: grid; grid-template-columns: repeat(7, minmax(0,1fr)); gap: .5rem; }
@media (max-width: 940px) { .days { grid-template-columns: 1fr; } }

.day {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  min-height: 150px; display: flex; flex-direction: column;
}
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day > header {
  padding: .35rem .45rem; border-bottom: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .25rem .4rem;
}
.day .dname { font-size: .75rem; font-weight: 650; text-transform: uppercase; letter-spacing: .03em; }
.day .dnum { grid-column: 1; font-size: .7rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.day .dmins { grid-column: 2; grid-row: 2; font-size: .7rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.day .dadd { grid-column: 2; grid-row: 1; padding: 0 .3rem; line-height: 1.3; font-size: .95rem; }
.dropzone { flex: 1; padding: .4rem; display: flex; flex-direction: column; gap: .35rem; min-height: 60px; }
.dropzone.drag-over { background: var(--accent-soft); }

.chip {
  display: block; border-radius: 8px; padding: .35rem .45rem; overflow: hidden;
  background: var(--surface-2); border-left: 3px solid var(--border-strong);
  cursor: grab; position: relative;
}
.chip:active { cursor: grabbing; }
.chip .code { font-size: .68rem; font-weight: 700; letter-spacing: .05em; color: var(--muted); }
.chip .name { font-size: .8rem; line-height: 1.3; }
/* What to do, and (once ticked off) what was done. */
.chip .presc {
  font-size: .72rem; line-height: 1.35; color: var(--muted); margin-top: .15rem;
  /* A module description can run long; the card stays a card. The full text is
     in the tooltip and in the edit dialog. */
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3;
  line-clamp: 3; overflow: hidden;
}
/* The card body is the tap target for the details dialog. */
.chipmain { cursor: pointer; border-radius: 4px; }
.chipmain:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip .presc.did { color: var(--text); opacity: .85; }
.chip .presc.did::before { content: "✓ "; opacity: .6; }
.chip .meta { font-size: .68rem; color: var(--faint); font-variant-numeric: tabular-nums; }
/* Four actions have to fit one line inside a narrow day column. */
.chip .acts { display: flex; gap: .05rem; margin-top: .25rem; }
.chip .acts .btn {
  flex: 0 1 auto; min-width: 0; padding: .1rem .2rem; font-size: .8rem; line-height: 1.15;
  font-family: var(--sans); /* keep the glyphs out of emoji presentation */
}
.chip.done { opacity: .72; }
.chip.done .name { text-decoration: line-through; }
.chip.skipped { opacity: .45; }
.chip.skipped .name { text-decoration: line-through; }
.sortable-ghost { opacity: .35; }
.sortable-drag { box-shadow: var(--shadow); }

/* palette */
.palette { position: sticky; top: 4rem; }
@media (max-width: 940px) { .palette { position: static; } }
.req { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: .5rem; }
.req > summary {
  list-style: none; cursor: pointer; padding: .5rem .6rem;
  display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; align-items: center;
}
.req > summary::-webkit-details-marker { display: none; }
.req .dot { width: 9px; height: 9px; border-radius: 50%; }
.req .rname { font-size: .85rem; font-weight: 600; }
.req .rsub { font-size: .72rem; color: var(--faint); }
.req .count { font-size: .78rem; font-variant-numeric: tabular-nums; font-weight: 650; color: var(--muted); }
.req.satisfied .count { color: var(--ok); }
.bar { height: 3px; background: var(--surface-2); border-radius: 2px; overflow: hidden; margin: 0 .6rem .5rem; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.req.satisfied .bar > i { background: var(--ok); }
.modules { padding: 0 .5rem .5rem; display: flex; flex-direction: column; gap: .3rem; }
.modules .chip { background: var(--bg); }
.modules .chip .desc { font-size: .7rem; color: var(--faint); margin-top: .15rem; }
.req > summary:hover { background: var(--surface-2); border-radius: var(--radius); }
/* Tap-to-add list inside the day modal */
.addlist { display: flex; flex-direction: column; gap: .3rem; }
.addlist button { text-align: left; width: 100%; }
.addgroup { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--faint); font-weight: 650; margin: .5rem 0 .15rem; }
.addcustom { margin-top: .9rem; border-top: 1px solid var(--border); padding-top: .6rem; }
.addcustom > summary { cursor: pointer; font-weight: 650; font-size: .85rem; }
.addcustom > summary:hover { color: var(--accent); }
.addcustom form { margin-top: .6rem; }

/* ── Stats ──────────────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: .75rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .8rem; }
.stat .v { font-size: 1.55rem; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.sparkrow { display: flex; align-items: flex-end; gap: 3px; height: 72px; }
.sparkrow .b { flex: 1; min-width: 4px; background: var(--accent); border-radius: 2px 2px 0 0; position: relative; }
.sparkrow .b.done { background: var(--ok); }
.sparkrow .b.empty { background: var(--surface-2); }

/* ── Wizard ─────────────────────────────────────────────────────────────── */
.steps { display: flex; gap: .4rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.steps .s {
  display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--faint);
  padding: .25rem .6rem; border-radius: 999px; background: var(--surface-2);
}
.steps .s.cur { background: var(--accent); color: #fff; font-weight: 600; }
.steps .s.past { background: var(--ok-soft); color: var(--ok); }

.choice {
  display: grid; grid-template-columns: auto 1fr; gap: .15rem .55rem; align-items: start;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  padding: .7rem .8rem; cursor: pointer; background: var(--surface);
}
.choice + .choice { margin-top: .5rem; }
.choice:hover { border-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { grid-column: 1; grid-row: 1 / span 2; width: auto; margin: .25rem 0 0; }
.choice .t { grid-column: 2; font-weight: 600; }
.choice .d { grid-column: 2; font-size: .8rem; color: var(--muted); }

/* ── Draggable priority list ───────────────────────────────────────────── */
ol.prio { list-style: none; margin: .25rem 0 .5rem; padding: 0; counter-reset: prio; }
ol.prio li {
  counter-increment: prio;
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .55rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
ol.prio li + li { margin-top: .3rem; }
ol.prio li:first-child { border-color: var(--ok); }
ol.prio .grip { color: var(--faint); cursor: grab; font-size: 1rem; line-height: 1; touch-action: none; }
ol.prio li:active .grip { cursor: grabbing; }
ol.prio .n::before {
  content: counter(prio); display: inline-flex; align-items: center; justify-content: center;
  width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--surface-2);
  color: var(--muted); font-size: .75rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
ol.prio li:first-child .n::before { background: var(--ok-soft); color: var(--ok); }
ol.prio .pname { display: block; font-size: .875rem; }
ol.prio .moves { display: flex; gap: .1rem; }
ol.prio .moves .btn { padding: .1rem .35rem; line-height: 1.1; }

/* ── Tabs ───────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .45rem .7rem; font-size: .85rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ── AI context ────────────────────────────────────────────────────────── */
.fieldgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: .35rem .9rem; }
.fieldgrid label { display: flex; align-items: center; gap: .4rem; font-weight: 450;
  color: var(--text); font-size: .875rem; margin: 0; }
.fieldgrid input { width: auto; }
textarea.ctx {
  font: 12px/1.5 var(--mono); min-height: 24rem; background: var(--surface-2); white-space: pre;
}
.ctx-meta { font-variant-numeric: tabular-nums; }

/* ── Modal ──────────────────────────────────────────────────────────────── */
#modal:empty { display: none; }
#modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(10,16,22,.45);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-card { background: var(--surface); border-radius: 12px; padding: 1.1rem;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,.3); }

.htmx-request .spin { opacity: .5; }

/* ── Session details dialog ─────────────────────────────────────────────── */
.detail { margin: 0; display: grid; grid-template-columns: 1fr; gap: 0; }
.detail dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--faint); font-weight: 650; margin-top: .8rem; }
.detail dd { margin: .15rem 0 0; }
.detail .dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%;
  vertical-align: baseline; margin-right: .25rem; }
.detail .pre { white-space: pre-wrap; }
