/* Base layer: structure and behaviour. Every look is driven by the tokens below;
   a theme (css/themes/*.css) redefines them and adds its own overrides. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f1f5;
  --text: #14161a;
  --muted: #6b7280;
  --border: #e4e6eb;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eceefe;
  --good: #15803d;
  --good-soft: #e3f5e9;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --bad: #b91c1c;
  --bad-soft: #fde8e8;
  --radius: 14px;
  --radius-sm: 10px;
  --bw: 1px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: var(--font);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #171a1f;
    --surface-2: #1f232a;
    --text: #eceef2;
    --muted: #9aa3b2;
    --border: #272c35;
    --accent: #818cf8;
    --accent-text: #0e1013;
    --accent-soft: #252850;
    --good: #4ade80;
    --good-soft: #14301f;
    --warn: #fbbf24;
    --warn-soft: #3a2b10;
    --bad: #f87171;
    --bad-soft: #3b1717;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.2; font-family: var(--font-display); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.splash { display: grid; place-items: center; min-height: 100dvh; color: var(--muted); }
.icon { flex: none; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
.masthead { display: none; }
.nav {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: 2px;
  padding: 20px 12px; border-right: var(--bw) solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 18px; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.nav a.item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--radius-sm); color: var(--muted); font-weight: 500;
}
.nav a.item:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.item.active { background: var(--accent-soft); color: var(--accent); }
.nav .spacer { flex: 1; }
.badge-dot {
  margin-left: auto; min-width: 20px; padding: 0 6px; height: 20px; border-radius: 10px;
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.main { padding: 28px 32px 72px; width: 100%; min-width: 0; max-width: 1100px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; z-index: 20; inset: auto 0 0 0; height: auto;
    flex-direction: row; justify-content: space-around; gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: var(--bw) solid var(--border);
  }
  .brand, .nav .spacer { display: none; }
  .nav a.item {
    flex: 1; flex-direction: column; gap: 2px; padding: 6px 0;
    font-size: 10px; text-align: center; min-width: 0; align-items: center;
  }
  .nav a.item span.label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .badge-dot { position: absolute; top: 0; right: 14%; margin: 0; min-width: 16px; height: 16px; font-size: 10px; }
  .main { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
}

/* ---------- common ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; letter-spacing: -0.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 16px; }

.card {
  background: var(--surface); border: var(--bw) solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .count { color: var(--muted); font-weight: 500; }
.card h2 a { margin-left: auto; font-size: 13px; font-weight: 500; }
.stat { display: block; color: inherit; }
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; font-family: var(--font-display); }
.stat .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

.empty { color: var(--muted); padding: 18px 4px; text-align: center; font-size: 14px; }

/* ---------- forms ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface-2); border: var(--bw) solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; min-width: 0; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type="checkbox"] { width: auto; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.form-row > * { flex: 1 1 130px; }
.form-row > .grow { flex: 3 1 220px; }
.form-row > .fit { flex: 0 0 auto; }
.form-row > select.compact { flex: 0 0 auto; width: 72px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: var(--bw) solid var(--border); background: var(--surface); border-radius: var(--radius-sm);
  padding: 9px 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: calc(var(--radius-sm) - 2px); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; flex: none;
  border: 0; background: transparent; color: var(--muted); border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--bad); }

.tabs { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.tabs button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: calc(var(--radius-sm) - 2px); cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 13px;
}
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.pill.academic { background: var(--accent-soft); color: var(--accent); }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: var(--bw) solid var(--border); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 500; overflow-wrap: anywhere; }
.list .meta { color: var(--muted); font-size: 13px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.list .meta .overdue { color: var(--bad); font-weight: 600; }
.group-label { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 18px 0 2px; }
.group-label:first-child { margin-top: 0; }
.group-label.overdue { color: var(--bad); }

.check {
  width: 22px; height: 22px; border-radius: 50%; flex: none; cursor: pointer;
  border: 2px solid var(--border); background: transparent; display: grid; place-items: center; padding: 0; color: transparent;
}
.check:hover { border-color: var(--accent); }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
li.done .title { text-decoration: line-through; color: var(--muted); }

.edit-row { display: flex; gap: 8px; flex-wrap: wrap; width: 100%; }
.edit-row input { flex: 1 1 160px; }

/* ---------- time-based ---------- */
.event-time { width: 76px; flex: none; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.day { margin-top: 20px; }
.day:first-child { margin-top: 0; }
.day h3 { font-size: 14px; display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.day h3.today { color: var(--accent); }
.bar-track { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.3s; }
.bar-fill.good { background: var(--good); }
.cat-row { display: grid; grid-template-columns: 110px 1fr 70px; gap: 10px; align-items: center; padding: 5px 0; font-size: 14px; }
.cat-row .amt { text-align: right; font-variant-numeric: tabular-nums; }

.heat { max-width: 640px; display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.heat button {
  width: 100%; min-width: 10px; aspect-ratio: 1; border-radius: 4px; border: 0; padding: 0; cursor: pointer;
  background: var(--surface-2);
}
.heat button.l1 { background: color-mix(in srgb, var(--accent) 45%, var(--surface-2)); }
.heat button.l2 { background: var(--accent); }
.heat button.future { opacity: 0.35; cursor: default; }
.heat button.sel { outline: 2px solid var(--text); outline-offset: 1px; }

.chart { display: block; max-width: 640px; margin: 0 auto; }
.chart text { fill: var(--muted); font-size: 8px; }
.chart .bar { fill: var(--accent); }
.chart .bar.low { fill: var(--warn); }
.chart .target { stroke: var(--muted); stroke-dasharray: 3 3; }

/* ---------- auth + toasts ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth .card { max-width: 400px; width: 100%; padding: 28px; }
.auth h1 { font-size: 24px; margin: 14px 0 4px; }
.auth .stack { display: grid; gap: 10px; margin-top: 18px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 6px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.toasts { position: fixed; z-index: 50; left: 50%; transform: translateX(-50%); bottom: calc(88px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(92vw, 420px); }
@media (min-width: 861px) { .toasts { bottom: 24px; } }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.error { background: var(--bad); color: #fff; }

.banner { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; margin-bottom: 18px; font-size: 14px; }
.stack-gap > * + * { margin-top: 12px; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; }
.checks label { display: flex; gap: 6px; align-items: center; font-size: 14px; }

/* ---------- design workshop switcher (demo mode only) ---------- */
.switcher {
  position: fixed; z-index: 100; right: 12px; bottom: 12px;
  display: flex; gap: 4px; padding: 5px; border-radius: 999px;
  background: #15171c; color: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); font: 600 12px/1 system-ui, sans-serif;
}
.switcher button {
  border: 0; border-radius: 999px; padding: 8px 12px; cursor: pointer; background: transparent; color: #b8bdc9; font: inherit;
}
.switcher button.on { background: #fff; color: #15171c; }
@media (max-width: 860px) { .switcher { bottom: calc(76px + env(safe-area-inset-bottom)); } }
