/* PressureStation — modernised dashboard.
   Light palette on :root, dark redefined under both prefers-color-scheme and an
   explicit [data-theme="dark"], so the toggle wins in either direction. */

:root {
  color-scheme: light;

  --bg:          #f4f6f9;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --border:      #e2e8f0;
  --border-firm: #cbd5e1;

  --text:        #0f172a;
  --text-dim:    #64748b;
  --text-faint:  #94a3b8;

  --accent:      #2563eb;
  --accent-soft: #dbeafe;

  --ok:         #15803d;
  --ok-bg:      #dcfce7;
  --full:       #0e7490;
  --full-bg:    #cffafe;
  --warn:       #b45309;
  --warn-bg:    #fef3c7;
  --crit:       #b91c1c;
  --crit-bg:    #fee2e2;
  --unknown:    #64748b;
  --unknown-bg: #f1f5f9;

  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:          #0b1120;
    --surface:     #131c2e;
    --surface-2:   #1a2437;
    --border:      #26324a;
    --border-firm: #35435f;
    --text:        #e8edf6;
    --text-dim:    #94a3b8;
    --text-faint:  #64748b;
    --accent:      #60a5fa;
    --accent-soft: #1e3a5f;
    --ok:         #4ade80;
    --ok-bg:      #14331f;
    --full:       #22d3ee;
    --full-bg:    #0c3440;
    --warn:       #fbbf24;
    --warn-bg:    #3b2c08;
    --crit:       #f87171;
    --crit-bg:    #3f1414;
    --unknown:    #94a3b8;
    --unknown-bg: #1e293b;
    --shadow:     0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:          #0b1120;
  --surface:     #131c2e;
  --surface-2:   #1a2437;
  --border:      #26324a;
  --border-firm: #35435f;
  --text:        #e8edf6;
  --text-dim:    #94a3b8;
  --text-faint:  #64748b;
  --accent:      #60a5fa;
  --accent-soft: #1e3a5f;
  --ok:         #4ade80;
  --ok-bg:      #14331f;
  --full:       #22d3ee;
  --full-bg:    #0c3440;
  --warn:       #fbbf24;
  --warn-bg:    #3b2c08;
  --crit:       #f87171;
  --crit-bg:    #3f1414;
  --unknown:    #94a3b8;
  --unknown-bg: #1e293b;
  --shadow:     0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

/* The .panel--empty / .panel--error / .detail rules below set `display`, and an
   author class rule beats the browser's own [hidden] { display: none }. Without
   this the empty state, the detail view and the error box all render at once. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- topbar -- */

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar__logo  { height: 30px; width: auto; border-radius: 4px; }
.topbar h1 {
  font-size: 1.0625rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__actions { display: flex; align-items: center; gap: 10px; }

.live {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px;
  font-size: .75rem; font-weight: 550;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.live__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  flex: none;
}
.live[data-state="live"]    .live__dot { background: var(--ok); animation: pulse 2.4s ease-in-out infinite; }
.live[data-state="loading"] .live__dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.live[data-state="error"]   .live__dot { background: var(--crit); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .25; }
}

.user { display: flex; align-items: center; gap: 8px; }
.user__name { font-size: .8125rem; color: var(--text-dim); }

/* -------------------------------------------------------------- controls -- */

.btn {
  font: inherit; font-size: .8125rem; font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-firm);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn--icon  { padding: 7px 10px; font-size: .9375rem; line-height: 1; }
.btn--quiet { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn--quiet:hover { background: var(--surface-2); color: var(--text); }

.input {
  width: 100%;
  font: inherit; font-size: .8125rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
}
.input::placeholder { color: var(--text-faint); }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.badge {
  font-size: .6875rem; font-weight: 600;
  padding: 4px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em;
}
.badge--muted { color: var(--text-dim); background: var(--unknown-bg); }

/* ---------------------------------------------------------------- layout -- */

.layout {
  display: grid;
  grid-template-columns: 274px minmax(0, 1fr);
  gap: 20px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  align-items: start;
}

/* --------------------------------------------------------------- sidebar -- */

.sidebar {
  position: sticky;
  top: calc(72px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.sidebar__head { padding: 12px; border-bottom: 1px solid var(--border); }
.sidebar__list { max-height: min(68vh, 760px); overflow-y: auto; padding: 6px; }

.group__label {
  padding: 10px 10px 5px;
  font-size: .6875rem; font-weight: 650;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint);
}

.device {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 10px;
  margin-bottom: 2px;
  font: inherit; text-align: left;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.device:hover { background: var(--surface-2); }
.device[aria-current="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.device__dot  { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.device__body { min-width: 0; flex: 1; }
.device__name { font-weight: 550; font-size: .8125rem; }
.device__sub  { font-size: .6875rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.device__offline { color: var(--text-faint); font-style: italic; }

/* ------------------------------------------------------------------ main -- */

.main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.panel--empty, .panel--error {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; min-height: 260px; color: var(--text-dim); text-align: center;
}
.panel--error { border-color: var(--crit); color: var(--crit); }

.panel__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 10px; flex-wrap: wrap;
}
.panel__head h3 { font-size: .9375rem; }
.panel__sub { font-weight: 400; font-size: .75rem; color: var(--text-dim); margin-left: 8px; }

.detail { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.detail__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.detail__head h2 { font-size: 1.25rem; }
.detail__meta { margin: 4px 0 0; font-size: .8125rem; color: var(--text-dim); }

.rangebar {
  display: flex; gap: 3px; padding: 3px; flex-wrap: wrap;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.rangebar button {
  font: inherit; font-size: .75rem; font-weight: 550;
  color: var(--text-dim); background: transparent;
  border: 0; border-radius: 6px; padding: 6px 11px; cursor: pointer; white-space: nowrap;
}
.rangebar button:hover { color: var(--text); }
.rangebar button[aria-pressed="true"] {
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}

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

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 15px 17px;
}
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 6px;
}
.card__head h3 { font-size: .8125rem; font-weight: 600; color: var(--text-dim); }
.card__value {
  margin: 0;
  font-size: 2.125rem; font-weight: 680; line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.card__unit  { font-size: .875rem; font-weight: 500; color: var(--text-dim); margin-left: 5px; }
.card__scale { margin: 7px 0 0; font-size: .6875rem; color: var(--text-faint); font-variant-numeric: tabular-nums; }

.pill {
  font-size: .6875rem; font-weight: 650;
  padding: 3px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em;
  color: var(--unknown); background: var(--unknown-bg);
}
.pill[data-status="full"]     { color: var(--full); background: var(--full-bg); }
.pill[data-status="ok"]       { color: var(--ok);   background: var(--ok-bg); }
.pill[data-status="warning"]  { color: var(--warn); background: var(--warn-bg); }
.pill[data-status="critical"] { color: var(--crit); background: var(--crit-bg); }

/* Threshold-position bar under each current value. */
.gauge {
  position: relative; height: 6px; margin-top: 12px;
  border-radius: 999px; background: var(--surface-2); overflow: hidden;
}
.gauge__fill {
  position: absolute; inset: 0 auto 0 0;
  border-radius: 999px; transition: width .35s ease;
}
.gauge__fill[data-status="full"]     { background: var(--full); }
.gauge__fill[data-status="ok"]       { background: var(--ok); }
.gauge__fill[data-status="warning"]  { background: var(--warn); }
.gauge__fill[data-status="critical"] { background: var(--crit); }
.gauge__fill[data-status="unknown"]  { background: var(--unknown); }
.gauge__tick { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--border-firm); }

/* ---------------------------------------------------------------- charts -- */

.chart { width: 100%; height: 340px; }

.chart__failed {
  display: flex; align-items: center; justify-content: center;
  height: 100%; padding: 20px; text-align: center;
  font-size: .8125rem; color: var(--crit);
  background: var(--crit-bg); border-radius: var(--radius-sm);
}

.note { margin: 0; font-size: .75rem; color: var(--text-faint); text-align: right; }
.placeholder { padding: 22px 14px; color: var(--text-faint); font-size: .8125rem; text-align: center; }

/* ------------------------------------------------------------ login page -- */

.login-wrap { min-height: 82vh; display: grid; place-items: center; padding: 24px; }
.login {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.login h1 { font-size: 1.125rem; margin-bottom: 4px; }
.login p.sub { margin: 0 0 20px; font-size: .8125rem; color: var(--text-dim); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .75rem; font-weight: 600; color: var(--text-dim); margin-bottom: 5px; }
.login .btn {
  width: 100%; padding: 10px;
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.login .btn:hover { filter: brightness(1.08); background: var(--accent); }
.form-error {
  margin: 0 0 14px; padding: 9px 12px;
  font-size: .8125rem; color: var(--crit);
  background: var(--crit-bg); border-radius: var(--radius-sm);
}

/* ------------------------------------------------------------ responsive -- */

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 14px; gap: 14px; }
  .sidebar { position: static; }
  .sidebar__list { max-height: 260px; }
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: .9375rem; }
  .chart { height: 290px; }
  .card__value { font-size: 1.75rem; }
}

@media (max-width: 480px) {
  .topbar__actions { width: 100%; justify-content: space-between; }
  .chart { height: 250px; }
  .detail__head { flex-direction: column; align-items: stretch; }
}

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