/* Cascadia Command Center — mobile-first styles. Phone layout is the default;
   wider screens are layered on with min-width queries. */
:root {
  --ink: #17303f;
  --ink-soft: #536b77;
  --bg: #f2f5f4;
  --surface: #ffffff;
  --line: #d8e2e4;
  --brand: #0c2836;
  --brand-ink: #ffffff;
  --brand-soft: #b9dbd3;
  --accent: #0f6b69;

  --gh: #1d6b3a;
  --gh-bg: #e3f3e8;
  --demo: #8a4b00;
  --demo-bg: #fff3df;
  --demo-line: #e0a34f;

  --ok: #1d6b3a;
  --warn: #8a5a00;
  --bad: #a3271c;
  --off: #66737a;
  --off-bg: #eef1f2;
  --protected: #4a3c8c;
  --protected-bg: #eeebfa;

  --radius: 14px;
  --tap: 44px;
  --tabbar-h: 62px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e4ecee;
    --ink-soft: #9bb0b8;
    --bg: #0b1418;
    --surface: #132228;
    --line: #24383f;
    --brand: #0a1f29;
    --brand-soft: #8fc7ba;
    --accent: #5fc4bb;
    --gh: #7ad79a;
    --gh-bg: #143322;
    --demo: #ffc778;
    --demo-bg: #2e2210;
    --demo-line: #a8742c;
    --ok: #7ad79a;
    --warn: #f2c45c;
    --bad: #ff8a7d;
    --off: #a3b0b6;
    --off-bg: #1c2b31;
    --protected: #c4b8ff;
    --protected-bg: #241f3d;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 8px; }
body { margin: 0; background: var(--bg); line-height: 1.4; }
a { color: var(--accent); font-weight: 600; text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 1.1rem; margin: 22px 0 10px; }
h3 { font-size: .95rem; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }

/* Header */
.top {
  background: var(--brand);
  color: var(--brand-ink);
  padding: calc(14px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}
.top-inner { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; max-width: 960px; margin: 0 auto; }
.eyebrow { display: block; color: var(--brand-soft); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; }
.top h1 { font-size: 1.45rem; margin: 4px 0 0; letter-spacing: -.01em; }
.legend { max-width: 960px; margin: 12px auto 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: .75rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; margin-right: 10px; }
.legend-text { color: var(--brand-soft); }

.pill { display: inline-block; border-radius: 999px; padding: 4px 10px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.pill-proto { background: #ffe2a8; color: #5b3a00; margin-top: 4px; }

/* Source labels: the core "real vs demo" signal. Text, not colour alone. */
.src { display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 2px 7px; font-size: .68rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.src-github { background: var(--gh-bg); color: var(--gh); }
.src-github::before { content: "●"; font-size: .6rem; }
.src-demo { background: var(--demo-bg); color: var(--demo); border: 1px dashed var(--demo-line); }
.src-demo::before { content: "◇"; font-size: .7rem; }

/* Tab bar: fixed to the bottom on phones (thumb reach), top on wide screens. */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs-inner { display: grid; grid-template-columns: repeat(6, 1fr); max-width: 960px; margin: 0 auto; }
.tabs button {
  position: relative; appearance: none; border: 0; background: none; color: var(--ink-soft);
  font: inherit; font-size: .64rem; font-weight: 600; min-height: var(--tabbar-h); min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab-ico { font-size: 1.15rem; line-height: 1; }
.tabs button[aria-selected="true"] { color: var(--accent); }
.tabs button[aria-selected="true"]::after { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
.badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: .65rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }

/* Main */
.wrap {
  max-width: 960px; margin: 0 auto;
  padding: 14px max(16px, env(safe-area-inset-right)) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px) max(16px, env(safe-area-inset-left));
}
.controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.snapshot { font-size: .8rem; color: var(--ink-soft); flex: 1 1 220px; }
.snapshot strong { color: var(--ink); }
.snapshot.stale strong { color: var(--warn); }

.switch { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap); font-size: .85rem; font-weight: 600; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; transition: background .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #0003; transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--demo-line); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Cards and lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card + .card { margin-top: 10px; }
.card.is-demo { background: repeating-linear-gradient(135deg, var(--surface) 0 14px, var(--demo-bg) 14px 16px); border: 1.5px dashed var(--demo-line); }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 0 8px; }
.group-head h2 { margin: 0; }
.group-note { font-size: .78rem; color: var(--ink-soft); margin: -2px 0 10px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list.is-demo { border: 1.5px dashed var(--demo-line); background: var(--demo-bg); }
.list > li { padding: 12px 16px; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list.is-demo > li { border-top-color: color-mix(in srgb, var(--demo-line) 40%, transparent); }
.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.row-main { min-width: 0; flex: 1; }
.title { font-weight: 650; font-size: .93rem; overflow-wrap: anywhere; }
.meta { font-size: .78rem; color: var(--ink-soft); margin-top: 3px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }
a.row-link { display: block; color: inherit; font-weight: inherit; margin: -12px -16px; padding: 12px 16px; min-height: var(--tap); }
a.row-link:hover { text-decoration: none; background: color-mix(in srgb, var(--accent) 6%, transparent); }
a.row-link .chev { color: var(--ink-soft); font-size: 1.1rem; align-self: center; }

.status { display: inline-flex; align-items: baseline; gap: 5px; font-size: .74rem; font-weight: 700; border-radius: 12px; padding: 3px 9px; max-width: 100%; background: var(--off-bg); color: var(--off); }
.status::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: currentColor; transform: translateY(-1px); }
.status-on, .status-done, .status-scheduled { color: var(--ok); background: var(--gh-bg); }
.status-open, .status-in_progress, .status-review { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.status-blocked, .status-high { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.status-medium, .status-manual { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.status-protected { color: var(--protected); background: var(--protected-bg); }

.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progress > span { display: block; height: 100%; background: var(--demo-line); }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; min-height: 108px; }
.tile.is-demo { border: 1.5px dashed var(--demo-line); background: var(--demo-bg); }
.tile-label { font-size: .76rem; color: var(--ink-soft); font-weight: 600; }
.tile-value { font-size: 1.9rem; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: .74rem; color: var(--ink-soft); margin-top: auto; overflow-wrap: anywhere; }
.tile .src { align-self: flex-start; }

.notice { border-left: 4px solid var(--demo-line); background: var(--demo-bg); padding: 12px 14px; border-radius: 8px; font-size: .85rem; margin-top: 12px; }
.safeguards { display: grid; gap: 8px; font-size: .86rem; }
.safeguards p::before { content: "🔒 "; }
.empty { font-size: .86rem; color: var(--ink-soft); padding: 14px 16px; }

.foot { margin-top: 28px; color: var(--ink-soft); font-size: .76rem; display: grid; gap: 6px; }

/* Wider screens */
@media (min-width: 640px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .top h1 { font-size: 1.7rem; }
}
@media (min-width: 900px) {
  .tabs { position: sticky; top: 0; bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); padding-bottom: 0; }
  .tabs-inner { display: flex; gap: 4px; padding: 0 16px; }
  .tabs button { flex-direction: row; font-size: .9rem; min-height: 50px; padding: 0 14px; gap: 8px; }
  .tabs button[aria-selected="true"]::after { top: auto; bottom: 0; left: 10px; right: 10px; border-radius: 3px 3px 0 0; }
  .badge { position: static; }
  .wrap { padding-bottom: 40px; }
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; align-items: start; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Six tabs on a 320px phone (53px each): shrink the labels so none is clipped, whatever the font. */
@media (max-width: 359px) {
  .tabs button { font-size: .54rem; letter-spacing: -.02em; }
}

/* Customers tab (synthetic demo). Inputs are 16px so iOS Safari does not zoom on focus. */
.cd { padding-top: 6px; }
.cd-banner { border: 2px solid var(--demo-line); background: var(--demo-bg); color: var(--demo); border-radius: 10px; padding: 10px 12px; font-size: .78rem; display: grid; gap: 4px; margin-bottom: 10px; }
.cd-banner strong { font-size: .8rem; letter-spacing: .03em; }
.cd-alert { border-left: 4px solid var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--surface)); padding: 10px 12px; border-radius: 8px; font-size: .86rem; margin: 10px 0; }
.cd-alert.cd-storage { border-left-color: var(--warn); }
.cd-notice { border-left: 4px solid var(--ok); background: var(--gh-bg); color: var(--ink); padding: 8px 12px; border-radius: 8px; font-size: .84rem; margin: 8px 0; }
.cd-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 10px 0 6px; }
.cd-head h2, .cd-head h3 { margin: 0; overflow-wrap: anywhere; }
.cd h2:focus { outline: none; }
.cd-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-top: 12px; }
.cd-card h3 { font-size: 1rem; }
.cd-btn { appearance: none; font: inherit; font-size: .9rem; font-weight: 650; min-height: var(--tap); padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.cd-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { .cd-primary { color: #06161b; } }
.cd-secondary { border-color: var(--accent); color: var(--accent); }
.cd-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.cd-link { border: 0; background: none; color: var(--accent); padding: 0 4px; min-height: var(--tap); }
.cd-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.cd-searchbox { margin: 8px 0; }
.cd-searchbox input, .cd-field input, .cd-field textarea, .cd-field select { width: 100%; font: inherit; font-size: 16px; min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.cd-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cd-count { font-size: .78rem; color: var(--ink-soft); margin: 4px 2px 8px; }
.cd-list { list-style: none; margin: 8px 0 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.cd-card .cd-list { margin-top: 8px; }
.cd-list > li { padding: 10px 14px; border-top: 1px solid var(--line); }
.cd-list > li:first-child { border-top: 0; }
.cd-list > li:has(> .cd-row) { padding: 0; }
.cd-row { display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit; font: inherit; padding: 12px 14px; min-height: var(--tap); cursor: pointer; border-radius: 0; }
.cd-row-title { display: block; font-weight: 650; font-size: .95rem; overflow-wrap: anywhere; }
.cd-row-meta { display: block; font-size: .78rem; color: var(--ink-soft); margin-top: 2px; overflow-wrap: anywhere; }
.cd-note { font-size: .88rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.cd-empty { font-size: .86rem; color: var(--ink-soft); padding: 12px 2px; }
.cd-hint { font-size: .76rem; color: var(--ink-soft); margin: 4px 0; }
.cd-field { margin-top: 10px; display: grid; gap: 4px; }
.cd-field label { font-size: .82rem; font-weight: 650; }
.cd-field.cd-inline { grid-template-columns: 78px minmax(0, 1fr); align-items: center; }
.cd-dl { margin: 6px 0 0; display: grid; gap: 6px; }
.cd-kv { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; font-size: .88rem; }
.cd-kv dt { color: var(--ink-soft); font-weight: 650; }
.cd-kv dd { margin: 0; overflow-wrap: anywhere; }
.cd-status { display: inline-block; margin-top: 6px; font-size: .74rem; font-weight: 700; border-radius: 12px; padding: 3px 9px; background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
.cd-status[data-status="Closed – Lost"] { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.cd-status[data-status="Completed"], .cd-status[data-status="Accepted"] { background: var(--gh-bg); color: var(--ok); }
.cd-history { margin-top: 8px; font-size: .8rem; }
.cd-history summary { cursor: pointer; min-height: var(--tap); display: flex; align-items: center; font-weight: 650; color: var(--accent); }
.cd-history ol { margin: 4px 0 0; padding-left: 20px; overflow-wrap: anywhere; }
.cd-notes { margin: 8px 0 0; padding-left: 18px; font-size: .82rem; }
.cd-confirm, .cd-dup { border: 2px solid var(--bad); border-radius: 10px; padding: 12px 14px; margin: 10px 0; display: grid; gap: 10px; background: var(--surface); }
.cd-dup .cd-btn { width: 100%; }
.cd-foot { margin-top: 24px; }
