/* 动态课程表 · 移动优先样式 */

:root {
  --bg: #f4f5fa;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #7a8194;
  --line: #e7e9f2;
  --primary: #4f6ef7;
  --primary-deep: #3b55d9;
  --primary-soft: #e8eeff;
  --danger: #e5484d;
  --danger-soft: #fdebec;
  --ok: #2e9e5b;
  --shadow: 0 1px 3px rgba(24, 32, 62, 0.06), 0 4px 16px rgba(24, 32, 62, 0.05);
  --radius: 16px;
  --tabbar-h: 58px;

  /* 课程配色（柔和底 + 深字） */
  --c0-bg: #e8eeff; --c0-fg: #3454d1;
  --c1-bg: #e3f6ec; --c1-fg: #1e7a4b;
  --c2-bg: #fff0e0; --c2-fg: #a35a10;
  --c3-bg: #f1e8ff; --c3-fg: #6d3fc4;
  --c4-bg: #ffe9ef; --c4-fg: #bb3f68;
  --c5-bg: #e0f6f6; --c5-fg: #0e7a7a;
  --c6-bg: #fdf6d8; --c6-fg: #8a6d1a;
  --c7-bg: #e8edf2; --c7-fg: #47617a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161d;
    --card: #1e212b;
    --text: #e8eaf2;
    --muted: #8b91a5;
    --line: #2a2e3c;
    --primary: #6d8bff;
    --primary-deep: #5470f0;
    --primary-soft: #232c4d;
    --danger: #ff6369;
    --danger-soft: #3d2224;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);

    --c0-bg: #26304f; --c0-fg: #a9c0ff;
    --c1-bg: #1c3529; --c1-fg: #8fd8ae;
    --c2-bg: #3a2c1a; --c2-fg: #ffce93;
    --c3-bg: #302547; --c3-fg: #cdb4ff;
    --c4-bg: #3c2230; --c4-fg: #ffa8c2;
    --c5-bg: #1a3232; --c5-fg: #93dcdd;
    --c6-bg: #363020; --c6-fg: #ecd98a;
    --c7-bg: #262c38; --c7-fg: #b3c2d4;
  }
}

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

html { font-size: 16px; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100dvh;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 28px);
}

.boot-splash { text-align: center; padding: 30vh 0 0; color: var(--muted); }
.boot-logo { font-size: 44px; }

h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 10px; color: var(--text); }
h3, h4 { margin: 14px 0 6px; }
h3 { font-size: 1.02rem; }
h4 { font-size: 0.95rem; }

/* ---------- 页头 ---------- */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 2px 14px;
}
.page-head .sub { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.week-nav { display: flex; gap: 6px; }

/* ---------- 卡片 ---------- */

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-highlight { outline: 2px solid var(--primary-soft); }
.hint-card { text-align: center; color: var(--muted); }

.hint { color: var(--muted); font-size: 0.8rem; margin: 8px 0 0; }
.hint b { color: var(--text); }
.example {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.78rem;
  overflow-x: auto;
  white-space: pre;
  margin: 8px 0;
}

/* ---------- 状态卡（今日页） ---------- */

.status-card { text-align: center; padding: 20px 16px; }
.status-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg);
  border-radius: 999px;
  padding: 3px 12px;
  margin-bottom: 8px;
}
.status-label.now { color: var(--ok); }
.status-label.next { color: var(--primary); }
.status-course { font-size: 1.45rem; font-weight: 700; margin: 2px 0; }
.status-meta { color: var(--muted); font-size: 0.88rem; }
.tm-preview { margin-top: 10px; text-align: left; }
.tm-preview ul { margin: 6px 0 0; padding-left: 0; list-style: none; }
.tm-preview li { font-size: 0.85rem; padding: 2px 0; }

/* ---------- 快捷操作 ---------- */

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
  transition: opacity 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--card); border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; margin-top: 10px; }
.btn-sm { padding: 5px 12px; font-size: 0.78rem; border-radius: 9px; }
.btn-icon { padding: 8px; border-radius: 10px; background: var(--card); border-color: var(--line); }
.btn-row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.btn-row .btn { flex: 1; }

/* ---------- 今日时间线 ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 8px;
  border-radius: 12px;
  margin-bottom: 4px;
}
.tl-item.tl-now { background: var(--primary-soft); }
.tl-item.tl-past { opacity: 0.45; }
.tl-time { font-size: 0.9rem; font-weight: 700; }
.tl-time span { display: block; font-size: 0.72rem; font-weight: 400; color: var(--muted); }
.tl-course { font-weight: 600; padding: 3px 10px; border-radius: 8px; font-size: 0.9rem; }
.tl-room { text-align: right; font-size: 0.82rem; color: var(--muted); }
.tl-room span { display: block; font-size: 0.72rem; }
.tl-empty { text-align: center; color: var(--muted); padding: 14px 0; }

.c0 { background: var(--c0-bg); color: var(--c0-fg); }
.c1 { background: var(--c1-bg); color: var(--c1-fg); }
.c2 { background: var(--c2-bg); color: var(--c2-fg); }
.c3 { background: var(--c3-bg); color: var(--c3-fg); }
.c4 { background: var(--c4-bg); color: var(--c4-fg); }
.c5 { background: var(--c5-bg); color: var(--c5-fg); }
.c6 { background: var(--c6-bg); color: var(--c6-fg); }
.c7 { background: var(--c7-bg); color: var(--c7-fg); }

/* ---------- 迷你笔记列表 ---------- */

.mini-notes { list-style: none; margin: 0; padding: 0; }
.mini-notes li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--line);
}
.mini-notes li:last-child { border-bottom: none; }
.mn-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
.mn-imgs { color: var(--muted); font-size: 0.78rem; display: inline-flex; gap: 3px; align-items: center; }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- 课表网格 ---------- */

.sched-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.sched-grid {
  display: grid;
  grid-template-columns: 52px repeat(7, minmax(56px, 1fr));
  gap: 3px;
  min-width: 480px;
}
.sg-head {
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 0;
}
.sg-head.sg-today { color: var(--primary); }
.sg-corner { font-size: 0.7rem; }
.sg-period {
  font-size: 0.72rem;
  text-align: center;
  color: var(--muted);
  padding: 8px 0;
  line-height: 1.25;
}
.sg-period span { display: block; font-size: 0.62rem; opacity: 0.75; }
.sg-cell {
  border-radius: 10px;
  padding: 6px 4px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  font-size: 0.72rem;
  line-height: 1.3;
}
.sg-cell.sg-empty { background: var(--bg); opacity: 0.5; }
.sg-cell .sg-course { font-weight: 700; word-break: break-all; }
.sg-cell .sg-room { font-size: 0.64rem; opacity: 0.85; margin-top: 2px; }
.sg-cell.sg-cont { opacity: 0.7; min-height: 20px; }
.cont-mark { font-size: 0.8rem; }

/* ---------- 表单 ---------- */

.form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; align-items: center; gap: 12px; }
.form-row.column { flex-direction: column; align-items: stretch; gap: 6px; }
.form-row > label { width: 96px; flex-shrink: 0; font-size: 0.85rem; color: var(--muted); }
.form-row.column > label { width: auto; }
.form-row input:not([type="checkbox"]):not([type="file"]),
.form-row select,
.form-row textarea {
  flex: 1;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.92rem;
  font-family: inherit;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}
.switch-row { justify-content: space-between; }
.switch-row > label { width: auto; color: var(--text); }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
.inline-selects { display: flex; align-items: center; gap: 8px; flex: 1; }
.inline-selects input, .inline-selects select { flex: 1; min-width: 0; }

textarea#paste-area, .textarea-wrap textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  font-size: 0.92rem;
  font-family: inherit;
  resize: vertical;
}
.textarea-wrap { position: relative; }
.textarea-wrap textarea { padding-right: 64px; }
.mic-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.78rem;
  background: var(--card);
}
.mic-btn.rec {
  background: var(--danger);
  color: #fff;
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(229, 72, 77, 0); }
}

/* ---------- 导入 ---------- */

.import-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 8px; }
.import-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 6px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}
.import-btn svg { width: 24px; height: 24px; color: var(--primary); }
.ocr-status {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary-deep, var(--primary));
  font-size: 0.85rem;
}

/* ---------- 导入预览 ---------- */

.pv-head, .pv-row {
  display: grid;
  grid-template-columns: 58px 52px 1fr 74px 64px 28px;
  gap: 5px;
  align-items: center;
  margin-bottom: 6px;
}
.pv-head { font-size: 0.7rem; color: var(--muted); }
.pv-row input, .pv-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  padding: 7px 6px;
  font-size: 0.8rem;
}
.pv-del {
  border: none;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}

/* ---------- 设置：节次编辑 ---------- */

.period-head, .period-row {
  display: grid;
  grid-template-columns: 62px 64px 8px 64px 62px 30px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.period-head { font-size: 0.7rem; color: var(--muted); }
.period-row input, .period-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  padding: 7px 6px;
  font-size: 0.8rem;
}
.pr-del {
  border: none;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
}

/* ---------- 笔记列表 ---------- */

.note-list { list-style: none; margin: 0; padding: 0; }
.note-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.note-item:last-child { border-bottom: none; }
.note-main { flex: 1; min-width: 0; }
.note-top { display: flex; align-items: center; gap: 8px; }
.note-period, .note-time { font-size: 0.72rem; color: var(--muted); }
.note-time { margin-left: auto; }
.note-text {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
}

.fab {
  position: fixed;
  right: max(16px, calc(50vw - 304px));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 18px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(79, 110, 247, 0.45);
  cursor: pointer;
  z-index: 40;
}
.fab:active { transform: scale(0.94); }

/* ---------- 笔记详情 / 编辑 ---------- */

.detail-text { white-space: pre-wrap; font-size: 0.95rem; }
.detail-imgs { display: grid; gap: 10px; margin: 12px 0; }
.detail-imgs img { width: 100%; border-radius: 12px; }
.ocr-details summary { cursor: pointer; color: var(--primary); font-size: 0.85rem; }
.ocr-details pre {
  background: var(--bg);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
}

.photo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.photo-cell { position: relative; aspect-ratio: 1; }
.photo-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}
.photo-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.photo-actions { display: flex; gap: 10px; }

/* ---------- 总结 / Markdown ---------- */

.md-content { font-size: 0.9rem; }
.md-content p { margin: 6px 0; }
.md-content ul { margin: 6px 0; padding-left: 20px; }
.md-content li { margin: 3px 0; }
.md-content blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--primary);
  background: var(--primary-soft);
  border-radius: 0 10px 10px 0;
  font-size: 0.85rem;
}
.md-content .md-tasks { list-style: none; padding-left: 2px; }
.md-content .md-tasks li { display: flex; gap: 6px; align-items: baseline; }
.md-content .md-tasks li.done { opacity: 0.5; text-decoration: line-through; }
.task-box { flex-shrink: 0; }
.gen-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.75rem;
  margin: 10px 0 2px;
}

.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 0.88rem;
}
.history-list li:last-child { border-bottom: none; }
.hl-title { font-weight: 600; }
.hl-date, .hl-via { color: var(--muted); font-size: 0.78rem; }
.hl-via { margin-left: auto; }

/* ---------- 底部 Tab ---------- */

#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
}
#tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.68rem;
  padding: 4px 0;
  cursor: pointer;
}
#tabbar button.active { color: var(--primary); font-weight: 700; }

/* ---------- Sheet 底部弹层 ---------- */

.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 18, 30, 0.5);
  opacity: 0;
  transition: opacity 0.2s;
}
.sheet-wrap.open .sheet-mask { opacity: 1; }
.sheet {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 88dvh;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.22s ease-out;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.2);
}
.sheet-wrap.open .sheet { transform: translateY(0); }
.sheet-full { height: 92dvh; }
.sheet-header {
  display: flex;
  align-items: center;
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sheet-title { flex: 1; text-align: center; font-weight: 700; font-size: 0.98rem; }
.sheet-close {
  border: none;
  background: var(--bg);
  color: var(--muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sheet-header-spacer { width: 30px; }
.sheet-body {
  overflow-y: auto;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

/* ---------- 确认对话框 ---------- */

.confirm-wrap {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.confirm-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 18, 30, 0.5);
  opacity: 0;
  transition: opacity 0.18s;
}
.confirm-wrap.open .confirm-mask { opacity: 1; }
.confirm-box {
  position: relative;
  background: var(--card);
  border-radius: 16px;
  padding: 20px 18px 16px;
  width: 100%;
  max-width: 340px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.3);
  transform: scale(0.92);
  opacity: 0;
  transition: transform 0.18s, opacity 0.18s;
}
.confirm-wrap.open .confirm-box { transform: scale(1); opacity: 1; }
.confirm-msg { font-size: 0.95rem; margin: 0 0 4px; }

/* ---------- Toast ---------- */

#toast-root {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 20px);
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 60;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}
#toast-root.show { opacity: 1; transform: translateY(0); }
.toast {
  background: rgba(28, 32, 45, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.84rem;
  max-width: 86vw;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.toast-error { background: rgba(190, 45, 48, 0.95); }

/* ---------- 桌面适配 ---------- */

@media (min-width: 680px) {
  #app { padding-top: 28px; }
}
