:root {
    --primary: #0891b2;
    --primary-dark: #0e7490;
    --primary-light: #67e8f9;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #0891b2;
    --sidebar-text: #94a3b8;
    --sidebar-width: 260px;
    --header-h: 64px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.07), 0 4px 16px rgba(0,0,0,.05);
    --shadow-md: 0 4px 24px rgba(8,145,178,.14);
    --font: 'Sarabun', 'Inter', sans-serif;
}

*,*::before,*::after { box-sizing: border-box; }

body {
    font-family: var(--font);
    background: #f5f6fa;
    color: #1e293b;
    margin: 0;
    overflow-x: hidden;
}

/* ── SIDEBAR ── */
#sidebar {
    position: fixed;
    top: 0; left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: transform .3s ease, width .3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

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

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    text-decoration: none;
}
.sidebar-brand-icon {
    width: 38px; height: 38px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 18px;
    flex-shrink: 0;
}
.sidebar-brand-text {
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
}
.sidebar-brand-text span {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--sidebar-text);
    margin-top: 2px;
}

.sidebar-section {
    padding: 20px 12px 8px;
}
.sidebar-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: #6366f1;
    padding: 0 8px;
    margin-bottom: 4px;
}

.nav-group { margin-bottom: 2px; }

.nav-group-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--sidebar-text);
    font-size: 13.5px;
    font-weight: 500;
    transition: background .2s, color .2s;
    user-select: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}
.nav-group-toggle:hover { background: var(--sidebar-hover); color: #fff; }
.nav-group-toggle.open { color: #fff; }
.nav-group-toggle .nav-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: rgba(255,255,255,.07);
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    transition: background .2s;
}
.nav-group-toggle:hover .nav-icon,
.nav-group-toggle.open .nav-icon { background: rgba(99,102,241,.4); }
.nav-group-toggle .nav-label { flex: 1; }
.nav-group-toggle .nav-arrow {
    font-size: 11px;
    transition: transform .25s;
    opacity: .6;
}
.nav-group-toggle.open .nav-arrow { transform: rotate(90deg); }

.nav-sub {
    overflow: hidden;
    max-height: 0;
    transition: max-height .3s ease;
}
.nav-sub.open { max-height: 400px; }
.nav-sub a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px 7px 54px;
    font-size: 13px;
    color: #a5b4fc;
    text-decoration: none;
    border-radius: 6px;
    margin: 1px 0;
    transition: background .2s, color .2s;
}
.nav-sub a:hover { background: var(--sidebar-hover); color: #fff; }
.nav-sub a.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}
.nav-sub a::before {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    background: currentColor;
    opacity: .5;
    flex-shrink: 0;
}
.nav-sub a.active::before { opacity: 1; }

/* ── MAIN LAYOUT ── */
#main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left .3s ease;
}

/* ── HEADER ── */
#topbar {
    height: var(--header-h);
    background: #fff;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: 0 1px 0 #f1f5f9;
}
#sidebar-toggle {
    display: none;
    align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: 8px;
    border: none;
    background: #f8fafc;
    cursor: pointer;
    font-size: 16px;
    color: #64748b;
    transition: background .2s;
}
#sidebar-toggle:hover { background: #e2e8f0; }
.topbar-spacer { flex: 1; }
.topbar-action {
    width: 36px; height: 36px;
    border-radius: 8px;
    border: none;
    background: #f8fafc;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    color: #64748b;
    transition: background .2s;
    position: relative;
}
.topbar-action:hover { background: #e2e8f0; }
.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background .2s;
}
.topbar-user:hover { background: #f8fafc; }
.topbar-avatar {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
}
.topbar-username { font-size: 13px; font-weight: 600; color: #1e293b; }

/* ── PAGE CONTENT ── */
#page-content {
    padding: 28px 24px;
    flex: 1;
}
.page-header {
    margin-bottom: 24px;
}
.page-title {
    font-size: 20px;
    font-weight: 700;
    color: #0f172a;
    margin: 0 0 4px;
}
.page-subtitle { font-size: 13px; color: #64748b; margin: 0; }

/* ── CARDS ── */
.card {
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid #e9ecef;
    box-shadow: var(--shadow);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-title {
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}
.card-body { padding: 20px; }

/* ── STAT CARDS ── */
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid #e9ecef;
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: var(--shadow);
    transition: box-shadow .2s, transform .2s;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.stat-icon.indigo { background: #eef2ff; color: var(--primary); }
.stat-icon.green  { background: #f0fdf4; color: #16a34a; }
.stat-icon.amber  { background: #fffbeb; color: #d97706; }
.stat-icon.rose   { background: #fff1f2; color: #e11d48; }
.stat-label { font-size: 12px; font-weight: 600; color: #64748b; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.stat-value { font-size: 24px; font-weight: 700; color: #0f172a; line-height: 1.1; }
.stat-sub { font-size: 12px; color: #94a3b8; margin-top: 4px; }

/* ── FORMS ── */
.form-label { font-size: 13px; font-weight: 600; color: #374151; margin-bottom: 6px; }
.form-control {
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: var(--font);
    transition: border-color .2s, box-shadow .2s;
    background: #fff;
    width: 100%;
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.12);
    outline: none;
}

/* ── BUTTONS ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    border: none;
    transition: all .2s;
    text-decoration: none;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(79,70,229,.3); }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; box-shadow: 0 4px 12px rgba(22,163,74,.3); }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: #f1f5f9; color: #475569; border: 1.5px solid #e2e8f0; }
.btn-secondary:hover { background: #e2e8f0; }
.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: 6px; }
.btn-w100 { width: 100%; }

/* ── BADGE ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.badge-success { background: #dcfce7; color: #16a34a; }
.badge-danger  { background: #fee2e2; color: #dc2626; }
.badge-warning { background: #fef9c3; color: #ca8a04; }
.badge-info    { background: #dbeafe; color: #2563eb; }

/* ── TABLE ── */
.table-card { overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
    background: #f8fafc;
    padding: 11px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid #e9ecef;
    white-space: nowrap;
}
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: #374151;
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }

/* ── LOGIN PAGE ── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 40%, #4338ca 100%);
}
.login-left {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    display: none;
}
.login-right {
    width: 420px;
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 40px;
}
.login-logo {
    width: 52px; height: 52px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    color: #fff;
    margin-bottom: 20px;
}
.login-title { font-size: 22px; font-weight: 700; color: #0f172a; margin-bottom: 6px; }
.login-subtitle { font-size: 14px; color: #64748b; margin-bottom: 32px; text-align: center; }
.login-form { width: 100%; }
.login-form .form-group { margin-bottom: 16px; }
.input-icon-wrap { position: relative; }
.input-icon-wrap .form-control { padding-left: 40px; }
.input-icon-wrap .input-icon {
    position: absolute;
    left: 12px; top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 15px;
}
.login-divider { margin: 8px 0 24px; border: none; border-top: 1px solid #f1f5f9; }
.login-footer { font-size: 12px; color: #94a3b8; margin-top: 24px; text-align: center; }

/* ── RESPONSIVE ── */
@media (min-width: 992px) {
    .login-left { display: flex; }
    #sidebar-toggle { display: none; }
}
@media (max-width: 991.98px) {
    #sidebar {
        transform: translateX(-100%);
    }
    #sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.2);
    }
    #main-wrapper { margin-left: 0; }
    #sidebar-toggle { display: flex; }
    #sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.4);
        z-index: 999;
    }
    #sidebar-overlay.show { display: block; }
    .login-right { width: 100%; padding: 40px 24px; }
}
@media (max-width: 575.98px) {
    #page-content { padding: 20px 16px; }
    .stat-value { font-size: 20px; }
}

/* ── UTILITIES ── */
.text-muted { color: #64748b !important; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-0{margin-top:0}.mt-1{margin-top:4px}.mt-2{margin-top:8px}.mt-3{margin-top:12px}.mt-4{margin-top:16px}.mt-5{margin-top:20px}.mt-6{margin-top:24px}
.mb-0{margin-bottom:0}.mb-1{margin-bottom:4px}.mb-2{margin-bottom:8px}.mb-3{margin-bottom:12px}.mb-4{margin-bottom:16px}.mb-6{margin-bottom:24px}
.gap-2{gap:8px}.gap-3{gap:12px}
.d-flex{display:flex}.align-center{align-items:center}.justify-between{justify-content:space-between}
.w-100{width:100%}.rounded{border-radius:var(--radius)}
.overflow-hidden{overflow:hidden}
.dataTables_wrapper .dataTables_filter input { border: 1.5px solid #e2e8f0; border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.dataTables_wrapper .dataTables_length select { border: 1.5px solid #e2e8f0; border-radius: 8px; padding: 5px 8px; }
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 6px !important;
    border: none !important;
    padding: 4px 10px !important;
    font-size: 13px !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--primary) !important;
    color: #fff !important;
}
