/* Panell de criterio-radar. Colors com a tokens (clar/fosc), tipografia del sistema. */
:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --surface-2: #f2f1ed; --ink: #0b0b0b; --ink-2: #52514e;
  --muted: #898781; --grid: #e1e0d9; --axis: #c3c2b7; --border: rgba(11,11,11,.10);
  --accent: #2a78d6; --accent-wash: rgba(42,120,214,.10); --accent-ink: #1c5cab;
  --good: #0ca30c; --good-ink: #006300; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --ink: #f0efec; --ink-2: #c3c2b7;
    --muted: #898781; --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
    --accent: #3987e5; --accent-wash: rgba(57,135,229,.14); --accent-ink: #86b6ef;
    --good-ink: #0ca30c; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --ink: #f0efec; --ink-2: #c3c2b7;
  --muted: #898781; --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,.10);
  --accent: #3987e5; --accent-wash: rgba(57,135,229,.14); --accent-ink: #86b6ef;
  --good-ink: #0ca30c; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--page); color: var(--ink); }
a { color: var(--accent-ink); text-decoration: none; } a:hover { text-decoration: underline; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* --- Estructura: barra lateral + contingut --- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-wash); color: var(--accent-ink); }
.side-foot { position: absolute; bottom: 16px; left: 12px; right: 12px; font-size: 12px; color: var(--muted); }
.theme-btn { background: none; border: 1px solid var(--border); color: var(--ink-2); border-radius: 8px; padding: 6px 10px; cursor: pointer; width: 100%; margin-top: 8px; }
main { padding: 26px 32px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head p { margin: 2px 0 0; color: var(--ink-2); }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }

/* --- Targetes i graelles --- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.stat .label { font-size: 12px; color: var(--ink-2); }
.stat .value { font-size: 28px; font-weight: 650; margin-top: 2px; line-height: 1.15; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.hero .value { font-size: 48px; }
.muted { color: var(--muted); } .ink2 { color: var(--ink-2); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.between { justify-content: space-between; }

/* --- Etiquetes d'estat (sempre icona + text) --- */
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.tag .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.tag.n1 .dot, .tag.bad .dot { background: var(--critical); }
.tag.n2 .dot, .tag.warn .dot { background: var(--warning); }
.tag.n3 .dot { background: var(--accent); }
.tag.ok .dot { background: var(--good); }
.score { font-variant-numeric: tabular-nums; font-weight: 700; }

/* --- Alertes --- */
.alert { border-top: 1px solid var(--grid); padding: 14px 0; }
.alert:first-child { border-top: 0; padding-top: 0; }
.alert h3 { font-size: 15px; margin: 6px 0 2px; }
.alert .orig { font-size: 12px; color: var(--muted); }
.tweet { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-top: 8px; white-space: pre-wrap; font-size: 14px; }
.tweet-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.regen { font-size: 12px; color: var(--ink-2); margin-top: 6px; }
details summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }

/* --- Taules --- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--grid); }
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* --- Barres HTML (valors a la punta, sense color com a únic canal) --- */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 48px; align-items: center; gap: 10px; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 0 4px 4px 0; }
.bar { height: 10px; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar.target { background: none; border-right: 2px solid var(--ink-2); height: 16px; margin-top: -13px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }

/* --- Sèries i gràfics --- */
.kpi .value { font-size: 22px; font-weight: 650; }
.kpi .delta { font-size: 12px; color: var(--ink-2); }
.spark { width: 100%; height: 36px; margin-top: 6px; display: block; }
.chart { position: relative; }
.chart svg { width: 100%; height: 260px; display: block; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12); opacity: 0; transition: opacity .1s; white-space: nowrap; }
.chart .tip b { font-size: 14px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.chart-head h3 { margin: 0; font-size: 15px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 5px 10px; color: var(--ink-2); cursor: pointer; font: inherit; font-size: 12px; }
.seg button.on { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }

/* --- Calendari --- */
.day { margin-top: 18px; }
.day h3 { font-size: 14px; margin: 0 0 6px; }
.ev { display: grid; grid-template-columns: 52px 54px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--grid); }
.ev.past { opacity: .75; }
.ev .t { font-variant-numeric: tabular-nums; font-weight: 600; }
.ev .name { font-weight: 500; } .ev .name.imp3 { font-weight: 700; }
.ev .vals { font-size: 13px; color: var(--ink-2); text-align: right; white-space: nowrap; }
.stars { color: var(--warning); letter-spacing: 1px; font-size: 12px; }

/* --- Botons i filtres --- */
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
select, input[type=date] { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
.log { background: var(--surface-2); border-radius: 10px; padding: 12px; font: 12px/1.5 ui-monospace, Consolas, monospace; max-height: 420px; overflow: auto; white-space: pre-wrap; color: var(--ink-2); }
#toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: var(--page); padding: 10px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }

/* --- Mòbil --- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding-bottom: 8px; }
  .nav { display: flex; gap: 2px; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .side-foot { position: static; display: flex; gap: 8px; align-items: center; margin-top: 8px; }
  .theme-btn { width: auto; margin: 0; }
  main { padding: 18px 16px 50px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: span 2; }
  .bar-row { grid-template-columns: 110px 1fr 40px; }
}
@media (max-width: 560px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: span 1; }
  .hero .value { font-size: 40px; }
  .ev { grid-template-columns: 44px 24px 1fr; }
  .ev .vals { grid-column: 3; text-align: left; }
}
