:root {
    --sidebar-bg: #1f2a44;
    --sidebar-bg-2: #17203a;
    --sidebar-active: #22c55e;
    --sidebar-text: #c7d0e0;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #f4f6fb;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar .brand {
    padding: 1.1rem 1.25rem;
    font-size: 1.15rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    border-bottom: 1px solid rgba(255,255,255,.08);
    display: flex;
    align-items: center;
    gap: .6rem;
}
.sidebar .brand:hover { color: #fff; opacity: .9; }

.sidebar .nav-scroll { overflow-y: auto; flex: 1; padding: .5rem 0; }

.sidebar .nav-section {
    color: rgba(255,255,255,.38);
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: .85rem 1.25rem .35rem;
}

.sidebar .nav-link {
    color: var(--sidebar-text);
    padding: .7rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .93rem;
    border-left: 3px solid transparent;
}

.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }

.sidebar .nav-link.active {
    background: rgba(34,197,94,.15);
    color: #fff;
    border-left-color: var(--sidebar-active);
    font-weight: 600;
}

.sidebar .nav-link i { font-size: 1.05rem; width: 1.25rem; text-align: center; }

.sidebar .sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.08);
    padding: .85rem 1.25rem;
    font-size: .82rem;
}

/* ---------- Main area ---------- */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: #fff;
    border-bottom: 1px solid #e5e9f2;
    padding: .6rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.content { padding: 1.5rem; }

.card-kpi { border: none; border-radius: .8rem; box-shadow: 0 2px 10px rgba(31,42,68,.06); }

.table-wrap { background:#fff; border-radius:.6rem; box-shadow:0 2px 10px rgba(31,42,68,.05); overflow:hidden; }

.row-alert td { background-color: #fde8e8 !important; }
.badge-vencido { background-color:#dc3545; }
.badge-ok { background-color:#198754; }
.badge-proximo { background-color:#fd7e14; }

/* Modal simple sin JS */
.modal-backdrop-custom {
    position: fixed; inset: 0; background: rgba(15,23,42,.55);
    display: flex; align-items: flex-start; justify-content: center;
    z-index: 1050; padding: 3rem 1rem; overflow-y:auto;
}
.modal-card { background:#fff; border-radius:.7rem; width:100%; max-width:640px; box-shadow:0 20px 50px rgba(0,0,0,.3); }

.login-shell {
    display:flex; align-items:center; justify-content:center; min-height:100vh;
    background: linear-gradient(135deg, #1f2a44, #2f6fed);
}
.login-card { width:100%; max-width:400px; border-radius:1rem; }

@media (max-width: 768px) {
    .sidebar { width: 68px; }
    .sidebar .brand span, .sidebar .nav-link span, .sidebar .sidebar-footer { display:none; }
}

/* ---------- Dashboard ---------- */
:root {
    --c-blue:#2a78d6; --c-orange:#eb6834; --c-aqua:#1baf7a; --c-yellow:#eda100;
    --c-magenta:#e87ba4; --c-green:#008300; --c-violet:#4a3aa7; --c-red:#e34948;
    --s-good:#0ca30c; --s-warning:#fab219; --s-serious:#ec835a; --s-critical:#d03b3b;
    --ink-2:#52514e; --ink-muted:#898781; --grid:#e1e0d9;
}

.dash-card {
    background:#fff; border-radius:.7rem; box-shadow:0 2px 10px rgba(31,42,68,.05);
    padding:1.1rem 1.25rem; height:100%;
}
.dash-card h2 { font-size:1rem; font-weight:600; margin-bottom:.15rem; }
.dash-card .subtitle { color:var(--ink-muted); font-size:.8rem; margin-bottom:.9rem; }

.dash-row { display:flex; align-items:center; gap:.6rem; margin-bottom:.5rem; }
.dash-row .lbl { width:38%; font-size:.82rem; color:var(--ink-2); text-align:right;
    white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.dash-row .val { font-size:.82rem; font-weight:600; font-variant-numeric:tabular-nums; min-width:2.2rem; }

.dash-track {
    flex:1; height:20px; background:#f0f1f4; border-radius:6px;
    display:flex; overflow:hidden;
}
.dash-seg { height:100%; border-radius:6px; }
.dash-seg + .dash-seg { margin-left:2px; }

.dash-legend { display:flex; flex-wrap:wrap; gap:1rem; margin-top:.75rem; font-size:.8rem; color:var(--ink-2); }
.dash-legend .item { display:flex; align-items:center; gap:.4rem; }
.dash-legend .swatch { width:12px; height:12px; border-radius:3px; display:inline-block; }

.seg-toggle { display:inline-flex; border:1px solid var(--grid); border-radius:.5rem; overflow:hidden; }
.seg-toggle button { border:0; background:#fff; padding:.25rem .7rem; font-size:.8rem; color:var(--ink-2); cursor:pointer; }
.seg-toggle button.active { background:var(--c-blue); color:#fff; }

.kpi-tile { background:#fff; border-radius:.7rem; box-shadow:0 2px 10px rgba(31,42,68,.05); padding:.9rem 1rem; height:100%; }
.kpi-tile .k-label { color:var(--ink-muted); font-size:.78rem; }
.kpi-tile .k-value { font-size:1.6rem; font-weight:700; line-height:1.2; }

/* ======================================================================
   Dashboard: tarjetas clicables, Modo Oscuro y Modo TV (Centro de Comando)
   ====================================================================== */

/* KPIs superiores actúan como botón hacia su módulo */
.kpi-tile.clickable { cursor: pointer; transition: transform .08s ease, box-shadow .15s ease; }
.kpi-tile.clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(31,42,68,.14); }
.kpi-tile.clickable:active { transform: translateY(0); }

/* ---------- Modo Oscuro (se aplica a body con la clase .theme-dark) ---------- */
body.theme-dark { background-color: #0b1220; }
body.theme-dark .topbar { background: #111a2e; border-bottom-color: #1e2a44; color: #e6ecf7; }
body.theme-dark .content { color: #e6ecf7; }
body.theme-dark .dash-card,
body.theme-dark .kpi-tile,
body.theme-dark .table-wrap,
body.theme-dark .card-kpi { background: #131d33; color: #e6ecf7; box-shadow: 0 2px 12px rgba(0,0,0,.35); }
body.theme-dark .dash-card h2 { color: #f1f5fb; }
body.theme-dark .dash-card .subtitle,
body.theme-dark .kpi-tile .k-label,
body.theme-dark .dash-row .lbl { color: #9fb0cc; }
body.theme-dark .dash-row .val { color: #eef3fb; }
body.theme-dark .dash-track { background: #1e2a44; }
body.theme-dark .kpi-tile .k-value { color: #ffffff; }
body.theme-dark .text-muted { color: #8ea1c0 !important; }
body.theme-dark .dash-legend { color: #b9c6de; }
body.theme-dark .kpi-tile.clickable:hover { box-shadow: 0 6px 18px rgba(0,0,0,.5); }
body.theme-dark .seg-toggle { border-color: #2a3a5c; }
body.theme-dark .seg-toggle button { background: #131d33; color: #c7d3ea; }
body.theme-dark .seg-toggle button.active { background: var(--c-blue); color: #fff; }
body.theme-dark .input-group-text { background: #1b2743; border-color: #2a3a5c; color: #c7d3ea; }
body.theme-dark .form-select { background: #131d33; border-color: #2a3a5c; color: #e6ecf7; }
body.theme-dark .btn-outline-secondary { color: #c7d3ea; border-color: #3a4c72; }
body.theme-dark .btn-outline-secondary:hover { background: #1e2a44; color: #fff; }
/* Los rojos/amarillos de alerta resaltan más sobre fondo oscuro */
body.theme-dark .text-danger { color: #ff6b6b !important; }

/* ---------- Modo TV / Monitoreo: números grandes, oculta lo secundario ---------- */
body.mode-tv .kpi-tile .k-value { font-size: 2.8rem; }   /* números críticos mucho más grandes */
body.mode-tv .kpi-tile .k-label { font-size: 1rem; }
body.mode-tv .dash-card h2 { font-size: 1.45rem; }
body.mode-tv .dash-row .lbl,
body.mode-tv .dash-row .val { font-size: 1.1rem; }
body.mode-tv .dash-track { height: 28px; }
body.mode-tv .h3 { font-size: 2rem; }
/* Elementos que estorban en una TV (nadie interactúa con ella) */
body.mode-tv .dash-hide-tv { display: none !important; }

/* En pantallas muy grandes (monitores/TV) agranda los números aunque no esté el Modo TV */
@media (min-width: 1600px) {
    .kpi-tile .k-value { font-size: 2.15rem; }
}

/* ======================================================================
   KPIs modernos (tarjetas oscuras con número grande, ícono y sparkline)
   ====================================================================== */
.kpi2 {
    --accent: #7c6cf5;
    position: relative;
    border-radius: 16px;
    padding: 16px 18px;
    color: #fff;
    background: linear-gradient(135deg, #232a52 0%, #161a34 100%);
    box-shadow: 0 8px 24px rgba(23, 27, 56, .18);
    cursor: pointer;
    overflow: hidden;
    height: 100%;
    transition: transform .1s ease, box-shadow .15s ease;
}
.kpi2:hover { transform: translateY(-3px); box-shadow: 0 14px 32px rgba(23, 27, 56, .30); }
.kpi2::after {
    content: "";
    position: absolute; right: -30px; top: -30px;
    width: 90px; height: 90px; border-radius: 50%;
    background: var(--accent); opacity: .12;
}
.kpi2-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; position: relative; z-index: 1; }
.kpi2-ic {
    width: 42px; height: 42px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.25rem; color: #fff;
    background: var(--accent);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .28);
}
.kpi2-val { font-size: 2.3rem; font-weight: 800; line-height: 1; letter-spacing: -.5px; position: relative; z-index: 1; }
.kpi2-val.kpi2-alert { color: var(--accent); }
.kpi2-lbl { color: #aeb4de; font-size: .82rem; margin-top: 5px; position: relative; z-index: 1; }
.kpi2-sub {
    margin-top: 12px; display: inline-flex; align-items: center; gap: .35rem;
    font-size: .72rem; color: #e7e9ff;
    background: rgba(255, 255, 255, .08);
    border: 1px solid rgba(255, 255, 255, .14);
    padding: 3px 9px; border-radius: 999px; position: relative; z-index: 1;
}
.kpi2-spark { display: flex; align-items: flex-end; gap: 3px; height: 34px; }
.kpi2-spark .spark-bar { width: 5px; border-radius: 3px 3px 0 0; background: var(--accent); opacity: .85; }

/* Mini-área de tendencia (SVG) en los KPI con histórico */
.kpi2-area { width: 96px; height: 34px; display: block; }
.kpi2-area .ln { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.kpi2-area .ar { fill: var(--accent); opacity: .18; stroke: none; }
.kpi2-area .dot { fill: var(--accent); }


/* ---------- Logo de marca (UNIDOS Mayoreo) ---------- */
.sidebar .brand { justify-content: center; }
.sidebar .brand-logo {
    height: 40px;
    max-width: calc(100% - 8px);
    object-fit: contain;
    background: #fff;
    padding: 5px 10px;
    border-radius: 8px;
    display: block;
}
@media (max-width: 768px) {
    .sidebar .brand-logo { height: 30px; padding: 3px 4px; }
}
