:root {
  --bg: #F3F5F9;
  --panel: #FFFFFF;
  --ink: #15202B;
  --muted: #5B6675;
  --line: #E1E5EC;
  --navy: #0B2545;
  --navy-2: #13315C;
  --accent: #1F5FAD;
  --teal: #34C3A0;
  --green: #1E8E3E;
  --amber: #E8A100;
  --red: #D93025;
  --green-bg: #E6F4EA;
  --amber-bg: #FEF5DC;
  --red-bg: #FCE8E6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); display: flex; min-height: 100vh; font-size: 14px; }
a { color: var(--accent); }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--navy); }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* ---------- layout */
.sidebar { width: 232px; flex: 0 0 232px; background: var(--navy); color: #C9D6E8; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; flex-direction: column; gap: 14px; padding: 20px 16px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo { display: block; width: 100%; max-width: 180px; height: auto; }
.brand-app { border-left: 3px solid var(--teal); padding-left: 9px; }
.brand strong { color: #fff; font-size: 16px; display: block; }
.brand span { font-size: 11px; color: #8FA6C4; }
.sidebar nav { padding: 8px 8px; flex: 1; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6F87A8; padding: 14px 10px 6px; }
.sidebar nav a { display: flex; justify-content: space-between; align-items: center; color: #C9D6E8; text-decoration: none; padding: 9px 10px; border-radius: 7px; margin: 1px 0; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: var(--navy-2); color: #fff; box-shadow: inset 3px 0 0 var(--teal); }
.pill { background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.pill:empty { display: none; }
.sidebar-foot { font-size: 11px; color: #6F87A8; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-foot .logout { color: #8FA6C4; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 28px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { margin: 0; font-size: 20px; color: var(--navy); }
.topbar .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.top-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.badge-synth { font-size: 11px; font-weight: 600; color: #7A5B00; background: var(--amber-bg); border: 1px solid #F3D98A; padding: 4px 9px; border-radius: 20px; }
.view { padding: 22px 28px 40px; max-width: 1500px; width: 100%; }

/* ---------- componentes */
.btn { font: inherit; font-size: 13px; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 7px 13px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn[disabled] { opacity: .5; cursor: default; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.src { font-size: 11px; color: var(--muted); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 4px solid #999; }
.kpi .l { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 26px; font-weight: 700; margin: 4px 0 2px; color: var(--navy); }
.kpi .s { font-size: 11.5px; color: var(--muted); }
.st-verde { border-top-color: var(--green); } .st-ámbar { border-top-color: var(--amber); } .st-rojo { border-top-color: var(--red); }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-box.short { height: 200px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; padding: 8px 8px; border-bottom: 1px solid var(--line); background: #FAFBFD; position: sticky; top: 0; }
td { padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; } tr.click:hover td { background: #F6F9FE; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 460px; overflow-y: auto; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 12px; padding: 2px 9px; border-radius: 20px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.verde { color: var(--green); background: var(--green-bg); }
.status.ámbar { color: #A86F00; background: var(--amber-bg); }
.status.rojo { color: var(--red); background: var(--red-bg); }
.grade { display: inline-block; width: 24px; text-align: center; font-weight: 700; border-radius: 5px; color: #fff; padding: 1px 0; }
.grade.A { background: #1E8E3E; } .grade.B { background: #6BA539; } .grade.C { background: #E8A100; } .grade.D { background: #E8743B; } .grade.F { background: #D93025; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 4px; background: #EEF2F8; color: #3B4A5E; margin: 1px 2px 1px 0; }
.trend-mejora { color: var(--green); } .trend-empeora { color: var(--red); } .trend-estable { color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* semáforo de KRIs */
.kri-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.kri-tile { background: var(--panel); border: 1px solid var(--line); border-left: 6px solid #999; border-radius: 9px; padding: 11px 13px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-height: 140px; }
.kri-tile:hover { box-shadow: 0 4px 14px rgba(16,24,40,.10); }
.kri-tile.verde { border-left-color: var(--green); } .kri-tile.ámbar { border-left-color: var(--amber); } .kri-tile.rojo { border-left-color: var(--red); }
.kri-tile .id { font-size: 11px; font-weight: 700; color: var(--muted); display: flex; justify-content: space-between; }
.kri-tile .name { font-size: 12.5px; line-height: 1.3; min-height: 32px; }
.kri-tile .val { font-size: 21px; font-weight: 700; color: var(--navy); display: flex; align-items: baseline; gap: 8px; }
.kri-tile .val small { font-size: 12px; font-weight: 600; }
.kri-tile canvas { height: 34px !important; width: 100% !important; }

/* mapa de calor */
.heat td, .heat th { text-align: center; padding: 5px 4px; font-size: 12px; }
.heat td:first-child, .heat th:first-child { text-align: left; white-space: nowrap; }
.heat td.c { color: #fff; font-weight: 600; border: 2px solid #fff; border-radius: 4px; }
.heat td.c.verde { background: var(--green); } .heat td.c.ámbar { background: var(--amber); } .heat td.c.rojo { background: var(--red); }
.heat td.sep { border-top: 2px solid var(--line); }

.progress { height: 8px; background: #EDF0F5; border-radius: 6px; overflow: hidden; min-width: 80px; }
.progress span { display: block; height: 100%; background: var(--accent); }
.alert-row.rojo td:first-child { box-shadow: inset 4px 0 0 var(--red); }
.alert-row.ámbar td:first-child { box-shadow: inset 4px 0 0 var(--amber); }
.emerging { display: flex; flex-direction: column; gap: 10px; }
.emerging div { border-left: 3px solid var(--accent); padding: 2px 0 2px 10px; }
.emerging b { display: block; font-size: 13px; }

/* conectores */
.conn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-bottom: 16px; }
.conn { border-top: 4px solid var(--accent); }
.conn.out { border-top-color: var(--teal); }
.conn .mode { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: #EEF2F8; color: #3B4A5E; }
.conn dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 12.5px; margin: 10px 0 0; }
.conn dt { color: var(--muted); }
.conn dd { margin: 0; }
pre.payload { background: #0E1726; color: #D6E2F5; font-size: 11.5px; padding: 10px 12px; border-radius: 7px; overflow: auto; max-height: 280px; margin: 6px 0 0; }
details summary { cursor: pointer; }
.switch { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .toolbar select, .form input, .form select { font: inherit; padding: 6px 9px; border: 1px solid #C9D1DD; border-radius: 6px; background: #fff; }
.callout { background: #EEF4FC; border: 1px solid #CFE0F5; border-radius: 8px; padding: 10px 14px; font-size: 13px; color: #24425F; margin-bottom: 16px; }

/* modal y avisos */
.modal { position: fixed; inset: 0; background: rgba(11, 22, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 20; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 12px; width: min(980px, 100%); padding: 22px 24px; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-x { position: absolute; top: 10px; right: 12px; border: none; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; align-items: end; }
.form label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 30; }
.toast { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: 13px; max-width: 360px; animation: fade .25s ease; }
.toast.rojo { background: var(--red); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1100px) {
  .g3, .g-2-1 { grid-template-columns: minmax(0, 1fr); }
  .kri-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  body { flex-direction: column; }
  .sidebar { position: static; width: 100%; height: auto; flex: none; }
  .brand { flex-direction: row; align-items: center; justify-content: space-between; }
  .brand-logo { max-width: 140px; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-group, .sidebar-foot { display: none; }
  .g2 { grid-template-columns: minmax(0, 1fr); }
  .topbar { position: static; flex-direction: column; align-items: flex-start; padding: 14px 16px; }
  .view { padding: 16px; }
  .form { grid-template-columns: 1fr; }
  .kri-grid { grid-template-columns: minmax(0, 1fr); }
}
@media print {
  .sidebar, .top-actions { display: none; }
}

/* recorrido SDP */
.sidebar nav a.nav-tour { background: rgba(52,195,160,.14); color: #fff; font-weight: 600; margin: 6px 0 2px; }
.case-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.case { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.case-head { display: flex; justify-content: space-between; align-items: center; }
.case-n { font-weight: 700; font-size: 12px; color: #fff; background: var(--navy-2); border-radius: 6px; padding: 2px 8px; }
.case h3.case-q { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--navy); margin: 0; }
.case-a { margin: 0; font-size: 13px; color: #33404F; flex: 1; }
.case-actions { display: flex; gap: 8px; flex-wrap: wrap; }
a.btn { text-decoration: none; display: inline-block; }

/* simulador e interrupción */
.sim-controls { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 1fr; gap: 12px 16px; align-items: end; }
.sim-controls label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.sim-controls select, .sim-controls input[type=number] { font: inherit; padding: 6px 9px; border: 1px solid #C9D1DD; border-radius: 6px; background: #fff; }
.sim-controls input[type=range] { accent-color: var(--accent); }
.sim-controls b { color: var(--navy); }
.seg { display: inline-flex; border: 1px solid #C9D1DD; border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg a { padding: 6px 12px; font-size: 13px; color: var(--ink); text-decoration: none; border-right: 1px solid #E1E5EC; background: #fff; }
.seg a:last-child { border-right: none; }
.seg a.on { background: var(--navy-2); color: #fff; }
@media (max-width: 1100px) { .sim-controls { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) { .sim-controls { grid-template-columns: 1fr; } .case-grid { grid-template-columns: 1fr; } }
#s-kpis .kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
#s-kpis .kpi .v { font-size: 22px; }
