/* ===== CSS Variables ===== */
:root {
  --primary: #4F6EF7;
  --primary-light: #EEF1FE;
  --primary-dark: #3A56C9;
  --success: #52C41A;
  --success-light: #F6FFED;
  --warning: #FAAD14;
  --warning-light: #FFFBE6;
  --danger: #FF4D4F;
  --danger-light: #FFF2F0;
  --text-primary: #1a1a2e;
  --text-secondary: #6b7280;
  --text-hint: #9ca3af;
  --bg-page: #f5f7fa;
  --bg-card: #ffffff;
  --bg-hover: #f3f4f6;
  --border: #e5e7eb;
  --border-light: #f0f0f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --header-height: 56px;
  --tabbar-height: 60px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }

/* ===== Loading ===== */
.app-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  gap: 16px;
  color: var(--text-secondary);
}
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== App Layout ===== */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg-page);
  position: relative;
}
.app-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-title {
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  flex: 1;
}
.header-left, .header-right {
  width: 40px;
  display: flex;
  align-items: center;
}
.header-right { justify-content: flex-end; }
.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--bg-hover); }

/* ===== Tabbar ===== */
.app-tabbar {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: var(--tabbar-height);
  background: var(--bg-card);
  border-top: 1px solid var(--border-light);
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  color: var(--text-hint);
  font-size: 11px;
  transition: color 0.2s;
  text-decoration: none;
}
.tab-item svg { width: 22px; height: 22px; }
.tab-item.active, .tab-item:hover { color: var(--primary); }
.tab-item.active svg { stroke-width: 2.5; }

/* ===== Page Styles ===== */
.page { padding: 16px; padding-bottom: calc(var(--tabbar-height) + 24px); }
.page-full { padding: 0; padding-bottom: calc(var(--tabbar-height) + 24px); }

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

/* ===== Form Controls ===== */
.form-group {
  margin-bottom: 16px;
}
.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-card);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-input::placeholder { color: var(--text-hint); }
.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text-primary);
  background: var(--bg-card);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%239ca3af' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  outline: none;
  cursor: pointer;
}
.form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.4;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover {
  background: var(--primary-light);
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-hover); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ===== Calendar ===== */
.calendar {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
}
.calendar-title {
  font-size: 17px;
  font-weight: 600;
}
.calendar-nav {
  display: flex;
  gap: 4px;
}
.calendar-nav button {
  width: 32px; height: 32px;
  border: none;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}
.calendar-nav button:hover { background: var(--border); }
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 8px 8px 4px;
}
.calendar-weekday {
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-hint);
  padding: 4px 0;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 4px 8px 12px;
  gap: 2px;
}
.calendar-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
  font-size: 14px;
  gap: 2px;
}
.calendar-cell:hover { background: var(--bg-hover); }
.calendar-cell.other-month { color: var(--text-hint); }
.calendar-cell.today {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.calendar-cell.selected {
  background: var(--primary);
  color: #fff;
}
.calendar-cell.has-booking::after {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  position: absolute;
  bottom: 4px;
}
.calendar-cell.status-free { background: #e6f7e6; }
.calendar-cell.status-free::after { background: var(--success); }
.calendar-cell.status-ok { background: #fff7e6; }
.calendar-cell.status-ok::after { background: var(--warning); }
.calendar-cell.status-full { background: #ffe6e6; }
.calendar-cell.status-full::after { background: var(--danger); }
.calendar-cell.has-mine::after {
  background: var(--primary) !important;
  width: 6px; height: 6px;
}

/* ===== Time Slots ===== */
.time-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}
.time-slot {
  aspect-ratio: 1;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 500;
  min-width: 0;
}
.time-slot:hover { opacity: 0.8; }
.time-slot.free { background: #f0f9eb; border: 1px solid #c2e7b0; }
.time-slot.booked { background: #fef0f0; border: 1px solid #fbc4c4; color: var(--danger); }
.time-slot.buffer { background: #fdf6ec; border: 1px solid #f5dab1; color: #e6a23c; }
.time-slot.blocked { background: #f5f5f5; border: 1px solid #e0e0e0; color: #bbb; }
.time-slot.selected-slot {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  z-index: 1;
  background: var(--primary-light) !important;
}

/* ===== Room Tabs ===== */
.room-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.room-tab {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 14px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.room-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== Booking List ===== */
.booking-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  gap: 12px;
}
.booking-item:last-child { border-bottom: none; }
.booking-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.booking-info { flex: 1; min-width: 0; }
.booking-subject {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.booking-meta {
  font-size: 12px;
  color: var(--text-hint);
  margin-top: 2px;
}
.booking-time {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  flex-shrink: 0;
}

/* ===== Tag / Badge ===== */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
}
.tag-primary { background: var(--primary-light); color: var(--primary); }
.tag-success { background: var(--success-light); color: var(--success); }
.tag-warning { background: var(--warning-light); color: var(--warning); }
.tag-danger { background: var(--danger-light); color: var(--danger); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.2s;
}
.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.3s;
}
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}
.modal-actions .btn { flex: 1; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  box-shadow: var(--shadow-lg);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo h1 {
  font-size: 24px;
  color: var(--primary);
  margin-bottom: 4px;
}
.login-logo p {
  font-size: 14px;
  color: var(--text-hint);
}
.login-form .form-group { margin-bottom: 14px; }
.login-btn { margin-top: 8px; }
.login-links {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  font-size: 13px;
}
.login-role-switch {
  display: flex;
  margin-bottom: 20px;
  background: var(--bg-page);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.login-role-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.login-role-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ===== Stats Page ===== */
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.stat-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}
.stat-label {
  font-size: 13px;
  color: var(--text-hint);
  margin-top: 2px;
}
.heatmap-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}
.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-hint);
}
.heat-1 { background: #c8e6c9; }
.heat-2 { background: #a5d6a7; }
.heat-3 { background: #81c784; }
.heat-4 { background: #66bb6a; color: #fff; }
.heat-5 { background: #43a047; color: #fff; }

/* ===== Weekday Picker ===== */
.weekday-picker {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.weekday-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.weekday-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== Preview Dates ===== */
.preview-list {
  max-height: 200px;
  overflow-y: auto;
  margin: 12px 0;
}
.preview-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-page);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 13px;
}

/* ===== Guide Page ===== */
.guide-tabs {
  display: flex;
  background: var(--bg-page);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 16px;
}
.guide-tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.guide-tab.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.flow-step {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}
.flow-step:last-child { border-bottom: none; }
.flow-num {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}
.flow-text h4 { font-size: 14px; font-weight: 500; }
.flow-text p { font-size: 12px; color: var(--text-hint); margin-top: 2px; }

/* FAQ Accordion */
.faq-item {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  overflow: hidden;
}
.faq-question {
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
}
.faq-question::after {
  content: '+';
  font-size: 18px;
  color: var(--text-hint);
  transition: transform 0.2s;
}
.faq-item.open .faq-question::after {
  content: '\2212';
}
.faq-answer {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--bg-page);
  white-space: pre-line;
  display: none;
}
.faq-item.open .faq-answer { display: block; }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-hint);
}
.empty-state svg { margin: 0 auto 12px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 300;
  pointer-events: none;
  animation: fadeIn 0.2s;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== Teacher List ===== */
.teacher-item {
  display: flex;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  gap: 12px;
}
.teacher-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}
.teacher-info { flex: 1; }
.teacher-name { font-size: 15px; font-weight: 500; }
.teacher-subject { font-size: 12px; color: var(--text-hint); }

/* ===== Responsive ===== */
@media (min-width: 481px) {
  .app-container {
    box-shadow: var(--shadow-lg);
  }
}
@media (max-width: 380px) {
  .time-grid { grid-template-columns: repeat(7, 1fr); }
  .time-slot { font-size: 9px; }
}

/* ===== Block List ===== */
.block-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-left: 4px solid var(--warning);
}
.block-info { flex: 1; }
.block-room { font-size: 14px; font-weight: 500; }
.block-time { font-size: 12px; color: var(--text-hint); margin-top: 2px; }
.block-reason { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* ===== Date Selector ===== */
.date-selector {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}
.date-selector::-webkit-scrollbar { display: none; }
.date-chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  line-height: 1.3;
}
.date-chip .weekday { font-size: 11px; color: var(--text-hint); }
.date-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.date-chip.active .weekday { color: rgba(255,255,255,0.7); }

/* ===== Period Section ===== */
.period-section {
  margin-bottom: 16px;
}
.period-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 0 2px;
}
.period-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}
.period-time {
  font-size: 12px;
  color: var(--text-hint);
}

/* ===== Legend ===== */
.legend {
  display: flex;
  gap: 16px;
  padding: 8px 0;
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-hint);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.legend-dot {
  width: 12px; height: 12px;
  border-radius: 3px;
}
.legend-dot.free { background: #f0f9eb; border: 1px solid #c2e7b0; }
.legend-dot.booked { background: #fef0f0; border: 1px solid #fbc4c4; }
.legend-dot.buffer { background: #fdf6ec; border: 1px solid #f5dab1; }
.legend-dot.blocked { background: #f5f5f5; border: 1px solid #e0e0e0; }

/* ===== Booking Summary Dialog ===== */
.booking-summary {
  background: var(--bg-page);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin: 12px 0;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}
.summary-row .label { color: var(--text-hint); }
.summary-row .value { font-weight: 500; }

/* ===== Page Transition ===== */
.page-enter-active { animation: fadeIn 0.2s ease; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== Footer (备案) ===== */
.app-footer {
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: var(--text-light, #999);
}
.app-footer a {
  color: var(--text-light, #999);
  text-decoration: none;
}
