/* ============================================================
   课表日程 · 移动端样式
   零依赖，light / dark 随系统
   ============================================================ */

:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f2f2ef;
  --text: #16181c;
  --text-2: #666a72;
  --text-3: #9aa0a8;
  --line: rgba(0, 0, 0, 0.085);
  --line-strong: rgba(0, 0, 0, 0.16);
  --accent: #2f6fed;
  --danger: #d64545;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 -2px 24px rgba(0, 0, 0, 0.10);
  --hairline: 0.5px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --surface: #1d1d21;
    --surface-2: #26262b;
    --text: #ececf0;
    --text-2: #a0a0a8;
    --text-3: #6e6e78;
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.18);
    --accent: #6aa2ff;
    --danger: #ff6b6b;
    --shadow: 0 -2px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
}

button { border: none; background: none; padding: 0; cursor: pointer; }

/* ============ 框架 ============ */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
  max-width: 100vw;
}

@supports (height: 100dvh) {
  .app { height: 100dvh; }
}

/* ============ 顶栏 ============ */

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 6px;
  background: var(--bg);
  border-bottom: var(--hairline) solid var(--line);
  flex: 0 0 auto;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  border-radius: 50%;
  flex: 0 0 auto;
  transition: background 0.15s;
}
.icon-btn:active { background: var(--surface-2); }

.title-wrap {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
}

.title-wrap h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title-sub {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
  min-height: 14px;
}

/* ============ 分类筛选条 ============ */

.filterbar {
  display: flex;
  gap: 5px;
  padding: 8px 10px;
  overflow-x: auto;
  flex: 0 0 auto;
  scrollbar-width: none;
  border-bottom: var(--hairline) solid var(--line);
  -webkit-overflow-scrolling: touch;
}
.filterbar::-webkit-scrollbar { display: none; }

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  border-radius: 100px;
  font-size: 11.5px;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text-2);
  border: var(--hairline) solid transparent;
  flex: 0 0 auto;
  transition: opacity 0.15s;
}
.filter-chip .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.filter-chip.is-off { opacity: 0.38; }
.filter-chip.all { color: var(--text-2); }

/* ============ 视图容器 ============ */

.views {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.view {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}
.view.is-active { display: block; }
#view-month.is-active {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============ 月视图 ============ */

.month-head {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 6px 6px 4px;
  font-size: 11px;
  color: var(--text-3);
  text-align: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
  flex: 0 0 auto;
}
.month-head span.weekend { color: var(--text-3); }

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 1px;
  padding: 0 6px 8px;
  flex: 1 1 auto;
  min-height: 0;
}

.month-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 3px 2px 2px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  background: transparent;
}
.month-cell.is-out { opacity: 0.34; }
.month-cell.is-today .day-num {
  background: var(--accent);
  color: #fff;
}
.month-cell.is-selected:not(.is-today) { background: var(--surface-2); }

.day-num {
  font-size: 13px;
  font-weight: 500;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  border-radius: 50%;
  margin-bottom: 1px;
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.cell-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  min-width: 0;
}

.mini-event {
  font-size: 10px;
  line-height: 1.25;
  padding: 1px 3px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid;
  background: var(--surface-2);
  min-width: 0;
}

.cell-more {
  font-size: 9px;
  color: var(--text-3);
  padding-left: 4px;
}

/* ============ 周视图 ============ */

.week-sticky {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg);
  padding-top: 2px;
}

.week-daybar {
  display: grid;
  grid-template-columns: 38px repeat(7, minmax(0, 1fr));
  padding: 4px 4px 6px;
  border-bottom: var(--hairline) solid var(--line);
}

.wd-cell {
  text-align: center;
  padding: 3px 0 4px;
  border-radius: 8px;
  min-width: 0;
}
.wd-cell .wd-name {
  font-size: 10px;
  color: var(--text-3);
  display: block;
}
.wd-cell .wd-num {
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  display: inline-block;
  min-width: 24px;
  height: 24px;
  line-height: 24px;
  border-radius: 50%;
  margin-top: 1px;
}
.wd-cell.is-today .wd-num { background: var(--accent); color: #fff; }
.wd-cell.is-today .wd-name { color: var(--accent); }
.wd-cell.is-active:not(.is-today) .wd-num { color: var(--accent); font-weight: 700; }

.week-scroll {
  position: relative;
  padding-bottom: 40px;
}

.week-canvas {
  position: relative;
  display: grid;
  grid-template-columns: 38px repeat(7, minmax(0, 1fr));
  padding: 0 4px;
}

.hour-col {
  position: relative;
}
.hour-label {
  position: absolute;
  right: 4px;
  font-size: 9px;
  color: var(--text-3);
  transform: translateY(-50%);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.hour-label:first-child { transform: translateY(1px); }

.day-col {
  position: relative;
  border-left: var(--hairline) solid var(--line);
}
.day-col .hour-line {
  position: absolute;
  left: 0; right: 0;
  height: var(--hairline);
  background: var(--line);
}

.week-event {
  position: absolute;
  left: 1px;
  right: 1px;
  border-radius: 5px;
  padding: 2px 3px;
  font-size: 9.5px;
  line-height: 1.15;
  overflow: hidden;
  color: #fff;
  border-left: 2px solid rgba(0, 0, 0, 0.22);
}

.week-event .we-title {
  font-weight: 600;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.now-line {
  position: absolute;
  left: 38px;
  right: 4px;
  height: 1.5px;
  background: var(--danger);
  z-index: 4;
  pointer-events: none;
}
.now-line::before {
  content: "";
  position: absolute;
  left: -3px;
  top: -2.5px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--danger);
}

/* 全天后置顶条 */
.allday-row {
  display: grid;
  grid-template-columns: 38px repeat(7, minmax(0, 1fr));
  padding: 3px 4px 5px;
  gap: 2px;
  border-bottom: var(--hairline) solid var(--line);
}
.allday-row .ad-label {
  font-size: 9px;
  color: var(--text-3);
  text-align: right;
  padding-right: 4px;
  line-height: 16px;
}
.ad-item {
  font-size: 9.5px;
  line-height: 16px;
  padding: 0 3px;
  border-radius: 4px;
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ============ 日视图 ============ */

.day-wrap { padding: 8px 12px 80px; }

.day-hero {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 4px 2px 12px;
}
.day-hero .big {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
}
.day-hero .meta { font-size: 12px; color: var(--text-3); }

.day-empty {
  padding: 40px 0;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

.day-event {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 8px;
  border-left: 3px solid;
  align-items: flex-start;
}
.day-event .de-time {
  font-size: 10.5px;
  color: var(--text-3);
  width: 40px;
  flex: 0 0 auto;
  padding-top: 2px;
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  line-height: 1.4;
}
.day-event .de-main { flex: 1 1 auto; min-width: 0; }
.day-event .de-title {
  font-size: 14.5px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.day-event .de-sub {
  font-size: 11.5px;
  color: var(--text-2);
  margin-top: 2px;
  overflow-wrap: anywhere;
}
.day-event.is-done .de-title { text-decoration: line-through; color: var(--text-3); }
.day-event .de-bell { font-size: 11px; color: var(--text-3); flex: 0 0 auto; }

/* ============ 清单视图 ============ */

.list-wrap { padding: 8px 12px 80px; }

.list-group-title {
  font-size: 11px;
  color: var(--text-3);
  padding: 14px 4px 6px;
  font-weight: 500;
  letter-spacing: 0.4px;
}
.list-group-title:first-child { padding-top: 4px; }

.list-more {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  padding: 14px 0 4px;
}

.countdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 7px;
}
.countdown-item .ci-bar {
  width: 3px;
  align-self: stretch;
  border-radius: 2px;
  flex: 0 0 auto;
}
.countdown-item .ci-main { flex: 1 1 auto; min-width: 0; }
.countdown-item .ci-title { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.countdown-item .ci-sub { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }
.countdown-item .ci-days {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}
.countdown-item .ci-days.urgent { color: var(--danger); }
.countdown-item .ci-days.past { color: var(--text-3); }

/* ============ 悬浮按钮 / 底栏 ============ */

.fab {
  position: absolute;
  right: 16px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(47, 111, 237, 0.34);
  z-index: 20;
  transition: transform 0.12s;
}
.fab:active { transform: scale(0.93); }

.tabbar {
  display: flex;
  flex: 0 0 auto;
  border-top: var(--hairline) solid var(--line);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
  width: 100%;
  min-width: 0;
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  height: 50px;
  font-size: 13px;
  color: var(--text-3);
  position: relative;
}
.tab.is-active { color: var(--accent); font-weight: 600; }

/* ============ 抽屉 ============ */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s;
  z-index: 40;
}
.scrim.is-open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 88dvh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  transform: translateY(102%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.is-open { transform: translateY(0); }

.sheet-grab {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
  margin: 8px auto 0;
  flex: 0 0 auto;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  flex: 0 0 auto;
  border-bottom: var(--hairline) solid var(--line);
}
.sheet-title { font-size: 15px; font-weight: 600; }

.text-btn {
  font-size: 15px;
  color: var(--text-2);
  padding: 8px 6px;
  min-width: 44px;
  text-align: left;
}
.text-btn.strong { color: var(--accent); font-weight: 600; text-align: right; }

.sheet-body {
  padding: 12px 16px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
}

.sheet-foot { padding: 0 16px 12px; flex: 0 0 auto; }

.field-title {
  width: 100%;
  border: none;
  border-bottom: var(--hairline) solid var(--line);
  background: transparent;
  padding: 8px 2px 10px;
  font-size: 19px;
  font-weight: 500;
  border-radius: 0;
  outline: none;
}
.field-title::placeholder { color: var(--text-3); font-weight: 400; }

.field {
  padding: 12px 0;
  border-bottom: var(--hairline) solid var(--line);
}
.field-label {
  font-size: 12px;
  color: var(--text-3);
  margin-bottom: 7px;
}

.field input[type="text"],
.field input[type="date"],
.field input[type="time"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  border: var(--hairline) solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 9px 10px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.field textarea { resize: none; line-height: 1.5; }
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
                    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 18px, calc(100% - 10px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-inline > * { flex: 1 1 0; min-width: 0; }
.field-inline .dash { flex: 0 0 auto; color: var(--text-3); font-size: 13px; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
  flex: 0 0 auto;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 9px;
  border: var(--hairline) solid var(--line-strong);
}
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }

/* chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips-week { gap: 5px; }

.chip {
  padding: 7px 12px;
  border-radius: 100px;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1.5px solid transparent;
  transition: all 0.14s;
}
.chip.is-on { color: #fff; font-weight: 500; }

.chips-week .chip { padding: 8px 0; width: 38px; text-align: center; font-size: 13px; }

.hint {
  font-size: 11.5px;
  color: var(--text-3);
  line-height: 1.6;
  margin: 8px 0 0;
}
.hint.center { text-align: center; }

.btn-danger {
  width: 100%;
  padding: 13px;
  border-radius: var(--radius);
  background: rgba(214, 69, 69, 0.1);
  color: var(--danger);
  font-size: 15px;
  font-weight: 500;
}

/* 设置面板 */
.group { margin-bottom: 22px; }
.group-title {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  padding-left: 2px;
}

.row-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 13px 12px;
  background: var(--surface-2);
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 14.5px;
  text-align: left;
}
.row-btn-val { font-size: 12.5px; color: var(--text-3); flex: 0 0 auto; margin-left: 8px; }
.row-btn.danger-text { color: var(--danger); }

.cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
  margin-bottom: 6px;
}
.cat-row .cat-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.cat-row .cat-name { flex: 1 1 auto; font-size: 14px; }
.cat-row input[type="color"] {
  width: 30px; height: 26px;
  border: none;
  background: none;
  padding: 0;
  flex: 0 0 auto;
}
.cat-row .cat-del { color: var(--text-3); font-size: 18px; padding: 0 4px; }

/* ============ 提醒卡片 ============ */

.reminder-host {
  position: fixed;
  left: 10px; right: 10px;
  top: calc(8px + env(safe-area-inset-top));
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.reminder-card {
  pointer-events: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 11px 13px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.18);
  border-left: 3px solid var(--accent);
  animation: slideIn 0.26s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes slideIn {
  from { transform: translateY(-14px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.reminder-card .rc-main { flex: 1 1 auto; min-width: 0; }
.reminder-card .rc-title { font-size: 14px; font-weight: 600; }
.reminder-card .rc-sub { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }
.reminder-card .rc-x {
  font-size: 18px;
  color: var(--text-3);
  padding: 4px 6px;
  flex: 0 0 auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: rgba(28, 28, 32, 0.93);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 100px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s;
  z-index: 95;
  max-width: 82vw;
  text-align: center;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ============ 空状态 ============ */

.empty-block {
  padding: 56px 24px;
  text-align: center;
}
.empty-block .eb-title {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 6px;
}
.empty-block .eb-desc {
  font-size: 13px;
  color: var(--text-3);
  line-height: 1.6;
}
