/* iot.katta.cl - tokens: paleta de referencia de dataviz (claro/oscuro). */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --series: #2a78d6;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);
    --series: #3987e5;
    --accent: #3987e5;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.10);
  --wash: rgba(255, 255, 255, 0.05);
  --series: #3987e5;
  --accent: #3987e5;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

.wrap { max-width: 1180px; margin: 0 auto; padding-inline: 20px; }

/* ---- barra superior ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--ring);
}
.topbar .wrap { display: flex; align-items: center; gap: 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #1c5cab);
  display: grid; place-items: center;
}
.brand-mark svg { width: 15px; height: 15px; }
.brand small { color: var(--muted); font-weight: 500; }
.spacer { flex: 1; }
.select, .btn {
  height: 34px; border-radius: 9px; border: 1px solid var(--ring);
  background: var(--surface); color: var(--ink); padding: 0 12px; cursor: pointer;
}
.btn:hover, .select:hover { background: var(--wash); }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.user { color: var(--ink-2); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }

/* ---- encabezado del equipo ---- */
.device-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px 24px; padding-block: 28px 18px;
}
.device-head h1 { margin: 0; font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.device-head .sub { color: var(--ink-2); margin-top: 4px; }
.status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--ring); font-weight: 600;
}
.status .icon { width: 14px; height: 14px; flex: none; }
.status[data-state="online"] .icon { color: var(--good); }
.status[data-state="late"] .icon { color: var(--warning); }
.status[data-state="offline"] .icon,
.status[data-state="no-data"] .icon { color: var(--critical); }
.status-meta { color: var(--ink-2); font-size: 13px; margin-top: 6px; text-align: right; }

/* ---- tarjetas de lectura ---- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--ring); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.tile .label { color: var(--ink-2); font-size: 13px; font-weight: 550; display: flex; align-items: center; gap: 8px; }
.tile .key { width: 10px; height: 3px; border-radius: 2px; background: var(--series); }
.tile .value { font-size: 32px; font-weight: 650; letter-spacing: -0.02em; margin-top: 6px; line-height: 1.1; }
.tile .value .unit { font-size: 16px; font-weight: 550; color: var(--ink-2); margin-left: 3px; }
.tile .detail { color: var(--muted); font-size: 12.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .flag { color: var(--ink-2); font-size: 12.5px; margin-top: 6px; display: flex; gap: 6px; align-items: center; }
.tile .flag svg { width: 13px; height: 13px; color: var(--warning); flex: none; }

/* ---- filtros ---- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding-block: 26px 12px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer;
  color: var(--ink-2); font-weight: 550;
}
.seg button:hover { background: var(--wash); color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.toolbar .meta { color: var(--muted); font-size: 12.5px; }

/* ---- graficos ---- */
.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--ring); border-radius: var(--radius);
  padding: 16px 16px 8px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { margin: 0 2px; font-size: 14px; font-weight: 620; }
.card .hint { margin: 2px 2px 0; color: var(--muted); font-size: 12.5px; }
.chart { height: 240px; width: 100%; }
.empty { display: grid; place-items: center; height: 240px; color: var(--muted); }

/* ---- tabla ---- */
.table-card { margin-top: 14px; }
.table-scroll { overflow-x: auto; margin-top: 10px; max-height: 420px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13px; }
th, td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--ink-2); font-weight: 600; position: sticky; top: 0; background: var(--surface); }

footer { color: var(--muted); font-size: 12.5px; padding-block: 28px 40px; }
footer code { font-size: 12px; }

/* ---- pantalla de ingreso ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding-inline: 20px; }
.login-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--ring);
  border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); text-align: center;
}
.login-card .brand { justify-content: center; font-size: 18px; }
.login-card p { color: var(--ink-2); margin: 14px 0 22px; }
.login-card .btn { width: 100%; height: 42px; }
.login-card .err { color: var(--critical); font-size: 13px; margin-top: 14px; }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .wrap { padding-inline: 16px; }
  .tile .value { font-size: 26px; }
  .user { display: none; }
  .status-meta { text-align: left; }
  .device-head h1 { font-size: 22px; }
}
