/* TokenFlow dashboard. Two data colours only, used the same way everywhere:
   blue = the local lane, orange = the cloud lane. Text never wears them. */
:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --raised: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #73716c;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --local: #2a78d6;
  --cloud: #eb6834;
  --good: #0ca30c;
  --warn: #fab219;
  --bad: #d03b3b;
  --good-ink: #006300;
  --bad-ink: #a32222;
  --warn-ink: #7a5200;
  --focus: #256abf;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --raised: #222220;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #98968f;
    --line: #2c2c2a;
    --line-strong: #44443f;
    --local: #3987e5;
    --cloud: #d95926;
    --good-ink: #4cc24c;
    --bad-ink: #f08a8a;
    --warn-ink: #fab219;
    --focus: #86b6ef;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.skip { position: absolute; left: -9999px; top: 8px; background: var(--ink); color: var(--page); padding: 8px 12px; border-radius: 6px; z-index: 10; }
.skip:focus { left: 16px; }

main, .top, .banner { max-width: 1240px; margin-inline: auto; }
main { display: grid; gap: 20px; }

/* ---- header ---- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: calc(20px + env(safe-area-inset-top)) 0 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.mark { width: 36px; height: 36px; flex: none; }
.mark path { fill: none; stroke-width: 3.2; stroke-linecap: round; }
.mark-local { stroke: var(--local); }
.mark-cloud { stroke: var(--cloud); }
h1 { font-size: 22px; line-height: 1.1; letter-spacing: -0.02em; font-weight: 680; }
.tagline { color: var(--ink-2); font-size: 13px; margin-top: 2px; }
.conn { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.conn[data-state="live"] .dot { background: var(--good); }
.conn[data-state="lost"] .dot { background: var(--bad); }

.banner { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--line)); color: var(--ink); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 20px; font-size: 14px; }

/* ---- lanes ---- */
.lanes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.lane { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 6px; min-height: 104px; align-content: start; border-top: 3px solid var(--line-strong); }
.lane[data-lane="local"] { border-top-color: var(--local); }
.lane[data-lane="cloud"] { border-top-color: var(--cloud); }
.lane-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lane-name { font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.lane-model { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.lane-detail { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-tone="good"] { color: var(--good-ink); } .status[data-tone="good"]::before { background: var(--good); }
.status[data-tone="busy"] { color: var(--ink); } .status[data-tone="busy"]::before { background: var(--ink); animation: pulse 1.4s ease-in-out infinite; }
.status[data-tone="warn"] { color: var(--warn-ink); } .status[data-tone="warn"]::before { background: var(--warn); border-radius: 2px; }
.status[data-tone="bad"] { color: var(--bad-ink); } .status[data-tone="bad"]::before { background: var(--bad); border-radius: 0; transform: rotate(45deg); }
.status[data-tone="off"] { color: var(--muted); }
@keyframes pulse { 50% { opacity: 0.25; } }

/* ---- buttons ---- */
button { cursor: pointer; }
.btn, .primary { min-height: 36px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--raised); font-size: 13px; font-weight: 600; }
.btn:hover { border-color: var(--ink-2); }
.primary { background: var(--ink); color: var(--page); border-color: var(--ink); min-height: 44px; padding: 10px 18px; font-size: 15px; width: 100%; }
.primary:hover { opacity: 0.88; }
.primary:disabled, .btn:disabled { opacity: 0.5; cursor: progress; }
.btn.danger { color: var(--bad-ink); }
.link { background: none; border: 0; padding: 6px 0; color: var(--ink-2); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; min-height: 32px; }
.link:hover { color: var(--ink); }
.icon { background: none; border: 0; width: 40px; height: 40px; border-radius: 8px; font-size: 16px; color: var(--ink-2); }
.icon:hover { background: var(--line); }

/* ---- KPI tiles ---- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-height: 128px; display: grid; align-content: start; gap: 4px; }
.tile-label { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.swatch.local { background: var(--local); } .swatch.cloud { background: var(--cloud); }
.tile-value { font-size: 34px; line-height: 1.1; font-weight: 650; letter-spacing: -0.03em; }
.tile-unit { font-size: 15px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; margin-left: 4px; }
.tile-note { font-size: 13px; color: var(--ink-2); }
.meter { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--cloud); border-radius: 3px; }
.meter.local > i { background: var(--local); }

/* ---- panels ---- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
h2 { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
h3.sub { font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); margin: 18px 0 8px; }
.hint { font-size: 13px; color: var(--ink-2); }
.columns { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.stack { display: grid; gap: 20px; min-width: 0; }
.empty { border: 1px dashed var(--line-strong); border-radius: 8px; padding: 18px; color: var(--ink-2); font-size: 14px; text-align: center; }
.empty strong { display: block; color: var(--ink); font-weight: 600; margin-bottom: 2px; }

/* ---- charts ---- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.chart { min-height: 170px; min-width: 0; }
.chart-title { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.chart-total { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; margin-bottom: 10px; }
.plot { position: relative; height: 96px; display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid var(--line-strong); }
.plot::before { content: ""; position: absolute; inset: 0 0 50% 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); pointer-events: none; }
.bar-slot { flex: 1; height: 100%; display: flex; align-items: flex-end; position: relative; min-width: 0; }
.bar-slot:hover, .bar-slot:focus-visible { background: color-mix(in srgb, var(--ink) 6%, transparent); outline: none; }
.bar { width: 100%; border-radius: 4px 4px 0 0; min-height: 0; }
.chart[data-series="local"] .bar { background: var(--local); }
.chart[data-series="cloud"] .bar { background: var(--cloud); }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.chart-empty { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.tip { position: fixed; z-index: 20; background: var(--ink); color: var(--page); font-size: 12px; line-height: 1.35; padding: 6px 9px; border-radius: 6px; pointer-events: none; max-width: 240px; white-space: nowrap; }
.table-wrap { margin-top: 16px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--ink-2); font-weight: 600; }

/* ---- sessions ---- */
.sessions { display: grid; gap: 12px; }
.session { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: var(--raised); display: grid; gap: 10px; min-height: 96px; }
.session[data-stalled="true"] { border-color: var(--warn); }
.session-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.session-name { font-weight: 650; font-size: 15px; overflow-wrap: anywhere; }
.session-meta { font-size: 12px; color: var(--ink-2); overflow-wrap: anywhere; }
.session-stats { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.session-stats b { color: var(--ink); font-weight: 650; }
.todo-progress { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-2); }
.todo-progress .meter { flex: 1; margin: 0; }
.todo-progress .meter > i { background: var(--ink-2); }
.next-label { font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.next li { display: grid; grid-template-columns: 18px 1fr; gap: 6px; font-size: 14px; padding: 3px 0; overflow-wrap: anywhere; }
.next li[data-status="in_progress"] { font-weight: 600; }
.next .glyph { color: var(--ink-2); text-align: center; }
.next .more { color: var(--ink-2); font-size: 13px; }
.flag { font-size: 13px; color: var(--warn-ink); font-weight: 600; }
.session-foot { display: flex; justify-content: flex-end; }

/* ---- tasks ---- */
.task { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 2px; min-height: 52px; }
button.task:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
.task:last-child { border-bottom: 0; }
.task-lane { width: 6px; align-self: stretch; border-radius: 3px; background: var(--line-strong); }
.task[data-target="local"] .task-lane { background: var(--local); }
.task[data-target="cloud"] .task-lane { background: var(--cloud); }
.task-title { display: block; font-size: 14px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-sub { display: block; font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-main { display: block; min-width: 0; overflow: hidden; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--ink-2); white-space: nowrap; }
.pill[data-tone="bad"] { color: var(--bad-ink); border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.pill[data-tone="good"] { color: var(--good-ink); border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.pill[data-tone="busy"] { color: var(--ink); border-color: var(--ink); }

/* ---- form ---- */
form#add { display: grid; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: grid; gap: 5px; min-width: 0; }
label { font-size: 13px; font-weight: 600; }
.optional { font-weight: 400; color: var(--ink-2); }
input[type="text"], select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--raised); font-size: 15px; }
textarea { resize: vertical; min-height: 84px; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--muted); }
[aria-invalid="true"] { border-color: var(--bad); }
.error { color: var(--bad-ink); font-size: 13px; font-weight: 550; }
.preview { font-size: 13px; color: var(--ink-2); min-height: 20px; display: flex; align-items: center; gap: 8px; }

/* ---- activity ---- */
.activity li { display: grid; grid-template-columns: 132px 76px 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.activity li:last-child { border-bottom: 0; }
.activity time { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.activity .kind { font-size: 12px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-2); padding-top: 2px; }
.activity .kind[data-kind="warning"], .activity .kind[data-kind="failed"] { color: var(--bad-ink); }
.activity .text { overflow-wrap: anywhere; }

/* ---- dialog ---- */
dialog { border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 0; width: min(760px, calc(100vw - 32px)); max-height: min(86vh, 900px); }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 10px 10px 18px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { overflow-wrap: anywhere; }
.dialog-body { padding: 16px 18px; overflow: auto; display: grid; gap: 12px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dialog-actions:empty { display: none; }
.facts { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 14px; }
.facts dt { color: var(--ink-2); } .facts dd { margin: 0; overflow-wrap: anywhere; }
pre.result { margin: 0; padding: 14px; background: var(--page); border: 1px solid var(--line); border-radius: 8px; font: 13px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- loading skeletons ---- */
.skeleton { position: relative; overflow: hidden; background: var(--surface); border-color: var(--line); }
.skeleton.line { height: 34px; border-radius: 6px; margin-bottom: 6px; display: block; }
.skeleton.task { display: block; border-radius: 6px; margin-bottom: 6px; }
.skeleton::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ink) 7%, transparent), transparent); animation: sweep 1.3s linear infinite; }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skeleton::after, .status[data-tone="busy"]::before { animation: none; } }

/* ---- tablet ---- */
@media (max-width: 1020px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .columns { grid-template-columns: minmax(0, 1fr); }
}
/* ---- phone ---- */
@media (max-width: 640px) {
  .lanes { grid-template-columns: minmax(0, 1fr); }
  .lane { min-height: 0; }
  .charts { grid-template-columns: minmax(0, 1fr); }
  .tile { min-height: 0; }
  .tile-value { font-size: 28px; }
  .panel { padding: 14px; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .activity li { grid-template-columns: 1fr auto; gap: 2px 10px; }
  .activity .text { grid-column: 1 / -1; }
  .activity .kind { text-align: right; }
  .btn { min-height: 44px; }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 8px; }
}
@media (max-width: 380px) { .kpis { grid-template-columns: minmax(0, 1fr); } }

/* ---- sign-in page and remote view ---- */
.login-page { display: grid; min-height: 100dvh; place-items: center; padding-top: env(safe-area-inset-top); }
.login { display: grid; gap: 24px; width: min(380px, 100%); margin: 0; max-width: none; }
.login form { display: grid; gap: 16px; }
.access { display: inline-flex; align-items: center; gap: 12px; }
.badge { font-size: 12px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line-strong); color: var(--ink-2); }
body[data-readonly="true"] [data-write] { display: none !important; }

/* ---- live session indicator ---- */
.session[data-live="true"] { border-color: var(--cloud); box-shadow: inset 3px 0 0 var(--cloud); }
.live { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 650; white-space: nowrap; color: var(--ink); }
.live-word { letter-spacing: 0.06em; text-transform: uppercase; font-size: 12px; }
.live-time { font-family: var(--mono); font-weight: 500; color: var(--ink-2); min-width: 4ch; text-align: right; }
.live-line { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.eq i { width: 3px; height: 100%; border-radius: 1.5px; background: var(--cloud); transform-origin: bottom; animation: eq 0.9s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -0.3s; }
.eq i:nth-child(3) { animation-delay: -0.6s; }
@keyframes eq { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }
@media (prefers-reduced-motion: reduce) { .eq i { animation: none; transform: scaleY(0.7); } .eq i:nth-child(2) { transform: scaleY(1); } }
