/* XAds admin */
:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #1b1b19;
  --text-2: #52514e;
  --muted: #76756f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e3eefb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #e7e6e1;
  --good: #1f7a3e; --good-bg: #e2f3e7;
  --warn: #8a5a00; --warn-bg: #fbf0d6;
  --bad: #b42323;  --bad-bg: #fbe4e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f3f2ee;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #3987e5;
    --accent-soft: #1d2f47;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #2a2a27;
    --good: #6fd08f; --good-bg: #173322;
    --warn: #f0c060; --warn-bg: #3a2e12;
    --bad: #ff8a87;  --bad-bg: #3d1a1a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

/* shell */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); padding: 4px 8px 12px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.side nav a { display: block; padding: 7px 10px; border-radius: 7px; color: var(--text-2); }
.side nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.side nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.main { padding: 24px 28px 80px; min-width: 0; max-width: 1500px; }
.btn.menu-toggle { display: none; margin-bottom: 12px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section-title { margin: 24px 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + * { margin-top: 16px; }
.grid-edit { grid-template-columns: minmax(320px, 5fr) 6fr; align-items: start; }
.form-narrow { max-width: 620px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; padding: 10px; }

/* forms */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field em { font-style: normal; font-weight: 400; }
input[type=text], input:not([type]), input[type=email], input[type=url], input[type=password], input[type=number],
input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 9px; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input[type=file] { font: inherit; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.check-line { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.check-line-field { align-self: end; padding-bottom: 8px; }
.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sticky-actions { position: sticky; bottom: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); padding: 12px 0; margin-top: 16px; border-top: 1px solid var(--border); z-index: 5; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; width: fit-content; }
.segmented label { padding: 6px 14px; display: flex; gap: 6px; align-items: center; cursor: pointer; border-right: 1px solid var(--border); }
.segmented label:last-child { border-right: 0; }
.segmented label:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
[data-type-panel] { display: none; }
[data-type-panel].shown { display: block; }

.filters { padding: 12px 16px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.field-inline { margin: 0; min-width: 130px; flex: 0 1 auto; }
.field-inline select, .field-inline input { width: auto; min-width: 130px; max-width: 240px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { padding: 3px 10px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-2); font-size: 12.5px; }
.chip:hover { background: var(--surface-2); text-decoration: none; }
.chip-on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.flash-ok { background: var(--good-bg); color: var(--good); }
.flash-error { background: var(--bad-bg); color: var(--bad); }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; }
.badge-on { background: var(--good-bg); color: var(--good); }
.badge-off { background: var(--surface-2); color: var(--muted); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.size-tag { font-family: var(--mono); font-size: 11.5px; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 4px; }
.kpis-3 { grid-template-columns: repeat(3, 1fr); }
.kpi { margin-bottom: 0; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.kpi-row { display: flex; gap: 18px; flex-wrap: wrap; }
.kpi-value { font-size: 24px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-value-sm { font-size: 18px; padding-top: 5px; }
.kpi-sub { font-size: 11.5px; color: var(--muted); }
.kpi-foot { font-size: 12px; color: var(--muted); margin-top: 8px; }
.delta { font-weight: 600; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.kpis + .section-title, .kpis + .charts { margin-top: 16px; }

/* charts */
.charts { display: grid; grid-template-columns: 1fr; gap: 0; }
.chart-card { padding-bottom: 8px; }
.chart-head h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch-1 { background: var(--series-1); }
.swatch-2 { background: var(--series-2); }
.swatch-3 { background: var(--series-3); }
.chart-box { position: relative; height: 240px; }
.chart-box-sm { height: 150px; }
.table-view summary { cursor: pointer; color: var(--text-2); font-weight: 600; }
.table-view[open] summary { margin-bottom: 10px; }
.table-view .table-wrap { max-height: 360px; overflow: auto; }

/* tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tbody tr:hover { background: var(--surface-2); }
.table-compact th, .table-compact td { padding: 5px 8px; }
.num { text-align: right !important; }
.check { width: 32px; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]::after { content: " ↕"; opacity: .35; }
th[data-dir="asc"]::after { content: " ↑"; opacity: 1; }
th[data-dir="desc"]::after { content: " ↓"; opacity: 1; }
.row-actions { white-space: nowrap; text-align: right; font-size: 12.5px; }
.row-warn td { color: var(--bad); }
.meter-col { width: 22%; min-width: 80px; }
.meter { display: block; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter-fill { display: block; height: 100%; background: var(--series-1); border-radius: 3px; width: 0; }
.thumb { width: 72px; height: 9px; object-fit: cover; border-radius: 2px; display: block; margin-bottom: 4px; background: var(--surface-2); }
.thumb-lg { width: 120px; height: 15px; margin: 0; flex: none; }
.thumb-type { display: grid; place-items: center; font-size: 10px; font-weight: 700; color: var(--muted); }
.banner-cell { display: flex; gap: 10px; align-items: center; }
.selected-row { background: var(--accent-soft) !important; }

/* picker (zones / banners checklist) */
.picker-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.picker-search { width: 180px !important; }
.picker-count { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--accent); }
.picker-groups { display: flex; flex-direction: column; gap: 10px; max-height: 62vh; overflow-y: auto; padding-right: 4px; }
.picker-group { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px 8px; margin: 0; }
.picker-group legend { padding: 0 6px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.picker-group legend label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.pick { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.pick-banner { grid-template-columns: auto auto 1fr auto; }
.pick:hover { background: var(--surface-2); }
.pick-on { background: var(--accent-soft); }
.pick-meta { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.pick .thumb { margin: 0; width: 96px; height: 12px; }
.pick.hidden, .picker-group.hidden { display: none; }
.bulk-panel { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.bulk-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
.spacer { flex: 1; }

/* link matrix */
.matrix-card { padding: 0; overflow: hidden; }
.matrix-wrap { overflow: auto; max-height: 75vh; }
.matrix { border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.matrix th, .matrix td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; text-align: center; background: var(--surface); }
.matrix thead th { position: sticky; z-index: 2; }
.matrix thead tr:first-child th { top: 0; height: 30px; }
.matrix thead tr:nth-child(2) th { top: 30px; }
.matrix .m-corner { left: 0; z-index: 4; text-align: left; padding: 8px 12px; min-width: 260px; }
.matrix .m-site { background: var(--surface-2); font-weight: 600; padding: 6px; white-space: nowrap; }
.m-col { background: none; border: 0; color: var(--text); font: inherit; cursor: pointer; padding: 6px 6px; width: 112px; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 2px; align-items: center; }
.m-col span { font-weight: 600; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.m-col small { color: var(--muted); font-size: 10.5px; }
.m-col:hover { background: var(--accent-soft); }
.matrix tbody th { position: sticky; left: 0; z-index: 1; text-align: left; padding: 6px 10px; font-weight: 400; min-width: 260px; max-width: 340px; }
.m-banner { display: table-cell; }
.m-banner small { display: block; }
.m-rowbtn, .m-campbtn, .m-campcell { background: none; border: 1px solid var(--border); border-radius: 5px; color: var(--text-2); cursor: pointer; font: inherit; padding: 0 5px; margin-right: 6px; }
.m-rowbtn:hover, .m-campbtn:hover, .m-campcell:hover { background: var(--accent-soft); color: var(--accent); }
.m-camp th, .m-camp td { background: var(--surface-2) !important; }
.m-campbtn { font-weight: 600; border: 0; padding: 4px 0; text-align: left; }
.m-campcell { margin: 0; font-size: 10px; }
.matrix td { width: 112px; height: 34px; }
.matrix td input { width: 17px; height: 17px; cursor: pointer; }
.matrix td.m-mismatch { background: repeating-linear-gradient(135deg, var(--surface), var(--surface) 4px, var(--surface-2) 4px, var(--surface-2) 8px); }
.matrix tr:hover th, .matrix tr:hover td:not(.m-mismatch) { background: var(--accent-soft); }
.legend-mismatch { margin-left: auto; }

/* tabs */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; background: var(--surface-2); padding: 3px; border-radius: 8px; }
.tab { padding: 4px 12px; border-radius: 6px; color: var(--text-2); font-size: 12.5px; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab-on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* code */
.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap; word-break: break-all; margin: 0; }
.code-key { font-size: 16px; letter-spacing: .05em; text-align: center; margin: 8px 0; }
.preview-frame { width: 100%; height: 110px; border: 1px dashed var(--border); border-radius: 8px; background: #fff; }
.preview-frame-lg { height: 130px; }
.preview-img { margin-bottom: 10px; }
.preview-img img { max-width: 100%; height: auto; border-radius: 4px; border: 1px solid var(--border); }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; padding: 28px; }
.login h1 { margin: 6px 0 18px; font-size: 20px; }
.brand-login { padding: 0; }

/* installer */
.install { width: 100%; max-width: 720px; padding: 28px; margin: 24px 0; }
.install h1 { margin: 14px 0 14px; font-size: 20px; }
.install h2 { margin-top: 20px; }
.install .kpis { margin: 14px 0; }
.install ol { padding-left: 20px; }
.install ol li { margin-bottom: 6px; }
.steps { display: flex; gap: 6px; list-style: none; padding: 0 !important; margin: 16px 0 0; flex-wrap: wrap; counter-reset: s; }
.steps li { counter-increment: s; font-size: 12px; color: var(--muted); padding: 3px 10px 3px 6px; border-radius: 99px; background: var(--surface-2); margin: 0 !important; }
.steps li::before { content: counter(s); display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; background: var(--border); color: var(--text-2); font-size: 10.5px; font-weight: 700; margin-right: 6px; }
.steps li.cur { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.steps li.cur::before { background: var(--accent); color: #fff; }
.steps li.done::before { content: "✓"; background: var(--good-bg); color: var(--good); }

/* responsive */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-edit { grid-template-columns: 1fr; }
  .grid-2 > .card { margin-bottom: 16px; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s, box-shadow .2s; visibility: hidden; }
  .side.open { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .btn.menu-toggle { display: inline-flex; }
  .main { padding: 12px 16px 80px; }
  h1 { font-size: 20px; }
  .kpis, .kpis-3 { grid-template-columns: 1fr; }
  .kpi-value { font-size: 21px; }
  .row-3 { grid-template-columns: 1fr 1fr; }
  /* filters: two compact columns instead of a full-screen stack */
  .filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
  .field-inline { min-width: 0; }
  .field-inline select, .field-inline input { width: 100%; min-width: 0; max-width: none; }
  .filter-row > .btn { grid-column: 1 / -1; justify-content: center; }
  .card { padding: 12px; }
  .meter-col { display: none; }
  .chart-box { height: 200px; }
  .chart-box-sm { height: 130px; }
  .thumb-lg { width: 72px; height: 9px; }
  .banner-cell { flex-direction: column; align-items: flex-start; gap: 4px; }
  .table th, .table td { padding: 7px 6px; }
  /* compact sticky save bar */
  .sticky-actions { padding: 8px 0; gap: 6px; flex-wrap: nowrap; }
  .sticky-actions .btn-ghost, .sticky-actions .legend-mismatch { display: none; }
  .sticky-actions .btn { padding: 8px 12px; }
  /* matrix: narrow sticky banner column so zones fit */
  .matrix .m-corner, .matrix tbody th { min-width: 140px; max-width: 160px; }
  .matrix tbody th a { display: block; overflow-wrap: anywhere; font-size: 12px; }
  .m-col { width: 84px; }
  .matrix td { width: 84px; }
  .picker-groups { max-height: none; }
  .picker-search { width: 100% !important; order: 10; }
  .pick { grid-template-columns: auto 1fr; }
  .pick-meta { grid-column: 2; }
  .pick-banner { grid-template-columns: auto 1fr; }
  .pick-banner .thumb { grid-column: 2; }
  .bulk-buttons .btn { flex: 1 1 auto; justify-content: center; }
  .bulk-buttons .spacer { display: none; }
  .tabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .tab { white-space: nowrap; }
  .page-head .actions .btn { padding: 6px 10px; }
}

/* click quality */
.kpis-5 { grid-template-columns: repeat(5, 1fr); }
.kpi-link { color: var(--text); text-decoration: none !important; display: block; }
.kpi-link:hover { border-color: var(--accent); }
.kpi-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.kpis-5 + .grid-2 { margin-top: 16px; }
.ua { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 1100px) { .kpis-5 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) { .kpis-5 { grid-template-columns: 1fr; } }
.badge { white-space: nowrap; }
