* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, 'Microsoft YaHei', sans-serif; background: #f0f2f5; color: #333; min-height: 100vh; }

.navbar {
    background: linear-gradient(135deg, #1a237e, #283593);
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 56px;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
    position: sticky; top: 0; z-index: 100;
}
.nav-brand { color: #fff; font-size: 18px; font-weight: 700; margin-right: 32px; white-space: nowrap; }
.nav-tabs { display: flex; gap: 4px; flex: 1; }
.nav-tab {
    background: transparent; border: none; color: rgba(255,255,255,.7);
    padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px;
    transition: all .2s;
}
.nav-tab:hover { color: #fff; background: rgba(255,255,255,.1); }
.nav-tab.active { color: #fff; background: rgba(255,255,255,.2); font-weight: 600; }
.nav-actions { display: flex; gap: 8px; margin-left: auto; }

.btn {
    padding: 8px 16px; border: none; border-radius: 8px;
    cursor: pointer; font-size: 13px; font-weight: 600;
    transition: all .2s; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: #1976d2; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1565c0; }
.btn-success { background: #2e7d32; color: #fff; }
.btn-success:hover:not(:disabled) { background: #1b5e20; }
.btn-warning { background: #e65100; color: #fff; }
.btn-warning:hover:not(:disabled) { background: #bf360c; }
.btn-secondary { background: #e0e0e0; color: #333; }
.btn-secondary:hover { background: #d0d0d0; }
.btn-danger { background: #d32f2f; color: #fff; }
.btn-danger:hover { background: #c62828; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.tab-content { display: none; padding: 20px 24px; }
.tab-content.active { display: block; }

.toolbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; background: #fff; border-radius: 10px;
    margin-bottom: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.toolbar label { font-size: 13px; color: #666; }
.toolbar select, .toolbar input {
    padding: 6px 10px; border: 1px solid #ddd; border-radius: 6px;
    font-size: 13px; margin-left: 4px;
}
.schedule-status { font-size: 14px; font-weight: 600; }
.schedule-score { font-size: 13px; color: #666; margin-left: 12px; }

/* Schedule Table */
.schedule-table-wrapper { overflow-x: auto; background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.schedule-table {
    width: 100%; border-collapse: collapse; font-size: 13px; min-width: 800px;
}
.schedule-table th, .schedule-table td {
    border: 1px solid #e0e0e0; padding: 8px 4px; text-align: center;
    min-width: 60px; height: 40px; vertical-align: middle;
}
.schedule-table th {
    background: #e3f2fd; font-weight: 700; position: sticky; top: 0; z-index: 10;
}
.schedule-table .day-header { background: #1565c0; color: #fff; font-size: 14px; }
.schedule-table .section-header { background: #90caf9; font-size: 12px; color: #1a237e; }
.schedule-table .class-name { background: #fff8e1; font-weight: 700; min-width: 70px; position: sticky; left: 0; z-index: 5; }
.schedule-table .period-num { background: #e8f5e9; font-size: 11px; color: #2e7d32; }
.schedule-table td.subject-cell { cursor: pointer; transition: background .15s; }
.schedule-table td.subject-cell:hover { filter: brightness(0.95); }
.schedule-table td.subject-cell.dragging { opacity: 0.4; }
.schedule-table td.subject-cell.drag-over { outline: 3px dashed #1976d2; outline-offset: -3px; background: #e3f2fd !important; }

.view-summary {
    display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; align-items: stretch;
}
.view-summary-card {
    background: #fff; border: 1px solid #dbe8ff; border-radius: 10px; padding: 12px 14px;
    min-width: 110px; box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.view-summary-card strong {
    display: block; font-size: 22px; color: #1565c0; line-height: 1.1; margin-bottom: 4px;
}
.view-summary-card span { font-size: 12px; color: #666; }
.view-summary-card.success { background: #e8f5e9; border-color: #a5d6a7; }
.view-summary-card.success strong { color: #2e7d32; }
.view-summary-card.warning { background: #fff3e0; border-color: #ffb74d; }
.view-summary-card.warning strong { color: #ef6c00; }
.view-summary-tip {
    flex: 1; min-width: 260px; background: #f8f9fb; border: 1px solid #eceff5; border-radius: 10px;
    padding: 12px 14px; font-size: 13px; color: #546e7a; display: flex; align-items: center; line-height: 1.6;
}
.teacher-slot-cell,
.subject-summary-cell {
    cursor: default !important;
}
.teacher-slot-cell:hover,
.subject-summary-cell:hover {
    filter: none !important;
}
.teacher-filled-cell {
    box-shadow: inset 0 0 0 1px rgba(21, 101, 192, 0.12);
}
.teacher-slot-item {
    display: flex; flex-direction: column; gap: 2px; line-height: 1.25;
}
.teacher-slot-item + .teacher-slot-item {
    margin-top: 6px; padding-top: 6px; border-top: 1px dashed rgba(211, 47, 47, 0.28);
}
.teacher-slot-class {
    font-weight: 700; color: #1a237e;
}
.teacher-slot-subject {
    font-size: 11px; color: #546e7a;
}
.teacher-conflict-cell {
    background: #ffebee !important; border-color: #ef9a9a !important;
}
.teacher-conflict-cell .teacher-slot-class,
.teacher-conflict-cell .teacher-slot-subject {
    color: #c62828;
}
.teacher-conflict-badge {
    display: inline-block; margin-bottom: 6px; padding: 2px 8px; border-radius: 999px;
    background: #d32f2f; color: #fff; font-size: 11px; font-weight: 700;
}
.subject-summary-cell {
    background: #fafafa;
}
.subject-summary-cell.has-data {
    background: #f5f9ff;
}
.subject-summary-count {
    font-size: 15px; font-weight: 700; color: #1565c0; margin-bottom: 4px;
}
.subject-summary-names {
    font-size: 11px; color: #607d8b; line-height: 1.45;
}

/* Subject colors */

.sub-语文 { background: #FFF3E0 !important; }
.sub-数学 { background: #E3F2FD !important; }
.sub-英语 { background: #E8F5E9 !important; }
.sub-物理 { background: #FFFDE7 !important; }
.sub-化学 { background: #FCE4EC !important; }
.sub-生物 { background: #F3E5F5 !important; }
.sub-历史 { background: #E0F7FA !important; }
.sub-地理 { background: #FFF8E1 !important; }
.sub-政治 { background: #F1F8E9 !important; }
.sub-体育 { background: #E1F5FE !important; }
.sub-音乐 { background: #F5F5F5 !important; }
.sub-美术 { background: #FAFAFA !important; }
.sub-信息技术 { background: #E0F2F1 !important; }
.sub-通用技术 { background: #E0F2F1 !important; }
.sub-班会 { background: #EEEEEE !important; }

/* Conflicts */
#conflictsPanel {
    margin-top: 16px; background: #fff; border-radius: 10px; padding: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
#conflictsPanel h3 { color: #d32f2f; margin-bottom: 10px; }
.conflict-item {
    padding: 8px 12px; margin: 4px 0; border-radius: 6px;
    background: #ffebee; font-size: 13px; border-left: 3px solid #d32f2f;
}

/* Panels */
.panel {
    background: #fff; border-radius: 10px; padding: 20px;
    margin-bottom: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-header h2 { font-size: 16px; color: #1a237e; }
.panel-actions { display: flex; gap: 8px; align-items: center; }
.panel-actions input, .panel-actions select {
    padding: 6px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 13px;
}

/* Class Grid */
.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.class-card {
    background: #f5f5f5; border: 2px solid transparent; border-radius: 10px;
    padding: 12px; text-align: center; cursor: pointer; transition: all .2s;
}
.class-card:hover { border-color: #1976d2; background: #e3f2fd; transform: translateY(-1px); }
.class-card .class-id { font-size: 16px; font-weight: 700; color: #1a237e; }
.class-card .class-info { font-size: 11px; color: #888; margin-top: 4px; }
.class-card .class-actions { margin-top: 6px; }

/* Teacher List */
.teacher-group { margin-bottom: 20px; }
.teacher-group h3 { font-size: 14px; color: #1565c0; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 2px solid #e3f2fd; }
.teacher-tags { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }

.teacher-card {
    background: #fafafa; border: 1px solid #e0e0e0; border-radius: 10px;
    padding: 10px; min-width: 260px; transition: all .2s;
}
.teacher-card:hover { border-color: #90caf9; box-shadow: 0 2px 8px rgba(0,0,0,.08); }

.teacher-card-name {
    font-size: 14px; font-weight: 700; color: #1a237e;
    display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.teacher-card-name .remove-teacher {
    cursor: pointer; color: #bbb; font-size: 18px; line-height: 1; margin-left: auto;
}
.teacher-card-name .remove-teacher:hover { color: #d32f2f; }

.teacher-card-classes {
    display: flex; flex-wrap: wrap; gap: 4px;
}
.class-check {
    display: inline-flex; align-items: center; gap: 2px;
    padding: 2px 6px; border-radius: 4px; font-size: 11px;
    cursor: pointer; background: #f0f0f0; transition: all .15s;
    user-select: none;
}
.class-check:hover { background: #e3f2fd; }
.class-check input[type="checkbox"] { margin: 0; cursor: pointer; width: 13px; height: 13px; }
.class-check:has(input:checked) {
    background: #1976d2; color: #fff; font-weight: 600;
}

/* Rules */
.rules-container { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 13px; color: #555; margin-bottom: 4px; font-weight: 600; }
.form-group input, .form-group select {
    width: 100%; padding: 8px 12px; border: 1px solid #ddd; border-radius: 6px; font-size: 13px;
}
.form-group input[type="number"] { width: 100px; }
.form-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.form-row label { font-size: 13px; color: #666; }
.form-row select, .form-row input { padding: 6px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 13px; }

.tag-container { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.pref-tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border-radius: 16px; font-size: 12px;
    cursor: pointer; border: 2px solid transparent; transition: all .2s;
    background: #f5f5f5;
}
.pref-tag.active { background: #e3f2fd; border-color: #1976d2; color: #1565c0; font-weight: 600; }

.fixed-item {
    display: inline-flex; align-items: center; gap: 6px;
    background: #fff3e0; padding: 6px 12px; border-radius: 8px;
    font-size: 13px; margin: 4px;
}
.fixed-item .remove-fixed { cursor: pointer; color: #999; }
.fixed-item .remove-fixed:hover { color: #d32f2f; }

/* Period limit grid */
.period-limit-table { border-collapse: collapse; width: 100%; }
.period-limit-table th, .period-limit-table td {
    border: 1px solid #e0e0e0; padding: 4px 2px; text-align: center; font-size: 11px;
}
.period-limit-table th { background: #e3f2fd; font-weight: 600; font-size: 12px; }
.period-limit-table .pl-label { background: #fff8e1; font-weight: 600; font-size: 11px; min-width: 40px; }
.period-limit-table .pl-cell {
    cursor: pointer; transition: all .15s; background: #fafafa; user-select: none;
}
.period-limit-table .pl-cell:hover { background: #e3f2fd; }
.period-limit-table .pl-cell.selected { background: #1976d2 !important; color: #fff; font-weight: 700; }

/* Day-Period forbidden grid */
#dayPeriodForbidGrid .period-limit-table .pl-cell.forbidden { background: #d32f2f !important; color: #fff; font-weight: 700; }
#dayPeriodForbidGrid .period-limit-table .pl-cell:hover { background: #ffebee; }

/* Period limit tags (per-period selection) */
#periodLimitGrid .pl-cell {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 6px 16px; border-radius: 8px; font-size: 13px;
    cursor: pointer; border: 2px solid #e0e0e0; background: #fafafa;
    transition: all .15s; user-select: none; font-weight: 600;
}
#periodLimitGrid .pl-cell:hover { border-color: #1976d2; background: #e3f2fd; }
#periodLimitGrid .pl-cell.selected { background: #1976d2 !important; color: #fff; border-color: #1565c0; }

/* Class requirements table */
.req-table { width: 100%; border-collapse: collapse; }
.req-table th, .req-table td { border: 1px solid #e0e0e0; padding: 8px; text-align: center; }
.req-table th { background: #e3f2fd; font-size: 13px; }
.req-table td input {
    width: 60px; padding: 4px; text-align: center; border: 1px solid #ddd; border-radius: 4px;
    font-size: 13px;
}
.req-table td input::placeholder { color: #ccc; }

/* Modal */
.modal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,.5); z-index: 1000; align-items: center; justify-content: center;
}
.modal.show { display: flex; }
.modal-content {
    background: #fff; border-radius: 12px; width: 90%; max-width: 520px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2); animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }
.modal-header {
    padding: 16px 20px; border-bottom: 1px solid #eee;
    display: flex; justify-content: space-between; align-items: center;
}
.modal-header h2 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: #999; }
.modal-body { padding: 20px; }
.modal-body ul { margin: 12px 0; padding-left: 20px; }
.modal-body li { margin-bottom: 6px; font-size: 14px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid #eee; display: flex; justify-content: flex-end; gap: 8px; }

.progress-bar { height: 8px; background: #e0e0e0; border-radius: 4px; overflow: hidden; margin: 12px 0; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #1976d2, #42a5f5); border-radius: 4px; transition: width .3s; width: 0; }
#progressText { font-size: 13px; color: #666; text-align: center; }

/* Toast */
#toast-container { position: fixed; top: 70px; right: 20px; z-index: 2000; }

/* Import Modal */
.import-upload { text-align: center; padding: 30px 20px; }
.upload-area {
    border: 2px dashed #bbb; border-radius: 12px; padding: 30px;
    cursor: pointer; transition: all .2s; margin: 0 auto; max-width: 400px;
}
.upload-area:hover, .upload-area.dragover {
    border-color: #1976d2; background: #e3f2fd;
}
.import-stats {
    display: flex; gap: 16px; margin-bottom: 16px;
}
.import-stat-item {
    background: #f5f5f5; border-radius: 8px; padding: 10px 16px;
    text-align: center; flex: 1;
}
.import-stat-item .stat-num { font-size: 24px; font-weight: 700; color: #1a237e; }
.import-stat-item .stat-label { font-size: 12px; color: #888; margin-top: 2px; }
.import-table-wrapper {
    max-height: 400px; overflow: auto; border: 1px solid #e0e0e0;
    border-radius: 8px;
}
.import-table {
    width: 100%; border-collapse: collapse; font-size: 12px;
}
.import-table th, .import-table td {
    border: 1px solid #e0e0e0; padding: 6px 8px; text-align: center;
    white-space: nowrap;
}
.import-table th {
    background: #e3f2fd; font-weight: 700; position: sticky; top: 0; z-index: 1;
}
.import-table td.class-col { background: #fff8e1; font-weight: 700; color: #1a237e; }
.import-table td.cross-grade { color: #e65100; font-weight: 600; }
.import-table td.cross-grade::before { content: '▲ '; font-size: 10px; }
.toast {
    padding: 12px 20px; border-radius: 8px; margin-bottom: 8px;
    font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.15);
    animation: toastIn .3s ease; min-width: 200px;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }
.toast-success { background: #e8f5e9; color: #2e7d32; border-left: 4px solid #2e7d32; }
.toast-error { background: #ffebee; color: #d32f2f; border-left: 4px solid #d32f2f; }
.toast-info { background: #e3f2fd; color: #1565c0; border-left: 4px solid #1565c0; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c0c0c0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a0a0a0; }
