/* ============================================================================
   Admin Console - Main Stylesheet
   ============================================================================ */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --accent: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-card-hover: #273548;
    --bg-sidebar: #1e293b;
    --bg-input: #334155;

    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dark: #64748b;

    --border: #334155;
    --border-light: #475569;

    --sidebar-width: 260px;
    --navbar-height: 64px;

    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.4), 0 4px 6px -4px rgba(0,0,0,0.3);

    --transition: 150ms ease;
}

/* ─── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    max-width: 100vw;
}

a { color: var(--primary-light); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary); }

/* ─── Layout ────────────────────────────────────────────────────────── */
.admin-layout {
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
    max-width: 100vw;
}

/* ─── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 300ms ease;
}

.sidebar-brand {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-brand h1 {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text);
    line-height: 1.2;
}

.sidebar-brand small {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dark);
    padding: 0 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 13.5px;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-light);
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 16px;
    opacity: 0.8;
}

.nav-item.active i { opacity: 1; }

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-dark);
}

/* ─── Main Content ──────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
    overflow-x: hidden;
}

/* ─── Navbar ────────────────────────────────────────────────────────── */
.navbar {
    height: var(--navbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.navbar-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 13px;
}

.navbar-user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
}

/* ─── Page Content ──────────────────────────────────────────────────── */
.page-content {
    flex: 1;
    padding: 32px;
    min-width: 0;
    overflow-x: hidden;
}

/* ─── Cards ─────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 24px;
}

.card-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ─── Stat Cards ────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: border-color var(--transition);
}

.stat-card:hover { border-color: var(--border-light); }

.stat-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-bottom: 16px;
}

.stat-card-icon.blue { background: rgba(99,102,241,0.15); color: var(--primary-light); }
.stat-card-icon.green { background: rgba(16,185,129,0.15); color: var(--success); }
.stat-card-icon.yellow { background: rgba(245,158,11,0.15); color: var(--warning); }
.stat-card-icon.red { background: rgba(239,68,68,0.15); color: var(--danger); }
.stat-card-icon.cyan { background: rgba(6,182,212,0.15); color: var(--accent); }

.stat-card-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 4px;
}

.stat-card-label {
    font-size: 13px;
    color: var(--text-muted);
}

/* ─── Tables ────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dark);
    border-bottom: 1px solid var(--border);
    background: rgba(0,0,0,0.1);
    white-space: nowrap;
}

table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    vertical-align: middle;
}

table tbody tr:hover { background: var(--bg-card-hover); }
table tbody tr:last-child td { border-bottom: none; }

/* ─── Status Badges ─────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-active, .badge-success { background: rgba(16,185,129,0.15); color: var(--success); }
.badge-inactive { background: rgba(100,116,139,0.2); color: var(--text-muted); }
.badge-setup { background: rgba(245,158,11,0.15); color: var(--warning); }
.badge-suspended, .badge-failed { background: rgba(239,68,68,0.15); color: var(--danger); }
.badge-pending { background: rgba(99,102,241,0.15); color: var(--primary-light); }
.badge-running { background: rgba(6,182,212,0.15); color: var(--accent); }
.badge-rolled_back { background: rgba(100,116,139,0.2); color: var(--text-muted); }
.badge-info { background: rgba(59,130,246,0.15); color: var(--primary); }
.badge-secondary { background: rgba(107,114,128,0.15); color: var(--text-muted); }
.badge-primary { background: rgba(59,130,246,0.15); color: var(--primary); }
.badge-warning { background: rgba(234,179,8,0.15); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.15); color: var(--danger); }

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

.btn i { font-size: 14px; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; }

.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-success:hover { background: #059669; color: #fff; }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: #dc2626; color: #fff; }

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--border); color: #fff; }

.btn-outline {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}
.btn-outline:hover { border-color: var(--text-muted); color: var(--text); }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-icon { padding: 8px; }

/* ─── Forms ─────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.2);
}

.form-control::placeholder { color: var(--text-dark); }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-hint {
    font-size: 12px;
    color: var(--text-dark);
    margin-top: 4px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* ─── Alerts ────────────────────────────────────────────────────────── */
.alert {
    padding: 14px 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: rgba(16,185,129,0.15); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
.alert-error { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.alert-warning { background: rgba(245,158,11,0.15); color: var(--warning); border: 1px solid rgba(245,158,11,0.3); }
.alert-info { background: rgba(59,130,246,0.15); color: var(--info); border: 1px solid rgba(59,130,246,0.3); }

/* ─── Code / Log ────────────────────────────────────────────────────── */
.log-output {
    background: #0c1222;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12.5px;
    line-height: 1.7;
    color: var(--text-muted);
    overflow-x: auto;
    white-space: pre-wrap;
    max-height: 500px;
    overflow-y: auto;
}

/* ─── Pagination ────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 20px;
    justify-content: center;
}

.pagination a, .pagination span {
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-muted);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.pagination a:hover { background: var(--bg-card-hover); color: var(--text); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ─── Empty State ───────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 48px;
    opacity: 0.3;
    margin-bottom: 16px;
    display: block;
}

.empty-state p { font-size: 15px; }

/* ─── Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.show { display: flex; }

.modal, .modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-box { width: 500px; max-width: 95vw; }
.modal-box.modal-lg { width: 700px; }
.modal-box.modal-sm { width: 380px; }

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 16px; margin: 0; font-weight: 600; }
.modal-header.bg-success { background: var(--success); border-radius: var(--radius-lg) var(--radius-lg) 0 0; color: #fff; border-bottom: none; }
.modal-header.bg-primary { background: var(--primary); border-radius: var(--radius-lg) var(--radius-lg) 0 0; color: #fff; border-bottom: none; }
.modal-header.bg-danger { background: var(--danger); border-radius: var(--radius-lg) var(--radius-lg) 0 0; color: #fff; border-bottom: none; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    padding: 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-header.bg-success .modal-close,
.modal-header.bg-primary .modal-close,
.modal-header.bg-danger .modal-close { color: rgba(255,255,255,0.8); }
.modal-header.bg-success .modal-close:hover,
.modal-header.bg-primary .modal-close:hover,
.modal-header.bg-danger .modal-close:hover { color: #fff; }

.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ─── Toggle Switch ────────────────────────────────────────────────── */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    cursor: pointer;
    vertical-align: middle;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 22px;
    transition: background var(--transition);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    left: 3px;
    top: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--transition);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--success);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* ─── Grid Helpers ──────────────────────────────────────────────────── */
.grid-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.grid-3col {
    grid-template-columns: repeat(3, 1fr);
}

/* ─── Utility ───────────────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary-light); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mr-1 { margin-right: 8px; }
.gap-2 { gap: 16px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }

/* ─── Auth Layout ───────────────────────────────────────────────────── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 20px;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    padding: 40px 32px 24px;
}

.auth-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-lg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 20px;
}

.auth-header h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 14px;
}

.auth-body {
    padding: 0 32px 32px;
}

.auth-body .form-group { margin-bottom: 16px; }

.auth-body .btn { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }

/* ─── Content Header ────────────────────────────────────────────────── */
.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.content-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* (Modal styles consolidated above) */

/* ─── Permissions Grid ──────────────────────────────────────────────── */
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}
.perm-group {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}
.perm-group h6 {
    margin: 0 0 8px 0;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.perm-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    cursor: pointer;
    padding: 2px 0;
}
.perm-item input[type="checkbox"] {
    accent-color: var(--primary);
}

/* ─── Lock Screen ───────────────────────────────────────────────────── */
#lockScreenOverlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .3s;
}
.lock-card {
    background: var(--card);
    border-radius: 16px;
    padding: 40px 36px 32px;
    width: 340px;
    max-width: 90vw;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.lock-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 1.5rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}
.lock-user { font-size: 1.1rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.lock-hint { font-size: 0.82rem; color: var(--text-light); margin-bottom: 20px; }
.lock-pin-wrap { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }
.lock-pin-wrap input {
    width: 44px;
    height: 52px;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 700;
    border: 2px solid var(--border);
    border-radius: 10px;
    outline: none;
    background: var(--bg);
    color: var(--text);
    transition: border-color .2s;
}
.lock-pin-wrap input:focus { border-color: var(--primary); }
.lock-pin-wrap input.shake { animation: lockShake .4s; border-color: var(--danger); }
@keyframes lockShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}
.lock-error { color: var(--danger); font-size: 0.82rem; min-height: 1.2em; margin-bottom: 12px; }
.lock-btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    transition: .2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.lock-btn-primary { background: var(--primary); color: #fff; }
.lock-btn-primary:hover { opacity: 0.9; }
.lock-btn-outline { background: transparent; color: var(--text-light); border: 1px solid var(--border); margin-top: 8px; }
.lock-btn-outline:hover { background: var(--bg); }
.lock-time { font-size: 0.75rem; color: var(--text-light); margin-top: 16px; }
.lock-set-pin-input {
    width: 100%;
    padding: 12px;
    font-size: 1.2rem;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: 10px;
    letter-spacing: 8px;
    margin-bottom: 12px;
    background: var(--bg);
    color: var(--text);
}

/* ─── Responsive ────────────────────────────────────────────────────── */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 22px;
    cursor: pointer;
    padding: 4px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 9998;
}

@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        position: fixed;
        z-index: 9999;
        height: 100vh;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }
    .sidebar.open ~ .sidebar-backdrop,
    .sidebar-backdrop.show { display: block; }
    .main-content { margin-left: 0; }
    .sidebar-toggle { display: block; }
    .form-row { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .navbar-title { font-size: 1rem; }
    .navbar-user span { display: none; }
    .content-header { flex-direction: column; align-items: flex-start; }
    .permissions-grid { grid-template-columns: 1fr; }
    .modal-box.modal-lg { width: 95vw; }

    /* Grid helpers collapse */
    .grid-2col { grid-template-columns: 1fr; }
    .grid-3col { grid-template-columns: repeat(2, 1fr); }

    /* Inline grid overrides (fallback) */
    [style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
    [style*="grid-template-columns: repeat(3"] { grid-template-columns: repeat(2, 1fr) !important; }
    [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }

    /* Action button groups wrap */
    .d-flex.gap-2 { flex-wrap: wrap; }

    /* Table scroll for all tables */
    .table-wrap, .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrap table, .table-responsive table { min-width: 600px; }

    /* Danger zone stack */
    .card-body.d-flex.align-center.justify-between {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

@media (max-width: 576px) {
    .page-content { padding: 16px; }
    .navbar { padding: 0 16px; }
    .stats-grid { grid-template-columns: 1fr !important; }
    .grid-2col { grid-template-columns: 1fr; }
    .grid-3col { grid-template-columns: 1fr; }
    [style*="grid-template-columns: repeat(3"] { grid-template-columns: 1fr !important; }
    .navbar-actions { gap: 4px; }
    .navbar-actions .btn-sm { padding: 5px 8px; font-size: 11px; }
    .navbar-actions .btn-sm span,
    .navbar-actions .btn-outline.btn-sm span { display: none; }
    .btn-sm { padding: 6px 10px; font-size: 12px; }
    .lock-card { padding: 28px 20px 24px; }
    .lock-pin-wrap input { width: 38px; height: 44px; font-size: 1.2rem; }

    /* Modal full-width on small screens */
    .modal, .modal-box { width: 100%; max-width: 100%; }
    .modal-overlay { padding: 10px; }

    /* Card padding reduce */
    .card-body { padding: 16px; }
    .card-header { padding: 14px 16px; }

    /* Stat card compact */
    .stat-card { padding: 16px; }
    .stat-card-value { font-size: 22px; }
    .stat-card-icon { width: 36px; height: 36px; font-size: 16px; margin-bottom: 12px; }

    /* Hide logout text, keep icon */
    .navbar-actions a.btn-outline.btn-sm { padding: 5px 8px; }
}
