/* ============================================================
   应用布局与组件样式
   ============================================================ */

/* ---------- 头部 ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.app-header-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- 主内容区 ---------- */
.app-main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 12px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
}

.page {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page[hidden] {
  display: none;
}

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  display: flex;
}

.tabbar .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-3);
  font-size: 0.6875rem;
  transition: color 0.15s;
}

.tabbar .tab .icon {
  width: 22px;
  height: 22px;
}

.tabbar .tab.active {
  color: var(--brand-ink);
  font-weight: 600;
}

@media (min-width: 768px) {
  .tabbar {
    left: 50%;
    transform: translateX(-50%);
    width: var(--content-max);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
  }
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-l);
  padding: 16px;
  box-shadow: var(--shadow-s);
}

.card + .card {
  margin-top: 0;
}

.card-title {
  font-size: 0.9375rem;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title .hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--ink-3);
}

/* 区块标题：真正的标题排版（不用大写小号 kicker） */
.section-label {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--ink);
  margin: 8px 4px 2px;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-m);
  font-weight: 600;
  font-size: 0.9375rem;
  transition: transform 0.1s, filter 0.15s;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:active {
  filter: brightness(0.92);
}

.btn-soft {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--ink-2);
}

.btn-danger {
  background: var(--critical-soft);
  color: var(--critical-ink);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8125rem;
  border-radius: var(--radius-s);
}

.btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--ink-2);
}

/* 用伪元素扩大热区到 48px，保证移动端触控目标 */
.icon-btn::after {
  content: "";
  position: absolute;
  inset: -6px;
}

.icon-btn:active {
  background: var(--surface-2);
}

/* ---------- 浮动操作按钮 ---------- */
.fab {
  position: fixed;
  right: max(16px, calc(50vw - var(--content-max) / 2 + 16px));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  z-index: 35;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-m);
}

.fab .icon {
  width: 24px;
  height: 24px;
}

.fab:active {
  transform: scale(0.94);
}

/* ---------- 分段控件 ---------- */
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-m);
  padding: 3px;
  gap: 3px;
}

.seg button {
  flex: 1;
  padding: 7px 0;
  border-radius: calc(var(--radius-m) - 3px);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink-2);
  transition: background 0.15s, color 0.15s;
}

.seg button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-s);
}

/* ---------- 徽章与标签 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.6;
}

.badge-L { background: var(--L-soft); color: var(--L-ink); }
.badge-R { background: var(--R-soft); color: var(--R-ink); }
.badge-W { background: var(--W-soft); color: var(--W-ink); }
.badge-S { background: var(--S-soft); color: var(--S-ink); }
.badge-good { background: var(--good-soft); color: var(--good-ink); }
.badge-warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge-critical { background: var(--critical-soft); color: var(--critical-ink); }
.badge-mute { background: var(--surface-2); color: var(--ink-3); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.8125rem;
}

.chip.active {
  border-color: var(--brand);
  color: var(--brand-ink);
  background: var(--brand-soft);
}

/* ---------- KPI 瓦片 ---------- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 10px 8px;
  text-align: center;
}

.kpi .kpi-num {
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-num);
}

.kpi .kpi-label {
  font-size: 0.6875rem;
  color: var(--ink-3);
  margin-top: 2px;
}

/* ---------- 列表 ---------- */
.list {
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--line);
}

.list-item:last-child {
  border-bottom: 0;
}

.list-item .grow {
  flex: 1;
  min-width: 0;
}

.list-item .title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item .sub {
  font-size: 0.8125rem;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 开关 ---------- */
.switch {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--line);
  transition: background 0.2s;
  flex: none;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: left 0.2s;
}

.switch.on {
  background: var(--brand);
}

.switch.on::after {
  left: 21px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---------- 表单 ---------- */
.field {
  margin-bottom: 14px;
}

.search-wrap {
  position: relative;
}

.search-wrap .input {
  padding-left: 36px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  display: flex;
  pointer-events: none;
}

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}

.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface);
  color: var(--ink);
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--brand);
  outline: 2px solid var(--brand-soft);
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.select {
  appearance: auto;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ---------- 空状态 ---------- */
.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--ink-3);
}

.empty .icon {
  width: 40px;
  height: 40px;
  stroke-width: 1.5;
  margin-bottom: 10px;
}

.empty p {
  font-size: 0.875rem;
  margin-bottom: 14px;
}

/* ---------- 弹层 Sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.45);
  animation: fade-in 0.2s ease;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 51;
  width: min(100%, var(--content-max));
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-l);
  animation: slide-up 0.24s cubic-bezier(0.2, 0.9, 0.3, 1);
  overscroll-behavior: contain;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 6px auto 12px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-title {
  font-size: 1.0625rem;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.sheet-actions .btn {
  flex: 1;
}

/* ---------- 确认对话框 ---------- */
.dialog {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.5);
  animation: fade-in 0.18s ease;
}

.dialog-box {
  width: min(100%, 320px);
  background: var(--surface);
  border-radius: var(--radius-l);
  padding: 20px;
  box-shadow: var(--shadow-l);
  animation: pop-in 0.2s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.dialog-box h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.dialog-box p {
  font-size: 0.875rem;
  color: var(--ink-2);
  margin-bottom: 18px;
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(90vw, var(--content-max));
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: var(--page);
  padding: 10px 16px;
  border-radius: var(--radius-m);
  font-size: 0.875rem;
  text-align: center;
  box-shadow: var(--shadow-m);
  animation: toast-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.toast.leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.ok { background: var(--good-ink); color: #fff; }
.toast.warn { background: var(--warn); color: #3d2c00; }
.toast.error { background: var(--critical); color: #fff; }

/* ---------- 动画 ---------- */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { transform: translate(-50%, 100%); }
  to { transform: translate(-50%, 0); }
}

@keyframes pop-in {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- 首页 Hero ---------- */
.hero-days {
  font-size: 2.3rem;
  font-weight: 700;
  line-height: 1.15;
  font-family: var(--font-num);
}

.hero-unit {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-3);
  margin-left: 4px;
}

.hero-target {
  text-align: right;
}

.hero-score {
  font-size: 2.3rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--brand-ink);
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
  max-width: 150px;
  margin-top: 6px;
}

/* ---------- 任务行 ---------- */
.check-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--line);
  color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.check-btn .icon {
  width: 17px;
  height: 17px;
  stroke-width: 3;
}

.check-btn.on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.list-item .title.done {
  text-decoration: line-through;
  color: var(--ink-3);
}

/* ---------- 模考分数 ---------- */
.mock-band {
  font-size: 1.35rem;
  font-weight: 700;
  font-family: var(--font-num);
  color: var(--ink);
}

/* ---------- 测验 ---------- */
.quiz-word {
  font-size: 1.7rem;
  font-weight: 700;
  text-align: center;
  margin: 4px 0 14px;
  font-family: var(--font-num);
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface);
  font-size: 0.9375rem;
  transition: border-color 0.15s, background 0.15s;
}

.quiz-opt:active {
  transform: scale(0.98);
}

.quiz-opt .qkey {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink-2);
  flex: none;
}

.quiz-opt.correct {
  border-color: var(--good);
  background: var(--good-soft);
}

.quiz-opt.correct .qkey {
  background: var(--good-ink);
  color: #fff;
}

.quiz-opt.wrong {
  border-color: var(--critical);
  background: var(--critical-soft);
}

.quiz-opt.wrong .qkey {
  background: var(--critical-ink);
  color: #fff;
}

.quiz-opt.dim {
  opacity: 0.55;
}

/* ---------- KPI 补充 ---------- */
.kpi .progress-bar {
  margin-top: 6px;
}

.kpi-total {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-3);
}

/* ---------- 其他通用 ---------- */
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.grow { flex: 1; min-width: 0; }

.text-mute { color: var(--ink-3); font-size: 0.8125rem; }

.banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-m);
  font-size: 0.8125rem;
  background: var(--warn-soft);
  color: var(--warn-ink);
}

.banner .icon { width: 18px; height: 18px; flex: none; margin-top: 2px; }

.progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar > span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: var(--brand);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.3s ease;
}

.mono { font-family: var(--font-num); }

.article-body {
  line-height: 1.75;
  font-size: 0.9375rem;
  white-space: pre-wrap;
  word-break: break-word;
}
