/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: rgba(42, 120, 214, 0.10);

  /* capacity bar: one blue ramp, strongest = grid connected, faintest = balance */
  --bar-grid: #1c5cab;
  --bar-feas: #3987e5;
  --bar-bal: #86b6ef;

  /* status (reserved) */
  --st-good: #0ca30c;
  --st-good-text: #006300;
  --st-warn: #fab219;
  --st-crit: #d03b3b;
  --st-crit-text: #b52f2f;
  --st-warn-text: #8a5a00;

  /* status washes: card background + border tint per state */
  --wash-good: #eaf7ea;
  --wash-warn: #fff6e0;
  --wash-crit: #fdeaea;
  --edge-good: rgba(12, 163, 12, 0.35);
  --edge-warn: rgba(250, 178, 25, 0.45);
  --edge-crit: rgba(208, 59, 59, 0.35);

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px -12px rgba(11, 11, 11, 0.12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --bar-grid: #6da7ec;
    --bar-feas: #2a78d6;
    --bar-bal: #184f95;
    --st-good-text: #0ca30c;
    --st-crit: #e66767;
    --st-crit-text: #e66767;
    --st-warn-text: #fab219;
    --wash-good: #16261a;
    --wash-warn: #2a2415;
    --wash-crit: #2c1a1a;
    --edge-good: rgba(12, 163, 12, 0.45);
    --edge-warn: rgba(250, 178, 25, 0.45);
    --edge-crit: rgba(230, 103, 103, 0.45);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.6);
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--plane);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 16px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.page > * { min-width: 0; }
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: grid;
  gap: 18px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- masthead ---------- */
.masthead { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px 24px; }
.brand { display: flex; gap: 12px; align-items: flex-start; }
.brand-mark { color: var(--accent); flex: none; margin-top: 2px; }
.brand h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
.tagline { color: var(--ink-2); font-size: 0.9rem; }
.office { text-align: right; font-size: 0.9rem; display: grid; gap: 2px; }
.office-name { font-weight: 600; }
.office-phone { color: var(--ink-2); text-decoration: none; }
.office-phone:hover { text-decoration: underline; }

/* ---------- controls ---------- */
.controls {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(180px, 1.6fr) minmax(130px, 0.8fr) auto;
  gap: 12px 14px;
  align-items: end;
}
.field { display: grid; gap: 5px; min-width: 0; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
.select-wrap { position: relative; }
.select-wrap::after {
  content: ""; position: absolute; right: 12px; top: 50%; width: 8px; height: 8px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
select, .input-unit input, .search-wrap input {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  appearance: none; -webkit-appearance: none;
}
select { padding-right: 32px; text-overflow: ellipsis; }
select:disabled { color: var(--muted); }
.input-unit { position: relative; }
.input-unit input { padding-right: 40px; }
.input-unit .unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.85rem; pointer-events: none; }
.actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 42px; padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform 0.08s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-sm { min-height: 34px; padding: 4px 10px; font-size: 0.85rem; }
.icon { width: 18px; height: 18px; flex: none; }
.is-loading #refresh .icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- hero ---------- */
.hero { padding: 20px 22px; display: grid; gap: 18px; position: relative; overflow: hidden; min-width: 0; }
.hero-body > * { min-width: 0; }
.hero::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--muted);
}
.hero[data-status="available"]::before { background: var(--st-good); }
.hero[data-status="low"]::before { background: var(--st-warn); }
.hero[data-status="full"]::before { background: var(--st-crit); }
.hero[data-status="available"] { background: var(--wash-good); border-color: var(--edge-good); }
.hero[data-status="low"]       { background: var(--wash-warn); border-color: var(--edge-warn); }
.hero[data-status="full"]      { background: var(--wash-crit); border-color: var(--edge-crit); }
.hero[data-status="available"] .hero-value .num { color: var(--st-good-text); }
.hero[data-status="low"] .hero-value .num       { color: var(--st-warn-text); }
.hero[data-status="full"] .hero-value .num      { color: var(--st-crit-text); }
.hero[data-status] .bar { background: rgba(127, 127, 127, 0.12); }
.eyebrow { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.hero-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hero-name { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; margin-top: 2px; }
.hero-feeder { color: var(--ink-2); font-size: 0.9rem; }
.hero-body { display: grid; grid-template-columns: minmax(200px, 0.9fr) minmax(240px, 1.4fr); gap: 20px 32px; align-items: center; }
.hero-figure { display: grid; gap: 2px; }
.hero-value { display: flex; align-items: baseline; gap: 6px; }
.hero-value .num { font-size: clamp(44px, 9vw, 64px); font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.hero-value .unit { font-size: 1.1rem; color: var(--ink-2); font-weight: 600; }
.hero-sub { color: var(--ink-2); }
.verdict { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-weight: 600; }
.verdict[data-status="available"] { color: var(--st-good-text); }
.verdict[data-status="low"] { color: var(--st-warn-text); }
.verdict[data-status="full"] { color: var(--st-crit-text); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
[data-status="available"] > .dot, .pill[data-status="available"] .dot { background: var(--st-good); }
[data-status="low"] > .dot { background: var(--st-warn); }
[data-status="full"] > .dot { background: var(--st-crit); }

.hero-bar { display: grid; gap: 10px; }
.bar {
  display: flex; gap: 2px; height: 22px;
  background: var(--surface-2);
  border-radius: 6px; overflow: hidden;
}
.bar .seg { display: block; height: 100%; transition: width 0.4s ease; min-width: 0; }
.bar .seg[hidden] { display: none; }
.seg-grid { background: var(--bar-grid); }
.seg-feas { background: var(--bar-feas); }
.seg-bal { background: var(--bar-bal); }
.bar-sm { height: 8px; border-radius: 4px; margin: 10px 0 12px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 0.88rem; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 7px; }
.legend b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.sw-grid { background: var(--bar-grid); }
.sw-feas { background: var(--bar-feas); }
.sw-bal { background: var(--bar-bal); }
.hero-cap { color: var(--ink-2); font-size: 0.88rem; }
.hero-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; font-size: 0.82rem; color: var(--muted); border-top: 1px solid var(--hairline); padding-top: 12px; }
.hero-empty, .error { gap: 6px; }
.hero-note, .error-msg { color: var(--ink-2); }
.error::before { background: var(--st-crit); }
.error-title { font-size: 1.2rem; font-weight: 700; }
.error-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); display: grid; gap: 2px; }
.stat-label { font-size: 0.8rem; color: var(--ink-2); font-weight: 600; }
.stat-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.stat-hint { font-size: 0.8rem; color: var(--muted); }
.stat[data-status="available"] .stat-value { color: var(--st-good-text); }
.stat[data-status="full"] .stat-value { color: var(--st-crit-text); }

/* ---------- list ---------- */
.list-section { display: grid; gap: 14px; }
.list-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 16px; }
.list-toolbar h2 { font-size: 1.1rem; font-weight: 700; }
.count { color: var(--muted); font-weight: 500; font-size: 0.9rem; margin-left: 6px; }
.list-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.search-wrap { position: relative; min-width: 200px; }
.search-wrap .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-wrap input { padding-left: 34px; min-height: 38px; }
.select-sm select { min-height: 38px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 0.92rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 36px; height: 20px; border-radius: 10px; background: var(--hairline); position: relative; transition: background 0.15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform 0.15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.feeder-head { grid-column: 1 / -1; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-top: 8px; }
.card {
  min-width: 0;
  padding: 14px 16px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  display: grid; align-content: start;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.card:hover { transform: translateY(-1px); }
.card { border-left-width: 5px; }
.card[data-status="available"] { background: var(--wash-good); border-color: var(--edge-good); border-left-color: var(--st-good); }
.card[data-status="low"]       { background: var(--wash-warn); border-color: var(--edge-warn); border-left-color: var(--st-warn); }
.card[data-status="full"]      { background: var(--wash-crit); border-color: var(--edge-crit); border-left-color: var(--st-crit); }
.card[data-status="available"] .card-value .num { color: var(--st-good-text); }
.card[data-status="low"] .card-value .num       { color: var(--st-warn-text); }
.card[data-status="full"] .card-value .num      { color: var(--st-crit-text); }
.card[data-status="low"] .pill { color: var(--st-warn-text); }
.card[data-status] .pill, .card[data-status] .bar { background: rgba(127, 127, 127, 0.12); }
.card.pinned { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; min-width: 0; }
.card-titles { min-width: 0; flex: 1 1 auto; overflow: hidden; }
.card-name { font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }
.card-feeder { font-size: 0.78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin {
  flex: none; width: 44px; height: 44px; margin: -8px -10px 0 0;
  border: none; background: transparent; border-radius: 50%; color: var(--muted); cursor: pointer;
  display: grid; place-items: center;
}
.pin svg { width: 20px; height: 20px; }
.pin:hover { background: var(--surface-2); color: var(--ink); }
.pin[aria-pressed="true"] { color: var(--accent); }
.pin[aria-pressed="true"] svg path { fill: currentColor; }
.card-value { display: flex; align-items: baseline; gap: 4px; margin-top: 8px; }
.card-value .num { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.card-value .unit { color: var(--ink-2); font-size: 0.85rem; font-weight: 600; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 0.78rem; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-weight: 600; font-size: 0.76rem; }
.pill .dot { width: 8px; height: 8px; }
.card[data-status="available"] .pill .dot { background: var(--st-good); }
.card[data-status="available"] .pill { color: var(--st-good-text); }
.card[data-status="low"] .pill .dot { background: var(--st-warn); }
.card[data-status="full"] .pill .dot { background: var(--st-crit); }
.card[data-status="full"] .pill { color: var(--st-crit-text); }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* ---------- about ---------- */
.about { padding: 20px 22px; display: grid; gap: 12px; color: var(--ink-2); font-size: 0.92rem; line-height: 1.55; }
.about h2 { font-size: 1.05rem; font-weight: 700; color: var(--ink); }
.about strong { color: var(--ink); }
.faq { margin: 0; display: grid; gap: 4px 0; }
.faq dt { font-weight: 600; color: var(--ink); margin-top: 8px; }
.faq dd { margin: 0; }

/* ---------- footer, toast ---------- */
.foot { color: var(--muted); font-size: 0.8rem; display: grid; gap: 6px; padding-top: 8px; border-top: 1px solid var(--hairline); }
.foot a { color: inherit; }
.disclaimer { padding: 10px 12px; border: 1px solid var(--hairline); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); font-size: 0.76rem; line-height: 1.5; }
.disclaimer strong { color: var(--ink-2); }
.credit { color: var(--ink-2); font-weight: 600; }
.credit a { color: var(--accent); text-decoration: none; }
.credit a:hover { text-decoration: underline; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--plane); padding: 10px 16px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600; box-shadow: var(--shadow); z-index: 20; max-width: calc(100vw - 32px);
  animation: rise 0.2s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- skeleton ---------- */
.sk {
  display: block; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--hairline) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.sk-eyebrow { width: 120px; height: 12px; }
.sk-title { width: 60%; height: 22px; margin-top: 8px; }
.sk-line { width: 80%; height: 12px; margin-top: 8px; }
.sk-line.short { width: 40%; }
.sk-big { width: 140px; height: 56px; margin-top: 6px; }
.sk-bar { width: 100%; height: 22px; margin-top: 6px; }
.stat.skeleton .sk-line, .stat.skeleton .sk-title { margin: 4px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .field-wide { grid-column: 1 / -1; }
  .actions { grid-column: 1 / -1; }
  .actions .btn { flex: 1; justify-content: center; }
}
@media (max-width: 560px) {
  .page { padding: 14px 16px 32px; gap: 14px; }
  .controls { grid-template-columns: 1fr; }
  .office { text-align: left; }
  .hero { padding: 18px 16px; }
  .hero-body { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr; }
  .search-wrap { min-width: 0; flex: 1 1 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
