:root {
  --bg: #0b0f1a;
  --bg-2: #111827;
  --panel: #151c2c;
  --panel-2: #1b2233;
  --border: #232c40;
  --text: #e6ebf5;
  --muted: #8a95ab;
  --brand: #4f8cff;
  --brand-2: #7c5cff;
  --green: #2ecc71;
  --blue: #3aa0ff;
  --amber: #f5b301;
  --red: #ff5c6c;
  --gray: #6b7280;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
a { color: var(--brand); text-decoration: none; }

/* LOGIN */
.login-screen { height: 100vh; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 30% -10%, #1b2748 0%, var(--bg) 55%); }
.login-card { width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 34px; box-shadow: var(--shadow); }
.brand-mark { font-size: 26px; font-weight: 800; letter-spacing: 1px; }
.brand-mark span { color: var(--brand); }
.login-sub { color: var(--muted); margin: 4px 0 22px; font-size: 14px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.login-card input { width: 100%; padding: 11px 12px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 14px; }
.login-card button { width: 100%; margin-top: 20px; padding: 12px; border: 0; border-radius: 10px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 700;
  cursor: pointer; font-size: 15px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 16px; }
.login-foot { color: var(--muted); font-size: 12px; margin-top: 20px; text-align: center; }

/* APP LAYOUT */
.app { display: grid; grid-template-columns: 244px 1fr; height: 100vh; }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); display: flex;
  flex-direction: column; padding: 18px 12px; }
.logo { font-weight: 800; font-size: 18px; letter-spacing: .5px; padding: 6px 10px 18px; }
.logo span { color: var(--brand); }
.logo small { display: block; color: var(--muted); font-weight: 500; font-size: 11px; letter-spacing: 1px; }
#nav { flex: 1; overflow-y: auto; }
.nav-group { color: var(--muted); font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase;
  padding: 16px 12px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px;
  color: var(--text); cursor: pointer; font-size: 14px; opacity: .82; }
.nav-item:hover { background: var(--panel); opacity: 1; }
.nav-item.active { background: linear-gradient(90deg, rgba(79,140,255,.18), rgba(124,92,255,.06));
  opacity: 1; box-shadow: inset 2px 0 0 var(--brand); }
.nav-item .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; }
.freshness { font-size: 11px; color: var(--muted); padding: 4px 8px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; width: 100%; }
.btn-ghost:hover { color: var(--text); border-color: var(--brand); }

.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px;
  border-bottom: 1px solid var(--border); background: var(--bg); }
.crumbs { font-size: 18px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.global-search { position: relative; }
.global-search input { width: 280px; padding: 9px 12px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-size: 13px; }
.gsearch-results { position: absolute; top: 42px; left: 0; right: 0; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px; max-height: 380px; overflow-y: auto; z-index: 40;
  box-shadow: var(--shadow); }
.gsearch-results .r { padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.gsearch-results .r:hover { background: var(--panel); }
.gsearch-results .r small { color: var(--muted); }
.year-select label { color: var(--muted); font-size: 12px; margin-right: 6px; }
.year-select select { background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px; }
.indicadores { display: flex; gap: 12px; }
.ind { font-size: 12px; color: var(--muted); }
.ind b { color: var(--text); }

.view { flex: 1; overflow-y: auto; padding: 22px; }
.appfoot { padding: 8px 22px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* GRID + CARDS */
.grid { display: grid; gap: 16px; }
.g5 { grid-template-columns: repeat(5, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1400px) { .g5 { grid-template-columns: repeat(3,1fr);} .g4{grid-template-columns:repeat(2,1fr);} }
@media (max-width: 1000px) { .g5,.g4,.g3,.g2 { grid-template-columns: 1fr; } .app{grid-template-columns:1fr;} .sidebar{display:none;} }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; }
.card h3 { margin: 0 0 14px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .3px;
  text-transform: uppercase; }
.kpi { cursor: default; position: relative; overflow: hidden; }
.kpi.click { cursor: pointer; }
.kpi.click:hover { border-color: var(--brand); }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 26px; font-weight: 800; margin-top: 8px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.kpi .accent { position:absolute; right:-20px; top:-20px; width: 80px; height: 80px; border-radius: 50%;
  background: radial-gradient(circle, rgba(79,140,255,.18), transparent 70%); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.green { background: rgba(46,204,113,.15); color: var(--green); }
.badge.blue { background: rgba(58,160,255,.15); color: var(--blue); }
.badge.amber { background: rgba(245,179,1,.15); color: var(--amber); }
.badge.red { background: rgba(255,92,108,.15); color: var(--red); }
.badge.gray { background: rgba(107,114,128,.18); color: #aab2c3; }

/* TABLE */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; color: var(--muted); font-weight: 600; padding: 10px 12px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); cursor: pointer; white-space: nowrap; }
table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl tr:hover td { background: var(--panel-2); }
.row-click { cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.na { color: var(--gray); font-style: italic; }
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input, .toolbar select { background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.btn { background: linear-gradient(90deg,var(--brand),var(--brand-2)); border:0; color:#fff; font-weight:600;
  border-radius: 8px; padding: 8px 14px; cursor:pointer; font-size: 13px; }
.pill { font-size: 11px; padding: 4px 8px; border-radius: 6px; background: var(--panel-2); color: var(--muted); }
.section-title { font-size: 15px; font-weight: 700; margin: 8px 0 14px; }
.gap-note { border: 1px dashed var(--border); border-radius: 10px; padding: 14px; color: var(--muted);
  font-size: 13px; background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255,255,255,.01) 10px, rgba(255,255,255,.01) 20px); }
.gap-note b { color: var(--amber); }

/* TIMELINE */
.timeline { display: flex; flex-wrap: wrap; gap: 6px; }
.tl-step { flex:1; min-width: 90px; text-align:center; padding: 10px 6px; border-radius: 10px; border:1px solid var(--border); }
.tl-step .tl-ico { font-size: 16px; }
.tl-step .tl-name { font-size: 11px; margin-top: 4px; }
.tl-step.done { border-color: var(--green); } .tl-step.done .tl-ico{ color: var(--green);}
.tl-step.active { border-color: var(--blue); } .tl-step.active .tl-ico{ color: var(--blue);}
.tl-step.warn { border-color: var(--amber); } .tl-step.warn .tl-ico{ color: var(--amber);}
.tl-step.risk { border-color: var(--red); } .tl-step.risk .tl-ico{ color: var(--red);}
.tl-step.pending { opacity: .55; }

/* DRAWER */
.drawer { position: fixed; inset: 0; z-index: 100; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.drawer-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(760px, 92vw);
  background: var(--bg-2); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column; animation: slide .2s ease; }
@keyframes slide { from { transform: translateX(30px); opacity: .6; } to { transform:none; opacity:1; } }
.drawer-head { display:flex; justify-content: space-between; align-items:center; padding: 18px 20px;
  border-bottom: 1px solid var(--border); }
.drawer-head #drawer-title { font-size: 16px; font-weight: 700; }
.drawer-head .btn-ghost { width: auto; }
.drawer-body { padding: 20px; overflow-y: auto; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.hs-ring { display:inline-flex; align-items:center; justify-content:center; width: 64px; height:64px;
  border-radius: 50%; font-weight: 800; }

/* ============ COMPONENTES DE DECISIÓN (v2) ============ */
/* Insight Bar */
.insightbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.insight { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px;
  font-size: 13px; border: 1px solid var(--border); background: var(--panel); }
.insight .ico { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.insight.green { border-left: 3px solid var(--green); } .insight.green .ico { background: var(--green); }
.insight.amber { border-left: 3px solid var(--amber); } .insight.amber .ico { background: var(--amber); }
.insight.red   { border-left: 3px solid var(--red); }   .insight.red .ico { background: var(--red); }
.insight.blue  { border-left: 3px solid var(--blue); }  .insight.blue .ico { background: var(--blue); }
.insight.gray  { border-left: 3px solid var(--gray); }  .insight.gray .ico { background: var(--gray); }
.insight a { margin-left: auto; font-size: 12px; white-space: nowrap; }

/* KPI con delta + sparkline */
.kpi .delta { font-size: 12px; font-weight: 700; margin-top: 6px; display: inline-flex; align-items: center; gap: 4px; }
.kpi .delta.up { color: var(--green); } .kpi .delta.down { color: var(--red); } .kpi .delta.flat { color: var(--muted); }
.kpi .spark { margin-top: 10px; height: 34px; }
.kpi.sem-green { box-shadow: inset 3px 0 0 var(--green); }
.kpi.sem-amber { box-shadow: inset 3px 0 0 var(--amber); }
.kpi.sem-red   { box-shadow: inset 3px 0 0 var(--red); }
.kpi.sem-blue  { box-shadow: inset 3px 0 0 var(--blue); }

/* Health ring grande */
.health-hero { display: flex; align-items: center; gap: 22px; }
.health-ring { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center;
  font-size: 30px; font-weight: 800; flex: none; }
.health-ring small { display:block; font-size: 10px; font-weight: 600; letter-spacing: 1px; }
.health-reasons { color: var(--muted); font-size: 13px; }
.health-reasons li { margin: 3px 0; }

/* Decision cards (Top decisiones de hoy) */
.decision { display: flex; gap: 14px; padding: 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel); align-items: flex-start; cursor: pointer; transition: border-color .15s; }
.decision:hover { border-color: var(--brand); }
.decision .sev { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }
.decision .sev.critical { background: var(--red); }
.decision .sev.high { background: var(--amber); }
.decision .sev.medium { background: var(--blue); }
.decision .body { flex: 1; }
.decision .t { font-weight: 700; font-size: 14px; }
.decision .d { color: var(--muted); font-size: 13px; margin: 4px 0; }
.decision .act { font-size: 12px; color: var(--brand); }
.decision .impact { text-align: right; flex: none; }
.decision .impact .v { font-weight: 800; font-size: 15px; }
.decision .impact .l { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.decision .impact .v.neg { color: var(--red); }

/* Gauge de meta */
.gauge-wrap { display: flex; align-items: center; gap: 16px; }
.gauge { position: relative; width: 120px; height: 60px; flex: none; }

/* Matriz valor x urgencia */
.matrix { position: relative; height: 320px; }
.pareto-flag { display:inline-block; padding: 2px 8px; border-radius: 6px; font-size: 11px;
  background: rgba(245,179,1,.15); color: var(--amber); font-weight: 700; }

/* barra de progreso concentración */
.conc-bar { height: 10px; border-radius: 6px; background: var(--panel-2); overflow: hidden; margin-top: 8px; }
.conc-bar > span { display:block; height:100%; background: linear-gradient(90deg,var(--brand),var(--brand-2)); }

/* ============ EXPLICABILIDAD (botón ⓘ) ============ */
.info-btn { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px;
  border-radius: 50%; border: 1px solid var(--border); color: var(--muted); font-size: 11px; font-weight: 700;
  cursor: pointer; margin-left: 6px; line-height: 1; vertical-align: middle; user-select: none; flex: none; }
.info-btn:hover { color: var(--brand); border-color: var(--brand); }
.info-pop { position: fixed; z-index: 200; width: 340px; max-width: 90vw; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 16px; font-size: 12.5px; }
.info-pop h4 { margin: 0 0 4px; font-size: 14px; }
.info-pop .nat { display:inline-block; font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-bottom: 10px; text-transform: uppercase; letter-spacing: .5px; }
.info-pop .nat.real { background: rgba(46,204,113,.15); color: var(--green); }
.info-pop .nat.derivado { background: rgba(58,160,255,.15); color: var(--blue); }
.info-pop .nat.estimado { background: rgba(245,179,1,.15); color: var(--amber); }
.info-pop .nat.na { background: rgba(107,114,128,.2); color: #aab2c3; }
.info-pop .sec { margin: 9px 0; }
.info-pop .sec .lbl { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 2px; }
.info-pop .sec .val { line-height: 1.45; }
.info-pop code, .info-pop .formula { display:block; background: var(--bg-2); border:1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-family: ui-monospace, monospace; font-size: 11.5px; margin-top: 3px; white-space: pre-wrap; }
.info-pop .components { background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-top: 3px; }
.info-pop .components .c { display: flex; justify-content: space-between; padding: 2px 0; }
.info-pop .components .c b { font-variant-numeric: tabular-nums; }
.info-backdrop { position: fixed; inset: 0; z-index: 199; }
h3 .info-btn, .label .info-btn { vertical-align: baseline; }

/* ============ COPILOT (chat IA) ============ */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 200px); min-height: 420px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 8px 4px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 82%; padding: 12px 15px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; }
.msg.user { align-self: flex-end; background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.bot table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 12px; }
.msg.bot th, .msg.bot td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; }
.msg.bot th { background: var(--panel-2); color: var(--muted); }
.msg.bot h1, .msg.bot h2, .msg.bot h3 { font-size: 14px; margin: 10px 0 4px; }
.msg.bot code { background: var(--bg-2); padding: 1px 5px; border-radius: 4px; }
.msg-tools { align-self: flex-start; display: flex; gap: 8px; margin-top: -6px; }
.msg-tools button { font-size: 11px; padding: 5px 10px; border-radius: 7px; border: 1px solid var(--border); background: var(--panel); color: var(--muted); cursor: pointer; }
.msg-tools button:hover { color: var(--brand); border-color: var(--brand); }
.chat-typing { align-self: flex-start; color: var(--muted); font-size: 12px; padding: 6px 12px; }
.chat-input { display: flex; gap: 10px; margin-top: 12px; }
.chat-input input { flex: 1; padding: 13px 15px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; color: var(--text); font-size: 14px; }
.chat-input button { padding: 0 20px; border: 0; border-radius: 12px; background: linear-gradient(90deg,var(--brand),var(--brand-2)); color: #fff; font-weight: 700; cursor: pointer; }
.chat-input button:disabled { opacity: .5; cursor: default; }
.chat-suggests { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chat-chip { font-size: 12px; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; }
.chat-chip:hover { border-color: var(--brand); color: var(--brand); }
.chat-mode { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.chat-mode label { font-size: 12px; color: var(--muted); }
.copilot-badge { font-size: 10px; padding: 2px 7px; border-radius: 999px; background: rgba(124,92,255,.18); color: var(--brand-2); font-weight: 700; }
