/* Panel Alfa Green: barra lateral verde profundo, superficie clara con
   leve tinte verde, datos en monoespaciada. */
:root {
  --brand: #1B5E4A;
  --brand-2: #558B2F;
  --lime: #7CB342;
  --bg: #F3F6F4;
  --surface: #FFFFFF;
  --line: #DCE5DF;
  --text: #17231E;
  --muted: #5E6E66;
  --ok: #2E7D32;  --ok-bg: #E3F1E4;
  --warn: #8A5A00; --warn-bg: #FBF0D9;
  --bad: #B3261E;  --bad-bg: #FBE4E2;
  --info: #24527A; --info-bg: #E2ECF5;
  --sans: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--sans); color: var(--text); background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 22px; margin: 0 0 4px; text-wrap: balance; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 14px; margin: 0; }
.muted { color: var(--muted); }
.mono, td.num, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #E8F5E9; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; padding: 0 10px 18px; }
.brand span { color: var(--lime); }
.side a { color: #D6EAD9; text-decoration: none; padding: 8px 10px; border-radius: 6px; }
.side a:hover, .side a.on { background: rgba(255,255,255,.12); color: #fff; }
.side form { margin-top: auto; }
.envtag { font: 11px var(--mono); text-transform: uppercase; letter-spacing: 1px; padding: 4px 10px; border-radius: 4px; background: var(--lime); color: #0F2A20; align-self: flex-start; margin: 0 10px 14px; }
.envtag.prod { background: #F4B4AE; }
main { padding: 28px 32px; min-width: 0; display: flex; flex-direction: column; gap: 22px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel > header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel > .body { padding: 16px 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font: 600 26px var(--mono); }
.kpi .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.body-cell { white-space: pre-wrap; max-width: 460px; font-size: 13px; }

.pill { display: inline-block; font: 600 11px var(--mono); padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.bad { color: var(--bad); background: var(--bad-bg); }
.pill.info { color: var(--info); background: var(--info-bg); }
.pill.off { color: var(--muted); background: var(--bg); }

form.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
input, select, textarea { font: inherit; color: var(--text); background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--lime); outline-offset: 1px; }
fieldset { border: 1px solid var(--line); border-radius: 6px; display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 10px; margin: 0; }
legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.span2 { grid-column: span 2; }
@media (max-width: 700px) { .span2 { grid-column: auto; } }

.btn { font: 600 13px var(--sans); border: 1px solid var(--brand); background: var(--brand); color: #fff; padding: 7px 14px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap; }
.btn:hover { background: #154a3a; }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--ok-bg); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.danger { border-color: var(--bad); background: transparent; color: var(--bad); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
details > summary { cursor: pointer; color: var(--brand); font-weight: 600; padding: 4px 0; }
details[open] > summary { margin-bottom: 12px; }
.sub { border-top: 1px solid var(--line); padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.sub:first-of-type { border-top: 0; }
.subhead { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.meta { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.meta b { color: var(--text); font-weight: 600; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font: 12px var(--mono); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; }
.preview { background: var(--bg); border-radius: 6px; padding: 10px 12px; font-size: 13px; }
.preview:empty { display: none; }
tr.pv td { padding: 0 12px 10px; }
tr.pv:has(.preview:empty) { display: none; }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); padding: 18px; text-align: center; }
.error { color: var(--bad); background: var(--bad-bg); padding: 8px 12px; border-radius: 6px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--brand); }
.login .panel { width: min(360px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }

@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
  .brand { padding: 0 10px 0 0; }
  .side form { margin: 0 0 0 auto; }
  main { padding: 20px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.volume { border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; border-left: 4px solid; }
.volume ul { margin: 6px 0 0; padding-left: 18px; }
.volume.danger { background: var(--bad-bg); border-color: var(--bad); }
.volume.warn { background: var(--warn-bg); border-color: var(--warn); }
.volume.ok { background: var(--ok-bg); border-color: var(--ok); }
.txt-bad { color: var(--bad); }
.txt-warn { color: var(--warn); }
.hint { color: var(--muted); margin: 0 0 12px; max-width: 70ch; }
.panel.attention { border-color: var(--bad); }
.panel.attention > header { background: var(--bad-bg); border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }

/* ---------------------------------------------------------------- v2: componentes */
.small { font-size: 12px; }
.err { color: var(--bad); }
.back { font-size: 13px; text-decoration: none; }
.notes { margin: 8px 0 0; color: var(--muted); max-width: 70ch; white-space: pre-wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.end { align-self: end; }

/* Tooltip: ícono "?" que muestra la explicación con hover o foco de teclado */
.tip { position: relative; display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%;
  font: 600 10px/1 var(--sans); color: var(--brand); background: var(--ok-bg); border: 1px solid #C7DDCD;
  cursor: help; vertical-align: 1px; text-transform: none; letter-spacing: 0; flex: none; }
.tip-body { position: absolute; z-index: 30; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 280px; padding: 8px 10px; border-radius: 6px; background: #17231E; color: #F1F6F3;
  font: 400 12px/1.45 var(--sans); text-align: left; white-space: normal; box-shadow: 0 6px 18px rgba(0,0,0,.18);
  opacity: 0; visibility: hidden; transition: opacity .12s; pointer-events: none; }
.tip-body::after { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: #17231E; }
.tip:hover .tip-body, .tip:focus .tip-body { opacity: 1; visibility: visible; }
.tip:focus { outline: 2px solid var(--lime); outline-offset: 1px; }

/* Avisos de confirmación */
.toasts { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 16px); right: 16px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 8px; background: #17231E; color: #F1F6F3; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); border-left: 4px solid var(--lime); transition: opacity .5s, transform .5s; }
.toast.warn { border-left-color: #E0A526; }
.toast.bad { border-left-color: #E5534B; }
.toast.hide { opacity: 0; transform: translateY(-6px); }

/* Barra de uso diario */
.usage { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.usage-track { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; min-width: 60px; }
.usage-fill { height: 100%; border-radius: 3px; }
.usage-fill.ok { background: var(--lime); } .usage-fill.warn { background: #E0A526; } .usage-fill.bad { background: var(--bad); }
.usage-txt { font-size: 12px; white-space: nowrap; }

/* Bloque de servicio */
.panel.sub { padding: 18px; display: flex; flex-direction: column; gap: 16px; }
.panel.sub h2 { font-size: 17px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 20px;
  background: var(--bg); border-radius: 8px; padding: 12px 14px; }
.kv > div { display: flex; flex-direction: column; gap: 4px; }
.kv .k { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); display: flex; gap: 6px; align-items: center; }

/* Tarjetas de búsqueda */
.clist { display: flex; flex-direction: column; gap: 12px; }
.ccard { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; background: var(--surface); }
.ccard.paused { background: var(--bg); }
.ccard.paused .facts { opacity: .7; }
.ccard.editing { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ok-bg); }
.ccard-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.ccard-title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ccard h4 { margin: 0; font-size: 15px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 18px; margin: 0; }
.facts > div { min-width: 0; } .facts .wide { grid-column: 1 / -1; }
.facts dt { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 2px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.ccard-stats { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: 12px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 10px; }
.stat { cursor: help; } .stat b { color: var(--text); }
.addbox { border: 1px dashed #B9CDBF; border-radius: 8px; padding: 12px 16px; }
.addbox[open] { border-style: solid; }

/* Formularios por secciones */
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: start; }
.fgrid .span2 { grid-column: span 2; } .fgrid .span3 { grid-column: 1 / -1; }
@media (max-width: 700px) { .fgrid .span2 { grid-column: auto; } }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.lbl { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text); }
.lbl label { display: inline; font: inherit; color: inherit; }
.fsec { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px 14px; margin: 0; display: block; }
.fsec > legend { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 0 6px; }
details.fsec > summary { font-size: 13px; color: var(--brand); font-weight: 600; cursor: pointer; }
details.fsec[open] > summary { margin-bottom: 12px; }
input:disabled { background: var(--bg); color: var(--muted); cursor: not-allowed; }

/* Botones de alternancia (condición) */
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggles .tg { position: absolute; opacity: 0; pointer-events: none; }
.toggles .tg + label { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 99px;
  font-size: 13px; color: var(--text); background: #fff; cursor: pointer; user-select: none; }
.toggles .tg:checked + label { background: var(--brand); border-color: var(--brand); color: #fff; }
.toggles .tg:checked + label::before { content: "✓ "; }
.toggles .tg:focus-visible + label { outline: 2px solid var(--lime); outline-offset: 1px; }

/* Barra de filtros de las listas */
.filterbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filterbar input[type=search] { flex: 1 1 220px; min-width: 0; }
.segmented { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { padding: 5px 10px; border-radius: 6px; font-size: 13px; cursor: pointer; color: var(--muted); }
.segmented input:checked + label { background: var(--brand); color: #fff; }
.segmented input:focus-visible + label { outline: 2px solid var(--lime); }
.segmented .count { font: 600 11px var(--mono); opacity: .75; }
.pager { display: flex; gap: 12px; justify-content: center; align-items: center; padding: 12px; border-top: 1px solid var(--line); }
table.list tbody tr:hover { background: #F7FAF8; }
tr.rowlink { cursor: pointer; }
thead th { position: sticky; top: 0; background: var(--surface); }

/* Menú desplegable con formulario (editar cliente, nuevo cliente) */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; } .dropdown > summary::-webkit-details-marker { display: none; }
.editbox { display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 16px; }
.editbox h3 { margin: 0; }
.editbox.pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: min(360px, calc(100vw - 32px));
  box-shadow: 0 12px 30px rgba(0,0,0,.14); }
#sub-edit-1 .editbox, [id^=sub-edit-] .editbox { border-color: var(--brand); }

/* KPIs como enlaces */
a.kpi { color: inherit; text-decoration: none; transition: border-color .12s; }
a.kpi:hover { border-color: var(--brand-2); }
.kpi .l { display: flex; gap: 6px; align-items: center; }
.kpi-bad .v { color: var(--bad); }
.segmented label { white-space: nowrap; display: inline-flex; gap: 6px; align-items: baseline; }
.panel.sub > header.subhead { padding: 0 0 14px; }
