:root {
  --wine-950: #3d0d1d;
  --wine-900: #57142a;
  --wine-800: #711d38;
  --wine-700: #8d294a;
  --wine-100: #f7e9ee;
  --gold-500: #c99a43;
  --gold-100: #f7f0e4;
  --ink: #171311;
  --text: #3f3733;
  --muted: #796f69;
  --line: #e5ded9;
  --line-strong: #d5cbc5;
  --surface: #ffffff;
  --canvas: #faf8f6;
  --soft: #f5f1ee;
  --success: #1f7651;
  --danger: #a32b3f;
  --radius: 12px;
  --shadow: 0 10px 28px rgba(42, 25, 19, 0.06);
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--canvas); color: var(--ink); }
button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: var(--wine-950);
}

.auth-panel {
  width: min(100%, 440px);
  padding: 38px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0,0,0,.24);
}

.auth-brand { display: flex; align-items: baseline; gap: 10px; margin-bottom: 34px; }
.auth-brand strong { font-family: SimSun, "Songti SC", serif; font-size: 24px; }
.auth-brand span { color: var(--muted); font-size: 13px; }
.auth-panel h1 { margin: 6px 0 10px; font-size: clamp(26px, 4vw, 34px); letter-spacing: -0.03em; }
.auth-copy { margin: 0 0 28px; color: var(--muted); line-height: 1.7; }
.auth-form { display: grid; gap: 18px; }

.eyebrow { margin: 0 0 6px; color: var(--wine-700); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
label { color: var(--text); font-size: 13px; font-weight: 700; }
label > span { display: block; margin-bottom: 8px; }
input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 13px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
input:focus, select:focus { border-color: var(--wine-700); box-shadow: 0 0 0 3px rgba(141,41,74,.12); }

.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 18px;
  background: transparent;
  cursor: pointer;
  font-weight: 800;
  transition: background .16s ease, border-color .16s ease, transform .16s ease;
}
.button:hover { transform: translateY(-1px); }
.button:focus-visible, .nav-button:focus-visible, .segmented button:focus-visible { outline: 3px solid rgba(201,154,67,.48); outline-offset: 2px; }
.button.primary { background: var(--wine-800); color: #fff; }
.button.primary:hover { background: var(--wine-900); }
.button.primary:disabled { background: #b9aeaa; cursor: not-allowed; transform: none; }
.button.quiet { border-color: var(--line); background: var(--surface); color: var(--text); }
.button.wide { width: 100%; }
.button.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.topbar-quiet { min-height: 34px; padding: 0 8px; color: #fff; }

.form-error { min-height: 20px; margin: 0; color: var(--danger); font-size: 13px; font-weight: 600; }
.app-shell { min-height: 100vh; }

.topbar {
  min-height: 74px;
  display: grid;
  grid-template-columns: minmax(220px, auto) 1fr minmax(170px, auto);
  align-items: stretch;
  background: var(--wine-950);
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 var(--space-xl);
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgba(255, 213, 228, .22));
}
.brand strong { font-family: SimSun, "Songti SC", serif; font-size: 23px; letter-spacing: .04em; }
.brand span { color: rgba(255,255,255,.68); font-size: 12px; }

.nav { display: flex; justify-content: center; align-items: stretch; gap: 18px; }
.nav, .seller-select-list { scrollbar-width: none; }
.nav::-webkit-scrollbar, .seller-select-list::-webkit-scrollbar { display: none; }
.nav-button {
  position: relative;
  min-width: 108px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.72);
  cursor: pointer;
  font-weight: 800;
}
.nav-icon { width: 18px; height: 18px; filter: invert(1); opacity: .72; }
.nav-button:hover .nav-icon, .nav-button.active .nav-icon { opacity: 1; }
.nav-button::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 0;
  height: 3px;
  background: transparent;
}
.nav-button:hover, .nav-button.active { color: #fff; }
.nav-button.active::after { background: var(--gold-500); }

.user-menu { display: flex; align-items: center; justify-content: flex-end; gap: 18px; padding: 0 26px; }
.user-menu > div { display: grid; justify-items: end; gap: 2px; }
.user-menu span { color: rgba(255,255,255,.68); font-size: 11px; }
.workspace { width: 100%; padding: 22px 20px 36px; }
.view { width: 100%; }

.dashboard-toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) 180px;
  align-items: end;
  gap: 24px;
  margin-bottom: 18px;
}
.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}
.dashboard-period-control > span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 700; }
.dashboard-period-tabs { margin: 0; }
.dashboard-context { min-width: 0; }
.date-line { display: flex; align-items: baseline; gap: 14px; }
.date-line strong { font-size: 18px; color: var(--wine-800); }
.date-line span, .page-heading p { color: var(--muted); font-size: 13px; }
.page-heading h1 { margin: 2px 0 6px; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.04em; }
.page-heading p { margin: 0; }
.compact-control { width: 180px; }
.compact-control span { color: var(--muted); font-size: 11px; }
.compact-control input, .compact-control select { min-height: 44px; background: var(--surface); }

.surface {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(360px, .88fr) minmax(620px, 1.62fr);
  gap: var(--space-md);
  align-items: stretch;
}
.ranking-panel { padding: 20px 24px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.panel-heading h1, .panel-heading h2 { margin: 0; letter-spacing: -.025em; }
.panel-heading h1 { font-size: 25px; }
.panel-heading h2 { font-size: 21px; }
.ranking-heading { align-items: flex-start; }
.ranking-panel .period-note { margin-top: 18px; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 22px 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
}
.segmented button { min-height: 40px; border: 0; border-right: 1px solid var(--line); background: #fff; cursor: pointer; font-weight: 800; }
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--wine-800); color: #fff; }
.period-note { min-height: 20px; margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.ranking-list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.ranking-row {
  display: grid;
  grid-template-columns: 42px minmax(100px, 1fr) minmax(110px, auto) 76px;
  align-items: center;
  min-height: 70px;
  border-top: 1px solid var(--line);
}
.ranking-number {
  width: 34px;
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  font-weight: 900;
}
.ranking-number img { width: 19px; height: 19px; opacity: .34; }
.ranking-number b { font-size: 12px; }
.ranking-row:first-child .ranking-number { color: #9f6e18; }
.ranking-row:first-child .ranking-number img { filter: sepia(1) saturate(4) hue-rotate(354deg); opacity: .86; }
.ranking-name { font-size: 18px; font-weight: 900; }
.ranking-money { color: var(--wine-800); font-size: 21px; font-weight: 900; text-align: right; }
.ranking-pieces { color: var(--text); font-weight: 800; text-align: right; }
.empty-state { padding: 42px 12px; color: var(--muted); text-align: center; }

.metric-matrix {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: 220px;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--wine-800);
  color: #fff;
  box-shadow: var(--shadow);
}
.period-metric { min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 24px; border-left: 1px solid rgba(255,255,255,.18); }
.period-metric:first-child { border-left: 0; }
.period-metric span { color: rgba(255,255,255,.72); font-size: 13px; font-weight: 800; }
.period-metric strong { margin-top: 10px; font-size: clamp(25px, 2.4vw, 36px); line-height: 1.1; white-space: nowrap; }
.period-metric small { margin-top: 12px; color: rgba(255,255,255,.64); font-size: 11px; line-height: 1.5; }
.period-metric.metric-profit strong { color: #f5d98e; }
.period-metric.metric-margin strong { color: #b9e6cc; }
.period-metric.metric-pieces strong, .period-metric.metric-shipments strong { font-size: clamp(22px, 2vw, 30px); }

.trend-panel { min-height: 320px; margin: var(--space-lg) 0; padding: 20px 24px 14px; }
.trend-range { color: var(--muted); font-size: 12px; font-weight: 700; }
.chart-wrap { position: relative; height: 235px; margin-top: 10px; }
#trendChart { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: pan-y; }
.chart-guide { position: absolute; top: 20px; bottom: 34px; width: 1px; background: rgba(113,29,56,.28); pointer-events: none; }
.chart-tooltip { position: absolute; z-index: 3; min-width: 176px; border-radius: 8px; background: #2d2024; color: #fff; padding: 12px 14px; box-shadow: 0 6px 16px rgba(31,16,21,.22); pointer-events: none; }
.chart-tooltip strong { display: block; margin-bottom: 8px; font-size: 13px; }
.chart-tooltip dl { display: grid; grid-template-columns: auto auto; gap: 6px 16px; margin: 0; font-size: 12px; }
.chart-tooltip dt { color: rgba(255,255,255,.68); }
.chart-tooltip dd { margin: 0; text-align: right; font-weight: 800; }
.chart-tooltip .tooltip-note { margin: 8px 0 0; color: rgba(255,255,255,.72); font-size: 12px; }
.chart-legend { display: flex; align-items: center; justify-content: flex-end; column-gap: 16px; row-gap: 8px; margin-top: 12px; color: var(--text); font-size: 12px; }
.chart-legend span { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.chart-legend i { width: 18px; height: 3px; display: inline-block; }
.legend-revenue { background: var(--wine-700); }
.legend-profit { background: var(--success); }
.legend-pieces { background: var(--gold-500); }
.legend-target { height: 0 !important; border-top: 2px dashed #c83b46; background: transparent; }
.chart-legend .muted { color: var(--muted); }

.performance-section { padding: 22px 0 0; overflow: hidden; }
.performance-section > .panel-heading { padding: 0 24px 18px; }
.table-scroll { overflow-x: auto; }
.performance-table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 13px; }
.performance-table th, .performance-table td { height: 48px; padding: 9px 16px; border-top: 1px solid var(--line); border-right: 1px solid var(--line); text-align: center; white-space: nowrap; }
.performance-table th:last-child, .performance-table td:last-child { border-right: 0; }
.performance-table thead th { background: #f8f5f2; color: var(--text); }
.performance-table thead tr:first-child th { font-size: 14px; }
.performance-table tbody th { text-align: left; font-size: 15px; }
.performance-table tbody tr:first-child { background: #fffaf0; }
.performance-table tfoot { background: var(--soft); font-weight: 900; }
.money { color: var(--wine-800); font-weight: 900; }

.entry-layout { display: grid; grid-template-columns: minmax(250px, 320px) 1fr; gap: 18px; align-items: start; }
.summary-form { margin-bottom: 18px; }
.summary-readonly > span { display: block; margin-bottom: 8px; color: var(--text); font-size: 13px; font-weight: 700; }
.summary-readonly output { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); padding: 0 13px; }
.summary-readonly output strong { font-size: 16px; }
.summary-readonly output small { color: var(--muted); font-size: 11px; }
.seller-selector { padding: 22px; position: sticky; top: 18px; }
.seller-select-list { display: grid; gap: 7px; margin-top: 18px; }
.seller-select-button {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--soft);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 900;
}
.seller-select-button span { color: var(--muted); font-size: 12px; font-weight: 600; }
.seller-select-button.active { border-color: var(--wine-700); background: var(--wine-100); color: var(--wine-800); }
.entry-forms { display: grid; gap: 18px; }
.data-form, .account-form { padding: 24px; }
.data-form .panel-heading, .account-form .panel-heading { margin-bottom: 24px; }
.save-state { color: var(--success); font-size: 12px; font-weight: 800; }
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.money-field { display: grid; grid-template-columns: 34px 1fr; align-items: center; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; }
.money-field:focus-within { border-color: var(--wine-700); box-shadow: 0 0 0 3px rgba(141,41,74,.12); }
.money-field > span { text-align: right; color: var(--muted); }
.money-field input { border: 0; box-shadow: none !important; }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 24px; }
.form-actions .form-error { flex: 1; }

.inline-create-form { display: grid; grid-template-columns: minmax(240px, 420px) auto 1fr; align-items: end; gap: 14px; padding: 20px; margin-bottom: 16px; }
.inline-create-form .form-error { align-self: center; }
.list-surface { overflow: hidden; }
.list-surface > .panel-heading { padding: 22px 24px; }
.management-list { display: grid; gap: 12px; }
.list-surface .management-list { gap: 0; }
.management-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(170px, .8fr) auto;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  padding: 12px 24px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.account-list-row { border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.management-row strong { display: block; }
.management-row span { color: var(--muted); font-size: 12px; }
.management-actions { display: flex; align-items: flex-end; justify-content: flex-end; gap: 10px; }
.management-actions .button { min-height: 44px; }
.status-tag { display: inline-flex; width: fit-content; border-radius: 999px; background: #edf7f1; color: var(--success); padding: 4px 9px; font-size: 11px; font-weight: 900; }
.status-tag.inactive { background: var(--soft); color: var(--muted); }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: min(380px, calc(100vw - 44px)); border-radius: 9px; background: var(--ink); color: #fff; padding: 13px 16px; box-shadow: 0 18px 48px rgba(0,0,0,.2); font-weight: 700; }

@media (max-width: 1120px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .brand span { display: none; }
  .brand { padding: 0 20px; }
  .nav { gap: 4px; }
  .nav-button { min-width: 92px; }
  .user-menu { padding: 0 16px; }
  .dashboard-grid { grid-template-columns: 1fr; gap: var(--space-lg); }
  .form-grid.four { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .topbar { min-height: auto; grid-template-columns: 1fr auto; grid-template-areas: "brand user" "nav nav"; }
  .brand { grid-area: brand; min-height: 58px; padding: 0 var(--space-md); }
  .brand-mark { width: 24px; height: 24px; flex-basis: 24px; }
  .brand strong { font-size: 20px; }
  .user-menu { grid-area: user; min-height: 58px; }
  .user-menu > div { display: none; }
  .nav { grid-area: nav; justify-content: flex-start; overflow-x: auto; border-top: 1px solid rgba(255,255,255,.08); }
  .nav-button { flex: 0 0 auto; min-height: 48px; min-width: 104px; }
  .workspace { padding: 16px 12px 28px; }
  .dashboard-toolbar { grid-template-columns: 1fr; align-items: stretch; gap: 16px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .compact-control { width: 100%; }
  .date-line { align-items: flex-start; flex-direction: column; gap: 4px; }
  .ranking-panel, .trend-panel, .data-form, .account-form { padding: 18px; }
  .ranking-list { grid-template-columns: 1fr; }
  .ranking-row { grid-template-columns: 38px 1fr auto; min-height: 70px; border-width: 1px 0 0; border-radius: 0; }
  .ranking-money { grid-column: 3; grid-row: 1; text-align: right; font-size: 18px; }
  .ranking-pieces { grid-column: 3; grid-row: 2; text-align: right; }
  .metric-matrix { grid-template-columns: 1fr; min-height: 0; }
  .period-metric { min-height: 104px; border-top: 1px solid rgba(255,255,255,.18); border-left: 0; padding: 18px 20px; }
  .period-metric:first-child { border-top: 0; }
  .period-metric strong, .period-metric.metric-pieces strong, .period-metric.metric-shipments strong { font-size: 24px; }
  .performance-table { min-width: 100%; table-layout: fixed; }
  .performance-table th, .performance-table td { padding-right: 8px; padding-left: 8px; }
  .performance-table th:first-child { width: 38%; }
  .trend-panel { margin: var(--space-md) 0; }
  .chart-wrap { height: 220px; }
  .chart-legend { flex-wrap: wrap; justify-content: flex-start; }
  .entry-layout { grid-template-columns: 1fr; }
  .entry-layout > *, .entry-forms, .seller-selector, .data-form, .form-grid, .form-grid > label { min-width: 0; }
  .seller-selector { position: static; width: 100%; }
  .seller-select-list { width: 100%; max-width: 100%; display: flex; overflow-x: auto; padding-bottom: 4px; }
  .seller-select-button { flex: 0 0 150px; }
  .form-grid.two, .form-grid.three, .form-grid.four { grid-template-columns: 1fr; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .form-actions .button { width: 100%; }
  .inline-create-form { grid-template-columns: 1fr; align-items: stretch; }
  .management-row { grid-template-columns: 1fr; gap: 10px; }
  .management-actions { justify-content: flex-start; flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
