/*
 * ตารางสอน / ตารางเรียน (ใช้ร่วมกัน: schedule.php และ admin/schedule.php)
 * - หน้าจอ: แบบทันสมัย มีเอฟเฟค ไฮไลต์วัน/คาบปัจจุบัน กดช่องเพื่อดูชื่อวิชา
 * - พิมพ์: รูปแบบทางการขาวดำตามแบบฟอร์มโรงเรียน
 */

/* Spacing utilities ที่ Bootstrap ไม่มี */
.gap-1\.5 { gap: 0.375rem !important; }
.gap-2\.5 { gap: 0.75rem !important; }
.me-1\.5 { margin-right: 0.375rem !important; }

/* ===== Official School Timetable Layout (Matching School Format) ===== */
.official-timetable-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.15rem 1.35rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 4px 18px rgba(15, 23, 42, 0.04);
}
[data-theme="dark"] .official-timetable-card,
[data-bs-theme="dark"] .official-timetable-card,
body.dark-mode .official-timetable-card {
    background-color: #131f37 !important;
    border-color: #1e293b !important;
}
[data-theme="dark"] .official-title-text,
[data-bs-theme="dark"] .official-title-text,
body.dark-mode .official-title-text {
    color: #f1f5f9 !important;
}
[data-theme="dark"] .timetable-signatures,
[data-bs-theme="dark"] .timetable-signatures,
body.dark-mode .timetable-signatures {
    color: #cbd5e1 !important;
}
[data-theme="dark"] .official-timetable-table thead th,
[data-bs-theme="dark"] .official-timetable-table thead th,
body.dark-mode .official-timetable-table thead th {
    background-color: #1e293b !important;
    color: #f1f5f9 !important;
}
.official-timetable-header {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    margin-bottom: 0.95rem;
    min-height: 55px;
}
.official-logo-box {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}
.official-logo-img {
    width: 52px;
    height: 52px;
    object-fit: contain;
}
.official-title-text {
    font-size: 1.08rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
    line-height: 1.45;
    padding: 0 60px;
    text-align: center;
}
.tt-title-main, .tt-title-name, .tt-title-term, .tt-title-school {
    display: inline;
}
.tt-title-main::after, .tt-title-name::after, .tt-title-term::after {
    content: " ";
}
.official-timetable-table {
    width: 100%;
    min-width: 900px;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.78rem;
    margin-bottom: 0;
}
.official-timetable-table th,
.official-timetable-table td {
    border: 1px solid #475569 !important;
    vertical-align: middle;
    text-align: center;
    padding: 2px 2px;
}
.official-timetable-table thead th {
    background-color: #f8fafc;
    color: #0f172a;
}
.official-timetable-table thead .th-period-num {
    font-weight: 700;
    font-size: 0.88rem;
    height: 27px;
}
.official-timetable-table thead .th-time-val {
    font-weight: 500;
    font-size: 0.69rem;
    color: #1e293b;
    height: 23px;
    white-space: nowrap;
}
.col-day-header {
    width: 72px;
    font-weight: 700;
    font-size: 0.84rem;
}
.schedule-slot-cell {
    height: 58px;
    min-height: 58px;
    vertical-align: middle;
    padding: 3px 2px !important;
}
.slot-title {
    font-weight: 700;
    font-size: 0.82rem;
    line-height: 1.15;
    color: #0f172a;
}
.slot-subtitle {
    font-size: 0.73rem;
    line-height: 1.15;
    color: #1e293b;
    margin-top: 1px;
}
.slot-room {
    font-size: 0.69rem;
    line-height: 1.1;
    color: #475569;
    margin-top: 1px;
}
.timetable-signatures {
    margin-top: 1.75rem;
    font-size: 0.88rem;
    color: #0f172a;
}

/* ===== Modern timetable (หน้าจอเท่านั้น — ตอนพิมพ์ใช้รูปแบบทางการด้านล่าง) ===== */
@media screen {
    .official-timetable-card {
        position: relative;
        overflow: hidden;
        border: 1px solid rgba(99, 102, 241, 0.18);
        background:
            radial-gradient(1200px 220px at 10% -40%, rgba(99, 102, 241, 0.10), transparent 60%),
            radial-gradient(900px 200px at 95% -30%, rgba(14, 165, 233, 0.10), transparent 60%),
            #ffffff;
        box-shadow: 0 10px 30px -12px rgba(30, 58, 138, 0.18), 0 2px 6px rgba(15, 23, 42, 0.04);
        animation: ttCardIn .5s cubic-bezier(.2, .8, .2, 1) both;
    }
    .official-timetable-card::before {
        content: "";
        position: absolute; inset: 0 0 auto 0; height: 3px;
        background: linear-gradient(90deg, #6366f1, #0ea5e9, #22c55e, #f97316, #ec4899, #6366f1);
        background-size: 200% 100%;
        animation: ttShimmer 8s linear infinite;
    }
    .official-title-text {
        background: linear-gradient(90deg, #1e3a8a, #4f46e5 50%, #0369a1);
        -webkit-background-clip: text; background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    .official-logo-img { filter: drop-shadow(0 4px 8px rgba(30, 58, 138, 0.25)); }

    .official-timetable-table {
        border-collapse: separate;
        border-spacing: 4px;
        width: 100%;
        min-width: 900px;
    }
    .official-timetable-card .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        padding-bottom: 6px;
    }
    .official-timetable-card .table-responsive::-webkit-scrollbar {
        height: 6px;
    }
    .official-timetable-card .table-responsive::-webkit-scrollbar-track {
        background: #f1f5f9;
        border-radius: 999px;
    }
    .official-timetable-card .table-responsive::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 999px;
    }
    .official-timetable-card .table-responsive::-webkit-scrollbar-thumb:hover {
        background: #94a3b8;
    }
    @media (min-width: 1400px) {
        .official-timetable-card .table-responsive { overflow-x: visible; }
    }
    @media (max-width: 767.98px) {
        .official-timetable-card {
            padding: 0.85rem 0.65rem;
            border-radius: 12px;
        }
        .official-timetable-header {
            min-height: 44px;
            margin-bottom: 0.75rem;
        }
        .official-title-text {
            font-size: 0.95rem;
            padding: 0 42px;
            line-height: 1.35;
        }
        .official-logo-img {
            width: 40px;
            height: 40px;
        }
        .tt-title-main {
            display: block;
            font-size: 1.05rem;
            font-weight: 800;
            line-height: 1.3;
        }
        .tt-title-name {
            display: block;
            font-size: 0.96rem;
            font-weight: 700;
            line-height: 1.35;
            margin-top: 2px;
        }
        .tt-title-term {
            display: block;
            font-size: 0.82rem;
            font-weight: 600;
            line-height: 1.3;
            margin-top: 2px;
            opacity: 0.9;
        }
        .tt-title-school {
            display: none !important;
        }
        .tt-title-main::after,
        .tt-title-name::after,
        .tt-title-term::after {
            content: "" !important;
        }
    }
    .official-timetable-table th,
    .official-timetable-table td {
        border: none !important;
        border-radius: 10px;
    }
    .official-timetable-table thead .th-period-num {
        background: linear-gradient(135deg, #1e3a8a, #4f46e5) !important;
        color: #fff !important;
        box-shadow: 0 4px 10px -4px rgba(79, 70, 229, 0.6);
    }
    .official-timetable-table thead .th-time-val {
        background: #eef2ff !important;
        color: #3730a3 !important;
        font-variant-numeric: tabular-nums;
        white-space: normal;
        line-height: 1.15;
        padding: 3px 2px;
    }
    .day-header-cell {
        position: relative;
        background: var(--day-bg) !important;
        color: #0f172a !important;
        box-shadow: inset 4px 0 0 var(--day-accent);
    }

    .schedule-slot-cell {
        position: relative;
        background: #f8fafc !important;
        transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
        animation: ttCellIn .45s cubic-bezier(.2, .8, .2, 1) both;
        animation-delay: calc(var(--col, 0) * 35ms + var(--row, 0) * 50ms);
    }
    .schedule-slot-cell.has-slot {
        background: linear-gradient(160deg, #ffffff 0%, var(--day-bg) 100%) !important;
        box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--day-accent) 35%, transparent),
                    inset 0 3px 0 var(--day-accent),
                    0 2px 6px -2px rgba(15, 23, 42, 0.10);
        cursor: pointer;
    }
    .schedule-slot-cell.has-slot:hover,
    .schedule-slot-cell.has-slot:focus-visible {
        transform: translateY(-3px);
        z-index: 2;
        outline: none;
        box-shadow: inset 0 0 0 1px var(--day-accent),
                    inset 0 3px 0 var(--day-accent),
                    0 12px 24px -8px color-mix(in srgb, var(--day-accent) 55%, transparent);
    }
    .schedule-slot-cell.is-activity {
        background: repeating-linear-gradient(135deg, #ffffff 0 8px, #f8fafc 8px 16px) !important;
        box-shadow: inset 0 0 0 1px #e2e8f0;
    }
    .schedule-slot-cell.is-activity .slot-title { color: #64748b; font-weight: 600; }
    .schedule-slot-cell.has-slot .slot-title { color: color-mix(in srgb, var(--day-accent) 45%, #0f172a); }

    /* คาบ/วันปัจจุบัน */
    .official-timetable-table tr.is-today .day-header-cell {
        background: var(--day-accent) !important; color: #fff !important;
    }
    .official-timetable-table th.is-now-col {
        background: linear-gradient(135deg, #f97316, #ec4899) !important;
        color: #fff !important;
    }
    .schedule-slot-cell.is-now {
        outline: 2px solid #f97316;
        outline-offset: 1px;
        animation: ttCellIn .45s both, ttPulse 2s ease-in-out .6s infinite;
    }
    .schedule-slot-cell.is-now::after {
        content: "ตอนนี้";
        position: absolute; top: -7px; right: 4px;
        font-size: .58rem; font-weight: 700; line-height: 1;
        padding: 2px 6px; border-radius: 999px;
        background: linear-gradient(135deg, #f97316, #ec4899); color: #fff;
    }

    @keyframes ttCardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
    @keyframes ttCellIn { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }
    @keyframes ttShimmer { to { background-position: -200% 0; } }
    @keyframes ttPulse {
        0%, 100% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.45); }
        50% { box-shadow: 0 0 0 6px rgba(249, 115, 22, 0); }
    }

    [data-theme="dark"] .official-timetable-card,
    [data-bs-theme="dark"] .official-timetable-card,
    body.dark-mode .official-timetable-card {
        background:
            radial-gradient(1200px 220px at 10% -40%, rgba(99, 102, 241, 0.18), transparent 60%),
            #131f37 !important;
    }
    [data-theme="dark"] .official-title-text,
    [data-bs-theme="dark"] .official-title-text,
    body.dark-mode .official-title-text {
        background: linear-gradient(90deg, #a5b4fc, #7dd3fc);
        -webkit-background-clip: text; background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    [data-theme="dark"] .official-timetable-card .table-responsive::-webkit-scrollbar-track,
    [data-bs-theme="dark"] .official-timetable-card .table-responsive::-webkit-scrollbar-track,
    body.dark-mode .official-timetable-card .table-responsive::-webkit-scrollbar-track {
        background: #1e293b;
    }
    [data-theme="dark"] .official-timetable-card .table-responsive::-webkit-scrollbar-thumb,
    [data-bs-theme="dark"] .official-timetable-card .table-responsive::-webkit-scrollbar-thumb,
    body.dark-mode .official-timetable-card .table-responsive::-webkit-scrollbar-thumb {
        background: #475569;
    }
    [data-theme="dark"] .schedule-slot-cell,
    [data-bs-theme="dark"] .schedule-slot-cell,
    body.dark-mode .schedule-slot-cell { background: #1a2742 !important; }
    [data-theme="dark"] .schedule-slot-cell.has-slot,
    [data-bs-theme="dark"] .schedule-slot-cell.has-slot,
    body.dark-mode .schedule-slot-cell.has-slot {
        background: linear-gradient(160deg, #1e293b, color-mix(in srgb, var(--day-accent) 22%, #1e293b)) !important;
    }
    [data-theme="dark"] .schedule-slot-cell.is-activity,
    [data-bs-theme="dark"] .schedule-slot-cell.is-activity,
    body.dark-mode .schedule-slot-cell.is-activity {
        background: repeating-linear-gradient(135deg, #1e293b 0 8px, #1a2742 8px 16px) !important;
    }
    [data-theme="dark"] .slot-title, [data-theme="dark"] .slot-subtitle,
    body.dark-mode .slot-title, body.dark-mode .slot-subtitle { color: #e2e8f0 !important; }
    [data-theme="dark"] .day-header-cell, body.dark-mode .day-header-cell {
        background: color-mix(in srgb, var(--day-accent) 25%, #1e293b) !important; color: #f1f5f9 !important;
    }
    [data-theme="dark"] .official-timetable-table thead .th-time-val,
    body.dark-mode .official-timetable-table thead .th-time-val { background: #1e293b !important; color: #c7d2fe !important; }

    /* ===== ป๊อปอัปรายละเอียดวิชา (กดที่ช่องในตาราง) ===== */
    .tt-subject-pop {
        position: fixed; z-index: 2000;
        width: min(320px, calc(100vw - 24px));
        background: #ffffff;
        border-radius: 14px;
        border: 1px solid color-mix(in srgb, var(--day-accent, #6366f1) 35%, #e2e8f0);
        box-shadow: 0 20px 40px -12px rgba(15, 23, 42, 0.35);
        overflow: hidden;
        animation: ttPopIn .18s cubic-bezier(.2, .8, .2, 1) both;
    }
    .tt-subject-pop .tt-pop-head {
        padding: .7rem .9rem .6rem;
        background: linear-gradient(135deg, color-mix(in srgb, var(--day-accent, #6366f1) 22%, #ffffff), #ffffff);
        border-bottom: 1px solid #eef2f7;
        position: relative;
    }
    .tt-subject-pop .tt-pop-code {
        display: inline-block; font-family: ui-monospace, monospace; font-weight: 700; font-size: .78rem;
        padding: 1px 8px; border-radius: 999px; color: #fff;
        background: var(--day-accent, #6366f1);
    }
    .tt-subject-pop .tt-pop-title { font-weight: 700; font-size: .98rem; color: #0f172a; margin-top: .35rem; line-height: 1.35; padding-right: 1.4rem; }
    .tt-subject-pop .tt-pop-title.is-missing { color: #94a3b8; font-weight: 500; font-size: .85rem; }
    .tt-subject-pop .tt-pop-close {
        position: absolute; top: .45rem; right: .5rem; border: 0; background: transparent;
        color: #64748b; font-size: 1.1rem; line-height: 1; padding: .2rem; cursor: pointer;
    }
    .tt-subject-pop .tt-pop-body { padding: .6rem .9rem .75rem; font-size: .8rem; }
    .tt-subject-pop .tt-pop-row { display: flex; gap: .5rem; padding: .18rem 0; color: #334155; }
    .tt-subject-pop .tt-pop-row i { color: var(--day-accent, #6366f1); width: 1rem; text-align: center; }
    .tt-subject-pop .tt-pop-row span.lbl { color: #94a3b8; min-width: 62px; }
    .tt-subject-pop .tt-pop-badges { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .45rem; }
    .tt-subject-pop .tt-pop-badges span {
        font-size: .7rem; padding: 2px 8px; border-radius: 999px;
        background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0;
    }
    @keyframes ttPopIn { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }

    [data-theme="dark"] .tt-subject-pop, body.dark-mode .tt-subject-pop { background: #1e293b; border-color: #334155; }
    [data-theme="dark"] .tt-subject-pop .tt-pop-head, body.dark-mode .tt-subject-pop .tt-pop-head {
        background: linear-gradient(135deg, color-mix(in srgb, var(--day-accent, #6366f1) 30%, #1e293b), #1e293b); border-color: #334155;
    }
    [data-theme="dark"] .tt-subject-pop .tt-pop-title, body.dark-mode .tt-subject-pop .tt-pop-title { color: #f1f5f9; }
    [data-theme="dark"] .tt-subject-pop .tt-pop-row, body.dark-mode .tt-subject-pop .tt-pop-row { color: #cbd5e1; }
    [data-theme="dark"] .tt-subject-pop .tt-pop-badges span, body.dark-mode .tt-subject-pop .tt-pop-badges span {
        background: #0f172a; color: #cbd5e1; border-color: #334155;
    }

    @media (prefers-reduced-motion: reduce) {
        .official-timetable-card, .official-timetable-card::before,
        .schedule-slot-cell, .schedule-slot-cell.is-now, .tt-subject-pop { animation: none !important; }
        .schedule-slot-cell.has-slot:hover { transform: none; }
    }
}

/* ===== พิมพ์: รูปแบบทางการขาวดำ ===== */
@media print {
    .tt-subject-pop { display: none !important; }
    .official-timetable-card {
        padding: 0 !important;
        box-shadow: none !important;
        border: none !important;
    }
    .official-title-text {
        font-size: 13pt !important;
        color: #000 !important;
        padding: 0 45px !important;
    }
    .tt-title-main, .tt-title-name, .tt-title-term, .tt-title-school {
        display: inline !important;
    }
    .tt-title-school {
        display: inline !important;
    }
    .tt-title-main::after, .tt-title-name::after, .tt-title-term::after {
        content: " " !important;
    }
    .official-logo-img {
        width: 48px !important;
        height: 48px !important;
    }
    .official-timetable-table {
        min-width: 0 !important;
        width: 100% !important;
        table-layout: fixed !important;
    }
    .official-timetable-table th,
    .official-timetable-table td {
        border: 1px solid #000 !important;
        color: #000 !important;
        background-color: transparent !important;
    }
    .slot-title, .slot-subtitle, .slot-room {
        color: #000 !important;
    }
    .slot-title {
        font-size: 8.5pt !important;
    }
    .slot-subtitle, .slot-room {
        font-size: 7.5pt !important;
    }
    .schedule-slot-cell {
        height: 52px !important;
    }
    .timetable-signatures {
        display: flex !important;
        margin-top: 1.75rem !important;
        font-size: 9.5pt !important;
        color: #000 !important;
        page-break-inside: avoid;
    }
}
