/* ============================================
   ระบบจัดการวันลาข้าราชการครู - Style System
   ============================================ */

/* --- CSS Variables / Theme --- */
:root {
    /* Colors */
    --primary: #1e40af;
    --primary-light: #3b82f6;
    --primary-dark: #1e3a8a;
    --primary-gradient: linear-gradient(135deg, #1e40af 0%, #3b82f6 50%, #6366f1 100%);
    --accent: #6366f1;

    /* Leave Type Colors */
    --color-personal: #f59e0b;
    --color-personal-bg: rgba(245, 158, 11, 0.12);
    --color-personal-border: rgba(245, 158, 11, 0.3);
    --color-sick: #ef4444;
    --color-sick-bg: rgba(239, 68, 68, 0.12);
    --color-sick-border: rgba(239, 68, 68, 0.3);
    --color-other: #8b5cf6;
    --color-other-bg: rgba(139, 92, 246, 0.12);
    --color-other-border: rgba(139, 92, 246, 0.3);
    --color-total: #10b981;
    --color-total-bg: rgba(16, 185, 129, 0.12);

    /* Surface */
    --bg: #f1f5f9;
    --bg-card: #ffffff;
    --bg-header: rgba(255, 255, 255, 0.85);
    --bg-table-header: #f8fafc;
    --bg-table-row-hover: #f1f5f9;
    --bg-table-stripe: #fafbfc;
    --bg-modal-overlay: rgba(15, 23, 42, 0.5);
    --bg-input: #ffffff;

    /* Text */
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* Borders */
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    /* Shadows */
    --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.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 40px -10px rgba(0, 0, 0, 0.12);

    /* Sizing */
    --header-height: 64px;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    /* Transitions */
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme */
[data-theme="dark"] {
    --primary: #60a5fa;
    --primary-light: #93bbfd;
    --primary-dark: #2563eb;
    --primary-gradient: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #4f46e5 100%);

    --color-personal-bg: rgba(245, 158, 11, 0.18);
    --color-personal-border: rgba(245, 158, 11, 0.4);
    --color-sick-bg: rgba(239, 68, 68, 0.18);
    --color-sick-border: rgba(239, 68, 68, 0.4);
    --color-other-bg: rgba(139, 92, 246, 0.18);
    --color-other-border: rgba(139, 92, 246, 0.4);
    --color-total-bg: rgba(16, 185, 129, 0.18);

    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-header: rgba(30, 41, 59, 0.9);
    --bg-table-header: #1a2332;
    --bg-table-row-hover: #263548;
    --bg-table-stripe: #1a2536;
    --bg-modal-overlay: rgba(0, 0, 0, 0.7);
    --bg-input: #0f172a;

    --text: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;

    --border: #334155;
    --border-light: #1e293b;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.4);
}

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

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* --- Header --- */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-header);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
    transition: background var(--transition);
}

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

.hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}

.hamburger:hover {
    background: var(--border-light);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 28px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo h1 {
    font-size: 1.15rem;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

/* --- Navigation --- */
#main-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

.mobile-nav-header {
    display: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--transition);
    white-space: nowrap;
}

.nav-item:hover {
    color: var(--primary);
    background: var(--color-personal-bg);
}

.nav-item.active {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
    font-weight: 600;
}

.nav-item .material-icons-round {
    font-size: 20px;
}

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

/* --- Mobile Navigation Overlay --- */
.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-modal-overlay);
    z-index: 98;
    opacity: 0;
    transition: opacity var(--transition);
}

.nav-overlay.open {
    display: block;
    opacity: 1;
}

/* --- Utilities --- */
.admin-only {
    display: none !important;
}

body.is-admin .admin-only {
    display: block !important;
}

body.is-admin span.admin-only,
body.is-admin a.admin-only,
body.is-admin button.admin-only {
    display: inline-flex !important;
}

body.is-admin td.admin-only,
body.is-admin th.admin-only {
    display: table-cell !important;
}

body.is-admin .admin-only-flex {
    display: flex !important;
}

body.is-admin .admin-only-inline {
    display: inline-flex !important;
}

#auth-toggle.is-admin {
    color: #10b981;
}

/* --- Copy Protection for Non-Admins --- */
body:not(.is-admin) {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}


/* --- Sync & Loaders --- */
.global-loader {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-main);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--primary);
}

.loader-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.sync-indicator {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    z-index: 1000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.sync-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

.spinning {
    animation: spin 1s linear infinite;
}

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

/* --- Main Content --- */
#app-content {
    margin-top: var(--header-height);
    padding: 24px 20px;
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    min-height: calc(100vh - var(--header-height));
}

/* --- Pages --- */
.page {
    display: none;
    animation: fadeIn 0.35s ease;
}

.page.active {
    display: block;
}

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

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* --- Search Box --- */
.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 14px;
    transition: all var(--transition);
    min-width: 220px;
}

.search-box:focus-within {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.search-box .material-icons-round {
    color: var(--text-muted);
    font-size: 20px;
}

.search-box input {
    border: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    width: 100%;
}

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

/* --- Dropdown --- */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--bg-card);
    min-width: 180px;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    z-index: 100;
    flex-direction: column;
    padding: 8px 0;
}

.dropdown-menu.show {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    transition: background var(--transition);
    width: 100%;
}

.dropdown-item:hover {
    background: var(--bg-table-row-hover);
    color: var(--primary);
}

.dropdown-item .material-icons-round {
    font-size: 20px;
}

/* --- Buttons --- */
.btn-primary, .btn-secondary, .btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: var(--shadow-sm);
}

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

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

.btn-secondary:hover {
    background: var(--bg-table-row-hover);
    border-color: var(--text-muted);
}

.btn-danger {
    background: #ef4444;
    color: white;
}

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

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon:hover {
    background: var(--border-light);
    color: var(--primary);
}

.btn-icon-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-icon-sm:hover {
    background: var(--border-light);
}

.btn-edit:hover {
    color: var(--primary-light);
    background: rgba(59, 130, 246, 0.1);
}

.btn-delete:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* --- Table Styles --- */
.table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    border: 1px solid var(--border);
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
}

.table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
    -webkit-overflow-scrolling: touch;
}

.leave-table {
    width: max-content;
    margin: 0 auto;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}

.leave-table th,
.leave-table td {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border-light);
    white-space: nowrap;
}

.leave-table th {
    background: var(--bg-table-header);
    font-weight: 600;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
    z-index: 10;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.header-months th {
    z-index: 12;
}

.header-types th {
    top: 41px;
    z-index: 11;
}

.month-header {
    background: var(--primary-gradient) !important;
    color: white !important;
    font-size: 0.85rem !important;
    letter-spacing: 0 !important;
}

/* Leave type column colors */
.type-col.type-personal,
th.type-personal { color: var(--color-personal); padding: 6px 4px !important; min-width: 35px; }
.type-col.type-sick,
th.type-sick { color: var(--color-sick); padding: 6px 4px !important; min-width: 35px; }
.type-col.type-other,
th.type-other { color: var(--color-other); padding: 6px 4px !important; min-width: 35px; }
.type-col.type-total,
th.type-total { color: var(--color-total); font-weight: 700; }

/* Sticky columns */
.sticky-left {
    position: sticky;
    z-index: 5;
    background: var(--bg-card);
}

.sticky-left.col-order {
    left: 0;
    min-width: 50px;
    width: 50px;
}

.sticky-left.col-name {
    left: 50px;
    min-width: 160px;
    max-width: 220px;
    text-align: left;
    font-weight: 500;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

thead .sticky-left {
    z-index: 15;
    background: var(--bg-table-header);
}

tfoot .sticky-left {
    z-index: 6;
    background: var(--bg-table-header);
}

.sticky-right {
    position: sticky;
    z-index: 5;
    background: var(--bg-card);
}

thead .sticky-right {
    z-index: 15;
    background: var(--bg-table-header);
}

tfoot .sticky-right {
    z-index: 6;
    background: var(--bg-table-header);
}

/* Summary cells */
.summary-cell {
    font-weight: 700;
    font-size: 0.9rem;
}

.summary-cell.type-personal { background: var(--color-personal-bg) !important; color: var(--color-personal); }
.summary-cell.type-sick { background: var(--color-sick-bg) !important; color: var(--color-sick); }
.summary-cell.type-other { background: var(--color-other-bg) !important; color: var(--color-other); }
.summary-cell.type-total { background: var(--color-total-bg) !important; color: var(--color-total); }

/* Leave cells */
.leave-cell {
    cursor: pointer;
    transition: all var(--transition);
    min-width: 35px;
    padding: 6px 4px !important;
    position: relative;
}

.leave-cell:hover {
    background: var(--bg-table-row-hover);
    transform: scale(1.02);
}

.leave-cell.has-data {
    font-weight: 600;
}

.leave-cell.has-data.type-personal { background: var(--color-personal-bg); color: var(--color-personal); }
.leave-cell.has-data.type-sick { background: var(--color-sick-bg); color: var(--color-sick); }
.leave-cell.has-data.type-other { background: var(--color-other-bg); color: var(--color-other); }

/* Table row hover */
.teacher-row:hover td {
    background: var(--bg-table-row-hover);
}

.teacher-row:hover .sticky-left,
.teacher-row:hover .sticky-right {
    background: var(--bg-table-row-hover);
}

.teacher-row:hover .has-data.type-personal { background: rgba(245, 158, 11, 0.2); }
.teacher-row:hover .has-data.type-sick { background: rgba(239, 68, 68, 0.2); }
.teacher-row:hover .has-data.type-other { background: rgba(139, 92, 246, 0.2); }

/* Striped rows */
.teacher-row:nth-child(even) td {
    background: var(--bg-table-stripe);
}
.teacher-row:nth-child(even) .sticky-left,
.teacher-row:nth-child(even) .sticky-right {
    background: var(--bg-table-stripe);
}
.teacher-row:nth-child(even) .has-data.type-personal { background: var(--color-personal-bg); }
.teacher-row:nth-child(even) .has-data.type-sick { background: var(--color-sick-bg); }
.teacher-row:nth-child(even) .has-data.type-other { background: var(--color-other-bg); }

/* Summary row (footer) */
.summary-row {
    background: var(--bg-table-header);
    font-weight: 700;
}

.summary-row td {
    border-top: 2px solid var(--primary);
    position: sticky;
    bottom: 0;
    z-index: 4;
    background: var(--bg-table-header);
}

.summary-header {
    background: var(--color-total-bg) !important;
    color: var(--color-total) !important;
}

/* Tooltip for leave cells */
.leave-cell[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--text-inverse);
    padding: 6px 10px;
    border-radius: var(--radius-xs);
    font-size: 0.75rem;
    font-weight: 400;
    white-space: pre-wrap;
    max-width: 200px;
    z-index: 50;
    box-shadow: var(--shadow-lg);
    pointer-events: none;
}

/* Remarks column */
.remarks-header {
    background: #6366f1 !important;
    color: white !important;
    font-size: 0.85rem !important;
    letter-spacing: 0 !important;
    min-width: 100px;
}

.remarks-cell {
    text-align: left;
    min-width: 100px;
    max-width: 180px;
    white-space: normal;
    word-break: break-word;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background var(--transition);
}

.remarks-cell:hover {
    background: var(--bg-table-row-hover);
}

.remarks-placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

/* Summary column type colors */
.summary-cell.type-times {
    background: var(--color-total-bg) !important;
    color: var(--color-total);
    padding: 4px 2px !important;
    min-width: 35px;
}

.summary-cell.type-days {
    background: var(--color-total-bg) !important;
    color: var(--color-total);
    padding: 4px 2px !important;
    min-width: 35px;
}

.type-col.type-times,
th.type-times { color: var(--color-total); font-weight: 700; padding: 4px 2px !important; min-width: 35px; }
.type-col.type-days,
th.type-days { color: var(--color-total); font-weight: 700; padding: 4px 2px !important; min-width: 35px; }

.sum-col {
    background: var(--bg-table-header) !important;
}

/* File input */
.file-input {
    padding: 10px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
    width: 100%;
}

.file-input:hover {
    border-color: var(--primary-light);
}

/* Import preview */
.import-name-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.import-name-item {
    padding: 4px 8px;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border-light);
}

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

/* --- Dashboard --- */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

.stat-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 16px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.02);
    transition: all var(--transition);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
}

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

.stat-icon .material-icons-round {
    font-size: 26px;
    color: white;
}

.card-total .stat-icon { background: var(--primary-gradient); }
.card-personal .stat-icon { background: linear-gradient(135deg, #f59e0b, #d97706); }
.card-sick .stat-icon { background: linear-gradient(135deg, #ef4444, #dc2626); }
.card-other .stat-icon { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.card-all .stat-icon { background: linear-gradient(135deg, #10b981, #059669); }

.stat-value {
    font-size: 2.2rem;
    font-weight: 500;
    line-height: 1;
    color: var(--text);
    letter-spacing: -0.5px;
    white-space: nowrap;
}

.stat-label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.dashboard-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

.chart-card {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 28px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.02);
}

.chart-card.wide {
    grid-column: span 2;
}

.chart-card h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.chart-wrapper {
    height: 300px;
    position: relative;
}

.chart-wrapper-pie {
    height: 280px;
}

/* --- Calendar --- */
.cal-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cal-month-label {
    font-size: 1.1rem;
    font-weight: 600;
    min-width: 180px;
    text-align: center;
    color: var(--text);
}

.calendar-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    max-width: 1000px;
    margin: 0 auto;
}

.calendar-grid {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.cal-header-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    margin-bottom: 8px;
}

.cal-day-name {
    text-align: center;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-secondary);
    padding: 8px 0;
}

.cal-day-name.weekend {
    color: var(--color-sick);
}

.cal-body {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.cal-cell {
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    min-height: 50px;
    border: 2px solid transparent;
}

.cal-cell:not(.empty):hover {
    background: var(--bg-table-row-hover);
    border-color: var(--border);
}

.cal-cell.selected {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.08);
}

.cal-cell.weekend .cal-date {
    color: var(--color-sick);
}

.cal-cell.empty {
    cursor: default;
}

.cal-cell.today .cal-date {
    background: var(--primary);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cal-cell.today {
    background: rgba(59, 130, 246, 0.06);
}

.cal-date {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text);
}

.cal-dots {
    display: flex;
    gap: 3px;
    margin-top: 2px;
}

.cal-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.cal-dot.type-personal { background: var(--color-personal); }
.cal-dot.type-sick { background: var(--color-sick); }
.cal-dot.type-other { background: var(--color-other); }

.cal-count {
    position: absolute;
    top: 3px;
    right: 3px;
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cal-cell.has-events {
    background: rgba(59, 130, 246, 0.05);
}

/* Calendar Detail Panel */
.calendar-detail {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    max-height: 500px;
    overflow-y: auto;
}

.cal-detail-placeholder,
.cal-detail-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-muted);
    text-align: center;
}

.cal-detail-placeholder .material-icons-round {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.cal-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.cal-detail-header h4 {
    font-size: 1rem;
    font-weight: 600;
}

.badge {
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
}

.cal-detail-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cal-detail-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border-left: 3px solid transparent;
}

.cal-detail-item.type-personal {
    background: var(--color-personal-bg);
    border-left-color: var(--color-personal);
}

.cal-detail-item.type-sick {
    background: var(--color-sick-bg);
    border-left-color: var(--color-sick);
}

.cal-detail-item.type-other {
    background: var(--color-other-bg);
    border-left-color: var(--color-other);
}

.cal-detail-item .material-icons-round {
    font-size: 20px;
}

.cal-detail-item.type-personal .material-icons-round { color: var(--color-personal); }
.cal-detail-item.type-sick .material-icons-round { color: var(--color-sick); }
.cal-detail-item.type-other .material-icons-round { color: var(--color-other); }

.cal-detail-info {
    display: flex;
    flex-direction: column;
}

.cal-detail-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.cal-detail-type {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* --- Teacher Management --- */
.teacher-table {
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.teacher-table th {
    background: var(--bg-table-header);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.teacher-table td {
    padding: 4px 12px;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

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

.teacher-table tr:hover td {
    background: var(--bg-table-row-hover);
}

.order-cell {
    width: 60px;
    text-align: center;
    font-weight: 600;
    color: var(--text-secondary);
}

.name-cell {
    font-weight: 500;
    font-size: 0.95rem;
}

.section-badge {
    display: inline-flex;
    align-items: center;
    background: rgba(99, 102, 241, 0.1);
    color: #4f46e5;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    width: fit-content;
}

.actions-cell {
    width: 100px;
    text-align: center;
    white-space: nowrap;
}

.teacher-count {
    text-align: center;
    padding: 16px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* --- Settings --- */
.settings-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 700px;
}

.settings-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.settings-card h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.settings-card h3 .material-icons-round {
    font-size: 22px;
    color: var(--primary);
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.settings-preview {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px;
    background: rgba(59, 130, 246, 0.06);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(59, 130, 246, 0.15);
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.settings-preview .material-icons-round {
    font-size: 18px;
    color: var(--primary);
    flex-shrink: 0;
    margin-top: 2px;
}

.export-import-btns {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.danger-zone {
    border-color: rgba(239, 68, 68, 0.3);
}

.danger-zone h3 .material-icons-round {
    color: #ef4444;
}

/* --- Forms --- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: all var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-group textarea {
    resize: vertical;
}

.form-static {
    font-weight: 500;
    color: var(--text);
    padding: 6px 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* --- Modals --- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    align-items: center;
    justify-content: center;
    background: var(--bg-modal-overlay);
    padding: 20px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal.open {
    display: flex;
    opacity: 1;
    animation: modalFadeIn 0.25s ease;
}

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

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-xl);
    animation: modalSlideUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-sm {
    max-width: 380px;
}

@keyframes modalSlideUp {
    from { transform: translateY(30px) scale(0.95); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--border-light);
    color: var(--text);
}

.modal-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

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

/* --- Toast --- */
#toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    font-size: 0.9rem;
    font-weight: 500;
    transform: translateX(120%);
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: auto;
    max-width: 350px;
}

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

.toast-success .material-icons-round { color: #10b981; }
.toast-error .material-icons-round { color: #ef4444; }
.toast-warning .material-icons-round { color: #f59e0b; }
.toast-info .material-icons-round { color: #3b82f6; }

/* --- Empty State --- */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}

.empty-state .material-icons-round {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state p {
    font-size: 1rem;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablet (640px - 1024px) */
@media (max-width: 1024px) {
    .dashboard-charts {
        grid-template-columns: 1fr;
    }

    .chart-card.wide {
        grid-column: span 1;
    }

    .calendar-container {
        grid-template-columns: 1fr;
    }

    .nav-item .nav-label {
        font-size: 0.82rem;
    }

    .nav-item {
        padding: 8px 12px;
    }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
    html { font-size: 15px; }

    .hamburger {
        display: flex;
    }

    .logo h1 {
        font-size: 1rem;
    }

    #main-nav {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        background: var(--bg-card);
        flex-direction: column;
        align-items: stretch;
        padding: 24px 16px;
        gap: 4px;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 99;
        box-shadow: var(--shadow-xl);
    }

    #main-nav.open {
        transform: translateX(0);
    }

    .mobile-nav-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        padding-bottom: 20px;
        margin-bottom: 12px;
        border-bottom: 1px solid var(--border);
    }

    .nav-header-info {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .nav-header-info .logo-icon {
        font-size: 32px;
    }

    .nav-header-text h2 {
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--text);
        background: var(--primary-gradient);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        margin-bottom: 2px;
    }

    .nav-header-text p {
        font-size: 0.8rem;
        color: var(--text-secondary);
    }

    .nav-item {
        padding: 14px 16px;
        border-radius: var(--radius-sm);
        font-size: 1rem;
    }

    .nav-item .material-icons-round {
        font-size: 24px;
    }

    #app-content {
        padding: 16px 12px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-actions {
        width: 100%;
    }

    .search-box {
        width: 100%;
        min-width: unset;
    }

    .table-container {
        max-height: calc(100vh - 240px);
    }

    .leave-table th,
    .leave-table td {
        padding: 8px 8px;
        font-size: 0.8rem;
    }

    .sticky-left.col-name {
        min-width: unset;
        max-width: 130px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .leave-cell {
        min-width: 48px;
    }

    .dashboard-cards {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .stat-card {
        padding: 16px 10px;
        gap: 8px;
        flex-direction: column;
        justify-content: center;
        text-align: center;
    }

    .stat-icon {
        width: 40px;
        height: 40px;
    }

    .stat-icon .material-icons-round {
        font-size: 20px;
    }

    .stat-value {
        font-size: 1.15rem;
    }
    
    .stat-label {
        font-size: 0.8rem;
        margin-top: 2px;
    }

    .chart-wrapper {
        height: 250px;
    }

    .cal-cell {
        min-height: 42px;
    }

    .calendar-detail {
        max-height: 300px;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }

    .settings-container {
        max-width: 100%;
    }

    /* Modal as bottom sheet on mobile */
    .modal {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        max-width: 100%;
        border-radius: var(--radius) var(--radius) 0 0;
        max-height: 85vh;
    }

    .modal-header {
        padding: 12px 16px;
    }

    .modal-body {
        padding: 12px 16px;
        gap: 10px;
    }

    .modal-footer {
        padding: 12px 16px;
    }

    @keyframes modalSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    #toast-container {
        right: 12px;
        left: 12px;
        top: 72px;
    }

    .toast {
        max-width: 100%;
    }

    .export-import-btns {
        flex-direction: column;
    }

    .btn-primary, .btn-secondary, .btn-danger {
        padding: 12px 20px;
        justify-content: center;
    }
}

/* Small Mobile (< 480px) */
@media (max-width: 480px) {
    .dashboard-cards {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px 6px;
        gap: 6px;
    }

    .modal-header, .modal-body, .modal-footer {
        padding: 10px 14px;
    }

    .stat-icon {
        width: 34px;
        height: 34px;
    }

    .stat-icon .material-icons-round {
        font-size: 18px;
    }

    .stat-value {
        font-size: 0.95rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .cal-day-name {
        font-size: 0.72rem;
    }

    .cal-date {
        font-size: 0.85rem;
    }

    .cal-cell {
        min-height: 36px;
    }

    .cal-count {
        width: 15px;
        height: 15px;
        font-size: 0.6rem;
    }

    .header-types th {
        font-size: 0.7rem;
    }
}

/* --- Print Styles --- */
@media print {
    #app-header, .nav-overlay, .modal, #toast-container, .page-actions {
        display: none !important;
    }

    #app-content {
        margin-top: 0;
        padding: 0;
    }

    .table-wrapper {
        box-shadow: none;
        border: 1px solid #ccc;
    }

    .leave-table th, .leave-table td {
        border: 1px solid #ccc;
    }

    .sticky-left, .sticky-right {
        position: static;
    }

    /* Print Leave Form Specifics */
    #app-content {
        display: none !important;
    }
    
    body {
        background: #fff !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .print-only {
        display: block !important;
        font-family: 'Sarabun', 'TH Sarabun New', 'Noto Sans Thai', serif;
        font-size: 16pt;
        line-height: 1.5;
        padding: 0 1cm; /* Margins are handled by printer settings */
    }
    
    .print-stats-table {
        border-collapse: collapse;
        width: 100%;
        margin-top: 10px;
        font-size: 14pt;
    }
    
    .print-stats-table th, .print-stats-table td {
        border: 1px solid #000;
        padding: 4px;
        font-weight: normal;
    }
}

.print-only {
    display: none;
}

/* Minimalist About Modal */
.about-overlay {
    display: flex; position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.4); z-index: 9999;
    align-items: center; justify-content: center;
    backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.about-overlay.open { opacity: 1; pointer-events: auto; }

.about-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px; width: max-content; min-width: 220px; max-width: 90vw;
    padding: 24px 32px; text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
    transform: translateY(20px); opacity: 0;
    transition: all 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    position: relative;
}
.about-overlay.open .about-box { transform: translateY(0); opacity: 1; }

.about-logo {
    color: var(--primary); margin: 0 auto 16px; width: 56px; height: 56px; 
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 28px; background: rgba(59, 130, 246, 0.1);
}

.about-title {
    margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--text);
}

.about-version {
    color: var(--text-muted); font-size: 0.8rem; margin-top: 4px; font-weight: 500; font-family: monospace;
}

.about-dev {
    margin-top: 24px; font-size: 0.8rem; color: var(--text-secondary);
}

/* Sleek Rainbow Text Effect */
.premium-gold {
    display: block;
    margin-top: 6px;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(to right, #f43f5e, #f59e0b, #10b981, #3b82f6, #8b5cf6, #f43f5e);
    background-size: 200% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: sleekRainbow 3s linear infinite;
}

@keyframes sleekRainbow {
    to { background-position: 200% center; }
}

.about-close-abs {
    position: absolute; top: 12px; right: 12px;
    background: transparent; border: none; color: var(--text-muted);
    width: 28px; height: 28px; border-radius: 50%;
    font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.about-close-abs:hover { background: var(--bg-table-row-hover); color: var(--text); }
/ *  
 P r e m i u m  
 A b o u t  
 M o d a l  
 * /  
 