:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #f8fafc;
    --dark: #0f172a;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;
    --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --glass-bg: rgba(255, 255, 255, 0.85);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Kanit', sans-serif;
}

body {
    background-color: #f1f5f9;
    color: var(--text-main);
}

/* =========================================
   Login Page
========================================= */
.login-body {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    padding: 1rem;
    width: 100%;
    max-width: 420px;
}

.login-box {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 1.5rem;
    padding: 2.5rem 2rem;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    animation: fadeUp 0.6s ease-out;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-circle {
    width: 64px;
    height: 64px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin: 0 auto 1rem;
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.3);
}

.login-header h2 {
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 0.25rem;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.input-group {
    margin-bottom: 1.25rem;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.input-group input, .input-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    outline: none;
    font-size: 1rem;
    transition: all 0.2s;
    background: white;
}

.input-group input:focus, .input-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn-primary {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.875rem;
    border-radius: 0.75rem;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.error-msg {
    background: #fef2f2;
    color: var(--danger);
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    margin-bottom: 1rem;
    border: 1px solid #fecaca;
    text-align: center;
}

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* =========================================
   Dashboard Area
========================================= */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: white;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 10;
}

.sidebar-brand {
    padding: 1.5rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-menu {
    flex: 1;
    padding: 1.5rem 1rem;
    list-style: none;
}

.nav-item {
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 0.75rem;
    transition: all 0.2s;
    font-weight: 500;
}

.nav-link:hover, .nav-link.active {
    background: #eff6ff;
    color: var(--primary);
}

.user-profile {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
}

.user-name {
    font-weight: 500;
    color: var(--dark);
    margin-bottom: 0.25rem;
}

.user-role {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.btn-logout {
    margin-top: 1rem;
    width: 100%;
    padding: 0.5rem;
    font-size: 0.875rem;
    color: var(--danger);
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: 0.2s;
}

.btn-logout:hover {
    background: var(--danger);
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--dark);
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

/* Table */
.table-responsive {
    overflow-x: auto;
}

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

.styled-table th, .styled-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.styled-table th {
    background: var(--secondary);
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 600;
    white-space: nowrap;
}

.styled-table tbody tr {
    transition: background 0.2s;
}

.styled-table tbody tr:hover {
    background: #f8fafc;
}

/* Pagination */
.pagination-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.page-btn {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-muted);
    min-width: 36px;
    height: 36px;
    padding: 0 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}

.page-btn:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: #eff6ff;
}

.page-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #f8fafc;
}

.page-info {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-right: auto; 
}

/* Badges */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-ปกติ { background: #e2e8f0; color: #475569; }
.badge-ด่วน { background: #fef3c7; color: #b45309; }
.badge-ด่วนมาก { background: #ffedd5; color: #c2410c; }
.badge-ด่วนที่สุด { background: #fee2e2; color: #b91c1c; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.5);
    z-index: 50;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: white;
    width: 100%;
    max-width: 600px;
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
    animation: slideUp 0.3s ease-out;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content::-webkit-scrollbar {
    width: 8px;
}
.modal-content::-webkit-scrollbar-track {
    background: transparent;
}
.modal-content::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 10px;
}

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

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
}

.close-btn:hover { color: var(--danger); }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

/* File Input */
.file-upload-wrapper {
    position: relative;
    width: 100%;
    height: 100px;
    border: 2px dashed var(--border);
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    cursor: pointer;
    transition: 0.2s;
}

.file-upload-wrapper:hover {
    border-color: var(--primary);
    background: #eff6ff;
}

.file-upload-wrapper input[type="file"] {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.file-upload-text {
    text-align: center;
    color: var(--text-muted);
    pointer-events: none;
}

.actions-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    color: var(--text-muted);
}
.actions-btn:hover { color: var(--danger); }
.download-btn { color: var(--primary); text-decoration: none; margin-right: 0.5rem;}
.download-btn:hover { text-decoration: underline; }

/* Animations */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(50px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   Responsive Design (Mobile)
========================================= */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    
    .nav-menu {
        display: flex;
        overflow-x: auto;
        padding: 0.5rem 1rem;
        gap: 0.5rem;
    }
    
    .nav-item {
        margin-bottom: 0;
        white-space: nowrap;
    }
    
    .user-profile {
        padding: 1rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-top: none;
        border-bottom: 1px solid var(--border);
    }
    
    .user-name {
        margin-bottom: 0;
    }
    
    .btn-logout {
        margin-top: 0;
        width: auto;
        padding: 0.35rem 0.75rem;
    }
    
    .main-content {
        margin-left: 0;
        padding: 1rem;
    }
    
    .top-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    
    .top-bar .btn-primary {
        width: 100% !important;
    }
    
    .grid-2 {
        grid-template-columns: 1fr;
    }
    
    .modal-content {
        max-width: 92%;
        padding: 1.5rem;
    }
    
    .modal-header h2 {
        font-size: 1.25rem;
    }
    
    .styled-table th, .styled-table td {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}
