/* ==========================================================================
   市场营销分析 · Marketing Desk
   依据 Web Tools 统一视觉与交互规范（STYLE_GUIDE.md v1.0）实现
   柔光植物工作台：暖纸白 + 鼠尾草绿 + 位图植物画框
   ========================================================================== */

:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #eeede7;

  --ink: #24231f;
  --ink-2: #56544c;
  --muted: #6b685d;

  --line: #e7e5dc;
  --line-strong: #d9d6ca;

  --accent: #5f7c61;
  --accent-deep: #42584a;
  --accent-soft: #e6ece1;

  --success: #4f9d6b;
  --warning: #a47735;
  --danger: #b0594b;

  --radius-panel: 18px;
  --radius-control: 10px;
  --radius-small: 7px;

  --shadow-sm:
    0 1px 2px rgba(36, 35, 31, 0.05),
    0 4px 12px rgba(36, 35, 31, 0.05);
  --shadow-md:
    0 2px 6px rgba(36, 35, 31, 0.05),
    0 16px 40px rgba(36, 35, 31, 0.10);

  --font-display: 'Space Grotesk', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --font-body: 'Inter', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* 固定植物背景（位图植物画框，规范 4.1） */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url('/assets/botanical-frame-desktop-v1.png');
  background-repeat: no-repeat;
  background-position: center -64px;
  background-size: 100% auto;
  opacity: 0.38;
}

.shell { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }

button, input, select, textarea { font: inherit; color: inherit; }

button { cursor: pointer; background: none; border: none; padding: 0; }

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-small);
}

/* --------------------------------------------------------------------------
   顶部品牌横条（规范 4.2）
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 14px clamp(20px, 5vw, 72px);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }

.brand__mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-control);
  box-shadow: var(--shadow-sm);
  flex: none;
}

.brand__mark svg { width: 36px; height: 36px; display: block; }

.brand__word { display: flex; flex-direction: column; line-height: 1.15; }

/* 标题颜色锁定（规范 3.2） */
.brand__word strong,
.hero__title,
.hero__title * {
  color: #42584a;
}

.brand__word strong {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand__word small {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.topbar__meta { display: flex; align-items: center; gap: 18px; }

.back {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.back:hover { color: var(--accent-deep); border-color: var(--accent); background: var(--accent-soft); }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12px;
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
}

.status::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(79, 157, 107, 0.14);
}

/* --------------------------------------------------------------------------
   内容容器与标题区（规范 4.3 / 4.4）
   -------------------------------------------------------------------------- */
.main { flex: 1; width: min(1120px, calc(100% - 40px)); margin-inline: auto; }

.hero { padding: 40px 0 34px; }

.eyebrow {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 20px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--accent-deep);
  text-transform: uppercase;
}

.eyebrow__rule { width: 34px; height: 2px; border-radius: 2px; background: var(--accent); }

.hero__title {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: clamp(25px, 5vw, 40px);
  line-height: 1.15;
  letter-spacing: 0;
  font-weight: 700;
}

.hero__lead {
  max-width: 640px;
  margin: 0;
  font-size: 16px;
  line-height: 1.8;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   工具箱 / 视图 Tab
   -------------------------------------------------------------------------- */
.toolbox { padding: 8px 0 72px; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding-bottom: 26px;
}

.tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  color: var(--muted);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 13px;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.tab:hover { color: var(--ink); border-color: var(--line-strong); }

.tab.is-active {
  color: var(--accent-deep);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tab__icon { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab__label { font-weight: 600; white-space: nowrap; }
.tab__code { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.12em; opacity: 0.55; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.section-kicker { margin: 0 0 8px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; color: var(--accent-deep); }

.section-head h2 { margin: 0; font-family: var(--font-display); font-size: 24px; font-weight: 700; letter-spacing: 0; color: var(--accent-deep); }

.section-head p { margin: 8px 0 0; font-size: 13px; line-height: 1.7; color: var(--muted); }

.section-actions { display: flex; gap: 10px; flex: none; }

.period-chip {
  flex: none;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
}

/* --------------------------------------------------------------------------
   按钮（规范 5.3）
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 18px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-control);
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.btn:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.btn--ghost { color: var(--accent-deep); background: var(--surface); border-color: var(--line-strong); }
.btn--ghost:hover { background: var(--accent-soft); border-color: var(--accent); }

.btn--danger { color: var(--danger); background: var(--surface); border-color: var(--line-strong); }
.btn--danger:hover { background: rgba(176, 89, 75, 0.08); border-color: var(--danger); }

/* --------------------------------------------------------------------------
   KPI 卡片
   -------------------------------------------------------------------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.kpi-card {
  position: relative;
  padding: 18px 18px 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.kpi-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }

.kpi-card__fold {
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-top: 22px solid var(--accent);
  border-right: 22px solid transparent;
  filter: drop-shadow(-2px 3px 3px rgba(36, 35, 31, 0.12));
  pointer-events: none;
}

.kpi-card__label {
  padding-right: 20px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

.kpi-card__value {
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--ink);
}

.kpi-card__hint { margin-top: 6px; font-size: 11px; line-height: 1.6; color: var(--muted); }
.kpi-card__hint.is-good { color: var(--success); }
.kpi-card__hint.is-warn { color: var(--warning); }
.kpi-card__hint.is-bad { color: var(--danger); }

/* --------------------------------------------------------------------------
   面板（规范 5.5：标题栏 surface-2，正文 surface，不嵌套卡片）
   -------------------------------------------------------------------------- */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.panel {
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.split .panel { margin-bottom: 0; }

.panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.panel__head h3 { margin: 0; font-family: var(--font-display); font-size: 16px; font-weight: 700; letter-spacing: 0; color: var(--accent-deep); }

.panel__code { font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.12em; color: var(--muted); }

.panel__body { padding: 20px; }

/* --------------------------------------------------------------------------
   图表
   -------------------------------------------------------------------------- */
.chart { width: 100%; }

.chart svg { display: block; width: 100%; height: auto; }

.bar-label { font-family: var(--font-mono); font-size: 11px; fill: var(--muted); }
.bar-track { fill: var(--surface-2); rx: 6; }
.bar-fill { rx: 6; }
.bar-val { font-family: var(--font-mono); font-size: 10px; fill: var(--ink-2); }

.funnel-row {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  align-items: center;
  gap: 12px;
  margin: 6px 0;
}

.funnel-row__name { font-family: var(--font-mono); font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

.funnel-row__bar { height: 34px; border-radius: var(--radius-small); }

.funnel-row__val { min-width: 96px; text-align: right; font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); }

.funnel-row__val small { display: block; color: var(--muted); font-size: 9px; margin-top: 2px; }

.rfm { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }

.rfm__title { margin: 0 0 12px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--muted); font-weight: 500; }

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

.rfm__tier {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  font-size: 12px;
}

.rfm__tier-name { flex: none; font-family: var(--font-mono); font-size: 11px; font-weight: 500; }

.rfm--high .rfm__tier-name { color: var(--success); }
.rfm--mid .rfm__tier-name { color: var(--warning); }
.rfm--low .rfm__tier-name { color: var(--danger); }

.rfm__tier-items { color: var(--ink-2); line-height: 1.7; }

.rfm__empty { margin: 0; font-size: 12px; color: var(--muted); }

/* --------------------------------------------------------------------------
   表格
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

.table th {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  font-weight: 500;
  white-space: nowrap;
}

.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }

.table tbody tr:last-child td { border-bottom: 0; }

.table tbody tr { transition: background 0.18s ease; }
.table tbody tr:hover { background: var(--accent-soft); }

.table .num { text-align: right; font-family: var(--font-mono); font-size: 12px; }
.table .pos { color: var(--success); }
.table .neg { color: var(--danger); }

.table--edit td { padding: 6px 8px; }

.table--edit input {
  width: 100%;
  min-width: 90px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-small);
  background: transparent;
  font-size: 12.5px;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.table--edit input:hover { border-color: var(--line); background: var(--surface); }

.table--edit input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.table__del {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-small);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  transition: color 0.18s ease, background 0.18s ease;
}

.table__del:hover { color: var(--danger); background: rgba(176, 89, 75, 0.1); }

/* --------------------------------------------------------------------------
   工具栏与提示
   -------------------------------------------------------------------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.toolbar__spacer { flex: 1; }

.toolbar__hint { margin: 10px 0 0; font-size: 11px; color: var(--muted); }

/* --------------------------------------------------------------------------
   表单（规范 5.4：输入框背景 --surface）
   -------------------------------------------------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.field { display: flex; flex-direction: column; gap: 7px; }

.field > span { font-size: 12px; color: var(--muted); font-weight: 500; }

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  resize: vertical;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(95, 124, 97, 0.12);
}

.notes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* --------------------------------------------------------------------------
   4P · 4C
   -------------------------------------------------------------------------- */
.p4-cell textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  font-size: 12.5px;
  line-height: 1.7;
  resize: vertical;
}

.p4-cell textarea:focus { outline: none; border-color: var(--accent); }

.p4-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.p4-cell {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.p4-cell__tag { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; color: var(--accent-deep); }

/* --------------------------------------------------------------------------
   报告
   -------------------------------------------------------------------------- */
.report {
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.report__body {
  padding: clamp(24px, 5vw, 52px);
  max-width: 860px;
  margin: 0 auto;
  font-size: 14px;
  line-height: 1.9;
  color: var(--ink);
}

.report__body h1 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--accent-deep);
}

.report__body .report__meta {
  margin: 0 0 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.report__body h2 {
  margin: 28px 0 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  color: var(--accent-deep);
}

.report__body h3 { margin: 20px 0 8px; font-size: 15px; font-weight: 600; color: var(--accent-deep); }

.report__body p { margin: 10px 0; }
.report__body ul, .report__body ol { margin: 10px 0; padding-left: 22px; }
.report__body li { margin: 5px 0; }
.report__body strong { color: var(--ink); }

.report__body table {
  width: 100%;
  margin: 14px 0;
  border-collapse: collapse;
  font-size: 12.5px;
}

.report__body th, .report__body td { padding: 8px 10px; border: 1px solid var(--line); text-align: left; }

.report__body th { background: var(--accent-soft); color: var(--accent-deep); font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.05em; }

.report__body .report__kpi { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0; }

.report__body .report__kpi span {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: 12px;
}

.report__body .report__kpi strong { display: block; font-size: 16px; color: var(--accent-deep); }

.report__body blockquote {
  margin: 14px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 10px 10px 0;
  color: var(--ink-2);
}

/* --------------------------------------------------------------------------
   页脚
   -------------------------------------------------------------------------- */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 18px clamp(20px, 5vw, 72px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
}

/* --------------------------------------------------------------------------
   响应式（规范 7）
   -------------------------------------------------------------------------- */
@media (max-width: 720px) {
  .split { grid-template-columns: 1fr; }
  .split .panel { margin-bottom: 20px; }
  .notes-grid { grid-template-columns: 1fr; }
  .p4-grid { grid-template-columns: 1fr; }
  .tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .section-actions { width: 100%; }
  .section-actions .btn { flex: 1; }
}

@media (max-width: 560px) {
  body::after {
    background-image: url('/assets/botanical-frame-mobile-v2.png');
    background-position: center -38px;
    background-size: 100% auto;
    opacity: 0.28;
  }

  .topbar { padding: 12px 16px; }
  .back { padding: 8px 10px; font-size: 12px; }
  .status { display: none; }

  .main { width: min(100% - 32px, 1120px); }
  .hero { padding: 32px 0 28px; }
  .hero__lead { font-size: 16px; }

  .toolbox { padding: 4px 0 48px; }
  .tabs { gap: 8px; padding-bottom: 18px; }
  .tab { padding: 9px 10px; }
  .tab__code { display: none; }

  .panel__head { padding: 12px 16px; }
  .panel__body { padding: 16px; }

  .funnel-row { grid-template-columns: 78px 1fr auto; gap: 8px; }
  .funnel-row__val { min-width: 74px; }

  .footer { flex-direction: column; gap: 8px; padding: 16px 16px; }
}

/* --------------------------------------------------------------------------
   动效（规范 6）：常规过渡，无持续动画；支持减少动态
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --------------------------------------------------------------------------
   打印：仅显示报告
   -------------------------------------------------------------------------- */
@media print {
  body::after, .topbar, .hero, .tabs, .section-head, .footer { display: none !important; }
  body { background: #fff; }
  .toolbox { padding: 0; }
  .view { display: none !important; }
  #view-report { display: block !important; }
  .main { width: 100%; margin: 0; }
  .report { border: 0; box-shadow: none; border-radius: 0; }
  .report__body { padding: 0; max-width: none; }
  .report__body h2 { border-top: 1px solid #ccc; page-break-after: avoid; }
  .report__body table { page-break-inside: avoid; }
}
