:root {
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --sidebar-width: 246px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="light"] {
    color-scheme: light;
    --bg-app: #F8FAFC;
    --bg-surface: #FFFFFF;
    --bg-subtle: #F1F5F9;
    --bg-hover: #F1F5F9;
    --text-main: #0F172A;
    --text-secondary: #475569;
    --text-muted: #64748B;
    --border-color: #E2E8F0;
    --accent: #2563EB;
    --accent-hover: #1D4ED8;
    --accent-soft: #EFF6FF;
    --accent-text: #1D4ED8;
    --success: #059669;
    --success-soft: #ECFDF5;
    --warning: #D97706;
    --warning-soft: #FFFBEB;
    --danger: #DC2626;
    --danger-soft: #FEF2F2;
    --sidebar-bg: #FFFFFF;
    --sidebar-border: #E2E8F0;
    --sidebar-text: #475569;
    --sidebar-text-active: #0F172A;
    --sidebar-icon: #64748B;
    --sidebar-icon-active: #2563EB;
    --sidebar-hover-bg: #F1F5F9;
    --sidebar-active-bg: #EFF6FF;
    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.04);
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg-app: #09090B;
    --bg-surface: #121215;
    --bg-subtle: #18181B;
    --bg-hover: #1F1F23;
    --text-main: #FAFAFA;
    --text-secondary: #A1A1AA;
    --text-muted: #71717A;
    --border-color: #27272A;
    --accent: #3B82F6;
    --accent-hover: #2563EB;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --accent-text: #60A5FA;
    --success: #10B981;
    --success-soft: rgba(16, 185, 129, 0.15);
    --warning: #F59E0B;
    --warning-soft: rgba(245, 158, 11, 0.15);
    --danger: #EF4444;
    --danger-soft: rgba(239, 68, 68, 0.15);
    --sidebar-bg: #0C0C0E;
    --sidebar-border: #1F1F23;
    --sidebar-text: #A1A1AA;
    --sidebar-text-active: #FAFAFA;
    --sidebar-icon: #A1A1AA;
    --sidebar-icon-active: #60A5FA;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
    --sidebar-active-bg: rgba(59, 130, 246, 0.16);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
    background: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-sans);
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-size: 13.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.num { font-variant-numeric: tabular-nums; }
h1, h2, h3, h4, h5 { color: var(--text-main); font-weight: 600; margin: 0; letter-spacing: -0.015em; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 99px; }

/* Auth Screen */
.login-container {
    width: 100%; height: 100vh; display: flex; flex-direction: column;
    justify-content: center; align-items: center; position: fixed; inset: 0;
    z-index: 99999; background: var(--bg-app);
}
.login-box {
    background: var(--bg-surface); padding: 32px; border-radius: var(--radius-lg);
    width: 360px; border: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
}

/* Forms & Upload Input Group */
.form-group { margin-bottom: 14px; width: 100%; }
.form-row { display: flex; gap: 12px; width: 100%; }
.form-row > div { flex: 1; min-width: 0; }
label { display: block; margin-bottom: 5px; font-size: 12px; font-weight: 500; color: var(--text-secondary); }
input, select, textarea {
    display: block; width: 100%; padding: 8px 11px; font-size: 13.5px; color: var(--text-main);
    background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    font-family: inherit; color-scheme: inherit; transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft);
}
.input-upload-group { display: flex; gap: 6px; align-items: center; }
.input-upload-group input { flex: 1; }

/* Layout & Unified Sidebar */
#dashboardSection { display: none; width: 100%; height: 100vh; }
.admin-wrapper { display: flex; width: 100%; height: 100%; }
.sidebar {
    width: var(--sidebar-width); background: var(--sidebar-bg); border-right: 1px solid var(--sidebar-border);
    display: flex; flex-direction: column; flex-shrink: 0; z-index: 100; transition: background 0.15s, border-color 0.15s;
}
.brand {
    padding: 20px 22px; display: flex; align-items: center; justify-content: space-between;
    font-size: 15px; font-weight: 700; color: var(--text-main); border-bottom: 1px solid var(--sidebar-border);
    letter-spacing: 0.08em;
}
.menu-list { flex: 1; padding: 10px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.menu-label {
    font-size: 11px; color: var(--text-muted); font-weight: 600;
    padding: 14px 10px 4px 10px; text-transform: uppercase; letter-spacing: 0.05em;
}
.menu-btn {
    background: transparent; border: none; width: 100%; padding: 8px 10px; text-align: left;
    color: var(--sidebar-text); font-size: 13px; font-weight: 500; cursor: pointer; display: flex; align-items: center;
    gap: 10px; border-radius: var(--radius-sm); font-family: inherit; transition: all 0.12s;
}
.menu-btn i { width: 18px; text-align: center; font-size: 13.5px; color: var(--sidebar-icon); transition: color 0.12s; }
.menu-btn:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text-active); }
.menu-btn:hover i { color: var(--sidebar-text-active); }
.menu-btn.active { background: var(--sidebar-active-bg); color: var(--sidebar-text-active); font-weight: 600; }
.menu-btn.active i { color: var(--sidebar-icon-active); }
.badge-count {
    background: var(--accent); color: #fff; font-size: 11px; padding: 1px 6px;
    border-radius: 99px; margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums;
}
.sidebar-footer {
    padding: 12px 14px; border-top: 1px solid var(--sidebar-border);
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

.main-wrapper { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.top-bar {
    height: 56px; padding: 0 28px; background: var(--bg-surface); border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
}
.content-area { flex: 1; padding: 24px 28px; overflow-y: auto; max-width: 1440px; width: 100%; margin: 0 auto; }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card {
    background: var(--bg-surface); padding: 18px 20px; border-radius: var(--radius-md);
    border: 1px solid var(--border-color); box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.kpi-value { font-size: 24px; font-weight: 700; color: var(--text-main); letter-spacing: -0.025em; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; display: flex; align-items: center; gap: 6px; }

/* Controls & Tables */
.controls {
    display: flex; gap: 10px; margin-bottom: 16px; align-items: center; justify-content: space-between;
    flex-wrap: wrap; background: var(--bg-surface); padding: 12px 14px; border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
.controls-left, .controls-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card {
    background: var(--bg-surface); border-radius: var(--radius-md); border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm); overflow: hidden; margin-bottom: 20px;
}
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th {
    color: var(--text-muted); font-size: 11.5px; font-weight: 600; padding: 10px 16px;
    border-bottom: 1px solid var(--border-color); text-transform: uppercase; letter-spacing: 0.04em;
    background: var(--bg-subtle);
}
td { padding: 12px 16px; border-bottom: 1px solid var(--border-color); vertical-align: middle; color: var(--text-main); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }
img.thumb { width: 36px; height: 52px; object-fit: cover; border-radius: 4px; background: var(--bg-subtle); border: 1px solid var(--border-color); flex-shrink: 0; }

/* Buttons & Badges */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
    padding: 7px 13px; font-size: 13px; font-weight: 500; border-radius: var(--radius-sm);
    border: 1px solid transparent; font-family: inherit; transition: all 0.12s; white-space: nowrap;
}
.btn i { font-size: 12.5px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: var(--bg-surface); color: var(--text-main); border-color: var(--border-color); }
.btn-outline:hover { background: var(--bg-subtle); }
.btn-outline.active-page { background: var(--text-main); color: var(--bg-surface); border-color: var(--text-main); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.92; }

.pill {
    display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500;
    padding: 2px 8px; border-radius: 99px; border: 1px solid var(--border-color); background: var(--bg-subtle); color: var(--text-secondary);
}
.pill-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.pill-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.pill-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill-accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }

.action-group { display: flex; justify-content: flex-end; gap: 4px; }
.btn-icon {
    width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid transparent;
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    background: transparent; color: var(--text-secondary); transition: all 0.12s; font-size: 13.5px;
}
.btn-icon:hover { background: var(--bg-subtle); color: var(--text-main); border-color: var(--border-color); }
.btn-icon.active { color: var(--warning); background: var(--warning-soft); }

/* Monthly Bar Chart */
.chart-bars { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding: 20px 10px 6px 10px; border-bottom: 1px solid var(--border-color); }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chart-bar-wrap { width: 100%; height: 125px; display: flex; align-items: flex-end; justify-content: center; }
.chart-bar { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 4px; transition: height 0.3s ease; }
.chart-lbl { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* Progress Bars */
.prog-track { width: 100%; height: 6px; background: var(--bg-subtle); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.prog-fill { height: 100%; background: var(--accent); transition: width 0.2s ease; }

/* Modals */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(9, 9, 11, 0.6); backdrop-filter: blur(2px); z-index: 9000; justify-content: center; align-items: center; padding: 16px; }
.modal-content { background: var(--bg-surface); width: 460px; max-width: 100%; border-radius: var(--radius-lg); display: flex; flex-direction: column; max-height: 90vh; border: 1px solid var(--border-color); box-shadow: 0 20px 25px -5px rgba(0,0,0,0.25); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-subtle); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
#editLinkModal { z-index: 9500 !important; }

.switch { position: relative; display: inline-block; width: 36px; height: 20px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background-color: var(--border-color); transition: .2s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .2s; border-radius: 50%; }
input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(16px); }

.pagination { display: flex; justify-content: center; align-items: center; gap: 6px; padding: 14px; border-top: 1px solid var(--border-color); }
div.swal2-container { z-index: 999999 !important; font-family: var(--font-sans) !important; }
.swal2-popup { background: var(--bg-surface) !important; color: var(--text-main) !important; border: 1px solid var(--border-color) !important; border-radius: var(--radius-lg) !important; }

@media (max-width: 768px) {
    .sidebar { position: fixed; left: -260px; height: 100vh; transition: left 0.25s ease; }
    .sidebar.active { left: 0; }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }
    .sidebar-overlay.active { display: block; }
    .content-area { padding: 16px; }
}