/* R1 static SPA shell — dark, minimalist, information-dense.
   Self-hosted only: no @import, no CDN, no build step. */

:root {
  --bg: #0B0D10;
  --surface: #15181D;
  --surface-2: #1B1F26;
  --border: #232830;
  --text: #E6E9EE;
  --text-dim: #9AA3B2;
  --accent: #5E9BFF;
  --ok: #3FB950;
  --warn: #D29922;
  --crit: #F85149;
  --muted: #6E7681;
  --radius: 8px;
  --sidebar-w: 240px;
  --gap: 16px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
  transition: top 0.12s ease;
}
.skip-link:focus { top: 8px; }

.shell { display: flex; min-height: 100vh; }

/* Sidebar ---------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__brand { padding: 0 12px 20px; border-bottom: 1px solid var(--border); }
.sidebar__logo {
  display: block;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.sidebar__brand-sub { color: var(--text-dim); font-size: 12px; }

.nav-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 2px; }
.nav-link {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--text-dim);
  text-decoration: none;
  border-left: 2px solid transparent;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active {
  background: var(--surface-2);
  color: var(--text);
  border-left-color: var(--accent);
  font-weight: 600;
}

.sidebar__footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.conn-dot--idle { background: var(--warn); }

.nav-toggle { display: none; }
.nav-backdrop { display: none; }

/* Workspace -------------------------------------------------------------- */
.workspace { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar__title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.topbar__meta { display: flex; align-items: center; gap: 12px; }
.live { display: inline-flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 12px; }
.live__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live--sse .live__dot { background: var(--ok); }
.live--polling .live__dot, .live--connecting .live__dot { background: var(--warn); }
.live__label { font-variant-numeric: tabular-nums; }

.main { padding: 24px; width: 100%; max-width: 1400px; }
.page-stack { display: grid; gap: var(--gap); }
.section-title { margin: 0; font-size: 16px; font-weight: 600; color: var(--text-dim); }

/* Components ------------------------------------------------------------- */
.empty, .notice, .metric, .error, .chart, .progress {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.empty { text-align: center; padding: 48px 16px; }
.empty__icon { font-size: 32px; color: var(--muted); line-height: 1; }
.empty__title { margin: 12px 0 4px; font-size: 16px; font-weight: 600; }
.empty__desc { margin: 0 auto; max-width: 46ch; color: var(--text-dim); }

.notice { display: grid; gap: 4px; border-left: 3px solid var(--muted); }
.notice__icon { color: var(--muted); font-weight: 700; }
.notice__text { color: var(--text-dim); }
.notice__hint, .notice__source { color: var(--muted); font-size: 12px; }
.notice--unsupported { border-left-color: var(--muted); }
.notice--unavailable { border-left-color: var(--muted); }
.notice--permission_required { border-left-color: var(--warn); }
.notice--stale { border-left-color: var(--warn); }
.notice--ok { border-left-color: var(--ok); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
}
.badge__icon { font-weight: 700; }
.badge--ok { color: var(--ok); }
.badge--warning, .badge--stale { color: var(--warn); }
.badge--critical { color: var(--crit); }
.badge--unsupported, .badge--unavailable, .badge--permission_required { color: var(--muted); }

.metric { display: grid; gap: 8px; }
.metric__label { margin: 0; font-size: 13px; color: var(--text-dim); font-weight: 500; }
.metric__value { margin: 0; display: flex; align-items: baseline; gap: 4px; }
.metric__num { font: 28px/1.2 var(--font-mono); font-variant-numeric: tabular-nums; }
.metric__unit { color: var(--text-dim); font-size: 13px; }
.metric__trend { font-size: 12px; color: var(--text-dim); }
.metric__spark { height: 24px; border-bottom: 1px dashed var(--border); }

.progress { display: grid; gap: 8px; }
.progress__head { color: var(--text-dim); font-size: 13px; }
.progress__track { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress__fill { height: 100%; width: 0; background: var(--accent); }
.progress__unavailable { color: var(--muted); font-size: 12px; }

.fresh, .stale { font-size: 12px; color: var(--text-dim); }
.stale { color: var(--warn); }

.error { display: grid; gap: 8px; border-left: 3px solid var(--crit); }
.error__title { margin: 0; font-size: 15px; }
.error__message { margin: 0; color: var(--text-dim); }
.error__rid { color: var(--muted); font-family: var(--font-mono); }
.btn {
  min-height: 36px;
  padding: 6px 14px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.6; cursor: wait; }
[hidden] { display: none !important; }

.login {
  width: min(100%, 380px);
  margin: min(12vh, 96px) auto 0;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.login h2 { margin: 0 0 4px; font-size: 20px; }
.login__hint { margin: 0 0 24px; color: var(--text-dim); }
.login__form { display: grid; gap: 10px; }
.login__form label { color: var(--text-dim); }
.login__form input {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.login__form .btn { margin-top: 10px; }
.login__error { margin: 0; color: var(--crit); }

.chart { margin: 0; }
.chart figcaption { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; }
.chart__note, .chart__data { color: var(--text-dim); font-size: 12px; }

.service-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.service-table caption { text-align: left; color: var(--text-dim); padding-bottom: 8px; }
.service-table th, .service-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.service-table th { color: var(--text-dim); font-weight: 500; }

.skeleton { display: grid; gap: 8px; }
.skeleton__block {
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-2), #232830, var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton--card .skeleton__block { height: 64px; }
.skeleton--chart .skeleton__block { height: 180px; }

@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.noscript { padding: 16px 24px; color: var(--warn); }

/* Responsive ------------------------------------------------------------- */
@media (max-width: 1100px) {
  .main { padding: 16px; }
  .metric-grid, .chart-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .nav-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 44px;
    height: 44px;
    padding: 10px;
    margin-right: 4px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
  }
  .nav-toggle__bar { display: block; height: 2px; background: var(--text); border-radius: 2px; }
  .topbar { padding: 8px 12px; }
  .topbar__title { font-size: 16px; }
  .sidebar {
    position: fixed;
    z-index: 20;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0);
  }
  .sidebar.is-open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.5); }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 15;
    background: transparent;
  }
  .nav-backdrop[hidden] { display: none; }
  .nav-link { min-height: 44px; }
  .main { padding: 12px; }
  .empty { padding: 32px 12px; }
  .service-table { display: block; overflow-x: auto; }
}

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

/* Dashboard layout ------------------------------------------------------- */
.dashboard { display: grid; gap: var(--gap); }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; padding-bottom: 4px;
}
.page-head__title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.page-head__subtitle { margin: 4px 0 0; color: var(--text-dim); font-size: 13px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--gap); }
.chart-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--gap); align-items: start; }
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; display: grid; gap: 12px;
}
.panel__title { margin: 0; font-size: 14px; font-weight: 600; color: var(--text); }
.panel__hint { margin: -6px 0 0; font-size: 12px; color: var(--muted); }
.panel .empty { padding: 24px 12px; }
.metric { min-height: 132px; }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .page-head { align-items: flex-start; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
}

.chart__legend { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 8px; font-size: 12px; color: var(--text-dim); }
.chart__legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart__legend-item::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

/* Single-view dashboard (no tab bar) ------------------------------------ */
.shell { display: block; }
.workspace { width: 100%; }
.main { max-width: 1600px; margin: 0 auto; }
.dashboard-stack { display: grid; gap: 24px; }
.dashboard-section { min-width: 0; }
.dashboard-section > .page-stack,
.dashboard-section > .dashboard { gap: var(--gap); }

.quota-card {
  display: grid; justify-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.quota-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.quota-card .metric__label { text-align: center; }
.quota-card .panel__hint { margin: 0; text-align: center; }
.quota-notices { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.quota-notices:empty { display: none; }
.quota-notices .notice { padding: 10px 12px; }
.quota-card .notice { width: 100%; }
.quota-card .notice__text { overflow-wrap: anywhere; }
.quota-ring { position: relative; width: 112px; height: 112px; }
.quota-ring__svg { width: 100%; height: 100%; }
.quota-ring__track { fill: none; stroke: var(--surface-2); stroke-width: 8; }
.quota-ring__progress {
  fill: none; stroke: var(--accent); stroke-width: 8; stroke-linecap: round;
  transition: stroke-dasharray 0.35s ease;
}
.quota-ring__value {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 24px/1 var(--font-mono); color: var(--text);
}
.quota-ring__value--missing { color: var(--muted); }


/* R3 — time range, hardware states, settings ----------------------------- */
.nav-link { justify-content: space-between; gap: 8px; }
.nav-link__note {
  flex: none;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.toolbar__hint { color: var(--muted); font-size: 12px; }
.range-picker { display: inline-flex; align-items: center; gap: 4px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.range-picker__label { padding: 0 8px; color: var(--text-dim); font-size: 12px; }
.range-picker__btn {
  min-height: 28px;
  min-width: 44px;
  padding: 4px 10px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.range-picker__btn:hover { color: var(--text); background: var(--surface-2); }
.range-picker__btn.is-active { color: var(--text); background: var(--surface-2); border-color: var(--accent); font-weight: 600; }

.page-head__actions { display: inline-flex; align-items: center; gap: 8px; }
.badge-row { display: flex; flex-wrap: wrap; gap: 8px; }
.inventory-slot, .power-slot, .settings-list { display: grid; gap: 12px; }
.hardware-list { display: grid; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.hardware-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(110px, auto) minmax(200px, 2fr);
  align-items: center;
  gap: 8px 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.hardware-row:last-child { border-bottom: 0; }
.hardware-row__name { font-weight: 500; }
.hardware-row__value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.hardware-row__detail { color: var(--text-dim); font-size: 12px; overflow-wrap: anywhere; }

.settings-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(160px, 2fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: 0; }
.settings__key { color: var(--text-dim); font-family: var(--font-mono); font-size: 12px; }
.settings__input {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.settings__input:focus-visible { border-color: var(--accent); }
.settings__status { color: var(--text-dim); font-size: 12px; min-width: 56px; }
.settings__status--error { color: var(--crit); }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; }
  .topbar__meta { flex-wrap: wrap; justify-content: flex-end; }
  .quota-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .settings-row { grid-template-columns: 1fr; }
  .hardware-row { grid-template-columns: minmax(0, 1fr) auto; }
  .hardware-row__detail { grid-column: 1 / -1; }
  .range-picker { max-width: 100%; overflow-x: auto; }
}
