/* Acquire dashboard. A ledger-like tool: quiet surfaces, tabular numbers,
   and one loud idea: costs we don't know yet are striped, never shown as zero. */
:root {
  --paper: #EEF1F0;
  --surface: #FFFFFF;
  --ink: #16232E;
  --muted: #5A6A74;
  --rule: #D3DADC;
  --accent: #2C4F6B;
  --profit: #1D6A46;
  --loss: #A2302A;
  --caution: #8A5D0E;
  --caution-bg: #FBF3E2;
  --error-bg: #FBE9E7;
  --info-bg: #E8EEF3;
  --stripe: repeating-linear-gradient(-45deg, transparent 0 6px, rgba(138, 93, 14, .16) 6px 9px);
  --font: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --radius: 6px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121A21; --surface: #18232C; --ink: #E4EAEE; --muted: #93A3AD; --rule: #2A3843;
    --accent: #8FB4D3; --profit: #6CC79A; --loss: #F08A80; --caution: #E7B65E;
    --caution-bg: #2B2416; --error-bg: #33201E; --info-bg: #1D2A35;
    --stripe: repeating-linear-gradient(-45deg, transparent 0 6px, rgba(231, 182, 94, .18) 6px 9px);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 15px/1.5 var(--font); font-variant-numeric: tabular-nums; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { background: var(--surface); border-bottom: 1px solid var(--rule); }
.top-inner { max-width: 1240px; margin: 0 auto; padding: 14px 24px 0; display: flex; flex-wrap: wrap; gap: 8px 24px; align-items: end; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -.01em; padding-bottom: 12px; margin-right: auto; }
.brand small { font-weight: 400; color: var(--muted); font-size: 14px; margin-left: 8px; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; }
nav.tabs a { padding: 8px 12px 11px; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; }
nav.tabs a[aria-current="page"] { color: var(--ink); border-color: var(--accent); font-weight: 600; }
.signout { padding-bottom: 12px; font-size: 14px; }

main { max-width: 1240px; margin: 0 auto; padding: 24px; }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -.015em; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 12px; }
.lede { color: var(--muted); margin: 0 0 20px; max-width: 72ch; }

.sources { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; padding: 0; list-style: none; }
.sources li { background: var(--surface); border: 1px solid var(--rule); border-radius: 999px; padding: 4px 12px 4px 10px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.state-live .dot { background: var(--profit); }
.state-sample .dot { background: var(--caution); }
.state-stale .dot, .state-failed .dot { background: var(--loss); }
.state-not_connected .dot { background: transparent; border: 1.5px solid var(--muted); }
.sources .when { color: var(--muted); }

.rangebar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 20px; }
.rangebar .presets a { display: inline-block; padding: 6px 10px; border: 1px solid var(--rule); background: var(--surface); text-decoration: none; color: var(--ink); margin-right: -1px; }
.rangebar .presets a:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.rangebar .presets a:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.rangebar .presets a[aria-current="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
label { font-size: 13px; color: var(--muted); display: block; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 6px 8px; }
button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--ink); background: var(--ink); color: var(--surface); border-radius: var(--radius); padding: 6px 14px; cursor: pointer; text-decoration: none; display: inline-block; }
button.ghost { background: transparent; color: var(--ink); border-color: var(--rule); font-weight: 500; }
button.small { padding: 3px 9px; font-size: 13px; }

.flags { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 6px; }
.flags li { padding: 8px 12px; border-left: 4px solid var(--muted); background: var(--info-bg); border-radius: 0 var(--radius) var(--radius) 0; max-width: 90ch; }
.flags .warn { border-color: var(--caution); background: var(--caution-bg); }
.flags .error { border-color: var(--loss); background: var(--error-bg); }

.grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 20px; }

/* The ledger */
.ledger { width: 100%; border-collapse: collapse; }
.ledger td { padding: 7px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.ledger td.amt { text-align: right; white-space: nowrap; padding-left: 16px; font-size: 16px; }
.ledger .note { display: block; color: var(--muted); font-size: 13px; }
.ledger tr.cost td.amt::before { content: "− "; color: var(--muted); }
.ledger tr.subtotal td { font-weight: 600; border-bottom: 2px solid var(--ink); }
.ledger tr.missing td { background: var(--stripe); }
.ledger tr.missing td.amt { color: var(--caution); font-weight: 600; font-size: 14px; }
.ledger tr.missing td.amt::before { content: ""; }
.result { margin-top: 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.result .label { font-weight: 700; font-size: 17px; }
.result .value { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.result .value.pos { color: var(--profit); }
.result .value.neg { color: var(--loss); }
.result .value.incomplete { color: var(--caution); font-size: 22px; }
.result p { flex-basis: 100%; margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.memo { margin-top: 18px; font-size: 13px; color: var(--muted); }
.memo table { width: 100%; border-collapse: collapse; }
.memo td { padding: 3px 0; }
.memo td.amt { text-align: right; white-space: nowrap; }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
.kpi { padding: 12px 0; border-bottom: 1px solid var(--rule); }
.kpi:nth-child(odd) { padding-right: 12px; }
.kpi .v { font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.kpi .k { color: var(--muted); font-size: 13px; }
.definition { font-size: 13px; color: var(--muted); margin: 12px 0 0; }

.chart-wrap { position: relative; height: 260px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: right; font-weight: 600; color: var(--muted); font-size: 13px; padding: 6px 10px; border-bottom: 2px solid var(--rule); white-space: nowrap; }
table.data td { text-align: right; padding: 6px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td.gap { background: var(--stripe); color: var(--caution); }
table.data td.name { white-space: normal; min-width: 220px; }
.sub { color: var(--muted); font-size: 12px; display: block; }

.section { margin-top: 24px; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.a-pause, .a-reduce { color: var(--loss); }
.a-review, .a-review_creative { color: var(--caution); }
.a-scale { color: var(--profit); }
.a-not_enough_data { color: var(--muted); }
.rec { margin: 6px 0 0; max-width: 60ch; text-align: left; white-space: normal; font-size: 13px; }
.rec .why { display: block; color: var(--ink); margin: 3px 0; }
.rec form { display: inline; }
.decided { font-size: 12px; color: var(--muted); }
td.recs { text-align: left !important; white-space: normal !important; min-width: 280px; }
.levels { margin-bottom: 14px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px 24px; }
.field input { width: 100%; margin-top: 4px; }
.field .help { font-size: 12px; color: var(--muted); margin-top: 4px; }
.banner { padding: 10px 14px; border-radius: var(--radius); background: var(--caution-bg); border-left: 4px solid var(--caution); margin-bottom: 16px; max-width: 90ch; }
.banner.ok { background: var(--info-bg); border-color: var(--profit); }
.status-success { color: var(--profit); }
.status-failed { color: var(--loss); }
.status-skipped { color: var(--muted); }

.center { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; }
.login input { width: 100%; margin: 6px 0 12px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Creative page */
.filters select { min-width: 140px; }
.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 6px 20px; }
@media (max-width: 700px) { .kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.ad-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.ad-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.thumb { position: relative; aspect-ratio: 1 / 1; background: var(--paper); border-bottom: 1px solid var(--rule); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-empty { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 13px; background: var(--stripe); }
.thumb .fmt, .thumb .share { position: absolute; top: 8px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: rgba(22, 35, 46, .82); color: #fff; }
.thumb .fmt { left: 8px; text-transform: capitalize; }
.thumb .share { right: 8px; }
.ad-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.ad-body h3 { margin: 0; font-size: 15px; line-height: 1.3; }
.ad-body .sub { margin: 0; }
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 12px; margin: 6px 0 0; }
.metrics div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--rule); padding: 3px 0; font-size: 13px; }
.metrics dt { color: var(--muted); }
.metrics dd { margin: 0; font-weight: 600; }
.spark { width: 100%; height: 28px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.rec-line { margin: 2px 0; font-size: 13px; }
details summary { cursor: pointer; font-size: 13px; color: var(--accent); }
details .copy { white-space: pre-line; font-size: 13px; margin: 6px 0; }

/* Ad Library */
.ad-library-error { background: var(--error-bg); border-color: var(--loss); overflow-wrap: anywhere; }
.ad-library-form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 700px; }
.ad-library-checkbox { display: flex; align-items: flex-start; gap: 10px; margin: 16px 0; }
.ad-library-checkbox input { flex: none; margin: 3px 0 0; }
.ad-library-checkbox label { color: var(--ink); font-size: 14px; font-weight: 600; }
.ad-library-checkbox .definition { margin: 2px 0 0; }
.ad-library-layout { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: 20px; align-items: start; }
.ad-library-watches { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ad-library-watches li { min-width: 0; }
.ad-library-watch { display: grid; gap: 2px; padding: 10px 12px; color: var(--ink); text-decoration: none; border: 1px solid var(--rule); border-radius: var(--radius); overflow-wrap: anywhere; }
.ad-library-watch:hover, .ad-library-watch[aria-current="page"] { border-color: var(--accent); background: var(--info-bg); }
.ad-library-watch[aria-current="page"] { box-shadow: inset 3px 0 var(--accent); }
.ad-library-watch-meta { color: var(--muted); font-size: 12px; }
.ad-library-watch-error { color: var(--loss); font-size: 12px; margin: 4px 2px 0; overflow-wrap: anywhere; }
.ad-library-empty { margin: 0; color: var(--muted); }
.ad-library-results { min-width: 0; }
.ad-library-selected-heading { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 16px; }
.ad-library-selected-heading h2 { margin-bottom: 6px; overflow-wrap: anywhere; }
.ad-library-country { color: var(--muted); font-weight: 500; }
.ad-library-sync { margin: 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.ad-library-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ad-library-actions form { margin: 0; }
.ad-library-actions button:disabled { cursor: not-allowed; opacity: .6; }
.ad-library-loading { margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.ad-library-last-error { margin: 14px 0 0; }
.ad-library-fields-notice { margin-top: 16px; }
.ad-library-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); margin-top: 12px; }
.ad-library-media { aspect-ratio: 4 / 3; background: var(--paper); border-bottom: 1px solid var(--rule); }
.ad-library-media img, .ad-library-media video { display: block; width: 100%; height: 100%; object-fit: contain; }
.ad-library-card-body { min-width: 0; overflow-wrap: anywhere; }
.ad-library-details { margin: 6px 0; font-size: 13px; }
.ad-library-details div { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px solid var(--rule); }
.ad-library-details dt { color: var(--muted); }
.ad-library-details dd { margin: 0; text-align: right; }
.ad-library-title { margin: 4px 0 0; font-weight: 600; }
.ad-library-copy { margin: 0; white-space: pre-line; }
.ad-library-link { margin: 8px 0 0; }
.ad-library-link .sub { display: inline; }
@media (max-width: 700px) {
  .ad-library-layout { grid-template-columns: minmax(0, 1fr); }
  .ad-library-form-grid { grid-template-columns: minmax(0, 1fr); }
}
