:root {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #222220;
  --line: #2e2e2b;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --accent: #3987e5;
  --track: #1b2f4d;
  --good: #0ca30c;
  --warn: #fab219;
  --serious: #ec835a;
  --crit: #d03b3b;
  --warn-ink: #fab219;
  --crit-ink: #ef6b6b;
  --hatch: rgba(240, 239, 236, 0.14);
  --radius: 10px;
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f1f1ee;
    --surface: #fcfcfb;
    --surface-2: #f4f4f1;
    --line: #e2e1dc;
    --text: #0b0b0b;
    --text-2: #52514e;
    --text-3: #7a7974;
    --accent: #2a78d6;
    --track: #cde2fb;
    --warn-ink: #8a5a00;
    --crit-ink: #b42b2b;
    --hatch: rgba(11, 11, 11, 0.12);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

h1, h2, p { margin: 0; }

.app {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px 28px;
  display: grid;
  gap: 12px;
}

/* ---------- header ---------- */

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}

.brand {
  flex: 1 1 auto;
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand h1 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand-sub {
  color: var(--text-3);
  font-size: 12px;
}

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.btn[aria-pressed="true"] { background: transparent; color: var(--text); border-color: var(--line); }
.btn:disabled { cursor: not-allowed; opacity: 0.45; }

/* ---------- pills, dots, chips ---------- */

.pill, .act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-2);
}

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
}

.pill--live .dot, .act--active .dot { background: var(--good); }
.pill--pending .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--text-3); }
.pill--warn .dot, .act--attention .dot { background: var(--warn); }
.pill--error .dot { background: var(--crit); }
.pill--error { color: var(--text); border-color: var(--crit); }
.act--idle .dot { background: var(--text-3); }
.act--unknown .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--text-3); }
.act--active, .act--attention { color: var(--text); }

.pill--live .dot { animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.act-mark {
  font-size: 10px;
  padding: 0 4px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--text-3);
}

/* ---------- notices ---------- */

.notice {
  font-size: 12.5px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
}
.notice--warn { border-left: 3px solid var(--warn); }
.notice--pending { border-left: 3px solid var(--text-3); }
.notice--info { border-left: 3px solid var(--accent); }
.notice[hidden] { display: none; }

/* ---------- account cards ---------- */

.accounts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.card-title {
  font-size: 15px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.act-detail {
  margin-top: -6px;
  font-size: 11.5px;
  color: var(--text-3);
  min-height: 1.45em;
}

.wins {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.win {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.win-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
}
.win-name { flex: 1; }

.win-tag {
  font-size: 10.5px;
  font-weight: 600;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid currentColor;
}
.win-tag--warning { color: var(--warn-ink); }
.win-tag--critical { color: var(--crit-ink); }
.win-tag--stale { color: var(--text-3); }

.win-value {
  display: flex;
  align-items: baseline;
  gap: 2px;
  line-height: 1;
}
.num { font-size: 32px; font-weight: 650; letter-spacing: -0.02em; }
.num--muted { color: var(--text-3); font-weight: 500; }
.unit { font-size: 14px; color: var(--text-2); }
.win.is-stale .num { color: var(--text-2); }

.win-reset {
  font-size: 11.5px;
  color: var(--text-3);
  overflow-wrap: anywhere;
}
.win--reset .win-reset { color: var(--warn-ink); }

.quota-line {
  font-size: 11.5px;
  color: var(--text-3);
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.quota-line--stale, .quota-line--partial { color: var(--warn-ink); }
.quota-line--unavailable { color: var(--crit-ink); }

/* ---------- meters: one hue, same-ramp track; status colour only when low ---------- */

.meter {
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}

.meter-fill {
  display: block;
  height: 100%;
  width: calc(var(--pct, 0) * 1%);
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.4s ease;
}
.meter--warning .meter-fill { background: var(--warn); }
.meter--critical .meter-fill { background: var(--crit); }

/* Stale readings and reset-crossed windows carry a texture, not only a colour. */
.meter.is-stale .meter-fill {
  opacity: 0.55;
  background-image: repeating-linear-gradient(45deg, transparent 0 3px, var(--hatch) 3px 6px);
}
.meter--reset, .meter--unknown {
  background: var(--surface-2);
  background-image: repeating-linear-gradient(135deg, transparent 0 3px, var(--hatch) 3px 6px);
  box-shadow: inset 0 0 0 1px var(--line);
}

.empty {
  grid-column: 1 / -1;
  padding: 28px 16px;
  text-align: center;
  color: var(--text-3);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.foot {
  display: grid;
  gap: 4px;
  font-size: 11.5px;
  color: var(--text-3);
  padding: 0 2px;
}

/* ---------- compact floating panel (Document PiP) ---------- */

.pip-body {
  overflow: hidden;
  font-size: 12px;
}

.pip {
  display: grid;
  gap: 6px;
  padding: 8px 10px 10px;
  min-height: 100vh;
  align-content: start;
}

.pip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.pip-head .pill { padding: 1px 8px; font-size: 11px; }
.pip-note { font-size: 11px; color: var(--text-3); white-space: nowrap; }

.prow {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  display: grid;
  gap: 3px;
}

.prow-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.prow-name {
  font-weight: 650;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prow-head .act { font-size: 11.5px; margin-right: auto; }

.pflag {
  font-size: 10.5px;
  font-weight: 600;
  padding: 0 5px;
  border-radius: 4px;
  border: 1px solid currentColor;
  color: var(--warn-ink);
}
.pflag--unavailable { color: var(--crit-ink); }

.pwin {
  display: grid;
  grid-template-columns: 2.6em 3.2em minmax(40px, 1fr) auto;
  align-items: center;
  gap: 8px;
}
.pwin-name { color: var(--text-3); font-size: 11px; }
.pwin-value {
  font-weight: 650;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.pwin--reset .pwin-value, .pwin--unknown .pwin-value, .pwin.is-stale .pwin-value { color: var(--text-3); }
.pwin-tail {
  font-size: 11px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 4.2em;
  text-align: right;
}
.pwin--reset .pwin-tail { color: var(--warn-ink); }
.pwin .meter { height: 5px; }

/* ---------- small screens, motion, forced colours ---------- */

@media (max-width: 420px) {
  .app { padding: 12px 10px 20px; }
  .brand-sub { display: none; }
  .num { font-size: 26px; }
  .wins { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .meter-fill { transition: none; }
  .pill--live .dot { animation: none; }
}

@media (forced-colors: active) {
  .meter { border: 1px solid CanvasText; }
  .meter-fill { background: CanvasText; }
  .dot { border: 1px solid CanvasText; }
}
