:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --border: #dce3ef;
    --text: #1f2a37;
    --muted: #6b7280;
    --primary: #2563eb;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
    background: var(--bg);
    color: var(--text);
}

.container {
    width: min(1160px, 94%);
    margin: 0 auto;
}

.topbar {
    background: #0f172a;
    color: #fff;
    padding: 14px 0;
}

.nav-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
}

.topbar h1 {
    font-size: 22px;
    margin: 0;
}

.topbar a {
    color: #fff;
    text-decoration: none;
    margin-left: 14px;
}

.main-content {
    padding: 24px 0 40px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 16px;
}

.form-grid .full-width {
    grid-column: 1 / -1;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
}

.simple-form, .narrow-card {
    max-width: 420px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
}

input, select, textarea, button, .btn-secondary {
    font: inherit;
}

input, select, textarea {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff;
}

button, .btn-secondary {
    border: none;
    border-radius: 8px;
    padding: 10px 16px;
    background: var(--primary);
    color: white;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

.btn-secondary { background: #475569; }
.btn-warning { background: var(--warning); }
.btn-danger { background: var(--danger); }

.flash {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.flash-success { background: #ecfdf5; border-color: #bbf7d0; }
.flash-danger { background: #fef2f2; border-color: #fecaca; }
.flash-warning { background: #fffbeb; border-color: #fde68a; }
.flash-info { background: #eff6ff; border-color: #bfdbfe; }

.muted { color: var(--muted); }
.list { padding-left: 20px; }
.tip-box {
    margin-top: 14px;
    padding: 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    line-height: 1.7;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    border-bottom: 1px solid var(--border);
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
    font-size: 14px;
}

thead th {
    background: #f8fafc;
}

.action-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

@media (max-width: 900px) {
    .grid-2, .form-grid {
        grid-template-columns: 1fr;
    }

    .nav-wrap {
        flex-direction: column;
        align-items: flex-start;
    }
}


.schedule-box {
    margin-top: 18px;
}

.schedule-box h3 {
    margin-top: 18px;
    margin-bottom: 12px;
}


.overview-stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.overview-room h3 {
    margin: 0 0 10px;
}

.overview-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 12px;
}

.overview-day {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: #f8fafc;
    min-height: 140px;
}

.overview-day-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 13px;
}

.mini-booking-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mini-booking-list li {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    line-height: 1.5;
}

.mini-booking-list .time {
    display: block;
    font-weight: 700;
    color: var(--primary);
}

.mini-booking-list .dept {
    display: block;
    font-size: 13px;
}

.small {
    font-size: 13px;
}

@media (max-width: 1200px) {
    .overview-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 900px) {
    .overview-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .overview-grid {
        grid-template-columns: 1fr;
    }
}

.block-item {
    background: #fff7ed;
    border-color: #fed7aa;
}
.block-item .time {
    color: var(--warning);
}

/* Shared schedule cards */
[hidden] { display: none !important; }
.key-notice { margin: 0 0 22px; }
.table-scroll { overflow-x: auto; }
.card h2, .card h3 { line-height: 1.5; }
.daily-section > h3 { margin: 0 0 10px; font-size: 20px; }
.daily-section > p { margin: 0 0 22px; line-height: 1.8; }
.daily-events { display: grid; grid-template-columns: repeat(auto-fit,minmax(240px,1fr)); gap: 12px; align-items: start; }
.schedule-event { min-width: 0; display: flex; flex-direction: column; gap: 8px; background: #eef5ff; border: 1px solid #d1e2fa; border-left: 4px solid #6798de; border-radius: 10px; padding: 12px 14px; line-height: 1.45; overflow-wrap: anywhere; }
.event-heading { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.schedule-event .time { display: block; color: #234e84; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.event-badge { display: inline-block; border-radius: 5px; padding: 2px 7px; font-size: 11px; color: #416a9e; background: #dfeafb; white-space: nowrap; }
.event-details { display: flex; flex-direction: column; gap: 3px; }
.event-name { font-size: 15px; font-weight: 600; color: #273c54; }
.event-person, .event-phone { display: block; font-size: 14px; color: #52647a; }
.event-phone { font-variant-numeric: tabular-nums; letter-spacing: .3px; }
.schedule-event .status { align-self: flex-start; margin-top: auto; padding: 2px 8px; font-size: 12px; border-radius: 20px; background: #fff; color: #52647a; }
.schedule-event .status-approved { color: #30745a; background: #e0f0e6; }
.schedule-event .status-pending { color: #94651e; background: #fff0cc; }
.schedule-event.block-item { background: #fff7eb; border-color: #f0dcbc; border-left-color: #d5a454; }
.schedule-event.block-item .time { color: #946124; }
.block-item .event-badge { color: #946124; background: #f7e9d2; }
.block-item .event-name { color: #755533; }
.overview-stack { gap: 28px; }
.overview-day { padding: 10px; background: #fafbfd; }
.overview-day-head { margin-bottom: 10px; gap: 8px; }
.mini-booking-list { gap: 8px; }
.mini-booking-list .schedule-event { padding: 8px; gap: 6px; border-left-width: 3px; }
.mini-booking-list .schedule-event .time { font-size: 13px; }
.mini-booking-list .event-details { gap: 2px; }
.mini-booking-list .event-name, .mini-booking-list .event-person, .mini-booking-list .event-phone { font-size: 13px; }

/* Weekly timetable: state, time, and arrangement each have their own space. */
.schedule-legend { display: flex; gap: 22px; margin: 20px 0 12px; font-size: 13px; color: #64748b; }
.schedule-legend span { display: flex; align-items: center; gap: 7px; }
.schedule-legend i { width: 12px; height: 12px; display: inline-block; border-radius: 3px; border: 1px solid #dce3ea; }
.legend-free { background: #f5f7fa; }
.schedule-legend .legend-occupied { background: #f6e5c6; border-color: #e6c48d; }
.lesson-table { min-width: 980px; table-layout: fixed; border-collapse: separate; border-spacing: 5px; }
.lesson-table th, .lesson-table td { border: 0; }
.lesson-table th { text-align: center; vertical-align: middle; line-height: 1.9; }
.lesson-table th:first-child { width: 92px; }
.lesson-table thead th { background: transparent; color: #52647a; }
.lesson-table td { padding: 0; }
.lesson-cell { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 9px; width: 100%; min-height: 118px; height: 100%; background: #f5f7fa; color: #738096; padding: 16px 10px; border: 1px solid #e5eaf0; border-radius: 10px; text-align: center; transition: border-color .15s, box-shadow .15s; }
.lesson-cell .lesson-time { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; color: #54647a; font-variant-numeric: tabular-nums; }
.lesson-cell .lesson-title { display: block; font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.lesson-empty { display: block; font-size: 13px; }
.lesson-edit { display: block; font-size: 11px; color: #8390a2; }
.lesson-cell.occupied { background: #fff3dd; border-color: #ecd1a2; color: #825d23; }
.lesson-cell.occupied .lesson-time { color: #8b641f; }
.lesson-cell:hover { border-color: #8daacf; box-shadow: 0 3px 9px rgb(45 70 100 / 9%); }

/* Compact arrangement dialog */
button:focus-visible, a:focus-visible { outline: 3px solid #93b9ea; outline-offset: 3px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #87ace0; box-shadow: 0 0 0 3px rgb(89 140 210 / 12%); }
#lesson-dialog { width: min(760px, calc(100vw - 32px)); max-height: min(90vh, 760px); overflow-y: auto; border: 0; border-radius: 18px; padding: 24px 28px 0; color: var(--text); box-shadow: 0 24px 80px rgb(15 23 42 / 22%); }
#lesson-dialog::backdrop { background: rgb(30 41 59 / 35%); backdrop-filter: blur(3px); }
#lesson-form { grid-template-columns: 1fr 1fr; gap: 16px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding-bottom: 4px; }
.dialog-eyebrow { margin: 0 0 4px; color: #718096; font-size: 12px; letter-spacing: 1px; }
.dialog-heading h3 { margin: 0; font-size: 22px; line-height: 1.5; }
.dialog-close { align-self: flex-start; background: #f1f4f8; color: #718096; padding: 0; width: 32px; height: 32px; border-radius: 50%; font-size: 22px; line-height: 1; }
#lesson-form label { min-width: 0; gap: 7px; color: #536176; font-size: 13px; }
#lesson-form input, #lesson-form select { min-width: 0; width: 100%; font-size: 14px; padding: 10px; }
#weeks-panel { background: #f8fafc; border: 1px solid #e8edf3; border-radius: 12px; padding: 14px; }
.week-actions { margin: 12px 0; gap: 8px; }
.week-actions button { padding: 5px 13px; font-size: 12px; background: #e8eff9; color: #426692; }
.week-actions button:hover { background: #d9e6f7; }
.week-grid { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 7px; max-height: 222px; overflow-y: auto; padding: 2px; scrollbar-width: thin; }
#lesson-form .week-grid label { flex-direction: row; align-items: center; gap: 7px; background: #fff; border: 1px solid #e0e6ee; padding: 7px; border-radius: 7px; cursor: pointer; }
#lesson-form .week-grid label:has(input:checked) { background: #e7f0fd; border-color: #91b4e4; color: #345e98; }
#lesson-form .week-grid input { width: 14px; height: 14px; margin: 0; padding: 0; flex: 0 0 auto; accent-color: #4c7fbe; box-shadow: none; }
.week-label { display: flex; flex-direction: row; align-items: center; justify-content: space-between; flex: 1; gap: 4px; }
.week-label strong { font-size: 12px; font-weight: 600; white-space: nowrap; }
.week-label small { font-size: 10px; color: #8190a3; }
.week-summary { margin: 10px 0 0; font-size: 12px; color: #8090a4; }
#week-count { color: #4a6d99; font-weight: 600; }
#lesson-help { margin: 0; font-size: 12px; line-height: 1.6; color: #7a889a; }
.dialog-actions { position: sticky; bottom: 0; background: #fff; padding: 16px 0 20px; border-top: 1px solid #edf0f5; justify-content: flex-end; }
.dialog-actions .btn-secondary { order: -1; background: #f0f3f7; color: #607087; }
summary { cursor: pointer; font-weight: bold; padding: 8px 0; }
.daily-time-row { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
@media (min-width: 1201px) { .container { width: min(1440px, 96%); } }
@media (max-width: 900px) { .daily-events { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media (max-width: 600px) {
 .daily-events { grid-template-columns: 1fr; }
 #lesson-dialog { padding: 18px 16px 0; border-radius: 14px; }
 #lesson-form { grid-template-columns: 1fr; gap: 12px; }
 .dialog-heading h3 { font-size: 19px; }
 .week-grid { grid-template-columns: repeat(3,minmax(0,1fr)); max-height: 200px; }
 #lesson-form .week-grid label { padding: 6px 4px; gap: 4px; }
 #weeks-panel { padding: 10px; }
 .week-label { flex-direction: column; align-items: flex-start; gap: 1px; }
 .week-summary { line-height: 1.6; }
 .daily-time-row { grid-template-columns: 1fr 1fr; }
 .daily-time-row strong { grid-column: 1 / -1; }
}
