/* =========================================================================
 * base.css — 全局 reset + 小程序风格外壳（状态栏 / 胶囊 / 底部 TabBar）
 * 以及通用组件：按钮、卡片、胶囊标签、徽章、空状态、Toast。
 * 费乐 FEELO 风：4 Tab（图纸/教程/书架/我的），每 Tab 独立强调色。
 * ========================================================================= */

/* ---------- reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
}

img {
  display: block;
  max-width: 100%;
}

/* ---------- 手机框（桌面端居中，移动端铺满）---------- */
.app-shell {
  position: relative;
  max-width: var(--app-max-width);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(31, 41, 55, 0.08);
}

/* 可滚动内容区 */
.view-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 12px);
}

/* ---------- 状态栏（时间 + 信号 + 电池占位）---------- */
.statusbar {
  position: relative;
  height: calc(var(--statusbar-height) + var(--safe-top));
  padding: var(--safe-top) 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--fs-caption);
  font-weight: 600;
  color: var(--text-primary);
  flex: 0 0 auto;
  z-index: 20;
}

.statusbar .sb-time {
  letter-spacing: 0.4px;
  font-variant-numeric: tabular-nums;
}

.statusbar .sb-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.statusbar .sb-right svg {
  width: 18px;
  height: 14px;
  display: block;
}

/* ---------- 右上角胶囊按钮（··· ⊙，88×32）---------- */
.capsule {
  position: absolute;
  top: calc(var(--safe-top) + 8px);
  right: calc(14px + var(--safe-right));
  width: 88px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-full);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  z-index: 30;
}

.capsule .cap-dots {
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--text-secondary);
  line-height: 1;
}

.capsule .cap-divider {
  width: 1px;
  height: 14px;
  background: var(--border-soft);
}

.capsule .cap-circle {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1;
}

/* ---------- 底部 TabBar（图纸 / 教程 / 书架 / 我的）---------- */
.tabbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--border-soft);
  box-shadow: 0 -4px 16px rgba(31, 41, 55, 0.05);
  z-index: 40;
}

.tabbar .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.tabbar .tab svg {
  width: 24px;
  height: 24px;
}

.tabbar .tab .tab-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* 激活态：彩色图标 + 浅色胶囊底 */
.tabbar .tab.active {
  color: var(--accent-blue);
}

.tabbar .tab.active::before {
  content: "";
  position: absolute;
  top: 4px;
  width: 46px;
  height: 30px;
  border-radius: var(--radius-full);
  background: var(--accent-blue-soft);
  z-index: -1;
}

.tabbar .tab.active svg {
  fill: currentColor;
}

.tabbar .tab.active svg .no-fill {
  fill: none;
}

/* 各 Tab 强调色 */
.tabbar .tab[data-name="blueprint"].active { color: var(--accent-blue); }
.tabbar .tab[data-name="blueprint"].active::before { background: var(--accent-blue-soft); }
.tabbar .tab[data-name="tutorial"].active { color: var(--brand); }
.tabbar .tab[data-name="tutorial"].active::before { background: var(--brand-soft); }
.tabbar .tab[data-name="bookshelf"].active { color: var(--accent-orange); }
.tabbar .tab[data-name="bookshelf"].active::before { background: var(--accent-yellow-soft); }
.tabbar .tab[data-name="mine"].active { color: var(--accent-teal); }
.tabbar .tab[data-name="mine"].active::before { background: var(--accent-teal-soft); }

/* ---------- 通用组件 ---------- */
/* 页面大标题区 */
.page-head {
  padding: var(--space-3) var(--space-4) var(--space-2);
}

.page-head h1 {
  margin: 0;
  font-size: var(--fs-h1);
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.page-head p {
  margin: 4px 0 0;
  font-size: var(--fs-caption);
  color: var(--text-secondary);
}

/* 按钮（最小触控 44px） */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: #fff;
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-button);
  transition: filter 0.15s, background 0.15s, transform 0.1s;
}

.btn:hover { filter: brightness(1.05); }
.btn:active { filter: brightness(0.95); transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; filter: none; box-shadow: none; }

.btn.ghost {
  background: var(--bg-card);
  color: var(--brand);
  border-color: var(--brand);
  box-shadow: none;
}

.btn.light {
  background: var(--brand-soft);
  color: var(--brand);
  box-shadow: none;
}

.btn.danger {
  background: #fff;
  color: var(--status-error);
  border-color: var(--status-error);
  box-shadow: none;
}

.btn.block { display: flex; width: 100%; }

.btn.sm {
  min-height: 34px;
  padding: 0 var(--space-3);
  font-size: var(--fs-caption);
  border-radius: var(--radius-sm);
  box-shadow: none;
}

/* 卡片 */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-card);
}

.card-title {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-h2);
  font-weight: 700;
  color: var(--text-primary);
}

/* 胶囊标签（分类筛选） */
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 16px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-full);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: var(--fs-caption);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
  box-shadow: 0 3px 8px rgba(255, 77, 46, 0.25);
}

/* 徽章 */
.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-small);
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand);
}

.badge.blue { background: var(--accent-blue-soft); color: var(--accent-blue); }
.badge.gray { background: var(--bg); color: var(--text-secondary); border: 1px solid var(--border-soft); }
.badge.warn { background: rgba(245, 158, 11, 0.14); color: var(--status-warn); }

/* 空状态 */
.empty {
  text-align: center;
  color: var(--text-tertiary);
  font-size: var(--fs-caption);
  padding: var(--space-6) var(--space-4);
}

.empty svg {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-3);
  color: var(--divider);
}

/* 输入框 / 下拉 / 文件 */
.field { display: block; }

.field > label {
  display: block;
  font-size: var(--fs-caption);
  color: var(--text-secondary);
  margin: 0 0 6px;
}

.input,
.select,
.file {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  font-size: var(--fs-body);
  background: #fff;
  color: var(--text-primary);
}

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

/* Toast 轻提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(10px);
  max-width: 80%;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: rgba(31, 41, 55, 0.92);
  color: #fff;
  font-size: var(--fs-caption);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: rgba(239, 68, 68, 0.95); }
.toast.ok { background: rgba(255, 77, 46, 0.95); }

/* 无障碍：可见焦点 */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* 尊重 reduce-motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
