*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── DESIGN TOKENS ─────────────────────────────────────────────────────────── */
:root {
    --bg:              #f5f5f4;
    --surface:         #ffffff;
    --border:          #e8e8e6;
    --text-primary:    #111110;
    --text-secondary:  #888885;
    --text-muted:      #b5b3ad;
    --accent:          #111110;
    --accent-green:    #16a34a;
    --accent-red:      #dc2626;
    --accent-blue:     #2563eb;
    --accent-amber:    #d97706;
    --shadow-sm:       0 1px 2px rgba(0,0,0,.05);
    --shadow-md:       0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
    --shadow-lg:       0 4px 6px rgba(0,0,0,.05), 0 16px 48px rgba(0,0,0,.1);
    --radius:          12px;
    --radius-sm:       8px;
    --font:            'Geist', system-ui, sans-serif;
    --sidebar-width:   220px;
}

/* ── BASE ───────────────────────────────────────────────────────────────────── */
body {
    background: var(--bg);
    font-family: var(--font);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }

/* ── LAYOUT ─────────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── SIDEBAR ────────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}
.logo-icon {
    width: 30px; height: 30px;
    background: var(--accent);
    border-radius: 7px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.logo-icon svg { width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 2; }
.logo-text { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.logo-badge {
    font-size: 10px; background: #f0f0ef; color: var(--text-secondary);
    padding: 1px 6px; border-radius: 20px; font-weight: 500; margin-left: auto;
}
.nav-label {
    font-size: 10px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .7px;
    padding: 0 10px; margin-bottom: 4px; margin-top: 14px;
}
.nav-item {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 10px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-size: 13.5px; font-weight: 500;
    cursor: pointer; transition: all .15s; text-decoration: none;
    border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--bg); color: var(--text-primary); }
.nav-item.active { background: var(--bg); color: var(--text-primary); font-weight: 600; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .65; }
.nav-item.active svg { opacity: 1; }
.sidebar-footer {
    margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border);
}
.sidebar-user {
    display: flex; align-items: center; gap: 9px; padding: 8px 10px; margin-bottom: 4px;
}
.sidebar-user-avatar {
    width: 28px; height: 28px; background: var(--accent); border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.sidebar-user-name { font-size: 12.5px; font-weight: 600; color: var(--text-primary); }
.sidebar-user-role { font-size: 11px; color: var(--text-muted); }
.logout-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 10px; border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 13px; font-weight: 500;
    cursor: pointer; transition: all .15s; text-decoration: none;
    width: 100%; border: none; background: none; font-family: var(--font);
}
.logout-btn:hover { color: var(--accent-red); background: #fef2f2; }
.logout-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* ── MAIN ───────────────────────────────────────────────────────────────────── */
.main { flex: 1; min-width: 0; padding: 28px 32px; }

/* ── TOPBAR ─────────────────────────────────────────────────────────────────── */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 28px; flex-wrap: wrap; gap: 12px;
}
.topbar-title { font-size: 22px; font-weight: 600; letter-spacing: -.3px; }
.topbar-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.search-wrap {
    display: flex; align-items: center; gap: 8px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 7px 12px; width: 220px;
    transition: border-color .15s;
}
.search-wrap:focus-within { border-color: #aaa; }
.search-wrap svg { width: 14px; height: 14px; stroke: var(--text-muted); flex-shrink: 0; }
.search-input {
    border: none; outline: none; font-family: var(--font);
    font-size: 13px; color: var(--text-primary); background: transparent; width: 100%;
}
.search-input::placeholder { color: var(--text-muted); }

/* ── BUTTONS ────────────────────────────────────────────────────────────────── */
.export-btn {
    display: flex; align-items: center; gap: 7px;
    background: var(--accent); color: #fff; border: none;
    border-radius: var(--radius-sm); padding: 8px 14px;
    font-size: 13px; font-weight: 500; cursor: pointer;
    font-family: var(--font); text-decoration: none; transition: background .15s;
}
.export-btn:hover { background: #333; }
.export-btn svg { width: 14px; height: 14px; fill: none; stroke: #fff; stroke-width: 2; }

.btn-primary {
    background: var(--accent); color: #fff; border: none;
    border-radius: var(--radius-sm); padding: 8px 16px;
    font-size: 13px; font-weight: 500; cursor: pointer;
    font-family: var(--font); transition: background .15s;
    display: inline-flex; align-items: center; gap: 7px;
}
.btn-primary:hover { background: #333; }
.btn-secondary {
    background: none; color: var(--text-secondary);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 7px 14px; font-size: 13px; font-weight: 500; cursor: pointer;
    font-family: var(--font); transition: all .15s;
    display: inline-flex; align-items: center; gap: 7px;
}
.btn-secondary:hover { border-color: #aaa; color: var(--text-primary); }
.btn-apply {
    background: var(--accent); color: #fff; border: none;
    border-radius: var(--radius-sm); padding: 8px 16px;
    font-size: 13px; font-weight: 500; cursor: pointer; font-family: var(--font); transition: background .15s;
}
.btn-apply:hover { background: #333; }
.btn-reset {
    background: none; color: var(--text-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 7px 14px; font-size: 13px; font-weight: 500;
    cursor: pointer; font-family: var(--font); text-decoration: none; transition: all .15s;
}
.btn-reset:hover { border-color: #aaa; color: var(--text-primary); }

/* ── CARDS ──────────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); }
.card-pad { padding: 20px 22px; }

/* ── KPI ────────────────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 14px; }
.kpi-card { padding: 18px 20px; }
.kpi-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.kpi-value { font-size: 28px; font-weight: 700; color: var(--text-primary); letter-spacing: -.5px; line-height: 1; }
.kpi-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.kpi-delta {
    display: inline-flex; align-items: center; gap: 3px;
    font-size: 11px; font-weight: 600; padding: 2px 7px;
    border-radius: 20px; margin-top: 8px;
}
.kpi-delta.up      { background: #dcfce7; color: var(--accent-green); }
.kpi-delta.down    { background: #fee2e2; color: var(--accent-red); }
.kpi-delta.neutral { background: #f5f5f4; color: var(--text-muted); }

/* Period buttons */
.period-btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.period-btn {
    padding: 6px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text-muted); font-size: 12px; font-weight: 500;
    cursor: pointer; font-family: var(--font); transition: all .18s;
}
.period-btn:hover { border-color: var(--accent); color: var(--accent); }
.period-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── GRIDS ──────────────────────────────────────────────────────────────────── */
.grid-2   { display: grid; grid-template-columns: 1fr 1fr;     gap: 20px; margin-bottom: 20px; }
.grid-3   { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.grid-3-1 { display: grid; grid-template-columns: 2fr 1fr;     gap: 20px; margin-bottom: 20px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr;     gap: 20px; margin-bottom: 20px; }

/* ── SECTION HEADER ─────────────────────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title  { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.section-sub    { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── FILTER BAR ─────────────────────────────────────────────────────────────── */
.filter-bar {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 20px; margin-bottom: 20px;
    display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.filter-select, .filter-input {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 7px 10px; font-size: 13px; font-family: var(--font);
    color: var(--text-primary); background: var(--bg); outline: none; transition: border-color .15s;
}
.filter-select:focus, .filter-input:focus { border-color: #aaa; }

/* ── TABLE ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
    text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .4px; padding: 10px 12px;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid var(--border); color: var(--text-primary); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafaf9; }

/* ── BADGES & PILLS ─────────────────────────────────────────────────────────── */
.src-pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 20px; background: #f0f0ef; color: var(--text-primary); }
.src-pill.no-utm  { background: #fef3c7; color: #92400e; }
.src-pill.paid    { background: #ede9fe; color: #6d28d9; }
.src-pill.organic { background: #dcfce7; color: #15803d; }
.src-pill.direct  { background: #e0f2fe; color: #0369a1; }

.badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.badge-green { background: #dcfce7; color: var(--accent-green); }
.badge-red   { background: #fee2e2; color: var(--accent-red); }
.badge-blue  { background: #dbeafe; color: var(--accent-blue); }
.badge-amber { background: #fef3c7; color: var(--accent-amber); }
.badge-gray  { background: #f0f0ef; color: var(--text-secondary); }

/* ── EVENT CHIPS ────────────────────────────────────────────────────────────── */
.events-filter { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.event-chip {
    display: inline-flex; align-items: center; gap: 5px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
    padding: 5px 10px; font-size: 12px; font-weight: 500; cursor: pointer;
    transition: all .15s; color: var(--text-secondary);
}
.event-chip:hover { border-color: #aaa; color: var(--text-primary); }
.event-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.event-chip .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

/* ── CHART ──────────────────────────────────────────────────────────────────── */
.chart-full { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; margin-bottom: 20px; }
.chart-wrap canvas { width: 100% !important; }
.group-btns { display: flex; gap: 4px; }
.group-btn {
    padding: 5px 12px; border-radius: 6px; font-size: 12px; font-weight: 500;
    color: var(--text-secondary); border: 1px solid var(--border); background: var(--bg);
    cursor: pointer; transition: all .15s; font-family: var(--font); text-decoration: none;
}
.group-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── MODAL ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.4); backdrop-filter: blur(2px);
    z-index: 1000; display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 680px; max-height: 85vh; overflow-y: auto; position: relative;
}
.modal-header {
    padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
    display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
    width: 28px; height: 28px; border-radius: 6px; border: none; background: var(--bg);
    cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s;
}
.modal-close:hover { background: #e8e8e6; }
.modal-close svg { width: 14px; height: 14px; stroke: var(--text-secondary); stroke-width: 2; fill: none; }
.modal-body { padding: 20px 24px; }

/* ── LOGIN PAGE ─────────────────────────────────────────────────────────────── */
body.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box {
    background: var(--surface); border-radius: 16px; padding: 40px; width: 380px;
    box-shadow: var(--shadow-lg); border: 1px solid var(--border);
}
.login-logo { font-size: 16px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.login-logo .logo-icon { width: 34px; height: 34px; border-radius: 8px; }
.login-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 28px; }
.login-error { background: #fef2f2; color: var(--accent-red); font-size: 13px; padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid #fecaca; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .4px; }
.login-field input { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; font-size: 14px; font-family: var(--font); outline: none; transition: border-color .2s; background: var(--bg); color: var(--text-primary); }
.login-field input:focus { border-color: #aaa; background: var(--surface); }
.login-btn { width: 100%; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); padding: 11px; font-size: 14px; font-weight: 500; cursor: pointer; margin-top: 8px; font-family: var(--font); transition: background .2s; }
.login-btn:hover { background: #333; }
.login-success { background: #f0fdf4; color: #15803d; font-size: 13px; padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid #bbf7d0; line-height: 1.5; }
.site-selector { padding: 4px 16px 12px; }
.site-selector select { width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 10px; font-size: 13px; font-family: var(--font); background: var(--bg); color: var(--text-primary); cursor: pointer; outline: none; }
.site-selector select:focus { border-color: #aaa; }
.site-selector-empty { font-size: 12px; color: var(--text-secondary); padding: 8px 16px 12px; }
.login-alt { margin-top: 18px; font-size: 13px; color: var(--text-secondary); text-align: center; }
.login-alt a { color: var(--text-primary); font-weight: 500; }

/* ── UTM ────────────────────────────────────────────────────────────────────── */
.utm-period-btn { border: 1px solid var(--border); background: var(--bg); border-radius: 6px; padding: 4px 10px; font-size: 11px; font-weight: 500; font-family: var(--font); color: var(--text-secondary); cursor: pointer; transition: all .15s; }
.utm-period-btn:hover { border-color: #aaa; color: var(--text-primary); }
.utm-period-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.leads-count-link { color: var(--accent-green); font-weight: 700; cursor: pointer; text-decoration: underline dotted; transition: color .15s; }
.leads-count-link:hover { color: #15803d; }

/* ── UTILITY ────────────────────────────────────────────────────────────────── */
.text-muted     { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-green     { color: var(--accent-green); }
.text-red       { color: var(--accent-red); }
.text-blue      { color: var(--accent-blue); }
.text-amber     { color: var(--accent-amber); }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fs-12  { font-size: 12px; }
.fs-13  { font-size: 13px; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mt-20  { margin-top: 20px; }
.mb-16  { margin-bottom: 16px; }
.mb-20  { margin-bottom: 20px; }
.mb-24  { margin-bottom: 24px; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── SCROLLBAR ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* ── Унифицированные ячейки таблиц пользователей (v13) ─────────────────── */
.wa-pv-badge {
    display: inline-block; min-width: 26px; text-align: center;
    padding: 2px 7px; border-radius: 6px;
    background: #f1f5f9; color: #334155; font-weight: 600; font-size: 12px;
}
.wa-inapp-chip {
    display: inline-block; padding: 1px 7px; border-radius: 10px;
    background: #eef2ff; color: #4338ca; font-size: 11px; font-weight: 500;
    white-space: nowrap;
}
.wa-inapp-trans {
    display: inline-block; padding: 1px 7px; border-radius: 10px;
    background: #ecfdf5; color: #047857; font-size: 11px; font-weight: 600;
    white-space: nowrap;
}
