/* NexaKeys Admin. Misma base que cliente/css/styles.css */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

/* Tokens: claro */
:root {
  color-scheme: light;
  --bg:        #f3f1ec;
  --surface:   #fbfaf7;
  --surface-2: #eeebe4;
  --surface-3: #e5e1d8;
  --line:      #dfdace;
  --line-2:    #cbc5b6;
  --ink:       #1b1a16;
  --ink-2:     #565248;
  --ink-3:     #858073;

  --accent:      #4f7a12;   /* texto y marcas */
  --accent-ink:  #1b2a05;   /* texto sobre --accent-fill */
  --accent-fill: #c8ec6a;   /* botón primario, resaltado */
  --accent-soft: #e6f3c4;

  --crit: #c2412f;  --crit-soft: #f6dfd9;
  --high: #c06a12;  --high-soft: #f6e5cf;
  --warn: #9a7a00;  --warn-soft: #f1ead0;
  --ok:   #2c7a46;  --ok-soft:   #dcefe1;
  --info: #3a6fb5;  --info-soft: #dde7f4;

  --bar:       #4f7a12;
  --bar-muted: #cfd6bf;
  --spark:     #565248;

  --shadow: 0 1px 0 rgba(27,26,22,.04), 0 8px 24px -12px rgba(27,26,22,.18);
  --overlay: rgba(27,26,22,.36);

  --sidebar-w: 232px;
  --topbar-h:  56px;
  --r:   6px;
  --r-lg: 10px;

  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

/* Tokens: oscuro */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        #11110f;
    --surface:   #191916;
    --surface-2: #21201c;
    --surface-3: #2a2924;
    --line:      #2c2b26;
    --line-2:    #3b3a33;
    --ink:       #edece6;
    --ink-2:     #b0aea3;
    --ink-3:     #7d7b71;
    --accent:      #b9e05a;
    --accent-ink:  #172204;
    --accent-fill: #b9e05a;
    --accent-soft: #283415;
    --crit: #ee6b5a;  --crit-soft: #3a1c17;
    --high: #f0a050;  --high-soft: #3a2914;
    --warn: #dcc054;  --warn-soft: #34301a;
    --ok:   #62c283;  --ok-soft:   #16301f;
    --info: #78a8ea;  --info-soft: #182840;
    --bar:       #b9e05a;
    --bar-muted: #3a4126;
    --spark:     #b0aea3;
    --shadow: 0 1px 0 rgba(0,0,0,.3), 0 12px 32px -12px rgba(0,0,0,.6);
    --overlay: rgba(0,0,0,.55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #11110f;
  --surface:   #191916;
  --surface-2: #21201c;
  --surface-3: #2a2924;
  --line:      #2c2b26;
  --line-2:    #3b3a33;
  --ink:       #edece6;
  --ink-2:     #b0aea3;
  --ink-3:     #7d7b71;
  --accent:      #b9e05a;
  --accent-ink:  #172204;
  --accent-fill: #b9e05a;
  --accent-soft: #283415;
  --crit: #ee6b5a;  --crit-soft: #3a1c17;
  --high: #f0a050;  --high-soft: #3a2914;
  --warn: #dcc054;  --warn-soft: #34301a;
  --ok:   #62c283;  --ok-soft:   #16301f;
  --info: #78a8ea;  --info-soft: #182840;
  --bar:       #b9e05a;
  --bar-muted: #3a4126;
  --spark:     #b0aea3;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 12px 32px -12px rgba(0,0,0,.6);
  --overlay: rgba(0,0,0,.55);
}

/* Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
svg.i { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.ink-2 { color: var(--ink-2); }
.hidden { display: none !important; }
::selection { background: var(--accent-fill); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 2px solid var(--bg); }

.eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}

/* Login */
.login {
  position: fixed; inset: 0; z-index: 100;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.login-side {
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  padding: 40px;
  display: flex; flex-direction: column; justify-content: space-between;
  overflow: hidden;
}
.login-ledger { font-family: var(--mono); font-size: 12px; color: var(--ink-3); line-height: 2; }
.login-ledger div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line-2); max-width: 360px; }
.login-ledger b { color: var(--ink); font-weight: 500; }
.login-main { display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 22px; font-weight: 600; letter-spacing: -.01em; margin: 18px 0 4px; }
.login-card p { color: var(--ink-2); margin-bottom: 24px; }
.login-error { margin-top: 12px; padding: 10px 12px; border-radius: var(--r); background: var(--crit-soft); color: var(--crit); font-size: 13px; }

/* Marca */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -.01em; font-size: 15px; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; display: block; flex: none; }
.brand-mark.lg { width: 44px; height: 44px; border-radius: 11px; }
.brand-name { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name small { font-family: var(--mono); font-size: 9.5px; font-weight: 500; letter-spacing: .16em; color: var(--ink-3); margin-top: 2px; }

/* Layout */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 16px 12px;
}
.sidebar .brand { padding: 4px 8px 20px; }
.nav { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; }
.nav .eyebrow { padding: 16px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: var(--r);
  color: var(--ink-2); font-weight: 500; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--surface-3); color: var(--ink); }
.nav-item.active svg { color: var(--accent); }
.nav-count {
  margin-left: auto; font-family: var(--mono); font-size: 11px;
  padding: 0 6px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2);
}
.nav-count.crit { background: var(--crit); color: #fff; }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; align-items: center; gap: 10px; }
.sidebar-foot .who { flex: 1; min-width: 0; }
.sidebar-foot .who div:first-child { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.menu-btn { display: none; }
.search-trigger {
  display: flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 10px; min-width: 260px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  color: var(--ink-3);
}
.search-trigger:hover { border-color: var(--line-2); }
.search-trigger span { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
kbd {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-3);
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px;
  background: var(--surface-2);
}
.topbar-spacer { flex: 1; }

.content { padding: 24px; max-width: 1400px; width: 100%; }
.page { display: none; }
.page.active { display: block; animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.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; font-weight: 600; letter-spacing: -.015em; }
.page-head p { color: var(--ink-2); margin-top: 2px; }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Controles */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px; border-radius: var(--r);
  font-weight: 500; white-space: nowrap;
  border: 1px solid var(--line-2); background: var(--surface);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent-fill); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent-fill) 88%, var(--ink)); }
.btn-danger { color: var(--crit); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 34px; padding: 0; }
.btn-sm.btn-icon { width: 28px; }
.btn-block { width: 100%; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 2px; }
.seg button { height: 28px; padding: 0 10px; border-radius: 4px; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.input, select.input, textarea.input {
  height: 36px; padding: 0 11px; width: 100%;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r);
  outline: none;
}
textarea.input { height: auto; padding: 8px 11px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.num { text-align: right; }
.input-sm { height: 30px; font-size: 13px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-wrap { position: relative; }
.input-wrap svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.input-wrap .input { padding-left: 32px; }
.input-affix { display: flex; align-items: stretch; }
.input-affix span {
  display: grid; place-items: center; padding: 0 10px;
  border: 1px solid var(--line-2); border-right: 0; border-radius: var(--r) 0 0 var(--r);
  background: var(--surface-2); color: var(--ink-3); font-family: var(--mono); font-size: 12px;
  white-space: nowrap;
}
.input-affix .input { border-radius: 0 var(--r) var(--r) 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; padding: 0 11px; border-radius: 99px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); font-size: 13px;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Superficies */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 0; }
.card-head h2 { font-size: 14px; font-weight: 600; }
.card-head .sub { color: var(--ink-3); font-size: 12.5px; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-half { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mt { margin-top: 16px; }

/* Franja Intexa */
.reserve {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.4fr);
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
  margin-bottom: 16px;
}
.reserve > div { padding: 16px 18px; border-right: 1px solid var(--line); min-width: 0; }
.reserve > div:last-child { border-right: 0; }
.reserve .big { font-family: var(--mono); font-size: 24px; font-weight: 500; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.reserve .big.neg { color: var(--crit); }
.reserve .note { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.gauge { height: 10px; border-radius: 3px; background: var(--surface-2); display: flex; gap: 2px; overflow: hidden; margin: 12px 0 8px; }
.gauge i { display: block; height: 100%; }
.gauge .g-cli { background: var(--ink-2); border-radius: 3px 0 0 3px; }
.gauge .g-free { background: var(--bar); border-radius: 0 3px 3px 0; }
.gauge-legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.gauge-legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; background: var(--c); }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); margin-bottom: 16px; }
/* Selector de período (Resumen y Finanzas) */
.periodo { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.periodo-rango { display: flex; align-items: center; gap: 6px; }
/* Estado de resultados (Finanzas) */
.fin { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.fin td { padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.fin td.r { text-align: right; font-family: var(--mono); white-space: nowrap; padding-left: 12px; }
.fin tr.sec td { padding-top: 20px; border-bottom: 0; font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.fin tr.sec:first-child td { padding-top: 0; }
.fin tr.total td { font-weight: 600; }
.fin tr.big td { font-size: 15px; font-weight: 600; border-bottom: 2px solid var(--ink); }
.fin .det { display: block; margin-top: 2px; font-size: 12px; color: var(--ink-3); }
.fin .pos { color: var(--ok); } .fin .neg { color: var(--crit); }
.kpis.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { padding: 14px 16px 12px; border-right: 1px solid var(--line); min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi .val { font-family: var(--mono); font-size: 22px; font-weight: 500; letter-spacing: -.02em; margin: 6px 0 2px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--ink-3); }
.kpi svg.spark { width: 72px; height: 22px; flex: none; }
.delta { font-family: var(--mono); font-size: 11.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 2px; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--crit); }
.delta.flat { color: var(--ink-3); }

/* Gráfico */
.chart { position: relative; height: 240px; margin-top: 8px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .axis text { fill: var(--ink-3); font-family: var(--mono); font-size: 10.5px; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .base-line { stroke: var(--line-2); stroke-width: 1; }
.chart .bar { fill: var(--bar); }
.chart .bar.dim { fill: var(--bar-muted); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:hover + .bar, .chart .bar.hl { fill: var(--ink); }
.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--ink); color: var(--bg);
  border-radius: var(--r); padding: 8px 10px; font-size: 12px; min-width: 150px;
  box-shadow: var(--shadow); transform: translate(-50%, calc(-100% - 10px));
  white-space: nowrap;
}
.tip b { display: block; font-family: var(--mono); font-weight: 500; font-size: 11px; opacity: .7; margin-bottom: 4px; }
.tip div { display: flex; justify-content: space-between; gap: 16px; }
.tip .num { font-weight: 500; }

/* Alertas */
.alerts { display: flex; flex-direction: column; }
.alert { display: grid; grid-template-columns: 4px 1fr; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.alert:first-child { border-top: 0; }
.alert .stripe { border-radius: 4px; background: var(--c); }
.alert .lvl { display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--c); font-weight: 600; }
.alert h3 { font-size: 13.5px; font-weight: 600; margin: 2px 0; }
.alert p { color: var(--ink-2); font-size: 12.5px; }
.alert .who { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.alert .who button { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); }
.alert .who button:hover { border-color: var(--line-2); background: var(--surface-3); }
.lv-critico { --c: var(--crit); }
.lv-alto { --c: var(--high); }
.lv-aviso { --c: var(--warn); }
.lv-info { --c: var(--info); }
.alerts-empty { padding: 28px 16px; text-align: center; color: var(--ink-3); }
.alerts-empty svg { width: 22px; height: 22px; color: var(--ok); margin-bottom: 6px; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3);
  padding: 10px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--surface);
}
th.r, td.r { text-align: right; }
td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, td .num { font-size: 13px; }
td.num, td.r, td .num { white-space: nowrap; }
.who-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-cell .t { min-width: 0; }
.who-cell .t div:first-child { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.who-cell .t div:last-child { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
.avatar {
  width: 30px; height: 30px; border-radius: 6px; flex: none;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--ink-2);
  font-family: var(--mono); font-size: 11px; font-weight: 600;
}
.avatar.lg { width: 44px; height: 44px; font-size: 15px; border-radius: 8px; }
.inline-bar { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.inline-bar .track { width: 70px; height: 6px; border-radius: 2px; background: var(--surface-2); overflow: hidden; flex: none; }
.inline-bar .track i { display: block; height: 100%; background: var(--bar); border-radius: 2px; }
.toolbar { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.toolbar .input-wrap { flex: 1; min-width: 200px; max-width: 360px; }
.toolbar .spacer { flex: 1; }
.toolbar select.input, .toolbar input[type="date"] { width: auto; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 12.5px; }
.pager .btns { display: flex; gap: 6px; }
.empty { padding: 40px 16px; text-align: center; color: var(--ink-3); }
.empty svg { width: 24px; height: 24px; margin-bottom: 8px; }
.empty strong { display: block; color: var(--ink-2); font-weight: 500; margin-bottom: 2px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 8px; border-radius: 4px;
  font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.crit { background: var(--crit-soft); color: var(--crit); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.mono { font-family: var(--mono); font-size: 11.5px; }
.tag { font-family: var(--mono); font-size: 11.5px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--ink-2); white-space: nowrap; }

/* Drawer (ficha de cliente) */
.scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .18s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 41;
  width: min(560px, 100vw);
  background: var(--bg); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .22s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.drawer-head .top { display: flex; gap: 12px; align-items: flex-start; }
.drawer-head h2 { font-size: 17px; font-weight: 600; }
.drawer-head .meta { color: var(--ink-3); font-size: 12.5px; }
.drawer-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 20px 32px; }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.facts > div { padding: 12px 14px; border-right: 1px solid var(--line); min-width: 0; }
.facts > div:last-child { border-right: 0; }
.facts .v { font-family: var(--mono); font-size: 17px; font-weight: 500; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 8px; }
.section-title h3 { font-size: 13px; font-weight: 600; }
.mini-chart { height: 90px; }
.list { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.list-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--line); font-size: 13px; }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 20px 0 12px; }
.tabs button { padding: 8px 12px; color: var(--ink-3); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-color: var(--ink); }

/* Modal */
.modal-bg { position: fixed; inset: 0; z-index: 60; background: var(--overlay); display: none; align-items: flex-start; justify-content: center; padding: 10vh 16px 16px; overflow-y: auto; }
.modal-bg.open { display: flex; }
.modal { width: 100%; max-width: 460px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); animation: rise .18s ease-out; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.callout { padding: 10px 12px; border-radius: var(--r); background: var(--surface-2); font-size: 13px; color: var(--ink-2); margin-bottom: 14px; }
.callout strong { color: var(--ink); }
.calc { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-3); margin-top: -6px; margin-bottom: 14px; }

/* Paleta de comandos */
.cmd-bg { position: fixed; inset: 0; z-index: 70; background: var(--overlay); display: none; justify-content: center; padding: 12vh 16px 16px; }
.cmd-bg.open { display: flex; }
.cmd { width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; align-self: flex-start; }
.cmd-input { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.cmd-input input { flex: 1; height: 50px; border: 0; outline: none; background: transparent; font-size: 15px; }
.cmd-list { max-height: 360px; overflow-y: auto; padding: 6px; }
.cmd-group { padding: 8px 10px 4px; }
.cmd-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: var(--r); text-align: left; }
.cmd-item .grow { flex: 1; min-width: 0; }
.cmd-item .sub { font-size: 12px; color: var(--ink-3); }
.cmd-item.sel { background: var(--surface-2); }
.cmd-foot { display: flex; gap: 14px; padding: 8px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-3); }

/* Toast */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--r); background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: 13px; animation: rise .2s ease-out; max-width: calc(100vw - 32px); }
.toast.err svg { color: var(--crit); }
.toast.ok svg { color: var(--accent-fill); }

/* Auditoría */
.timeline { padding: 4px 16px; }
.tl-row { display: grid; grid-template-columns: 120px 1fr; gap: 16px; padding: 12px 0; border-bottom: 1px dashed var(--line-2); }
.tl-row:last-child { border-bottom: 0; }
.tl-row .when { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.tl-row .what { font-size: 13px; }
.tl-row .what .tag { margin-right: 6px; }
.tl-row .detail { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; }

/* Ajustes */
.kv { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { font-family: var(--mono); text-align: right; }
.status-line { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--r); font-size: 13px; margin-bottom: 14px; }
.status-line.ok { background: var(--ok-soft); color: var(--ok); }
.status-line.crit { background: var(--crit-soft); color: var(--crit); }
.status-line.warn { background: var(--warn-soft); color: var(--warn); }

/* Skeleton */
.sk { display: block; height: 12px; border-radius: 3px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite linear; }
@keyframes sk { to { background-position: -200% 0; } }

/* Responsive */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #kpis .kpi:nth-child(3) { border-right: 0; }
  #kpis .kpi:nth-child(n+4) { border-top: 1px solid var(--line); }
  .reserve { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .reserve > div:nth-child(3) { border-right: 0; }
  .reserve > div:last-child { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .g-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-btn { display: inline-flex; }
  .g-half { grid-template-columns: minmax(0, 1fr); }
  .search-trigger { min-width: 0; flex: 1; }
  .search-trigger kbd { display: none; }
  .login { grid-template-columns: 1fr; }
  .login-side { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 0 16px; gap: 8px; }
  .content { padding: 16px; }
  .kpis, .kpis.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #fin-grid { grid-template-columns: 1fr !important; }
  .periodo { justify-content: flex-start; }
  .kpi { border-right: 1px solid var(--line) !important; border-top: 1px solid var(--line); }
  /* "of .kpi": en #propias el primer hijo es el título, no una tarjeta */
  .kpi:nth-child(-n+2 of .kpi) { border-top: 0; }
  .kpi:nth-child(2n of .kpi) { border-right: 0 !important; }
  #kpis .kpi:nth-child(5) { grid-column: 1 / -1; border-right: 0 !important; }   /* la 5.ª no queda sola con un hueco */
  .kpi .val { font-size: 19px; }
  .kpi svg.spark { display: none; }   /* sin espacio para el minigráfico: el texto se partía en tres líneas */
  .seg { max-width: 100%; overflow-x: auto; }
  .seg button { white-space: nowrap; flex: none; }
  .reserve { grid-template-columns: 1fr; }
  .reserve > div { border-right: 0 !important; border-top: 1px solid var(--line); }
  .reserve > div:first-child { border-top: 0; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .facts > div:nth-child(2) { border-right: 0; }
  .facts > div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .row { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 19px; }
  .tl-row { grid-template-columns: 1fr; gap: 2px; }
  .hide-sm { display: none; }
  .inline-bar .track { display: none; }
  .list-row { flex-wrap: wrap; row-gap: 4px; }
  .search-trigger { min-width: 0; }
  th, td { padding: 9px 12px; }
}

/* Servicios: filtro y separadores por pestaña */
.srv-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 13px; }
.srv-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.srv-bar .i { width: 14px; height: 14px; vertical-align: -2px; }
.srv-grupo td { background: var(--surface-2); font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); padding-top: 8px; padding-bottom: 8px; }
