:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eaeef5;
  --text: #172238;
  --text-secondary: #3d4a60;
  --text-muted: #566279;
  --border: #dde3ed;
  --primary: #3159db;
  --primary-solid: #3159db;
  --on-primary: #ffffff;
  --primary-soft: #e6ecfd;
  --accent: #d8ef9e;
  --accent-ink: #172238;
  --positive: #1d7a3e;
  --positive-soft: #e3f4e8;
  --negative: #b42e27;
  --negative-soft: #fbe7e5;
  --chart-1: #3159db;
  --chart-2: #9aa7bf;
  --heat-0: #eef1f7;
  --heat-rgb: 49, 89, 219;
  --shadow: 0 1px 2px rgba(23, 34, 56, .04), 0 10px 28px -16px rgba(23, 34, 56, .18);
  --radius: 18px;
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1320;
  --surface: #151d2d;
  --surface-2: #1f2a3e;
  --text: #e8edf6;
  --text-secondary: #c0cadb;
  --text-muted: #9aa6bb;
  --border: #263247;
  --primary: #8eabff;
  --primary-solid: #8eabff;
  --on-primary: #0d1530;
  --primary-soft: #1d2a4d;
  --accent: #d8ef9e;
  --accent-ink: #172238;
  --positive: #7fd69a;
  --positive-soft: #163222;
  --negative: #ff8a80;
  --negative-soft: #3a1d1b;
  --chart-1: #8eabff;
  --chart-2: #56637a;
  --heat-0: #1a2335;
  --heat-rgb: 142, 171, 255;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0d1320;
    --surface: #151d2d;
    --surface-2: #1f2a3e;
    --text: #e8edf6;
    --text-secondary: #c0cadb;
    --text-muted: #9aa6bb;
    --border: #263247;
    --primary: #8eabff;
    --primary-solid: #8eabff;
    --on-primary: #0d1530;
    --primary-soft: #1d2a4d;
    --accent: #d8ef9e;
    --accent-ink: #172238;
    --positive: #7fd69a;
    --positive-soft: #163222;
    --negative: #ff8a80;
    --negative-soft: #3a1d1b;
    --chart-1: #8eabff;
    --chart-2: #56637a;
    --heat-0: #1a2335;
    --heat-rgb: 142, 171, 255;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
a { color: var(--primary); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

.boot { min-height: 100vh; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--text-muted); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.02em; }
.brand__mark { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 11px; background: #172238; color: #fff; font-weight: 800; font-size: 15px; }
.brand__mark span { color: var(--accent); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; line-height: 1.25; transition: transform .15s, background .2s; }
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--primary-solid); border-color: var(--primary-solid); color: var(--on-primary); }
.btn--danger-soft { background: var(--negative-soft); border-color: transparent; color: var(--negative); }
.btn--small { min-height: 40px; padding: 0 14px; border-radius: 12px; font-size: 14px; }
.btn--block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--text-secondary); font-size: 18px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.link-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; border: 0; background: none; color: var(--primary); font-weight: 600; font-size: 14px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login__card { width: min(100%, 400px); background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 32px 28px; box-shadow: var(--shadow); display: grid; gap: 18px; }
.login__card h1 { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-top: 8px; }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.field input { min-height: 48px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); padding: 0 14px; font-weight: 500; }
.form-error { color: var(--negative); background: var(--negative-soft); border-radius: 12px; padding: 10px 14px; font-size: 14px; }

.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.topbar__inner { max-width: 1320px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 14px; }
.topbar__actions { margin-left: auto; display: flex; gap: 2px; }
.live-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-weight: 700; font-size: 14px; }
.live-pill__label { font-weight: 500; color: var(--text-muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #2fb36a; box-shadow: 0 0 0 0 rgba(47, 179, 106, .5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(47, 179, 106, 0); } 100% { box-shadow: 0 0 0 0 rgba(47, 179, 106, 0); } }

.shell { max-width: 1320px; margin: 0 auto; padding: 20px 20px 48px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.shell > * { animation: rise .5s cubic-bezier(.2, .8, .2, 1) backwards; }
.shell > *:nth-child(2) { animation-delay: .04s; }
.shell > *:nth-child(3) { animation-delay: .08s; }
.shell > *:nth-child(4) { animation-delay: .12s; }
.shell > *:nth-child(5) { animation-delay: .16s; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.segmented { display: inline-flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.segmented button { min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent; color: var(--text-secondary); font-weight: 600; font-size: 14px; white-space: nowrap; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(23, 34, 56, .12); }
.segmented--small button { min-height: 40px; padding: 0 12px; font-size: 13px; }
.chip-row { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.custom-range { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.custom-range input, .select-wrap select { min-height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); padding: 0 10px; }
.range-label { color: var(--text-muted); font-size: 14px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.filters:empty { display: none; }
.filter-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 6px 0 14px; border-radius: 999px; border: 0; background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: 14px; }
.filter-chip i { display: inline-flex; width: 28px; height: 28px; align-items: center; justify-content: center; border-radius: 50%; }
.filter-chip:hover i { background: var(--surface); }

.empty-banner { display: flex; gap: 14px; align-items: flex-start; padding: 18px 20px; border-radius: var(--radius); background: var(--surface); border: 1px dashed var(--border); }
.empty-banner i { font-size: 22px; color: var(--primary); }
.empty-banner p { color: var(--text-muted); margin-top: 4px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 18px 16px; box-shadow: var(--shadow); display: grid; gap: 6px; align-content: start; }
.kpi__label { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.kpi__value { font-size: 30px; font-weight: 800; letter-spacing: -.03em; line-height: 1.15; }
.kpi__foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--text-muted); }
.delta { display: inline-flex; align-items: center; gap: 2px; padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 12px; background: var(--surface-2); color: var(--text-secondary); }
.delta--up { background: var(--positive-soft); color: var(--positive); }
.delta--down { background: var(--negative-soft); color: var(--negative); }
.kpi--skeleton .kpi__value, .skeleton-line { background: var(--surface-2); border-radius: 8px; color: transparent; animation: shimmer 1.2s ease-in-out infinite alternate; }
@keyframes shimmer { to { opacity: .55; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; display: flex; flex-direction: column; min-width: 0; }
.card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card__head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.card__controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card__foot { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.card--wide { grid-column: 1 / -1; }
.chart { min-height: 300px; margin: 0 -8px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { min-height: 40px; padding: 0 10px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-muted); font-weight: 600; font-size: 14px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--primary); }

.list { display: grid; gap: 2px; padding-bottom: 8px; }
.list__head, .row { display: grid; grid-template-columns: minmax(0, 1fr) repeat(var(--cols, 2), 72px); gap: 8px; align-items: center; }
.list__head { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); padding: 0 10px 6px; }
.list__head span:not(:first-child), .row span:not(:first-child) { text-align: right; }
.row { position: relative; min-height: 44px; padding: 0 10px; border: 0; border-radius: 10px; background: none; text-align: left; font-size: 14px; z-index: 0; width: 100%; }
.row::before { content: ''; position: absolute; inset: 4px auto 4px 0; width: var(--bar, 0%); background: var(--primary-soft); border-radius: 8px; z-index: -1; transform-origin: left; animation: grow .7s cubic-bezier(.2, .8, .2, 1) backwards; }
@keyframes grow { from { transform: scaleX(0); } }
.row:hover { background: var(--surface-2); }
.row__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.row__label small { font-weight: 500; color: var(--text-muted); margin-left: 6px; }
.row span:not(:first-child) { color: var(--text-secondary); }
.list-empty { padding: 28px 10px; text-align: center; color: var(--text-muted); }
.list-empty i { display: block; font-size: 24px; margin-bottom: 6px; }

.funnel { display: grid; gap: 12px; }
.funnel__step { display: grid; gap: 6px; }
.funnel__top { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.funnel__top strong { font-weight: 700; }
.funnel__bar { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.funnel__bar span { display: block; height: 100%; border-radius: inherit; background: var(--primary-solid); transform-origin: left; animation: grow .8s cubic-bezier(.2, .8, .2, 1) backwards; }
.funnel__meta { font-size: 13px; color: var(--text-muted); }

.goals { display: grid; gap: 10px; }
.goal { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 12px 14px; border-radius: 14px; background: var(--surface-2); }
.goal__name { font-weight: 700; font-size: 14px; }
.goal__value { font-weight: 800; font-size: 18px; text-align: right; }
.goal__meta { font-size: 13px; color: var(--text-muted); grid-column: 1 / -1; }

.realtime { display: grid; gap: 14px; }
.realtime__top { display: flex; align-items: baseline; gap: 10px; }
.realtime__big { font-size: 42px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.realtime__bars { display: grid; grid-template-columns: repeat(30, 1fr); align-items: end; gap: 3px; height: 70px; }
.realtime__bars span { background: var(--primary-solid); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.realtime__axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }
.realtime__pages { display: grid; gap: 6px; font-size: 14px; }
.realtime__pages div { display: flex; justify-content: space-between; gap: 10px; }
.realtime__pages span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.heatmap { display: grid; grid-template-columns: 40px repeat(24, minmax(0, 1fr)); gap: 3px; font-size: 12px; overflow-x: auto; }
.heatmap__day { display: flex; align-items: center; color: var(--text-muted); font-weight: 600; }
.heatmap__hour { text-align: center; color: var(--text-muted); }
.heatmap__cell { aspect-ratio: 1.4; min-width: 14px; border-radius: 4px; background: var(--heat-0); }
.heatmap__legend { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 8px; color: var(--text-muted); }
.heatmap__legend i { width: 14px; height: 10px; border-radius: 3px; display: inline-block; }

.sheet-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(13, 19, 32, .45); backdrop-filter: blur(4px); display: flex; align-items: flex-end; justify-content: center; animation: fade .25s ease; }
.sheet { width: min(100%, 560px); max-height: 92vh; overflow: auto; background: var(--surface); border-radius: 28px 28px 0 0; padding: 8px 22px calc(24px + env(safe-area-inset-bottom)); animation: up .3s cubic-bezier(.2, .8, .2, 1); }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; }
.sheet__head h2 { font-size: 20px; font-weight: 800; }
.sheet__body { display: grid; gap: 12px; }
.sheet__actions { display: flex; gap: 10px; flex-wrap: wrap; }
.group-label { margin-top: 12px; font-size: 12px; font-weight: 700; letter-spacing: .05em; color: var(--text-muted); }
.token-box { display: grid; gap: 8px; padding: 14px; border-radius: 14px; background: var(--surface-2); }
.token-box code { display: block; padding: 10px 12px; border-radius: 10px; background: var(--surface); font-size: 13px; overflow-wrap: anywhere; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) { .sheet-overlay { align-items: center; } .sheet { border-radius: 28px; } }

.toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 60; padding: 12px 18px; border-radius: 14px; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(14px); border: 1px solid var(--border); border-left: 4px solid var(--primary); box-shadow: var(--shadow); font-weight: 600; max-width: calc(100% - 32px); }
.toast--error { border-left-color: var(--negative); }

.apexcharts-tooltip { box-shadow: var(--shadow) !important; border: 1px solid var(--border) !important; background: var(--surface) !important; color: var(--text) !important; }
.apexcharts-tooltip-title { background: var(--surface-2) !important; border-bottom: 1px solid var(--border) !important; }

@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 600px) {
  .topbar__inner, .shell { padding-left: 16px; padding-right: 16px; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi__value { font-size: 24px; }
  .live-pill__label { display: none; }
  .card { padding: 16px; }
  .list__head, .row { grid-template-columns: minmax(0, 1fr) repeat(var(--cols, 2), 60px); gap: 6px; padding-inline: 8px; }
  .list__head { font-size: 11px; letter-spacing: .01em; }
  .chart { min-height: 240px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
