:root {
    --sidebar-width: 250px;
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-surface-2: #263548;
    --color-border: #334155;
    --color-primary: #0d6efd;
    --color-text: #e2e8f0;
    --color-text-muted: #94a3b8;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    min-height: 100vh;
}

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

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: linear-gradient(180deg, #111c34 0%, #0f172a 100%);
    border-right: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1.1rem .85rem;
    z-index: 1050;
}

.brand {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .35rem .5rem 1.2rem;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 1rem;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: .6rem;
    display: grid;
    place-items: center;
    background: rgba(13, 110, 253, .18);
    color: #60a5fa;
    font-size: 1.2rem;
    flex: 0 0 auto;
}

.brand-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    flex: 0 0 auto;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, .45));
}

.brand-name { font-weight: 700; font-size: 1.02rem; letter-spacing: .02em; line-height: 1.1; }
.brand-sub { font-size: .68rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .08em; }

.nav-side { display: flex; flex-direction: column; gap: .2rem; flex: 1; }

.nav-side .nav-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .6rem .75rem;
    border-radius: .55rem;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: .92rem;
    font-weight: 500;
    transition: background .15s, color .15s;
}

.nav-side .nav-link:hover { background: var(--color-surface-2); color: var(--color-text); }
.nav-side .nav-link.active {
    background: var(--color-primary);
    color: #fff;
    box-shadow: 0 6px 16px rgba(13, 110, 253, .35);
}
.nav-side .nav-link i { font-size: 1.05rem; }

.sidebar-foot {
    font-size: .72rem;
    color: var(--color-text-muted);
    padding: .75rem .5rem 0;
    border-top: 1px solid var(--color-border);
}

/* ---------- Main ---------- */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.contenido { padding: 1.5rem 1.75rem 2.5rem; }

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.page-head h1 { font-size: 1.55rem; font-weight: 700; margin: 0; }
.page-head .sub { color: var(--color-text-muted); font-size: .88rem; margin-top: .2rem; }

/* ---------- Cards ---------- */
.card {
    background: var(--color-surface) !important;
    border: 1px solid var(--color-border) !important;
    color: var(--color-text);
    border-radius: .75rem;
}
.card-header { background: transparent !important; border-bottom: 1px solid var(--color-border) !important; }
.card-footer { background: transparent !important; border-top: 1px solid var(--color-border) !important; }
.card-title { font-size: 1rem; font-weight: 600; }

/* ---------- Formularios ---------- */
.form-control, .form-select {
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    color: var(--color-text);
}
.form-control:focus, .form-select:focus {
    background: var(--color-surface-2);
    border-color: var(--color-primary);
    color: var(--color-text);
    box-shadow: 0 0 0 .2rem rgba(13, 110, 253, .25);
}
.form-control::placeholder { color: #64748b; }
.form-label {
    font-size: .74rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    margin-bottom: .35rem;
}
.input-group-text {
    background: var(--color-surface-2);
    border-color: var(--color-border);
    color: var(--color-text-muted);
}

/* ---------- Tabla ---------- */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--color-text);
    --bs-table-border-color: var(--color-border);
    margin-bottom: 0;
}
.table thead th {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--color-text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}
.table tbody td { border-color: rgba(51, 65, 85, .6); vertical-align: middle; }
.table-hover tbody tr:hover {
    --bs-table-hover-bg: rgba(38, 53, 72, .55);
    --bs-table-hover-color: var(--color-text);
}

.cliente-nombre { font-weight: 600; }
.cliente-meta { font-size: .76rem; color: var(--color-text-muted); }
.dir-text {
    font-size: .82rem;
    color: var(--color-text-muted);
    max-width: 230px;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

/* ---------- Badges ---------- */
.badge-suave { font-size: .72rem; font-weight: 600; padding: .32rem .55rem; border-radius: .5rem; }
.badge-plan { background: rgba(59, 130, 246, .15); color: #93c5fd; border: 1px solid rgba(59, 130, 246, .35); }
.badge-ok   { background: rgba(34, 197, 94, .15);  color: #86efac; border: 1px solid rgba(34, 197, 94, .35); }
.badge-off  { background: rgba(239, 68, 68, .15);  color: #fca5a5; border: 1px solid rgba(239, 68, 68, .35); }
.badge-sin  { background: rgba(148, 163, 184, .15); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, .35); }
.badge-pend { background: rgba(245, 158, 11, .15);  color: #fcd34d; border: 1px solid rgba(245, 158, 11, .35); }

/* ---------- Stat cards ---------- */
.stat-card { display: flex; align-items: center; gap: .9rem; padding: 1rem 1.1rem; height: 100%; }
.stat-icon {
    width: 46px;
    height: 46px;
    border-radius: .7rem;
    display: grid;
    place-items: center;
    font-size: 1.3rem;
    flex: 0 0 auto;
}
.stat-val { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: .72rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Dashboard ---------- */
.page-head h1 { letter-spacing: -.01em; }
.card.shadow-sm { transition: border-color .18s ease, box-shadow .18s ease; }
.card.shadow-sm:hover { border-color: #3f5169 !important; }
.stat-card .stat-icon { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05); }
.stat-val { font-variant-numeric: tabular-nums; letter-spacing: -.015em; }
.stat-label { margin-top: .1rem; }

.tarjeta-reporte {
    background: linear-gradient(135deg, #223049 0%, var(--color-surface) 55%) !important;
    border-color: rgba(59, 130, 246, .35) !important;
}
.tarjeta-reporte .card-title {
    text-transform: uppercase;
    font-size: .74rem;
    letter-spacing: .06em;
    font-weight: 700;
    color: #93c5fd;
}
.tarjeta-reporte .stat-val { font-size: 1.55rem; }

#pagos thead th { position: sticky; top: 0; background: var(--color-surface); z-index: 1; }

/* ---------- Vacio ---------- */
.empty { color: var(--color-text-muted); text-align: center; padding: 2rem 1rem; }
.empty i { font-size: 2rem; opacity: .5; display: block; margin-bottom: .5rem; }

/* ---------- Botones ---------- */
.btn-primary { box-shadow: 0 4px 12px rgba(13, 110, 253, .3); }
.btn-outline-secondary {
    --bs-btn-color: #cbd5e1;
    --bs-btn-border-color: #475569;
    --bs-btn-hover-bg: #334155;
    --bs-btn-hover-border-color: #475569;
    --bs-btn-hover-color: #fff;
}

/* ---------- SweetAlert oscuro ---------- */
.swal2-popup.dark-swal {
    background: var(--color-surface) !important;
    color: var(--color-text) !important;
    border: 1px solid var(--color-border);
    border-radius: .85rem !important;
}
.swal2-popup.dark-swal .swal2-title { color: var(--color-text) !important; }
.swal2-popup.dark-swal .swal2-html-container { color: var(--color-text-muted) !important; }
.swal2-popup.dark-swal .swal2-confirm { background: #3b82f6 !important; }
.swal2-popup.dark-swal .swal2-cancel {
    background: transparent !important;
    border: 1px solid #475569 !important;
    color: #e2e8f0 !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .sidebar.abierto { transform: translateX(0); }
    .app-main { width: 100%; }
    .contenido { padding: 1.1rem 1rem 2rem; }
}
