:root {
  --paper: #F6F4EA;
  --surface: #FFFFFF;
  --ink: #292C26;
  --muted: #626B59;
  --faint: #8A8E82;
  --rule: #DCD8CC;
  --olive: #556B2F;
  --sage: #A8BE73;
  --sage-soft: #E5ECD4;
  --note: #F3EAD0;
  --ok: #39734C;
  --warn: #94611D;
  --danger: #B23C3C;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Inter", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(246, 244, 234, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  width: min(1320px, calc(100% - 36px));
  margin: 0 auto;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
}
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.brand small {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.seg {
  display: inline-flex;
  background: #EAE7DA;
  padding: 3px;
  border-radius: 9px;
  gap: 2px;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 7px;
  font-weight: 600;
  font-size: 13px;
}
.seg button.active {
  background: var(--surface);
  color: var(--olive);
  box-shadow: 0 1px 4px rgba(41, 44, 38, 0.08);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}
.btn:hover { background: var(--sage-soft); border-color: #C4D4A7; }
.btn-primary {
  background: var(--olive);
  border-color: var(--olive);
  color: #fff;
}
.btn-primary:hover { background: #435624; }

.wrap {
  width: min(1320px, calc(100% - 36px));
  margin: 22px auto 48px;
}
.meta-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.auth-wall {
  max-width: 520px;
  margin: 72px auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
}
.auth-wall h2 { margin: 0 0 10px; font-size: 20px; }
.auth-wall p { margin: 0 0 20px; color: var(--muted); }

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.kpi-val {
  font-size: 26px;
  font-weight: 750;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.kpi-sub {
  font-size: 12px;
  color: var(--faint);
}
.delta {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: #EEF1E7;
  color: var(--muted);
}
.delta.up { background: #E4F2E8; color: var(--ok); }
.delta.down { background: #FCE8E8; color: var(--danger); }

/* Two-column panels */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 18px 20px;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}
.panel-head small {
  color: var(--faint);
  font-size: 12px;
}

.chart-wrap {
  width: 100%;
  overflow-x: auto;
}
.chart-svg {
  width: 100%;
  min-width: 420px;
  height: 220px;
  display: block;
}
.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.legend i {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* Bars & Funnel */
.bar-list {
  display: grid;
  gap: 11px;
}
.bar-row-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}
.bar-track {
  height: 8px;
  background: #EFECE0;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--olive);
  border-radius: 999px;
}
.bar-fill.sage { background: var(--sage); }

.device-pills {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
}
.pill {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
}
.pill strong { color: var(--ink); font-size: 14px; margin-left: 4px; }

/* Tables */
.table-scroll { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid #ECEAE0;
  white-space: nowrap;
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  background: #FAF9F4;
}
.num { font-variant-numeric: tabular-nums; text-align: right; }
.ok-txt { color: var(--ok); font-weight: 600; }
.bad-txt { color: var(--danger); font-weight: 600; }
.hidden { display: none !important; }

@media (max-width: 1060px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
