:root {
    --sidebar-width: 240px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #1d4ed8;
    --topbar-height: 54px;
    --accent: #3b82f6;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f1f5f9;
    color: #1e293b;
    overflow-x: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: #e2e8f0;
    overflow-y: auto;
    z-index: 1000;
    transition: width .25s ease;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 14px 20px;
    border-bottom: 1px solid #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #060e1f;
    height: 54px;
}

.sidebar-logo {
    display: block;
    height: 22px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

.sidebar-collapsed .sidebar-logo { display: none; }

.sidebar-nav {
    padding: 12px 0;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.875rem;
    transition: background .15s, color .15s;
    white-space: nowrap;
    border-radius: 0;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}

.nav-item i {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-section {
    padding: 16px 20px 6px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1.2px;
    color: #475569;
    text-transform: uppercase;
}

/* ── Main content ─────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left .25s ease;
}

.topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.content-area {
    padding: 24px;
}

/* ── KPI Cards ───────────────────────────────────────────── */
.kpi-card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    border-left-width: 4px;
    padding: 18px 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.bg-success-soft { background: #dcfce7; }
.bg-primary-soft  { background: #dbeafe; }
.bg-danger-soft   { background: #fee2e2; }
.bg-warning-soft  { background: #fef3c7; }

.kpi-body { flex: 1; min-width: 0; }
.kpi-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #64748b; }
.kpi-value { font-size: 1.45rem; font-weight: 800; line-height: 1.2; margin: 2px 0; }
.kpi-sub   { font-size: 0.75rem; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 12px 18px;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 10px 10px 0 0 !important;
}

.stat-card .card-body { padding: 20px 16px; }

/* ── Page header ─────────────────────────────────────────── */
.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

/* ── Tables ──────────────────────────────────────────────── */
.table { font-size: 0.875rem; }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table-dark { background: #0f172a; }

/* ── Forms ───────────────────────────────────────────────── */
.form-label { font-size: 0.8rem; font-weight: 600; color: #475569; margin-bottom: .3rem; }
.form-control, .form-select { font-size: 0.875rem; border-radius: 6px; }
.form-control:focus, .form-select:focus { box-shadow: 0 0 0 3px rgba(59,130,246,.15); border-color: var(--accent); }

/* ── Badges ──────────────────────────────────────────────── */
.badge { font-size: 0.7rem; font-weight: 600; border-radius: 4px; }

/* ── Sidebar collapsed ───────────────────────────────────── */
.sidebar-collapsed {
    width: 60px;
}

.sidebar-collapsed .brand-text,
.sidebar-collapsed .nav-item span,
.sidebar-collapsed .nav-section {
    display: none;
}

.sidebar-collapsed + .main-content {
    margin-left: 60px;
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── Sidebar overlay (mobile) ────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 999;
}
.sidebar-overlay.active { display: block; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
        box-shadow: 2px 0 12px rgba(0,0,0,.2);
    }
    .sidebar.open { transform: translateX(0); }

    .main-content { margin-left: 0 !important; }

    .topbar {
        padding: 0 12px;
        gap: 4px;
    }
    .topbar .breadcrumb,
    .topbar .topbar-clock { display: none; }

    .topbar .user-name { display: none; }

    .content-area { padding: 14px 12px; }

    .page-title { font-size: 1.15rem; }

    /* KPI cards apilados */
    .kpi-card { padding: 14px 14px; }
    .kpi-value { font-size: 1.2rem; }

    /* Tablas con scroll horizontal automático */
    .card-body > .table,
    .content-area > .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Botones de acción en tablas que no se rompan en varias líneas */
    .table .btn-group { flex-wrap: nowrap; }

    /* Desactivar colapso desktop en mobile */
    .sidebar-collapsed {
        width: 260px;
        transform: translateX(-100%);
    }
    .sidebar-collapsed .brand-text,
    .sidebar-collapsed .nav-item span,
    .sidebar-collapsed .nav-section { display: block; }
    .sidebar-collapsed + .main-content { margin-left: 0; }

    /* Forms y cards mejor espaciados */
    .card-header { padding: 10px 14px; }

    /* Dropdown de usuario más compacto */
    .topbar .dropdown-toggle::after { margin-left: 4px; }
}

@media (max-width: 480px) {
    .content-area { padding: 12px 8px; }
    .kpi-card { padding: 12px; gap: 10px; }
    .kpi-icon { width: 40px; height: 40px; font-size: 1.2rem; }
    .page-title { font-size: 1.05rem; }
}
