:root {
  color-scheme: dark;
  --bg: #080c14;
  --panel: #0e1420;
  --panel-2: #131b2a;
  --line: #1b2433;
  --line-2: #273142;
  --text: #e8ecf3;
  --text-2: #a3acbd;
  --muted: #6b7588;
  --green: #2fd07f;
  --lime: #c5e83a;
  --orange: #f3a530;
  --blue: #4d8ff5;
  --red: #f05252;
  --yellow: #f5c542;
  --c1: #3987e5; --c2: #d95926; --c3: #199e70; --c4: #c98500;
  --c5: #d55181; --c6: #2fae2f; --c7: #9085e9; --c8: #e66767;
  --font: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); color: var(--text); font: 13px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
b { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- barra superior ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 24px; border-bottom: 1px solid var(--line); background: #070a11;
}
.brand { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; letter-spacing: .06em; }
.brand b { font-size: 14px; }
.logo { width: 22px; height: 22px; fill: var(--lime); }
.dot-sep, .brand-sub { color: var(--muted); font-weight: 500; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 6px;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text-2);
  font-size: 11px; font-weight: 500; letter-spacing: .03em; white-space: nowrap;
}
.top-right { display: flex; align-items: center; gap: 14px; }
.live { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; flex: none; color: var(--green); font-weight: 700; font-size: 11px; letter-spacing: .08em; }
.live i { position: relative; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(47, 208, 127, .18); }
/* El latido va en una capa aparte (transform y opacity): animar box-shadow repinta la barra fija
   entera y en el iPhone deja el título borroso. */
.live i::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; background: rgba(47, 208, 127, .35); animation: pulse 2s infinite; will-change: transform, opacity; }
.live.off { color: var(--red); }
.live.off i { background: var(--red); box-shadow: 0 0 0 3px rgba(240, 82, 82, .18); }
.live.off i::after { display: none; }
@keyframes pulse { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.8); opacity: 0; } }
.clock { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; padding: 4px 12px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); }
button { font: inherit; color: var(--text-2); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { color: var(--text); border-color: var(--muted); }
button:disabled { opacity: .35; cursor: default; }
.icon-btn { font-size: 15px; line-height: 1; padding: 5px 9px; }

main { max-width: 1600px; margin: 0 auto; padding: 18px 24px 40px; display: grid; gap: 14px; }

/* ---------- paneles ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.ph-title { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.ph-title b { font-size: 13.5px; }
.ph-icon {
  width: 24px; height: 24px; display: inline-grid; place-items: center; border-radius: 6px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2); font-size: 12px;
}
.row { display: grid; gap: 14px; }
.r-main { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.r-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.r-bottom { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.25fr) minmax(280px, .8fr); }

/* ---------- franja del minero ---------- */
.host {
  display: flex; justify-content: space-between; align-items: center; gap: 18px; flex-wrap: wrap;
  border-left: 3px solid var(--lime);
  background: linear-gradient(90deg, rgba(197, 232, 58, .06), transparent 40%), var(--panel);
}
.host.down { border-left-color: var(--red); background: linear-gradient(90deg, rgba(240, 82, 82, .07), transparent 40%), var(--panel); }
.host-id { display: flex; gap: 14px; align-items: center; }
.host-icon { position: relative; width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; background: rgba(197, 232, 58, .12); border: 1px solid rgba(197, 232, 58, .35); }
.host-icon svg { width: 22px; height: 22px; fill: none; stroke: var(--lime); stroke-width: 1.6; }
.host-icon i { position: absolute; right: -4px; bottom: -4px; width: 13px; height: 13px; border-radius: 50%; background: var(--green); border: 3px solid var(--panel); }
.host.down .host-icon i { background: var(--red); }
.host-name { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.host-sub { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.tag { font-size: 10.5px; font-weight: 700; letter-spacing: .08em; padding: 3px 8px; border-radius: 5px; color: var(--green); background: rgba(47, 208, 127, .12); border: 1px solid rgba(47, 208, 127, .35); }
.tag.bad { color: var(--red); background: rgba(240, 82, 82, .12); border-color: rgba(240, 82, 82, .35); }
.host-stats { display: flex; flex-wrap: wrap; }
.hs { padding: 2px 22px; border-left: 1px solid var(--line-2); min-width: 110px; }
.hs-label, .label { font-size: 10.5px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.hs-val { font-size: 16px; font-weight: 700; margin-top: 3px; white-space: nowrap; }
.hs-val small { font-size: 11.5px; font-weight: 500; color: var(--text-2); margin-left: 3px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi {
  --a: var(--green); --a-rgb: 47, 208, 127;
  position: relative; overflow: hidden; border-radius: 10px; padding: 16px 16px 58px;
  background: linear-gradient(180deg, rgba(var(--a-rgb), .07), rgba(var(--a-rgb), 0) 55%), var(--panel);
  border: 1px solid var(--line); border-left: 3px solid var(--a);
}
.kpi.lime { --a: var(--lime); --a-rgb: 197, 232, 58; }
.kpi.orange { --a: var(--orange); --a-rgb: 243, 165, 48; }
.kpi.blue { --a: var(--blue); --a-rgb: 77, 143, 245; }
.kpi.red { --a: var(--red); --a-rgb: 240, 82, 82; }
.kpi-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.kpi-id { display: flex; gap: 10px; align-items: center; }
.kpi-icon { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-size: 15px; color: var(--a); background: rgba(var(--a-rgb), .12); border: 1px solid rgba(var(--a-rgb), .35); }
.kpi-title { font-weight: 600; font-size: 13.5px; }
.kpi-sub { color: var(--muted); font-size: 11.5px; }
.kpi-value { display: flex; align-items: baseline; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.kpi-value .v { font-size: 34px; font-weight: 700; letter-spacing: -.01em; line-height: 1; }
.kpi-value .u { font-size: 15px; color: var(--text-2); font-weight: 500; }
.delta { font-size: 11.5px; font-weight: 600; padding: 2px 7px; border-radius: 5px; margin-left: 6px; white-space: nowrap; }
.delta.up { color: var(--green); background: rgba(47, 208, 127, .12); }
.delta.down { color: var(--red); background: rgba(240, 82, 82, .13); }
.delta.flat { color: var(--text-2); background: var(--panel-2); }
.kpi-foot { color: var(--muted); font-size: 11.5px; margin-top: 10px; }
.kpi-foot b { color: var(--text-2); }
.spark { position: absolute; left: 0; right: 0; bottom: 0; height: 52px; }
.spark svg { display: block; width: 100%; height: 100%; }

/* ---------- mini estadísticas ---------- */
.minis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.mini { border: 1px solid var(--line-2); background: var(--panel-2); border-radius: 8px; padding: 10px 12px; }
.mini .label { display: flex; align-items: center; gap: 6px; }
.mini .label i { width: 7px; height: 7px; border-radius: 50%; }
.mini-val { font-size: 19px; font-weight: 700; margin-top: 4px; }
.mini-val small { font-size: 11.5px; color: var(--text-2); font-weight: 500; }
.mini-sub { font-size: 11px; color: var(--muted); }

/* ---------- donut ---------- */
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut { width: 170px; height: 170px; flex: none; position: relative; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-center .big { font-size: 26px; font-weight: 700; }
.donut-center .label { margin-top: 2px; }
.donut-center .sub { font-size: 11px; color: var(--text-2); margin-top: 2px; }
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 170px; display: grid; gap: 9px; }
.donut-legend li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.donut-legend li i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.donut-legend li b { margin-left: auto; }
.donut-legend li span.pct { color: var(--muted); width: 48px; text-align: right; font-size: 11.5px; }
.donut-legend li.note { color: var(--text-2); font-size: 12px; border-top: 1px solid var(--line); padding-top: 9px; }
.bar-block { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.bar-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; margin-bottom: 8px; }
.bar-head span { display: flex; align-items: center; gap: 8px; }
.sw { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.track { position: relative; height: 8px; border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line-2); }
.track i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; width: 0; transition: width .4s; }
.track .mark { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--muted); }
.bar-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 10.5px; margin-top: 5px; }

/* ---------- gráficas ---------- */
.chart { position: relative; height: 200px; }
.chart.tall { height: 230px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis line { stroke: var(--line-2); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .ref { stroke: var(--orange); stroke-dasharray: 4 4; stroke-width: 1; opacity: .8; }
.chart text.ref-label { fill: var(--orange); font-weight: 600; letter-spacing: .06em; }
.chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .dot { stroke: var(--panel); stroke-width: 2; }
.chart .bar.dim { opacity: .45; }
.empty { color: var(--muted); font-size: 12.5px; padding: 28px 0; text-align: center; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; padding: 8px 11px; border-radius: 8px;
  background: #0a0f19; color: var(--text); border: 1px solid var(--line-2);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45); font-size: 12px; white-space: nowrap;
}
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row i, .legend i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.tip-row b { margin-left: auto; padding-left: 14px; }
.tip-time { color: var(--muted); margin-top: 3px; }

/* ---------- controles ---------- */
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; background: var(--panel-2); }
.seg[hidden] { display: none; }
.seg button { border: 0; border-radius: 0; padding: 4px 10px; background: transparent; font-size: 12px; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--line-2); color: var(--text); font-weight: 600; }
select {
  font: inherit; font-size: 12px; color: var(--text); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 24px 4px 8px; max-width: 200px;
  /* iOS pinta su propio botón gris y encoge el texto: flecha propia en su lugar */
  -webkit-appearance: none; appearance: none;
  background: var(--panel-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236b7588' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 8px center;
}
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11.5px; color: var(--text-2); margin: 10px 0 6px; min-height: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 420px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { color: var(--muted); font-weight: 600; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; position: sticky; top: 0; background: var(--panel); }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(255, 255, 255, .02); }
.cell-bar { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.ibar { width: 70px; height: 5px; border-radius: 3px; background: var(--line-2); overflow: hidden; flex: none; }
.ibar i { display: block; height: 100%; border-radius: 3px; }
.sub-line { display: block; color: var(--muted); font-size: 11px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; }
th.group-head { text-align: center; color: var(--text-2); border-bottom: 1px solid var(--line-2); }
td.oc { color: var(--text-2); }

.st { display: inline-flex; align-items: center; gap: 6px; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; padding: 3px 8px; border-radius: 5px; text-transform: uppercase; }
.st::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st.good { color: var(--green); background: rgba(47, 208, 127, .1); border: 1px solid rgba(47, 208, 127, .3); }
.st.bad { color: var(--red); background: rgba(240, 82, 82, .1); border: 1px solid rgba(240, 82, 82, .3); }
.st.warn { color: var(--yellow); background: rgba(245, 197, 66, .1); border: 1px solid rgba(245, 197, 66, .3); }

/* ---------- rigs ---------- */
.rig { border: 1px solid var(--line-2); border-radius: 10px; padding: 14px; background: rgba(255, 255, 255, .01); }
.rig + .rig { margin-top: 12px; }
.rig.down { border-left: 3px solid var(--red); }
.rig-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.rig-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 10px; }
.rig-stats { display: flex; gap: 6px 18px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.rig-stats b { color: var(--text); }
.rig-chart { margin-top: 14px; }
.rig-chart .chart { height: 230px; }
details.sys { margin-top: 12px; }
details.sys summary { cursor: pointer; color: var(--text-2); font-size: 12px; }
details.sys .kv { margin-top: 10px; max-width: 640px; }
details.sys .kv dd { text-align: left; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 12px; }

/* ---------- problemas ---------- */
.prob-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; }
.prob-count { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.prob-count .n { font-size: 44px; font-weight: 700; line-height: 1; color: var(--red); }
.prob-count .n.zero { color: var(--green); }
.prob-count .label { line-height: 1.3; color: var(--text-2); }
.sev-row { display: grid; grid-template-columns: 70px 1fr 20px; align-items: center; gap: 10px; font-size: 12px; margin-bottom: 8px; }
.sev-row .track { height: 5px; }
.sev-row b { text-align: right; }
.sev { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; padding: 3px 9px; border-radius: 5px; text-transform: uppercase; }
.sev.crit { color: #ff8a8a; background: rgba(240, 82, 82, .14); border: 1px solid rgba(240, 82, 82, .4); }
.sev.high { color: var(--orange); background: rgba(243, 165, 48, .12); border: 1px solid rgba(243, 165, 48, .4); }
.sev.med { color: var(--yellow); background: rgba(245, 197, 66, .1); border: 1px solid rgba(245, 197, 66, .35); }
.sev.info { color: var(--blue); background: rgba(77, 143, 245, .1); border: 1px solid rgba(77, 143, 245, .35); }
tr.p-crit td:first-child { box-shadow: inset 3px 0 0 var(--red); }
tr.p-high td:first-child { box-shadow: inset 3px 0 0 var(--orange); }
tr.p-med td:first-child { box-shadow: inset 3px 0 0 var(--yellow); }
tr.p-info td:first-child { box-shadow: inset 3px 0 0 var(--blue); }
.no-problems { color: var(--green); padding: 18px 0; }

@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .r-main, .r-bottom { grid-template-columns: 1fr; }
  .r-3 { grid-template-columns: 1fr 1fr; }
  .r-3 > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  main, .topbar { padding-left: 16px; padding-right: 16px; }
  .kpis, .r-3, .prob-grid { grid-template-columns: 1fr; }
  .minis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hs { padding: 6px 14px 6px 0; border-left: 0; min-width: 45%; }
  .kpi-value .v { font-size: 28px; }
  .top-right .muted { display: none; }
  /* iOS hace zoom al tocar un campo con letra de menos de 16 px */
  select, input[type="text"], .alert-form input[type="text"], .power-cfg input { font-size: 16px; }
}

/* ---------- moneda y avisos ---------- */
#currency button { font-weight: 600; }
.r-alerts { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.r-alerts[hidden] { display: none; }
.alert-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel-2); }
.alert-form input[type="text"] { font: inherit; font-size: 12.5px; color: var(--text); background: var(--panel); border: 1px solid var(--line-2); border-radius: 6px; padding: 5px 8px; width: 90px; }
.alert-form input[name="note"] { width: 180px; flex: 1; min-width: 120px; }
.alert-form input:focus, select:focus { outline: 1px solid var(--blue); outline-offset: 0; }
.check { display: inline-flex; align-items: center; gap: 5px; color: var(--text-2); font-size: 12.5px; cursor: pointer; }
button.primary { color: #0a0f19; background: var(--lime); border-color: var(--lime); font-weight: 700; }
button.primary:hover { color: #0a0f19; filter: brightness(1.08); }
button.danger:hover { color: var(--red); border-color: var(--red); }
.form-msg { min-height: 18px; margin: 6px 2px 4px; }
.form-msg.err { color: var(--red); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button { font-size: 11.5px; padding: 3px 8px; }
.channels { display: grid; gap: 10px; }
.channel { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel-2); }
.channel b { display: block; }
.channel .muted { font-size: 11.5px; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 240px; overflow-y: auto; }
.events li { border-left: 3px solid var(--orange); padding: 6px 10px; background: var(--panel-2); border-radius: 0 6px 6px 0; font-size: 12px; white-space: pre-line; }
.events li .muted { display: block; font-size: 11px; margin-top: 2px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: 340px; padding: 12px 14px; border-radius: 10px; background: #0a0f19; border: 1px solid var(--orange); box-shadow: 0 10px 30px rgba(0,0,0,.5); font-size: 13px; white-space: pre-line; }
@media (max-width: 1200px) { .r-alerts { grid-template-columns: 1fr; } }

/* ---------- calendario ---------- */
.r-cal { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.cal-title { min-width: 130px; text-align: center; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-grid.year { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cal-dow { font-size: 10.5px; font-weight: 600; letter-spacing: .09em; color: var(--muted); text-transform: uppercase; padding: 0 4px 2px; }
.cal-cell {
  position: relative; min-height: 72px; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2);
  display: flex; flex-direction: column; gap: 2px; overflow: hidden;
}
.cal-grid.year .cal-cell { min-height: 92px; }
.cal-cell.empty { background: transparent; border-color: transparent; }
.cal-cell.est { border-style: dashed; border-color: var(--line-2); background: transparent; }
.cal-cell.today { border-color: var(--lime); box-shadow: inset 0 0 0 1px var(--lime); }
.cal-cell .heat { position: absolute; inset: 0; background: var(--lime); pointer-events: none; }
.cal-cell > *:not(.heat) { position: relative; }
.cal-d { font-size: 11.5px; color: var(--text-2); font-weight: 600; display: flex; justify-content: space-between; }
.cal-d .tag-est { font-size: 9.5px; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.cal-v { font-size: 13.5px; font-weight: 700; margin-top: auto; }
.cal-cell.est .cal-v { color: var(--text-2); }
.cal-m { font-size: 11.5px; color: var(--text-2); }
.cal-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 11.5px; color: var(--text-2); }
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw.est { background: transparent; border: 1px dashed var(--text-2); }
.proj { display: grid; gap: 8px; }
.proj-row { display: grid; grid-template-columns: 70px 1fr auto; align-items: baseline; gap: 10px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel-2); }
.proj-row .label { margin: 0; }
.proj-row .pv { font-size: 17px; font-weight: 700; }
.proj-row .pv small { font-size: 11.5px; color: var(--text-2); font-weight: 500; }
.proj-row .pm { text-align: right; font-weight: 600; white-space: nowrap; }
.proj-row .pm small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }
.power-cfg { display: flex; align-items: center; gap: 8px; margin: 14px 0 6px; font-size: 12.5px; color: var(--text-2); }
.power-cfg input { font: inherit; font-size: 12.5px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 5px 8px; width: 80px; }
@media (max-width: 1200px) { .r-cal { grid-template-columns: 1fr; } }
@media (max-width: 720px) { .cal-cell { min-height: 58px; padding: 5px; } .cal-m { display: none; } .cal-v { font-size: 11.5px; } .cal-grid.year { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- app instalada y móvil ---------- */
.topbar { padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); position: sticky; top: 0; z-index: 5; }
main { padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.chart svg { touch-action: pan-y; }
#install[hidden] { display: none; }

@media (max-width: 720px) {
  body { font-size: 13.5px; }
  /* iOS 26+ difumina con su cristal la franja de debajo de la hora y la batería: el título baja
     lo justo para quedar fuera de ella. */
  .topbar { padding: calc(env(safe-area-inset-top) + 22px) 14px 10px; gap: 8px; }
  .brand .chip, .dot-sep, .brand-sub { display: none; }
  .brand b { font-size: 15px; font-weight: 700; letter-spacing: .04em; }
  .top-right { gap: 8px; width: 100%; justify-content: space-between; flex-wrap: wrap; row-gap: 8px; }
  .top-right > * { flex: none; }
  /* en el iPhone no cabe todo en una línea: la moneda solo con su símbolo */
  .cur-code, .btn-text { display: none; }
  #currency button { padding: 4px 12px; font-size: 14px; }
  .clock { font-size: 13px; padding: 3px 8px; }
  main { padding: 12px 12px max(32px, env(safe-area-inset-bottom)); gap: 12px; }
  .panel { padding: 13px; }
  .host { padding: 13px; }
  .host-name { font-size: 17px; }
  .host-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; gap: 10px 0; }
  .hs { min-width: 0; padding: 0 8px 0 0; }
  .hs-val { font-size: 14px; }
  .kpi { padding: 14px 14px 54px; }
  .kpi-value .v { font-size: 30px; }
  .seg { flex-wrap: wrap; }
  .controls { width: 100%; }
  .rig-chart .controls .seg { width: 100%; }
  .rig-chart .seg button { flex: 1; }
  .chart, .chart.tall, .rig-chart .chart { height: 200px; }
  .donut { width: 150px; height: 150px; margin: 0 auto; }
  .donut-wrap { justify-content: center; }
  .cal-grid { gap: 4px; }
  .cal-cell { min-height: 54px; padding: 4px 5px; border-radius: 6px; }
  .cal-d { font-size: 10.5px; }
  .cal-d .tag-est { display: none; }
  .cal-v { font-size: 11px; }
  .cal-title { min-width: 0; flex: 1; }
  .alert-form > * { flex: 1 1 auto; }
  .alert-form input[type="text"] { width: auto; min-width: 0; }
  .proj-row { grid-template-columns: 58px 1fr auto; padding: 9px 10px; }
  .prob-grid { grid-template-columns: 1fr; }
  .table-wrap.scroll { max-height: none; }

  /* tablas en tarjetas */
  table.rt, table.rt tbody, table.rt tr, table.rt td { display: block; width: 100%; }
  table.rt thead { display: none; }
  table.rt tr { border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 12px; margin-bottom: 8px; background: var(--panel-2); }
  table.rt tbody tr:hover td { background: transparent; }
  table.rt td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); white-space: normal; text-align: right; }
  table.rt td:last-child { border-bottom: 0; }
  table.rt td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; text-align: left; }
  table.rt td[data-label=""]::before { content: none; }
  table.rt td[data-label=""] { justify-content: flex-end; }
  table.rt td:first-child { font-weight: 700; font-size: 14px; }
  table.rt .td-v { min-width: 0; }
  table.rt .cell-bar { justify-content: flex-end; }
  table.rt .ibar { width: 56px; }
  table.rt td.oc { color: var(--text); }
  tr.p-crit, tr.p-high, tr.p-med, tr.p-info { border-left-width: 3px !important; }
  tr.p-crit { border-left-color: var(--red) !important; }
  tr.p-high { border-left-color: var(--orange) !important; }
  tr.p-med { border-left-color: var(--yellow) !important; }
  tr.p-info { border-left-color: var(--blue) !important; }
  table.rt tr td:first-child { box-shadow: none !important; }
}
.proj-row.got { border-left: 3px solid var(--lime); }

/* ---------- paneles plegables ---------- */
.ph-title { cursor: pointer; user-select: none; }
.collapse-btn { position: absolute; right: 0; top: 0; width: 28px; height: 26px; padding: 0; font-size: 13px; line-height: 1; transition: transform .2s; }
.panel-head { padding-right: 38px; min-height: 26px; }
.panel.collapsed .collapse-btn { transform: rotate(-90deg); }
.panel.collapsed > :not(.panel-head) { display: none !important; }
.panel.collapsed .panel-head { margin-bottom: 0; }
.panel.collapsed .panel-head > :not(.ph-title):not(.collapse-btn) { display: none; }
.row > .panel.collapsed { align-self: start; }
.panel-head { position: relative; }


/* ---------- tablero ordenable ---------- */
.board { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; grid-auto-flow: row dense; }
.board > .panel { grid-column: span 6; position: relative; }
.board > .panel[hidden] { display: none; }
.board > .span-2 { grid-column: span 2; }
.board > .span-3 { grid-column: span 3; }
.board > .span-4 { grid-column: span 4; }
.board > .span-6 { grid-column: span 6; }
.board > .panel.collapsed { align-self: start; }
@media (max-width: 1200px) {
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board > .span-2, .board > .span-3 { grid-column: span 1; }
  .board > .span-4, .board > .span-6 { grid-column: span 2; }
}
@media (max-width: 720px) {
  .board { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .board > .panel { grid-column: span 1 !important; }
  .panel-tools [data-size], .panel-tools .drag { display: none; }
}

.panel-tools { display: none; }
body.editing .panel-tools { display: flex; align-items: center; gap: 6px; margin: -4px 0 12px; padding: 6px 8px; border-radius: 7px; background: rgba(197, 232, 58, .08); border: 1px dashed rgba(197, 232, 58, .45); }
body.editing .panel.collapsed > .panel-tools { display: flex !important; }
body.editing .board > .panel { outline: 1px dashed var(--line-2); outline-offset: 3px; }
body.editing .board > .panel[draggable="true"] { cursor: grab; }
.panel-tools .drag { font-size: 18px; color: var(--lime); cursor: grab; padding: 0 4px; line-height: 1; user-select: none; }
.panel-tools button { padding: 3px 10px; font-size: 12px; }
.panel-tools [data-size] { margin-left: auto; min-width: 40px; font-weight: 700; }
.panel.dragging { opacity: .45; outline-color: var(--lime) !important; }
#arrange[hidden] { display: none; }
body.editing #arrange { color: #0a0f19; background: var(--lime); border-color: var(--lime); font-weight: 700; }
.edit-bar {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; width: min(760px, calc(100vw - 24px));
  padding: 10px 14px; border-radius: 10px; background: #0a0f19; border: 1px solid var(--lime); box-shadow: 0 10px 30px rgba(0,0,0,.55); font-size: 12.5px;
}
.edit-bar[hidden] { display: none; }
.edit-actions { display: flex; gap: 8px; margin-left: auto; }
body.editing main { padding-bottom: 120px; }
#layout-default[hidden] { display: none; }
