/* ==========================================================================
   学习记录小助手 - 外壳样式（移动端优先 + 电脑端增强）
   与 assets/pages.css 分工：
     - 本文件：设计令牌、外壳（topbar / content / tabbar / sidebar）、通用组件
     - pages.css：各业务页面专用样式（英语单元、听力、测一测、积分、后台等）
   本文件在 pages.css 之后加载，同名通用组件以本文件为准。
   ========================================================================== */

/* ---------- 设计令牌 ---------- */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f0f1f4;
  --text: #1a1c1f;
  --text-2: #6b7280;
  --border: #e3e5e9;
  --primary: #0b5ed7;
  --primary-text: #ffffff;
  --danger: #dc3545;
  --success: #16a34a;
  --warn: #d97706;
  --radius: 12px;
  --tabbar-h: 56px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--primary); text-decoration: none; }

/* 兼容旧页面里用到的 .container 包裹层 */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 12px;
}

/* ---------- 三段式布局：topbar / content / tabbar ---------- */
.content {
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 12px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}
.content.no-tabbar { padding-bottom: 24px; }
.content.login-content { max-width: 1100px; padding-bottom: 24px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 600; }
.topbar .brand-logo { width: 26px; height: 26px; border-radius: 7px; flex: 0 0 auto; object-fit: contain; }
.topbar .back {
  font-size: 22px;
  line-height: 1;
  min-width: 44px;
  justify-content: center;
  color: var(--text);
}
.topbar a { display: inline-flex; align-items: center; justify-content: center; }
.topbar .btn { min-height: 36px; padding: 0 12px; font-size: 14px; }
.topbar .topbar-icon-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 10px;
  color: var(--text);
  flex: 0 0 auto;
}
.topbar .topbar-icon-btn svg { width: 22px; height: 22px; display: block; }
.topbar .topbar-icon-btn:active { background: var(--border); }

/* ---------- 底部 Tab ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-2);
}
.tabbar a .ico { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--primary); }
.tabbar a .ico,
.sidebar .nav-item .ico { display: flex; align-items: center; justify-content: center; }
.tabbar a .ico svg,
.sidebar .nav-item .ico svg { display: block; }
.tabbar a .ico svg { width: 20px; height: 20px; }

/* 桌面端外壳默认全部收起，只在 >=1024px 展开 */
.sidebar { display: none; }
.topbar .t-desktop { display: none; }

/* ---------- 电脑端外壳（>=1024px） ---------- */
@media (min-width: 1024px) {
  :root { --sidebar-w: 220px; }

  .tabbar { display: none; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: var(--sidebar-w);
    padding: 14px 12px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  .sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 16px;
    font-size: 16px;
    font-weight: 600;
  }
  .sidebar-brand img { width: 26px; height: 26px; border-radius: 7px; object-fit: contain; }
  .sidebar .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
  }
  .sidebar .nav-item .ico { width: 20px; font-size: 18px; text-align: center; }
  .sidebar .nav-item:hover { background: var(--surface-2); }
  .sidebar .nav-item.active { background: var(--surface-2); color: var(--primary); font-weight: 600; }
  .sidebar-foot { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); }

  .topbar { margin-left: var(--sidebar-w); }
  .topbar .brand-logo,
  .topbar .t-mobile { display: none; }
  .topbar .t-desktop { display: inline; }

  .content {
    margin-left: var(--sidebar-w);
    margin-right: auto;
    max-width: 1100px;
    padding: 16px 20px 32px;
  }
  .content.no-tabbar { padding-bottom: 32px; }
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head .time { font-size: 13px; color: var(--text-2); margin-left: auto; }
.card-text { white-space: pre-wrap; word-break: break-word; margin: 0 0 8px; }
.card-meta { font-size: 13px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 8px; }

.section-title { font-size: 14px; color: var(--text-2); margin: 18px 4px 8px; }
.section-title:first-child { margin-top: 4px; }

/* ---------- 徽标 ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.6;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge.primary { background: rgba(11, 94, 215, .12); color: var(--primary); }
.badge.success { background: rgba(22, 163, 74, .14); color: var(--success); }
.badge.warn    { background: rgba(217, 119, 6, .15); color: var(--warn); }
.badge.danger  { background: rgba(220, 53, 69, .14); color: var(--danger); }

.amount { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.amount.expense { color: var(--danger); }
.amount.income  { color: var(--success); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }

input[type=text], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=time], select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  appearance: none;
}
textarea { min-height: 90px; line-height: 1.5; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(11, 94, 215, .15);
}
.hint { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* ---------- 按钮 ---------- */
.btn,
button[type="submit"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: auto;
  min-height: 44px;
  padding: 0 16px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}
button[type="submit"] { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn:active,
button[type="submit"]:active { opacity: .75; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-primary   { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-success   { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger    { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-warning   { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-ghost     { background: transparent; border-color: transparent; color: var(--primary); }
.btn-sm        { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn-block     { width: 100%; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-group .btn { flex: 1; min-width: 100px; }

/* ---------- 筛选 chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* ---------- 列表 ---------- */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .sub { font-size: 13px; color: var(--text-2); }

.empty { text-align: center; color: var(--text-2); padding: 48px 16px; font-size: 15px; }

/* ---------- 开关 ---------- */
.switch { position: relative; display: inline-block; flex: 0 0 auto; width: 56px; height: 44px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch .track {
  position: absolute; left: 0; right: 0; top: 6px; height: 32px;
  background: var(--border); border-radius: 999px; transition: background .18s; pointer-events: none;
}
.switch .track::before {
  content: ''; position: absolute; left: 3px; top: 3px; width: 26px; height: 26px;
  background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .18s;
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::before { transform: translateX(24px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(11, 94, 215, .3); }

/* ---------- 底部固定操作栏 ---------- */
.actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.actionbar .btn { flex: 1; min-width: 0; padding: 0 10px; font-size: 15px; }

/* 桌面端左侧被边栏占了，操作栏要让开。
   必须写在 .actionbar 基础规则之后，否则会被 left:0 盖掉 */
@media (min-width: 1024px) {
  .actionbar { left: var(--sidebar-w); }
}

/* ---------- 嵌入预览（?embed=1） ---------- */
.embed .topbar,
.embed .sidebar,
.embed .tabbar,
.embed .actionbar,
.embed .btn-group { display: none; }
.embed .content { margin-left: 0; padding: 12px; max-width: none; }
.embed .content.no-tabbar { padding-bottom: 12px; }

/* ---------- 通用工具类 ---------- */
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.hidden { display: none !important; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

.md-body { white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.md-body strong { font-weight: 600; }
