/* RAS Monitor — estilo inspirado en Grafana. Tema oscuro por defecto; claro con data-theme="light". */

:root {
  color-scheme: dark;
  --brand: #3d8bd9;
  --primary: #3d71d9;
  --primary-text: #6e9fff;
  --primary-wash: rgba(61, 113, 217, 0.16);

  --canvas: #111217;
  --panel: #181b1f;
  --panel-2: #22252b;
  --input: #111217;
  --sidebar: #181b1f;
  --chart-surface: #181b1f;
  --text: #ccccdc;
  --text-strong: #e5e5ee;
  --text-2: rgba(204, 204, 220, 0.65);
  --muted: rgba(204, 204, 220, 0.5);
  --border: rgba(204, 204, 220, 0.12);
  --border-strong: rgba(204, 204, 220, 0.22);
  --grid: rgba(204, 204, 220, 0.08);
  --axis: rgba(204, 204, 220, 0.5);
  --hover: rgba(204, 204, 220, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  --scrollbar: rgba(204, 204, 220, 0.18);

  /* Estados (reservados: siempre acompañados de ícono + texto) */
  --ok: #73bf69;
  --ok-wash: rgba(115, 191, 105, 0.12);
  --warn: #ff9830;
  --crit: #f2495c;
  --crit-text: #ff7383;
  --crit-wash: rgba(242, 73, 92, 0.14);
  --stale: #6e7280;

  /* Series (paleta validada para daltonismo sobre el panel oscuro) */
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;

  --radius: 6px;
  --font: 'Inter Variable', Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --sidebar-w: 232px;
}

:root[data-theme='light'] {
  color-scheme: light;
  --primary: #3871dc;
  --primary-text: #1f62e0;
  --primary-wash: rgba(56, 113, 220, 0.1);
  --canvas: #f4f5f5;
  --panel: #ffffff;
  --panel-2: #f4f5f5;
  --input: #ffffff;
  --sidebar: #ffffff;
  --chart-surface: #ffffff;
  --text: #24292e;
  --text-strong: #111418;
  --text-2: rgba(36, 41, 46, 0.75);
  --muted: rgba(36, 41, 46, 0.55);
  --border: rgba(36, 41, 46, 0.12);
  --border-strong: rgba(36, 41, 46, 0.25);
  --grid: rgba(36, 41, 46, 0.08);
  --axis: rgba(36, 41, 46, 0.6);
  --hover: rgba(36, 41, 46, 0.06);
  --shadow: 0 1px 2px rgba(36, 41, 46, 0.08);
  --scrollbar: rgba(36, 41, 46, 0.2);
  --ok: #1a7f4b;
  --ok-wash: rgba(26, 127, 75, 0.1);
  --warn: #c75000;
  --crit: #d10e5c;
  --crit-text: #b8004a;
  --crit-wash: rgba(209, 14, 92, 0.08);
  --stale: #9aa0a8;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--canvas);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--text-strong); font-weight: 500; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }
[hidden] { display: none !important; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

/* ===================== Estructura ===================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  background: var(--sidebar); border-right: 1px solid var(--border); padding: 14px 10px;
}
.sb-brand { display: flex; align-items: center; justify-content: center; padding: 6px 8px 16px; }
.sb-brand img { height: 40px; width: auto; }
.logo-light { display: none; }
:root[data-theme='light'] .logo-light { display: block; }
:root[data-theme='light'] .logo-dark { display: none; }
.sb-section { font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.sb-link {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 4px;
  color: var(--text-2); font-weight: 450; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  position: relative;
}
.sb-link:hover { background: var(--hover); color: var(--text-strong); text-decoration: none; }
.sb-link.active { background: var(--primary-wash); color: var(--text-strong); }
.sb-link.active::before { content: ''; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 2px; background: linear-gradient(#f2cc0c, #ff8833 50%, #f2495c); }
.sb-link svg { width: 16px; height: 16px; flex: none; }
.sb-link .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; margin: 0 4px; background: var(--stale); }
.sb-link .dot.ok { background: var(--ok); }
.sb-link .dot.bad { background: var(--crit); }
.sb-link .label { overflow: hidden; text-overflow: ellipsis; }
.sb-spacer { flex: 1; min-height: 16px; }
.sb-user { display: flex; align-items: center; gap: 6px; padding: 10px 6px 0; border-top: 1px solid var(--border); margin-top: 8px; }
.sb-user .who { flex: 1; min-width: 0; font-size: 12px; }
.sb-user .who b { display: block; color: var(--text-strong); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user .who span { color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  min-height: 52px; padding: 8px 20px; background: var(--canvas); border-bottom: 1px solid var(--border);
}
.crumbs { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text-2); min-width: 0; }
.crumbs a { color: var(--text-2); }
.crumbs .sep { color: var(--muted); }
.crumbs .cur { color: var(--text-strong); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--stale); }
.live.on .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-wash); }
.content { padding: 16px 20px 48px; }
.menu-btn { display: none; }

/* ===================== Controles ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 4px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border-strong); background: var(--panel-2); color: var(--text); font-weight: 500; font-size: 13px;
}
.btn:hover { border-color: var(--text-2); color: var(--text-strong); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.12); }
.btn.danger { color: var(--crit-text); }
.btn.danger.solid { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn.icon { width: 32px; padding: 0; }
.btn.sm.icon { width: 26px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 4px 4px 0; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 500; color: var(--text-2); }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=datetime-local], select, textarea {
  height: 32px; padding: 0 8px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--input); min-width: 0; font-size: 13px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-wash); }
.btn:focus-visible, .seg button:focus-visible, a:focus-visible, .stat:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type=checkbox] { accent-color: var(--primary); width: 15px; height: 15px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.error-msg { color: var(--crit-text); font-size: 13px; min-height: 18px; }
.seg { display: inline-flex; padding: 2px; border-radius: 4px; border: 1px solid var(--border-strong); background: var(--input); }
.seg button { border: 0; background: transparent; padding: 3px 12px; border-radius: 3px; cursor: pointer; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.seg button:hover { color: var(--text-strong); }
.seg button[aria-pressed=true] { background: var(--panel-2); color: var(--text-strong); box-shadow: var(--shadow), inset 0 0 0 1px var(--border-strong); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text-strong); text-decoration: none; }
.tabs a.active { color: var(--text-strong); border-bottom-color: #ff8833; }

/* Selector de rango de tiempo */
.picker { position: relative; }
.picker-pop {
  position: absolute; right: 0; top: 38px; z-index: 30; width: 460px; max-width: calc(100vw - 24px);
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  background: var(--panel); border: 1px solid var(--border-strong); border-radius: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.picker-pop .col { padding: 12px; }
.picker-pop .col + .col { border-left: 1px solid var(--border); }
.picker-pop h4 { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.picker-pop .opt { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 3px; cursor: pointer; font-size: 13px; color: var(--text); }
.picker-pop .opt:hover { background: var(--hover); }
.picker-pop .opt.sel { background: var(--primary-wash); color: var(--text-strong); }
.picker-pop label.field { margin-bottom: 10px; }

/* ===================== Paneles ===================== */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 12px 0; }
.panel-title { font-size: 13px; font-weight: 500; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 4px 12px 12px; }
.panel-body.flush { padding: 0; }
.grid { display: grid; gap: 8px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.plants { grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); }

/* Fila colapsable (como las "rows" de Grafana) */
.row { margin: 18px 0 8px; }
.row-head { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; background: none; border: 0; padding: 4px 0; color: var(--text-strong); font-size: 15px; font-weight: 500; }
.row-head svg { width: 14px; height: 14px; transition: transform .15s; color: var(--text-2); }
.row.collapsed .row-head svg { transform: rotate(-90deg); }
.row.collapsed .row-body { display: none; }
.row-head .count { font-size: 12px; color: var(--muted); font-weight: 400; }
.row-body { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

/* Panel de estadística (stat) */
.stat {
  position: relative; display: flex; flex-direction: column; text-align: left; overflow: hidden;
  padding: 8px 12px 0; cursor: default;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.stat .s-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; z-index: 1; }
.stat .s-title svg { width: 13px; height: 13px; flex: none; }
.stat .s-value { position: relative; z-index: 1; font-size: 30px; font-weight: 500; line-height: 1.1; letter-spacing: -0.01em; color: var(--ok); margin-top: 2px; white-space: nowrap; }
.stat .s-value small { font-size: 14px; font-weight: 400; margin-left: 3px; opacity: 0.85; }
.stat .s-name { overflow: hidden; text-overflow: ellipsis; }
.stat .s-lim { margin-left: auto; padding-left: 8px; font-size: 11px; font-weight: 400; color: var(--muted); flex: none; }
.stat .s-foot { position: relative; z-index: 1; font-size: 11px; color: var(--muted); min-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Minigráfico en una franja propia al pie del panel (no tapa el texto). */
.stat .spark { order: 9; height: 34px; margin: 2px -12px 0; pointer-events: none; }
.stat.alarm { border-color: color-mix(in srgb, var(--crit) 55%, transparent); background: linear-gradient(var(--crit-wash), var(--crit-wash)), var(--panel); }
.stat.alarm .s-value, .stat.alarm .s-title { color: var(--crit-text); }
.stat.stale .s-value { color: var(--stale); }
.stat.neutral .s-value { color: var(--text-strong); }
.stat.off .s-value { color: var(--text-2); }
a.stat:hover { border-color: var(--border-strong); text-decoration: none; cursor: pointer; }

/* Tarjeta de planta en el resumen */
.plant-card .panel-head { padding-top: 10px; }
.plant-card .meta { font-size: 12px; color: var(--muted); }
.plant-card .mini { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 6px 12px 0; }
.plant-card .mini .k { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plant-card .mini .v { font-size: 20px; font-weight: 500; color: var(--text-strong); white-space: nowrap; }
.plant-card .mini .v small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 2px; }
.plant-card .mini .v.alarm { color: var(--crit-text); }
.plant-card .card-spark { height: 70px; margin-top: 6px; }
.plant-card .foot { display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.plant-card .foot .alarms { color: var(--crit-text); display: inline-flex; align-items: center; gap: 4px; }
.plant-card .foot svg { width: 13px; height: 13px; }
a.plant-card { color: inherit; display: block; }
a.plant-card:hover { border-color: var(--border-strong); text-decoration: none; }

/* Estados */
.pill { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 3px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--panel-2); color: var(--text-2); border: 1px solid var(--border); }
.pill svg { width: 12px; height: 12px; }
.pill.ok { color: var(--ok); background: var(--ok-wash); border-color: transparent; }
.pill.bad { color: var(--crit-text); background: var(--crit-wash); border-color: transparent; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.notice { padding: 10px 12px; border-radius: 4px; font-size: 13px; background: rgba(255, 152, 48, 0.12); border-left: 3px solid var(--warn); margin: 8px 0; }
.notice.info { background: var(--primary-wash); border-left-color: var(--primary); }
.notice.bad { background: var(--crit-wash); border-left-color: var(--crit); }

/* ===================== Gráficos ===================== */
.ts-panel .chart { position: relative; }
.ts-panel .u-legend { display: none; }
.chart .u-select { background: var(--primary-wash); }
.legend-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.legend-table th { text-align: right; font-weight: 500; color: var(--primary-text); padding: 3px 8px; border: 0; white-space: nowrap; }
.legend-table th:first-child { text-align: left; }
.legend-table td { padding: 2px 8px; border: 0; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.legend-table td:first-child { text-align: left; cursor: pointer; }
.legend-table tr.hidden td { opacity: 0.4; }
.legend-table .key { display: inline-block; width: 14px; height: 4px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }
.legend-table tr:hover td { background: var(--hover); }
.tooltip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 180px;
  background: var(--panel-2); border: 1px solid var(--border-strong); border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0,0,0,.35); padding: 8px 10px; font-size: 12px;
}
.tooltip .tt-time { color: var(--text-2); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; line-height: 1.6; }
.tooltip .tt-row .key { width: 10px; height: 3px; border-radius: 2px; flex: none; }
.tooltip .tt-row .v { margin-left: auto; padding-left: 14px; font-weight: 500; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* ===================== Mapa ===================== */
.map-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 8px; height: calc(100vh - 52px - 32px); min-height: 480px; }
.map-side { display: flex; flex-direction: column; min-height: 0; }
.map-side .panel-body { overflow-y: auto; flex: 1; }
.map-box { position: relative; min-height: 0; overflow: hidden; }
.map-canvas { position: absolute; inset: 0; border-radius: var(--radius); }
.map-item { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--border); padding: 10px 4px; cursor: pointer; color: var(--text); }
.map-item:hover { background: var(--hover); }
.map-item .t { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 500; color: var(--text-strong); }
.map-item .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
.map-item .vals { display: flex; gap: 12px; margin-top: 4px; font-size: 12px; }
.map-item .vals b { font-weight: 500; color: var(--text-strong); }
.map-item .vals b.alarm { color: var(--crit-text); }
.map-popup { min-width: 210px; font: 13px/1.45 var(--font); color: var(--text); }
.map-popup h3 { margin-bottom: 4px; }
.map-popup .row2 { display: flex; justify-content: space-between; gap: 12px; }
.map-popup .row2 b { font-weight: 500; }
.map-popup .row2 b.alarm { color: var(--crit-text); }
.map-popup .actions { margin-top: 8px; }
.leaflet-container { background: var(--panel-2); font-family: var(--font); }
:root:not([data-theme='light']) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.92) saturate(0.6); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel-2); color: var(--text); border: 1px solid var(--border-strong); box-shadow: 0 6px 18px rgba(0,0,0,.35); border-radius: 4px; }
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--text-2); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--panel) 80%, transparent) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-bar a { background: var(--panel-2); color: var(--text); border-color: var(--border-strong); }
.leaflet-bar a:hover { background: var(--panel); }
.map-pick { height: 280px; border-radius: 4px; border: 1px solid var(--border-strong); position: relative; }
.search-results { border: 1px solid var(--border-strong); border-radius: 4px; background: var(--panel-2); max-height: 200px; overflow-y: auto; }
.search-results button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 10px; cursor: pointer; font-size: 13px; color: var(--text); }
.search-results button:hover { background: var(--hover); }

/* ===================== Tablas ===================== */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-size: 12px; font-weight: 500; color: var(--text-2); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--panel); position: sticky; top: 0; z-index: 1; }
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--hover); }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data td input[type=text], table.data td input[type=number] { height: 28px; width: 100%; font-size: 12px; }
table.data td input.w-num { width: 76px; }
table.data .sel td { background: var(--primary-wash); }
.tag-name { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.scroll-box { max-height: 460px; overflow: auto; border: 1px solid var(--border); border-radius: 4px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input[type=search] { width: 260px; }
.badge { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 11px; background: var(--panel-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.o2 { color: var(--s1); border-color: currentColor; }
.badge.wq { color: var(--s3); border-color: currentColor; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--primary-text); animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.section { margin-bottom: 12px; }
.section > .panel-head { padding-top: 12px; }
.section > .panel-body { padding-top: 10px; }

/* ===================== Diálogos y avisos ===================== */
dialog {
  border: 1px solid var(--border-strong); border-radius: 6px; padding: 0; width: min(560px, calc(100vw - 24px));
  background: var(--panel); color: var(--text); box-shadow: 0 16px 48px rgba(0,0,0,.45);
}
dialog.wide { width: min(1100px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.dlg-body { padding: 18px; max-height: calc(100vh - 190px); overflow: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.keybox { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 4px; background: var(--input); border: 1px solid var(--border-strong); font-family: var(--mono); font-size: 12px; word-break: break-all; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 3px; font-size: 13px; cursor: pointer; background: var(--input); }
#toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--panel-2); color: var(--text-strong); border: 1px solid var(--border-strong); border-left: 4px solid var(--ok); padding: 10px 14px; border-radius: 4px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 380px; }
.toast.err { border-left-color: var(--crit); }

/* ===================== Login ===================== */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% 0%, rgba(61, 139, 217, 0.18), transparent 60%), radial-gradient(900px 500px at 100% 100%, rgba(23, 59, 87, 0.5), transparent 60%), var(--canvas);
}
.login { width: min(400px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 34px 30px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.login .brand-lg { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; margin-bottom: 8px; }
.login .brand-lg img { height: 64px; width: auto; }
.login .brand-lg .tag { font-size: 13px; color: var(--text-2); }
.login .btn { height: 38px; font-size: 14px; }
.login input { height: 38px; font-size: 14px; }

/* ===================== Móvil ===================== */
@media (max-width: 1100px) {
  .grid.plants { grid-template-columns: 1fr; }
  .map-layout { grid-template-columns: 1fr; height: auto; }
  .map-box { height: 60vh; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.5); }
  .app.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 8px 12px; }
  .content { padding: 12px 12px 40px; }
  .grid.cols-2, .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .grid.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat .s-value { font-size: 24px; }
  .plant-card .mini { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .picker-pop { grid-template-columns: 1fr; width: 300px; }
  .picker-pop .col + .col { border-left: 0; border-top: 1px solid var(--border); }
  .toolbar input[type=search] { width: 100%; }
  .live span { display: none; }
}

/* Indicadores del resumen (sin minigráfico) */
.grid.kpis .stat { min-height: 104px; justify-content: space-between; padding-bottom: 10px; }

/* Título grande de la medición en cada gráfico ("pH", "Temperatura (°C)") */
.ts-panel .panel-head { min-height: 44px; padding-top: 10px; }
.ts-panel .panel-title { font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }

/* Personalización del tablero */
.customize-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; margin: 10px 0 4px; border: 1px dashed var(--primary); border-radius: var(--radius); background: var(--primary-wash); font-size: 13px; }
.customize-bar .chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border-radius: 3px; background: var(--panel); border: 1px solid var(--border-strong); font-size: 12px; cursor: pointer; color: var(--text); }
.customize-bar .chip:hover { border-color: var(--primary); }
.customize-bar .chip svg { width: 13px; height: 13px; }
.editing .ts-panel { outline: 1px dashed var(--border-strong); outline-offset: -1px; }
.key-btn { border: 0; background: none; padding: 4px 2px; margin-right: 4px; cursor: pointer; border-radius: 3px; }
.key-btn:hover { background: var(--hover); }
.key-btn .key { margin-right: 0; width: 18px; height: 8px; }
.color-pop { position: absolute; z-index: 60; width: 220px; padding: 10px; background: var(--panel); border: 1px solid var(--border-strong); border-radius: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.color-pop .swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 10px; }
.color-pop .swatch { width: 100%; aspect-ratio: 1; border-radius: 3px; border: 2px solid transparent; cursor: pointer; }
.color-pop .swatch.sel, .color-pop .swatch:hover { border-color: var(--text-strong); }
.color-pop .row-c { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.color-pop input[type=color] { width: 34px; height: 24px; padding: 0; border: 1px solid var(--border-strong); background: none; vertical-align: middle; cursor: pointer; }
.customize-bar > svg { width: 16px; height: 16px; flex: none; color: var(--primary-text); }

/* ===================== Indicadores (gauge / bar gauge / state timeline) ===================== */
.grid.gauges { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.gauge-panel { display: flex; flex-direction: column; padding: 8px 10px 6px; min-width: 0; }
.gauge-panel .s-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--text-2); white-space: nowrap; overflow: hidden; }
.gauge-panel .s-title svg { width: 13px; height: 13px; flex: none; }
.gauge-panel .s-name { overflow: hidden; text-overflow: ellipsis; }
.gauge-panel .gauge-svg { width: 100%; max-height: 170px; display: block; margin: 2px auto 0; }
.gauge-panel .g-note { font-size: 11px; color: var(--muted); min-height: 15px; text-align: center; }
.gauge-panel.alarm { border-color: color-mix(in srgb, var(--crit) 55%, transparent); background: linear-gradient(var(--crit-wash), var(--crit-wash)), var(--panel); }
.gauge-panel.alarm .s-title, .gauge-panel.alarm .g-note { color: var(--crit-text); }

.bar-gauge .bg-list { display: flex; flex-direction: column; gap: 6px; padding-top: 4px; }
.bar-gauge.horizontal .bg-row { display: grid; grid-template-columns: minmax(110px, 200px) minmax(0, 1fr) 92px; align-items: center; gap: 10px; font-size: 13px; }
.bar-gauge .bg-label { display: flex; align-items: center; gap: 5px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-gauge .bg-label svg { width: 13px; height: 13px; flex: none; color: var(--crit); }
.bar-gauge .bg-row.alarm .bg-label { color: var(--crit-text); font-weight: 500; }
.bar-gauge .bg-row.stale .bg-label, .bar-gauge .bg-row.off .bg-label { color: var(--muted); }
.bar-gauge .bg-track { position: relative; display: block; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.bar-gauge.horizontal .bg-track { height: 18px; }
.bar-gauge .bg-fill { position: absolute; left: 0; bottom: 0; border-radius: 3px; transition: width .4s, height .4s; }
.bar-gauge.horizontal .bg-fill { top: 0; }
.bar-gauge .bg-mark { position: absolute; background: var(--text-strong); opacity: .55; }
.bar-gauge.horizontal .bg-mark { top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.bar-gauge .bg-value { text-align: right; font-weight: 600; font-size: 15px; color: var(--text-strong); white-space: nowrap; }
.bar-gauge .bg-value small { font-size: 11px; font-weight: 400; color: var(--muted); }
.bar-gauge.vertical .bg-list { flex-direction: row; align-items: stretch; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.bar-gauge.vertical .bg-row { display: flex; flex-direction: column-reverse; align-items: center; gap: 6px; flex: 1 0 54px; min-width: 54px; max-width: 110px; }
.bar-gauge.vertical .bg-track { width: 26px; height: 170px; }
.bar-gauge.vertical .bg-fill { right: 0; }
.bar-gauge.vertical .bg-mark { left: 0; right: 0; height: 2px; margin-bottom: -1px; }
.bar-gauge.vertical .bg-label { font-size: 11px; max-width: 100%; justify-content: center; }
.bar-gauge.vertical .bg-value { text-align: center; font-size: 13px; }
.bar-gauge.vertical .bg-value small { display: block; }

.stat.bg-mode { border: 0; }
.stat.bg-mode .s-title, .stat.bg-mode .s-value, .stat.bg-mode .s-foot, .stat.bg-mode .s-value small { color: #fff !important; opacity: 1; }
.stat.bg-mode.ok-bg { background: linear-gradient(135deg, #2f8f3a, #56a64b); }
.stat.bg-mode.alarm-bg { background: linear-gradient(135deg, #c4162a, #f2495c); }
.stat.bg-mode.stale-bg { background: linear-gradient(135deg, #3d4048, #5a5e68); }
.stat.bg-mode.neutral-bg { background: linear-gradient(135deg, #1f60c4, #3274d9); }

.state-timeline .st-lane { display: grid; grid-template-columns: minmax(110px, 220px) minmax(0, 1fr); align-items: center; gap: 10px; margin: 3px 0; font-size: 12px; }
.state-timeline .st-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.state-timeline .st-svg { width: 100%; height: 22px; display: block; border-radius: 3px; }
.state-timeline .st-axis { display: flex; justify-content: space-between; margin-left: calc(min(220px, 30%) + 10px); font-size: 11px; color: var(--muted); padding-top: 4px; }

/* Selector de visualización en modo personalizar */
.viz-pick { display: inline-flex; gap: 6px; align-items: center; margin-left: 12px; font-size: 12px; font-weight: 400; }
.viz-pick select { height: 26px; font-size: 12px; }
.editing-card { outline: 1px dashed var(--primary); outline-offset: -1px; }
.card-tools { display: flex; gap: 4px; }
@media (max-width: 860px) {
  .bar-gauge.horizontal .bg-row { grid-template-columns: minmax(80px, 120px) minmax(0, 1fr) 70px; }
  .grid.gauges { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Tarjetas del resumen: modo barras y etiqueta del minigráfico */
.plant-card .mini.bars { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; }
.plant-card .mini-bar { display: grid; grid-template-columns: minmax(80px, 34%) minmax(0, 1fr) 84px; align-items: center; gap: 8px; }
.plant-card .mini-bar .k { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plant-card .mini-bar .track { position: relative; height: 12px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.plant-card .mini-bar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; transition: width .4s; }
.plant-card .mini-bar .v { font-size: 15px; text-align: right; }
.plant-card .spark-label { font-size: 11px; color: var(--muted); padding: 0 12px 4px; }
