/* ============================================================
   金久缘 AIOS · 原型设计系统
   基于 docs/ui/linear-reference-light.md（蝴蝶兰浅色系统）
   ============================================================ */

:root {
  /* 画布与表面 */
  --canvas: #F7F6F9;
  --surface: #FFFFFF;
  --surface-3: #EDEBF0;
  --surface-4: #E3E0E7;
  --hairline: #E2E0E6;
  --hairline-strong: #D0CDD6;
  --inverse-canvas: #1A1A20;

  /* 文字 */
  --ink: #1A1A20;
  --ink-muted: #4A4A55;
  --ink-subtle: #6E6A78;
  --ink-tertiary: #9A96A4;

  /* 蝴蝶兰品牌色 */
  --primary: #C458B6;
  --primary-hover: #B148A3;
  --primary-text: #8E2F82;
  --primary-soft: #F7E4F4;
  --pink-soft: #FADCEE;
  --pink-text: #A8346E;
  --yellow-soft: #FBEFCF;
  --yellow-text: #8A6A12;

  /* 语义色 */
  --success: #1E8E3A;
  --success-soft: #DFF1E4;
  --danger: #C23A3A;
  --danger-soft: #F9E3E3;

  /* 图表系列色（已过 CVD 校验） */
  --chart-1: #8E2F82;
  --chart-2: #A8346E;
  --chart-3: #8A6A12;
  --chart-4: #7C5CB0;

  /* 阴影（紫调基底） */
  --shadow-1: 0 1px 2px rgba(26,10,38,.04), 0 1px 3px rgba(26,10,38,.06);
  --shadow-2: 0 2px 6px rgba(26,10,38,.06), 0 4px 12px rgba(26,10,38,.05);
  --shadow-3: 0 4px 12px rgba(26,10,38,.08), 0 8px 24px rgba(26,10,38,.06);

  /* 圆角 */
  --r-xs: 4px; --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px;

  --font: "SF Pro Display", -apple-system, "Segoe UI", "PingFang SC",
          "Microsoft YaHei", system-ui, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --tabbar-h: 60px;
  --header-h: 52px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--canvas);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -.05px;
}
img { max-width: 100%; display: block; }
a { color: var(--primary-text); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; font-size: inherit; color: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }

:focus-visible { outline: 2px solid rgba(196,88,182,.4); outline-offset: 1px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- 排版 ---------- */
.display-lg { font-size: 34px; font-weight: 600; line-height: 1.1; letter-spacing: -1.2px; }
.headline   { font-size: 24px; font-weight: 600; line-height: 1.2; letter-spacing: -.6px; }
.card-title { font-size: 17px; font-weight: 600; line-height: 1.25; letter-spacing: -.3px; }
.eyebrow    { font-size: 12px; font-weight: 500; letter-spacing: .6px; color: var(--ink-subtle); text-transform: uppercase; }
.caption    { font-size: 12px; color: var(--ink-subtle); line-height: 1.4; }
.mono       { font-family: var(--mono); font-size: 12px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 14px; min-height: 38px;
  border-radius: var(--r-md);
  font-size: 14px; font-weight: 500; line-height: 1.2;
  transition: background .15s ease, box-shadow .15s ease, transform .06s ease;
  user-select: none; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: var(--surface-4); color: var(--ink-tertiary); cursor: not-allowed; }

.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--hairline); box-shadow: var(--shadow-1); }
.btn-secondary:hover { border-color: var(--hairline-strong); background: #FDFCFE; }

.btn-tertiary { background: transparent; color: var(--ink-muted); }
.btn-tertiary:hover { background: var(--surface-3); color: var(--ink); }

.btn-danger-ghost { background: var(--surface); color: var(--danger); border: 1px solid var(--hairline); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: #E8C8C8; }

.btn-sm { padding: 5px 10px; min-height: 30px; font-size: 13px; border-radius: var(--r-sm); }

/* 图标按钮 */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--r-md);
  color: var(--ink-muted); transition: background .15s ease, color .15s ease;
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}
.card-lift:hover { box-shadow: var(--shadow-2); border-color: var(--hairline-strong); }
.card-pad { padding: 16px; }
@media (min-width: 768px) { .card-pad { padding: 20px; } }

/* ---------- 标签 / 状态胶囊 ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 1.5;
  background: var(--surface-3); color: var(--ink-muted);
}
.tag-purple { background: var(--primary-soft); color: var(--primary-text); }
.tag-pink   { background: var(--pink-soft); color: var(--pink-text); }
.tag-yellow { background: var(--yellow-soft); color: var(--yellow-text); }
.tag-green  { background: var(--success-soft); color: var(--success); }
.tag-red    { background: var(--danger-soft); color: var(--danger); }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: none; }
.dot-green { background: var(--success); }
.dot-yellow { background: #D9A514; }
.dot-red { background: var(--danger); }
.dot-gray { background: var(--ink-tertiary); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap;
}
table.data th {
  text-align: left; font-weight: 500; color: var(--ink-subtle);
  padding: 8px 12px; border-bottom: 1px solid var(--hairline);
  font-size: 12px;
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--surface-3); }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background .12s ease; }
table.data tbody tr:hover { background: #FBFAFC; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data th.num { text-align: right; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--ink-muted); }
.input {
  width: 100%; padding: 10px 12px; min-height: 44px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--hairline); border-radius: var(--r-md);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input::placeholder { color: var(--ink-tertiary); }
.input:focus { outline: none; border-color: var(--hairline-strong); box-shadow: 0 0 0 2px rgba(196,88,182,.35); }

/* ---------- 品牌标 ---------- */
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -.3px; color: var(--ink); }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  background: #fff; border: 1px solid var(--hairline); overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand small { display: block; font-size: 11px; font-weight: 400; color: var(--ink-subtle); letter-spacing: 0; }

/* ---------- 应用框架：手机优先 ---------- */
.app {
  min-height: 100dvh;
  display: flex; flex-direction: column;
}
.app-header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px;
  background: rgba(247,246,249,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hairline);
}
.app-main { flex: 1; width: 100%; }
.page-pad { padding: 16px 16px calc(var(--tabbar-h) + 24px); max-width: 1120px; margin: 0 auto; width: 100%; }

/* 底部 Tab（手机） */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--hairline);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--ink-subtle); transition: color .15s ease;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a:hover { color: var(--ink); }
.tabbar a.active { color: var(--primary-text); font-weight: 500; }

/* 桌面侧边栏 */
.side-nav { display: none; }

@media (min-width: 1024px) {
  .tabbar { display: none; }
  .app { flex-direction: row; }
  .side-nav {
    display: flex; flex-direction: column;
    width: 232px; flex: none;
    position: sticky; top: 0; height: 100dvh;
    border-right: 1px solid var(--hairline);
    background: var(--canvas);
    padding: 16px 12px;
    gap: 4px;
  }
  .side-nav .brand { padding: 4px 10px 16px; }
  .side-nav a.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: var(--r-md);
    color: var(--ink-muted); font-size: 14px;
    transition: background .12s ease, color .12s ease;
  }
  .side-nav a.nav-item svg { width: 18px; height: 18px; }
  .side-nav a.nav-item:hover { background: var(--surface-3); color: var(--ink); }
  .side-nav a.nav-item.active { background: var(--surface); color: var(--primary-text); font-weight: 500; box-shadow: var(--shadow-1); border: 1px solid var(--hairline); }
  .side-nav .nav-footer { margin-top: auto; }
  .app-header { padding: 0 16px; }
  .page-pad { padding: 24px 32px 48px; }
}

/* ---------- 数据印记（来源引用条 · 签名组件） ---------- */
.source-cite {
  margin-top: 10px;
  border-top: 1px dashed var(--hairline-strong);
  padding-top: 8px;
  font-size: 12px; color: var(--ink-subtle);
}
.source-cite .cite-line {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px;
  cursor: pointer; user-select: none;
}
.source-cite .cite-line:hover { color: var(--ink-muted); }
.source-cite .hallmark {
  width: 14px; height: 14px; flex: none; color: var(--primary);
}
.source-cite .cite-detail {
  display: none;
  margin-top: 8px; padding: 10px 12px;
  background: var(--canvas); border: 1px solid var(--hairline); border-radius: var(--r-md);
  font-size: 12px; color: var(--ink-muted); line-height: 1.7;
}
.source-cite.open .cite-detail { display: block; }
.source-cite .chev { transition: transform .15s ease; margin-left: auto; }
.source-cite.open .chev { transform: rotate(180deg); }

/* ---------- 图表 ---------- */
.chart-tooltip {
  position: fixed; z-index: 90; pointer-events: none;
  background: var(--surface); border: 1px solid var(--hairline-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow-3);
  padding: 8px 10px; font-size: 12px; color: var(--ink);
  opacity: 0; transition: opacity .1s ease;
  max-width: 240px;
}
.chart-tooltip.show { opacity: 1; }
.chart-tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; color: var(--ink-muted); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-muted); }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

/* ---------- 抽屉 / 弹层 ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.4);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.scrim.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 70;
  width: min(84vw, 320px);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  transform: translateX(-104%); transition: transform .22s ease;
  display: flex; flex-direction: column;
}
.drawer.show { transform: translateX(0); }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  transform: translateY(105%); transition: transform .24s cubic-bezier(.3,.9,.3,1);
  max-height: 76dvh; display: flex; flex-direction: column;
}
.sheet.show { transform: translateY(0); }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--surface-4); margin: 8px auto 4px; flex: none; }
@media (min-width: 768px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -46%) scale(.98); opacity: 0; pointer-events: none;
    width: 520px; border-radius: var(--r-lg); max-height: 70vh; transition: opacity .18s ease, transform .18s ease; }
  .sheet.show { transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto; }
  .sheet-grip { display: none; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 20px); z-index: 95;
  transform: translate(-50%, 16px);
  background: var(--inverse-canvas); color: #fff;
  padding: 10px 16px; border-radius: var(--r-md);
  font-size: 13px; box-shadow: var(--shadow-3);
  opacity: 0; transition: opacity .2s ease, transform .2s ease;
  pointer-events: none; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 1024px) { .toast { bottom: 32px; } }

/* ---------- 骨架屏 / 空状态 ---------- */
.empty {
  text-align: center; padding: 36px 16px; color: var(--ink-subtle); font-size: 13px;
}
.empty .empty-icon { font-size: 28px; margin-bottom: 8px; opacity: .6; }

/* ---------- 通用工具 ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 12px; }
@media (min-width: 768px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.muted { color: var(--ink-subtle); }
.hide-mobile { display: none; }
@media (min-width: 768px) { .hide-mobile { display: initial; } .hide-desktop { display: none; } }
