/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #F8FAFC;
  color: #1E293B;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ========== Layout ========== */
.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px; background: #1E293B; color: #CBD5E1;
  display: flex; flex-direction: column; position: fixed;
  top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform 0.2s ease;
}
.sidebar-header {
  padding: 20px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-header h1 {
  font-size: 18px; font-weight: 600; color: #FFFFFF; line-height: 1.3;
}
.sidebar-header p {
  font-size: 12px; color: #64748B; margin-top: 4px;
}
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; margin: 2px 8px; border-radius: 6px;
  font-size: 14px; color: #94A3B8; cursor: pointer;
  transition: all 0.2s ease; border: none; background: none; width: calc(100% - 16px); text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #E2E8F0; }
.nav-item.active { background: #4F46E5; color: #FFFFFF; }
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12px; color: #475569;
}
.role-info { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.role-label {
  display: inline-block; padding: 4px 10px; border-radius: 4px;
  font-size: 12px; font-weight: 500; text-align: center;
}
.role-label.admin { background: rgba(79,70,229,0.2); color: #A5B4FC; }
.role-label.teacher { background: rgba(16,185,129,0.2); color: #6EE7B7; }
.storage-hint { margin-top: 4px; }

/* Main Content */
.main-content {
  flex: 1; margin-left: 240px; padding: 24px; max-width: 1400px;
}

/* Mobile hamburger */
.mobile-header {
  display: none; position: fixed; top: 0; left: 0; right: 0;
  height: 56px; background: #1E293B; z-index: 99;
  align-items: center; padding: 0 16px; gap: 12px;
}
.hamburger-btn {
  background: none; border: none; color: #FFFFFF; padding: 4px;
}
.hamburger-btn svg { width: 24px; height: 24px; }
.mobile-header h1 { font-size: 16px; color: #FFFFFF; font-weight: 600; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99;
}

/* ========== Page Sections ========== */
.page-section { display: none; }
.page-section.active { display: block; }

.page-title {
  font-size: 22px; font-weight: 600; color: #1E293B; margin-bottom: 4px;
}
.page-desc {
  font-size: 13px; color: #64748B; margin-bottom: 24px;
}

/* ========== Cards ========== */
.card {
  background: #FFFFFF; border: 1px solid #E2E8F0; border-radius: 8px;
  padding: 20px; margin-bottom: 16px;
}
.card-title {
  font-size: 15px; font-weight: 600; color: #1E293B; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}

/* ========== Stats Row ========== */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: #FFFFFF; border: 1px solid #E2E8F0; border-radius: 8px;
  padding: 16px 20px; display: flex; align-items: center; gap: 14px;
}
.stat-icon {
  width: 40px; height: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 20px; height: 20px; }
.stat-icon.blue { background: #EEF2FF; color: #4F46E5; }
.stat-icon.amber { background: #FFFBEB; color: #F59E0B; }
.stat-icon.green { background: #ECFDF5; color: #10B981; }
.stat-icon.red { background: #FEF2F2; color: #EF4444; }
.stat-info {}
.stat-value { font-size: 22px; font-weight: 700; color: #1E293B; line-height: 1.2; }
.stat-label { font-size: 12px; color: #64748B; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent; transition: all 0.2s ease;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: #4F46E5; color: #FFFFFF; }
.btn-primary:hover { background: #4338CA; box-shadow: 0 1px 3px rgba(79,70,229,0.3); }
.btn-secondary { background: #FFFFFF; color: #1E293B; border-color: #E2E8F0; }
.btn-secondary:hover { background: #F8FAFC; border-color: #CBD5E1; }
.btn-danger { background: #FEF2F2; color: #EF4444; border-color: #FECACA; }
.btn-danger:hover { background: #FEE2E2; }
.btn-success { background: #ECFDF5; color: #059669; border-color: #A7F3D0; }
.btn-success:hover { background: #D1FAE5; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-outline { background: transparent; color: #CBD5E1; border-color: rgba(255,255,255,0.2); }
.btn-outline:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.4); }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ========== Forms ========== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 13px; font-weight: 500; color: #374151; margin-bottom: 6px;
}
.form-input, .form-select {
  width: 100%; padding: 8px 12px; border: 1px solid #E2E8F0; border-radius: 6px;
  font-size: 14px; color: #1E293B; background: #FFFFFF;
  transition: border-color 0.2s ease;
}
.form-input:focus, .form-select:focus {
  outline: none; border-color: #4F46E5; box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.form-input::placeholder { color: #94A3B8; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-hint { font-size: 12px; color: #64748B; margin-top: 4px; }

/* Checkbox group */
.checkbox-group { display: flex; flex-wrap: wrap; gap: 8px; }
.checkbox-item {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid #E2E8F0; border-radius: 4px;
  font-size: 13px; cursor: pointer; transition: all 0.15s ease; user-select: none;
}
.checkbox-item:hover { border-color: #4F46E5; }
.checkbox-item.checked { background: #EEF2FF; border-color: #4F46E5; color: #4F46E5; }
.checkbox-item input { display: none; }

/* ========== Tables ========== */
.table-wrapper { overflow-x: auto; border: 1px solid #E2E8F0; border-radius: 8px; }
.table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
.table th {
  background: #F8FAFC; font-weight: 600; color: #475569;
  padding: 10px 12px; text-align: left; border-bottom: 1px solid #E2E8F0;
  white-space: nowrap; position: sticky; top: 0;
}
.table td {
  padding: 10px 12px; border-bottom: 1px solid #F1F5F9;
  color: #1E293B; vertical-align: middle;
}
.table tbody tr:hover { background: #F8FAFC; }
.table tbody tr:last-child td { border-bottom: none; }

/* Tags */
.tag {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 4px; font-size: 12px; font-weight: 500;
}
.tag-blue { background: #EEF2FF; color: #4F46E5; }
.tag-green { background: #ECFDF5; color: #059669; }
.tag-red { background: #FEF2F2; color: #EF4444; }
.tag-amber { background: #FFFBEB; color: #D97706; }
.tag-gray { background: #F1F5F9; color: #64748B; }

/* Leave mark */
.leave-mark {
  border-left: 3px solid #EF4444; background: #FEF2F2;
  padding: 4px 8px; border-radius: 0 4px 4px 0;
}

/* ========== Upload Area ========== */
.upload-area {
  border: 2px dashed #E2E8F0; border-radius: 8px;
  padding: 40px 20px; text-align: center; cursor: pointer;
  transition: all 0.2s ease;
}
.upload-area:hover { border-color: #4F46E5; background: #FAFAFE; }
.upload-area.dragover { border-color: #4F46E5; background: #EEF2FF; }
.upload-area svg { width: 40px; height: 40px; color: #94A3B8; margin-bottom: 12px; }
.upload-area p { font-size: 14px; color: #64748B; }
.upload-area .upload-hint { font-size: 12px; color: #94A3B8; margin-top: 4px; }

/* ========== Empty State ========== */
.empty-state {
  text-align: center; padding: 48px 20px; color: #94A3B8;
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ========== Modal ========== */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 200; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #FFFFFF; border-radius: 8px; width: 100%; max-width: 520px;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid #E2E8F0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: #64748B; padding: 4px; border-radius: 4px;
}
.modal-close:hover { background: #F1F5F9; }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 12px 20px; border-top: 1px solid #E2E8F0;
  display: flex; justify-content: flex-end; gap: 8px;
}

/* ========== Toast ========== */
.toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 16px; border-radius: 6px; font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1); animation: slideIn 0.2s ease;
  display: flex; align-items: center; gap: 8px; max-width: 360px;
}
.toast-success { background: #ECFDF5; color: #065F46; border: 1px solid #A7F3D0; }
.toast-error { background: #FEF2F2; color: #991B1B; border: 1px solid #FECACA; }
.toast-info { background: #EEF2FF; color: #3730A3; border: 1px solid #C7D2FE; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========== Schedule Grid ========== */
.schedule-grid { overflow-x: auto; }
.schedule-grid table { min-width: 700px; }
.schedule-grid th, .schedule-grid td { text-align: center; min-width: 90px; }
.schedule-grid td .cell-info { font-size: 12px; line-height: 1.4; }
.schedule-grid td .cell-teacher { font-weight: 500; color: #1E293B; }
.schedule-grid td .cell-subject { color: #64748B; }
.schedule-grid td.has-leave { background: #FEF2F2; }

/* ========== Substitution Result ========== */
.sub-result-card {
  border: 1px solid #E2E8F0; border-radius: 8px; padding: 16px;
  margin-bottom: 12px; background: #FFFFFF;
  display: grid; grid-template-columns: auto 1fr auto; gap: 16px; align-items: center;
}
.sub-result-date {
  text-align: center; padding: 8px 12px; background: #F8FAFC;
  border-radius: 6px; min-width: 70px;
}
.sub-result-date .day { font-size: 20px; font-weight: 700; color: #4F46E5; }
.sub-result-date .weekday { font-size: 12px; color: #64748B; }
.sub-result-info {}
.sub-result-info .period { font-size: 12px; color: #64748B; }
.sub-result-info .detail { font-size: 14px; color: #1E293B; margin-top: 2px; }
.sub-result-info .detail strong { color: #EF4444; }
.sub-result-info .detail .arrow { color: #94A3B8; margin: 0 4px; }
.sub-result-info .detail .sub-teacher { color: #059669; font-weight: 600; }
.sub-result-actions {}

/* ========== Print Styles ========== */
@media print {
  .sidebar, .mobile-header, .sidebar-overlay, .btn, .toast-container,
  .no-print, .page-desc { display: none !important; }
  .main-content { margin-left: 0 !important; padding: 0 !important; }
  .card { border: none !important; box-shadow: none !important; }
  .table { font-size: 11px; }
  .table th { background: #F1F5F9 !important; }
  body { background: #FFFFFF; }
  .page-title { font-size: 18px; }
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .mobile-header { display: flex; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; padding: 72px 16px 24px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
  .sub-result-card { grid-template-columns: 1fr; }
  .sub-result-date { display: flex; gap: 8px; justify-content: center; }
}
