/* ============================
   EMS Nasan - Professional Medical Theme
   สีน้ำเงินขาว สไตล์สถานพยาบาล
   ============================ */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #1565C0;
    --primary-dark: #0D47A1;
    --primary-light: #42A5F5;
    --primary-bg: #E3F2FD;
    --secondary: #0288D1;
    --accent: #FF6F00;
    --white: #FFFFFF;
    --gray-50: #FAFAFA;
    --gray-100: #F5F5F5;
    --gray-200: #EEEEEE;
    --gray-300: #E0E0E0;
    --gray-400: #BDBDBD;
    --gray-500: #9E9E9E;
    --gray-600: #757575;
    --gray-700: #616161;
    --gray-800: #424242;
    --gray-900: #212121;
    --success: #2E7D32;
    --warning: #F57F17;
    --danger: #C62828;
    --info: #0277BD;
    --red-severity: #D32F2F;
    --orange-severity: #F57C00;
    --yellow-severity: #FBC02D;
    --green-severity: #388E3C;
    --white-severity: #78909C;
    --sidebar-width: 260px;
    --header-height: 64px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --radius: 8px;
    --radius-lg: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', 'TH Sarabun New', sans-serif;
    font-size: 16px;
    background: var(--gray-100);
    color: var(--gray-800);
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ====== LOGIN PAGE ====== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary-light) 100%);
    position: relative;
    overflow: hidden;
}

.login-wrapper::before {
    content: '';
    position: absolute;
    width: 600px; height: 600px;
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
    top: -200px; right: -100px;
}

.login-wrapper::after {
    content: '';
    position: absolute;
    width: 400px; height: 400px;
    background: rgba(255,255,255,0.03);
    border-radius: 50%;
    bottom: -150px; left: -100px;
}

.login-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 440px;
    position: relative;
    z-index: 1;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .ems-icon {
    width: 80px; height: 80px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    box-shadow: 0 4px 15px rgba(21,101,192,0.3);
}

.login-logo .ems-icon svg {
    width: 44px; height: 44px;
    fill: var(--white);
}

.login-logo h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--primary-dark);
    line-height: 1.4;
}

.login-logo p {
    font-size: 14px;
    color: var(--gray-500);
    margin-top: 4px;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--primary-dark) 0%, #0a3d7a 100%);
    color: var(--white);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header .logo-circle {
    width: 56px; height: 56px;
    background: rgba(255,255,255,0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
}

.sidebar-header .logo-circle svg {
    width: 32px; height: 32px;
    fill: var(--white);
}

.sidebar-header h2 {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
}

.sidebar-header small {
    font-size: 11px;
    opacity: 0.7;
}

.sidebar-nav {
    padding: 12px 0;
}

.sidebar-nav .nav-section {
    padding: 8px 20px 4px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.5;
    font-weight: 600;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    color: rgba(255,255,255,0.8);
    font-size: 15px;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: rgba(255,255,255,0.1);
    color: var(--white);
}

.sidebar-nav a.active {
    background: rgba(255,255,255,0.15);
    color: var(--white);
    border-left-color: var(--white);
    font-weight: 600;
}

.sidebar-nav a svg {
    width: 20px; height: 20px;
    fill: currentColor;
    flex-shrink: 0;
}

/* Main Content */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.top-header {
    height: var(--header-height);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.top-header .page-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-800);
}

.top-header .header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--primary-bg);
    border-radius: 20px;
    font-size: 14px;
    color: var(--primary-dark);
    font-weight: 500;
}

.user-badge svg {
    width: 18px; height: 18px;
    fill: var(--primary);
}

.btn-logout {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    background: var(--danger);
    color: var(--white);
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-logout:hover { background: #b71c1c; }
.btn-logout svg { width: 16px; height: 16px; fill: currentColor; }

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

/* ====== CARDS ====== */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--gray-800);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header h3 svg {
    width: 22px; height: 22px;
    fill: var(--primary);
}

.card-body { padding: 20px; }
.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
}

/* ====== BUTTONS ====== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn svg { width: 18px; height: 18px; fill: currentColor; }

.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); color: var(--white); }

.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover { background: #1b5e20; color: var(--white); }

.btn-warning { background: var(--warning); color: var(--white); }
.btn-warning:hover { background: #e65100; color: var(--white); }

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

.btn-info { background: var(--info); color: var(--white); }
.btn-info:hover { background: #01579b; color: var(--white); }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--primary);
    color: var(--primary);
}
.btn-outline:hover { background: var(--primary); color: var(--white); }

.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-sm svg { width: 15px; height: 15px; }

.btn-lg { padding: 12px 28px; font-size: 17px; }

/* ====== FORMS ====== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group label .required {
    color: var(--danger);
    margin-left: 2px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-300);
    border-radius: 6px;
    font-family: inherit;
    font-size: 15px;
    color: var(--gray-800);
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--white);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(21,101,192,0.1);
}

.form-control::placeholder { color: var(--gray-400); }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23757575' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

textarea.form-control {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.form-row-3 { grid-template-columns: repeat(3, 1fr); }
.form-row-4 { grid-template-columns: repeat(4, 1fr); }
.form-row-6 { grid-template-columns: repeat(6, 1fr); }

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

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

.table th, .table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--gray-200);
    font-size: 14px;
}

.table th {
    background: var(--primary-bg);
    color: var(--primary-dark);
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.table tbody tr:hover {
    background: #f0f7ff;
}

.table .actions {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

/* ====== STATS CARDS ====== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 16px;
    border-left: 4px solid var(--primary);
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.info { border-left-color: var(--info); }

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

.stat-icon.blue { background: var(--primary-bg); }
.stat-icon.blue svg { fill: var(--primary); }
.stat-icon.green { background: #E8F5E9; }
.stat-icon.green svg { fill: var(--success); }
.stat-icon.orange { background: #FFF3E0; }
.stat-icon.orange svg { fill: var(--warning); }
.stat-icon.red { background: #FFEBEE; }
.stat-icon.red svg { fill: var(--danger); }

.stat-icon svg { width: 28px; height: 28px; }

.stat-info h4 {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-800);
    line-height: 1;
}

.stat-info p {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 4px;
}

/* ====== SEVERITY BADGES ====== */
.severity-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.severity-red { background: #FFEBEE; color: var(--red-severity); }
.severity-orange { background: #FFF3E0; color: var(--orange-severity); }
.severity-yellow { background: #FFFDE7; color: #F57F17; }
.severity-green { background: #E8F5E9; color: var(--green-severity); }
.severity-white { background: var(--gray-200); color: var(--gray-600); }

/* ====== ALERTS ====== */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-success { background: #E8F5E9; color: var(--success); border: 1px solid #C8E6C9; }
.alert-danger { background: #FFEBEE; color: var(--danger); border: 1px solid #FFCDD2; }
.alert-warning { background: #FFF3E0; color: #E65100; border: 1px solid #FFE0B2; }
.alert-info { background: var(--primary-bg); color: var(--info); border: 1px solid #BBDEFB; }

/* ====== SEARCH BAR ====== */
.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.search-bar .form-control {
    max-width: 300px;
}

/* ====== PAGINATION ====== */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    padding: 16px 0;
}

.pagination a, .pagination span {
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 14px;
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
    transition: all 0.2s;
}

.pagination a:hover { background: var(--primary-bg); color: var(--primary); border-color: var(--primary); }
.pagination .active { background: var(--primary); color: var(--white); border-color: var(--primary); }

/* ====== DASHBOARD CHARTS ====== */
.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

/* ====== EMPTY STATE ====== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--gray-500);
}

.empty-state svg {
    width: 64px; height: 64px;
    fill: var(--gray-300);
    margin-bottom: 16px;
}

.empty-state h4 { font-size: 18px; color: var(--gray-600); }
.empty-state p { font-size: 14px; margin-top: 8px; }

/* ====== MODAL ====== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    padding: 24px;
}

.modal-box h3 {
    font-size: 18px;
    margin-bottom: 12px;
}

.modal-box .modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ====== RESPONSIVE ====== */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.menu-toggle svg {
    width: 28px; height: 28px;
    fill: var(--gray-700);
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .menu-toggle {
        display: block;
    }
    .form-row-3, .form-row-4, .form-row-6 {
        grid-template-columns: 1fr;
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ====== PRINT ====== */
@media print {
    @page {
        size: A4 portrait;
        margin: 10mm 12mm;
    }

    *, *::before, *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        font-size: 11px !important;
        line-height: 1.35 !important;
        background: #fff !important;
        color: #000 !important;
    }

    .sidebar, .top-header, .btn, .btn-logout, .search-bar, .pagination,
    .no-print, .d-flex.gap-2.mb-2 { display: none !important; }

    .app-wrapper { display: block !important; }
    .main-content { margin-left: 0 !important; }
    .content-area { padding: 0 !important; }

    .print-header { display: block !important; }

    .card {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        margin-bottom: 4px !important;
        page-break-inside: avoid;
    }

    .card-header {
        padding: 5px 10px !important;
        background: #E3F2FD !important;
    }

    .card-header h3 {
        font-size: 12px !important;
    }

    .card-header h3 svg { display: none !important; }

    .card-body {
        padding: 6px 10px !important;
        font-size: 11px !important;
    }

    .card-body strong { font-size: 11px !important; }

    .form-row, .form-row-3 {
        gap: 4px !important;
    }

    .table th, .table td {
        padding: 3px 6px !important;
        font-size: 10px !important;
    }

    .severity-badge {
        font-size: 10px !important;
        padding: 1px 6px !important;
        border: 1px solid #999 !important;
    }

    .mb-2 { margin-bottom: 4px !important; }

    .print-footer-info {
        display: block !important;
        font-size: 9px;
        color: #666;
        border-top: 1px solid #ccc;
        padding-top: 4px;
        margin-top: 4px;
    }
}

/* ====== UTILITIES ====== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--gray-500); }
.fw-bold { font-weight: 700; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.d-flex { display: flex; }
.gap-2 { gap: 16px; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.w-100 { width: 100%; }
