/* UYARIQ SALUD · Torre de control (desktop, sala de control oscura) */

body.app-torre {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
  background:
    radial-gradient(800px 400px at 100% 0%, rgba(30, 139, 148, .08), transparent 60%),
    var(--bg);
}

/* ---------- Sidebar ---------- */
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.side .brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--petrol-700); display: grid; place-items: center; flex: none; }
.side .brand-name { font-family: var(--font-display); font-weight: 800; font-size: 15px; }
.side .brand-name span { color: var(--petrol-300); font-weight: 400; }
.side .brand-sub { font-size: 9.5px; color: var(--muted); letter-spacing: .09em; text-transform: uppercase; font-weight: 700; }

.side .sec { font-size: var(--fs-micro); font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }

.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--petrol-300); }
.nav-item .n-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-item .n-flag {
  margin-left: auto; font-size: 10px; font-weight: 700;
  background: var(--crit); color: #fff; border-radius: var(--r-pill);
  min-width: 17px; height: 17px; display: grid; place-items: center; padding: 0 5px;
}

.side .foot { margin-top: auto; padding: 10px; font-size: var(--fs-micro); color: var(--muted); border-top: 1px solid var(--line); }
.side .foot a { color: var(--petrol-300); text-decoration: none; font-weight: 700; }

/* ---------- Zona principal ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 28px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); z-index: 30;
}
.topbar h1 { font-size: 19px; }
.topbar .estab {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 7px 16px; font-size: var(--fs-small); font-weight: 650;
}
.topbar .estab .e-dot { color: var(--ok); font-size: 10px; }
.topbar .fecha { font-size: var(--fs-small); color: var(--muted); }

.content { padding: 26px 28px 60px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- KPIs héroe ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi { padding: 18px; position: relative; overflow: hidden; }
.kpi .k-label { font-size: var(--fs-micro); font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); }
.kpi .k-value { font-family: var(--font-display); font-weight: 800; font-size: 34px; margin: 8px 0 2px; }
.kpi .k-value .unit { font-size: 16px; color: var(--ink-2); font-weight: 600; }
.kpi .k-delta { font-size: var(--fs-small); font-weight: 650; display: flex; align-items: center; gap: 5px; }
.kpi .k-delta.good { color: var(--ok); }
.kpi .k-delta.bad { color: var(--crit); }
.kpi .k-delta .vs { color: var(--muted); font-weight: 500; }
.kpi::after {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--brand); opacity: .65;
}
.kpi.k-gamify::after { background: var(--gamify); }

/* ---------- Paneles ---------- */
.panel-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 14px; align-items: start; }
.panel h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.panel h3 .p-icon { font-size: 17px; }

.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 11px 14px; font-size: var(--fs-small);
}
.alert-item .a-txt { flex: 1; }
.alert-item .a-txt strong { display: block; font-size: var(--fs-body); }
.alert-item .a-txt span { color: var(--ink-2); }
.alert-item .btn { flex: none; }

.goals-panel .goalbar { margin-bottom: 14px; }
.goals-panel .gb-note { font-size: var(--fs-micro); color: var(--muted); margin-top: -6px; margin-bottom: 12px; }

/* ---------- Tablas de datos ---------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  font-size: var(--fs-micro); font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--baseline, var(--line));
}
.data-table td { padding: 10px; font-size: var(--fs-small); border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .t-strong { font-weight: 700; color: var(--ink); }
.data-table .t-sub { font-size: var(--fs-micro); color: var(--muted); display: block; }

/* ---------- Heatmap ---------- */
.heat { display: grid; gap: 3px; margin-top: 6px; }
.ht-col, .ht-row { font-size: var(--fs-micro); color: var(--muted); font-weight: 650; display: flex; align-items: center; }
.ht-col { justify-content: center; padding-bottom: 2px; }
.ht-row { padding-right: 8px; justify-content: flex-end; text-align: right; }
.ht-cell {
  aspect-ratio: 1.6; border-radius: 4px; display: grid; place-items: center;
  font-size: 10px; font-weight: 800; color: #fff;
  transition: transform .12s var(--ease-out);
}
.ht-cell:hover { transform: scale(1.12); outline: 1.5px solid var(--brand); }
.ht-cell.full { outline: 1.5px solid var(--gamify); color: var(--gamify); }
.ht-legend { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: var(--fs-micro); color: var(--muted); }
.ht-scale { width: 110px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, rgba(30,139,148,.08), rgba(30,139,148,.9)); }
.ht-full { margin-left: auto; color: var(--gamify); font-weight: 700; }

/* ---------- Barras horizontales ---------- */
.chart-barsh { display: flex; flex-direction: column; gap: 9px; }
.cb-row { display: grid; grid-template-columns: 150px 1fr 52px; align-items: center; gap: 10px; }
.cb-label { font-size: var(--fs-small); color: var(--ink-2); }
.cb-track { height: 12px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.cb-fill { height: 100%; border-radius: 4px 0 0 4px; background: var(--brand); }
.cb-fill.warn { background: var(--warn); } .cb-fill.crit { background: var(--crit); }
.cb-val { font-size: var(--fs-small); font-weight: 700; text-align: right; }

/* ---------- Scatter ---------- */
.chart-scatter { width: 100%; height: auto; }
.chart-scatter .sc-label { font-size: 11px; fill: var(--ink-2); font-weight: 600; }
.chart-scatter .sc-axis { font-size: 10.5px; fill: var(--muted); letter-spacing: .04em; }
.chart-scatter .sc-ref { font-size: 10px; fill: var(--muted); text-anchor: end; }
.flag-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 8px; font-size: var(--fs-micro); color: var(--ink-2); }
.flag-legend .fl { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; }
.fl-sq { width: 11px; height: 11px; border-radius: 2px; background: var(--crit); }
.fl-tr { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 11px solid var(--warn); }
.fl-ci { width: 11px; height: 11px; border-radius: 50%; background: var(--brand); }

/* ---------- Kanban (ruta oncológica) ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; align-items: start; }
.kb-col { background: var(--surface-2); border-radius: var(--r-md); padding: 10px; }
.kb-head { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 8px; }
.kb-title { font-size: var(--fs-micro); font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-2); }
.kb-n { font-size: var(--fs-micro); color: var(--muted); font-weight: 700; }
.kb-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 10px 11px; margin-bottom: 8px; font-size: var(--fs-small);
}
.kb-card .kb-id { font-weight: 700; color: var(--ink); }
.kb-card .kb-dias { display: block; font-size: var(--fs-micro); color: var(--muted); margin-top: 2px; }
.kb-card.exced { border-color: var(--crit); }
.kb-card .btn { margin-top: 8px; width: 100%; }

/* ---------- Ranking (comité) ---------- */
.rk-medal { font-size: 17px; width: 26px; display: inline-block; }
.rk-delta { font-weight: 700; font-size: var(--fs-micro); }
.rk-delta.up { color: var(--ok); } .rk-delta.down { color: var(--crit); }
tr.rk-yo td { background: var(--brand-soft); }
tr.rk-yo td:first-child { border-radius: var(--r-sm) 0 0 var(--r-sm); }
tr.rk-yo td:last-child { border-radius: 0 var(--r-sm) var(--r-sm) 0; }

/* ---------- Mini-KPIs dentro de paneles ---------- */
.mini-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.mini-kpi { background: var(--surface-2); border-radius: var(--r-sm); padding: 12px; }
.mini-kpi .mk-v { font-family: var(--font-display); font-weight: 800; font-size: 23px; }
.mini-kpi .mk-k { font-size: var(--fs-micro); color: var(--muted); margin-top: 2px; }

.panel-note { font-size: var(--fs-micro); color: var(--muted); margin-top: 10px; }

/* ---------- Sparkline en KPI ---------- */
.kpi-spark { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.kpi-spark span { font-size: 9.5px; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; font-weight: 650; }

/* ---------- Mapa de demanda y expansión ---------- */
.exp-map { width: 100%; max-width: 680px; height: auto; margin: 4px auto 0; display: block; }
.exp-map .em-d { stroke: var(--bg); stroke-width: 2; stroke-linejoin: round; transition: filter .15s; }
.exp-map .em-d:hover { filter: brightness(1.35); }
.exp-map .em-ocean { font-size: 11px; fill: var(--muted); letter-spacing: .22em; font-weight: 650; opacity: .7; }
.exp-map .em-name { font-size: 11.5px; fill: var(--ink); font-weight: 700; pointer-events: none; }
.exp-map .em-pct { fill: var(--ink-2); font-weight: 800; }
.exp-map .rm-pt circle { stroke: var(--surface); stroke-width: 2; }
.exp-map .rm-pt circle[stroke='var(--gamify)'] { stroke: var(--gamify); }
.exp-map .em-plus { font-size: 13px; font-weight: 800; fill: var(--gamify); text-anchor: middle; }
.exp-map .em-site-lbl { font-size: 11px; font-weight: 700; fill: var(--gamify); text-anchor: middle; }
.exp-map .em-site circle { animation: site-pulse 2.2s infinite; transform-origin: center; transform-box: fill-box; }
@keyframes site-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.em-grad { width: 64px; height: 10px; border-radius: 5px; display: inline-block; background: linear-gradient(90deg, rgba(30,139,148,.12), rgba(30,139,148,.68)); }
.em-dash { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 2px dashed var(--gamify); }

/* ---------- Sectores (mini-mapa esquemático) ---------- */
.sector-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.sector { border-radius: var(--r-sm); padding: 10px 6px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.sector .sg-n { font-family: var(--font-display); font-weight: 800; font-size: 20px; }
.sector .sg-l { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-2); }
.sector.s-crit { background: var(--crit-bg); } .sector.s-crit .sg-n { color: var(--crit); }
.sector.s-warn { background: var(--warn-bg); } .sector.s-warn .sg-n { color: var(--warn); }
.sector.s-ok { background: var(--ok-bg); } .sector.s-ok .sg-n { color: var(--ok); }
.pill-count {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border-radius: var(--r-pill);
  padding: 4px 12px; font-size: var(--fs-micro); font-weight: 700; color: var(--ink-2);
}

@media (max-width: 1000px) {
  body.app-torre { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .side .sec, .side .foot { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .panel-grid, .kanban, .mini-kpis { grid-template-columns: 1fr; }
  .cb-row { grid-template-columns: 110px 1fr 48px; }
}
