:root {
  --ink: #17202b;
  --muted: #69717d;
  --line: #dfe3e8;
  --surface: #f5f6f8;
  --paper: #ffffff;
  --accent: #e96817;
  --accent-soft: #fff0e6;
  --success: #278657;
  --danger: #bb3f3f;
  --navy: #34495e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--surface);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
button, input, select { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
.shell { width: min(1380px, calc(100% - 40px)); margin: 0 auto; }

.app-header {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.header-inner {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}
.brand > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.brand strong { font-size: 15px; }
.brand small, .header-status, .page-heading p, .panel-heading small {
  color: var(--muted);
  font-size: 12px;
}
.header-status {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.login-view { display: grid; min-height: calc(100vh - 150px); padding: 40px 20px; place-items: center; }
.login-panel {
  width: min(520px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; }
.login-panel h1, .page-heading h1 { margin: 8px 0 0; letter-spacing: 0; }
.login-panel h1 { font-size: 28px; }
.login-panel > p:not(.form-message) { margin: 12px 0 24px; color: var(--muted); }
.login-panel label, .toolbar label { color: var(--muted); font-size: 12px; font-weight: 700; }
.login-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; margin-top: 8px; }
input, select {
  min-height: 40px;
  border: 1px solid #bec5ce;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}
input { width: 100%; padding: 0 12px; }
select { min-width: 112px; padding: 0 30px 0 10px; }
button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}
button:disabled { cursor: wait; opacity: .6; }
button:focus-visible, input:focus, select:focus {
  outline: 3px solid rgba(233, 104, 23, .2);
  outline-offset: 2px;
}
.quiet-button { border-color: var(--line); background: var(--paper); color: var(--muted); }
.danger-button { border-color: var(--danger); background: var(--paper); color: var(--danger); }
.danger-button:hover { background: #fff0f0; }
.icon-button { width: 40px; padding: 0; font-size: 21px; }
.icon-button.is-loading { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.form-message { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 13px; }

.dashboard { padding: 30px 0 64px; }
.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}
.page-heading h1 { font-size: 28px; }
.page-heading p { margin: 6px 0 0; }
.toolbar { display: flex; align-items: end; gap: 8px; }
.toolbar label { display: grid; gap: 5px; }
.report-alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #e8b7b7;
  border-radius: 6px;
  background: #fff0f0;
  color: var(--danger);
}
.report-alert.is-success {
  border-color: #9fcfad;
  background: #eff9f1;
  color: #24733b;
}

.report-tabs {
  display: flex;
  overflow-x: auto;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}
.tab.is-active { border-bottom-color: var(--accent); color: var(--ink); }
.tab-view { display: none; }
.tab-view.is-active { display: block; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.metric { min-width: 0; padding: 19px 20px; }
.metric + .metric { border-left: 1px solid var(--line); }
.metric:nth-child(5) { border-left: 0; }
.metric:nth-child(n+5) { border-top: 1px solid var(--line); }
.metric span, .metric small { display: block; color: var(--muted); font-size: 12px; }
.metric strong {
  display: block;
  overflow: hidden;
  margin: 8px 0 5px;
  font-size: 27px;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.metric-grid.compact .metric:nth-child(n) { border-top: 0; }
.metric-grid.compact .metric:nth-child(5) { border-left: 1px solid var(--line); }

.split-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, .75fr); gap: 18px; }
.split-grid.equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.report-panel {
  min-width: 0;
  margin-bottom: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.panel-heading span { color: var(--accent); font-size: 11px; font-weight: 800; }
.panel-heading h2 { margin: 5px 0 0; font-size: 18px; letter-spacing: 0; }

.activity-chart {
  display: grid;
  min-height: 250px;
  grid-template-columns: repeat(var(--columns, 1), minmax(38px, 1fr));
  align-items: end;
  gap: 7px;
}
.activity-column { display: grid; min-width: 0; grid-template-rows: auto 1fr auto; gap: 7px; text-align: center; }
.activity-column strong, .activity-column span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.activity-bars { display: flex; min-height: 190px; align-items: end; justify-content: center; border-bottom: 1px solid var(--line); }
.activity-bar { width: min(22px, 62%); min-height: 3px; border-radius: 3px 3px 0 0; background: var(--navy); }

.retention-summary { display: grid; gap: 0; border-top: 1px solid var(--line); }
.retention-item { display: grid; grid-template-columns: 44px 1fr auto; align-items: baseline; gap: 10px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.retention-item span { color: var(--muted); font-size: 12px; font-weight: 700; }
.retention-item strong { color: var(--success); font-size: 24px; }
.retention-item small { color: var(--muted); font-size: 11px; }

.funnel-list { display: grid; gap: 14px; }
.funnel-item { display: grid; grid-template-columns: minmax(220px, .65fr) minmax(180px, 1fr) minmax(230px, .8fr); align-items: center; gap: 14px; }
.funnel-main { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; align-items: center; gap: 8px; font-size: 13px; }
.step-index { color: var(--accent); font-variant-numeric: tabular-nums; }
.funnel-users { color: var(--muted); }
.funnel-item small { color: var(--muted); font-size: 11px; }
.bar-track { overflow: hidden; height: 7px; border-radius: 4px; background: #e8ebef; }
.bar-fill { height: 100%; border-radius: inherit; background: var(--accent); }

.rank-list { display: grid; gap: 14px; }
.rank-item { display: grid; gap: 7px; }
.rank-heading { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.rank-list.danger .bar-fill { background: var(--danger); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: 11px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
.dense-table { min-width: 980px; }
.empty-state, .empty-cell { min-height: 120px; color: var(--muted); font-size: 13px; text-align: center !important; }
.empty-state { display: grid; place-items: center; }
.empty-cell { padding: 50px 10px; }

footer { border-top: 1px solid var(--line); background: var(--paper); color: var(--muted); font-size: 12px; }
footer .shell { display: flex; min-height: 76px; align-items: center; justify-content: center; }

@media (max-width: 1050px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(odd) { border-left: 0; }
  .metric:nth-child(n+3) { border-top: 1px solid var(--line); }
  .metric-grid.compact .metric:nth-child(3) { border-left: 0; }
  .metric-grid.compact .metric:nth-child(n+3) { border-top: 1px solid var(--line); }
  .split-grid, .split-grid.equal { grid-template-columns: 1fr; }
  .funnel-item { grid-template-columns: minmax(220px, .8fr) 1fr; }
  .funnel-item small { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .shell { width: min(100% - 24px, 1380px); }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; flex-wrap: wrap; }
  .toolbar label { flex: 1 1 130px; }
  .toolbar select { width: 100%; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric:nth-child(n) { border-top: 1px solid var(--line); border-left: 0; }
  .metric:first-child { border-top: 0; }
  .activity-chart { overflow-x: auto; grid-template-columns: repeat(var(--columns, 1), minmax(44px, 1fr)); }
  .funnel-item { grid-template-columns: 1fr; }
  .login-panel { padding: 24px; }
  .login-row { grid-template-columns: 1fr; }
}
