/* Calendar Section - Premium Design */
.calendar-section {
    background: white;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    margin-bottom: 30px;
    border: 1px solid rgba(0,0,0,0.06);
    animation: fadeInUp 0.6s ease-out 0.5s both;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Calendar Header */
.calendar-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 30px 35px;
    color: white;
    position: relative;
    overflow: hidden;
}

.btn-header-action {
    padding: 12px 24px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    font-family: 'Kanit', sans-serif;
    transition: all 0.3s;
    color: white;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.btn-header-action:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

.calendar-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -5%;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: pulse 4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

.calendar-header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 1;
}

.room-info {
    flex: 1;
}

.room-info h2 {
    font-size: 26px;
    margin-bottom: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}

.room-info p {
    font-size: 15px;
    opacity: 0.95;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.room-info-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    backdrop-filter: blur(10px);
}

/* Table Wrapper - ไม่มี scroll */
.table-wrapper {
    overflow-x: visible;
    padding: 0;
    width: 100%;
}

/* Calendar Table - ปรับให้พอดีหน้าจอ */
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
    font-size: 11px;
}

/* Table Header - แถวที่ 1: หมายเลขคาบ (1, 2, 3...) */
thead tr:first-child th {
    background: linear-gradient(135deg, #2d3748, #1a202c);
    color: white;
    font-weight: 700;
    padding: 14px 4px !important;
    text-align: center;
    font-size: 13px !important;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    letter-spacing: 0.3px;
    width: auto !important;
    min-width: 60px !important;
    max-width: 80px !important;
    vertical-align: middle;
    line-height: 1.3;
    height: 55px;
}

/* คอลัมน์แรกของแถวที่ 1 (วัน/เวลา) */
thead tr:first-child th:first-child {
    background: linear-gradient(135deg, #1a202c, #0d1117);
    width: 90px !important;
    min-width: 90px !important;
    max-width: 90px !important;
    font-size: 12px !important;
    position: relative;
    height: 55px;
}

/* ไม่มีเส้นขวาสุดของแถว */
thead tr:first-child th:last-child {
    border-right: none;
}

/* Table Header - แถวที่ 2: ช่วงเวลา */
thead tr:nth-child(2) {
    height: 65px;
}

/* คอลัมน์เวลาด้านซ้าย */
thead tr:nth-child(2) th.time-column {
    background: linear-gradient(135deg, #f7fafc, #edf2f7);
    font-weight: 700;
    color: #2d3748;
    padding: 12px 4px !important;
    border-right: 2px solid #cbd5e0;
    border-bottom: 2px solid #cbd5e0;
    text-align: center;
    width: 90px !important;
    min-width: 90px !important;
    max-width: 90px !important;
    font-size: 10px !important;
    line-height: 1.3;
    vertical-align: middle;
    height: 65px;
}

/* ช่วงเวลาแต่ละช่อง */
thead tr:nth-child(2) td {
    background: linear-gradient(135deg, #ffffff, #f7fafc);
    font-size: 10px !important;
    color: #2d3748;
    padding: 10px 2px !important;
    text-align: center;
    border-right: 1px solid #e2e8f0;
    border-bottom: 2px solid #cbd5e0;
    font-weight: 600;
    line-height: 1.3;
    vertical-align: middle;
    width: auto !important;
    min-width: 60px !important;
    max-width: 80px !important;
    white-space: nowrap;
    height: 65px;
}

thead tr:nth-child(2) td:last-child {
    border-right: none;
}

/* Table Body */
tbody .time-column {
    background: linear-gradient(135deg, #f7fafc, #edf2f7);
    font-weight: 700;
    color: #2d3748;
    width: 90px !important;
    min-width: 90px !important;
    max-width: 90px !important;
    text-align: center;
    padding: 20px 4px !important;
    border-right: 2px solid #cbd5e0;
    border-bottom: 1px solid #e2e8f0;
    font-size: 11px !important;
    position: sticky;
    left: 0;
    z-index: 10;
    box-shadow: 2px 0 4px rgba(0,0,0,0.05);
    vertical-align: middle;
    height: 80px;
}

tbody td {
    padding: 20px 4px !important;
    text-align: center;
    border-right: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    font-size: 10px !important;
    transition: all 0.3s;
    position: relative;
    min-height: 80px;
    height: 80px;
    width: auto;
    min-width: 60px;
    max-width: 80px;
    vertical-align: middle;
}

tbody td:last-child {
    border-right: none;
}

/* ✅ ช่องว่าง - เปิดให้กดได้ */
.slot-available {
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    cursor: pointer !important;
    color: #2e7d32;
    font-weight: 700;
    font-size: 11px;
    position: relative;
    overflow: hidden;
    user-select: none;
}

.schedule-cell {
    position: relative;
    cursor: pointer !important;
}

.schedule-cell.selecting {
    background: linear-gradient(135deg, #bbdefb, #90caf9) !important;
    border: 2px solid #2196f3 !important;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.5);
}

.schedule-cell.highlighted {
    position: relative;
    z-index: 5;
}

.highlight-label {
    position: absolute;
    top: 4px;
    left: 4px;
    right: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 10;
}

.highlight-delete-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 11;
    transition: all 0.2s;
}

.schedule-cell.highlighted:hover .highlight-delete-btn {
    display: flex;
}

.highlight-delete-btn:hover {
    background: #dc2626;
    transform: scale(1.1);
}

.slot-available::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.4), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.slot-available:hover::before {
    opacity: 1;
}

.slot-available:hover {
    background: linear-gradient(135deg, #c8e6c9, #a5d6a7);
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(46, 125, 50, 0.2);
    z-index: 5;
}

/* ✅ ช่องจอง - อนุมัติแล้ว */
.slot-booked {
    background: linear-gradient(135deg, #ffebee, #ffcdd2);
    color: #c62828;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer !important;
    transition: all 0.3s;
    user-select: none;
    padding: 12px 4px !important;
}

.slot-booked:hover {
    background: linear-gradient(135deg, #ffcdd2, #ef9a9a);
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(198, 40, 40, 0.2);
    z-index: 5;
}

/* ✅ ช่องจอง - รออนุมัติ */
.slot-pending {
    background: linear-gradient(135deg, #fff3e0, #ffe0b2);
    color: #e65100;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer !important;
    transition: all 0.3s;
    user-select: none;
    padding: 12px 4px !important;
}

.slot-pending:hover {
    background: linear-gradient(135deg, #ffe0b2, #ffcc80);
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(230, 81, 0, 0.2);
    z-index: 5;
}

/* ✅ ช่องรายวิชา */
.course-cell {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb);
    color: #1565c0;
    cursor: pointer !important;
    font-size: 11px;
    padding: 6px 3px;
    line-height: 1.2;
    vertical-align: middle;
    transition: all 0.3s;
    user-select: none;
}

.course-cell:hover {
    background: linear-gradient(135deg, #bbdefb, #90caf9);
    transform: scale(1.02);
    box-shadow: 0 4px 15px rgba(21, 101, 192, 0.2);
    z-index: 5;
}

/* ✅ แก้ไข: ลบ .course-teacher ซ้ำออก และเพิ่ม !important */
.course-code {
    font-weight: 700;
    font-size: 13px !important;
    margin-bottom: 2px;
    color: #1a237e !important;  /* น้ำเงินเข้มมาก */
}

.course-teacher {
    font-size: 12px !important;
    opacity: 1;                  /* ลบ opacity ออก ทำให้ไม่จาง */
    color: #4527a0 !important;  /* ม่วงเข้ม */
    font-weight: 600;
}

/* 🔴 CSS สำหรับช่องว่างของห้องที่ปิด */
.room-closed-cell {
    background: linear-gradient(135deg, #fef3c7, #fde68a) !important;
    cursor: not-allowed !important;
    opacity: 0.8;
}

.room-closed-cell:hover {
    background: linear-gradient(135deg, #fde68a, #fcd34d) !important;
    opacity: 0.9;
    transform: none !important;
}

.room-closed-cell i {
    color: #92400e;
}

/* CSS สำหรับคอลัมน์วันที่ของห้องปิด */
.room-closed-date {
    background: linear-gradient(135deg, #fef3c7, #fde68a) !important;
    border-left: 4px solid #f59e0b !important;
}

/* CSS สำหรับเซลล์วันหยุด */
.holiday-cell-merged {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%) !important;
    cursor: not-allowed !important;
    color: #991b1b;
    font-weight: 600;
    text-align: center !important;
    vertical-align: middle !important;
    padding: 12px 8px !important;
}

.holiday-cell-merged:hover {
    background: linear-gradient(135deg, #fecaca 0%, #fca5a5 100%) !important;
}

.holiday-content-merged {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.holiday-content-merged i {
    font-size: 16px;
    opacity: 0.8;
}

.holiday-reason-merged {
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    line-height: 1.3;
    color: #991b1b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.holiday-date {
    background: linear-gradient(135deg, #fee2e2, #fecaca) !important;
    color: #991b1b !important;
    font-weight: 700 !important;
}

.time-column[data-holiday="true"] {
    border-left: 4px solid #ef4444 !important;
}

/* Legend */
.legend {
    display: flex;
    gap: 25px;
    padding: 20px 35px;
    background: linear-gradient(135deg, #f7fafc, #edf2f7);
    border-top: 2px solid #e2e8f0;
    font-size: 14px;
    flex-wrap: wrap;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: all 0.3s;
}

.legend-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.legend-box {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

.legend-item span {
    font-weight: 600;
    color: #2d3748;
}

/* Modal Styles */
.course-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.course-modal-content {
    background: white;
    padding: 35px 40px;
    border-radius: 24px;
    width: 90%;
    max-width: 550px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 25px 70px rgba(0,0,0,0.5);
    animation: modalSlideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(30px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.course-modal-content h3 {
    margin: 0 0 15px 0;
    color: #2d3748;
    font-size: 26px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
}

.course-modal-content .form-group {
    margin-bottom: 20px;
}

.course-modal-content label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
    color: #2d3748;
    font-size: 14px;
}

.course-modal-content input,
.course-modal-content select,
.course-modal-content textarea {
    width: 100%;
    padding: 14px 18px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 15px;
    font-family: 'Kanit', sans-serif;
    transition: all 0.3s;
    background: #f7fafc;
}

.course-modal-content input:focus,
.course-modal-content select:focus,
.course-modal-content textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.course-modal-content .form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 25px;
}

.btn-cancel,
.btn-submit,
.btn-edit,
.btn-delete {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    font-size: 15px;
    font-family: 'Kanit', sans-serif;
    transition: all 0.3s;
}

.btn-cancel {
    background: linear-gradient(135deg, #e2e8f0, #cbd5e0);
    color: #2d3748;
}

.btn-cancel:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn-submit {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-submit:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
}

.btn-edit {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-edit:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}

.btn-delete {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-delete:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(239, 68, 68, 0.4);
}

/* Booking Detail Styles */
.booking-detail-row {
    display: flex;
    padding: 14px 16px;
    border-bottom: 1px solid #e2e8f0;
    align-items: center;
    transition: background 0.2s;
}

.booking-detail-row:hover {
    background: #f7fafc;
}

.booking-detail-row:last-child {
    border-bottom: none;
}

.booking-detail-row label {
    width: 180px;
    font-weight: 700;
    color: #4a5568;
    margin: 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.booking-detail-row span {
    flex: 1;
    color: #2d3748;
    font-weight: 500;
}

/* Highlight Toolbar */
.highlight-toolbar {
    position: fixed;
    top: 80px;
    right: -350px;
    width: 320px;
    background: white;
    border-radius: 20px 0 0 20px;
    box-shadow: -5px 0 30px rgba(0,0,0,0.2);
    z-index: 9999;
    transition: right 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.highlight-toolbar.show {
    right: 0;
}

.highlight-toolbar-content {
    padding: 25px;
    position: relative;
}

.toolbar-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #ef4444;
    color: white;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    font-weight: 700;
}

.toolbar-close-btn:hover {
    background: #dc2626;
    transform: rotate(90deg) scale(1.1);
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 10px;
}

.color-circle {
    width: 100%;
    aspect-ratio: 1;
    border: 3px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
}

.color-circle:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.color-circle.selected {
    border-color: #2d3748;
    box-shadow: 0 0 0 2px white, 0 0 0 5px #2d3748;
    transform: scale(1.1);
}

.color-circle.selected::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 18px;
    font-weight: 700;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

/* Responsive */
@media (max-width: 768px) {
    .calendar-header {
        padding: 20px;
    }

    .calendar-header-content {
        flex-direction: column;
        gap: 15px;
    }

    .room-info h2 {
        font-size: 20px;
    }

    .room-info p {
        font-size: 13px;
    }

    .legend {
        padding: 15px 20px;
        gap: 15px;
    }

    .legend-item {
        font-size: 12px;
        padding: 6px 12px;
    }

    .course-modal-content {
        padding: 25px 20px;
    }

    .booking-detail-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .booking-detail-row label {
        width: 100%;
    }

    thead tr:first-child th {
        font-size: 13px;
        padding: 12px 4px;
        width: 90px;
        min-width: 90px;
    }

    thead tr:first-child th:first-child {
        width: 100px;
        min-width: 100px;
        font-size: 12px;
    }

    thead tr:nth-child(2) th.time-column {
        width: 100px;
        min-width: 100px;
        font-size: 11px;
        padding: 8px 4px;
    }

    thead tr:nth-child(2) td {
        font-size: 10px;
        padding: 8px 2px;
        width: 90px;
        min-width: 90px;
    }

    tbody .time-column {
        font-size: 11px;
        padding: 12px 4px;
        width: 100px;
        min-width: 100px;
    }

    tbody td {
        padding: 12px 4px;
        font-size: 11px;
        width: 90px;
        min-width: 90px;
    }
}