* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; 
  -webkit-tap-highlight-color: transparent; 
}

body { 
  background-color: var(--bg); 
  color: var(--text); 
  padding: env(safe-area-inset-top, 10px) 8px calc(env(safe-area-inset-bottom, 10px) + 64px) 8px; 
  transition: background-color 0.2s, color 0.2s; 
  user-select: none; 
}

/* ================== Header & Utilities ================== */
header { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  margin-bottom: 8px; 
  flex-wrap: wrap; 
  gap: 6px; 
}

h1 { 
  font-size: 1.15rem; 
  font-weight: 800; 
  color: var(--text); 
  letter-spacing: -0.3px; 
}

.header-actions { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
}

.theme-select { 
  padding: 4px 6px; 
  border: 1px solid var(--border); 
  background: var(--card-bg); 
  color: var(--text); 
  border-radius: 6px; 
  font-size: 0.75rem; 
  font-weight: 600; 
  cursor: pointer; 
  outline: none; 
}

.theme-toggle-btn { 
  padding: 4px 8px; 
  border: 1px solid var(--border); 
  background: var(--card-bg); 
  color: var(--text); 
  border-radius: 6px; 
  cursor: pointer; 
  font-size: 0.75rem; 
  font-weight: 600; 
  display: flex; 
  align-items: center; 
  gap: 4px; 
}

.sync-bar { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  background: var(--card-bg); 
  border: 1px solid var(--border); 
  border-radius: 6px; 
  padding: 5px 10px; 
  margin-bottom: 8px; 
  font-size: 0.75rem; 
}

.sync-status { 
  display: flex; 
  align-items: center; 
  gap: 5px; 
  font-weight: 600; 
}

.status-dot { 
  width: 8px; 
  height: 8px; 
  border-radius: 50%; 
  background: #64748b; 
}

.status-dot.online { 
  background: #22c55e; 
}

/* ================== Navigations ================== */
.week-nav-bar { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  background: var(--card-bg); 
  padding: 6px 10px; 
  border-radius: 8px; 
  border: 1px solid var(--border); 
  margin-bottom: 8px; 
  flex-wrap: wrap; 
  gap: 6px; 
}

.week-nav-btns { display: flex; align-items: center; gap: 4px; }
.week-display { font-weight: 700; font-size: 0.80rem; color: var(--text); }

.control-bar { 
  display: flex; 
  gap: 5px; 
  margin-top: 8px; 
  margin-bottom: 8px; 
  flex-wrap: wrap; 
  align-items: center; 
}

/* ================== Buttons ================== */
.btn { 
  padding: 5px 9px; 
  background: var(--primary); 
  color: #ffffff; 
  border: none; 
  border-radius: 6px; 
  cursor: pointer; 
  font-size: 0.75rem; 
  font-weight: 600; 
  display: inline-flex; 
  align-items: center; 
  justify-content: center; 
  transition: transform 0.1s; 
}

.btn-secondary { background: #64748b; color: #ffffff; }
.btn-warning { background: #f59e0b; color: #ffffff; }
.btn-danger { background: #ef4444; color: #ffffff; }
.btn-edit-mode { border: 2px solid var(--primary); font-weight: 700; }
.btn:active { transform: scale(0.97); }

.checkbox-label { 
  display: flex; 
  align-items: center; 
  gap: 4px; 
  font-size: 0.75rem; 
  font-weight: 600; 
  cursor: pointer; 
  color: var(--text); 
}

/* ================== Deadlines ================== */
.deadline-banner { 
  background: var(--student-stat-bg); 
  border: 1px solid var(--student-stat-border); 
  border-radius: 8px; 
  margin-bottom: 8px; 
  overflow: hidden; 
  transition: background 0.2s, border-color 0.2s; 
}

.deadline-header { 
  padding: 8px 10px; 
  display: flex; 
  justify-content: space-between; 
  align-items: flex-start; 
  cursor: pointer; 
  color: var(--student-stat-text); 
  transition: color 0.2s; 
}

.deadline-list { 
  display: none; 
  padding: 0 10px 8px 10px; 
  border-top: 1px dashed var(--student-stat-border); 
  transition: border-color 0.2s; 
}

.deadline-list.active { display: block; }
.deadline-item { 
  display: flex; 
  justify-content: space-between; 
  font-size: 0.75rem; 
  padding: 4px 0; 
  border-bottom: 1px dashed var(--student-stat-border); 
  color: var(--text); 
  transition: border-color 0.2s, color 0.2s; 
}
.deadline-item:last-child { border-bottom: none; }

/* ================== Timetable ================== */
.timetable-container { 
  width: 100%; 
  overflow-x: auto; 
  background: var(--card-bg); 
  border-radius: 8px; 
  box-shadow: 0 1px 3px rgba(0,0,0,0.06); 
  border: 1px solid var(--border); 
  -webkit-overflow-scrolling: touch; 
}

table { table-layout: fixed; border-collapse: collapse; }
th, td { border: 1px solid var(--border); padding: 0; text-align: center; vertical-align: top; }
th { 
  background: var(--table-th-bg); 
  font-size: 0.72rem; 
  color: var(--text-muted); 
  height: 34px; 
  padding: 2px; 
}

th.today-header { 
  background: var(--today-header-bg); 
  color: var(--today-header-text); 
  border-bottom: 2px solid var(--primary); 
  font-weight: 700; 
}

.col-time { 
  width: 68px; 
  background: var(--card-bg); 
  font-size: 0.62rem; 
  font-weight: 600; 
  vertical-align: middle; 
  padding: 4px 2px; 
  text-align: center; 
}

.table-col-wrapper { position: relative; width: 100%; height: 100%; }
.cell-slot { 
  height: 56px; 
  cursor: pointer; 
  padding: 2px; 
  display: flex; 
  flex-direction: column; 
  justify-content: center; 
  align-items: center; 
  transition: background 0.15s ease; 
  position: relative; 
}
.cell-slot:active { background: var(--slot-hover); }

.align-left { text-align: left !important; align-items: flex-start !important; }
.align-center { text-align: center !important; align-items: center !important; }
.align-right { text-align: right !important; align-items: flex-end !important; }

.slot-item { 
  border-radius: 4px; 
  padding: 3px 4px; 
  font-size: 0.68rem; 
  box-shadow: 0 1px 2px rgba(0,0,0,0.06); 
  border: none; 
  width: 100%; 
  height: 100%; 
  display: flex; 
  flex-direction: column; 
  justify-content: center; 
  line-height: 1.2; 
  position: relative; 
}

.item-title { 
  font-weight: 700; 
  font-size: 0.68rem; 
  white-space: normal; 
  overflow: hidden; 
  display: -webkit-box; 
  -webkit-line-clamp: 2; 
  -webkit-box-orient: vertical; 
  word-break: break-all; 
}

.item-sub { 
  font-size: 0.60rem; 
  opacity: 0.9; 
  margin-top: 1px; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  white-space: nowrap; 
}

.memo-badge { 
  position: absolute; 
  top: 2px; 
  right: 2px; 
  background: #fbbf24; 
  color: #78350f; 
  font-size: 0.55rem; 
  padding: 1px 3px; 
  border-radius: 3px; 
  font-weight: 700; 
  box-shadow: 0 1px 2px rgba(0,0,0,0.15); 
  z-index: 20; 
}

/* ================== Float Cards (Timetable) ================== */
.col-overlay-container { 
  position: absolute; 
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%; 
  pointer-events: none; 
  z-index: 10; 
}

.tutoring-float-card { 
  position: absolute; 
  left: 2px; 
  right: 2px; 
  pointer-events: auto; 
  border-radius: 6px; 
  padding: 3px 4px; 
  cursor: pointer; 
  display: flex; 
  flex-direction: column; 
  justify-content: center; 
  overflow: hidden; 
  z-index: 12; 
  line-height: 1.2; 
}

.tutoring-float-card.is-tutoring, 
.tutoring-float-card.is-work, 
.tutoring-float-card.is-school { 
  border: none; 
  box-shadow: 0 1px 2px rgba(0,0,0,0.06); 
}

.tutoring-float-card.is-override-temp { 
  border: 2px solid var(--primary); 
  border-radius: 6px; 
  box-shadow: 0 3px 8px rgba(0,0,0,0.15), inset 0 0 0 1px var(--card-bg); 
  justify-content: center; 
}

.evening-row td, .noon-row td { 
  background: var(--card-bg); 
  vertical-align: middle; 
}

.noon-cell, .evening-cell { 
  height: 56px; 
  padding: 2px; 
  display: flex; 
  flex-direction: column; 
  justify-content: center; 
  align-items: stretch; 
}

.evening-empty, .noon-empty { font-size: 0.68rem; color: var(--text-muted); text-align: center; }

.evening-card, .noon-card { 
  border-radius: 4px; 
  padding: 3px 4px; 
  cursor: pointer; 
  width: 100%; 
  height: 100%; 
  font-size: 0.68rem; 
  line-height: 1.2; 
  display: flex; 
  flex-direction: column; 
  justify-content: center; 
}

.evening-card.is-tutoring, .evening-card.is-work { 
  border: none; 
  box-shadow: 0 1px 2px rgba(0,0,0,0.06); 
}

.evening-card.is-override-temp, .noon-card { 
  border: 2px solid var(--primary); 
  border-radius: 4px; 
  box-shadow: 0 3px 8px rgba(0,0,0,0.15), inset 0 0 0 1px var(--card-bg); 
  justify-content: center; 
}

.schedule-footer-banner { 
  background: var(--card-bg); 
  border: 1px solid var(--border); 
  border-radius: 8px; 
  padding: 6px 10px; 
  margin-top: 8px; 
  text-align: center; 
  font-size: 0.78rem; 
  font-weight: 700; 
  color: var(--text); 
  cursor: pointer; 
  transition: background 0.2s; 
}

.schedule-footer-banner:hover { background: var(--table-th-bg); }

/* ================== Mobile Bottom Tab ================== */
.mobile-tab-bar { 
  position: fixed; 
  bottom: 0; 
  left: 0; 
  width: 100%; 
  height: calc(env(safe-area-inset-bottom, 0px) + 52px); 
  padding-bottom: env(safe-area-inset-bottom, 0px); 
  background: var(--card-bg); 
  border-top: 1px solid var(--border); 
  display: flex; 
  justify-content: space-around; 
  align-items: center; 
  z-index: 90; 
}

.mobile-tab-item { 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: center; 
  flex: 1; 
  height: 100%; 
  color: var(--text-muted); 
  font-size: 0.72rem; 
  font-weight: 600; 
  cursor: pointer; 
}

.mobile-tab-item.active { color: var(--primary); font-weight: 700; }
.mobile-tab-icon { font-size: 1.15rem; margin-bottom: 1px; position: relative;}
.badge { position: absolute; top: -2px; right: -8px; background: #ef4444; color: white; font-size: 0.55rem; padding: 2px 4px; border-radius: 10px; display: none; }

/* ================== Panels & Filters ================== */
.billing-panel, .personal-finance-panel, .friends-panel { 
  background: var(--card-bg); 
  padding: 12px; 
  border-radius: 8px; 
  border: 1px solid var(--border); 
  display: none; 
}

.billing-type-bar { display: flex; gap: 6px; margin-bottom: 10px; }
.billing-type-btn { 
  padding: 6px 14px; 
  border-radius: 6px; 
  border: 1px solid var(--border); 
  background: var(--table-th-bg); 
  color: var(--text-muted); 
  font-size: 0.78rem; 
  font-weight: 700; 
  cursor: pointer; 
  transition: all 0.2s ease; 
}
.billing-type-btn.active { background: var(--primary); color: #ffffff; border-color: var(--primary); }

.month-filter-bar { 
  display: flex; 
  align-items: center; 
  gap: 6px; 
  background: var(--table-th-bg); 
  padding: 8px 10px; 
  border-radius: 6px; 
  margin-bottom: 10px; 
  flex-wrap: wrap; 
}
.month-filter-bar select, .month-filter-bar input { 
  padding: 4px 6px; 
  border-radius: 4px; 
  border: 1px solid var(--border); 
  font-size: 0.80rem; 
  background: var(--input-bg); 
  color: var(--text); 
}

.student-filter-chips, .finance-filter-chips { 
  display: flex; gap: 5px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; align-items: center; 
}
.student-chip, .finance-chip { 
  padding: 3px 10px; 
  border-radius: 12px; 
  font-size: 0.72rem; 
  font-weight: 600; 
  background: var(--table-th-bg); 
  color: var(--text-muted); 
  border: 1px solid var(--border); 
  cursor: pointer; 
  white-space: nowrap; 
}
.student-chip.active, .finance-chip.active { background: var(--primary); color: #ffffff; border-color: var(--primary); }

/* ================== Stats & Charts ================== */
.stats-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 6px; margin-bottom: 12px; }
.stat-box { 
  background: var(--stat-card-bg); 
  border: 1px solid var(--border); 
  padding: 6px 8px; 
  border-radius: 6px; 
  cursor: pointer; 
  transition: transform 0.1s; 
  text-align: center; 
}
.stat-box:active { transform: scale(0.97); }
.stat-title { font-size: 0.65rem; color: var(--text-muted); margin-bottom: 2px; }
.stat-val { font-size: 0.90rem; font-weight: 700; color: var(--primary); }

.expense-chart-container { 
  display: none; 
  background: var(--stat-card-bg); 
  border: 1px solid var(--border); 
  border-radius: 8px; 
  padding: 12px; 
  margin-bottom: 12px; 
}
.expense-chart-container.active { display: block; }

.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; margin-bottom: 4px; }
.legend-color { width: 10px; height: 10px; border-radius: 50%; }

.student-stats-section { margin-bottom: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.student-stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; margin-top: 6px; }
.student-stat-card { 
  background: var(--student-stat-bg); 
  border: 1px solid var(--student-stat-border); 
  border-radius: 6px; 
  padding: 6px 8px; 
  color: var(--student-stat-text); 
}
.student-stat-name { font-weight: 700; font-size: 0.82rem; margin-bottom: 3px; border-bottom: 1px solid rgba(0,0,0,0.1); padding-bottom: 2px; }
.student-stat-row { display: flex; justify-content: space-between; font-size: 0.72rem; margin-bottom: 2px; }

/* ================== Data Tables ================== */
.billing-table, .finance-table { width: 100%; border-collapse: collapse; margin-top: 8px; min-width: 480px; }
.billing-table th, .billing-table td, .finance-table th, .finance-table td { padding: 5px 6px; border: 1px solid var(--border); font-size: 0.75rem; }

.tag-paid { background: #dcfce7; color: #15803d; padding: 1px 4px; border-radius: 3px; font-size: 0.68rem; font-weight: 600; }
.tag-unpaid { background: #fee2e2; color: #b91c1c; padding: 1px 4px; border-radius: 3px; font-size: 0.68rem; font-weight: 600; }
.tag-income { background: #dcfce7; color: #15803d; padding: 1px 5px; border-radius: 3px; font-size: 0.68rem; font-weight: 600; }
.tag-expense { background: #fee2e2; color: #b91c1c; padding: 1px 5px; border-radius: 3px; font-size: 0.68rem; font-weight: 600; }
.tag-receivable { background: #fef08a; color: #713f12; padding: 1px 5px; border-radius: 3px; font-size: 0.68rem; font-weight: 600; }
.tag-payable { background: #ffedd5; color: #9a3412; padding: 1px 5px; border-radius: 3px; font-size: 0.68rem; font-weight: 600; }
.tag-hidden { background: #e2e8f0; color: #64748b; padding: 1px 4px; border-radius: 3px; font-size: 0.62rem; font-weight: 600; margin-left: 4px; }

.cat-manage-item, .recurring-manage-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 0.78rem; }
.cat-manage-actions { display: flex; gap: 4px; }

/* ================== Modals ================== */
.modal { 
  display: none; 
  position: fixed; 
  top: 0; left: 0; 
  width: 100%; height: 100%; 
  background: rgba(0,0,0,0.6); 
  justify-content: center; 
  align-items: center; 
  z-index: 100; 
  padding: 12px; 
}
.modal.active { display: flex; }
.modal-content { 
  background: var(--modal-bg); 
  color: var(--text); 
  border-radius: 10px; 
  width: 100%; max-width: 440px; 
  max-height: 85vh; 
  overflow-y: auto; 
  padding: 14px; 
  position: relative; 
  border: 1px solid var(--border); 
}
.modal-header { font-size: 0.95rem; font-weight: 700; margin-bottom: 8px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }

.form-group { margin-bottom: 8px; }
.form-group label { display: block; font-size: 0.74rem; font-weight: 600; color: var(--text-muted); margin-bottom: 3px; }
.form-group input, .form-group textarea, .form-group select { 
  width: 100%; 
  padding: 6px 8px; 
  border: 1px solid var(--border); 
  border-radius: 6px; 
  font-size: 0.80rem; 
  background: var(--input-bg); 
  color: var(--text); 
  outline: none; 
}
.form-row { display: flex; gap: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 12px; }

.detail-card { background: var(--table-th-bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.detail-label { font-size: 0.70rem; font-weight: 600; color: var(--text-muted); margin-top: 4px; }
.detail-value { font-size: 0.80rem; color: var(--text); margin-bottom: 2px; word-break: break-all; }

.period-edit-table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 0.75rem; }
.period-edit-table th, .period-edit-table td { padding: 4px 6px; border: 1px solid var(--border); }
.period-edit-table input { padding: 3px; border-radius: 4px; border: 1px solid var(--border); width: 100%; font-size: 0.75rem; background: var(--input-bg); color: var(--text); }

/* ================== Friends Connect & Notifications ================== */
.friend-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.friend-card { background: var(--table-th-bg); border: 1px solid var(--border); padding: 8px 10px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.friend-info { display: flex; flex-direction: column; gap: 2px; }
.friend-name { font-weight: 700; font-size: 0.85rem; color: var(--text); }
.friend-email { font-size: 0.7rem; color: var(--text-muted); }
.msg-card { background: var(--today-header-bg); border: 1px solid var(--primary); padding: 8px 10px; border-radius: 6px; margin-bottom: 8px; font-size: 0.8rem; }
.common-empty { background-color: rgba(34, 197, 94, 0.25) !important; border: 2px dashed #22c55e !important; box-shadow: inset 0 0 5px rgba(34, 197, 94, 0.5); }
.viewing-friend-banner { background: #f59e0b; color: white; font-weight: bold; text-align: center; padding: 6px; border-radius: 8px; margin-bottom: 8px; font-size: 0.85rem; display: flex; justify-content: space-between; align-items: center; }

/* ================== Error Toast Notification (新增) ================== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  z-index: 9999;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
  pointer-events: none;
}
.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}
.toast.error {
  background: #ef4444; /* 紅色警告 */
}
.toast.success {
  background: #10b981; /* 綠色成功 */
}
/* ================== Splash Screen 啟動畫面 (時針狂轉精準版) ================== */
#splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: #0f172a; /* 與時鐘沉穩搭配的深色背景 */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.splash-content {
  text-align: center;
  color: #ffffff;
}

/* 完美對齊的圖示與時鐘容器 (120px) */
.splash-icon-container {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 16px auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 圓形時鐘外框：精準 120px，邊框改為與 icon 一致的 #0284c7 */
.clock {
  position: absolute;
  top: 0;
  left: 0;
  width: 120px;
  height: 120px;
  border: 4px solid #0284c7;
  border-radius: 50%;
  opacity: 0;
  z-index: 2;
  animation: fadeIn 0.3s forwards, clockFadeOnly 0.2s forwards 1.5s;
}

/* 內部時針：長度 45px，在 120px 框內狂轉 */
.hand {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 45px;
  background: white;
  transform-origin: bottom center;
  margin-top: -45px;
  margin-left: -2px;
  animation: spinFast 1.5s cubic-bezier(0.5, 0, 0.5, 1) forwards;
}

/* 圓形百寶袋 Icon：等待時鐘轉完後彈出 */
.splash-icon {
  width: 120px;
  height: 120px;
  position: relative;
  z-index: 1;
  animation: popIn 0.8s forwards 1.5s;
  opacity: 0;
}

.splash-title {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 2px;
  color: #ffffff;
  opacity: 0;
  animation: textSlideUp 0.8s forwards 1.7s;
}

/* 隱藏啟動畫面 */
#splash-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* --- 動畫 Keyframes --- */
@keyframes fadeIn {
  to { opacity: 1; }
}

@keyframes spinFast {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(1440deg); opacity: 0; }
}

/* 時鐘外框原地淡出，絕不向外放大 */
@keyframes clockFadeOnly {
  to { opacity: 0; transform: scale(1); }
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes textSlideUp {
  0% { transform: translateY(20px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}