:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --text: #182229;
  --muted: #68747c;
  --border: #dfe5e8;
  --brand: #087f5b;
  --brand-dark: #056246;
  --teal-soft: #dff5ec;
  --blue: #3274d9;
  --amber: #c88617;
  --red: #c74444;
  --purple: #7a5bbb;
  --shadow: 0 1px 2px rgba(20, 36, 45, 0.04);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111719;
  --surface: #182124;
  --surface-soft: #202b2e;
  --text: #edf2f1;
  --muted: #9facb0;
  --border: #2e3b3f;
  --brand: #3fc28f;
  --brand-dark: #62d5a8;
  --teal-soft: #183d31;
  --blue: #6d9fee;
  --amber: #e3ad4f;
  --red: #e36f6f;
  --purple: #a28bdd;
  --shadow: none;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; letter-spacing: 0; }
button, select { font: inherit; }
button { color: inherit; }
.app-shell { min-height: 100vh; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: 232px; display: flex; flex-direction: column; padding: 24px 16px; background: #14241f; color: #edf6f2; }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 28px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 7px; background: #42c493; color: #102b21; font-size: 17px; font-weight: 900; }
.brand div { display: grid; gap: 1px; }
.brand strong { font-size: 15px; }
.brand span:last-child { color: #91a9a0; font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px; }
nav { display: grid; gap: 5px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 42px; border: 0; border-radius: 6px; padding: 0 12px; background: transparent; color: #a8bbb4; text-align: left; cursor: pointer; transition: background .18s, color .18s; }
.nav-item:hover { background: rgba(255,255,255,.06); color: white; }
.nav-item.active { background: #25463b; color: #fff; }
.nav-icon { width: 19px; font-size: 17px; text-align: center; }
.sidebar-footer { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 14px 8px 0; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-footer div { display: grid; gap: 2px; }
.sidebar-footer strong { font-size: 11px; font-weight: 600; }
.sidebar-footer span:last-child { color: #839b92; font-size: 9px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #52d79f; box-shadow: 0 0 0 4px rgba(82,215,159,.12); }
main { min-width: 0; margin-left: 232px; }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 76px; display: flex; align-items: center; gap: 16px; padding: 12px 30px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(12px); }
.page-heading p, .eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 10px; font-weight: 650; text-transform: uppercase; }
.page-heading h1 { margin: 0; font-size: 21px; line-height: 1.2; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-button, .secondary-button, .primary-button { min-height: 38px; border-radius: 6px; cursor: pointer; }
.icon-button { width: 38px; border: 1px solid var(--border); background: var(--surface); font-size: 17px; }
.secondary-button, .primary-button { display: inline-flex; align-items: center; gap: 7px; padding: 0 13px; font-size: 12px; font-weight: 650; }
.secondary-button { border: 1px solid var(--border); background: var(--surface); }
.primary-button { border: 1px solid var(--brand); background: var(--brand); color: #fff; }
.primary-button:hover { background: var(--brand-dark); }
.menu-button { display: none; }
.dashboard { max-width: 1500px; margin: auto; padding: 22px 30px 38px; }
.toolbar { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.range-control { display: flex; padding: 3px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.range-control button { min-height: 30px; border: 0; border-radius: 4px; padding: 0 12px; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; }
.range-control button.active { background: var(--text); color: var(--surface); }
.select-control { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 8px 0 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--muted); font-size: 11px; }
.select-control select { min-width: 100px; border: 0; outline: 0; background: transparent; color: var(--text); font-weight: 600; }
.data-note { display: flex; align-items: center; gap: 7px; margin-left: auto; color: var(--muted); font-size: 10px; }
.data-note span { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.kpi-card, .panel { border: 1px solid var(--border); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.kpi-card { min-width: 0; padding: 17px 18px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { color: var(--muted); font-size: 11px; font-weight: 600; }
.kpi-icon { display: grid; place-items: center; width: 27px; height: 27px; border-radius: 6px; background: var(--surface-soft); color: var(--brand); font-size: 14px; }
.kpi-value { display: block; margin-top: 11px; overflow: hidden; font-size: clamp(21px, 2.2vw, 28px); line-height: 1; white-space: nowrap; text-overflow: ellipsis; }
.kpi-meta { display: flex; align-items: center; gap: 7px; margin-top: 11px; color: var(--muted); font-size: 10px; }
.trend { font-weight: 700; }
.trend.up { color: var(--brand); }
.trend.down { color: var(--red); }
.analytics-grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(310px, .75fr); gap: 12px; margin-bottom: 12px; }
.lower-grid { grid-template-columns: minmax(330px, .85fr) minmax(0, 1.65fr); margin-bottom: 0; }
.panel { min-width: 0; padding: 18px; }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel h2 { margin: 0; font-size: 14px; }
.legend { display: flex; flex-wrap: wrap; gap: 13px; color: var(--muted); font-size: 10px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend-line { width: 15px; height: 3px; border-radius: 3px; }
.legend-line.revenue { background: var(--brand); }
.legend-line.orders { background: var(--blue); }
.chart-wrap { position: relative; height: 245px; }
#trendChart { display: block; width: 100%; height: 100%; overflow: visible; }
.grid-line { stroke: var(--border); stroke-width: 1; }
.axis-label { fill: var(--muted); font-size: 9px; }
.revenue-path { fill: none; stroke: var(--brand); stroke-width: 2.5; }
.orders-path { fill: none; stroke: var(--blue); stroke-width: 2; }
.revenue-area { fill: var(--teal-soft); opacity: .65; }
.chart-hit { fill: transparent; cursor: crosshair; }
.hover-line { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-point { stroke: var(--surface); stroke-width: 2; }
.chart-tooltip { position: absolute; z-index: 3; min-width: 118px; pointer-events: none; transform: translate(-50%, -110%); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; background: var(--text); color: var(--surface); font-size: 10px; line-height: 1.6; box-shadow: 0 8px 24px rgba(0,0,0,.16); }
.benchmark { border-radius: 4px; padding: 5px 7px; background: var(--teal-soft); color: var(--brand-dark); font-size: 9px; font-weight: 700; }
.funnel { display: grid; gap: 15px; }
.funnel-row { display: grid; grid-template-columns: 72px minmax(0,1fr) 48px; align-items: center; gap: 9px; }
.funnel-label { color: var(--muted); font-size: 10px; }
.funnel-track { height: 10px; border-radius: 3px; background: var(--surface-soft); overflow: hidden; }
.funnel-fill { height: 100%; border-radius: 3px; background: var(--brand); transform-origin: left; animation: grow .55s ease both; }
.funnel-row:nth-child(2) .funnel-fill { background: #2f9b78; }
.funnel-row:nth-child(3) .funnel-fill { background: var(--blue); }
.funnel-row:nth-child(4) .funnel-fill { background: var(--purple); }
.funnel-value { text-align: right; font-size: 10px; font-weight: 700; }
.funnel-rate { grid-column: 2 / 4; margin-top: -11px; color: var(--muted); font-size: 8px; }
@keyframes grow { from { transform: scaleX(0); } }
.channel-content { display: grid; grid-template-columns: 140px minmax(0,1fr); align-items: center; gap: 18px; }
.donut { position: relative; width: 134px; aspect-ratio: 1; border-radius: 50%; }
.donut::after { content: ""; position: absolute; inset: 23px; border-radius: 50%; background: var(--surface); }
.donut div { position: absolute; inset: 0; z-index: 1; display: grid; place-content: center; text-align: center; }
.donut strong { font-size: 17px; }
.donut span { margin-top: 3px; color: var(--muted); font-size: 8px; }
.channel-list { display: grid; gap: 10px; }
.channel-row { display: grid; grid-template-columns: 9px 1fr auto; align-items: center; gap: 8px; font-size: 10px; }
.channel-row i { width: 7px; height: 7px; border-radius: 2px; }
.channel-row span { color: var(--muted); }
.channel-row strong { font-size: 10px; }
.panel-total { color: var(--muted); font-size: 10px; }
.text-button { border: 0; background: transparent; color: var(--brand); font-size: 10px; font-weight: 650; cursor: pointer; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 10px; }
th { padding: 0 9px 8px; color: var(--muted); font-weight: 600; text-align: left; }
td { padding: 10px 9px; border-top: 1px solid var(--border); white-space: nowrap; }
td:first-child { font-weight: 650; }
.channel-tag, .status-tag { display: inline-block; border-radius: 4px; padding: 3px 6px; font-size: 8px; font-weight: 650; }
.channel-tag { background: var(--surface-soft); color: var(--muted); }
.status-tag.active { background: var(--teal-soft); color: var(--brand-dark); }
.status-tag.ended { background: var(--surface-soft); color: var(--muted); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 280px; transform: translateY(20px); opacity: 0; pointer-events: none; border-radius: 6px; padding: 11px 14px; background: var(--text); color: var(--surface); font-size: 11px; transition: .2s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.sidebar-backdrop { display: none; }

@media (max-width: 1000px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .analytics-grid, .lower-grid { grid-template-columns: 1fr; }
  .chart-wrap { height: 230px; }
}

@media (max-width: 720px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; border: 0; background: rgba(0,0,0,.4); }
  .sidebar-backdrop.show { display: block; }
  main { margin-left: 0; }
  .topbar { padding: 10px 16px; }
  .menu-button { display: block; }
  .page-heading p { display: none; }
  .topbar-actions .secondary-button { width: 38px; padding: 0; justify-content: center; font-size: 0; }
  .topbar-actions .secondary-button span { font-size: 18px; }
  .dashboard { padding: 16px; }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .range-control { flex: 1 1 auto; }
  .range-control button { flex: 1; padding: 0 7px; }
  .select-control { flex: 1 1 145px; }
  .data-note { width: 100%; margin-left: 0; }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 21px; }
  .channel-content { grid-template-columns: 120px minmax(0,1fr); gap: 10px; }
  .donut { width: 114px; }
  .donut::after { inset: 20px; }
}

@media (max-width: 430px) {
  .topbar-actions .primary-button { width: 38px; padding: 0; justify-content: center; font-size: 0; }
  .topbar-actions .primary-button span { font-size: 18px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi-card { min-height: 124px; }
  .kpi-meta { align-items: flex-start; flex-direction: column; gap: 4px; }
  .panel { padding: 14px; }
  .legend { max-width: 100px; }
  .chart-wrap { height: 210px; }
  .channel-content { grid-template-columns: 1fr; justify-items: center; }
  .channel-list { width: 100%; }
}
