/* app.css — components del panell, derivats de tokens.css. Disseny pla, sense ombres. */

/* Open Sans auto-allotjada: deixa els .woff2 a assets/fonts/ i descomenta.
   (Sense CDN.) Mentre no hi siguin, s'usa la pila de sistema com a fallback.
@font-face { font-family:"Open Sans"; font-weight:400; font-display:swap;
  src:url("../fonts/open-sans-400.woff2") format("woff2"); }
@font-face { font-family:"Open Sans"; font-weight:600; font-display:swap;
  src:url("../fonts/open-sans-600.woff2") format("woff2"); }
@font-face { font-family:"Open Sans"; font-weight:700; font-display:swap;
  src:url("../fonts/open-sans-700.woff2") format("woff2"); }
*/

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "Open Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }
.wrap { max-width: 1080px; margin: 0 auto; padding: 22px 20px 64px; }

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; margin-bottom: 22px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
}
.topbar .mark { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.topbar .mark .logo { height: 24px; width: auto; display: block; }
.topbar .sep, .topbar .crumb { color: var(--muted); }
.topbar .crumb a { color: var(--muted); text-decoration: none; }
.topbar .crumb a:hover { text-decoration: underline; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: 13px; }
.topbar .logout { color: var(--muted); font-size: 13px; text-decoration: none; }
.topbar .logout:hover { text-decoration: underline; }

/* ── Títols ──────────────────────────────────────────────── */
h1 { font-size: 24px; color: var(--brand-strong); margin: 0 0 4px; line-height: 1.2; }
h1 + .lead { color: var(--muted); margin: 0 0 20px; max-width: 60ch; }
.section-h { font-size: 12px; letter-spacing: .10em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; margin: 30px 0 12px; }

/* ── Targetes i graella ──────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px; }
.card.crit { border-left: 4px solid var(--crit-bg); }
.card-link { text-decoration: none; color: inherit; display: block; }
.card-link:hover { border-color: var(--sage); }

.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.house { font-weight: 700; font-size: 17px; color: var(--brand-strong); line-height: 1.2; }
.subid { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ── Lectura gran ────────────────────────────────────────── */
.reading { display: flex; align-items: baseline; gap: 8px; margin: 16px 0 4px; }
.reading .val { font-size: 44px; font-weight: 800; line-height: 1; color: var(--ink);
  font-variant-numeric: tabular-nums; }
.reading .unit { font-size: 19px; font-weight: 700; color: var(--muted); }
.stamp { color: var(--muted); font-size: 13px; }

.metrics { display: flex; flex-wrap: wrap; gap: 24px; margin-top: 18px;
  padding-top: 16px; border-top: 1px solid var(--line-soft); }
.metric .k { font-size: 12px; color: var(--muted); }
.metric .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Badges d'estat ──────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.badge.dot-only { padding: 4px; }
.b-ok   { background: var(--ok-bg);   color: var(--ok-ink); }   .b-ok .dot   { background: var(--ok-dot); }
.b-warn { background: var(--warn-bg); color: var(--warn-ink); } .b-warn .dot { background: var(--warn-dot); }
.b-crit { background: var(--crit-bg); color: var(--crit-ink); } .b-crit .dot { background: var(--crit-dot); }
.b-none { background: var(--none-bg); color: var(--none-ink); } .b-none .dot { background: var(--none-dot); }

/* ── Llistat de sensors (files) ──────────────────────────── */
.list { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 0 14px 0 0;
  border-top: 1px solid var(--line-soft); }
.row:first-child { border-top: 0; }
.row:hover { background: var(--line-soft); }
.row-main { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0;
  padding: 11px 0 11px 14px; text-decoration: none; color: inherit; }
.row .nm { font-weight: 600; }
.row .rd { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
.row .ago { color: var(--muted); font-size: 12.5px; min-width: 78px; text-align: right; }
.reorder { display: flex; flex-direction: column; gap: 2px; flex: none; }
.reorder form { margin: 0; line-height: 0; }
.reorder .arrow { font: inherit; font-size: 11px; line-height: 1; cursor: pointer;
  color: var(--muted); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 2px 7px; }
.reorder .arrow:hover:not(:disabled) { border-color: var(--sage); color: var(--brand-strong); }
.reorder .arrow:disabled { opacity: .35; cursor: default; }

/* ── Gràfica ─────────────────────────────────────────────── */
.segbar { display: flex; gap: 4px; margin: 2px 0 14px; flex-wrap: wrap; }
.seg { font-size: 12.5px; font-weight: 700; color: var(--muted); background: transparent;
  border: 1px solid var(--line); padding: 5px 12px; border-radius: 999px; cursor: pointer; }
.seg:hover { border-color: var(--sage); }
.seg.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chart-box { position: relative; height: 240px; }
.chartnote { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* ── Formularis ──────────────────────────────────────────── */
.form { max-width: 520px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.field input, .field select {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
}
.field input:focus, .field select:focus { outline: none; border: 2px solid var(--brand); padding: 8px 10px; }

.actions { display: flex; gap: 10px; align-items: center; margin-top: 22px; }
.btn { font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
  padding: 9px 16px; border-radius: var(--r-md); border: 1px solid transparent; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--sage); }
.btn-danger { background: transparent; color: var(--crit-soft-ink); border-color: var(--crit-soft-ink); }
.btn-danger:hover { background: var(--crit-soft-bg); }

/* ── Missatges ───────────────────────────────────────────── */
.flash { padding: 11px 14px; border-radius: var(--r-md); margin-bottom: 18px; font-size: 13.5px; }
.flash-ok  { background: var(--ok-bg);        color: var(--ok-ink); }
.flash-err { background: var(--crit-soft-bg); color: var(--crit-soft-ink); }
.empty { padding: 16px; border: 1px dashed var(--line); border-radius: var(--r-lg);
  color: var(--muted); background: var(--surface); }

/* ── Login ───────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg); padding: 26px; }
.login-card .mark { display: flex; justify-content: center; margin-bottom: 22px; }
.login-card .mark .logo { height: 34px; width: auto; max-width: 100%; display: block; }

.table-cap { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }

/* ── Caixa d'URL (webhook d'ingesta) ─────────────────────── */
.urlbox { display: block; margin-top: 4px; padding: 12px 14px;
  background: var(--line-soft); border: 1px solid var(--line); border-radius: var(--r-md);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px;
  color: var(--ink); line-height: 1.55; word-break: break-all; overflow-x: auto; user-select: all; }
