/* Nook design system — tokens, base, and shared components.
   See DESIGN.md for the rationale. Linked AFTER each page's own <style>
   (via templates/_nook_head.html.j2) so these tokens win; the legacy
   variable names (--ink, --accent, --red …) are aliased onto them so
   older page-level CSS picks up the brand without being rewritten. */

:root {
  /* Surfaces — warm paper, not clinical white */
  --n-bg: #f7f6f2;
  --n-surface: #ffffff;
  --n-surface-2: #f1efe9;
  --n-border: #e4e1d8;
  --n-border-strong: #cfcbbf;

  /* Text */
  --n-ink: #1a1c23;
  --n-ink-2: #4a4d57;
  --n-muted: #7a7d86;

  /* Brand — ink indigo, plus the lamp amber used only for the logo and stars */
  --n-brand: #2d3a8c;
  --n-brand-hover: #24307a;
  --n-brand-tint: #eceef9;
  --n-on-brand: #ffffff;
  --n-lamp: #f5b83d;

  /* Signals — the only place red/amber/green appear */
  --n-pos: #1e7a4c;  --n-pos-bg: #e6f2ea;
  --n-warn: #9a6200; --n-warn-bg: #fbf0d9;
  --n-neg: #b42318;  --n-neg-bg: #fbe9e7;

  --n-radius-sm: 6px;
  --n-radius: 10px;
  --n-shadow: 0 1px 2px rgba(26, 28, 35, 0.05), 0 1px 1px rgba(26, 28, 35, 0.03);
  --n-font: "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  /* Legacy aliases for page-level CSS written before the design system */
  --ink: var(--n-ink); --muted: var(--n-muted); --border: var(--n-border);
  --bg: var(--n-surface); --row-alt: var(--n-surface-2); --accent: var(--n-brand);
  --red: var(--n-neg); --red-bg: var(--n-neg-bg);
  --yellow: var(--n-warn); --yellow-bg: var(--n-warn-bg);
  --green: var(--n-pos); --green-bg: var(--n-pos-bg);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --n-bg: #111216;
    --n-surface: #191b21;
    --n-surface-2: #20232b;
    --n-border: #2c2f38;
    --n-border-strong: #3a3e49;
    --n-ink: #ecedef;
    --n-ink-2: #b5b8c0;
    --n-muted: #8b8f99;
    --n-brand: #9aa6ff;
    --n-brand-hover: #b3bcff;
    --n-brand-tint: #23284a;
    --n-on-brand: #10132b;
    --n-pos: #5cc98d;  --n-pos-bg: #16291f;
    --n-warn: #e8b04a; --n-warn-bg: #2e2513;
    --n-neg: #f27c6f;  --n-neg-bg: #33191a;
    --n-shadow: none;
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; padding: 0;
  font-family: var(--n-font); font-size: 15px; line-height: 1.5;
  color: var(--n-ink); background: var(--n-bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05", "cv08"; /* Inter: open 'l', slashed-zero off */
}
a { color: var(--n-brand); }
a:hover { color: var(--n-brand-hover); }
input, select, textarea, button { font: inherit; }
:focus-visible { outline: 2px solid var(--n-brand); outline-offset: 2px; }
::selection { background: var(--n-brand-tint); }
.wrap { padding: 28px 24px 56px; }
@media (max-width: 640px) { .wrap { padding: 20px 16px 48px; } }
h1 { letter-spacing: -0.02em; font-weight: 650; }
h2, h3 { letter-spacing: -0.01em; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- App header ---------- */
.nk-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--n-surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--n-border);
}
.nk-header-inner {
  max-width: 1240px; margin: 0 auto; height: 56px; padding: 0 24px;
  display: flex; align-items: center; gap: 28px;
}
.nk-logo { display: flex; align-items: center; gap: 9px; color: var(--n-ink); text-decoration: none; flex-shrink: 0; }
.nk-logo:hover { color: var(--n-ink); }
.nk-logo .nk-mark { width: 26px; height: 26px; display: block; }
.nk-logo .nk-word { height: 17px; width: auto; display: block; }
.nk-nav { display: flex; align-items: stretch; gap: 2px; height: 100%; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nk-nav::-webkit-scrollbar { display: none; }
.nk-nav a {
  display: flex; align-items: center; padding: 0 12px; white-space: nowrap;
  font-size: 14px; font-weight: 500; color: var(--n-ink-2); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.nk-nav a:hover { color: var(--n-ink); }
.nk-nav a.active { color: var(--n-ink); border-bottom-color: var(--n-brand); font-weight: 600; }
.nk-nav .nk-nav-spacer { flex: 1; }
.nk-nav a.nk-nav-quiet { color: var(--n-muted); }
.nk-nav a.nk-nav-quiet.active { color: var(--n-ink); }
.nk-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 999px; background: var(--n-brand-tint); color: var(--n-brand); font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums;
}
@media (max-width: 720px) {
  .nk-header-inner { padding: 0 16px; gap: 16px; }
  .nk-logo .nk-word { display: none; }
  .nk-nav a { padding: 0 9px; }
}

/* ---------- Page head ---------- */
.nk-page { max-width: 1240px; margin: 0 auto; }
.nk-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.nk-page-head h1 { font-size: 26px; line-height: 1.2; margin: 0; }
.nk-sub { color: var(--n-muted); font-size: 13.5px; margin: 4px 0 0; }
.nk-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.nk-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--n-radius-sm);
  font-size: 14px; font-weight: 550; line-height: 1; white-space: nowrap;
  text-decoration: none; cursor: pointer;
  border: 1px solid var(--n-border-strong); background: var(--n-surface); color: var(--n-ink);
  box-shadow: var(--n-shadow);
}
.nk-btn:hover { background: var(--n-surface-2); color: var(--n-ink); }
.nk-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.nk-chip svg { width: 12px; height: 12px; flex-shrink: 0; }
.nk-btn-primary { background: var(--n-brand); border-color: var(--n-brand); color: var(--n-on-brand); }
.nk-btn-primary:hover { background: var(--n-brand-hover); border-color: var(--n-brand-hover); color: var(--n-on-brand); }
.nk-btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--n-ink-2); }
.nk-btn-ghost:hover { background: var(--n-surface-2); }
.nk-btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.nk-btn:disabled { opacity: 0.6; cursor: progress; }
.nk-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border-radius: var(--n-radius-sm); border: none; background: transparent; color: var(--n-muted); cursor: pointer; padding: 0;
}
.nk-icon-btn:hover { background: var(--n-surface-2); color: var(--n-ink); }
.nk-icon-btn svg { width: 16px; height: 16px; }
.nk-star.on { color: var(--n-lamp); }
.nk-star.on svg { fill: currentColor; }
.nk-btn.nk-star.on { color: var(--n-ink); background: var(--n-surface-2); }
.nk-btn.nk-star.on svg { color: var(--n-lamp); }

/* ---------- Form controls ---------- */
.nk-input, .nk-select {
  height: 36px; padding: 0 10px; border-radius: var(--n-radius-sm);
  border: 1px solid var(--n-border-strong); background: var(--n-surface); color: var(--n-ink); font-size: 14px;
}
.nk-select { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a7d86' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; }
.nk-select[multiple] { height: auto; padding: 4px; background-image: none; }
.nk-input:focus, .nk-select:focus { outline: none; border-color: var(--n-brand); box-shadow: 0 0 0 3px var(--n-brand-tint); }
.nk-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 550; color: var(--n-muted); }
.nk-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--n-ink-2); cursor: pointer; white-space: nowrap; }
.nk-check input { accent-color: var(--n-brand); width: 15px; height: 15px; margin: 0; }
.nk-search { position: relative; }
.nk-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--n-muted); pointer-events: none; }
.nk-search .nk-input { padding-left: 32px; width: 100%; }

/* ---------- Toolbar & disclosure ---------- */
.nk-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.nk-toolbar .nk-grow { flex: 1 1 220px; min-width: 180px; }
details.nk-more > summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: var(--n-radius-sm);
  border: 1px dashed var(--n-border-strong); color: var(--n-ink-2); font-size: 14px; font-weight: 500;
}
details.nk-more > summary::-webkit-details-marker { display: none; }
details.nk-more > summary::before { content: "+"; font-weight: 600; color: var(--n-muted); }
details.nk-more[open] > summary::before { content: "−"; }
details.nk-more[open] > summary { border-style: solid; background: var(--n-surface); }

/* ---------- Chips & score ---------- */
.nk-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 550; white-space: nowrap; line-height: 1;
  background: var(--n-surface-2); color: var(--n-ink-2);
}
.nk-chip.pos { background: var(--n-pos-bg); color: var(--n-pos); }
.nk-chip.warn { background: var(--n-warn-bg); color: var(--n-warn); }
.nk-chip.neg { background: var(--n-neg-bg); color: var(--n-neg); }
.nk-chip.brand { background: var(--n-brand-tint); color: var(--n-brand); }
.nk-chip.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--n-border-strong); color: var(--n-muted); }
.nk-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
a.nk-chip { text-decoration: none; }
a.nk-chip:hover { filter: brightness(0.96); }

.nk-score {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 56px; height: 56px; border-radius: var(--n-radius); flex-shrink: 0;
  background: var(--n-surface-2); color: var(--n-muted);
}
.nk-score b { font-size: 21px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.nk-score small { font-size: 10px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; }
.nk-score.pos { background: var(--n-pos-bg); color: var(--n-pos); }
.nk-score.top { background: var(--n-pos); color: var(--n-surface); }
.nk-score.warn { background: var(--n-warn-bg); color: var(--n-warn); }
.nk-score.neg { background: var(--n-neg-bg); color: var(--n-neg); }

/* ---------- Cards, stats, notices ---------- */
.nk-card { background: var(--n-surface); border: 1px solid var(--n-border); border-radius: var(--n-radius); box-shadow: var(--n-shadow); }
.nk-stats { display: flex; flex-wrap: wrap; background: var(--n-surface); border: 1px solid var(--n-border); border-radius: var(--n-radius); box-shadow: var(--n-shadow); margin-bottom: 20px; }
.nk-stat { flex: 1 1 120px; padding: 12px 16px; border-left: 1px solid var(--n-border); }
.nk-stat:first-child { border-left: none; }
.nk-stat .v { display: block; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1.2; }
.nk-stat .l { font-size: 12.5px; color: var(--n-muted); display: inline-flex; align-items: center; gap: 6px; }
.nk-stat .l .nk-dot.neg { color: var(--n-neg); } .nk-stat .l .nk-dot.warn { color: var(--n-warn); } .nk-stat .l .nk-dot.pos { color: var(--n-pos); }
@media (max-width: 640px) { .nk-stat { flex-basis: 33%; border-left: none; } }

.nk-notice {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: var(--n-radius); font-size: 13.5px; margin-bottom: 16px;
  background: var(--n-surface); border: 1px solid var(--n-border); color: var(--n-ink-2);
}
.nk-notice form { margin: 0; }
.flash { border-radius: var(--n-radius); }

/* ---------- Dialog ---------- */
dialog.nk-dialog {
  border: 1px solid var(--n-border); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--n-surface); color: var(--n-ink); box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
}
dialog.nk-dialog::backdrop { background: rgba(17, 18, 22, 0.45); }
.nk-dialog-body { padding: 22px 22px 18px; display: flex; flex-direction: column; gap: 12px; }
.nk-dialog-body h2 { margin: 0; font-size: 18px; }
.nk-dialog-body p { margin: 0; color: var(--n-muted); font-size: 13.5px; }
.nk-dialog-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 22px; border-top: 1px solid var(--n-border); background: var(--n-surface-2); border-radius: 0 0 14px 14px; }
.nk-hint { font-size: 12.5px; color: var(--n-muted); }

/* ---------- Footer ---------- */
.nk-footer { max-width: 1240px; margin: 40px auto 0; padding-top: 16px; border-top: 1px solid var(--n-border); font-size: 12.5px; color: var(--n-muted); display: flex; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
