/* ---------- Theme tokens ---------- */

:root {
  --radius: 16px;
  --radius-sm: 11px;
  --gap: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  --bg: #eef1f6;
  --bg-accent: radial-gradient(120% 80% at 50% -20%, #cfe0ff 0%, #eef1f6 55%);
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --text: #10141b;
  --muted: #5d6a7d;
  --border: #dfe4ec;
  --accent: #2f6bff;
  --accent-text: #ffffff;
  --accent-soft: #e6efff;
  --good: #17a673;
  --warn: #d9822b;
  --bad: #d93848;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .07);
  --track: #e8ecf3;
}

html[data-theme="dark"] {
  --bg: #0b0f16;
  --bg-accent: radial-gradient(120% 80% at 50% -20%, #16305c 0%, #0b0f16 60%);
  --surface: #141a24;
  --surface-2: #1b2331;
  --text: #e8edf5;
  --muted: #93a1b5;
  --border: #232d3d;
  --accent: #4d86ff;
  --accent-text: #ffffff;
  --accent-soft: #1c2b47;
  --good: #2ed39a;
  --warn: #f0a05a;
  --bad: #ff6b78;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  --track: #0f141d;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-accent);
  background-attachment: fixed;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.view[hidden] { display: none; }

.view {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 14px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

h1, h2 { margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--bad); font-size: .9rem; margin: 0; }

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.panel-title {
  font-size: .78rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head .panel-title { margin-bottom: 0; }

.panel > .panel-title { margin-bottom: 12px; }

.panel, .status-card { animation: rise .35s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Login ---------- */

#login-view { justify-content: center; }

.login-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px 20px;
}

.login-brand { text-align: center; display: grid; justify-items: center; gap: 6px; margin-bottom: 6px; }
.login-brand h1 { font-size: 1.4rem; }
.login-brand p { margin: 0; font-size: .92rem; }

.logo {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  border-radius: 15px;
  color: var(--accent-text);
  background: linear-gradient(140deg, var(--accent), #7b5cff);
  box-shadow: var(--shadow);
}
.logo svg { width: 28px; height: 28px; }
.logo.sm { width: 34px; height: 34px; border-radius: 11px; }
.logo.sm svg { width: 19px; height: 19px; }

.field { display: grid; gap: 6px; font-size: .86rem; font-weight: 600; }
.field span { color: var(--muted); }

input, .select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}

input:focus-visible, .select:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .seg-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 620;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 14px;
  cursor: pointer;
  transition: transform .06s, background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.primary {
  background: linear-gradient(140deg, var(--accent), #6d5cff);
  border-color: transparent;
  color: var(--accent-text);
}
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: progress; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.icon-btn svg { width: 19px; height: 19px; }
html[data-theme="dark"] .ico-moon { display: none; }
html[data-theme="light"] .ico-sun { display: none; }

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { display: grid; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: .95rem; }
.brand-text span { font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
#device-select { width: auto; padding: 9px 10px; font-size: .84rem; border-radius: 11px; }

/* ---------- Status ---------- */

.status-row { display: flex; align-items: center; gap: 12px; }
.status-text { display: grid; min-width: 0; flex: 1; }
.status-text strong { font-size: 1.05rem; }
.status-text strong.offline {
  color: var(--bad);
  font-weight: 750;
  letter-spacing: .14em;
}
.status-text span { font-size: .8rem; }

.dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--muted);
  flex: none;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--muted) 22%, transparent);
}
.dot.on   { background: var(--good); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 22%, transparent); }
.dot.boost{ background: var(--warn); box-shadow: 0 0 0 4px color-mix(in srgb, var(--warn) 25%, transparent); animation: pulse 1.6s ease-in-out infinite; }
.dot.off  { background: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 22%, transparent); }

@keyframes pulse { 50% { opacity: .45; } }

.pill {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 9px;
  flex: none;
}

/* ---------- Segmented control ---------- */

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: var(--track);
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 4px;
}

.seg-btn {
  font: inherit;
  font-weight: 640;
  display: grid;
  gap: 1px;
  justify-items: center;
  padding: 9px 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .18s, color .18s, transform .06s;
}
.seg-btn small { font-size: .66rem; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; opacity: .85; }
.seg-btn:hover { color: var(--text); }
.seg-btn:active { transform: scale(.97); }
.seg-btn[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.seg-btn[aria-pressed="true"] small { color: var(--accent); opacity: 1; }
.seg-btn:disabled { opacity: .5; cursor: progress; }

/* ---------- Boost ---------- */

.boost-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}
.btn.boost[aria-pressed="true"] {
  background: color-mix(in srgb, var(--warn) 20%, var(--surface-2));
  border-color: var(--warn);
  color: color-mix(in srgb, var(--warn) 70%, var(--text));
}
#boost-remaining { font-family: var(--mono); font-size: .82rem; }
#boost-remaining.active { color: var(--warn); font-weight: 650; }

/* ---------- Metrics ---------- */

#metrics { display: grid; gap: 14px; }

.metric-group { display: grid; gap: 8px; }
.metric-group > .panel-title { padding-left: 2px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 11px 13px;
  display: grid;
  gap: 2px;
  min-width: 0;
}
.metric .k {
  font-size: .71rem;
  color: var(--muted);
  letter-spacing: .02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.metric .v {
  font-family: var(--mono);
  font-size: 1.45rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.metric .v.blank { color: var(--muted); opacity: .5; }
.metric .v u {
  font-size: .74rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--muted);
  margin-left: 3px;
}
.foot { text-align: center; font-size: .74rem; margin: 4px 0 0; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--bad);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 11px 14px;
  font-size: .88rem;
  z-index: 10;
}

/* ---------- Larger screens ---------- */

@media (min-width: 700px) {
  .view { max-width: 760px; gap: 16px; }
  .metric-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
  .metric .v { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
