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

body {
    font-family: 'Sarabun', 'Tahoma', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    padding: 20px 10px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: #fff;
    border-radius: 12px;
    padding: 10px 30px 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

.page-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 3px solid #667eea;
    position: relative;
}

.header-controls {
    position: absolute;
    top: 122px;
    right: 0;
    display: flex;
    gap: 10px;
    align-items: center;
}

.header-tabs {
    position: absolute;
    top: 122px;
    left: 0;
    display: flex;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #c5cae9;
}
.header-tabs .tab {
    padding: 8px 22px;
    text-decoration: none;
    color: #555;
    font-weight: 600;
    transition: all 0.2s;
    border-right: 1px solid #c5cae9;
    font-size: 14px;
}
.header-tabs .tab:last-child { border-right: none; }
.header-tabs .tab:hover { background: #f0f3ff; }
.header-tabs .tab.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.header-controls .year-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    background: transparent;
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
}
.header-controls .year-selector label {
    font-weight: 700;
    color: #4a3f8f;
    margin: 0;
    font-size: 14px;
    white-space: nowrap;
}
.header-controls .year-selector select {
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-family: inherit;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    min-width: 70px;
}
.header-controls .year-selector select:focus {
    outline: none;
    border-color: #667eea;
}

.header-manage-btn {
    background: linear-gradient(135deg, #3b82f6, #2563eb) !important;
    color: white !important;
    font-size: 14px !important;
    padding: 10px 22px !important;
    text-decoration: none !important;
    border-radius: 999px !important;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.4) !important;
    font-weight: 600 !important;
    border: none !important;
}
.header-manage-btn:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.55) !important;
    background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
}

.page-header h1 {
    color: #4a3f8f;
    font-size: 16pt;
    margin-bottom: 8px;
}

.page-header h2.term-title {
    display: inline-block;
    color: white;
    background-color: #28a745;
    font-size: 12pt;
    margin-top: 8px;
    padding: 6px 22px;
    border-radius: 999px;
    box-shadow: 0 2px 4px rgba(40, 167, 69, 0.3);
}

.page-header .subtitle, .page-header .date-range {
    color: #666;
    font-size: 12pt;
    margin-top: 5px;
}

.page-header .school-full-name {
    color: #555;
    font-size: 12pt;
    margin: 6px 0 4px;
    font-weight: 500;
}

.page-header .days-summary {
    color: #4a3f8f;
    font-size: 11pt;
    margin-top: 8px;
    font-weight: 500;
}
.page-header .days-summary strong {
    display: inline-block;
    color: white;
    background-color: #dc3545;
    font-size: 10pt;
    padding: 1px 10px;
    border-radius: 999px;
    margin: 0 2px;
    box-shadow: 0 1px 3px rgba(220, 53, 69, 0.3);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 18px;
    background: #e0e0e0;
    color: #333;
    text-decoration: none;
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    margin: 4px 2px;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
.btn-primary { background: #667eea; color: white; }
.btn-warn { background: #f39c12; color: white; }
.btn-danger { background: #e74c3c; color: white; }
.btn-back { background: #95a5a6; color: white; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ปุ่มเพิ่มวันหยุด - แคปซูลสีฟ้า */
.btn-add-event {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    font-weight: 600;
    padding: 10px 24px;
    border-radius: 999px;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.4);
    font-size: 15px;
}
.btn-add-event:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.55);
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
    align-items: center;
}

/* Selector Bar (term tabs only) */
.selector-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    background: transparent;
    border-radius: 0;
    margin-bottom: 18px;
    border-left: none;
}

.btn-print {
    background: white;
    color: #555;
    padding: 8px 18px;
    border: 2px solid #c5cae9;
    border-radius: 999px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.2s;
}
.btn-print:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.legend-hint {
    margin-left: auto;
    color: #4a3f8f;
    font-size: 13px;
    font-style: italic;
    background: #fff8e1;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px dashed #f1c40f;
}
.year-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}
.year-selector label {
    font-weight: 700;
    color: #4a3f8f;
    margin: 0;
}
.year-selector select {
    padding: 8px 14px;
    border: 2px solid #c5cae9;
    border-radius: 6px;
    background: white;
    font-family: inherit;
    font-size: 15px;
    color: #333;
    cursor: pointer;
    min-width: 220px;
}
.year-selector select:focus {
    outline: none;
    border-color: #667eea;
}

.term-tabs {
    display: flex;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #c5cae9;
}
.term-tabs .tab {
    padding: 8px 22px;
    text-decoration: none;
    color: #555;
    font-weight: 600;
    transition: all 0.2s;
    border-right: 1px solid #c5cae9;
}
.term-tabs .tab:last-child { border-right: none; }
.term-tabs .tab:hover { background: #f0f3ff; }
.term-tabs .tab.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

/* Year Cards */
.year-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
}

.year-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf3 100%);
    border-radius: 10px;
    padding: 20px;
    border-left: 5px solid #667eea;
    transition: all 0.3s;
}
.year-card:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(0,0,0,0.1); }

.year-card-header h2 { color: #4a3f8f; margin-bottom: 4px; }
.school-name { color: #777; font-size: 14px; }

.year-card-body { margin: 15px 0; }
.term-info {
    padding: 8px 0;
    border-bottom: 1px dashed #ccc;
    font-size: 14px;
}
.term-info strong { color: #4a3f8f; display: block; }

.year-card-footer { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }

.empty-state {
    grid-column: 1/-1;
    text-align: center;
    padding: 40px;
    color: #999;
    background: #f9f9f9;
    border-radius: 10px;
}

/* Form */
.form-card {
    background: #f9fafc;
    padding: 30px;
    border-radius: 10px;
    margin-top: 20px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #4a3f8f;
}
.form-group input, .form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    transition: border 0.2s;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: #667eea;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }

fieldset {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}
fieldset legend {
    padding: 0 10px;
    font-weight: 700;
    color: #667eea;
}

.form-actions { display: flex; gap: 10px; margin-top: 20px; }

.alert {
    padding: 12px 18px;
    border-radius: 6px;
    margin-bottom: 15px;
}
.alert-error { background: #fee; color: #c33; border-left: 4px solid #c33; }

/* Calendar */
.calendar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 12px 18px;
    background: #f5f7fa;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.dot { width: 16px; height: 16px; border-radius: 4px; display: inline-block; }
.dot-school { background: #fff; border: 1px solid #ccc; }
.dot-weekend { background: #3b82f6; }
.dot-holiday { background: #dc3545; }
.dot-makeup { background: #ffd93d; }

.calendars-grid {
    display: flex;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 25px;
    max-width: 100%;
    margin-left: 0;
    margin-right: auto;
}

/* แต่ละแถวของเดือน — ปฏิทินซ้าย + ตารางกิจกรรมขวา */
.month-row {
    display: flex;
    gap: 14px;
    align-items: stretch;
}
.month-row .month-box {
    flex: 0 0 420px;
    max-width: 420px;
}
.month-row .month-events {
    flex: 1;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.events-table {
    width: 100%;
    height: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.events-table th {
    background: #28a745;
    color: white;
    padding: 8px 10px;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    border: 1px solid #1e7d22;
}
.events-table td {
    padding: 8px 12px;
    border: 1px solid #e0e0e0;
    vertical-align: top;
    width: 50%;
}
.events-table td.clickable-event {
    cursor: pointer;
    transition: background 0.15s;
}
.events-table td.clickable-event:hover {
    background: #fffbe6;
}
.events-table td strong {
    color: #28a745;
    margin-right: 4px;
}
.events-table td strong.event-date-badge {
    display: inline-block;
    color: white;
    background-color: #dc3545;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    margin-right: 6px;
    box-shadow: 0 1px 3px rgba(220, 53, 69, 0.3);
}
.event-prefix-holiday {
    color: #dc3545;
    font-weight: 600;
}
.event-prefix-makeup {
    color: #d39e00;
    font-weight: 600;
}
.event-prefix-regular {
    color: #4a3f8f;
    font-weight: 600;
}

/* ตอนพิมพ์ - ปรับให้ดูดี */
@media (max-width: 1100px) {
    .month-row { flex-direction: column; }
    .month-row .month-box { flex: 1; max-width: 100%; }
}

.month-box {
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    overflow: hidden;
}
.month-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    padding: 10px;
    text-align: center;
    font-weight: 700;
    font-size: 16px;
}

.month-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
.month-table th, .month-table td {
    padding: 8px 4px;
    text-align: center;
    border: 1px solid #eee;
    width: 12%;
    height: 36px;
}
.month-table th {
    background: #28a745;
    color: white;
    font-size: 13px;
}
.month-table th.sat, .month-table th.sun {
    background: #28a745;
    color: white;
}
.month-table td.sat, .month-table td.sun {
    color: white;
    background: #3b82f6;
}
.month-table td.holiday {
    background: #dc3545;
    color: white;
    font-weight: 700;
}
.month-table td.makeup {
    background: #ffd93d;
    color: #333;
    font-weight: 700;
}
.month-table td.regular-override {
    background: #fff;
    color: #333;
}
.month-table td.school { background: #fff; }
.month-table td.empty, .month-table td.out-range { background: #f8f8f8; color: #ccc; }

/* ช่องวันที่ที่คลิกเพิ่ม event ได้ */
.month-table td.clickable-day {
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
}
.month-table td.clickable-day:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
    z-index: 2;
    outline: 2px solid #667eea;
}
.month-table td.cum-col {
    background: #e2efda;
    color: #4a3f8f;
    font-weight: 700;
    font-size: 12px;
    width: 14%;
}
.month-table th.cum {
    background: #28a745;
    color: white;
    font-weight: 700;
    font-size: 12px;
    width: 14%;
}
.month-table td.week-col {
    background: #fff8e1;
    color: #b8860b;
    font-weight: 700;
    font-size: 12px;
    width: 66px;
    border-right: 2px solid #f1c40f;
    white-space: nowrap;
}
.month-table th.week-col {
    background: #28a745;
    color: white;
    font-weight: 700;
    font-size: 10px;
    width: 66px;
    border-right: 2px solid #f1c40f;
    white-space: nowrap;
}

.month-summary {
    padding: 8px 12px;
    background: #f5f7fa;
    font-size: 13px;
    text-align: center;
    color: #555;
    border-top: 1px solid #eee;
}
.month-summary strong {
    display: inline-block;
    color: white;
    background-color: #dc3545;
    padding: 1px 10px;
    border-radius: 999px;
    margin: 0 3px;
    box-shadow: 0 1px 3px rgba(220, 53, 69, 0.3);
}

/* Event List */
.event-list {
    margin-top: 30px;
    background: #f9fafc;
    padding: 20px;
    border-radius: 10px;
}
.event-list h3 { color: #4a3f8f; margin-bottom: 15px; }
.event-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 6px;
    overflow: hidden;
}
.event-table th, .event-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}
.event-table th {
    background: #667eea;
    color: white;
}
.event-table tr:hover { background: #f5f7fa; }
.event-list .empty { text-align: center; color: #999; padding: 20px; }

.grand-summary {
    margin-top: 20px;
    padding: 18px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    text-align: center;
    border-radius: 8px;
    font-size: 18px;
}
.grand-summary strong { font-size: 24px; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal.show { display: flex; }
.modal-content {
    background: white;
    padding: 25px;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #eee;
}
.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: #999;
}

/* Print */
@media print {
    body { background: white; padding: 0; }
    .container { box-shadow: none; padding: 10px; }
    .action-bar, .selector-bar, .no-print, .modal { display: none !important; }
    .calendars-grid { 
        display: flex;
        flex-direction: column;
        gap: 8px;
        max-width: 350px;
        margin-left: 0;
        margin-right: auto;
    }
    .month-table { font-size: 12px; }
}

/* ===== Login Page ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-box {
    background: white;
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    max-width: 400px;
    width: 100%;
}
.login-header {
    text-align: center;
    margin-bottom: 25px;
}
.login-header h1 {
    color: #4a3f8f;
    font-size: 24px;
    margin-bottom: 5px;
}
.login-header p {
    color: #888;
    font-size: 16px;
}
.login-form .form-group {
    margin-bottom: 18px;
}
.login-form input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
}
.login-form input:focus {
    outline: none;
    border-color: #667eea;
}
.login-btn {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    background: linear-gradient(135deg, #667eea, #764ba2);
}
.login-hint {
    margin-top: 25px;
    padding: 12px;
    background: #fff8e1;
    border-radius: 6px;
    font-size: 13px;
    color: #856404;
    border: 1px dashed #f1c40f;
}
.login-hint code {
    background: #fff;
    padding: 1px 6px;
    border-radius: 3px;
    color: #c0392b;
}

/* ===== Header user info (ปุ่ม ออกจากระบบ) ===== */
.user-info {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #dc3545;
    font-size: 14px;
    background: #fff5f5;
    padding: 6px 16px 6px 8px;
    border-radius: 999px;
    border: 1px solid #f5c2c7;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
    cursor: pointer;
}
.user-info .power-icon {
    background: linear-gradient(135deg, #dc3545 0%, #b02a37 100%);
    color: white;
    border-radius: 50%;
    padding: 5px;
    width: 26px;
    height: 26px;
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.4), inset 0 -2px 4px rgba(0,0,0,0.15), inset 0 2px 3px rgba(255,255,255,0.3);
    transition: all 0.2s;
    flex-shrink: 0;
}
.user-info:hover {
    background: #dc3545;
    color: white;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.4);
    transform: translateY(-1px);
}
.user-info:hover .power-icon {
    background: white;
    color: #dc3545;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2), inset 0 -2px 4px rgba(0,0,0,0.1), inset 0 2px 3px rgba(255,255,255,0.5);
}

.header-users-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706) !important;
    color: white !important;
    font-size: 14px !important;
    padding: 10px 18px !important;
    text-decoration: none !important;
    border-radius: 999px !important;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4) !important;
    font-weight: 600 !important;
    border: none !important;
}
.header-users-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.55) !important;
}

/* Role Badge */
.role-badge {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.role-admin {
    background: #dc3545;
    color: white;
}
.role-user {
    background: #6c757d;
    color: white;
}

.header-login-btn {
    background: linear-gradient(135deg, #667eea, #764ba2) !important;
    color: white !important;
    font-size: 14px !important;
    padding: 10px 20px !important;
    text-decoration: none !important;
    border-radius: 999px !important;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4) !important;
    font-weight: 600 !important;
    border: none !important;
}
.header-login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.55) !important;
}

/* ผู้ดูแลระบบ + logout มุมขวาบนสุด */
.header-user-corner {
    position: absolute;
    top: 10px;
    right: 0;
}

/* ปีการศึกษา มุมซ้ายบน (เหนือ tab ภาคเรียน) */
.year-selector-corner {
    position: absolute;
    top: 80px;
    left: 0;
    display: flex;
    align-items: center;
}
.year-selector-corner .year-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}
.year-selector-corner .year-selector label {
    font-weight: 600;
    color: #4a3f8f;
    font-size: 14px;
}
.year-selector-corner .year-selector select {
    padding: 4px 10px;
    border: 1px solid #c5cae9;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    background: white;
    width: 160px;
    min-width: 160px;
}
