:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1d2433;
    --muted: #5a6475;
    --border: #d9dde5;
    --primary: #1f4fd1;
    --primary-dark: #173ca3;
    --primary-soft: #e8eefc;
    --ok: #13753d;
    --ok-soft: #e3f4ea;
    --warn: #8a5a00;
    --warn-soft: #fff3d6;
    --danger: #b42318;
    --danger-soft: #fde8e6;
    --radius: 8px;
    --focus: 0 0 0 3px rgba(31, 79, 209, .35);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }
code { font-family: var(--mono); font-size: .9em; background: #eef0f4; padding: .05em .3em; border-radius: 4px; overflow-wrap: anywhere; }
img { max-width: 100%; height: auto; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 4px; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 1rem; top: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }

.shell { display: grid; grid-template-columns: 230px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.logo { font-weight: 700; text-decoration: none; color: var(--text); font-size: 1.1rem; }
.brand-current, .brand-switch summary { color: var(--muted); }
.brand-switch { position: relative; }
.brand-switch summary { cursor: pointer; padding: .25rem .5rem; border-radius: 6px; }
.brand-switch ul { position: absolute; z-index: 20; list-style: none; margin: .25rem 0 0; padding: .25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 200px; box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.brand-switch li button { width: 100%; text-align: left; padding: .5rem .75rem; }
.topbar__user { margin-left: auto; display: flex; gap: 1rem; align-items: center; }
.nav-toggle { display: none; }

.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 1rem .75rem; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { display: block; padding: .5rem .75rem; border-radius: 6px; color: var(--text); text-decoration: none; min-height: 40px; }
.sidebar a:hover { background: var(--bg); }
.sidebar a[aria-current="page"] { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-section { margin: 1rem .75rem .25rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.main { padding: 1.5rem 2rem 3rem; min-width: 0; max-width: 1280px; }
.main:focus { outline: none; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin: 0 0 1rem; min-width: 0; }
fieldset.card { margin-inline: 0; }
fieldset.card legend { font-weight: 600; padding: 0 .35rem; }
.grid { display: grid; gap: 1rem; }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack > * + * { margin-top: .9rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > .field { flex: 1 1 180px; }
.narrow { max-width: 560px; }

.stat { display: flex; flex-direction: column; gap: .15rem; }
.stat__value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat__label { color: var(--muted); font-size: .85rem; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field label, .field legend { font-weight: 600; }
.field--check { flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: .5rem; }
.field--check label { font-weight: 500; flex: 1 1 0; }
.field--check .help, .field--check .errors { flex-basis: 100%; margin-left: 1.6rem; }
.help { color: var(--muted); font-size: .85rem; margin: 0; }
.errors { list-style: none; margin: 0; padding: 0; color: var(--danger); font-size: .9rem; }
.field--error input, .field--error select, .field--error textarea { border-color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=search], input[type=date], input[type=datetime-local], input[type=file], select, textarea {
    font: inherit; color: inherit; width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); min-height: 42px;
}
input[type=color] { width: 64px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
textarea { min-height: 90px; resize: vertical; }
textarea.code { font-family: var(--mono); font-size: .85rem; min-height: 320px; }
input[type=checkbox], input[type=radio] { width: 1.1rem; height: 1.1rem; margin: .2rem 0 0; accent-color: var(--primary); flex: none; }
.choices { display: flex; flex-direction: column; gap: .4rem; }
.choice { display: flex; gap: .5rem; align-items: flex-start; }
.choice label { font-weight: 400; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; padding: .55rem 1rem; min-height: 42px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--bg); color: var(--text); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); color: #fff; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { background: #8f1c13; color: #fff; }
.btn--small { padding: .3rem .6rem; min-height: 34px; font-size: .85rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; text-decoration: underline; min-height: 24px; }
.inline { display: inline; }
.actions-bar { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-top: 1rem; }

.flash { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.flash--success { background: var(--ok-soft); border-color: #b5e0c5; color: #0c4f29; }
.flash--error { background: var(--danger-soft); border-color: #f5b8b2; color: #7a1610; }
.flash--warning { background: var(--warn-soft); border-color: #f0d08a; color: #5c3c00; }
.flash--info { background: var(--primary-soft); border-color: #c4d3f6; color: #173ca3; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: #eef0f4; color: var(--muted); white-space: nowrap; }
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--primary-soft); color: var(--primary-dark); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { background: #f9fafb; font-size: .85rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions > * + * { margin-left: .75rem; }

.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; flex: 1 1 160px; }
.filters .btn { flex: none; }
.pagination { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

.steps { display: flex; gap: .5rem; list-style: none; padding: 0; margin: 0 0 1.25rem; counter-reset: step; flex-wrap: wrap; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; }
.steps li::before { content: counter(step); display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); font-weight: 600; }
.steps li + li::after { order: -1; content: ""; width: 1.25rem; height: 1px; background: var(--border); }
.steps li[aria-current="step"] { color: var(--text); font-weight: 600; }
.steps li[aria-current="step"]::before { background: var(--primary); border-color: var(--primary); color: #fff; }
.steps li.done::before { background: var(--ok-soft); border-color: #b5e0c5; color: var(--ok); }
.steps a { color: inherit; }

.progress { height: 12px; background: #e6e9ef; border-radius: 999px; overflow: hidden; }
.progress__bar { height: 100%; background: var(--primary); transition: width .4s ease; }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: .6rem; align-items: flex-start; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.checks li:last-child { border-bottom: 0; }

.public { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.public__card { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }

.preview-frame { width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; min-height: 520px; }
.preview-frame--mobile { max-width: 390px; }
.block-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .75rem; }
.block-item { border: 1px solid var(--border); border-radius: var(--radius); background: #fbfcfd; padding: .9rem; }
.block-item__head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.block-item__tools { display: flex; gap: .25rem; flex-wrap: wrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; overflow-wrap: anywhere; }

.tabs { margin: 0 0 1rem; }
.tabs a[aria-current="page"] { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-soft); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem 1.25rem; }
.kpi { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.kpi__label { color: var(--muted); font-size: .85rem; font-weight: 600; }
.kpi__value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi__help { color: var(--muted); font-size: .8rem; }
.kpis + .help, .kpis ~ .help { margin-top: .9rem; }
.page-head .actions { align-items: center; }

.legend { display: flex; flex-wrap: wrap; gap: .25rem 1rem; list-style: none; margin: 0; padding: 0; font-size: .85rem; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: .4rem; }
.legend__swatch { width: 14px; height: 3px; border-radius: 2px; background: var(--series-1); }
.legend__swatch--clicks { background: var(--series-2); }

.chart { display: grid; grid-template-columns: 3rem minmax(0, 1fr); grid-template-rows: 220px auto; }
.chart__y { position: relative; font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart__y span { position: absolute; right: .5rem; transform: translateY(-50%); }
.chart__plot { position: relative; touch-action: pan-y; cursor: crosshair; }
.chart__plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart__grid { stroke: #e6e9ef; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart__line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart__line--opens { stroke: var(--series-1); }
.chart__line--clicks { stroke: var(--series-2); }
.chart__cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.chart__x { grid-column: 2; position: relative; height: 1.6rem; font-size: .75rem; color: var(--muted); }
.chart__x span { position: absolute; top: .35rem; white-space: nowrap; }
.chart__tip { position: absolute; top: 0; z-index: 5; display: flex; flex-direction: column; gap: .1rem; padding: .45rem .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.1); font-size: .8rem; pointer-events: none; white-space: nowrap; }
.chart__tip[hidden] { display: none; }
.chart__tip-title { font-weight: 600; }
.chart__tip-opens::before, .chart__tip-clicks::before { content: ""; display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; background: var(--series-1); }
.chart__tip-clicks::before { background: var(--series-2); }
.chart__tip-auto { color: var(--muted); }
.chart-table { margin-top: .75rem; }
.chart-table summary { cursor: pointer; color: var(--primary); min-height: 32px; display: flex; align-items: center; }

.bars { list-style: none; margin: 0 0 .75rem; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.bars li { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr) 6.5rem; gap: .75rem; align-items: center; }
.bars__track { height: 10px; background: #eef0f4; border-radius: 999px; overflow: hidden; }
.bars__fill { display: block; height: 100%; background: var(--series-1); border-radius: 999px; }
.bars__value { font-variant-numeric: tabular-nums; text-align: right; }
.url-cell { overflow-wrap: anywhere; }

.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.alerts li { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem .75rem; border-radius: var(--radius); border: 1px solid var(--border); }
.alerts .alert--danger { background: var(--danger-soft); border-color: #f5b8b2; }
.alerts .alert--warning { background: var(--warn-soft); border-color: #f0d08a; }
.alerts .alert--info { background: var(--primary-soft); border-color: #c4d3f6; }

.segment-layout { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 1rem; align-items: start; }
.segment-count { position: sticky; top: 1rem; display: flex; flex-direction: column; gap: .3rem; }
.segment-groups { display: flex; flex-direction: column; gap: .9rem; margin-bottom: .9rem; }
.segment-group { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem .9rem; margin: 0; background: #fbfcfd; min-width: 0; }
.segment-group legend { font-weight: 600; padding: 0 .35rem; }
.segment-group__head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.segment-group__head select { width: auto; flex: 0 1 auto; }
.segment-group__head .btn { margin-left: auto; }
.segment-conditions { list-style: none; margin: 0 0 .6rem; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.segment-condition { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .5rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.segment-condition select, .segment-condition input[type=text] { width: auto; flex: 1 1 150px; min-width: 0; }
.segment-condition input.segment-days { width: 6rem; flex: none; }
.segment-condition .link { margin-left: auto; min-height: 32px; }
.field--inline { flex-direction: row; flex-wrap: wrap; align-items: center; gap: .5rem; }
.field--inline select { width: auto; }

.approval { border-color: #c4d3f6; }
.approval__actions { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 1.5rem; align-items: start; margin-top: .5rem; }
.approval__reject { display: flex; flex-direction: column; align-items: flex-start; }
.approval__reject .field { width: 100%; }

@media (max-width: 900px) {
    .grid--3, .grid--4, .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .shell { grid-template-columns: 1fr; }
    .topbar { padding: .5rem 1rem; gap: .5rem .75rem; }
    .topbar__user { gap: .75rem; font-size: .9rem; }
    .nav-toggle { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); cursor: pointer; }
    .nav-toggle__bar, .nav-toggle__bar::before, .nav-toggle__bar::after { display: block; width: 18px; height: 2px; background: var(--text); position: relative; content: ""; }
    .nav-toggle__bar::before { position: absolute; top: -6px; }
    .nav-toggle__bar::after { position: absolute; top: 6px; }
    .sidebar { display: none; border-right: 0; border-bottom: 1px solid var(--border); }
    .sidebar.is-open { display: block; }
    .main { padding: 1rem 1rem 2.5rem; }
    .grid--2, .grid--3, .grid--4 { grid-template-columns: minmax(0, 1fr); }
    .segment-layout { grid-template-columns: minmax(0, 1fr); }
    .approval__actions { grid-template-columns: minmax(0, 1fr); }
    .segment-count { position: static; order: -1; }
    .segment-condition select, .segment-condition input[type=text] { flex-basis: 100%; }
    .grid--stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
    .grid--stats .card { padding: .9rem; margin: 0; }
    .grid--stats .stat__value { font-size: 1.35rem; }
    .public__card { padding: 1.25rem; }
    .chart { grid-template-columns: 2.4rem minmax(0, 1fr); grid-template-rows: 180px auto; }
    .chart__x span:not(:nth-child(3n+1)) { display: none; }
    .chart__x span:last-child { left: auto !important; right: 0; }
    .bars li { grid-template-columns: 5.5rem minmax(0, 1fr) 5.5rem; gap: .5rem; }
    .kpi__value { font-size: 1.35rem; }
    h1 { font-size: 1.35rem; }
    .table-wrap table.responsive thead { display: none; }
    .table-wrap table.responsive tr { display: block; border-bottom: 1px solid var(--border); padding: .4rem 0; }
    .table-wrap table.responsive td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .3rem .8rem; text-align: right; }
    .table-wrap table.responsive td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; flex: none; }
    .table-wrap table.responsive td.actions { justify-content: flex-end; }
    .table-wrap table.responsive td.actions::before { content: none; }
}
