:root {
  color-scheme: light;
  --blue-700: #174ea6;
  --blue-600: #2563b8;
  --blue-500: #3578cf;
  --blue-100: #eaf2fc;
  --blue-050: #f5f8fd;
  --ink: #172033;
  --ink-soft: #4d5b73;
  --line: #dbe3ef;
  --line-strong: #c7d2e3;
  --surface: #ffffff;
  --canvas: #f4f7fb;
  --warning: #a65012;
  --warning-bg: #fff6e8;
  --danger: #a63b3b;
  --danger-bg: #fff0f0;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button, .link-button { cursor: pointer; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 22px; letter-spacing: -0.02em; }
h2 { margin-bottom: 6px; font-size: 17px; }
.muted { color: var(--ink-soft); }
.compact { margin-bottom: 0; font-size: 13px; }
.eyebrow { margin-bottom: 4px; color: var(--blue-600); font-size: 11px; font-weight: 750; letter-spacing: .1em; }

.topbar { position: sticky; top: 0; z-index: 20; min-height: 76px; padding: 14px 32px; display: flex; align-items: center; justify-content: space-between; gap: 24px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand-row, .account-row { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; color: #fff; background: var(--blue-700); border-radius: 14px; font-size: 17px; font-weight: 800; letter-spacing: -.04em; }
.brand-mark.small { width: 44px; height: 44px; border-radius: 12px; font-size: 15px; }
.dashboard-layout { display: grid; grid-template-columns: 216px minmax(0, 1fr); align-items: start; min-height: calc(100vh - 76px); }
.sidebar { position: sticky; top: 76px; min-height: calc(100vh - 76px); padding: 24px 16px; background: var(--surface); border-right: 1px solid var(--line); }
.sidebar-caption { margin: 0 10px 10px; color: #7a879b; font-size: 11px; font-weight: 750; letter-spacing: .08em; }
.sidebar-nav { display: grid; gap: 7px; }
.nav-item { width: 100%; min-height: 44px; padding: 0 12px; display: flex; align-items: center; gap: 10px; color: var(--ink-soft); background: transparent; border: 1px solid transparent; border-radius: 9px; font-weight: 700; text-align: left; }
.nav-item span { width: 26px; height: 26px; display: grid; place-items: center; flex: 0 0 auto; color: var(--blue-700); background: var(--blue-100); border-radius: 7px; font-size: 11px; }
.nav-item:hover { color: var(--blue-700); background: var(--blue-050); }
.nav-item.active { color: var(--blue-700); background: var(--blue-100); border-color: #cfe0f5; }
.nav-item.active span { color: #fff; background: var(--blue-600); }
.dashboard-shell { width: min(1320px, calc(100% - 40px)); min-width: 0; margin: 24px auto 48px; }
.notice { padding: 13px 16px; background: var(--blue-100); border-left: 4px solid var(--blue-600); border-radius: 8px; color: #294766; font-size: 13px; }
.view-panel { margin-top: 18px; }
.view-panel > :first-child { margin-top: 0; }
.view-panel[hidden] { display: none; }
.events-only-filter[hidden] { display: none; }

.filter-panel, .chart-card, .table-card { margin-top: 18px; padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 3px 14px rgba(27, 47, 79, .045); }
.filter-panel { display: block; }
.filter-form { display: grid; grid-template-columns: repeat(4, minmax(130px, 1fr)) auto; align-items: end; gap: 12px; }
.filter-form.events-mode { grid-template-columns: repeat(6, minmax(120px, 1fr)) auto; }
label { display: grid; gap: 7px; color: var(--ink-soft); font-size: 12px; font-weight: 650; }
input, select { width: 100%; height: 40px; padding: 0 11px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 7px; outline: none; }
input:focus, select:focus { border-color: var(--blue-500); box-shadow: 0 0 0 3px rgba(53, 120, 207, .13); }
.primary-button, .secondary-button { min-height: 40px; padding: 0 16px; border-radius: 7px; font-weight: 700; }
.primary-button { color: #fff; background: var(--blue-600); border: 1px solid var(--blue-600); }
.primary-button:hover { background: var(--blue-700); }
.secondary-button { color: var(--ink); background: #fff; border: 1px solid var(--line-strong); }
.secondary-button:hover { background: var(--blue-050); border-color: #9fb2ce; }
.link-button { min-height: 36px; display: inline-flex; align-items: center; text-decoration: none; font-size: 13px; }
.status-message { min-height: 24px; padding-top: 10px; color: var(--ink-soft); font-size: 13px; }
.status-message.error { color: var(--danger); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi-card { padding: 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.kpi-card p { margin-bottom: 12px; color: var(--ink-soft); font-size: 13px; font-weight: 650; }
.kpi-card strong { display: block; margin-bottom: 8px; color: var(--blue-700); font-size: 31px; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.kpi-card span { color: #738198; font-size: 12px; }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 16px; }
.legend { display: flex; gap: 16px; color: var(--ink-soft); font-size: 12px; white-space: nowrap; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-line { display: inline-block; width: 24px; height: 3px; border-radius: 2px; }
.legend-line.blue { background: var(--blue-600); }
.legend-line.charcoal { background: #4d5b73; }
.legend-line.dashed { height: 0; background: transparent; border-top: 3px dashed #4d5b73; }
.trend-chart { min-height: 310px; overflow: hidden; }
.trend-chart svg { display: block; width: 100%; height: 310px; }
.chart-empty { min-height: 230px; display: grid; place-items: center; color: var(--ink-soft); font-size: 13px; }
.breakdown-grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 18px; }
.rank-bars { display: grid; gap: 14px; }
.rank-row { display: grid; grid-template-columns: minmax(90px, 150px) 1fr auto; align-items: center; gap: 12px; }
.rank-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 650; }
.rank-progress { width: 100%; height: 9px; overflow: hidden; appearance: none; border: 0; border-radius: 5px; background: #edf2f8; }
.rank-progress::-webkit-progress-bar { background: #edf2f8; border-radius: 5px; }
.rank-progress::-webkit-progress-value { background: var(--blue-500); border-radius: 5px; }
.rank-progress::-moz-progress-bar { background: var(--blue-500); border-radius: 5px; }
.rank-value { min-width: 70px; text-align: right; color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.analysis-card { min-height: 420px; }
.analysis-bars { max-width: 1080px; gap: 17px; }
.analysis-bars .rank-row { grid-template-columns: minmax(110px, 210px) 1fr auto; }

.table-heading { align-items: center; }
.table-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; min-width: 980px; background: #fff; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; white-space: nowrap; }
th { color: var(--ink-soft); background: var(--blue-050); font-weight: 750; }
td { color: #334158; }
tbody tr:last-child td { border-bottom: 0; }
.platform-pill, .status-pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 999px; background: var(--blue-100); color: var(--blue-700); font-size: 11px; font-weight: 700; }
.status-pill.warning { background: var(--warning-bg); color: var(--warning); }
.pagination { margin-top: 16px; display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.pagination button:disabled { cursor: not-allowed; opacity: .45; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef3f9; }
.login-shell { width: min(430px, 100%); }
.login-card { padding: 34px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 18px 44px rgba(27, 47, 79, .1); }
.login-card .brand-mark { margin-bottom: 22px; }
.login-card h1 { margin-bottom: 12px; font-size: 28px; }
.login-card > .muted { margin-bottom: 22px; line-height: 1.7; font-size: 13px; }
.login-form { display: grid; gap: 14px; }
.login-form .primary-button { margin-top: 6px; }
.form-error { margin-bottom: 16px; padding: 10px 12px; color: var(--danger); background: var(--danger-bg); border-radius: 7px; font-size: 13px; }

@media (max-width: 1050px) {
  .filter-form { grid-template-columns: repeat(2, 1fr); }
  .filter-form.events-mode { grid-template-columns: repeat(2, 1fr); }
  .filter-submit { min-width: 130px; }
  .breakdown-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .dashboard-layout { grid-template-columns: 1fr; }
  .sidebar { top: 72px; z-index: 10; min-height: 0; padding: 9px 12px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-caption { display: none; }
  .sidebar-nav { min-width: 480px; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .nav-item { min-height: 40px; justify-content: center; white-space: nowrap; }
  .dashboard-shell { width: min(100% - 28px, 1320px); margin-top: 16px; }
}

@media (max-width: 720px) {
  .topbar { padding: 12px 16px; }
  .topbar .eyebrow { display: none; }
  .account-row .muted { display: none; }
  .sidebar { top: 68px; }
  .dashboard-shell { width: min(100% - 24px, 1320px); margin-top: 14px; }
  .filter-panel, .chart-card, .table-card { padding: 16px; }
  .filter-form { grid-template-columns: 1fr; }
  .filter-form.events-mode { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-card { padding: 15px; }
  .kpi-card strong { font-size: 26px; }
  .card-heading { display: grid; }
  .table-heading .link-button { justify-self: start; }
  .legend { white-space: normal; }
  .rank-row { grid-template-columns: 96px 1fr; }
  .rank-value { grid-column: 2; text-align: left; }
}
