:root {
    --bg: #0b0e14;
    --bg-raised: #131824;
    --bg-hover: #1a2130;
    --border: #232b3d;
    --text: #e6eaf2;
    --text-muted: #8b95ad;
    --accent: #6ea8fe;
    --accent-soft: rgba(110, 168, 254, 0.14);
    --success: #4ade80;
    --danger: #f87171;
    --warning: #fbbf24;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.22);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.02rem; }

.muted { color: var(--text-muted); font-size: 0.86rem; margin: 0.25rem 0 0; }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.5rem;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.7rem; }

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px; height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6ea8fe, #a78bfa);
    color: #0b0e14;
    font-weight: 800;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}

.brand-name { font-weight: 600; }
.brand-name em { color: var(--text-muted); font-style: normal; font-weight: 500; }

.topbar-actions { display: flex; align-items: center; gap: 0.6rem; }

/* ---------- Controls ---------- */

select, input[type="text"], input[type="password"] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.45rem 0.7rem;
    font: inherit;
    font-size: 0.88rem;
}

select:focus-visible, input:focus-visible, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button {
    font: inherit;
    font-size: 0.88rem;
    border-radius: 9px;
    border: 1px solid transparent;
    padding: 0.45rem 0.9rem;
    background: var(--accent);
    color: #08111f;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s ease, background 0.15s ease;
}

button:hover { filter: brightness(1.08); }

.ghost, a.ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
    display: inline-block;
    font-weight: 500;
}

.ghost:hover, a.ghost:hover { background: var(--bg-hover); filter: none; }

/* ---------- Tabs ---------- */

.tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0 1.5rem;
    background: var(--bg-raised);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    color: var(--text-muted);
    padding: 0.7rem 0.9rem;
    font-weight: 500;
    white-space: nowrap;
}

.tab:hover { color: var(--text); filter: none; }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Layout ---------- */

main { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }

.view { display: none; }
.view.is-active { display: block; animation: fade 0.18s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.panel {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem;
    margin-bottom: 1.15rem;
    box-shadow: var(--shadow);
}

.panel-head { margin-bottom: 1rem; }

.panel-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 1.15rem;
}

.panel-row .panel { margin-bottom: 1.15rem; }

/* ---------- Stat cards ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.9rem;
    margin-bottom: 1.15rem;
}

.stat {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.stat-value { font-size: 1.75rem; font-weight: 650; margin-top: 0.35rem; letter-spacing: -0.02em; }

.stat-delta { font-size: 0.8rem; margin-top: 0.2rem; color: var(--text-muted); }
.stat-delta.up { color: var(--success); }
.stat-delta.down { color: var(--danger); }

/* ---------- Charts ---------- */

.chart-wrap { position: relative; height: 280px; }
.chart-wrap.chart-tall { height: 360px; }

.prop-picker {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    margin: 1.15rem 0 0.75rem;
}

.prop-picker-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.prop-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.prop-chip {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 0.4rem 0.85rem;
    font-size: 0.86rem;
    font-weight: 500;
    cursor: pointer;
}

.prop-chip:hover { background: var(--bg-hover); filter: none; }

.prop-chip.is-active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text);
}

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }

th, td {
    text-align: left;
    padding: 0.55rem 0.7rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody tr:hover { background: var(--bg-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

tr.is-selected { background: var(--accent-soft); }
tr[data-event] { cursor: pointer; }

.mono {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ---------- Events split view ---------- */

.split { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; gap: 1.15rem; }

@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.detail { border-left: 1px solid var(--border); padding-left: 1.15rem; min-height: 240px; }

@media (max-width: 900px) { .detail { border-left: none; padding-left: 0; } }

.empty { color: var(--text-muted); font-size: 0.88rem; }

.prop-group { margin-top: 1rem; }
.prop-group h3 { font-size: 0.82rem; color: var(--accent); margin-bottom: 0.35rem; }

/* ---------- Bar lists ---------- */

.bar-list { display: flex; flex-direction: column; gap: 0.6rem; }

.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem 0.75rem; align-items: center; }
.bar-row .label { font-size: 0.86rem; }
.bar-row .count { font-size: 0.86rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.bar-track {
    grid-column: 1 / -1;
    height: 6px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
}

.bar-fill { height: 100%; background: linear-gradient(90deg, #6ea8fe, #a78bfa); border-radius: 999px; }

/* ---------- Retention grid ---------- */

.retention-cell {
    text-align: center;
    font-variant-numeric: tabular-nums;
    border-radius: 6px;
}

.retention-cell.empty-cell { color: var(--text-muted); opacity: 0.35; }

/* ---------- Funnels ---------- */

.funnel-steps { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.8rem; }

.funnel-step { display: flex; align-items: center; gap: 0.5rem; }
.funnel-step select { flex: 1; max-width: 420px; }

.funnel-controls { display: flex; gap: 0.5rem; }

.funnel-result { margin-top: 1.25rem; display: flex; flex-direction: column; gap: 0.6rem; }

.funnel-bar { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.9rem; position: relative; overflow: hidden; }
.funnel-bar .fill { position: absolute; inset: 0 auto 0 0; background: var(--accent-soft); }
.funnel-bar .content { position: relative; display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.funnel-bar .step-name { font-weight: 600; }
.funnel-bar .step-stats { font-size: 0.84rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- Pager ---------- */

.pager { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.9rem; }

/* ---------- Alerts ---------- */

.alert {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #fecaca;
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    margin-bottom: 1rem;
    font-size: 0.88rem;
}

/* ---------- Login ---------- */

.login-body { display: grid; place-items: center; min-height: 100vh; padding: 1.5rem; }

.login-card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    width: min(380px, 100%);
    box-shadow: var(--shadow);
}

.login-mark {
    display: grid;
    place-items: center;
    width: 44px; height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #6ea8fe, #a78bfa);
    color: #0b0e14;
    font-weight: 800;
    margin-bottom: 1rem;
}

.login-card form { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 1.25rem; }
.login-card label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; margin-top: 0.5rem; }
.login-card button { margin-top: 1.1rem; padding: 0.6rem; }
