/* Projects - command-board UI, ported from Captain's Mission Control.
   Desktop: sidebar + stats strip + content + Live Activity rail.
   Phone: scrolling stat strip, single-column cards, bottom tab bar.

   THEMING: same pattern as the other apps - data-theme on <html>, all colour through
   CSS vars, persisted in localStorage. :root is dark; [data-theme="light"] overrides.
   With no explicit choice we follow the OS via prefers-color-scheme. Every component
   colour below goes through a var, so neither theme has hardcoded one-offs. */

:root,
:root[data-theme="dark"] {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2129;
  --border: #262c36;
  --border-soft: #21262d;
  --text: #e6edf3;
  --muted: #8b949e;
  --dim: #7d8590;
  --accent: #58a6ff;
  --accent-text: #04101f;
  --accent-hover: #79b8ff;
  --link: #58a6ff;
  --surface: #161b22;
  --danger: #f85149;
  --danger-border: #4a1f1f;
  --danger-hover: #2a1414;
  --warn: #d29922;
  --orange: #f0883e;
  --green: #3fb950;
  --purple: #bc8cff;

  --chip-on-bg: #132a4d;
  --chip-on-text: #cfe6ff;
  --tag-bg: #14243d;
  --tag-text: #9ecbff;
  --tag-border: #1f3b63;
  --col-over-bg: #121a26;
  --input-bg: #0d1117;
  --input-focus-bg: #10151c;
  --overlay: rgba(1, 4, 9, .72);
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);

  --pill-active-bg: #10301c;   --pill-active-fg: #6ee7a0;  --pill-active-bd: #1d5334;
  --pill-planning-bg: #3a2c08; --pill-planning-fg: #e3b341; --pill-planning-bd: #5a4410;
  --pill-paused-bg: #26262b;   --pill-paused-fg: #9ea7b3;  --pill-paused-bd: #3a3a42;
  --pill-research-bg: #10263f; --pill-research-fg: #79c0ff; --pill-research-bd: #1c3e64;
  --pill-future-bg: #2a1f3d;   --pill-future-fg: #d2a8ff;  --pill-future-bd: #402f5c;
  --pill-done-bg: #1a2a20;     --pill-done-fg: #7ee2a8;    --pill-done-bd: #234a33;

  --sidebar-w: 200px;
  --rail-w: 300px;
  --topbar-h: 74px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f8fa;
  --panel: #ffffff;
  --panel-2: #f2f5f8;
  --border: #d6dde5;
  --border-soft: #e4e9ee;
  --text: #1a1f26;
  --muted: #57606a;
  --dim: #6d757e;
  --accent: #0969da;
  --accent-text: #ffffff;
  --accent-hover: #0a5cbe;
  --link: #0969da;
  --surface: #ffffff;
  --danger: #cf222e;
  --danger-border: #f0c4c8;
  --danger-hover: #fdf0f1;
  --warn: #9a6700;
  --orange: #bc4c00;
  --green: #1a7f37;
  --purple: #8250df;

  --chip-on-bg: #ddf0ff;
  --chip-on-text: #0a4a8f;
  --tag-bg: #eaf3ff;
  --tag-text: #0a4a8f;
  --tag-border: #bcd9f5;
  --col-over-bg: #eef5fd;
  --input-bg: #ffffff;
  --input-focus-bg: #ffffff;
  --overlay: rgba(27, 33, 41, .42);
  --shadow: 0 18px 44px rgba(31, 41, 55, .16);

  --pill-active-bg: #dbf5e4;   --pill-active-fg: #10662f;  --pill-active-bd: #a6e3bd;
  --pill-planning-bg: #fdf1cd; --pill-planning-fg: #7a5300; --pill-planning-bd: #f0d68a;
  --pill-paused-bg: #eceff2;   --pill-paused-fg: #57606a;  --pill-paused-bd: #d3d9e0;
  --pill-research-bg: #ddeeff; --pill-research-fg: #0a4a8f; --pill-research-bd: #b3d6f7;
  --pill-future-bg: #f0e6ff;   --pill-future-fg: #6329bf;  --pill-future-bd: #dcc7f7;
  --pill-done-bg: #e3f3e8;     --pill-done-fg: #1a7f37;    --pill-done-bd: #b6dfc4;

  color-scheme: light;
}

/* No explicit choice yet? Follow the OS. An explicit data-theme always wins. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f6f8fa; --panel: #ffffff; --panel-2: #f2f5f8;
    --border: #d6dde5; --border-soft: #e4e9ee;
    --text: #1a1f26; --muted: #57606a; --dim: #6d757e;
    --accent: #0969da; --accent-text: #ffffff; --accent-hover: #0a5cbe; --link: #0969da;
    --surface: #ffffff;
    --danger: #cf222e; --danger-border: #f0c4c8; --danger-hover: #fdf0f1;
    --warn: #9a6700; --orange: #bc4c00; --green: #1a7f37; --purple: #8250df;
    --chip-on-bg: #ddf0ff; --chip-on-text: #0a4a8f;
    --tag-bg: #eaf3ff; --tag-text: #0a4a8f; --tag-border: #bcd9f5;
    --col-over-bg: #eef5fd;
    --input-bg: #ffffff; --input-focus-bg: #ffffff;
    --overlay: rgba(27, 33, 41, .42);
    --shadow: 0 18px 44px rgba(31, 41, 55, .16);
    --pill-active-bg: #dbf5e4;   --pill-active-fg: #10662f;  --pill-active-bd: #a6e3bd;
    --pill-planning-bg: #fdf1cd; --pill-planning-fg: #7a5300; --pill-planning-bd: #f0d68a;
    --pill-paused-bg: #eceff2;   --pill-paused-fg: #57606a;  --pill-paused-bd: #d3d9e0;
    --pill-research-bg: #ddeeff; --pill-research-fg: #0a4a8f; --pill-research-bd: #b3d6f7;
    --pill-future-bg: #f0e6ff;   --pill-future-fg: #6329bf;  --pill-future-bd: #dcc7f7;
    --pill-done-bg: #e3f3e8;     --pill-done-fg: #1a7f37;    --pill-done-bd: #b6dfc4;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }

.boot { padding: 60px 24px; text-align: center; color: var(--muted); }
.fatal { padding: 40px 24px; max-width: 620px; margin: 0 auto; }
.fatal code { background: var(--panel); padding: 2px 6px; border-radius: 4px; font-size: .85em; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr var(--rail-w); min-height: 100vh; }

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 0 24px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { padding: 0 18px 18px; border-bottom: 1px solid var(--border-soft); margin-bottom: 14px; }
.brand h1 { margin: 0; font-size: 1.05rem; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.brand .sub { color: var(--dim); font-size: .76rem; margin-top: 3px; word-break: break-all; }
.navgroup { color: var(--dim); font-size: .68rem; letter-spacing: .11em; text-transform: uppercase; padding: 12px 18px 6px; }
.navitem {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: none; border: 0; border-right: 2px solid transparent;
  padding: 9px 18px; color: var(--muted); text-align: left; font-size: .92rem;
}
.navitem:hover { background: var(--panel-2); color: var(--text); }
.navitem.on { background: var(--panel-2); color: var(--text); border-right-color: var(--accent); font-weight: 600; }
.navitem .count { margin-left: auto; font-size: .76rem; color: var(--dim); font-variant-numeric: tabular-nums; }
.navitem .ico { width: 15px; text-align: center; opacity: .75; }
.sidefoot { margin-top: auto; padding: 14px 18px 0; border-top: 1px solid var(--border-soft); color: var(--dim); font-size: .72rem; }
.sidefoot button { background: none; border: 0; color: var(--dim); padding: 6px 0; font-size: .72rem; text-decoration: underline; }
.sidefoot .build { font-variant-numeric: tabular-nums; }

/* ---------- main + stats strip ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.statsbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px 14px 26px; border-bottom: 1px solid var(--border);
  background: var(--panel); min-height: var(--topbar-h);
}
.stats-scroll {
  display: flex; gap: 32px; align-items: center; flex: 1; min-width: 0;
  overflow-x: auto; scrollbar-width: none;
}
.stats-scroll::-webkit-scrollbar { display: none; }
.stat { flex: 0 0 auto; }
.stat .n { font-size: 1.5rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .64rem; letter-spacing: .09em; text-transform: uppercase; color: var(--dim); margin-top: 2px; }
.stat.amber .n { color: var(--warn); }
.stat.green .n { color: var(--green); }
.stat.orange .n { color: var(--orange); }

/* theme switch - pinned outside the scrolling stats so it never scrolls away */
.themebtn {
  flex: 0 0 auto; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 9px; padding: 7px 12px; font-size: .78rem;
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
}
.themebtn:hover { color: var(--text); border-color: var(--dim); }
.themebtn .ico { display: flex; align-items: center; }
.auth-theme { display: flex; align-items: center; gap: 6px; justify-content: center; text-decoration: none; }
.auth-theme:hover { color: var(--text); }

.content { padding: 22px 26px 60px; flex: 1; min-width: 0; }
.page-h { margin: 0 0 4px; font-size: 1.35rem; }
.page-sub { color: var(--muted); font-size: .86rem; margin: 0 0 16px; }
.page-sub strong { color: var(--text); font-weight: 600; }

/* ---------- filter chips ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  background: var(--panel); border: 1px solid var(--border); color: var(--muted);
  border-radius: 7px; padding: 5px 13px; font-size: .84rem;
}
.chip:hover { color: var(--text); border-color: var(--dim); }
.chip.on { background: var(--chip-on-bg); border-color: var(--accent); color: var(--chip-on-text); font-weight: 600; }

/* ---------- kanban ---------- */
.columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
.col { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; min-height: 220px; }
.col.over { border-color: var(--accent); background: var(--col-over-bg); }
.col-h {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 13px; border-bottom: 1px solid var(--border-soft);
  border-top: 2px solid var(--tint, var(--dim)); border-radius: 10px 10px 0 0;
  font-weight: 600; font-size: .9rem;
}
.col-h .count { margin-left: auto; color: var(--dim); font-size: .8rem; font-variant-numeric: tabular-nums; }
.col-b { padding: 10px; display: flex; flex-direction: column; gap: 9px; min-height: 90px; }
.col-empty { color: var(--muted); font-size: .82rem; text-align: center; padding: 26px 12px; line-height: 1.45; }

.card {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 11px 12px; cursor: grab; position: relative;
}
.card:hover { border-color: var(--dim); }
.card.dragging { opacity: .45; }
/* Brain-dump titles are sometimes a whole dictated paragraph. Clamp them so one card
   can't own the column; the full text is always there in the card editor. */
.card .t {
  font-size: .89rem; line-height: 1.4; margin-bottom: 8px; word-break: break-word;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6;
  line-clamp: 6; overflow: hidden;
}
.card .more { font-size: .7rem; color: var(--accent); margin: -4px 0 8px; }
.card .meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .7rem; color: var(--muted); }
.tag {
  background: var(--tag-bg); color: var(--tag-text); border: 1px solid var(--tag-border);
  border-radius: 5px; padding: 2px 7px; font-size: .68rem; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tag.none { background: transparent; color: var(--muted); border-color: var(--border); }
.cat { font-size: .66rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- project registry ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; align-items: start; }
.pcard { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 15px 16px; }
.pcard:hover { border-color: var(--dim); }
.pcard-h { display: flex; align-items: flex-start; gap: 10px; }
.pcard-h h3 { margin: 0; font-size: 1rem; flex: 1; word-break: break-word; }
.pill {
  font-size: .68rem; padding: 2px 9px; border-radius: 999px; white-space: nowrap;
  border: 1px solid transparent; text-transform: lowercase;
}
.pill.active   { background: var(--pill-active-bg);   color: var(--pill-active-fg);   border-color: var(--pill-active-bd); }
.pill.planning { background: var(--pill-planning-bg); color: var(--pill-planning-fg); border-color: var(--pill-planning-bd); }
.pill.paused   { background: var(--pill-paused-bg);   color: var(--pill-paused-fg);   border-color: var(--pill-paused-bd); }
.pill.research { background: var(--pill-research-bg); color: var(--pill-research-fg); border-color: var(--pill-research-bd); }
.pill.future   { background: var(--pill-future-bg);   color: var(--pill-future-fg);   border-color: var(--pill-future-bd); }
.pill.done     { background: var(--pill-done-bg);     color: var(--pill-done-fg);     border-color: var(--pill-done-bd); }
.prio { display: flex; align-items: center; gap: 6px; font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 8px 0 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot.critical { background: var(--danger); }
.dot.high     { background: var(--orange); }
.dot.medium   { background: var(--warn); }
.dot.low      { background: var(--dim); }
.pcard .desc { color: var(--muted); font-size: .86rem; margin: 9px 0 0; line-height: 1.5; word-break: break-word; }
.pcard .links { border-top: 1px solid var(--border-soft); margin-top: 12px; padding-top: 10px; }
.pcard .links .lbl { font-size: .66rem; text-transform: uppercase; letter-spacing: .07em; color: var(--dim); margin-bottom: 5px; }
.pcard .links a { display: block; font-size: .84rem; margin-bottom: 3px; text-decoration: none; word-break: break-all; }
.pcard .links a:hover { text-decoration: underline; }
.pcard .upd { color: var(--muted); font-size: .72rem; margin-top: 11px; }
.bar { height: 4px; background: var(--border); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ---------- live activity rail ---------- */
.rail { background: var(--panel); border-left: 1px solid var(--border); position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.rail-h { display: flex; align-items: center; gap: 8px; padding: 16px 18px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: .95rem; position: sticky; top: 0; background: var(--panel); }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 18%, transparent); }
.act { padding: 12px 18px; border-bottom: 1px solid var(--border-soft); }
.act .who { color: var(--accent); font-weight: 600; font-size: .82rem; }
.act .when { color: var(--muted); font-size: .74rem; margin-left: 7px; }
.act .msg { color: var(--muted); font-size: .84rem; margin-top: 4px; line-height: 1.45; word-break: break-word; }
.rail .empty { padding: 22px 18px; color: var(--dim); font-size: .84rem; }

/* ---------- editor overlay ---------- */
.overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 60; overflow-y: auto; }
.sheet { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; box-shadow: var(--shadow); }
.sheet h3 { margin: 0 0 14px; font-size: 1.05rem; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--dim); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; font-size: .9rem; color: var(--text);
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sheet-actions { display: flex; gap: 9px; margin-top: 16px; }
.sheet-actions .grow { flex: 1; }
.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px; padding: 9px 16px; font-weight: 600; }
.primary:hover { background: var(--accent-hover); }
.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 16px; }
.ghost:hover { border-color: var(--dim); }
.danger { background: none; color: var(--danger); border: 1px solid var(--danger-border); border-radius: 8px; padding: 9px 14px; }
.danger:hover { background: var(--danger-hover); }
.readonly { background: var(--input-bg); border: 1px solid var(--border-soft); border-radius: 8px; padding: 10px 11px; font-size: .85rem; color: var(--muted); line-height: 1.5; white-space: pre-wrap; word-break: break-word; }

/* ---------- sign-in gate ----------
   auth-gate.js injects its own CSS but styles no inputs, so they fell back to a white
   browser default while inheriting our light text. Result: you could type but barely see
   it. These rules own the fields outright, in both themes. */
.auth-card { box-shadow: var(--shadow); }
.auth-card h2 { font-size: 1.25rem; }
.authform input {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 12px 13px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  -webkit-text-fill-color: var(--text);   /* iOS/Safari ignores `color` on some inputs */
  caret-color: var(--accent);
}
.authform input::placeholder { color: var(--dim); font-weight: 400; }
.authform input:focus { outline: none; border-color: var(--accent); background: var(--input-focus-bg); }
.authform input:-webkit-autofill,
.authform input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px var(--input-bg) inset;   /* kill Chrome's autofill wash */
}
.auth-card .muted { color: var(--muted); font-size: .88rem; }
.auth-theme {
  display: block; margin: 14px auto 0; background: none; border: 0;
  color: var(--dim); font-size: .76rem; text-decoration: underline;
}

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--border); color: var(--text); padding: 10px 18px; border-radius: 9px; font-size: .87rem; z-index: 80; box-shadow: var(--shadow); }
.toast.err { border-color: var(--danger); color: var(--danger); }

/* ---------- mobile tab bar (hidden on desktop) ---------- */
.tabbar { display: none; }

/* ---------- phone ---------- */
@media (max-width: 980px) {
  :root { --topbar-h: 62px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .rail { display: none; }
  .shell.show-activity .rail {
    display: block; position: fixed; inset: 0; height: 100dvh; z-index: 70; border-left: 0;
  }
  .statsbar { gap: 10px; padding: 11px 12px 11px 16px; position: sticky; top: 0; z-index: 20; }
  .stats-scroll { gap: 22px; }
  .stat .n { font-size: 1.2rem; }
  .themebtn { padding: 7px 9px; }
  .themebtn .lbl { display: none; }
  .content { padding: 16px 14px 92px; }
  .columns { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .card .t { -webkit-line-clamp: 5; line-clamp: 5; }

  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--panel); border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar button {
    flex: 1; background: none; border: 0; color: var(--dim);
    padding: 9px 4px 8px; font-size: .66rem; display: flex; flex-direction: column;
    align-items: center; gap: 3px; border-top: 2px solid transparent; margin-top: -1px;
  }
  .tabbar button.on { color: var(--accent); border-top-color: var(--accent); }
  .tabbar .ico { font-size: 1.05rem; line-height: 1; }
  .tabbar .count { font-variant-numeric: tabular-nums; }

  .overlay { padding: 0; align-items: stretch; }
  .sheet { max-width: none; border-radius: 0; min-height: 100dvh; padding: 18px 16px 40px; }
  .card { cursor: pointer; }
  .row2 { grid-template-columns: 1fr; }
}

@media (max-width: 1240px) and (min-width: 981px) {
  :root { --rail-w: 250px; }
}
