:root {
    /* ปรับธีมให้เข้ากับโลโก้ (น้ำเงิน/เหลือง) */
    --brand-bg: #0b1b3a;
    --brand-primary: #1e3a8a;
    --brand-accent: #f59e0b;
    --text-on-brand: #ffffff;
    --sidebar-width: 280px;
    --surface: #ffffff;
    --muted: #6b7280;
    --border: #e5e7eb;
    --page: #f6f7fb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--page);
    margin: 0;
    color: #0f172a;
}

.app {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
    transition: grid-template-columns 0.3s ease;
}

.app.sidebar-collapsed {
    grid-template-columns: 80px 1fr;
}

/* Sidebar Styles */
.sidebar {
    background: linear-gradient(135deg, var(--brand-bg) 0%, #0d2a59 50%, #1e3a8a 100%);
    color: var(--text-on-brand);
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 0px;
    position: sticky;
    top: 0;
    height: 100vh;
    box-shadow: var(--shadow-lg);
    overflow-y: auto;
    transition: all 0.3s ease;
}

.sidebar.collapsed {
    padding: 24px 12px;
}

.sidebar.collapsed .nav-title,
.sidebar.collapsed .nav a span,
.sidebar.collapsed .department-name,
.sidebar.collapsed .user-info {
    display: none;
}

.sidebar.collapsed .brand img {
    width: 40px;
    max-height: 40px;
}


.brand img {
    width: 200px;
    height: auto;
    max-height: 80px;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
    background: #fff;
    padding: 3px 6px;
    box-shadow: 0 2px 8px rgba(30, 58, 138, 0.10);
    object-fit: contain;
}

@media (max-width: 767px) {
    .brand {
        font-size: 18px;
        padding: 10px 4px;
        min-height: 48px;
    }

    .brand img {
        width: 80px;
        max-height: 36px;
        padding: 2px 4px;
    }
}

.brand:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    transition: all 0.3s ease;
}

.nav-section {
    margin-top: 8px;
}

.nav-title {
    font-size: 11px;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .6);
    margin: 16px 12px 8px;
    font-weight: 600;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #e5e7eb;
    text-decoration: none;
    padding: 14px 16px;
    border-radius: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.nav a:hover {
    background: rgba(255, 255, 255, .12);
    color: #fff;
    transform: translateX(4px);
    border-color: rgba(255, 255, 255, 0.2);
}

.nav a.active {
    background: linear-gradient(135deg, var(--brand-accent), #fbbf24);
    color: #111827;
    font-weight: 600;
    box-shadow: var(--shadow);
}

.nav a.active:hover {
    transform: translateX(4px) scale(1.02);
}

.profile {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, .2);
    padding: 12px 8px 8px 8px;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.profile .name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile .role {
    opacity: .7;
    margin-bottom: 8px;
    font-size: 11px;
}

.profile a {
    color: #fbbf24;
    text-decoration: none;
    font-weight: 600;
    padding: 6px 12px;
    background: rgba(251, 191, 36, 0.1);
    border-radius: 6px;
    display: inline-block;
    transition: all 0.3s ease;
    font-size: 12px;
    width: 100%;
    text-align: center;
}

.profile a:hover {
    background: #ff0000;
    color: #fff;
    transform: translateY(-1px);
}

.profile p {
    margin: 6px 0 0 0;
    font-size: 10px;
    opacity: 0.6;
    text-align: center;
}

/* Content Styles */
.content {
    padding: 32px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 32px;
    padding: 24px;
    background: var(--surface);
    border-radius: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.header h2 {
    margin: 0;
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header .badge {
    background: linear-gradient(135deg, var(--brand-accent), #fbbf24);
    color: #111827;
    font-weight: 800;
    border-radius: 999px;
    padding: 8px 16px;
    font-size: 12px;
    box-shadow: var(--shadow);
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.welcome-card,
.stat-card {
    background: var(--surface);
    border-radius: 20px;
    padding: 28px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.welcome-card::before,
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--brand-primary), var(--brand-accent));
}

.welcome-card:hover,
.stat-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}

.welcome-card h3,
.stat-card h3 {
    margin: 0 0 16px;
    font-size: 20px;
    font-weight: 700;
    color: var(--brand-primary);
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    color: var(--brand-accent);
    margin-bottom: 8px;
}

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

/* Mobile Menu Toggle */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: var(--brand-primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
}

/* Logout Popup Styles */
.logout-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease;
}

.logout-popup-content {
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.logout-popup-header {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    padding: 24px 24px 20px 24px;
    text-align: center;
}

.logout-popup-header h3 {
    margin: 0;
    color: #fff;
    font-size: 20px;
    font-weight: 600;
}

.logout-popup-body {
    padding: 24px;
    text-align: center;
}

.logout-popup-body p {
    margin: 0;
    color: #374151;
    font-size: 16px;
    line-height: 1.5;
}

.logout-popup-footer {
    padding: 0 24px 24px 24px;
    display: flex;
    gap: 12px;
    justify-content: center;
}

.logout-popup-footer button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 100px;
}

.btn-cancel {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-cancel:hover {
    background: #e5e7eb;
    transform: translateY(-1px);
}

.btn-confirm {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-confirm:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

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

/* Responsive Design */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 240px;
    }

    .content {
        padding: 24px;
    }

    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
}

@media (max-width: 767px) {
    .app {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        z-index: 999;
        width: 280px;
        transition: left 0.3s ease;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    }

    .sidebar.open {
        left: 0;
    }

    .mobile-toggle {
        display: block;
        background: linear-gradient(135deg, var(--brand-primary), var(--brand-accent));
        color: white;
        border: none;
        padding: 12px 16px;
        border-radius: 8px;
        font-size: 20px;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
        transition: all 0.3s ease;
    }

    .mobile-toggle:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .mobile-toggle:active {
        transform: translateY(0);
    }

    /* Backdrop overlay when sidebar is open */
    body.sidebar-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
        animation: fadeIn 0.3s ease;
    }

    @keyframes fadeIn {
        from {
            opacity: 0;
        }

        to {
            opacity: 1;
        }
    }

    .content {
        padding: 20px;
        margin-top: 70px;
    }

    .header {
        flex-direction: column;
        text-align: center;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .welcome-card,
    .stat-card {
        padding: 24px;
    }
}

@media (max-width: 480px) {
    .content {
        padding: 16px;
    }

    .header {
        padding: 20px;
    }

    .header h2 {
        font-size: 24px;
    }

    .welcome-card,
    .stat-card {
        padding: 20px;
    }

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

    .logout-popup-content {
        width: 95%;
        margin: 20px;
    }

    .logout-popup-header,
    .logout-popup-body,
    .logout-popup-footer {
        padding: 20px;
    }

    .logout-popup-footer {
        flex-direction: column;
    }

    .logout-popup-footer button {
        width: 100%;
    }
}

/* ===== WELCOME SECTION ===== */
.welcome-section {
    margin-bottom: 2rem;
}

.welcome-card {
    background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
    border-radius: 16px;
    padding: 2rem;
    color: white;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.welcome-icon {
    font-size: 3rem;
    opacity: 0.9;
}

.welcome-content h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.5rem;
    font-weight: 700;
}

.welcome-content p {
    margin: 0 0 1rem 0;
    opacity: 0.9;
    font-size: 1rem;
}

.welcome-features {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

.feature-icon {
    font-size: 1.2rem;
}

.feature-text {
    font-size: 0.9rem;
    font-weight: 500;
}

/* ===== SYSTEM STATUS SECTION ===== */
.system-status-section {
    margin-bottom: 2rem;
}

.system-status-section h3 {
    margin: 0 0 1rem 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--brand-primary);
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.status-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.status-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.status-icon {
    font-size: 2rem;
    opacity: 0.8;
}

.status-content h4 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--brand-primary);
}

.status-content p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--muted);
}

/* ===== QUICK ACTIONS SECTION ===== */
.quick-actions-section {
    margin-bottom: 2rem;
}

.quick-actions-section h3 {
    margin: 0 0 1rem 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--brand-primary);
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.action-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.action-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    text-decoration: none;
    color: inherit;
}

.action-icon {
    font-size: 2rem;
    opacity: 0.8;
}

.action-content h4 {
    margin: 0 0 0.25rem 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--brand-primary);
}

.action-content p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--muted);
}

/* ===== ANNOUNCEMENT SECTION ===== */
.announcement-section {
    margin-bottom: 2rem;
}

.announcement-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.announcement-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.announcement-icon {
    font-size: 1.5rem;
}

.announcement-header h2 {
    margin: 0;
    font-weight: 600;
    color: var(--brand-primary);
}

.announcement-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.announcement-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--page);
    border-radius: 8px;
    border-left: 4px solid var(--brand-accent);
}

.announcement-date {
    font-size: 1rem;
    font-weight: 600;
    color: var(--brand-accent);
    min-width: 80px;
    text-align: center;
    padding: 0.25rem 0.5rem;
    background: rgba(245, 158, 11, 0.1);
    border-radius: 4px;
    height: fit-content;
}

.announcement-text {
    flex: 1;
    font-size: 1.25rem;
    line-height: 1.5;
}

.announcement-text strong {
    color: var(--brand-primary);
    font-weight: 600;
}

/* ===== RESPONSIVE DESIGN FOR NEW SECTIONS ===== */
@media (max-width: 768px) {
    .welcome-card {
        flex-direction: column;
        text-align: center;
        padding: 1.5rem;
    }

    .welcome-features {
        justify-content: center;
    }

    .status-grid,
    .actions-grid {
        grid-template-columns: 1fr;
    }

    .announcement-item {
        flex-direction: column;
        gap: 0.5rem;
    }

    .announcement-date {
        min-width: auto;
        text-align: left;
    }
}