:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --surface-accent: #f0f7ff;
    --text: #172033;
    --text-soft: #667085;
    --text-muted: #98a2b3;
    --border: #e4e7ec;
    --border-strong: #d0d5dd;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #15803d;
    --success-soft: #ecfdf3;
    --warning: #b45309;
    --warning-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --info: #0369a1;
    --info-soft: #f0f9ff;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-md: 0 12px 28px rgba(15, 23, 42, .08);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --max-width: 1440px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--bg); }

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 12% -10%, rgba(37, 99, 235, .08), transparent 34rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
.logout-form { margin: 0; }
a { color: inherit; }

:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .22);
    outline-offset: 2px;
}

.app-shell { min-height: 100vh; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid rgba(228, 231, 236, .9);
    background: rgba(255, 255, 255, .88);
    backdrop-filter: blur(16px);
}

.topbar-inner {
    max-width: var(--max-width);
    min-height: 68px;
    margin: 0 auto;
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    color: #fff;
    background: linear-gradient(145deg, #3b82f6, #1d4ed8);
    box-shadow: 0 8px 18px rgba(37, 99, 235, .23);
    font-size: 18px;
    font-weight: 800;
}
.brand-copy { display: grid; line-height: 1.2; }
.brand-name { font-size: 15px; font-weight: 750; letter-spacing: -.01em; }
.brand-product { margin-top: 3px; color: var(--text-soft); font-size: 12px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; }
.environment-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-soft);
    background: var(--surface);
    font-size: 12px;
    font-weight: 650;
}
.environment-pill::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 3px #dcfce7;
}

.page {
    width: min(100% - 40px, var(--max-width));
    margin: 0 auto;
    padding: 36px 0 64px;
}

.page-narrow { max-width: 980px; }
.page-header {
    margin-bottom: 26px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 22px;
}
.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 750;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.page-title, .auth-title {
    margin: 0;
    font-size: clamp(25px, 3vw, 34px);
    line-height: 1.16;
    letter-spacing: -.035em;
}
.page-subtitle, .auth-subtitle {
    max-width: 720px;
    margin: 8px 0 0;
    color: var(--text-soft);
    font-size: 15px;
}

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}
.card-header {
    padding: 22px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}
.card-body { padding: 24px; }
.section-title { margin: 0; font-size: 17px; letter-spacing: -.015em; }
.section-copy { margin: 5px 0 0; color: var(--text-soft); font-size: 13px; }

.btn {
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--primary); box-shadow: 0 7px 14px rgba(37, 99, 235, .17); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { border-color: var(--border-strong); color: #344054; background: var(--surface); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { border-color: #b8c0cc; background: var(--surface-soft); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: var(--danger-soft); }
.btn-danger:hover { background: #fee2e2; }
.btn-quiet { color: var(--text-soft); border-color: transparent; background: transparent; }
.btn-quiet:hover { color: var(--text); background: var(--surface-soft); }
.btn-sm { min-height: 34px; padding: 7px 10px; border-radius: 8px; font-size: 13px; }
.btn-block { width: 100%; }
.button-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }

.icon { width: 16px; height: 16px; display: inline-block; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { min-width: 0; display: grid; align-content: start; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field-label { color: #344054; font-size: 13px; font-weight: 700; }
.field-hint { margin: -2px 0 0; color: var(--text-muted); font-size: 12px; }
.input, .textarea, .select {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.input:hover, .textarea:hover, .select:hover { border-color: #aeb7c4; }
.input:focus, .textarea:focus, .select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, .1);
}
.textarea { min-height: 106px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }

.switch-row {
    min-height: 60px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--surface-soft);
}
.switch-copy { display: grid; gap: 2px; }
.switch-title { color: #344054; font-weight: 700; }
.switch-description { color: var(--text-soft); font-size: 12px; }
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { position: absolute; inset: 0; border-radius: 999px; background: #d0d5dd; cursor: pointer; transition: background .18s ease; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(16, 24, 40, .2); transition: transform .18s ease; }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid rgba(37, 99, 235, .2); outline-offset: 2px; }

.segmented {
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 11px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    background: var(--surface-soft);
}
.segment { position: relative; }
.segment input { position: absolute; opacity: 0; }
.segment span {
    min-height: 36px;
    padding: 8px 10px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
.segment input:checked + span { color: var(--primary); background: var(--surface); box-shadow: var(--shadow-sm); }
.segment input:focus-visible + span { outline: 3px solid rgba(37, 99, 235, .2); }

.routing-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.routing-card { padding: 18px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-soft); }
.routing-head { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.routing-name { font-weight: 800; }
.routing-role { color: var(--text-muted); font-size: 12px; }
.routing-fields { margin-top: 14px; display: grid; gap: 12px; }

.status-box {
    padding: 13px 14px;
    border: 1px solid #bae6fd;
    border-radius: 10px;
    color: #0c4a6e;
    background: var(--info-soft);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.status-error {
    border-color: #fecaca;
    background: #fff7f7;
    color: #991b1b;
}

.form-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.section-nav { position: sticky; top: 92px; padding: 10px; }
.section-nav a { padding: 10px 12px; border-radius: 9px; display: block; color: var(--text-soft); text-decoration: none; font-size: 13px; font-weight: 650; }
.section-nav a:hover { color: var(--primary); background: var(--primary-soft); }
.form-sections { display: grid; gap: 18px; }
.action-bar {
    position: sticky;
    bottom: 16px;
    z-index: 40;
    margin-top: 20px;
    padding: 13px;
    border: 1px solid rgba(208, 213, 221, .9);
    border-radius: 14px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    background: rgba(255, 255, 255, .92);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(14px);
}

.campaign-list { overflow: hidden; }
.campaign-row { padding: 18px 22px; display: grid; grid-template-columns: minmax(220px, 1.2fr) minmax(220px, 1fr) auto; align-items: center; gap: 20px; border-top: 1px solid var(--border); }
.campaign-row:first-child { border-top: 0; }
.campaign-row:hover { background: var(--surface-soft); }
.campaign-name { margin: 0; font-size: 15px; font-weight: 800; }
.campaign-id { margin-top: 4px; color: var(--text-muted); font-size: 12px; }
.campaign-host { color: #344054; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.campaign-actions { display: flex; justify-content: flex-end; align-items: center; gap: 7px; }

.stats-grid { margin-bottom: 18px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { padding: 18px; }
.stat-label { color: var(--text-soft); font-size: 12px; font-weight: 700; }
.stat-value { margin-top: 7px; font-size: 27px; font-weight: 800; letter-spacing: -.035em; }
.stat-note { margin-top: 3px; color: var(--text-muted); font-size: 12px; }

.toolbar { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 14px; }
.filter-row { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
.compact-field { display: grid; gap: 5px; }
.compact-field .input { min-height: 38px; padding: 8px 10px; }
.compact-field .field-label { font-size: 11px; color: var(--text-soft); }

.table-scroll { width: 100%; overflow: auto; }
.data-table { width: 100%; min-width: 1380px; border-collapse: separate; border-spacing: 0; }
.data-table th { position: sticky; top: 0; z-index: 2; padding: 11px 12px; border-bottom: 1px solid var(--border); color: var(--text-soft); background: var(--surface-soft); text-align: left; font-size: 11px; font-weight: 800; letter-spacing: .045em; text-transform: uppercase; white-space: nowrap; }
.data-table td { max-width: 240px; padding: 12px; border-bottom: 1px solid #eef0f3; color: #344054; vertical-align: top; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #fafcff; }
.data-table td.expandable { cursor: zoom-in; }
.data-table td.expanded { white-space: normal; overflow: visible; word-break: break-word; cursor: zoom-out; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.check { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.badge-offer { color: var(--success); background: var(--success-soft); }
.badge-white { color: var(--info); background: var(--info-soft); }
.badge-neutral { color: #475467; background: #f2f4f7; }
.reason-text { color: #7c2d12; }

.empty-state { padding: 64px 24px; text-align: center; }
.empty-icon { width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 15px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); font-size: 22px; }
.empty-title { margin: 0; font-size: 17px; }
.empty-copy { max-width: 440px; margin: 7px auto 18px; color: var(--text-soft); }

.alert { margin-bottom: 16px; padding: 11px 13px; border: 1px solid #fecaca; border-radius: 10px; color: #991b1b; background: var(--danger-soft); font-size: 13px; }
.alert:empty { display: none; }

.auth-page { min-height: 100vh; padding: 32px 20px; display: grid; place-items: center; }
.auth-shell { width: min(100%, 980px); display: grid; grid-template-columns: 1.05fr .95fr; overflow: hidden; }
.auth-visual { padding: 48px; display: flex; flex-direction: column; justify-content: space-between; color: #fff; background: linear-gradient(145deg, #1d4ed8, #2563eb 58%, #60a5fa); }
.auth-visual .brand-mark { background: rgba(255,255,255,.16); box-shadow: none; backdrop-filter: blur(10px); }
.auth-visual .brand-product { color: rgba(255,255,255,.72); }
.auth-pitch { max-width: 390px; margin: 72px 0; }
.auth-pitch h2 { margin: 0; font-size: clamp(28px, 4vw, 42px); line-height: 1.1; letter-spacing: -.045em; }
.auth-pitch p { margin: 16px 0 0; color: rgba(255,255,255,.75); font-size: 15px; }
.auth-meta { color: rgba(255,255,255,.65); font-size: 12px; }
.auth-form-panel { padding: 50px 46px; display: flex; flex-direction: column; justify-content: center; background: var(--surface); }
.auth-form { margin-top: 28px; display: grid; gap: 17px; }
.auth-footer { margin: 18px 0 0; color: var(--text-soft); text-align: center; font-size: 13px; }
.auth-footer a { color: var(--primary); font-weight: 750; text-decoration: none; }

.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; }
.mobile-only { display: none; }

@media (max-width: 980px) {
    .form-layout { grid-template-columns: 1fr; }
    .section-nav { position: static; display: flex; gap: 4px; overflow-x: auto; }
    .section-nav a { white-space: nowrap; }
    .routing-grid, .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .campaign-row { grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr); }
    .campaign-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 720px) {
    .topbar-inner { min-height: 62px; padding: 0 18px; }
    .environment-pill { display: none; }
    .page { width: min(100% - 28px, var(--max-width)); padding-top: 26px; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .btn { width: 100%; }
    .form-grid, .form-grid.three, .routing-grid, .stats-grid { grid-template-columns: 1fr; }
    .card-header, .card-body { padding: 18px; }
    .campaign-row { grid-template-columns: 1fr; gap: 10px; }
    .campaign-actions { grid-column: auto; flex-wrap: wrap; }
    .campaign-actions .btn { flex: 1; }
    .action-bar { bottom: 8px; }
    .action-bar .btn { flex: 1; }
    .auth-page { padding: 0; }
    .auth-shell { min-height: 100vh; grid-template-columns: 1fr; border: 0; border-radius: 0; }
    .auth-visual { display: none; }
    .auth-form-panel { padding: 36px 24px; }
    .mobile-only { display: flex; margin-bottom: 36px; }
    .toolbar { align-items: stretch; }
    .filter-row { width: 100%; }
    .compact-field { flex: 1 1 140px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
