/* Shared base for Cockpit and Home: tokens, reset, typography and the common components.
   A page links this file first, then its own stylesheet. A page may override only --accent and --accent-soft.
   System fonts only: no web fonts are loaded. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --serif: var(--display);  /* old name, kept so older rules keep working */

  --ground: #F2F2F7; --surface: #FFFFFF; --raised: #FFFFFF;
  --ink: #1C1C1E; --muted: #6E6E73;
  --line: rgba(60, 60, 67, .16);
  --fill: rgba(120, 120, 128, .12);      /* control track, tinted buttons */
  --inset: #F2F2F7;                      /* a card inside a card */
  --edge: transparent;                   /* card border: none in light (the shadow does it), a hairline in dark */
  --accent: #2F55D4; --accent-soft: #E6ECFC;
  --on-accent: #FFFFFF;                  /* text on a filled accent button */
  --on-prio: #FFFFFF;                    /* text on a filled P1/P2 badge */
  --p1: #C8332B; --p2: #D0731A; --p3: #2F6FB0; --p4: #7A8494;
  --good: #1F8A55; --good-bg: #E3F4EA;
  --bad: #B3261E; --bad-bg: #FBE7E5;
  --warn: #9A6200; --warn-bg: #FBF0DC;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 14px rgb(0 0 0 / .05);
  --shadow-hover: 0 2px 4px rgb(0 0 0 / .05), 0 8px 22px rgb(0 0 0 / .08);
  --shadow-lg: 0 10px 40px rgb(0 0 0 / .18);

  --r-card: 12px; --r-ctl: 10px; --r-pill: 999px;
  --ease: cubic-bezier(.2, .8, .2, 1); --dur: 180ms;
}
/* Dark: "none" is written as a zero shadow so it can be combined with a ring (box-shadow lists) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: #000000; --surface: #1C1C1E; --raised: #2C2C2E;
    --ink: #F2F2F7; --muted: #98989F;
    --line: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .24);
    --inset: #2C2C2E;
    --edge: rgba(84, 84, 88, .55);
    --accent: #8AA6FF; --accent-soft: #232E4A;
    --on-accent: #0B1020;
    --p1: #FF7A70; --p2: #F5A54F; --p3: #77AEF0; --p4: #8D97A7;
    --on-prio: #1C1C1E;
    --good: #5CCF92; --good-bg: #173326;
    --bad: #FF8A80; --bad-bg: #3A1D1B;
    --warn: #E8B04E; --warn-bg: #33291A;
    --shadow: 0 0 #0000; --shadow-hover: 0 0 #0000;
    --shadow-lg: 0 10px 40px rgb(0 0 0 / .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: #000000; --surface: #1C1C1E; --raised: #2C2C2E;
  --ink: #F2F2F7; --muted: #98989F;
  --line: rgba(84, 84, 88, .55);
  --fill: rgba(118, 118, 128, .24);
  --inset: #2C2C2E;
  --edge: rgba(84, 84, 88, .55);
  --accent: #8AA6FF; --accent-soft: #232E4A;
  --on-accent: #0B1020;
  --p1: #FF7A70; --p2: #F5A54F; --p3: #77AEF0; --p4: #8D97A7;
  --on-prio: #1C1C1E;
  --good: #5CCF92; --good-bg: #173326;
  --bad: #FF8A80; --bad-bg: #3A1D1B;
  --warn: #E8B04E; --warn-bg: #33291A;
  --shadow: 0 0 #0000; --shadow-hover: 0 0 #0000;
  --shadow-lg: 0 10px 40px rgb(0 0 0 / .6);
}

/* ---------- Reset and type ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }  /* the hidden attribute must win over components that set display */
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--ground); color: var(--ink);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  padding: 0 0 env(safe-area-inset-bottom, 0);
}
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

h1 { font: 700 clamp(28px, 4vw, 34px)/1.1 var(--display); letter-spacing: -0.02em; margin: 28px 0 4px; text-wrap: balance; }
h2 { font: 600 20px/1.25 var(--display); letter-spacing: -0.01em; margin: 32px 0 10px; }
h3 { font-size: 15px; font-weight: 600; }
.hint { font: 400 13px/1.3 var(--sans); letter-spacing: 0; color: var(--muted); margin-left: 6px; }
.hint.mono { font-family: var(--mono); }
.sub { color: var(--muted); font-size: 15px; margin: 0; }
.eyebrow { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Page frame: header bar, brand switch, nav ---------- */
.wrap { margin: 0 auto; padding-inline: max(clamp(16px, 2.5vw, 40px), env(safe-area-inset-left, 0px)) max(clamp(16px, 2.5vw, 40px), env(safe-area-inset-right, 0px)); padding-block: 0 64px; }
/* Sticks at the very top; the bar's own background fills the status-bar / Dynamic Island strip */
header.top {
  position: sticky; top: 0; z-index: 5;
  padding-top: env(safe-area-inset-top, 0px);
  background: color-mix(in srgb, var(--ground) 72%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  header.top { background: var(--ground); }
}
header.top .wrap { display: flex; align-items: center; gap: 16px; padding-block: 10px; flex-wrap: wrap; }
.brand { margin-right: auto; }
nav { display: flex; gap: 2px; flex-wrap: wrap; row-gap: 4px; }
nav a {
  color: var(--muted); font: 500 14px/1.3 var(--sans); padding: 6px 12px; border-radius: var(--r-pill);
  text-decoration: none; white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
nav a:hover { background: var(--fill); color: var(--ink); text-decoration: none; }
nav a[aria-current="page"] { background: var(--raised); color: var(--ink); box-shadow: 0 0 0 1px var(--edge), var(--shadow); }
.who { font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; }
/* Switch between the two pages (Cockpit, Home): a segmented control, the current one selected */
.appswitch { display: inline-flex; align-self: center; gap: 2px; padding: 2px; border-radius: var(--r-ctl); background: var(--fill); }
.appswitch a { font: 600 15px/1.3 var(--display); letter-spacing: -0.01em; text-decoration: none; color: var(--muted); padding: 4px 12px; border-radius: 8px; white-space: nowrap; transition: color var(--dur) var(--ease); }
.appswitch a:hover { color: var(--ink); text-decoration: none; }
.appswitch a[aria-current="page"] { background: var(--raised); color: var(--ink); box-shadow: 0 0 0 1px var(--edge), var(--shadow); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 500 14px/1.25 var(--sans); background: var(--accent); color: var(--on-accent);
  border: 0; border-radius: var(--r-ctl); padding: 8px 14px; cursor: pointer; white-space: nowrap;
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.btn:hover { filter: brightness(1.06); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; filter: none; transform: none; }
.btn.ghost { background: var(--fill); color: var(--ink); }
.btn.ghost[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.btn.bad, .btn.ghost.bad { color: var(--bad); }
.btn.bad:not(.ghost) { background: var(--bad-bg); }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; text-decoration: none; }
.linkbtn:hover { text-decoration: underline; }
.linkbtn:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.linkbtn.lg { font-size: 14px; }
/* Small action on a card */
.qa {
  font: 500 12.5px/1.3 var(--sans); padding: 4px 10px; border-radius: 8px; border: 0;
  background: var(--fill); color: var(--ink); cursor: pointer;
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease), background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.qa:hover { filter: brightness(.97); }
.qa:active { transform: scale(.97); }
.qa.ok { color: var(--good); background: var(--good-bg); }
.qa.bad { color: var(--bad); background: var(--bad-bg); }
.qa.bad.arm, .btn.bad.arm, .btn.ghost.bad.arm { color: var(--on-prio); background: var(--bad); }  /* second tap of a two-tap confirm */

/* ---------- Segmented controls and chips ---------- */
.chips, .viewswitch, .seg { display: inline-flex; align-items: center; gap: 2px; padding: 2px; background: var(--fill); border-radius: var(--r-ctl); max-width: 100%; }
.chips button, .viewswitch button {
  font: 500 13px/1.3 var(--sans); color: var(--ink); background: transparent; border: 0;
  border-radius: 8px; padding: 5px 12px; cursor: pointer; white-space: nowrap;
  transition: background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.chips button[aria-pressed="true"], .viewswitch button[aria-pressed="true"] { background: var(--raised); box-shadow: 0 0 0 1px var(--edge), var(--shadow); }
.chips .n { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 12px; margin-left: 5px; color: var(--muted); }
/* Priority picker: the checked segment takes its priority colour */
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; left: 0; top: 0; margin: 0; opacity: 0; pointer-events: none; }  /* anchored, or the hidden radios widen the form on a phone */
.seg span { display: inline-block; font: 600 13px/1.3 var(--mono); padding: 5px 14px; border-radius: 8px; color: var(--muted); transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease); }
.seg label:hover span { color: var(--ink); }
.seg input:checked + span { color: var(--on-prio); box-shadow: var(--shadow); }
.seg .p1 input:checked + span { background: var(--p1); }
.seg .p2 input:checked + span { background: var(--p2); }
.seg .p3 input:checked + span { background: var(--p3); }
.seg .p4 input:checked + span { background: var(--p4); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Inputs ---------- */
:where(input:not([type="checkbox"], [type="radio"], [type="file"], [type="range"], [type="color"]), select, textarea) {
  font: 14px/1.3 var(--sans); color: var(--ink); background-color: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-ctl); padding: 8px 11px; min-width: 0;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
:where(input:not([type="checkbox"], [type="radio"], [type="file"], [type="range"], [type="color"]), select, textarea):focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}
:where(select:not([multiple])) {
  -webkit-appearance: none; appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%238E8E93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
:where(input[type="search"]) {
  -webkit-appearance: none; appearance: none; padding-left: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Ccircle cx='7' cy='7' r='4.75' fill='none' stroke='%238E8E93' stroke-width='1.6'/%3E%3Cpath d='m10.5 10.5 3 3' stroke='%238E8E93' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 11px center;
}
:where(textarea) { resize: vertical; line-height: 1.45; }
:where(input[type="checkbox"], input[type="radio"]) { accent-color: var(--accent); }
::placeholder { color: var(--muted); opacity: .8; }

/* ---------- Pills ---------- */
.pill { display: inline-block; font: 500 11.5px/1.45 var(--sans); padding: 2px 8px; border-radius: var(--r-pill); white-space: nowrap; vertical-align: baseline; color: var(--muted); background: var(--fill); }
a.pill:hover { text-decoration: none; filter: brightness(.97); }

/* ---------- Cards and grouped lists ---------- */
.card { background: var(--surface); border: 1px solid var(--edge); border-radius: var(--r-card); box-shadow: var(--shadow); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; justify-content: space-between; align-items: baseline; }
.list li:last-child { border-bottom: 0; }
/* Inset grouped table */
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--edge); border-radius: var(--r-card); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font: 600 12px/1.3 var(--sans); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: baseline; }
th:first-child, td:first-child { padding-left: 16px; }
th:last-child, td:last-child { padding-right: 16px; }
tbody tr:last-child > td { border-bottom: 0; }
th.num, td.num { text-align: right; }
td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
tbody tr { transition: background-color var(--dur) var(--ease); }
@media (hover: hover) { .tablewrap tbody tr:hover { background: var(--fill); } }

/* ---------- Notice, skeleton ---------- */
.notice { margin-top: 20px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--edge); border-radius: var(--r-card); box-shadow: var(--shadow); color: var(--muted); }
.notice.err { color: var(--bad); background: var(--bad-bg); box-shadow: none; border-color: transparent; }
.skel { height: 74px; border-radius: var(--r-card); background: linear-gradient(90deg, var(--surface) 0%, var(--fill) 50%, var(--surface) 100%); background-size: 200% 100%; animation: skel 1.4s linear infinite; }
@keyframes skel { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- Tabs: a scrollable strip of pills ---------- */
.tabs { display: flex; gap: 4px; margin-top: 26px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .tabs a {
  display: inline-flex; align-items: center; font: 500 14px/1.3 var(--sans); color: var(--muted);
  background: none; border: 0; border-radius: var(--r-pill); padding: 7px 14px; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tabs button:hover, .tabs a:hover { color: var(--ink); background: var(--fill); text-decoration: none; }
.tabs [aria-selected="true"], .tabs [aria-selected="true"]:hover { color: var(--ink); background: var(--raised); box-shadow: 0 0 0 1px var(--edge), var(--shadow); }
.tabs .n { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 12px; margin-left: 6px; color: var(--muted); }

/* ---------- Dialog sheet ---------- */
dialog { border: 0; border-radius: 16px; padding: 18px 20px; background: var(--ground); color: var(--ink); box-shadow: var(--shadow-lg); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(0, 0, 0, .35); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog[open] { animation: sheet-in 200ms var(--ease); }
dialog[open]::backdrop { animation: fade-in 200ms var(--ease); }
@keyframes sheet-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 50;
  max-width: calc(100vw - 32px); padding: 10px 18px; border-radius: var(--r-pill);
  font: 500 14px/1.35 var(--sans); color: var(--ground);
  background: color-mix(in srgb, var(--ink) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
  animation: toast-in 220ms var(--ease);
}
#toast.bad { background: var(--bad); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Login ---------- */
.login {
  width: min(380px, calc(100% - 32px)); margin: calc(12vh + env(safe-area-inset-top, 0px)) auto 0;
  padding: 28px; display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--edge); border-radius: 16px; box-shadow: var(--shadow);
}
.login h1 { margin: 0 0 2px; }
.login .stack { display: grid; gap: 12px; }
.login label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.login input { width: 100%; font-size: 15px; background-color: var(--ground); }
.login .btn { width: 100%; padding-block: 10px; font-size: 15px; }
.login .notice { margin-top: 0; }

/* ---------- Touch, motion ---------- */
@media (pointer: coarse) {
  nav a { padding: 8px 12px; }
  .appswitch a { padding: 6px 13px; }
  .chips button, .viewswitch button { padding: 7px 13px; }
  .qa { padding: 7px 12px; font-size: 13px; }
  .btn { min-height: 40px; }
  .linkbtn { padding: 6px 0; }
  .tabs button, .tabs a { padding: 9px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
