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

:root {
    --primary: #0e9f6e;        /* เขียว eHR */
    --primary-light: #16b981;
    --primary-dark: #087f5b;
    --accent: #e8a020;         /* ส้ม (ปุ่มแก้ไข) */
    --accent-light: #f5c04a;
    --success: #0ca678;
    --danger: #e03131;
    --warning: #f08c00;
    --info: #1098ad;
    --gray-50: #f6f9f8;
    --gray-100: #eef2f1;
    --gray-200: #dde5e2;
    --gray-300: #b9c6c1;
    --gray-500: #6b7b76;
    --gray-700: #374640;
    --gray-900: #16211d;
    --white: #ffffff;
    --sidebar-w: 260px;
    --header-h: 64px;
    --radius: 12px;
    --shadow: 0 2px 12px rgba(14,159,110,0.08);
    --shadow-lg: 0 8px 32px rgba(14,159,110,0.14);
    --font: 'Sarabun', 'TH Sarabun PSK', 'TH Sarabun New', sans-serif;
}

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

html { font-size: 16px; }

body {
    font-family: var(--font);
    font-size: 15px;
    background: #eef4f1;
    color: var(--gray-900);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* ========== SIDEBAR ========== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--white);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform .3s ease;
    box-shadow: 1px 0 0 var(--gray-200), 4px 0 22px rgba(14,159,110,0.06);
}

.sidebar-brand {
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--gray-100);
    text-align: center;
}

.sidebar-brand .school-icon {
    width: 52px; height: 52px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 10px;
    font-size: 26px;
    box-shadow: 0 4px 12px rgba(14,159,110,0.30);
}

.sidebar-brand h2 {
    color: var(--primary-dark);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0.3px;
}

.sidebar-brand p {
    color: var(--gray-500);
    font-size: 11.5px;
    margin-top: 2px;
}

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

.nav-section-label {
    color: var(--gray-300);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    padding: 12px 20px 4px;
    margin-top: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 18px;
    margin: 1px 10px;
    border-radius: 10px;
    color: var(--gray-700);
    text-decoration: none;
    font-size: 14.5px;
    font-weight: 500;
    transition: all .18s;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--gray-50);
    color: var(--primary-dark);
}

.nav-item.active {
    background: linear-gradient(135deg, rgba(14,159,110,0.12), rgba(22,185,129,0.10));
    color: var(--primary-dark);
    font-weight: 700;
}

.nav-item.active .nav-icon { color: var(--primary); }

.nav-item .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
    flex-shrink: 0;
}

/* ========== HEADER ========== */
.main-area {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    height: var(--header-h);
    background: var(--white);
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky; top: 0; z-index: 90;
    box-shadow: 0 1px 0 var(--gray-100);
}

.header-left {
    display: flex; align-items: center; gap: 14px;
}

.page-title {
    font-size: 18.5px;
    font-weight: 800;
    color: var(--primary-dark);
    letter-spacing: 0.2px;
}

.breadcrumb {
    font-size: 12.5px;
    color: var(--gray-500);
    margin-top: 1px;
}

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

.user-badge {
    display: flex; align-items: center; gap: 10px;
    background: #f4faf8;
    border: 1px solid #e3ede9;
    border-radius: 50px;
    padding: 5px 16px 5px 6px;
    cursor: pointer;
    transition: background .15s;
}
.user-badge:hover { background: #eaf5f1; }

.user-avatar {
    width: 32px; height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--white);
    font-size: 13px;
    font-weight: 700;
}

.user-info { font-size: 13px; }
.user-name { font-weight: 600; color: var(--gray-900); }
.user-role { font-size: 11px; color: var(--gray-500); }

/* ========== CONTENT ========== */
.content {
    padding: 26px 30px;
    flex: 1;
}

/* ========== CARDS ========== */
.card {
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(16,40,34,.04), 0 2px 10px rgba(16,40,34,.03);
    border: 1px solid #eef3f1;
    overflow: hidden;
}

.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--gray-100);
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap;
    background: var(--white);
}

.card-header h3 {
    font-size: 16.5px;
    font-weight: 800;
    color: var(--primary-dark);
    display: flex; align-items: center; gap: 9px;
}
.card-header h3 i { color: var(--primary); }

.card-body { padding: 24px; }

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

.stat-card {
    background: var(--white);
    border-radius: 16px;
    padding: 20px 22px;
    box-shadow: 0 1px 2px rgba(16,40,34,.04), 0 2px 10px rgba(16,40,34,.03);
    border: 1px solid #eef3f1;
    display: flex; align-items: center; gap: 15px;
    transition: transform .18s, box-shadow .18s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(14,159,110,.10);
}

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

.stat-icon.blue { background: #d1f0e6; color: var(--primary); }
.stat-icon.green { background: #d1fae5; color: var(--success); }
.stat-icon.amber { background: #fef3c7; color: var(--warning); }
.stat-icon.red { background: #fee2e2; color: var(--danger); }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }

.stat-value {
    font-size: 30px;
    font-weight: 800;
    color: var(--gray-900);
    line-height: 1;
}

.stat-label {
    font-size: 13px;
    color: var(--gray-500);
    margin-top: 3px;
    font-weight: 500;
}

/* ========== FORMS ========== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 18px;
}

.form-group { margin-bottom: 0; }

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

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

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: 10px;
    font-family: var(--font);
    font-size: 14.5px;
    color: var(--gray-900);
    background: #f8fbfa;
    transition: border-color .15s, box-shadow .15s, background .15s;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3.5px rgba(14,159,110,0.13);
}

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

.form-section {
    background: #f8fbfa;
    border: 1px solid #e8efec;
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
}

.form-section-title {
    font-size: 14.5px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
    display: flex; align-items: center; gap: 8px;
}

/* ========== TABLES ========== */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table thead th {
    background: #f1f7f4;
    color: var(--gray-700);
    padding: 13px 16px;
    font-weight: 700;
    font-size: 13.5px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1.5px solid var(--gray-200);
}

.data-table tbody tr {
    border-bottom: 1px solid var(--gray-100);
    transition: background .15s;
}

.data-table tbody tr:hover { background: #f4faf8; }

.data-table td {
    padding: 13px 16px;
    color: var(--gray-700);
    vertical-align: middle;
    font-size: 14px;
}

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

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 20px;
    border-radius: 10px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all .2s;
    white-space: nowrap;
    line-height: 1.3;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
    box-shadow: 0 3px 10px rgba(14,159,110,0.28);
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 5px 16px rgba(14,159,110,0.38); }

.btn-accent {
    background: var(--accent);
    color: var(--white);
}
.btn-accent:hover { background: var(--accent-light); }

.btn-success {
    background: var(--success);
    color: var(--white);
}
.btn-success:hover { opacity: .88; }

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

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

.btn-sm {
    padding: 5px 12px;
    font-size: 12.5px;
    border-radius: 6px;
}

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ========== BADGES / STATUS ========== */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 11px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
}
.badge-success { background: #d8f5e6; color: #0b7a4f; }
.badge-success::before { content:''; width:7px; height:7px; border-radius:50%; background:#12b886; display:inline-block; }
.badge-danger { background: #ffe3e3; color: #c92a2a; }
.badge-warning { background: #fff3bf; color: #b07400; }
.badge-info { background: #d3f0ee; color: #0b7285; }
.badge-gray { background: var(--gray-100); color: var(--gray-500); }
.badge-secondary { background: var(--gray-100); color: var(--gray-500); }

/* ========== ALERTS ========== */
.alert {
    padding: 13px 18px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    font-size: 14px;
    display: flex; align-items: flex-start; gap: 10px;
    border-left: 4px solid;
}
.alert-success { background: #f0fdf4; border-color: var(--success); color: #14532d; }
.alert-danger { background: #fef2f2; border-color: var(--danger); color: #7f1d1d; }
.alert-warning { background: #fffbeb; border-color: var(--warning); color: #78350f; }
.alert-info { background: #eff6ff; border-color: var(--info); color: #1e3a8a; }

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

.search-input-wrap {
    position: relative; flex: 1; min-width: 220px;
}

.search-input-wrap .search-icon {
    position: absolute; left: 12px; top: 50%;
    transform: translateY(-50%);
    color: var(--gray-300); font-size: 15px;
}

.search-input-wrap input {
    padding-left: 36px;
}

/* ========== PAGINATION ========== */
.pagination {
    display: flex; gap: 4px; align-items: center;
    justify-content: center; margin-top: 20px; flex-wrap: wrap;
}

.page-btn {
    min-width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 8px;
    border: 1.5px solid var(--gray-200);
    background: var(--white);
    color: var(--gray-700);
    font-family: var(--font);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all .2s;
    padding: 0 10px;
}

.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: var(--white); }
.page-btn.disabled { opacity: .45; cursor: default; }

/* ========== TABS ========== */
.tabs {
    display: flex; gap: 0;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 24px;
    overflow-x: auto;
}

.tab-btn {
    padding: 10px 20px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-500);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
    transition: all .2s;
    text-decoration: none;
    display: flex; align-items: center; gap: 7px;
}

.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ========== MODAL ========== */
.modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(8,45,34,0.55);
    z-index: 200;
    align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.show { display: flex; }

.modal {
    background: var(--white);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    max-width: 600px; width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn .25s ease;
}

@keyframes modalIn {
    from { transform: scale(.95) translateY(-10px); opacity: 0; }
    to   { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--gray-100);
    display: flex; align-items: center; justify-content: space-between;
}

.modal-header h3 {
    font-size: 16px; font-weight: 700; color: var(--primary);
}

.modal-close {
    width: 30px; height: 30px;
    border-radius: 7px;
    background: var(--gray-100);
    border: none; cursor: pointer;
    font-size: 16px; color: var(--gray-700);
    display: flex; align-items: center; justify-content: center;
    transition: background .2s;
}
.modal-close:hover { background: var(--gray-200); }

.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-100);
    display: flex; gap: 10px; justify-content: flex-end;
}

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

.login-page::before {
    content: '';
    position: absolute; inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-box {
    background: var(--white);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(10,25,50,0.4);
    width: 420px;
    max-width: 100%;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.login-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    padding: 32px 32px 28px;
    text-align: center;
}

.login-logo {
    width: 68px; height: 68px;
    background: var(--accent);
    border-radius: 18px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 14px;
    font-size: 32px;
    box-shadow: 0 6px 20px rgba(232,160,32,0.4);
}

.login-header h1 {
    color: var(--white);
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0.3px;
}

.login-header p {
    color: rgba(255,255,255,0.65);
    font-size: 13px;
    margin-top: 4px;
}

.login-body { padding: 32px; }

/* ========== PRINT STYLES ========== */
@media print {
    .sidebar, .header, .btn, .no-print { display: none !important; }
    .main-area { margin-left: 0 !important; }
    body { background: white; font-size: 14pt; }
    .card { box-shadow: none; border: 1px solid #ccc; }
    .content { padding: 0; }
}

/* ========== REPORT / CERTIFICATE ========== */
.report-page {
    width: 210mm; min-height: 297mm;
    margin: 0 auto;
    background: white;
    padding: 20mm;
    font-family: var(--font);
    font-size: 14pt;
}

.report-header {
    text-align: center;
    border-bottom: 3px double var(--primary);
    padding-bottom: 14px;
    margin-bottom: 18px;
}

.report-title {
    font-size: 18pt;
    font-weight: 800;
    color: var(--primary);
}

.report-subtitle { font-size: 14pt; font-weight: 600; margin-top: 4px; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-area { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .content { padding: 16px; }
    .form-grid { grid-template-columns: 1fr; }
}

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