:root {
  --bg: #ffffff;
  --card: #ffffff;
  --line: #eceef2;
  --line-soft: #f3f4f6;
  --text: #0b1220;
  --muted: #6b7280;
  --muted2: #9ca3af;
  --accent: #0b1220;
  --accent-soft: #f4f5f7;
  --green: #0c9b6a;
  --green-soft: #e7f8f1;
  --blue: #1d4ed8;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 28px rgba(15, 23, 42, 0.04);
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: #ffffff;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(32px + var(--safe-b));
  background: #ffffff;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: #ffffff;
}

.top { padding: 22px 18px 8px; }

.brand {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1.1;
  color: var(--text);
}

.sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.4;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 18px 4px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
#periods { padding-top: 6px; padding-bottom: 16px; }

.tab {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 0 14px;
  font: 600 13px/1 Inter, system-ui, sans-serif;
  letter-spacing: -0.01em;
  transition: background .18s ease, color .18s ease, border-color .18s ease, transform .15s ease, box-shadow .18s ease;
}
.tab:active { transform: scale(0.98); }
.tab.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
  box-shadow: 0 8px 18px rgba(11, 18, 32, 0.18);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 18px 14px;
}
.stats.compact { padding: 0 0 14px; }

@media (min-width: 900px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: "";
  position: absolute;
  right: -20px;
  top: -24px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(12, 155, 106, 0.12), transparent 70%);
  pointer-events: none;
}
.stat .k {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.01em;
  position: relative;
}
.stat .v {
  margin-top: 8px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.055em;
  color: var(--text);
  line-height: 1;
  position: relative;
}

.app {
  padding: 0 18px;
  display: grid;
  gap: 12px;
}

@media (min-width: 1100px) {
  .app {
    grid-template-columns: 1fr 1fr;
  }
  .app .card.wide,
  .app .card:last-child {
    grid-column: 1 / -1;
  }
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.chart-box {
  position: relative;
  height: 148px;
}
.chart-box canvas,
.chart-wrap canvas {
  max-height: 100%;
}

.chart-wrap {
  position: relative;
}
.chart-wrap.donut {
  height: 176px;
  max-width: 280px;
  margin: 0 auto;
}

.chart-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
  padding-bottom: 4px;
}
.chart-center .cc-k {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.chart-center .cc-v {
  margin-top: 2px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--text);
  line-height: 1.1;
}
.chart-center .cc-s {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
}

.bar-track {
  margin-top: 6px;
  height: 4px;
  border-radius: 999px;
  background: var(--line-soft);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0c9b6a, #34d399);
}

.funnel { display: grid; gap: 8px; }
.funnel-row {
  display: grid;
  grid-template-columns: 110px 1fr 48px;
  gap: 10px;
  align-items: center;
  cursor: default;
}
.funnel-row:hover .fill {
  filter: brightness(1.05);
}
.funnel-row .label {
  font-size: 13px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.funnel-row .track {
  height: 10px;
  border-radius: 999px;
  background: var(--line-soft);
  overflow: hidden;
}
.funnel-row .fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0c9b6a, #34d399);
}
.funnel-row .cnt {
  text-align: right;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.03em;
  color: var(--green);
}

.list { display: grid; gap: 0; max-height: 520px; overflow: auto; }

.item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line-soft);
}
.item:first-child { border-top: 0; padding-top: 2px; }

.rank {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
}
.item:nth-child(-n+3) .rank {
  background: var(--green-soft);
  color: var(--green);
}

.item .name {
  font-weight: 650;
  font-size: 13.5px;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.item .cat {
  color: var(--muted2);
  font-size: 11.5px;
  margin-top: 3px;
  font-weight: 500;
}
.item .cnt {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.03em;
  color: var(--green);
}

.muted-line {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.err {
  margin: 4px 0;
  padding: 16px;
  border-radius: 14px;
  border: 1px dashed var(--line);
  background: #fff;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 500;
}

.auth {
  padding: 18px;
  max-width: 420px;
  margin: 0 auto;
}
.auth-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: 500 14px Inter, system-ui, sans-serif;
  margin-bottom: 10px;
}
.auth-hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  min-height: 44px;
  background: var(--text);
  color: #fff;
  font: 700 14px Inter, system-ui, sans-serif;
  cursor: pointer;
}
.btn:active { transform: scale(0.99); }

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 650;
  background: var(--accent-soft);
  color: var(--muted);
  margin-right: 4px;
}
.pill.ok { background: var(--green-soft); color: var(--green); }
.pill.warn { background: #fff7ed; color: #c2410c; }
