/* Shared design system for Material Counting pages.
   Source: phone_streaming/for_ref/design.md ("dark operations console").
   Tokens, fonts and components only; each page keeps its own layout CSS. */

/* ---------- Fonts (self-hosted, SIL OFL, see /static/fonts/OFL.txt) ---------- */
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-display: swap; font-weight: 400;
  src: url(/static/fonts/ibm-plex-sans-thai-thai-400-normal.woff2) format("woff2");
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-display: swap; font-weight: 500;
  src: url(/static/fonts/ibm-plex-sans-thai-thai-500-normal.woff2) format("woff2");
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-display: swap; font-weight: 600;
  src: url(/static/fonts/ibm-plex-sans-thai-thai-600-normal.woff2) format("woff2");
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-display: swap; font-weight: 700;
  src: url(/static/fonts/ibm-plex-sans-thai-thai-700-normal.woff2) format("woff2");
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-display: swap; font-weight: 400;
  src: url(/static/fonts/ibm-plex-sans-thai-latin-400-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-display: swap; font-weight: 500;
  src: url(/static/fonts/ibm-plex-sans-thai-latin-500-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-display: swap; font-weight: 600;
  src: url(/static/fonts/ibm-plex-sans-thai-latin-600-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans Thai"; font-style: normal; font-display: swap; font-weight: 700;
  src: url(/static/fonts/ibm-plex-sans-thai-latin-700-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-display: swap; font-weight: 400;
  src: url(/static/fonts/ibm-plex-mono-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-display: swap; font-weight: 500;
  src: url(/static/fonts/ibm-plex-mono-latin-500-normal.woff2) format("woff2"); }

/* ---------- Tokens (design.md §2, dark only) ---------- */
:root {
  --accent: #2fbf71;
  --accent-ink: #0b0d10;
  --accent-soft: rgba(47, 191, 113, 0.16);
  --data: #9085e9;
  --data-rgb: 144, 133, 233;

  --bg: #0b0d10;
  --bg-raised: #0e1115;
  --surface: #12161c;
  --surface-2: #0f1318;
  --surface-3: #151a21;
  --hover: #1a1f27;
  --border: #222831;
  --border-strong: #2a313b;
  --divider: #1c2129;

  --text: #e7eaee;
  --text-2: #c6ccd4;
  --text-muted: #9aa4b0;
  --text-faint: #7d8692;

  --ok: #3ecf8e;    --ok-bg: #16221d;    --ok-text: #8fdcb6;
  --alarm: #ff5a55; --alarm-bg: #1d1214; --alarm-border: #5a2a2d; --alarm-text: #ffb3b0; --alarm-solid: #c9302c;
  --warn: #f5a524;  --warn-bg: #221b10;  --warn-text: #f8c978;  --warn-border: #5a4420;
  --info-text: #9cc0ff;

  --radius: 12px;
  --radius-sm: 8px;
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  /* logo parts (MatCount AI): material in, the AI network, the counted piece */
  --mk-in: #c6ccd4; --mk-net: #9085e9; --mk-out: #2fbf71;
  --header-h: 60px;
  --tabbar-h: 64px;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
a { color: var(--info-text); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Icons (single sprite, stroke 1.8, currentColor) ---------- */
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 28px; height: 28px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface-3); color: var(--text);
  font: 500 14px/1 var(--font); cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  text-decoration: none; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { background: transparent; border-color: var(--alarm-border); color: var(--alarm-text); }
.btn-danger:hover { background: var(--alarm-bg); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { height: 32px; font-size: 13px; border-radius: 8px; padding: 0 12px; }
.btn-icon { width: 40px; padding: 0; }
.btn-sm.btn-icon { width: 32px; }
@media (pointer: coarse) {
  .btn { height: 44px; }
  .btn-icon { width: 44px; }
  .btn-sm { height: 40px; }
  .btn-sm.btn-icon { width: 40px; }
}

/* Segmented control */
.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; }
.seg button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 64px; height: 34px;
  padding: 0 14px; border: 0; border-radius: 999px; background: transparent; color: var(--text-muted);
  font: 500 14px/1 var(--font); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg button:disabled { opacity: 0.5; cursor: not-allowed; }
@media (pointer: coarse) { .seg button { height: 40px; } }

/* ---------- Cards, KPI ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head .end { margin-left: auto; display: flex; gap: 8px; }
.card-body { padding: 16px; }
.inset { background: var(--surface-2); border-radius: 10px; }
.kpi-label { font-size: 13px; color: var(--text-muted); }
.kpi-value { font: 500 30px/1.1 var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.kpi-note { font-size: 13px; color: var(--text-faint); }

/* ---------- Status ---------- */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #5b6470; flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.alarm { background: var(--alarm); }
.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500; background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border-strong);
  white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.badge.alarm { background: var(--alarm-bg); color: var(--alarm-text); border-color: var(--alarm-border); }
.badge.solid-alarm { background: var(--alarm-solid); color: #fff; border-color: transparent; }
.banner { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text-2); font-size: 14px; }
.banner .icon { margin-top: 3px; }
.banner b { color: var(--text); font-weight: 600; }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
.banner.warn .icon { color: var(--warn); }
.banner.alarm { background: var(--alarm-bg); border-color: var(--alarm-border); color: var(--alarm-text); }
.banner.alarm .icon { color: var(--alarm); }
.banner.ok { background: var(--ok-bg); border-color: transparent; color: var(--ok-text); }
.banner.ok .icon { color: var(--ok); }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; color: var(--text-muted); }
.field .hint { font-size: 12px; color: var(--text-faint); }
.field .error { font-size: 12px; color: var(--alarm-text); }
.input { height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface-3); color: var(--text); font: 400 14px var(--font); width: 100%; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--alarm); }
@media (pointer: coarse) { .input { height: 44px; font-size: 16px; } }

/* ---------- Overlays ---------- */
.dialog { width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0; border: 1px solid var(--border-strong);
  border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.dialog::backdrop { background: rgba(5, 7, 9, 0.6); }
.dialog .card-head { position: sticky; top: 0; background: var(--surface); }
.dialog-body { padding: 20px; overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--divider); }
.toast-stack { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50;
  pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; background: #1a1f27;
  border: 1px solid var(--border-strong); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); font-size: 14px; pointer-events: auto; }
.toast.ok .icon { color: var(--ok); }
.toast.error .icon { color: var(--alarm); }

/* ---------- Loading ---------- */
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  /* a spinner says "still working"; a still one looks like a hang. iOS keeps its own spinners turning too. */
  .spinner { animation-duration: 0.9s !important; animation-iteration-count: infinite !important; }
}
