/* ========================================
   CSS Variables & Theme
   ======================================== */
:root {
    /* Colors */
    --primary: #fbcfe8;
    --primary-dark: #f9a8d4;
    --primary-light: #fce7f3;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* ── Bootstrap 5 CSS Variable Overrides (Theme Mapping) ── */
    --bs-primary: #ec4899;
    --bs-primary-rgb: 219, 39, 119;
    --bs-link-color: #ec4899;
    --bs-link-color-rgb: 219, 39, 119;
    --bs-link-hover-color: #db2777;
    --bs-link-hover-color-rgb: 190, 24, 93;
    /* Sidebar - ใช้สีตายตัว เพราะ sidebar มีพื้นหลังเข้มทั้ง light/dark */
    --sidebar-width: 260px;
    /* Topbar */
    --topbar-height: 64px;
    --topbar-bg: #ffffff;
    --topbar-border: #e2e8f0;
    /* Background */
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    /* Text */
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    /* Border */
    --border-color: #e2e8f0;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    /* Shadow */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    /* Transitions */
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;
}

/* ── Dark Theme ── */
[data-theme="dark"] {
    --topbar-bg: #0f172a;
    --topbar-border: #1e293b;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
}

[data-theme="dark"] .text-muted {
    color: #94a3b8 !important;
}

/* ── White / Blue Theme ── */
[data-theme="white"] {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --bs-primary: #2563eb;
    --bs-primary-rgb: 37, 99, 235;
    --bs-link-color: #2563eb;
    --bs-link-color-rgb: 37, 99, 235;
    --bs-link-hover-color: #1d4ed8;
    --bs-link-hover-color-rgb: 29, 78, 216;
    --topbar-bg: #ffffff;
    --topbar-border: #e2e8f0;
    --bg-primary: #ffffff;
    --bg-secondary: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #cbd5e1;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.06), 0 2px 4px -1px rgba(0,0,0,0.04);
}

[data-theme="white"] .bg-primary-soft {
    background: rgba(37, 99, 235, 0.08);
}

[data-theme="white"] .text-primary {
    color: var(--primary) !important;
}

/* ── White Theme: Sidebar Override (Blue) ── */
[data-theme="white"] .sidebar {
    background: linear-gradient(180deg, #0a1628 0%, #0f2044 50%, #1e3a8a 100%);
    border-right-color: rgba(147, 197, 253, 0.15);
}

[data-theme="white"] .brand-name {
    color: #eff6ff;
}

[data-theme="white"] .brand-tagline {
    color: #bfdbfe;
}

[data-theme="white"] .sidebar-close-btn {
    color: #bfdbfe;
}

[data-theme="white"] .sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #eff6ff;
}

[data-theme="white"] .sidebar-divider {
    background: rgba(147, 197, 253, 0.25);
}

[data-theme="white"] .user-name {
    color: #eff6ff;
}

[data-theme="white"] .user-role {
    color: #bfdbfe;
}

[data-theme="white"] .status-dot {
    border-color: #1d4ed8;
}

[data-theme="white"] .nav-section-label {
    color: #93c5fd;
}

[data-theme="white"] .sidebar-footer {
    border-top-color: rgba(147, 197, 253, 0.2);
}

[data-theme="white"] .app-version {
    color: #bfdbfe;
}

[data-theme="white"] .sidebar .nav-link {
    color: #bfdbfe !important;
    background-color: transparent !important;
}

[data-theme="white"] .sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    color: #eff6ff !important;
}

[data-theme="white"] .sidebar .nav-link.active {
    background-color: rgba(255, 255, 255, 0.18) !important;
    color: #ffffff !important;
    box-shadow: inset 3px 0 0 #93c5fd !important;
}

[data-theme="white"] .sidebar .nav-link.active .nav-icon {
    color: #93c5fd !important;
}

[data-theme="white"] .sidebar .nav-collapse-toggle {
    color: #bfdbfe !important;
    background-color: transparent !important;
}

[data-theme="white"] .sidebar .nav-collapse-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
    color: #eff6ff !important;
}

[data-theme="white"] .sidebar .nav-collapse-toggle.active {
    background-color: rgba(255, 255, 255, 0.18) !important;
    color: #ffffff !important;
}

[data-theme="white"] .sidebar a.nav-link:focus,
[data-theme="white"] .sidebar a.nav-link:focus-visible,
[data-theme="white"] .sidebar a.nav-collapse-toggle:focus,
[data-theme="white"] .sidebar a.nav-collapse-toggle:focus-visible {
    color: #eff6ff !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
    outline: 2px solid rgba(147, 197, 253, 0.4) !important;
}

[data-theme="white"] .sidebar .sub-nav-link {
    color: #bfdbfe !important;
    background-color: transparent !important;
}

[data-theme="white"] .sidebar .sub-nav-link:hover {
    color: #eff6ff !important;
    background-color: rgba(255, 255, 255, 0.08) !important;
}

[data-theme="white"] .sidebar .sub-nav-link.active {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.15) !important;
}

[data-theme="white"] .sidebar .sub-nav-link:hover .sub-dot,
[data-theme="white"] .sidebar .sub-nav-link.active .sub-dot {
    color: #93c5fd;
    opacity: 1;
}

[data-theme="white"] .sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(147, 197, 253, 0.3);
}

[data-theme="white"] .collapse-arrow {
    color: #93c5fd;
}

[data-theme="white"] .sidebar .nav-collapse-toggle[aria-expanded="true"] .collapse-arrow {
    color: #bfdbfe;
}

/* ========================================
   Base Styles
   ======================================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Sarabun', 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    transition: var(--transition-fast);
}

/* ========================================
   Scrollbar
   ======================================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

    ::-webkit-scrollbar-thumb:hover {
        background: var(--text-muted);
    }

/* ========================================
   Page Loader
   ======================================== */
#pageLoader {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

    #pageLoader.hidden {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }

.loader-spinner {
    text-align: center;
}

    .loader-spinner p {
        font-size: 14px;
        color: var(--text-muted);
        margin-top: 12px;
    }

.spinner-ring {
    width: 50px;
    height: 50px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========================================
   App Layout
   ======================================== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ========================================
   Sidebar
   ======================================== */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #be185d 0%, #db2777 60%, #ec4899 100%);
    border-right: 1px solid rgba(251, 207, 232, 0.3);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden; /* ห้าม scroll ที่ sidebar โดยตรง — ให้ sidebar-nav รับผิดชอบแทน */
}

[data-theme="dark"] .sidebar {
    background: #020617;
    border-right-color: #1e293b;
}

[data-theme="dark"] .brand-name {
    color: #f8fafc;
}

[data-theme="dark"] .brand-tagline {
    color: #cbd5e1;
}

[data-theme="dark"] .sidebar-close-btn {
    color: #cbd5e1;
}

[data-theme="dark"] .sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
}

[data-theme="dark"] .sidebar-divider {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .user-name {
    color: #f8fafc;
}

[data-theme="dark"] .user-role {
    color: #cbd5e1;
}

[data-theme="dark"] .nav-section-label {
    color: #64748b;
}

[data-theme="dark"] .sidebar-footer {
    border-top-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .app-version {
    color: #94a3b8;
}

[data-theme="dark"] .sidebar .nav-link {
    color: #f8fafc !important;
    background-color: transparent !important;
}

[data-theme="dark"] .sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.08) !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .sidebar .nav-link.active {
    background-color: rgba(251, 207, 232, 0.15) !important;
    color: #f8fafc !important;
    box-shadow: inset 3px 0 0 #fbcfe8 !important;
}

[data-theme="dark"] .sidebar .nav-link.active .nav-icon {
    color: #fbcfe8 !important;
}

[data-theme="dark"] .sidebar .nav-collapse-toggle {
    color: #f8fafc !important;
    background-color: transparent !important;
}

[data-theme="dark"] .sidebar .nav-collapse-toggle:hover {
    background-color: rgba(255, 255, 255, 0.08) !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .sidebar .nav-collapse-toggle.active {
    background-color: rgba(251, 207, 232, 0.15) !important;
    color: #f8fafc !important;
}

[data-theme="dark"] .sidebar a.nav-link:focus,
[data-theme="dark"] .sidebar a.nav-link:focus-visible,
[data-theme="dark"] .sidebar a.nav-collapse-toggle:focus,
[data-theme="dark"] .sidebar a.nav-collapse-toggle:focus-visible {
    color: #f8fafc !important;
    background-color: rgba(255, 255, 255, 0.08) !important;
    outline: 2px solid rgba(248, 250, 252, 0.3) !important;
}

[data-theme="dark"] .sidebar .sub-nav-link {
    color: #e2e8f0 !important;
    background-color: transparent !important;
}

[data-theme="dark"] .sidebar .sub-nav-link:hover {
    color: #f8fafc !important;
    background-color: rgba(255, 255, 255, 0.06) !important;
}

[data-theme="dark"] .sidebar .sub-nav-link.active {
    color: #f8fafc !important;
    background-color: rgba(251, 207, 232, 0.1) !important;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* ── Sidebar Brand ── */
.sidebar-brand {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    overflow: hidden;
}

.logo-icon {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #ffffff;
    padding: 2px;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15), 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: var(--transition-fast);
}

    .logo-icon:hover {
        box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3), 0 6px 16px rgba(0, 0, 0, 0.4);
        transform: scale(1.05);
    }

.logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}

.brand-text {
    overflow: hidden;
    transition: var(--transition);
    white-space: nowrap;
}

.brand-name {
    display: block;
    font-size: 16px;
    font-weight: 700;
    color: #fce7f3;
    letter-spacing: 0.5px;
}

.brand-tagline {
    display: block;
    font-size: 11px;
    color: #fbcfe8;
}

.sidebar-close-btn {
    background: none;
    border: none;
    color: #fbcfe8;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: var(--transition-fast);
    flex-shrink: 0;
}

    .sidebar-close-btn:hover {
        background: rgba(255, 255, 255, 0.1);
        color: #fce7f3;
    }

/* ── Sidebar Divider ── */
.sidebar-divider {
    height: 1px;
    background: rgba(251, 207, 232, 0.2);
    margin: 4px 20px;
    flex-shrink: 0;
}

/* ── Sidebar User ── */
.sidebar-user {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    overflow: hidden;
}

.user-avatar {
    position: relative;
    flex-shrink: 0;
}

.avatar-img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.1);
    object-fit: cover;
}

.status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 2px solid #ec4899;
}

[data-theme="dark"] .status-dot {
    border-color: #020617;
}

.status-dot.online {
    background: #22c55e;
}

.status-dot.away {
    background: #f59e0b;
}

.status-dot.offline {
    background: #64748b;
}

.user-info {
    overflow: hidden;
    white-space: nowrap;
    transition: var(--transition);
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: #fce7f3;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 11px;
    color: #fbcfe8;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 0;
}

/* ── Sidebar Navigation ── */
.sidebar-nav {
    flex: 1;
    padding: 8px 12px;
    overflow-y: auto;       /* scroll เมนูได้ตลอดเวลา */
    overflow-x: hidden;
    min-height: 0;          /* จำเป็นสำหรับ flex child ให้ scroll ได้ */
}

.sidebar-nav::-webkit-scrollbar {
    width: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(251, 207, 232, 0.3);
    border-radius: 2px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(251, 207, 232, 0.5);
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: #fbcfe8;
    padding: 12px 8px 6px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    transition: var(--transition);
}

.nav-list {
    list-style: none;
    padding: 0;
    margin: 0 0 8px;
}

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

/* ── Nav Link ── */
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #94a3b8;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
}

    .nav-link:hover {
        background: rgba(255, 255, 255, 0.08);
        color: #f8fafc;
        transform: translateX(2px);
    }

    .nav-link.active {
        background: rgba(251, 207, 232, 0.15);
        color: #fbcfe8;
        box-shadow: inset 3px 0 0 #fbcfe8;
    }

        .nav-link.active .nav-icon {
            color: #fbcfe8;
        }

.nav-icon {
    width: 20px;
    min-width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: var(--transition-fast);
}

.nav-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: var(--transition);
    color: inherit;
}

.nav-badge {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 20px;
    font-weight: 600;
    flex-shrink: 0;
    transition: var(--transition);
}

/* ── Collapse Arrow ── */
.collapse-arrow {
    font-size: 11px;
    flex-shrink: 0;
    color: #64748b;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.nav-collapse-toggle[aria-expanded="true"] .collapse-arrow {
    transform: rotate(90deg);
    color: #fbcfe8;
}

/* ========================================
   Sub Navigation - แก้ปัญหา Light Theme
   ======================================== */
.collapse-menu {
    overflow: hidden;
}

.sub-nav-list {
    list-style: none;
    padding: 4px 0 4px 20px;
    margin: 0;
}

/* ✅ กำหนดสีตายตัว ไม่ขึ้นกับ CSS Variable ของ theme หลัก
      เพราะ sidebar มีพื้นหลังเข้มเสมอทั้ง Light และ Dark theme */
.sub-nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    color: #94a3b8 !important;
    background: transparent !important;
    text-decoration: none;
    font-size: 13px;
    font-weight: 400;
    transition: color 0.15s ease, background 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
}

    .sub-nav-link:hover {
        color: #f8fafc !important;
        background: rgba(255, 255, 255, 0.06) !important;
    }

    .sub-nav-link.active {
        color: #fbcfe8 !important;
        background: rgba(251, 207, 232, 0.1) !important;
        font-weight: 500;
    }

.sub-nav-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
    opacity: 1;
    visibility: visible;
}

.sub-dot {
    font-size: 6px;
    flex-shrink: 0;
    min-width: 6px;
    color: #94a3b8;
    opacity: 0.4;
    transition: var(--transition-fast);
}

.sub-nav-link:hover .sub-dot {
    opacity: 1;
    color: #fbcfe8;
}

.sub-nav-link.active .sub-dot {
    opacity: 1;
    color: #fbcfe8;
}

/* ── Sidebar Footer ── */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(251, 207, 232, 0.2);
    flex-shrink: 0;
    overflow: hidden;
    transition: var(--transition);
}

.app-version {
    font-size: 11px;
    color: #fbcfe8;
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 1;
    white-space: nowrap;
}

/* ── Sidebar Overlay (Mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

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

/* ========================================
   Sidebar Collapsed State (Desktop)
   ======================================== */
.sidebar-collapsed .sidebar {
    width: 70px;
}

    .sidebar-collapsed .sidebar .brand-text,
    .sidebar-collapsed .sidebar .user-info,
    .sidebar-collapsed .sidebar .nav-text,
    .sidebar-collapsed .sidebar .nav-badge,
    .sidebar-collapsed .sidebar .collapse-arrow,
    .sidebar-collapsed .sidebar .nav-section-label,
    .sidebar-collapsed .sidebar .sidebar-footer {
        opacity: 0;
        width: 0;
        overflow: hidden;
    }

    .sidebar-collapsed .sidebar .collapse-menu {
        display: none !important;
    }

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

    .sidebar-collapsed .sidebar .sidebar-brand {
        justify-content: center;
        padding: 20px 15px;
    }

    .sidebar-collapsed .sidebar .sidebar-close-btn {
        display: none;
    }

    .sidebar-collapsed .sidebar .sidebar-user {
        justify-content: center;
        padding: 16px 10px;
    }

    /* ── Tooltip (Collapsed Sidebar) ── */
    .sidebar-collapsed .sidebar .nav-link {
        position: relative;
    }

        .sidebar-collapsed .sidebar .nav-link::after {
            content: attr(data-tooltip);
            position: absolute;
            left: calc(100% + 14px);
            top: 50%;
            transform: translateY(-50%);
            background: #1e293b;
            color: #f8fafc;
            padding: 6px 12px;
            border-radius: 8px;
            font-size: 13px;
            white-space: nowrap;
            pointer-events: none;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.2s ease, visibility 0.2s ease;
            z-index: 1050;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
        }

        .sidebar-collapsed .sidebar .nav-link::before {
            content: '';
            position: absolute;
            left: calc(100% + 8px);
            top: 50%;
            transform: translateY(-50%);
            border: 5px solid transparent;
            border-right-color: #1e293b;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.2s ease, visibility 0.2s ease;
            z-index: 1051;
        }

        .sidebar-collapsed .sidebar .nav-link:hover::after,
        .sidebar-collapsed .sidebar .nav-link:hover::before {
            opacity: 1;
            visibility: visible;
        }

/* ========================================
   Main Content
   ======================================== */
.main-content {
    flex: 1;
    min-width: 0;
    overflow-x: hidden;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-primary);
}

.sidebar-collapsed .main-content {
    margin-left: 70px;
}

/* ========================================
   Topbar
   ======================================== */
.topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Topbar Button ── */
.topbar-btn {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: var(--transition-fast);
    position: relative;
}

    .topbar-btn:hover {
        background: var(--bg-primary);
        color: var(--primary);
    }

/* ── Notification Badge ── */
.notification-badge {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 18px;
    height: 18px;
    background: var(--danger);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--topbar-bg);
    line-height: 1;
}

/* ── Search ── */
.topbar-search {
    display: flex;
    align-items: center;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    font-size: 14px;
    pointer-events: none;
}

.search-input {
    width: 280px;
    height: 38px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0 80px 0 36px;
    font-size: 14px;
    font-family: 'Sarabun', 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: width 0.3s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

    .search-input::placeholder {
        color: var(--text-muted);
    }

    .search-input:focus {
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(251, 207, 232, 0.12);
        width: 320px;
    }

.search-shortcut {
    position: absolute;
    right: 10px;
    font-size: 10px;
    background: var(--border-color);
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 5px;
    font-family: monospace;
    border: 1px solid var(--border-color);
    pointer-events: none;
}

/* ── Topbar Logo (Mobile) ── */
.topbar-logo {
    display: flex;
    align-items: center;
}

.topbar-logo-img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: 50%;
}

/* ── Topbar User Button ── */
.topbar-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px 4px 4px;
    border: 1px solid var(--border-color);
    border-radius: 40px;
    background: transparent;
    cursor: pointer;
    transition: var(--transition-fast);
    color: var(--text-primary);
}

    .topbar-user-btn:hover {
        background: var(--bg-primary);
        border-color: var(--primary);
    }

.user-avatar-sm {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name-sm {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
}

.user-role-sm {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1;
}

/* ── Notification Dropdown ── */
.notification-dropdown {
    width: 360px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    padding: 0;
    background: var(--bg-card);
}

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

    .dropdown-header h6 {
        color: var(--text-primary);
        margin: 0;
    }

.notification-list {
    max-height: 320px;
    overflow-y: auto;
}

.notification-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-primary);
    transition: var(--transition-fast);
}

    .notification-item:last-child {
        border-bottom: none;
    }

    .notification-item:hover {
        background: var(--bg-primary);
    }

    .notification-item.unread {
        background: rgba(251, 207, 232, 0.04);
    }

.notif-icon {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.bg-primary-soft {
    background: rgba(251, 207, 232, 0.12);
}

.bg-success-soft {
    background: rgba(34, 197, 94, 0.12);
}

.bg-warning-soft {
    background: rgba(245, 158, 11, 0.12);
}

.bg-danger-soft {
    background: rgba(239, 68, 68, 0.12);
}

.notif-content {
    flex: 1;
    overflow: hidden;
}

.notif-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notif-time {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.dropdown-footer {
    padding: 12px 16px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

/* ── User Dropdown ── */
.user-dropdown {
    min-width: 220px;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--border-radius) !important;
    box-shadow: var(--shadow-xl) !important;
    padding: 8px !important;
    background: var(--bg-card) !important;
    --bs-dropdown-bg: var(--bg-card);
    --bs-dropdown-color: var(--text-primary);
    --bs-dropdown-border-color: var(--border-color);
    --bs-dropdown-item-color: var(--text-primary);
}

.dropdown-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 8px;
    background: var(--bg-primary);
    margin-bottom: 4px;
}

    .dropdown-user-info img {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        object-fit: cover;
    }

    .dropdown-user-info p {
        color: var(--text-primary);
        margin: 0;
    }

    .dropdown-user-info small {
        color: var(--text-muted);
    }

.user-dropdown .dropdown-item {
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 13px;
    transition: var(--transition-fast);
    color: var(--text-primary);
    display: flex;
    align-items: center;
}

    .user-dropdown .dropdown-item:hover {
        background: rgba(251, 207, 232, 0.08);
        color: var(--primary);
    }

    .user-dropdown .dropdown-item.text-danger {
        color: #dc2626 !important;
        font-weight: 600;
    }

        .user-dropdown .dropdown-item.text-danger:hover {
            background: rgba(220, 38, 38, 0.10) !important;
            color: #b91c1c !important;
        }

.user-dropdown .dropdown-divider {
    border-color: var(--border-color);
    margin: 4px 0;
}

/* ========================================
   Content Area
   ======================================== */
.content-area {
    flex: 1;
    padding: 24px;
}

/* ── Breadcrumb ── */
.breadcrumb-wrapper {
    margin-bottom: 20px;
}

.breadcrumb {
    background: transparent;
    padding: 0;
    margin: 0;
    font-size: 13px;
}

.breadcrumb-item + .breadcrumb-item::before {
    color: var(--text-muted);
}

.breadcrumb-item a {
    color: var(--text-secondary);
    text-decoration: none;
}

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

.breadcrumb-item.active {
    color: var(--text-primary);
    font-weight: 500;
}

/* ── Alert ── */
.custom-alert {
    border-radius: var(--border-radius);
    border: none;
    padding: 14px 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    font-size: 14px;
}

/* ── Page Body Animation ── */
.page-body {
    animation: fadeInUp 0.4s ease both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   Cards
   ======================================== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

    .card:hover {
        box-shadow: var(--shadow-md);
    }

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    color: var(--text-primary);
}

/* ── Stat Card ── */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
}

    .stat-card:hover {
        transform: translateY(-3px);
        box-shadow: var(--shadow-lg);
        border-color: var(--primary);
        color: inherit;
    }

.stat-icon {
    width: 56px;
    height: 56px;
    min-width: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary);
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 2px 0;
}

.stat-change {
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 3px;
}

    .stat-change.up {
        color: var(--success);
    }

    .stat-change.down {
        color: var(--danger);
    }

/* ========================================
   Table
   ======================================== */
.table {
    color: var(--text-primary);
    --bs-table-bg: transparent;
    --bs-table-hover-bg: rgba(251, 207, 232, 0.04);
}

    .table thead th {
        font-size: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-muted);
        border-bottom: 1px solid var(--border-color);
        padding: 12px 16px;
        background: var(--bg-primary);
    }

    .table tbody td {
        padding: 14px 16px;
        border-bottom: 1px solid var(--border-color);
        vertical-align: middle;
        font-size: 14px;
        color: var(--text-primary);
    }

    .table tbody tr:last-child td {
        border-bottom: none;
    }

.table-light {
    --bs-table-bg: var(--bg-primary);
    color: var(--text-muted);
}

/* ========================================
   Buttons
   ======================================== */
.btn {
    border-radius: var(--border-radius-sm);
    font-weight: 500;
    font-size: 14px;
    font-family: 'Sarabun', 'Inter', sans-serif;
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

    .btn-primary:hover {
        background: var(--primary-dark);
        border-color: var(--primary-dark);
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(251, 207, 232, 0.35);
        color: #ffffff;
    }

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

    .btn-outline-primary:hover {
        background: var(--primary);
        border-color: var(--primary);
        transform: translateY(-1px);
        color: #ffffff;
    }

.btn-outline-secondary {
    color: var(--text-secondary);
    border-color: var(--border-color);
    background: var(--bg-card);
}

    .btn-outline-secondary:hover {
        background: var(--bg-primary);
        color: var(--text-primary);
        border-color: var(--border-color);
    }

/* ========================================
   Badge
   ======================================== */
.badge {
    font-weight: 600;
    font-size: 11px;
}

/* ========================================
   Progress
   ======================================== */
.progress {
    background: var(--border-color);
}

/* ========================================
   Forms
   ======================================== */
.form-control,
.form-select {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--border-radius-sm);
    font-family: 'Sarabun', 'Inter', sans-serif;
    font-size: 14px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

    .form-control:focus,
    .form-select:focus {
        background: var(--bg-card);
        border-color: var(--primary);
        color: var(--text-primary);
        box-shadow: 0 0 0 3px rgba(251, 207, 232, 0.12);
    }

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

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

/* ========================================
   Footer
   ======================================== */
.app-footer {
    background: var(--topbar-bg);
    border-top: 1px solid var(--topbar-border);
    padding: 16px 24px;
    transition: background 0.3s ease, left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── ป้องกัน content ถูก fixed footer บัง ── */
.content-area {
    padding-bottom: 60px;
}

.footer-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.footer-text {
    font-size: 13px;
    color: var(--text-secondary);
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

    .footer-links a {
        color: var(--text-secondary);
        text-decoration: none;
        transition: var(--transition-fast);
    }

        .footer-links a:hover {
            color: var(--primary);
        }

/* ========================================
   Toast
   ======================================== */
.toast {
    background: var(--bg-card) !important;
    border-radius: var(--border-radius) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary);
}

    .toast .btn-close {
        filter: var(--text-primary) == '#0f172a' ? none : invert(1);
    }

/* ========================================
   Utilities
   ======================================== */
.text-primary-custom {
    color: var(--primary) !important;
}

.bg-primary-gradient {
    background: linear-gradient(135deg, var(--primary), var(--primary-light)) !important;
}

.rounded-custom {
    border-radius: var(--border-radius) !important;
}

.shadow-custom {
    box-shadow: var(--shadow-md) !important;
}

/* ========================================
   Responsive - Tablet
   ======================================== */
@media (max-width: 991.98px) {

    /* Sidebar ซ่อนออกไปทางซ้าย */
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }

        .sidebar.show {
            transform: translateX(0);
        }

    /* Main content ใช้พื้นที่เต็ม */
    .main-content {
        margin-left: 0 !important;
    }

    /* ยกเลิก collapsed state บน tablet/mobile */
    .sidebar-collapsed .sidebar {
        width: var(--sidebar-width) !important;
    }

        .sidebar-collapsed .sidebar .brand-text,
        .sidebar-collapsed .sidebar .user-info,
        .sidebar-collapsed .sidebar .nav-text,
        .sidebar-collapsed .sidebar .nav-badge,
        .sidebar-collapsed .sidebar .collapse-arrow,
        .sidebar-collapsed .sidebar .nav-section-label,
        .sidebar-collapsed .sidebar .sidebar-footer {
            opacity: 1;
            width: auto;
            overflow: visible;
        }

        .sidebar-collapsed .sidebar .collapse-menu {
            display: block !important;
        }

        .sidebar-collapsed .sidebar .nav-link {
            justify-content: flex-start;
            padding: 10px 12px;
        }

        .sidebar-collapsed .sidebar .sidebar-brand {
            justify-content: space-between;
            padding: 20px;
        }

        .sidebar-collapsed .sidebar .sidebar-close-btn {
            display: flex;
        }

        .sidebar-collapsed .sidebar .sidebar-user {
            justify-content: flex-start;
            padding: 16px 20px;
        }

        /* ซ่อน Tooltip บน mobile */
        .sidebar-collapsed .sidebar .nav-link::after,
        .sidebar-collapsed .sidebar .nav-link::before {
            display: none;
        }

    /* Search input ย่อลง */
    .search-input {
        width: 180px;
    }

        .search-input:focus {
            width: 220px;
        }
}

/* ========================================
   Responsive - Mobile
   ======================================== */
@media (max-width: 575.98px) {

    .topbar {
        padding: 0 16px;
    }

    .content-area {
        padding: 16px;
    }

    /* ซ่อน Search บน Mobile เล็ก */
    .topbar-search {
        display: none;
    }

    .notification-dropdown {
        width: calc(100vw - 32px);
    }

    .footer-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .stat-card {
        padding: 16px;
        gap: 14px;
    }

    .stat-value {
        font-size: 22px;
    }

    .stat-icon {
        width: 46px;
        height: 46px;
        min-width: 46px;
        font-size: 20px;
    }
}

/* ========================================
   Nav Link - แก้ปัญหา Bootstrap Override
   ======================================== */

/* ✅ กำหนดสีตายตัวทุก state สำหรับ sidebar (pink theme) */
.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #fbcfe8 !important;
    background-color: transparent !important;
    text-decoration: none !important;
    transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
}

    .sidebar .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1) !important;
        color: #fce7f3 !important;
        transform: translateX(2px);
        text-decoration: none !important;
    }

    .sidebar .nav-link.active {
        background-color: rgba(251, 207, 232, 0.25) !important;
        color: #fce7f3 !important;
        box-shadow: inset 3px 0 0 #fbcfe8;
    }

        .sidebar .nav-link.active .nav-icon {
            color: #fbcfe8 !important;
        }

/* ✅ ขอใช้บริการรถยนต์ — call-to-action button */
.sidebar .nav-link.nav-link-create {
    background-color: #ffffff !important;
    color: #C2185B !important;
    font-weight: 600;
    margin: 2px 0 6px;
    border: 2px solid #C2185B !important;
    border-radius: 8px;
}

    .sidebar .nav-link.nav-link-create:hover {
        background-color: #fce4ec !important;
        color: #880E4F !important;
        border-color: #880E4F !important;
        transform: translateX(2px);
    }

    .sidebar .nav-link.nav-link-create.active {
        background-color: #fce4ec !important;
        color: #880E4F !important;
        border-color: #880E4F !important;
        box-shadow: inset 3px 0 0 #C2185B;
    }

    .sidebar .nav-link.nav-link-create .nav-icon {
        color: #C2185B !important;
    }

[data-theme="dark"] .sidebar .nav-link.nav-link-create {
    background-color: #1e1e2e !important;
    color: #f48fb1 !important;
    border-color: #f48fb1 !important;
}

    [data-theme="dark"] .sidebar .nav-link.nav-link-create:hover {
        background-color: #2d1b2e !important;
        color: #f06292 !important;
        border-color: #f06292 !important;
    }

[data-theme="white"] .sidebar .nav-link.nav-link-create {
    background-color: rgba(255, 255, 255, 0.15) !important;
    color: #ffffff !important;
    border: 2px solid rgba(255, 255, 255, 0.6) !important;
}

    [data-theme="white"] .sidebar .nav-link.nav-link-create:hover {
        background-color: rgba(255, 255, 255, 0.25) !important;
        color: #ffffff !important;
        border-color: #ffffff !important;
    }

    [data-theme="white"] .sidebar .nav-link.nav-link-create.active {
        background-color: rgba(255, 255, 255, 0.25) !important;
        color: #ffffff !important;
        border-color: #ffffff !important;
        box-shadow: inset 3px 0 0 #93c5fd;
    }

    [data-theme="white"] .sidebar .nav-link.nav-link-create .nav-icon {
        color: #ffffff !important;
    }

/* ✅ collapse toggle */
.sidebar .nav-collapse-toggle {
    color: #fbcfe8 !important;
    background-color: transparent !important;
    text-decoration: none !important;
}

    .sidebar .nav-collapse-toggle:hover {
        background-color: rgba(255, 255, 255, 0.1) !important;
        color: #fce7f3 !important;
        text-decoration: none !important;
    }

    .sidebar .nav-collapse-toggle.active {
        background-color: rgba(251, 207, 232, 0.25) !important;
        color: #fce7f3 !important;
    }

/* ✅ focus state */
.sidebar a.nav-link:focus,
.sidebar a.nav-link:focus-visible,
.sidebar a.nav-collapse-toggle:focus,
.sidebar a.nav-collapse-toggle:focus-visible {
    color: #fce7f3 !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
    outline: 2px solid rgba(251, 207, 232, 0.4);
    outline-offset: -2px;
    box-shadow: none !important;
    text-decoration: none !important;
}

/* ✅ sub-nav-link ทุก state */
.sidebar .sub-nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    color: #fbcfe8 !important;
    background-color: transparent !important;
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 400;
    transition: color 0.15s ease, background-color 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
}

    .sidebar .sub-nav-link:hover {
        color: #fce7f3 !important;
        background-color: rgba(255, 255, 255, 0.08) !important;
        text-decoration: none !important;
    }

    .sidebar .sub-nav-link.active {
        color: #fce7f3 !important;
        background-color: rgba(251, 207, 232, 0.2) !important;
        font-weight: 500;
    }

    .sidebar .sub-nav-link:focus,
    .sidebar .sub-nav-link:focus-visible {
        color: #fce7f3 !important;
        outline: 2px solid rgba(251, 207, 232, 0.4);
        outline-offset: -2px;
        text-decoration: none !important;
    }

/* ── nav-icon สี ── */
.sidebar .nav-icon {
    width: 20px;
    min-width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
    color: inherit;
    transition: color 0.15s ease;
}

/* ── nav-text ── */
.sidebar .nav-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
    opacity: 1 !important;
    visibility: visible !important;
}

/* ── collapse-arrow ── */
.sidebar .collapse-arrow {
    font-size: 11px;
    flex-shrink: 0;
    color: #fbcfe8;
    transition: transform 0.3s ease, color 0.15s ease;
}

.sidebar .nav-collapse-toggle[aria-expanded="true"] .collapse-arrow {
    transform: rotate(90deg);
    color: #fbcfe8;
}

.sidebar .nav-collapse-toggle:hover .collapse-arrow {
    color: #fce7f3;
}

[data-theme="dark"] .sidebar .collapse-arrow {
    color: #f8fafc;
}

[data-theme="dark"] .sidebar .nav-collapse-toggle[aria-expanded="true"] .collapse-arrow {
    color: #fbcfe8;
}

[data-theme="dark"] .sidebar .nav-collapse-toggle:hover .collapse-arrow {
    color: #f8fafc;
}

/* ── sub-nav-text ── */
.sidebar .sub-nav-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    color: inherit;
    opacity: 1 !important;
    visibility: visible !important;
    display: inline !important;
}

/* ── sub-dot ── */
.sidebar .sub-dot {
    font-size: 6px;
    flex-shrink: 0;
    min-width: 6px;
    color: #fbcfe8;
    opacity: 0.6;
    transition: opacity 0.15s ease, color 0.15s ease;
}

.sidebar .sub-nav-link:hover .sub-dot {
    opacity: 1;
    color: #fbcfe8;
}

.sidebar .sub-nav-link.active .sub-dot {
    opacity: 1;
    color: #fbcfe8;
}

/* ========================================
   Personnel Module Styles
   ======================================== */

/* ── Profile Header ── */
.profile-header-card {
    background: linear-gradient(135deg, #fbcfe8 0%, #ec4899 100%);
    border-radius: var(--border-radius-lg);
    color: #fff;
    padding: 32px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(251, 207, 232, 0.35);
}

.profile-header-card::before {
    content: '';
    position: absolute;
    top: -60px;
    right: -60px;
    width: 220px;
    height: 220px;
    background: rgba(255,255,255,0.06);
    border-radius: 50%;
}

.profile-header-card::after {
    content: '';
    position: absolute;
    bottom: -40px;
    left: 30%;
    width: 160px;
    height: 160px;
    background: rgba(255,255,255,0.04);
    border-radius: 50%;
}

.profile-avatar-lg {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 4px solid rgba(255,255,255,0.3);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    flex-shrink: 0;
}

/* ── Info Row helper ── */
.info-row {
    display: flex;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    width: 140px;
    min-width: 140px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
}

.info-value {
    flex: 1;
    color: var(--text-primary);
    word-break: break-word;
}

/* ── Personnel Table Avatar ── */
.personnel-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
}

.personnel-initials {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #fbcfe8, #ec4899);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Status Badges ── */
.badge-active    { background: rgba(34, 197, 94, 0.12); color: #16a34a; }
.badge-leave     { background: rgba(245, 158, 11, 0.12); color: #d97706; }
.badge-resigned  { background: rgba(239, 68, 68, 0.12); color: #dc2626; }
.badge-retired   { background: rgba(100, 116, 139, 0.12); color: #475569; }

/* ── Tabs (Personnel Details / Profile Edit) ── */
.nav-tabs {
    border-bottom: 2px solid var(--border-color);
    gap: 4px;
}

.nav-tabs .nav-link {
    border: none !important;
    border-radius: 8px 8px 0 0 !important;
    color: var(--text-secondary) !important;
    font-weight: 500;
    font-size: 14px;
    padding: 10px 18px !important;
    background: transparent !important;
    transition: color 0.2s ease, background 0.2s ease !important;
    box-shadow: none !important;
    transform: none !important;
}

.nav-tabs .nav-link:hover {
    color: var(--primary) !important;
    background: rgba(251, 207, 232, 0.06) !important;
    transform: none !important;
}

.nav-tabs .nav-link.active {
    color: var(--primary) !important;
    background: rgba(251, 207, 232, 0.1) !important;
    border-bottom: 2px solid var(--primary) !important;
    font-weight: 600;
}

/* ── Collection Item Cards (Education, Training, Achievement) ── */
.collection-item {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.collection-item:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(251, 207, 232, 0.1);
}

.collection-item:last-child {
    margin-bottom: 0;
}

.collection-delete-btn {
    position: absolute;
    top: 12px;
    right: 12px;
}

/* ── App Portal Card ── */
.bg-primary-soft {
    background: rgba(251, 207, 232, 0.12);
}

.bg-success-soft {
    background: rgba(34, 197, 94, 0.12);
}

.bg-warning-soft {
    background: rgba(245, 158, 11, 0.12);
}

.bg-danger-soft {
    background: rgba(239, 68, 68, 0.12);
}

.bg-info-soft {
    background: rgba(59, 130, 246, 0.12);
}

.bg-secondary-soft {
    background: rgba(100, 116, 139, 0.12);
}

/* Text color for soft badges */
.text-primary { color: var(--primary) !important; }
.text-success  { color: var(--success) !important; }
.text-warning  { color: var(--warning) !important; }
.text-danger   { color: var(--danger) !important; }
.text-info     { color: var(--info) !important; }

/* ── Dashboard Chart Cards ── */
.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    height: 100%;
}

.chart-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.chart-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* ── Filter Bar (Personnel Index) ── */
.filter-bar {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

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

.empty-state i {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.4;
}

/* ── Profile Edit Banner ── */
.profile-banner {
    background: linear-gradient(135deg, #f9a8d4 0%, #db2777 100%);
    border-radius: var(--border-radius-lg);
    padding: 20px 24px;
    color: #fff;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 20px rgba(251, 207, 232, 0.3);
}

[data-theme="white"] .profile-banner {
    background: linear-gradient(135deg, #2563eb 0%, #1e3a8a 100%);
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.3);
}

[data-theme="dark"] .profile-banner {
    background: linear-gradient(135deg, #9d174d 0%, #be185d 100%);
    box-shadow: 0 4px 20px rgba(157, 23, 77, 0.3);
}

/* utility class สำหรับ card ที่ใช้ inline style เดิม */
.card-header-theme {
    background: linear-gradient(135deg, #f9a8d4 0%, #db2777 100%) !important;
}

[data-theme="white"] .card-header-theme {
    background: linear-gradient(135deg, #2563eb 0%, #1e3a8a 100%) !important;
}

[data-theme="dark"] .card-header-theme {
    background: linear-gradient(135deg, #9d174d 0%, #be185d 100%) !important;
}

.profile-banner img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255,255,255,0.3);
}

/* ── Password Strength Hint ── */
.password-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Alert inside forms ── */
.alert {
    border-radius: var(--border-radius-sm);
    font-size: 13px;
}

/* ── Responsive for Personnel ── */
@media (max-width: 767.98px) {
    .profile-header-card {
        padding: 20px;
    }
    .profile-avatar-lg {
        width: 72px;
        height: 72px;
    }
    .info-label {
        width: 110px;
        min-width: 110px;
    }
    .nav-tabs .nav-link {
        padding: 8px 12px !important;
        font-size: 13px;
    }
}

/* ========================================
   KM Module — Knowledge Card
   ======================================== */

/* Thumbnail wrapper: ความสูงคงที่ ไม่ว่ารูปจะสูงแค่ไหน */
.km-card-thumb {
    height: 160px;
    overflow: hidden;
    flex-shrink: 0;
}

.km-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    transition: transform 0.3s ease;
    display: block;
}

.km-card:hover .km-thumb-img {
    transform: scale(1.04);
}

/* Placeholder (ไม่มีรูป) ใช้ความสูงเดียวกัน */
.km-thumb-placeholder {
    width: 100%;
    height: 100%;
}

/* Card hover lift effect */
.hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.hover-lift:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10) !important;
}

/* KM Q&A content blocks */
.km-question {
    background: #f0f8ff;
    border-left: 3px solid #0d6efd;
}

.km-answer {
    background: #f0fff4;
    border-left: 3px solid #198754;
}

.km-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

/* ========================================
   Theme Overrides — Bootstrap Color Remapping
   ปรับสี card เนื้อหาและ icon ให้เข้ากับธีมหลัก (Pink/Rose)
   ======================================== */

/* ── Bootstrap Primary → Rose/Pink Theme ── */
.bg-primary {
    background-color: #ec4899 !important;
}
.text-primary {
    color: #ec4899 !important;
}
.border-primary {
    border-color: #ec4899 !important;
}
.bg-primary-soft,
.bg-primary-subtle {
    background-color: rgba(219, 39, 119, 0.10) !important;
    color: #db2777 !important;
}

/* ── Bootstrap Info → Muted Pink/Blush Theme ── */
.bg-info {
    background-color: #f9a8d4 !important;
    color: #ffffff !important;
}
.text-info {
    color: #f9a8d4 !important;
}
.border-info {
    border-color: #f9a8d4 !important;
}
.bg-info-subtle {
    background-color: rgba(244, 114, 182, 0.12) !important;
    color: #db2777 !important;
}

/* ── card-header with Bootstrap bg utilities ── */
.card-header.bg-primary {
    background: linear-gradient(135deg, #be185d 0%, #db2777 60%, #ec4899 100%) !important;
    color: #ffffff !important;
    border-bottom: none;
}
.card-header.bg-primary .card-title,
.card-header.bg-primary h3,
.card-header.bg-primary h4,
.card-header.bg-primary h5 {
    color: #ffffff !important;
}

.card-header.bg-info {
    background: linear-gradient(135deg, #ec4899 0%, #f9a8d4 100%) !important;
    color: #ffffff !important;
    border-bottom: none;
}
.card-header.bg-info .card-title,
.card-header.bg-info h3,
.card-header.bg-info h4,
.card-header.bg-info h5 {
    color: #ffffff !important;
}

.card-header.bg-light {
    background-color: var(--bg-primary) !important;
    color: var(--text-primary) !important;
}

.card-header.bg-white {
    background-color: var(--bg-card) !important;
    color: var(--text-primary) !important;
}

/* ── card-header transparent/default (standard) ── */
.card-header:not([class*="bg-"]) {
    background: transparent;
    color: var(--text-primary);
}

/* ── Dark theme overrides for card-header ── */
[data-theme="dark"] .card-header.bg-primary {
    background: linear-gradient(135deg, #831843 0%, #be185d 60%, #db2777 100%) !important;
}
[data-theme="dark"] .card-header.bg-info {
    background: linear-gradient(135deg, #be185d 0%, #ec4899 100%) !important;
}
[data-theme="dark"] .card-header.bg-light {
    background-color: #1e293b !important;
    color: #f8fafc !important;
}
[data-theme="dark"] .card-header.bg-white {
    background-color: #1e293b !important;
    color: #f8fafc !important;
}

/* ── Info-box icons (AdminLTE-style) ── */
.info-box-icon.bg-primary {
    background: linear-gradient(135deg, #be185d, #ec4899) !important;
}
.info-box-icon.bg-info {
    background: linear-gradient(135deg, #ec4899, #f9a8d4) !important;
}
.info-box-icon.bg-success {
    background: linear-gradient(135deg, #16a34a, #22c55e) !important;
}
.info-box-icon.bg-warning {
    background: linear-gradient(135deg, #d97706, #f59e0b) !important;
}
.info-box-icon.bg-danger {
    background: linear-gradient(135deg, #dc2626, #ef4444) !important;
}

/* ── Headings / section titles in cards ── */
.card h5.text-primary,
.card h6.text-primary,
.card h4.text-primary,
.card h3.text-primary {
    color: #ec4899 !important;
}

/* ── border-bottom accent on text-primary headings ── */
.card .text-primary.border-bottom {
    border-color: rgba(219, 39, 119, 0.3) !important;
}

/* ── Buttons inside cards ── */
.card .btn-primary,
.btn-primary {
    background: linear-gradient(135deg, #db2777, #ec4899) !important;
    border-color: #db2777 !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(219, 39, 119, 0.25);
}
.card .btn-primary:hover,
.btn-primary:hover,
.card .btn-primary:focus,
.btn-primary:focus {
    background: linear-gradient(135deg, #be185d, #db2777) !important;
    border-color: #be185d !important;
    box-shadow: 0 4px 14px rgba(219, 39, 119, 0.40) !important;
    transform: translateY(-1px);
    color: #ffffff !important;
}

/* ── Badge primary / info ── */
.badge.bg-primary,
.badge.text-bg-primary {
    background-color: #ec4899 !important;
    color: #ffffff !important;
}
.badge.bg-info,
.badge.text-bg-info {
    background-color: #f9a8d4 !important;
    color: #ffffff !important;
}

/* ── Links inside cards ── */
.card a:not(.btn) {
    color: #ec4899;
}
.card a:not(.btn):hover {
    color: #be185d;
}

/* ── metric-amount color override (Dashboard cards) ── */
.metric-amount {
    color: #ec4899 !important;
}

/* ── card-header-custom (BudgetExpense dashboard) ── */
.card-header-custom {
    background: linear-gradient(135deg, #fce7f3 0%, #fbcfe8 100%) !important;
    border-top-left-radius: var(--border-radius) !important;
    border-top-right-radius: var(--border-radius) !important;
    border-bottom: 1px solid rgba(219, 39, 119, 0.15) !important;
    color: #be185d !important;
    font-weight: 600;
}
[data-theme="dark"] .card-header-custom {
    background: linear-gradient(135deg, #1e293b, #162032) !important;
    border-bottom: 1px solid rgba(219, 39, 119, 0.2) !important;
    color: #fbcfe8 !important;
}

/* ── Danger card-header ── */
.card-header.bg-danger {
    background: linear-gradient(135deg, #b91c1c, #ef4444) !important;
    color: #ffffff !important;
    border-bottom: none;
}

/* ── Success card-header ── */
.card-header.bg-success {
    background: linear-gradient(135deg, #15803d, #22c55e) !important;
    color: #ffffff !important;
    border-bottom: none;
}

/* ── Warning card-header ── */
.card-header.bg-warning {
    background: linear-gradient(135deg, #b45309, #f59e0b) !important;
    color: #1a1a1a !important;
    border-bottom: none;
}

/* ── Dark card-header ── */
.card-header.bg-dark,
.card-header.fw-semibold.bg-dark {
    background: linear-gradient(135deg, #0f172a, #1e293b) !important;
    color: #f8fafc !important;
    border-bottom: none;
}

/* ── Danger opacity card-header ── */
.card-header.bg-danger.bg-opacity-10 {
    background: rgba(239, 68, 68, 0.10) !important;
    color: #dc2626 !important;
}

/* ── Soft card-header variants ── */
.card-header.bg-primary-soft {
    background: rgba(219, 39, 119, 0.10) !important;
    color: #db2777 !important;
}
.card-header.bg-success-soft {
    background: rgba(34, 197, 94, 0.10) !important;
    color: #15803d !important;
}
.card-header.bg-warning-soft {
    background: rgba(245, 158, 11, 0.10) !important;
    color: #b45309 !important;
}
.card-header.bg-info-soft {
    background: rgba(59, 130, 246, 0.10) !important;
    color: #1d4ed8 !important;
}
.card-header.bg-secondary-soft {
    background: rgba(100, 116, 139, 0.10) !important;
    color: #475569 !important;
}
[data-theme="dark"] .card-header.bg-warning-soft {
    background: rgba(245, 158, 11, 0.15) !important;
    color: #fbbf24 !important;
}
[data-theme="dark"] .card-header.bg-info-soft {
    background: rgba(59, 130, 246, 0.15) !important;
    color: #60a5fa !important;
}
[data-theme="dark"] .card-header.bg-secondary-soft {
    background: rgba(100, 116, 139, 0.15) !important;
    color: #94a3b8 !important;
}

/* ── Icon colors in card content (fas/far) ── */
.card .fas,
.card .far,
.card .fab,
.card .bi {
    /* Inherit color by default; specific overrides below */
}

/* fa icons that use text-primary ─ already handled by .text-primary override above */

/* ── KM Q&A blocks theme update ── */
.km-question {
    background: rgba(219, 39, 119, 0.06) !important;
    border-left: 3px solid #ec4899 !important;
}

/* ── Scrollspy / nav-tabs active link ── */
.nav-tabs .nav-link.active {
    color: #ec4899 !important;
    border-bottom-color: #ec4899 !important;
}
.nav-pills .nav-link.active {
    background-color: #ec4899 !important;
}

/* ── List-group active: force white text for readability ── */
.list-group-item.active,
.list-group-item.active:hover,
.list-group-item.active:focus {
    color: #fff !important;
}
.list-group-item.active i,
.list-group-item.active span {
    color: #fff !important;
}

/* ── Progress bar primary ── */
.progress-bar.bg-primary {
    background: linear-gradient(90deg, #db2777, #ec4899) !important;
}
.progress-bar.bg-info {
    background: linear-gradient(90deg, #ec4899, #f9a8d4) !important;
}

/* ── Dark opacity card-header ── */
.card-header.bg-dark.bg-opacity-10,
.card-header.fw-semibold.bg-dark.bg-opacity-10 {
    background: rgba(15, 23, 42, 0.10) !important;
    color: var(--text-primary) !important;
}

/* ── bg-transparent card-header (standard border only) ── */
.card-header.bg-transparent {
    background: transparent !important;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

/* ── Ensure text-white stays white in colored card-headers ── */
.card-header.bg-primary.text-white *,
.card-header.bg-info.text-white *,
.card-header.bg-danger.text-white *,
.card-header.bg-success.text-white * {
    color: #ffffff !important;
}

/* ── btn-info override ── */
.btn-info {
    background: linear-gradient(135deg, #ec4899, #f9a8d4) !important;
    border-color: #ec4899 !important;
    color: #ffffff !important;
}
.btn-info:hover, .btn-info:focus {
    background: linear-gradient(135deg, #db2777, #ec4899) !important;
    border-color: #db2777 !important;
    color: #ffffff !important;
}

/* ── stat-card icon wrapper (ถ้ามีใช้ bg-primary/info) ── */
.stat-card .icon-wrapper.bg-primary,
.stat-card .icon-wrapper.bg-info {
    background: linear-gradient(135deg, #ec4899, #f9a8d4) !important;
    color: #ffffff !important;
}

/* ========================================
   Fix: metric-amount inside colored cards
   .metric-amount.text-white must stay white
   ======================================== */
.metric-amount.text-white,
.card.text-white .metric-amount,
.card.bg-primary .metric-amount,
.card.bg-success .metric-amount,
.card.bg-warning .metric-amount,
.card.bg-danger .metric-amount,
.card.bg-info .metric-amount,
.card.bg-dark .metric-amount {
    color: #ffffff !important;
}

/* metric-unit ใน colored cards */
.card.text-white .metric-unit,
.card.bg-primary .metric-unit,
.card.bg-success .metric-unit,
.card.bg-warning .metric-unit,
.card.bg-danger .metric-unit,
.card.bg-info .metric-unit {
    color: rgba(255, 255, 255, 0.85) !important;
}

/* metric-icon ใน colored cards */
.card.text-white .metric-icon,
.card.bg-primary .metric-icon,
.card.bg-success .metric-icon,
.card.bg-warning .metric-icon,
.card.bg-danger .metric-icon,
.card.bg-info .metric-icon {
    color: rgba(255, 255, 255, 0.4) !important;
}

/* text-uppercase label ใน colored cards */
.card.text-white .text-uppercase,
.card.bg-primary .text-uppercase,
.card.bg-success .text-uppercase,
.card.bg-warning .text-uppercase,
.card.bg-info .text-uppercase {
    color: rgba(255, 255, 255, 0.9) !important;
}

/* ========================================
   Modal Stacking Fix
   ======================================== */
/* เมื่อ modal เปิด ให้ topbar และ sidebar อยู่ด้านหลัง backdrop */
body.modal-open .topbar {
    z-index: 1030;
}
body.modal-open .sidebar {
    z-index: 1030;
}
body.modal-open .sidebar-overlay {
    z-index: 0;
}
