:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #fafafa;
  --ink: #24242a;
  --muted: #69707d;
  --line: #dfe2e7;
  --line-strong: #c8cdd5;
  --rose: #d9486e;
  --rose-soft: #fceef2;
  --teal: #16776f;
  --teal-soft: #e8f5f2;
  --amber: #b86a16;
  --amber-soft: #fff2df;
  --blue: #3e6ca8;
  --blue-soft: #eaf0f8;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(24, 31, 42, 0.06);
}

* { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
}

button, select { font: inherit; }

button:focus-visible {
  outline: 3px solid rgba(62, 108, 168, 0.28);
  outline-offset: 2px;
}

.shell {
  width: min(1240px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar {
  background: var(--ink);
  color: #fff;
}

.topbar-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  background: var(--rose);
  border-radius: 6px;
  font-size: 19px;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  font-weight: 720;
}

.brand p {
  margin: 3px 0 0;
  color: #b9bec7;
  font-size: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar form { margin: 0; }

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(48px, 1fr));
  padding: 3px;
  border: 1px solid #4a4b52;
  border-radius: 6px;
  background: #303137;
}

.segmented button {
  min-height: 32px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #c9cbd1;
  cursor: pointer;
}

.segmented button.active {
  background: #fff;
  color: var(--ink);
  font-weight: 650;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid #4a4b52;
  border-radius: 6px;
  background: #303137;
  color: #fff;
  cursor: pointer;
}

.icon-button span {
  font-size: 22px;
  line-height: 1;
}

.icon-button.loading span {
  animation: spin 0.8s linear infinite;
}

.logout-button {
  min-width: 54px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #4a4b52;
  border-radius: 6px;
  background: transparent;
  color: #e3e4e8;
  cursor: pointer;
}

.logout-button:hover { background: #303137; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background: #fff;
}

.login-shell {
  width: min(360px, 100%);
}

.login-brand {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 6px;
  background: var(--rose);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
}

.login-shell h1 {
  margin: 0 0 30px;
  font-size: 25px;
  line-height: 1.3;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.login-form input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.login-form input:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(62, 108, 168, 0.16);
}

.login-form button {
  height: 44px;
  margin-top: 4px;
  border: 0;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.login-error {
  min-height: 19px;
  margin: 0;
  color: var(--danger);
  font-size: 12px;
}

.status-band {
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.status-row {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.view-tabs {
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.tab-row {
  display: flex;
  gap: 28px;
}

.tab-row button {
  position: relative;
  min-height: 48px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}

.tab-row button.active {
  color: var(--ink);
}

.tab-row button.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: var(--rose);
}

.main {
  min-height: calc(100vh - 214px);
  padding-top: 24px;
  padding-bottom: 32px;
}

.loading-state,
.error-state {
  min-height: 280px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
}

.error-state {
  color: var(--danger);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--rose);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi {
  min-height: 110px;
  padding: 17px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent, var(--rose));
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
}

.kpi-value {
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.kpi-meta {
  margin-top: 9px;
  color: var(--muted);
  font-size: 11px;
}

.panel {
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.panel-heading {
  min-height: 54px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.panel-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.panel-body {
  padding: 18px;
}

.identity-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 16px;
}

.identity-item {
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.identity-item:last-child { border-right: 0; }

.identity-item strong {
  display: block;
  font-size: 20px;
  color: var(--rose);
  font-variant-numeric: tabular-nums;
}

.identity-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.chart-wrap {
  width: 100%;
  overflow: hidden;
}

.trend-chart {
  width: 100%;
  min-width: 680px;
  height: auto;
  display: block;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 11px;
}

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 5px;
  border-radius: 2px;
  vertical-align: -1px;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.data-table th,
.data-table td {
  height: 38px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

.data-table tbody tr:hover {
  background: #fff9fb;
}

.funnel-list {
  display: grid;
  gap: 7px;
}

.funnel-row {
  display: grid;
  grid-template-columns: 130px minmax(160px, 1fr) 70px 110px;
  align-items: center;
  gap: 14px;
  min-height: 38px;
}

.funnel-label {
  color: var(--ink);
  font-weight: 600;
}

.funnel-track {
  height: 16px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
}

.funnel-fill {
  height: 100%;
  min-width: 2px;
  background: var(--teal);
}

.funnel-users {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.funnel-rate {
  color: var(--muted);
  text-align: right;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.retention-table {
  min-width: 760px;
}

.retention-cell {
  display: inline-grid;
  min-width: 54px;
  min-height: 26px;
  place-items: center;
  padding: 3px 7px;
  border-radius: 3px;
  font-weight: 650;
}

.notes {
  display: grid;
  gap: 8px;
  padding: 14px 18px;
  background: var(--amber-soft);
  border: 1px solid #efd7b9;
  border-radius: 6px;
  color: #7e4b12;
  font-size: 12px;
}

.note-row {
  display: flex;
  gap: 8px;
}

.note-mark {
  flex: 0 0 auto;
  font-weight: 800;
}

.empty {
  padding: 52px 20px;
  text-align: center;
  color: var(--muted);
}

.footer {
  min-height: 58px;
  display: flex;
  align-items: center;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .identity-strip { grid-template-columns: repeat(2, 1fr); }
  .identity-item:nth-child(2) { border-right: 0; }
  .identity-item:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .chart-wrap { overflow-x: auto; }
}

@media (max-width: 620px) {
  .shell { width: min(100% - 24px, 1240px); }
  .topbar-inner {
    min-height: 118px;
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
  }
  .brand h1 { font-size: 17px; }
  .toolbar { width: 100%; }
  .segmented { flex: 1; }
  .status-row {
    min-height: 48px;
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
  }
  .tab-row { gap: 20px; overflow-x: auto; }
  .tab-row button { flex: 0 0 auto; }
  .main { padding-top: 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { min-height: 98px; padding: 14px; }
  .kpi-value { font-size: 26px; }
  .identity-strip { grid-template-columns: 1fr 1fr; }
  .identity-item { padding: 12px; }
  .panel-heading {
    min-height: 60px;
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
  }
  .panel-body { padding: 14px; }
  .funnel-row {
    grid-template-columns: 88px minmax(90px, 1fr) 46px;
    gap: 8px;
  }
  .funnel-rate { display: none; }
}

@media (max-width: 390px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .identity-strip { grid-template-columns: 1fr; }
  .identity-item {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .identity-item:last-child { border-bottom: 0; }
}
