/* ============================================================
   sidebar.css — SIGAP KPI Sidebar (unified)
   Dual theme · collapses to icons · shared via base.html
   ============================================================ */

:root, [data-sidebar-theme="dark"] {
    --sb-bg: #1a1d23; --sb-bg2: #22252d;
    --sb-border: rgba(255,255,255,0.05); --sb-divider: rgba(255,255,255,0.05);
    --sb-brand-icon: #818cf8; --sb-brand-title: #e4e7ee; --sb-brand-sub: #656a76;
    --sb-section: #515765; --sb-link: #929aab;
    --sb-link-hover-bg: rgba(255,255,255,0.05); --sb-link-hover: #d1d6e0;
    --sb-link-active-bg: rgba(129,140,248,0.14); --sb-link-active: #b4baf8; --sb-link-active-icon: #a0a8f5;
    --sb-footer: #515765; --sb-footer-border: rgba(255,255,255,0.05);
    --sb-toggle-bg: #22252d; --sb-toggle-color: #929aab; --sb-toggle-border: rgba(255,255,255,0.06);
    --sb-dot: #22c55e;
}

[data-sidebar-theme="light"] {
    --sb-bg: #f5f6f8; --sb-bg2: #ffffff;
    --sb-border: rgba(0,0,0,0.06); --sb-divider: rgba(0,0,0,0.05);
    --sb-brand-icon: #6366f1; --sb-brand-title: #1a1d23; --sb-brand-sub: #8b909a;
    --sb-section: #9ca0ab; --sb-link: #6b7280;
    --sb-link-hover-bg: rgba(0,0,0,0.04); --sb-link-hover: #374151;
    --sb-link-active-bg: rgba(99,102,241,0.1); --sb-link-active: #4f46e5; --sb-link-active-icon: #6366f1;
    --sb-footer: #9ca0ab; --sb-footer-border: rgba(0,0,0,0.05);
    --sb-toggle-bg: #ffffff; --sb-toggle-color: #6b7280; --sb-toggle-border: rgba(0,0,0,0.08);
    --sb-dot: #22c55e;
}

/* ── Sidebar ── */
.sidebar {
    position: fixed; top: 0; left: 0; z-index: 100;
    width: 300px; height: 100vh;
    background: var(--sb-bg); color: var(--sb-link);
    display: flex; flex-direction: column;
    border-right: 1px solid var(--sb-border);
    font-family: 'Roboto Condensed', sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow-y: auto; overflow-x: hidden;
    transition: width 0.25s ease, background 0.35s ease;
}

/* ── Collapsed: icon-only ── */
.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .sb-brand-text,
.sidebar.collapsed .sidebar-link span,
.sidebar.collapsed .sidebar-section,
.sidebar.collapsed .sb-footer-text,
.sidebar.collapsed .sidebar-footer-left span { display: none; }
.sidebar.collapsed .sidebar-brand { padding: 1rem 0.5rem; justify-content: center; }
.sidebar.collapsed .sidebar-brand i { margin: 0; }
.sidebar.collapsed .sidebar-nav { padding: 0.5rem 0; }
.sidebar.collapsed .sidebar-link { justify-content: center; padding: 0.65rem 0; margin: 0.1rem 0.5rem; }
.sidebar.collapsed .sidebar-link i { margin: 0; width: auto; }
.sidebar.collapsed .sidebar-footer { justify-content: center; padding: 0.5rem; }
.sidebar.collapsed .theme-toggle { margin: 0 auto; }
.sidebar.collapsed .sidebar-link { position: relative; }
.sidebar.collapsed .sidebar-link:hover::after {
    content: attr(title); position: absolute; left: 70px; top: 50%;
    transform: translateY(-50%); white-space: nowrap;
    background: var(--sb-bg2); color: var(--sb-brand-title);
    padding: 0.4rem 0.75rem; border-radius: 6px; font-size: 0.78rem;
    font-family: 'Roboto Condensed', sans-serif; z-index: 300;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3); border: 1px solid var(--sb-border);
    pointer-events: none;
}

/* ── Brand ── */
.sidebar-brand { padding: 1.4rem 1.1rem 1rem; display: flex; align-items: center; gap: 0.65rem; transition: padding 0.25s ease; }
.sidebar-brand i { font-size: 1.3rem; color: var(--sb-brand-icon); transition: color 0.35s ease; flex-shrink: 0; }
.sidebar-brand h2 { font-size: 0.95rem; font-weight: 650; color: var(--sb-brand-title); margin: 0; letter-spacing: -0.2px; }
.sidebar-brand span { font-size: 0.68rem; color: var(--sb-brand-sub); }

/* ── Nav ── */
.sidebar-nav { flex: 1; padding: 0.3rem 0.55rem; }
.sidebar-section { padding: 0.85rem 0.55rem 0.3rem; font-size: 0.62rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.11em; color: var(--sb-section); transition: color 0.35s ease; }
.sidebar-link { display: flex; align-items: center; gap: 0.55rem; padding: 0.5rem 0.65rem; margin: 0.1rem 0; color: var(--sb-link); text-decoration: none; font-size: 0.83rem; font-weight: 450; border-radius: 7px; cursor: pointer; transition: all 0.18s ease; }
.sidebar-link i { font-size: 1.05rem; width: 22px; text-align: center; flex-shrink: 0; opacity: 0.72; transition: opacity 0.18s ease; }
.sidebar-link:hover { background: var(--sb-link-hover-bg); color: var(--sb-link-hover); }
.sidebar-link:hover i { opacity: 1; }
.sidebar-link.active { background: var(--sb-link-active-bg); color: var(--sb-link-active); font-weight: 500; }
.sidebar-link.active i { opacity: 1; color: var(--sb-link-active-icon); }

/* ── Footer ── */
.sidebar-footer { padding: 0.55rem 0.85rem; border-top: 1px solid var(--sb-footer-border); display: flex; align-items: center; justify-content: space-between; font-size: 0.7rem; color: var(--sb-footer); transition: border-color 0.35s ease, padding 0.25s ease; }
.sidebar-footer-left { display: flex; align-items: center; gap: 0.45rem; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--sb-dot); animation: pulse-dot 2s ease-in-out infinite; flex-shrink: 0; }
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Theme toggle ── */
.theme-toggle { width: 30px; height: 30px; border-radius: 6px; background: var(--sb-toggle-bg); border: 1px solid var(--sb-toggle-border); color: var(--sb-toggle-color); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; transition: all 0.25s ease; flex-shrink: 0; }
.theme-toggle:hover { color: var(--sb-link-hover); }

/* ── Toggle button ── */
.sidebar-toggle { position: fixed; top: 0.85rem; left: 0.85rem; z-index: 200; width: 32px; height: 32px; border-radius: 7px; background: var(--sb-toggle-bg); color: var(--sb-toggle-color); border: 1px solid var(--sb-toggle-border); display: flex; align-items: center; justify-content: center; font-size: 0.95rem; cursor: pointer; transition: left 0.25s ease, background 0.35s ease, color 0.35s ease; box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
.sidebar-toggle:hover { color: var(--sb-link-hover); }
.sidebar:not(.collapsed) ~ .sidebar-toggle { left: 264px; }
.sidebar.collapsed ~ .sidebar-toggle { left: 80px; }

/* ── Main content ── */
.main-content { margin-left: 300px; transition: margin-left 0.25s ease; min-height: 100vh; }
.sidebar.collapsed ~ .main-content { margin-left: 64px; }

/* ── Topbar, cards, tables (unchanged) ── */
.topbar { background: #fff; border-bottom: 1px solid #e2e8f0; padding: 0.75rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; position: sticky; top: 0; z-index: 50; }
.topbar h1 { font-size: 1.25rem; font-weight: 600; color: #0f172a; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.content-area { padding: 1.5rem; }
.tab-panel { display: none; } .tab-panel.active { display: block; }
.kpi-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 1.25rem 1.5rem; transition: box-shadow .15s ease; }
.kpi-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.06); }
.kpi-card.primary { border-left: 3px solid #3b82f6; } .kpi-card.danger { border-left: 3px solid #ef4444; } .kpi-card.warning { border-left: 3px solid #f59e0b; }
.kpi-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: #64748b; margin-bottom: .25rem; }
.kpi-value { font-size: 2rem; font-weight: 700; color: #0f172a; line-height: 1.2; } .kpi-value.danger { color: #dc2626; }
.kpi-detail { font-size: .8rem; color: #64748b; margin-top: .5rem; line-height: 1.5; } .kpi-detail strong { color: #334155; }
.filter-bar { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.filter-bar .form-select,.filter-bar .form-control { border-color: #e2e8f0; font-size: .875rem; }
.filter-bar .form-select:focus,.filter-bar .form-control:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.table-card { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; overflow: hidden; } .table-card .table { margin-bottom: 0; }
.table-card thead th { background: #f8fafc!important; color: #475569!important; font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid #e2e8f0; padding: .75rem 1rem; }
.table-card tbody td { padding: .75rem 1rem; vertical-align: middle; border-bottom: 1px solid #f1f5f9; font-size: .9rem; }
.table-card tbody tr:hover { background: #f8fafc; }

@media (max-width: 768px) {
    .sidebar { width: 0 !important; } .sidebar.open { width: 248px !important; }
    .main-content { margin-left: 0 !important; }
    .sidebar-toggle { display: flex; }
    .kpi-grid { grid-template-columns: 1fr; }
}
