/* ---------------------------------------------------------------------------
   Tokens.

   The stage colours are an ORDINAL ramp — one hue, stepping darker as a project
   advances Idea -> Prototype -> Beta -> Live — because the stages are ordered,
   not arbitrary categories. Retired is deliberately outside the ramp: it is an
   inactive state, not a further step, so it takes neutral grey and recedes.

   Both ramps are validated against their own surface (monotone lightness,
   >=0.06 lightness gaps, single hue, end step clears the surface). Colour never
   carries a stage on its own — every swatch sits beside its written label.
--------------------------------------------------------------------------- */
:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface:     #fcfcfb;
  --surface-2:   #f2f1ed;
  --ink:         #0b0b0b;
  --ink-2:       #52514e;
  --muted:       #898781;
  --hairline:    #e1e0d9;
  --border:      rgba(11, 11, 11, 0.10);
  --shadow:      0 1px 2px rgba(11, 11, 11, 0.05), 0 8px 24px rgba(11, 11, 11, 0.07);

  --stage-idea:      #86b6ef;
  --stage-prototype: #5598e7;
  --stage-beta:      #2a78d6;
  --stage-live:      #1c5cab;
  --stage-retired:   #898781;

  --accent:    #2a78d6;
  --critical:  #d03b3b;
  --good:      #006300;

  --radius:   10px;
  --radius-s: 6px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Dark tokens are declared twice on purpose: the media query follows the OS
   setting, and the [data-theme] scope follows an explicit toggle, which has to
   win in BOTH directions. The :not() guard lets a light stamp beat OS-dark;
   the standalone [data-theme="dark"] rule lets a dark stamp beat OS-light. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:      #0d0d0d;
    --surface:   #1a1a19;
    --surface-2: #232322;
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --muted:     #898781;
    --hairline:  #2c2c2a;
    --border:    rgba(255, 255, 255, 0.10);
    --shadow:    0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);

    --stage-idea:      #1c5cab;
    --stage-prototype: #2a78d6;
    --stage-beta:      #5598e7;
    --stage-live:      #86b6ef;
    --stage-retired:   #898781;

    --accent:   #3987e5;
    --critical: #e66767;
    --good:     #0ca30c;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0d0d0d;
  --surface:   #1a1a19;
  --surface-2: #232322;
  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --muted:     #898781;
  --hairline:  #2c2c2a;
  --border:    rgba(255, 255, 255, 0.10);
  --shadow:    0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);

  --stage-idea:      #1c5cab;
  --stage-prototype: #2a78d6;
  --stage-beta:      #5598e7;
  --stage-live:      #86b6ef;
  --stage-retired:   #898781;

  --accent:   #3987e5;
  --critical: #e66767;
  --good:     #0ca30c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }

/* --- top bar ------------------------------------------------------------ */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.topbar-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex: none;
}

.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.topbar-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--page);
}
.auth-gate[hidden] { display: none; }
.auth-card {
  width: min(420px, 100%);
  padding: 32px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-card h2 { font-size: 22px; }
.auth-card p { margin: 10px 0 22px; color: var(--ink-2); }

.input {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 7px 10px;
  min-width: 140px;
}
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

textarea.input { min-height: 72px; resize: vertical; width: 100%; }

.btn {
  font: inherit;
  font-weight: 500;
  border-radius: var(--radius-s);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 7px 12px;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn-primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-danger { color: var(--critical); border-color: currentColor; }
.btn-sm { padding: 4px 9px; font-size: 13px; }

.linkbtn {
  font: inherit;
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

main { padding: 20px 24px 48px; }

/* --- stat tiles --------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: block;
  width: 100%;
}
.tile:hover { border-color: var(--muted); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tile[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

.tile-label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-2);
  font-size: 13px;
}
.tile-value { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; }
.tile-hint { color: var(--muted); font-size: 12px; }

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
  background: var(--stage-color, var(--muted));
}

/* --- board -------------------------------------------------------------- */

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}
@media (max-width: 1100px) { .board { grid-template-columns: repeat(2, minmax(220px, 1fr)); } }
@media (max-width: 640px)  { .board { grid-template-columns: 1fr; } }

.column {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 90px;
}

.column-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 4px 10px;
}
.column-head h2 { font-size: 13px; font-weight: 600; }
.column-count { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.column-empty { color: var(--muted); font-size: 12px; padding: 6px 4px 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 11px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
}
.card:hover { border-color: var(--muted); box-shadow: var(--shadow); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.card-retired { opacity: 0.72; }

.card-name { font-weight: 600; line-height: 1.35; }
.card-desc {
  color: var(--ink-2);
  font-size: 13px;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.chip {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 12px;
  color: var(--ink-2);
}
.chip-priority-high { color: var(--critical); border-color: currentColor; }

.dot { color: var(--hairline); }

/* --- drawer ------------------------------------------------------------- */

.scrim, .modal-scrim {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.35);
  z-index: 10;
}
.modal-scrim { display: grid; place-items: center; padding: 24px; z-index: 20; }
.modal-scrim[hidden] { display: none; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--hairline);
  z-index: 11;
  overflow-y: auto;
  padding: 20px 22px 40px;
  box-shadow: var(--shadow);
}

.drawer-head { display: flex; align-items: flex-start; gap: 12px; }
.drawer-head h2 { font-size: 18px; flex: 1; }
.drawer-section { margin-top: 22px; }
.drawer-section > h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.stage-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.linklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.linklist li { display: flex; align-items: flex-start; gap: 8px; }
.linklist a { color: var(--accent); overflow-wrap: anywhere; flex: 1; min-width: 0; }
.link-kind {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  min-width: 62px;
}

/* history timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative;
  padding: 0 0 14px 20px;
  border-left: 1px solid var(--hairline);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 4px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--stage-color, var(--muted));
  box-shadow: 0 0 0 2px var(--surface);
}
.timeline-head { font-size: 13px; }
.timeline-time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.timeline-note { color: var(--ink-2); font-size: 13px; margin-top: 2px; }

.notes-body { white-space: pre-wrap; color: var(--ink-2); font-size: 13px; }

/* --- modal -------------------------------------------------------------- */

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px 24px;
  width: min(520px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal h2 { font-size: 17px; margin-bottom: 14px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
.field .input { width: 100%; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.form-error { color: var(--critical); font-size: 13px; margin-top: 10px; }

/* --- misc --------------------------------------------------------------- */

.empty-state { color: var(--muted); text-align: center; padding: 48px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--page);
  padding: 9px 16px;
  border-radius: 999px;
  z-index: 40;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
