:root {
  --navy: #1f2a4d;
  --navy-2: #2b3a66;
  --brand-blue: #2f80c9;
  --brand-orange: #f39200;
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --line: #e3e7ef;
  --grid: #edf0f5;
  --text: #16203a;
  --text-2: #4d5872;
  --muted: #7d879c;
  --good: #0f8a4a;
  --good-bg: #e6f5ec;
  --warn: #b26b00;
  --warn-bg: #fff3dc;
  --bad: #c62f2f;
  --bad-bg: #fde9e9;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22, 32, 58, .06), 0 2px 8px rgba(22, 32, 58, .05);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--brand-blue); }
button, input, select, textarea { font: inherit; color: inherit; }
.oculto { display: none !important; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-marca {
  background: radial-gradient(circle at 20% 10%, #2f4a8a 0, var(--navy) 55%);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
}
.login-marca .logo-chip { background: #fff; border-radius: 12px; padding: 14px 18px; width: fit-content; }
.login-marca .logo-chip img { height: 54px; display: block; }
.login-marca h1 { font-size: 34px; line-height: 1.15; margin: 0 0 12px; font-weight: 650; }
.login-marca p { color: #c9d3ea; max-width: 440px; line-height: 1.55; margin: 0; }
.login-marca .rayo { color: var(--brand-orange); }
.login-marca small { color: #8f9cc0; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 32px; }
.login-form form { width: 100%; max-width: 360px; }
.login-form h2 { margin: 0 0 4px; font-size: 22px; }
.login-form .sub { color: var(--muted); margin: 0 0 24px; }
@media (max-width: 820px) { .login { grid-template-columns: 1fr; } .login-marca { padding: 28px; gap: 28px; } }

/* ---------- formularios ---------- */
label.campo { display: block; margin-bottom: 14px; }
label.campo > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid #ccd3e0; border-radius: 8px; background: #fff; outline: none;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-blue); box-shadow: 0 0 0 3px rgba(47, 128, 201, .15); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.btn {
  border: 1px solid transparent; border-radius: 8px; padding: 9px 16px; cursor: pointer; font-weight: 600;
  background: var(--navy); color: #fff; display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn:hover { background: var(--navy-2); }
.btn.naranja { background: var(--brand-orange); color: #1c1300; }
.btn.naranja:hover { background: #ffa41f; }
.btn.sec { background: #fff; color: var(--text); border-color: #ccd3e0; }
.btn.sec:hover { background: var(--surface-2); }
.btn.peligro { background: #fff; color: var(--bad); border-color: #f0c4c4; }
.btn.peligro:hover { background: var(--bad-bg); }
.btn.chico { padding: 5px 10px; font-size: 12.5px; }
.btn.bloque { width: 100%; justify-content: center; padding: 11px; }
.btn:disabled { opacity: .55; cursor: default; }
.error { background: var(--bad-bg); color: var(--bad); padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.icono-btn { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.icono-btn:hover { background: var(--grid); color: var(--text); }

/* ---------- shell ---------- */
.barra {
  background: var(--navy); color: #fff; height: 60px; padding: 0 24px; display: flex; align-items: center; gap: 28px;
  position: sticky; top: 0; z-index: 20;
}
.barra .logo-chip { background: #fff; border-radius: 8px; padding: 5px 9px; display: flex; }
.barra .logo-chip img { height: 28px; }
.barra nav { display: flex; gap: 4px; flex: 1; }
.barra nav a {
  color: #c9d3ea; text-decoration: none; padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
.barra nav a:hover { color: #fff; background: rgba(255, 255, 255, .07); }
.barra nav a.activo { color: #fff; background: rgba(255, 255, 255, .12); box-shadow: inset 0 -2px 0 var(--brand-orange); }
.usuario-menu { position: relative; }
.usuario-menu > button {
  background: rgba(255, 255, 255, .08); border: 0; color: #fff; border-radius: 999px; padding: 6px 12px 6px 6px;
  display: flex; align-items: center; gap: 8px; cursor: pointer;
}
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-orange); color: #1c1300;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.menu {
  position: absolute; right: 0; top: 44px; background: #fff; color: var(--text); border-radius: 10px; min-width: 210px;
  box-shadow: 0 8px 28px rgba(22, 32, 58, .18); padding: 6px; z-index: 30;
}
.menu .info { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 12.5px; color: var(--muted); }
.menu .info b { display: block; color: var(--text); font-size: 14px; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }
main { max-width: 1320px; margin: 0 auto; padding: 24px; }
.cabecera { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.cabecera h1 { margin: 0; font-size: 22px; }
.cabecera .sub { color: var(--muted); margin-top: 3px; font-size: 13px; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- filtros ---------- */
.filtros {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center; background: var(--surface); padding: 12px;
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px;
}
.filtros select, .filtros input { width: auto; min-width: 150px; padding: 7px 10px; }
.filtros input[type=search] { min-width: 220px; flex: 1; }
.segmento { display: inline-flex; background: var(--grid); border-radius: 8px; padding: 3px; }
.segmento button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--text-2); font-size: 13px; }
.segmento button.activo { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.filtros .sep { flex: 1; }

/* ---------- tarjetas / KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; position: relative; overflow: hidden; }
.kpi .etq { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 26px; font-weight: 650; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .det { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }
.kpi.destacado { background: var(--navy); color: #fff; }
.kpi.destacado .etq { color: #aab6d6; }
.kpi.destacado .det { color: #c9d3ea; }
.kpi.destacado::after { content: ""; position: absolute; right: -24px; top: -24px; width: 90px; height: 90px; border-radius: 50%; background: rgba(243, 146, 0, .18); }
.tarjeta { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; min-width: 0; }
.tarjeta h2 { font-size: 15px; margin: 0; }
.tarjeta .tsub { color: var(--muted); font-size: 12.5px; margin: 3px 0 14px; }
.tarjeta-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1.25fr 1fr; gap: 18px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- gráficos ---------- */
.grafico { position: relative; }
.grafico svg { display: block; width: 100%; overflow: visible; }
.grafico text { font-family: inherit; }
.leyenda { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-bottom: 10px; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tooltip {
  position: fixed; pointer-events: none; background: #fff; color: var(--text); border-radius: 8px; padding: 9px 11px;
  box-shadow: 0 6px 24px rgba(22, 32, 58, .2); font-size: 12.5px; z-index: 100; min-width: 170px; border: 1px solid var(--line);
}
.tooltip b { display: block; margin-bottom: 5px; font-size: 13px; }
.tooltip .fila { display: flex; justify-content: space-between; gap: 14px; color: var(--text-2); }
.tooltip .fila span:last-child { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
.tooltip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.barra-hit { cursor: pointer; }
.barra-hit:hover rect.marca { opacity: .82; }
.vacio { color: var(--muted); text-align: center; padding: 30px; }

/* ---------- tablas ---------- */
.tabla-wrap { overflow-x: auto; }
table.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface);
}
.tabla th.ordenable { cursor: pointer; user-select: none; }
.tabla th.ordenable:hover { color: var(--text); }
.tabla td { padding: 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.tabla tbody tr.clic { cursor: pointer; }
.tabla tbody tr.clic:hover { background: var(--surface-2); }
.tabla tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.tabla .grupo td { background: var(--surface-2); font-weight: 700; color: var(--text-2); font-size: 12.5px; }
.tabla .detalle { color: var(--text-2); white-space: pre-line; max-width: 380px; font-size: 12.5px; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.chip.gris { background: var(--grid); color: var(--text-2); }
.chip.azul { background: #e5f0fb; color: #1d5fa6; }
.chip.verde { background: var(--good-bg); color: var(--good); }
.chip.ambar { background: var(--warn-bg); color: var(--warn); }
.chip.rojo { background: var(--bad-bg); color: var(--bad); }
.margen { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.margen .pista { width: 60px; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.margen .pista div { height: 100%; border-radius: 3px; }
.alerta { color: var(--warn); font-size: 12px; font-weight: 600; }
.alerta::before { content: "⚠ "; }

/* ---------- detalle proyecto ---------- */
.volver { display: inline-flex; gap: 6px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 13px; margin-bottom: 8px; }
.volver:hover { color: var(--text); }
.ficha { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 18px; }
.ficha label.campo { margin-bottom: 10px; }
.ficha .ancho-2 { grid-column: span 2; }
.ficha .ancho-4 { grid-column: span 4; }
@media (max-width: 900px) { .ficha { grid-template-columns: 1fr 1fr; } .ficha .ancho-4 { grid-column: span 2; } }
.resultado { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .resultado { grid-template-columns: 1fr 1fr; } }
.comp { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 2px; background: var(--surface); margin: 6px 0 10px; }
.comp div { height: 100%; }

/* ---------- modal ---------- */
.modal-fondo { position: fixed; inset: 0; background: rgba(15, 22, 42, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 620px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal header { padding: 18px 22px 6px; display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { margin: 0; font-size: 17px; }
.modal .cuerpo { padding: 10px 22px; }
.modal footer { padding: 12px 22px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.dos-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.ayuda { font-size: 12px; color: var(--muted); margin: -8px 0 14px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff;
  padding: 10px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); z-index: 200; font-weight: 600;
}
.toast.error { background: var(--bad); }
.pie { text-align: center; color: var(--muted); font-size: 12px; padding: 10px 0 30px; }
