/* Meta Digital client report styles. Light theme only (reports are printed/shared as PDFs). */
:root {
  color-scheme: light;
  --accent: #2f8f3e;          /* client accent; overridden per client */
  --brand: #3aab47;           /* Meta Digital green */
  --dark: #313131;            /* Meta Digital charcoal */
  --bg: #f4f5f3;
  --surface: #ffffff;
  --ink: #1f2321;
  --ink-2: #555b57;
  --muted: #7a807c;
  --line: #e2e5e1;
  --grid: #eceeeb;
  --series-1: #2f8f3e;        /* validated pair: green / blue */
  --series-2: #1b75bb;
  --bar: #cfe8d3;
  --up: #237a33;
  --down: #c0392b;
  --radius: 10px;
  --font: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Montserrat", var(--font);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
h1, h2, h3 { font-family: var(--font-head); color: var(--dark); line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 0 0 1rem; }
h3 { font-size: 0.98rem; margin: 1.5rem 0 0.25rem; }
a { color: var(--series-2); }
.muted { color: var(--muted); }
.sub { color: var(--ink-2); margin: 0 0 0.75rem; font-size: 0.9rem; }
[hidden] { display: none !important; }

/* ---------- header / footer */
.topbar { background: var(--dark); color: #fff; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: 14px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; background: #fff; border-radius: 8px; padding: 6px 10px; }
.client-logo { height: 40px; width: auto; display: block; }
.client-name { font: 700 1.1rem var(--font-head); color: var(--dark); }
.topbar-title { font: 600 1.15rem var(--font-head); color: var(--brand); flex: 1; }
.topnav { display: flex; gap: 4px; }
.topnav a { color: #fff; text-decoration: none; padding: 6px 12px; border-radius: 6px; font-size: 0.9rem; }
.topnav a:hover, .topnav a[aria-current] { background: rgba(255, 255, 255, 0.12); }
.footer { background: var(--dark); color: #ddd; font-size: 0.85rem; display: flex; justify-content: center; align-items: center; gap: 10px; padding: 18px 16px; margin-top: 32px; }
.footer .agency-logo { height: 26px; background: #fff; border-radius: 4px; padding: 3px 6px; }
.agency-logo { height: 22px; vertical-align: middle; }

/* ---------- layout */
.page { max-width: 1180px; margin: 0 auto; padding: 20px 16px; transition: opacity 0.2s; }
.page.is-loading { opacity: 0.55; pointer-events: none; }
.loading { padding: 80px 0; text-align: center; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin: 0 0 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 0.5rem; }
.card-head h2 { margin: 0; }
.grid-2, .grid-3 { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 8px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.footnote { font-size: 0.8rem; color: var(--muted); font-style: italic; margin: 0.75rem 0 0; }
.empty { color: var(--muted); padding: 12px 0; margin: 0; }
.notice { background: #fff7e0; border: 1px solid #f0d58a; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }

/* ---------- controls */
.controls { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px; }
.controls-filters, .controls-actions, .custom { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.controls-info { display: flex; flex-direction: column; }
.controls label { display: flex; flex-direction: column; font-size: 0.78rem; color: var(--ink-2); gap: 3px; font-weight: 600; }
select, input[type="date"], input[type="password"], input[type="url"], input:not([type]), textarea {
  font: inherit; font-size: 0.92rem; color: var(--ink); background: #fff; border: 1px solid #c9cec8; border-radius: 7px; padding: 7px 10px; min-height: 38px;
}
textarea { width: 100%; min-height: 120px; }
select:focus-visible, input:focus-visible, textarea:focus-visible, .btn:focus-visible, .seg:focus-visible { outline: 2px solid var(--series-2); outline-offset: 2px; }
.range-note { font-size: 0.88rem; color: var(--ink-2); margin: 6px 2px 18px; }
.btn { font: 600 0.88rem var(--font); display: inline-flex; align-items: center; justify-content: center; min-height: 38px; padding: 7px 14px; border-radius: 7px; border: 1px solid #c9cec8; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { background: #f1f3f0; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(0.92); }
.btn-danger { color: var(--down); }
.linkbtn { background: none; border: 0; color: var(--series-2); font: 600 0.85rem var(--font); cursor: pointer; padding: 8px 0; }
.segmented { display: inline-flex; border: 1px solid #c9cec8; border-radius: 8px; overflow: hidden; }
.seg { font: 600 0.82rem var(--font); background: #fff; border: 0; padding: 7px 12px; cursor: pointer; color: var(--ink-2); min-height: 34px; }
.seg + .seg { border-left: 1px solid #c9cec8; }
.seg.on { background: var(--dark); color: #fff; }
.badge { font-size: 0.75rem; font-weight: 600; padding: 3px 8px; border-radius: 99px; align-self: center; }
.badge-draft { background: #fff1d6; color: #8a5a00; }
.badge-live { background: #dff2e2; color: #1d6b2a; }
.admin-bar { background: #fff1d6; border-radius: 8px; padding: 8px 12px; margin-bottom: 16px; font-size: 0.88rem; }
.admin-edit { margin-top: 16px; padding-top: 16px; border-top: 1px dashed var(--line); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--dark); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 10; }
dialog { border: 0; border-radius: 12px; padding: 0; max-width: min(460px, calc(100vw - 32px)); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dialog h2 { margin: 0; }
.dialog label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.85rem; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- KPIs */
.kpi-grid { display: grid; gap: 14px; }
.kpi-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; background: #fbfcfa; }
.kpi-label { font-size: 0.85rem; color: var(--ink-2); font-weight: 600; }
.kpi-value { font: 600 1.9rem/1.15 var(--font-head); color: var(--ink); margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-help { margin: 8px 0 0; font-size: 0.86rem; color: var(--ink-2); }
.delta { font-size: 0.84rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.neutral { color: var(--muted); }
.pairs { display: flex; flex-direction: column; gap: 14px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pair:nth-child(odd) .kpi { background: color-mix(in srgb, var(--brand) 7%, #fff); }

/* ---------- chart */
.chart-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 0.84rem; color: var(--ink-2); margin: 4px 0 8px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { width: 22px; height: 0; border-top: 2px solid var(--c); }
.legend-swatch.dashed { border-top-style: dashed; }
.chart-box { position: relative; height: 280px; }

/* ---------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
table.data th { text-align: left; font-weight: 600; color: #fff; background: var(--dark); padding: 8px 10px; white-space: nowrap; }
table.data th.num { text-align: right; }
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--line); }
table.data td.txt { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data td.num { text-align: right; white-space: nowrap; position: relative; }
table.data tr.extra { display: none; }
table.data.expanded tr.extra { display: table-row; }
.cellbar { position: absolute; inset: 4px 0 4px auto; width: var(--w); background: var(--bar); border-radius: 4px 0 0 4px; }
.cellval { position: relative; }
table.data a { color: inherit; text-decoration: none; }
table.data a:hover { text-decoration: underline; }

.hbars { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.hbars li { display: grid; grid-template-columns: 150px 1fr 56px; align-items: center; gap: 10px; font-size: 0.88rem; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: capitalize; }
.hbar-track { height: 12px; }
.hbar { display: block; height: 12px; width: var(--w); background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-value { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }

.commentary p { margin: 0 0 0.8rem; max-width: 75ch; }

/* ---------- archive */
.archive-list { list-style: none; padding: 0; margin: 0; }
.archive-item { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.archive-title { font-weight: 600; color: var(--ink); }
.archive-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 32px 28px; width: 100%; max-width: 400px; text-align: center; }
.login-logo { max-height: 64px; max-width: 220px; margin-bottom: 10px; }
.login form { display: flex; flex-direction: column; gap: 10px; text-align: left; margin-top: 16px; }
.login label { font-weight: 600; font-size: 0.85rem; }
.login-foot { font-size: 0.82rem; color: var(--muted); margin-top: 24px; }
.form-error { color: var(--down); margin: 0; font-size: 0.88rem; }

/* ---------- responsive */
@media (max-width: 900px) {
  .kpi-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .grid-2, .pair { grid-template-columns: 1fr; }
  .kpi-value { font-size: 1.6rem; }
  .card { padding: 16px; }
  .topbar-title { flex-basis: 100%; order: 3; }
  .controls { align-items: stretch; }
  .controls-filters label, .controls-filters select { width: 100%; }
}

/* ---------- print / PDF */
.print-only { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 11px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .no-print, .topnav, .show-more, .range-note .muted, dialog { display: none !important; }
  .print-only { display: flex; }
  .page { padding: 0; max-width: none; }
  .card { break-inside: avoid; border: 1px solid #ddd; padding: 14px; margin-bottom: 10px; }
  #pages, #audience, #queries { break-inside: auto; }
  .controls { border: 0; padding: 0 0 6px; }
  .kpi-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
  .grid-2, .pair { grid-template-columns: 1fr 1fr; }
  .chart-box { height: 260px; }
  table.data { font-size: 9.5px; }
  table.data td.txt { max-width: 260px; }
  tr { break-inside: avoid; }
  .footer { margin-top: 12px; }
}

/* ---------- admin */
.admin h1 { font-size: 1.4rem; margin: 0; }
.page-head { margin: 4px 0 16px; }
.sa-box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; font-size: 0.88rem; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em; background: #f1f3f0; padding: 2px 6px; border-radius: 4px; word-break: break-all; }
.btn-sm { min-height: 30px; padding: 4px 10px; font-size: 0.8rem; }
.flash { background: #dff2e2; border: 1px solid #b5dcbc; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.ok { color: var(--up); }
.warn { color: var(--down); }
.admin-form h2 { margin-top: 1.6rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.admin-form h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.admin-form label, .inline-form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.86rem; }
.admin-form input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]), .admin-form select, .inline-form input { width: 100%; }
.admin-form input[type="color"] { width: 64px; height: 38px; padding: 2px; border: 1px solid #c9cec8; border-radius: 7px; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; margin-bottom: 8px; }
.prefix-input { display: flex; align-items: stretch; }
.prefix-input > span { background: #f1f3f0; border: 1px solid #c9cec8; border-right: 0; border-radius: 7px 0 0 7px; padding: 7px 10px; color: var(--muted); }
.prefix-input input { border-radius: 0 7px 7px 0 !important; }
fieldset { border: 0; padding: 0; margin: 16px 0; }
legend { font-weight: 600; font-size: 0.86rem; margin-bottom: 8px; }
.check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; }
.check-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 20px; }
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.radio-cards legend { grid-column: 1 / -1; }
.radio-card { flex-direction: row !important; align-items: flex-start; gap: 10px !important; border: 1px solid var(--line); border-radius: 8px; padding: 12px; cursor: pointer; font-weight: 400 !important; }
.radio-card:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, #fff); }
.radio-card input { margin-top: 3px; }
.logo-preview { background: #f1f3f0; border-radius: 8px; padding: 10px; display: inline-block; margin-bottom: 6px; }
.logo-preview img { max-height: 48px; max-width: 220px; display: block; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form label { flex: 1; min-width: 220px; }
.danger-zone { border-color: #f1c4bf; }
.credentials { display: flex; flex-direction: column; gap: 10px; background: #f7f8f6; border-radius: 8px; padding: 14px; margin: 14px 0; }
.credentials > div { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.credentials .kpi-label { width: 80px; }
.credentials code { font-size: 1rem; }
@media (max-width: 640px) {
  .form-grid, .check-grid, .radio-cards { grid-template-columns: 1fr; }
}
.badge-custom { background: #e4eefa; color: #1b5a91; margin-left: 6px; }
.custom-note { background: #eef4fb; border: 1px solid #c6daf0; border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; font-size: 0.9rem; }
.custom-note ul { margin: 6px 0; padding-left: 20px; }
.check-list { display: flex; flex-direction: column; gap: 6px; }
