/* ─── CSS Variables ──────────────────────────────────────────────────────── */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 68px;
    --sidebar-bg: #1a1f2e;
    --sidebar-text: #8899aa;
    --sidebar-hover-bg: rgba(255,255,255,0.07);
    --sidebar-active-bg: #4f46e5;
    --sidebar-active-text: #fff;
    --navbar-height: 60px;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --content-bg: #f1f5f9;
    --card-bg: #fff;
    --border: #e2e8f0;
    --text-dark: #1e293b;
    --text-muted: #64748b;
}

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--content-bg);
    color: var(--text-dark);
    font-size: 14px;
}

a { text-decoration: none; color: inherit; }

/* ─── Layout Wrapper ─────────────────────────────────────────────────────── */
.wrapper {
    min-height: 100vh;
    display: flex;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.25s ease;
    scrollbar-width: thin;
    scrollbar-color: #2d3748 transparent;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: #2d3748; border-radius: 2px; }

#sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 70px;
    flex-shrink: 0;
}

.brand-logo {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    flex-shrink: 0;
}

.brand-text {
    overflow: hidden;
    white-space: nowrap;
}

.brand-text .brand-name {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    display: block;
    line-height: 1.2;
}

.brand-text .brand-sub {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--sidebar-text);
    display: block;
}

#sidebar.collapsed .brand-text { display: none; }

/* Menu */
.sidebar-menu {
    padding: 10px 0;
    flex: 1;
}

.menu-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #4a5568;
    padding: 14px 20px 6px;
    white-space: nowrap;
    overflow: hidden;
}

#sidebar.collapsed .menu-label {
    visibility: hidden;
    height: 28px;
    padding-top: 14px;
}

#sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 20px;
    color: var(--sidebar-text);
    border-radius: 0;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
    font-size: 13.5px;
    font-weight: 400;
    position: relative;
}

#sidebar .nav-link i {
    width: 18px;
    font-size: 14px;
    flex-shrink: 0;
    text-align: center;
    transition: color 0.15s;
}

#sidebar .nav-link span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

#sidebar .nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: #e2e8f0;
}

#sidebar .nav-link.active {
    background: var(--primary);
    color: var(--sidebar-active-text);
    font-weight: 500;
}

#sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 10px;
    gap: 0;
}

#sidebar.collapsed .nav-link span { display: none; }

/* ─── Main Content ────────────────────────────────────────────────────────── */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* ─── Top Navbar ──────────────────────────────────────────────────────────── */
.top-navbar {
    height: var(--navbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

#sidebarToggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 7px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: background 0.15s;
    padding: 0;
}

#sidebarToggle:hover {
    background: var(--content-bg);
}

.user-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 12px 5px 7px;
    color: var(--text-dark);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    transition: background 0.15s;
}

.user-btn:hover { background: var(--content-bg); }

.user-avatar {
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 12px;
}

.breadcrumb-item a { color: var(--primary); }
.breadcrumb-item a:hover { color: var(--primary-hover); }

/* ─── Page Content ────────────────────────────────────────────────────────── */
.page-content {
    padding: 24px;
    flex: 1;
}

/* ─── Page Header ─────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0;
    line-height: 1.3;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin: 3px 0 0;
}

/* ─── Stat Cards ──────────────────────────────────────────────────────────── */
.stat-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px 22px;
    border: 1px solid var(--border);
    transition: box-shadow 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    gap: 18px;
}

.stat-card:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
    transform: translateY(-1px);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.stat-info { flex: 1; min-width: 0; }

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 500;
}

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

.card-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    border-radius: 12px 12px 0 0;
}

.card-header h5, .card-header h6 {
    margin: 0;
    font-weight: 600;
}

.card-body { padding: 20px; }

/* ─── Tables ──────────────────────────────────────────────────────────────── */
.table {
    font-size: 13.5px;
}

.table thead th {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    padding: 10px 12px;
    background: #fafbfc;
    white-space: nowrap;
}

.table tbody td {
    padding: 11px 12px;
    vertical-align: middle;
    border-bottom: 1px solid #f0f4f8;
}

.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }

/* ─── Badges ──────────────────────────────────────────────────────────────── */
.badge-role {
    display: inline-block;
    background: #ede9fe;
    color: #5b21b6;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    margin: 1px 2px;
}

/* ─── Status Badge ────────────────────────────────────────────────────────── */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
}

.status-badge.active {
    background: #dcfce7;
    color: #166534;
}

.status-badge.inactive {
    background: #fee2e2;
    color: #991b1b;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn { border-radius: 8px; font-size: 13.5px; font-weight: 500; }
.btn-sm { border-radius: 6px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

/* Icon action buttons */
.btn-action {
    width: 30px;
    height: 30px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 12px;
    border: 1px solid transparent;
}

/* ─── Modals ──────────────────────────────────────────────────────────────── */
.modal-header {
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
}

.modal-footer {
    border-top: 1px solid var(--border);
    padding: 12px 20px;
}

.modal-title { font-size: 16px; font-weight: 600; }

/* ─── Form Controls ───────────────────────────────────────────────────────── */
.form-label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 5px;
}

.form-control, .form-select {
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13.5px;
    padding: 8px 12px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.form-text { font-size: 11.5px; }

/* ─── Permission Matrix ───────────────────────────────────────────────────── */
.permission-module {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 12px;
    overflow: hidden;
}

.permission-module-header {
    background: #f8fafc;
    padding: 10px 16px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}

.permission-module-body {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 12px 16px;
}

.perm-check {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    font-size: 12.5px;
}

.perm-check:hover {
    border-color: var(--primary);
    background: #ede9fe20;
}

.perm-check input[type="checkbox"] {
    cursor: pointer;
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
}

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

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

.empty-state p { margin: 0; font-size: 14px; }

/* ─── Auth Layout ─────────────────────────────────────────────────────────── */
.auth-wrapper {
    min-height: 100vh;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #2563eb 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.16);
}

.auth-header {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 24px;
    margin: 0 auto 14px;
}

.auth-header h4 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0 0 4px;
}

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

/* ─── DataTables Overrides ────────────────────────────────────────────────── */
div.dataTables_wrapper div.dataTables_filter input {
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 5px 10px;
    font-size: 13px;
}

div.dataTables_wrapper div.dataTables_length select {
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 4px 8px;
    font-size: 13px;
}

div.dataTables_wrapper div.dataTables_info { font-size: 12.5px; color: var(--text-muted); }

.page-item.active .page-link { background-color: var(--primary); border-color: var(--primary); }
.page-link { color: var(--primary); font-size: 13px; }
.page-link:hover { color: var(--primary-hover); }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        left: -260px;
        z-index: 1050;
        height: 100vh;
        transition: left 0.25s ease, width 0.25s ease;
    }

    #sidebar.mobile-open {
        left: 0;
    }

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

    .sidebar-overlay.active { display: block; }

    .page-content { padding: 16px; }
}

/* ─── Misc ────────────────────────────────────────────────────────────────── */
.dropdown-item { font-size: 13.5px; }
.dropdown-menu { border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.1); }
.alert { border-radius: 8px; font-size: 13.5px; }
.fw-semibold { font-weight: 600; }
