/* Rildeno dashboard.
 *
 * The register is instrumentation: a panel someone glances at across a shed,
 * not a landing page. That means high contrast, tabular numerals, restrained
 * colour, and colour used only to mean something — a card is tinted because a
 * pond is in trouble, never for decoration.
 */

:root {
  --bg: #f4f6f7;
  --surface: #ffffff;
  --ink: #12181c;
  --ink-2: #4a5760;
  --ink-3: #7b8892;
  --line: #dfe4e7;
  --line-2: #eceff1;

  --normal: #1c7a63;
  --normal-bg: #e8f4f0;
  --risk: #a86a08;
  --risk-bg: #fdf3e2;
  --alert: #b4231f;
  --alert-bg: #fdeceb;

  --avg: #17607d;
  --band: rgba(23, 96, 125, .18);
  --thr: #b4231f;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,32,.05), 0 4px 14px rgba(16,24,32,.05);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1316;
    --surface: #161d21;
    --ink: #e8edef;
    --ink-2: #a3b0b8;
    --ink-3: #74838c;
    --line: #263138;
    --line-2: #1d262b;
    --normal: #4cc7a5;
    --normal-bg: #13302a;
    --risk: #e3a53f;
    --risk-bg: #33280f;
    --alert: #ff6b62;
    --alert-bg: #3a1614;
    --avg: #5ab6d8;
    --band: rgba(90,182,216,.20);
    --thr: #ff6b62;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}

/* --- chrome --------------------------------------------------------------- */

.topbar {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  padding: .9rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: baseline; gap: .7rem; min-width: 0; }
.wordmark {
  font-weight: 650; letter-spacing: .16em; font-size: .95rem;
}
.brand .sub { color: var(--ink-3); font-size: .85rem; white-space: nowrap; }
.topmeta { display: flex; align-items: center; gap: .55rem; }
.chip {
  font-size: .74rem; color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 100px; padding: .18rem .6rem;
  white-space: nowrap;
}
.chip-demo { color: var(--risk); border-color: color-mix(in srgb, var(--risk) 40%, var(--line)); }
.clock { font: 600 .78rem/1 var(--mono); color: var(--ink-3); }

.footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.4rem 1.25rem 2rem;
  color: var(--ink-3); font-size: .78rem; letter-spacing: .02em;
}
.linkish { background: none; border: 0; color: var(--ink-3); cursor: pointer; font-size: 1rem; }

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

.grid {
  display: grid; gap: 1rem;
  grid-template-columns: minmax(0, 1fr);
  padding: 1rem 1.25rem;
  max-width: 1500px; margin: 0 auto;
}
@media (min-width: 1080px) {
  .grid { grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
}
.col-main, .col-side { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.section-title {
  margin: 0 0 .75rem; font-size: .78rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
  display: flex; align-items: center; gap: .5rem;
}
.panel { padding: 1rem 1.1rem; }
.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-size: .82rem; }

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

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

.pond {
  padding: 1rem 1.1rem 0.9rem;
  border-left: 3px solid var(--normal);
  transition: background-color .5s ease, border-color .5s ease;
}
.pond-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; }
.pond-head h3 { margin: 0; font-size: 1.02rem; font-weight: 600; }
.state { display: inline-flex; align-items: center; gap: .4rem; font-size: .76rem; font-weight: 600; }
.dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; flex: none; }

.state-normal   { border-left-color: var(--normal); }
.state-normal   .state { color: var(--normal); }
.state-at_risk  { border-left-color: var(--risk); background: var(--risk-bg); }
.state-at_risk  .state { color: var(--risk); }
.state-alerting { border-left-color: var(--alert); background: var(--alert-bg); }
.state-alerting .state { color: var(--alert); }
.state-alerting .dot { animation: beat 1.6s ease-in-out infinite; }

/* Fires once, when a card actually changes state — the screen-share moment.
   Re-running it on every poll would turn a signal into wallpaper. */
.pond.just-changed { animation: land .9s cubic-bezier(.2,.8,.2,1); }
@keyframes land {
  0%   { transform: translateY(-3px) scale(1.012); box-shadow: 0 0 0 6px color-mix(in srgb, currentColor 18%, transparent); }
  100% { transform: none; box-shadow: var(--shadow); }
}
@keyframes beat { 0%,100% { opacity: 1; } 50% { opacity: .28; } }
@media (prefers-reduced-motion: reduce) {
  .pond.just-changed { animation: none; }
  .state-alerting .dot { animation: none; }
}

.readings {
  margin: .9rem 0 0; padding: 0;
  display: grid; gap: .55rem .9rem; grid-template-columns: repeat(2, minmax(0,1fr));
}
.reading { margin: 0; min-width: 0; }
.reading dt { color: var(--ink-3); font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; }
.reading dd { margin: .1rem 0 0; display: flex; align-items: baseline; gap: .2rem; }
.reading .v { font: 600 1.25rem/1.1 var(--mono); }
.reading .u { color: var(--ink-3); font-size: .78rem; }
.reading.primary .v { font-size: 1.7rem; }
.reading.primary { grid-column: span 2; }
@media (min-width: 420px) { .reading.primary { grid-column: span 1; } }

.pond-foot {
  margin: .9rem -1.1rem 0; padding: .55rem 1.1rem;
  border-top: 1px solid var(--line-2);
  color: var(--ink-3); font-size: .76rem;
}

/* --- alerts --------------------------------------------------------------- */

.badge {
  background: var(--alert); color: #fff; border-radius: 100px;
  font-size: .7rem; padding: .05rem .45rem; letter-spacing: 0;
}
.alertlist, .historylist { list-style: none; margin: 0; padding: 0; }
.alert {
  border-left: 3px solid var(--alert); background: var(--alert-bg);
  border-radius: 6px; padding: .65rem .8rem; margin-bottom: .55rem;
}
.alert .line { margin: 0; font-weight: 550; }
.alert .meta, .hist .meta {
  margin: .25rem 0 0; color: var(--ink-3); font-size: .76rem;
  display: flex; flex-wrap: wrap; gap: .35rem;
}
.calm { padding: .4rem 0 .2rem; }

.hist { padding: .55rem 0; border-top: 1px solid var(--line-2); }
.hist:first-child { border-top: 0; }
.hist .line { margin: 0; font-size: .88rem; color: var(--ink-2); }
.hist.open .line { color: var(--ink); font-weight: 550; }

.pill {
  font-size: .68rem; border-radius: 100px; padding: .05rem .45rem;
  border: 1px solid var(--line); color: var(--ink-3);
}
.pill-sent { color: var(--normal); border-color: color-mix(in srgb, var(--normal) 35%, var(--line)); }
.pill-dead { color: var(--alert); border-color: color-mix(in srgb, var(--alert) 35%, var(--line)); }

/* --- devices -------------------------------------------------------------- */

.devices { width: 100%; border-collapse: collapse; font-size: .84rem; }
.devices th {
  text-align: left; font-weight: 600; font-size: .68rem; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3); padding: 0 0 .4rem;
}
.devices td { padding: .38rem 0; border-top: 1px solid var(--line-2); }
.devices td:nth-child(2) { display: flex; align-items: center; gap: .4rem; }
.dev-online td:nth-child(2) { color: var(--normal); }
.dev-offline td:nth-child(2) { color: var(--alert); }

/* --- chart ---------------------------------------------------------------- */

.chartblock { padding: 1rem 1.1rem 1.1rem; }
.chart-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .6rem; }
.chart-head .section-title { margin-bottom: 0; }
.controls { display: flex; flex-wrap: wrap; gap: .4rem; }
select, .ranges button {
  font: inherit; font-size: .8rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 7px; padding: .28rem .55rem; cursor: pointer;
}
.ranges { display: inline-flex; }
.ranges button { border-radius: 0; margin-left: -1px; }
.ranges button:first-child { border-radius: 7px 0 0 7px; margin-left: 0; }
.ranges button:last-child { border-radius: 0 7px 7px 0; }
.ranges button.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chart { margin-top: .8rem; min-height: 260px; }
.legend { margin: .5rem 0 0; color: var(--ink-3); font-size: .74rem; display: flex; gap: .8rem; align-items: center; }
.key { width: .8rem; height: .5rem; border-radius: 2px; display: inline-block; margin-right: .3rem; vertical-align: middle; }
.key-avg { background: var(--avg); height: 2px; }
.key-band { background: var(--band); }
.key-thr { background: var(--thr); height: 0; border-top: 2px dashed var(--thr); }

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

.centered { display: grid; place-items: center; padding: 4rem 1.25rem; }
.login { padding: 1.5rem; width: min(360px, 100%); display: grid; gap: .55rem; }
.login h1 { margin: 0 0 .4rem; font-size: 1.1rem; }
.login label { font-size: .78rem; color: var(--ink-2); }
.login input {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 7px; background: var(--bg); color: var(--ink);
}
.login button {
  font: inherit; font-weight: 600; padding: .5rem; cursor: pointer;
  border: 0; border-radius: 7px; background: var(--ink); color: var(--surface);
}
.login .hint, .login .error { margin: .1rem 0 0; font-size: .76rem; }
.login .hint { color: var(--ink-3); }
.login .error { color: var(--alert); }

.skeleton-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(290px,1fr)); }
.skeleton { height: 168px; border-radius: var(--radius); background: var(--line-2); }
