:root {
  --bg: #f4f2ea;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e7e3d6;
  --navy: #0f2a4a;
  --gold: #d9b64a;
  --brand: #1e6fd9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .05);
}
html, body { background: var(--bg); color: var(--ink); font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; }
body { font-size: .9rem; border-top: 5px solid var(--gold); }
a { color: var(--brand); }
.btn-brand { background: var(--navy); color: #fff; border: 0; font-weight: 600; border-radius: 10px; }
.btn-brand:hover, .btn-brand:focus { background: #173a64; color: #fff; }
.btn-outline-brand { border-color: var(--line); color: var(--navy); background: #fff; font-weight: 500; }
.btn-outline-brand:hover { background: #faf7ee; border-color: var(--gold); color: var(--navy); }
.btn-outline-brand.active { background: var(--navy) !important; color: #fff !important; border-color: var(--navy) !important; }

/* ---------- topbar ---------- */
.topbar { background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand-divider { width: 1px; height: 32px; background: var(--line); }
.brand-title { font-weight: 700; color: var(--navy); font-size: 1rem; }
.brand-sub { font-size: .72rem; color: var(--muted); margin-top: 3px; }
.topbar .nav-link { color: #334155; font-weight: 500; border-radius: 8px; padding: .4rem .7rem !important; }
.topbar .nav-link.active, .topbar .nav-link:hover { background: #f6f3e8; color: var(--navy); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--navy); color: #fff; display: inline-grid; place-items: center; font-weight: 700; font-size: .8rem; }
.demo-banner { background: #fff7db; border-bottom: 1px solid #f1df9c; color: #7a5b00; font-size: .8rem; padding: .35rem 1.5rem; }

/* ---------- cards ---------- */
.card-soft { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header-soft { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: space-between; align-items: center; padding: 1rem 1.25rem .5rem; }
.card-title-soft { font-size: .98rem; font-weight: 700; margin: 0; color: var(--navy); }
.card-title-soft i { color: var(--gold); margin-right: .25rem; }
.card-sub { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.filter-bar .form-label { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: .2rem; }

/* ---------- KPIs ---------- */
.kpi { position: relative; padding: 1rem 1.15rem; height: 100%; overflow: hidden; min-height: 118px; }
.kpi-icon { position: absolute; right: 14px; top: 12px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: #f6f1dd; color: #a8871f; font-size: 1.1rem; }
.kpi-label { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; color: var(--ink); margin-top: .2rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: .75rem; margin-top: .25rem; }
.kpi-delta .up { color: #15803d; font-weight: 600; } .kpi-delta .down { color: #b91c1c; font-weight: 600; }
.kpi-rend { padding-bottom: 46px; }
.sparkline { position: absolute; left: 0; right: 0; bottom: 0; height: 44px; }
.sem-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; box-shadow: 0 0 0 3px rgba(0, 0, 0, .05); margin-bottom: .55rem; vertical-align: middle; }
.sem-dot.sm { width: 9px; height: 9px; margin: 0 .2rem 0 0; box-shadow: none; }
.tabla-rend .sem-dot { margin: 0; }

/* ---------- estado en tiempo real ---------- */
.estado-chip { --c: #64748b; border: 1px solid color-mix(in srgb, var(--c) 35%, white); background: color-mix(in srgb, var(--c) 9%, white); color: color-mix(in srgb, var(--c) 80%, black);
  border-radius: 999px; padding: .3rem .75rem; font-size: .8rem; font-weight: 600; transition: .15s; }
.estado-chip b { background: var(--c); color: #fff; border-radius: 999px; padding: 0 .5rem; margin-left: .25rem; }
.estado-chip:hover, .estado-chip.active { background: var(--c); color: #fff; }
.estado-chip.active b, .estado-chip:hover b { background: rgba(255, 255, 255, .25); }
.equipo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .7rem; }
.equipo-tile { --c: #64748b; position: relative; border-radius: 12px; padding: .7rem .8rem .65rem 1rem; background: color-mix(in srgb, var(--c) 8%, white);
  border: 1px solid color-mix(in srgb, var(--c) 28%, white); overflow: hidden; transition: transform .15s, box-shadow .15s; }
.equipo-tile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c); }
.equipo-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.equipo-code { font-weight: 800; font-size: 1.05rem; color: var(--ink); letter-spacing: -.01em; }
.equipo-icon { color: var(--c); font-size: 1.15rem; }
.equipo-estado { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: color-mix(in srgb, var(--c) 85%, black); margin-top: .1rem; }
.equipo-suceso { font-size: .76rem; color: #334155; margin-top: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.equipo-oper { font-size: .7rem; color: #475569; margin-top: .1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.equipo-time { font-size: .7rem; color: var(--muted); margin-top: .3rem; }
.live-indicator { font-size: .78rem; color: #15803d; font-weight: 600; display: inline-flex; align-items: center; gap: .35rem; }
.live-indicator .dot { width: 9px; height: 9px; border-radius: 50%; background: #16a34a; animation: pulse 1.8s infinite; }
.live-indicator.off { color: #b91c1c; } .live-indicator.off .dot { background: #dc2626; animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, .55); } 70% { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); } 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); } }

/* ---------- tablas ---------- */
.table-scroll { max-height: 420px; overflow: auto; }
.table-scroll thead th { position: sticky; top: 0; background: #fbfaf5; z-index: 1; }
.table { --bs-table-bg: transparent; font-size: .82rem; }
.table thead th { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); }
.badge-estado { --c: #64748b; display: inline-block; font-size: .7rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 13%, white); color: color-mix(in srgb, var(--c) 85%, black); border: 1px solid color-mix(in srgb, var(--c) 30%, white); white-space: nowrap; }
.bar-inline { height: 8px; background: #f1efe6; border-radius: 99px; overflow: hidden; }
.bar-inline span { display: block; height: 100%; border-radius: 99px; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem; font-size: .85rem; }
body.is-loading .chart, body.is-loading .kpi-value { opacity: .55; transition: opacity .2s; }

/* ---------- login ---------- */
.login-page { border-top: 0; }
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { align-items: center; padding: 4rem; color: #fff; position: relative; overflow: hidden;
  background: radial-gradient(1200px 600px at -10% 110%, rgba(217, 182, 74, .35), transparent 60%), linear-gradient(135deg, #0b2140 0%, #0f2a4a 45%, #183e6b 100%); }
.login-hero::after { content: ""; position: absolute; inset: 0; background-image: radial-gradient(rgba(255, 255, 255, .07) 1px, transparent 1px); background-size: 22px 22px; }
.login-hero > div { position: relative; z-index: 1; max-width: 520px; }
.hero-kicker { color: var(--gold); text-transform: uppercase; letter-spacing: .15em; font-size: .75rem; font-weight: 700; margin-bottom: 1rem; }
.login-hero h1 { font-weight: 800; font-size: 2.6rem; line-height: 1.1; letter-spacing: -.02em; }
.login-hero p { color: #cbd5e1; font-size: 1rem; margin-top: 1rem; }
.hero-legend { list-style: none; padding: 0; margin-top: 2rem; display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.hero-legend li { display: flex; align-items: center; gap: .5rem; color: #e2e8f0; }
.hero-legend span { width: 12px; height: 12px; border-radius: 4px; }
.login-panel { display: grid; place-items: center; padding: 2rem 1rem; background: var(--bg); border-top: 5px solid var(--gold); }
.login-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 2.2rem; box-shadow: 0 20px 60px rgba(15, 42, 74, .12); }
.login-card .form-control { border-radius: 10px; }
.toggle-pass { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); color: var(--muted); z-index: 5; }
@media (max-width: 991px) { .login-wrap { grid-template-columns: 1fr; } }
@media (max-width: 575px) { .kpi-value { font-size: 1.45rem; } .equipo-grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------- pestañas de módulos ---------- */
.btn-gold { background: var(--gold); color: var(--navy); border: 0; font-weight: 600; border-radius: 10px; }
.btn-gold:hover, .btn-gold:focus, .btn-gold.show { background: #c9a53c; color: var(--navy); }
.tabs-modulos { gap: .4rem; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.tabs-modulos .nav-link { white-space: nowrap; color: #334155; background: #fff; border: 1px solid var(--line); border-radius: 10px; font-weight: 600; font-size: .84rem; padding: .45rem .9rem; }
.tabs-modulos .nav-link i { color: var(--gold); margin-right: .2rem; }
.tabs-modulos .nav-link:hover { border-color: var(--gold); color: var(--navy); }
.tabs-modulos .nav-link.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.tabs-modulos .nav-link.active i { color: var(--gold); }
.tab-pane.cargando .chart, .tab-pane.cargando .kpi-value { opacity: .5; transition: opacity .2s; }
.btn-icon { border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 8px; width: 30px; height: 30px; padding: 0; display: inline-grid; place-items: center; margin-left: auto; }
.btn-icon:hover { color: var(--navy); border-color: var(--gold); background: #faf7ee; }
.card-header-soft > div:first-child { flex: 1 1 auto; min-width: 0; }
.kpi-grupo { --c: #64748b; border-left: 5px solid var(--c); }
.kpi-grupo .kpi-value { font-size: 1.6rem; }
.fila-vital td:nth-child(2) { color: var(--navy); }
.fila-vital td:first-child { color: #a8871f !important; font-weight: 700; }
.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem; }
.foto { display: block; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fbfaf5; color: var(--ink); text-decoration: none; transition: .15s; }
.foto:hover { transform: translateY(-2px); box-shadow: var(--shadow); color: var(--ink); }
.foto img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #eee; }
.foto-info { padding: .45rem .6rem; font-size: .74rem; line-height: 1.35; }
.foto-info span { color: var(--muted); }

/* ---------- impresión / PDF ---------- */
.modo-impresion main { max-width: 1060px; margin: 0 auto; }
.modo-impresion .tab-pane.imprimir { display: block !important; opacity: 1 !important; }
.modo-impresion .tab-pane:not(.imprimir) { display: none !important; }
.modo-impresion .table-scroll { max-height: none !important; overflow: visible !important; }
/* En el PDF la bitácora y la galería se recortan (el detalle completo va en el Excel) */
.modo-impresion #tb-eventos tr:nth-child(n+41), .modo-impresion #cs-galeria .foto:nth-child(n+13),
.modo-impresion #tb-ck-fallas tr:nth-child(n+16) { display: none; }
.solo-impresion { display: none; }
.modo-impresion .solo-impresion { display: block; }
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  html, body { background: #fff !important; font-size: 11px; border-top: 0; }
  .topbar, .filter-bar, #tabs-modulos, .no-print, .toast-container, .demo-banner, .alert-dismissible, #buscar, .estado-chip { display: none !important; }
  .print-header { display: flex !important; justify-content: space-between; align-items: baseline; border-bottom: 3px solid var(--gold); padding-bottom: 6px; margin-bottom: 10px; color: var(--navy); }
  main { max-width: none !important; padding: 0 !important; }
  .card-soft { box-shadow: none !important; }
  .h-100 { height: auto !important; }
  .row > [class*="col"] { break-inside: avoid; page-break-inside: avoid; }
  .card-soft.mb-3, .card-soft.mb-4 { break-inside: avoid; }
  .tab-pane.imprimir + .tab-pane.imprimir { break-before: page; }
  .equipo-tile { break-inside: avoid; }
  .equipo-tile:hover, .foto:hover { transform: none; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
