/* Analytics Dashboard (apps/analytics-dashboard.html). Light theme only, built on the
 * shared tokens in 00-tokens.css. Desktop first; the phone layout is the
 * "Tablet / phone" block (<=760px) near the end. Spec: docs/analytics-rewrite.md. */

:root {
  --ad-bg: #f4f6f9;
  --ad-card: #ffffff;
  --ad-line: #e3e7ee;
  --ad-ink: var(--ce-navy, #25385b);
  --ad-text: var(--ce-text, #2d3436);
  --ad-muted: #6b7280;
  --ad-accent: var(--ce-blue, #0984e3);
  --ad-up: #0f9d58;
  --ad-down: #d63031;
  --ad-amber-bg: #fff4dc;
  --ad-amber: #a15c00;
  --ad-radius: 10px;
  --ad-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ad-bg);
  color: var(--ad-text);
  font-family: var(--ce-font, Arial, sans-serif);
  font-size: 14px;
  line-height: 1.4;
}
button, input { font: inherit; color: inherit; }
a { color: var(--ad-accent); }
[hidden] { display: none !important; }

/* ---------- Site header offset ----------
 * The page uses the shared Squarespace header/footer (same as project-explorer.html).
 * That header is position: fixed, and Squarespace only pads its own page sections,
 * so the dashboard root clears it itself. --ad-site-h is the header's measured height
 * (adTrackTabsHeight in adash-app.js); the tabs and filter bar stick just under it. */
.ad-root { padding-top: var(--ad-site-h, 100px); background: var(--ad-bg); }
/* Squarespace's site-bundle writes scroll-behavior: smooth (and scroll-padding-top)
   inline on <html>, so these need !important. The dashboard's tab-switch scroll and
   chart scrollIntoView calls expect instant jumps. */
html { scroll-behavior: auto !important; }

/* ---------- Buttons ---------- */
.ad-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border: 1px solid var(--ad-line); border-radius: 8px;
  background: var(--ad-card); color: var(--ad-ink); cursor: pointer;
  text-decoration: none; font-weight: 600; white-space: nowrap;
}
.ad-btn:hover { border-color: #c8d0dc; background: #fafbfc; }
.ad-btn-primary { background: var(--ad-accent); border-color: var(--ad-accent); color: #fff; }
.ad-btn-primary:hover { background: #2fa1f4; border-color: #2fa1f4; }
.ad-btn-ghost { border-color: transparent; background: transparent; color: var(--ad-muted); }
.ad-btn-lg { padding: 11px 28px; font-size: 15px; }
.ad-link { border: 0; background: none; color: var(--ad-accent); cursor: pointer; padding: 2px 4px; }
.ad-icon-btn {
  border: 1px solid transparent; background: none; cursor: pointer; color: var(--ad-muted);
  padding: 3px 7px; border-radius: 6px; font-size: 12px; font-weight: 600;
}
.ad-icon-btn:hover { border-color: var(--ad-line); color: var(--ad-ink); }

/* ---------- Tabs (sticky; the filter bar sticks under them on desktop) ---------- */
.ad-tabs {
  display: flex; gap: 4px; padding: 0 24px; background: var(--ad-card);
  border-bottom: 1px solid var(--ad-line); overflow-x: auto;
  position: sticky; top: var(--ad-site-h, 0px); z-index: 25;
}
.ad-tab {
  position: relative; border: 0; background: none; cursor: pointer; padding: 12px 14px 10px;
  color: var(--ad-muted); font-weight: 600; border-bottom: 3px solid transparent;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.ad-tab:hover { color: var(--ad-ink); }
.ad-tab:focus-visible { outline: 2px solid var(--ad-accent); outline-offset: -4px; border-radius: 6px; }
.ad-tab[aria-selected="true"] { color: var(--ad-ink); border-bottom-color: var(--ad-accent); }
.ad-tab-icon { width: 17px; height: 17px; flex-shrink: 0; }
.ad-tab[aria-selected="true"] .ad-tab-icon { color: var(--ad-accent); }
.ad-tab-short { display: none; }
.ad-tab .ad-lock { width: 13px; height: 13px; opacity: 0.65; flex-shrink: 0; }
.ad-tab.is-locked .ad-tab-icon, .ad-tab.is-locked .ad-tab-label, .ad-tab.is-locked .ad-tab-short { opacity: 0.75; }

/* ---------- Filter bar ---------- */
.ad-filterbar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 12px 24px; position: sticky; top: calc(var(--ad-site-h, 0px) + var(--ad-tabs-h, 46px)); z-index: 20;
  background: rgba(244, 246, 249, 0.96); backdrop-filter: blur(4px);
  border-bottom: 1px solid var(--ad-line);
}
.ad-filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.ad-filterbar-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.ad-stamp { color: var(--ad-muted); font-size: 13px; white-space: nowrap; }
.ad-stamp-m, .ad-export-icon { display: none; }
.ad-export-icon { width: 17px; height: 17px; }

.ad-dd { position: relative; }
.ad-dd-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px;
  border: 1px solid var(--ad-line); border-radius: 8px; background: var(--ad-card);
  cursor: pointer; font-weight: 600; color: var(--ad-ink);
}
.ad-dd-btn[aria-expanded="true"], .ad-dd.has-value .ad-dd-btn { border-color: var(--ad-accent); }
.ad-dd-count {
  background: var(--ad-accent); color: #fff; border-radius: 999px; padding: 0 7px;
  font-size: 12px; line-height: 18px;
}
.ad-caret { font-size: 11px; color: var(--ad-muted); }
.ad-dd-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  width: 300px; max-width: calc(100vw - 32px);
  background: var(--ad-card); border: 1px solid var(--ad-line); border-radius: var(--ad-radius);
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.15); padding: 8px;
}
.ad-dd-panel-wide { width: 380px; }
.ad-dd-search {
  width: 100%; padding: 8px 10px; border: 1px solid var(--ad-line); border-radius: 8px;
  margin-bottom: 6px;
}
.ad-dd-list { max-height: 320px; overflow-y: auto; }
.ad-opt {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px;
  cursor: pointer; user-select: none;
}
.ad-opt:hover { background: #f2f5f9; }
.ad-opt input { margin: 0; accent-color: var(--ad-accent); }
.ad-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.ad-opt-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-dd-actions { display: flex; justify-content: space-between; align-items: center; padding: 6px 4px 0; border-top: 1px solid var(--ad-line); margin-top: 6px; }
.ad-dd-note { color: var(--ad-muted); font-size: 12px; }
.ad-dd-done, .ad-dd-backdrop { display: none; }

.ad-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.ad-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px;
  background: #e8f2fd; color: var(--ad-ink); border: 1px solid #c7e0fa; border-radius: 999px;
  font-size: 12px; max-width: 320px;
}
.ad-chip.is-drill { background: #f1ecfb; border-color: #dccff5; }
.ad-chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-chip button {
  border: 0; background: none; cursor: pointer; color: var(--ad-muted);
  padding: 0 5px; border-radius: 999px; line-height: 18px;
}
.ad-chip button:hover { background: rgba(0, 0, 0, 0.07); color: var(--ad-ink); }

.ad-export { position: relative; }
.ad-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 240px;
  background: var(--ad-card); border: 1px solid var(--ad-line); border-radius: var(--ad-radius);
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.15); padding: 6px;
}
.ad-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.ad-menu button:hover { background: #f2f5f9; }

/* ---------- Page ---------- */
.ad-main { padding: 20px 24px 32px; max-width: 1680px; margin: 0 auto; }
.ad-section + .ad-section { margin-top: 20px; }
.ad-section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ad-muted); margin: 0 0 10px; }

.ad-scorecards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.ad-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.ad-grid .ad-span-2 { grid-column: 1 / -1; }
@media (max-width: 1000px) { .ad-grid { grid-template-columns: minmax(0, 1fr); } }

.ad-card {
  background: var(--ad-card); border: 1px solid var(--ad-line); border-radius: var(--ad-radius);
  box-shadow: var(--ad-shadow); min-width: 0; display: flex; flex-direction: column;
}

/* Scorecard */
.ad-sc { padding: 14px 16px 12px; gap: 4px; }
.ad-sc-title { color: var(--ad-muted); font-size: 12.5px; font-weight: 600; }
.ad-sc-value { font-size: 26px; font-weight: 700; color: var(--ad-ink); letter-spacing: -0.01em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.ad-sc-delta { font-size: 12.5px; font-weight: 600; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.ad-sc-delta .up { color: var(--ad-up); }
.ad-sc-delta .down { color: var(--ad-down); }
.ad-sc-delta .flat { color: var(--ad-muted); }
.ad-sc-delta .vs { color: var(--ad-muted); font-weight: 400; }
.ad-sc-hints { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }

/* Chart card */
.ad-cc-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 16px 6px; }
.ad-cc-titles { min-width: 0; flex: 1; }
.ad-cc-title { margin: 0; font-size: 15px; color: var(--ad-ink); font-weight: 700; }
.ad-crumbs { font-size: 12.5px; margin-top: 3px; color: var(--ad-muted); }
.ad-crumbs button { border: 0; background: none; padding: 0; color: var(--ad-accent); cursor: pointer; }
.ad-cc-tools { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.ad-range { display: inline-flex; border: 1px solid var(--ad-line); border-radius: 7px; overflow: hidden; }
.ad-range button { border: 0; background: none; padding: 3px 9px; cursor: pointer; font-size: 12px; color: var(--ad-muted); font-weight: 600; }
.ad-range button[aria-pressed="true"] { background: var(--ad-ink); color: #fff; }
.ad-cc-body { position: relative; padding: 4px 16px 8px; height: 340px; min-width: 0; }
.ad-cc-body.is-auto { height: auto; }
/* Touch: a sideways drag scrubs the chart instead of panning the page; vertical
   swipes still scroll. Press-and-hold scrubs in any direction (adWireTouch). */
.ad-cc-body canvas {
  cursor: default; touch-action: pan-y pinch-zoom;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.ad-card.ad-cc { transition: box-shadow 0.15s ease, border-color 0.15s ease; }
.ad-card.is-scrubbing { border-color: #b9d8f7; box-shadow: 0 0 0 3px rgba(9, 132, 227, 0.12), var(--ad-shadow); }
.ad-cc-hint { font-size: 12px; color: var(--ad-muted); padding: 0 16px; }

/* Selected-mark bar (touch): value + the click action as a button. */
.ad-cc-action {
  display: flex; align-items: center; gap: 8px; margin: 2px 16px 6px; padding: 6px 6px 6px 12px;
  background: #f2f7fd; border: 1px solid #d5e7fa; border-radius: 10px; min-width: 0;
  animation: ad-pop 0.14s ease-out;
}
.ad-act-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.ad-act-text strong { color: var(--ad-ink); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-act-text span { color: var(--ad-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ad-act-go { padding: 7px 12px; font-size: 13px; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.ad-act-close {
  border: 0; background: none; color: var(--ad-muted); font-size: 20px; line-height: 1;
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer; flex-shrink: 0;
}
.ad-act-close:hover { background: rgba(0, 0, 0, 0.05); color: var(--ad-ink); }
@keyframes ad-pop { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
.ad-cc-foot {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  padding: 8px 16px 12px; margin-top: auto; color: var(--ad-muted); font-size: 12px;
}
.ad-badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.ad-badge-stale { background: var(--ad-amber-bg); color: var(--ad-amber); }
.ad-badge-nf { background: #eef1f5; color: var(--ad-muted); }
.ad-footnote { flex-basis: 100%; }

/* Loading / empty / error */
.ad-card.is-loading .ad-cc-body, .ad-card.is-loading .ad-sc-value { opacity: 0.35; }
.ad-skeleton { position: absolute; inset: 8px 16px; border-radius: 8px; background: linear-gradient(90deg, #eef1f5 25%, #f7f8fa 50%, #eef1f5 75%); background-size: 400% 100%; animation: ad-shimmer 1.4s ease infinite; }
.ad-sc .ad-skel-line { height: 28px; width: 60%; border-radius: 6px; background: linear-gradient(90deg, #eef1f5 25%, #f7f8fa 50%, #eef1f5 75%); background-size: 400% 100%; animation: ad-shimmer 1.4s ease infinite; }
@keyframes ad-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.ad-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ad-muted); text-align: center; padding: 16px; }
.ad-error { color: var(--ad-down); }

/* Tables (voluntary cancellations, drilled transactions) */
.ad-table-tools { display: flex; gap: 8px; align-items: center; padding: 0 16px 8px; }
.ad-table-tools input { flex: 1; max-width: 320px; padding: 6px 10px; border: 1px solid var(--ad-line); border-radius: 8px; }
.ad-table-tools .ad-count { color: var(--ad-muted); font-size: 12px; margin-left: auto; }
.ad-table-wrap { overflow: auto; max-height: 560px; margin: 0 16px; border: 1px solid var(--ad-line); border-radius: 8px; }
.ad-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.ad-table th, .ad-table td { padding: 7px 10px; border-bottom: 1px solid #eef1f5; text-align: left; white-space: nowrap; }
.ad-table th { position: sticky; top: 0; background: #f7f9fb; color: var(--ad-ink); font-weight: 700; z-index: 2; }
.ad-table th.sortable { cursor: pointer; user-select: none; }
.ad-table th.sortable::after { content: " ↕"; color: #b5bdc9; font-weight: 400; }
.ad-table th.asc::after { content: " ↑"; color: var(--ad-ink); }
.ad-table th.desc::after { content: " ↓"; color: var(--ad-ink); }
.ad-table td.num, .ad-table th.num { text-align: right; }
.ad-table tbody tr:hover td { background: #f8fafc; }
.ad-pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 8px 16px 0; font-size: 12px; color: var(--ad-muted); }

/* Pivot heatmap */
.ad-pivot th:first-child, .ad-pivot td:first-child { position: sticky; left: 0; background: #fff; z-index: 1; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.ad-pivot th:first-child { z-index: 3; background: #f7f9fb; }
.ad-pivot td.cell { text-align: right; min-width: 92px; }
.ad-pivot tr.total td, .ad-pivot td.rowtotal { font-weight: 700; background: #f7f9fb; }
.ad-pivot tr.total td { position: sticky; bottom: 0; }

/* Modal */
.ad-modal { position: fixed; inset: 0; z-index: 100; background: rgba(17, 24, 39, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.ad-modal-card { position: relative; background: #fff; border-radius: 14px; padding: 28px 30px 26px; width: 100%; max-width: 380px; text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
.ad-modal-card h2 { margin: 0 0 10px; color: var(--ad-ink); font-size: 26px; }
.ad-modal-card p { margin: 0 0 16px; color: var(--ad-text); }
.ad-modal-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--ad-muted); }
.ad-auth-logos { display: flex; justify-content: center; gap: 20px; margin: 4px 0 20px; }
.ad-auth-logos svg { width: 28px; height: 28px; }

.ad-footer { text-align: center; color: var(--ad-muted); font-size: 12px; padding: 8px 16px 28px; }
.ad-print-summary { display: none; }

/* ---------- Tablet / phone ---------- */
@media (max-width: 760px) {
  body { font-size: 14px; -webkit-text-size-adjust: 100%; }

  .ad-tabs::-webkit-scrollbar { display: none; }

  /* Tabs: an app-style bar, icon over a short label, all five fit across a phone
     with no sideways scrolling. It stays pinned to the top while scrolling. */
  .ad-tabs { padding: 0; gap: 0; scrollbar-width: none; box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06); }
  .ad-tab {
    flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px;
    padding: 8px 2px 6px; font-size: 11px; letter-spacing: 0.01em;
  }
  .ad-tab-icon { width: 21px; height: 21px; }
  .ad-tab-label { display: none; }
  .ad-tab-short { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .ad-tab .ad-lock {
    position: absolute; top: 5px; left: calc(50% + 6px); width: 14px; height: 14px; padding: 2px;
    background: var(--ad-card); border-radius: 999px; opacity: 1; color: var(--ad-muted);
  }
  .ad-tab:active { background: #f2f5f9; }

  /* Filter bar: pinned under the tabs as one compact row (Method, Proponent, Reset,
     icon-only Export), with active chips on a second row that scrolls sideways. The
     data stamp moves out of the bar into #ad-stamp-m below it. Solid background
     because backdrop-filter would make the bar the containing block for the fixed
     bottom-sheet dropdowns below. */
  .ad-filterbar {
    flex-direction: row; align-items: flex-start; gap: 6px; padding: 8px 12px;
    background: var(--ad-bg); backdrop-filter: none;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.05);
  }
  .ad-filters { flex: 1; gap: 6px; }
  .ad-dd-btn, .ad-filterbar .ad-btn { padding: 7px 10px; }
  .ad-filterbar #ad-reset { padding: 7px 6px; }
  .ad-filterbar-right { gap: 6px; }
  .ad-stamp { display: none; }
  .ad-stamp-m { display: block; color: var(--ad-muted); font-size: 12px; margin: 0; padding: 10px 16px 0; }
  .ad-stamp-m:empty { display: none; }
  .ad-export-text { display: none; }
  .ad-export-icon { display: block; }
  .ad-chips {
    order: 10; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .ad-chips::-webkit-scrollbar { display: none; }
  .ad-chips:empty { display: none; }
  .ad-chip { max-width: 85%; flex-shrink: 0; }

  /* Dropdowns open as a bottom sheet instead of a popover that runs off-screen. */
  .ad-dd-panel, .ad-dd-panel-wide {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none;
    border-radius: 14px 14px 0 0; padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 40px rgba(16, 24, 40, 0.25); z-index: 60;
    bottom: var(--ad-kb, 0px);
    display: flex; flex-direction: column;
    max-height: calc(var(--ad-vvh, 100vh) - 24px);
  }
  /* The list shrinks to fit when the keyboard is up, so search, list and Done all stay visible. */
  .ad-dd-list { max-height: 55vh; flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; }
  .ad-dd-search, .ad-dd-actions { flex-shrink: 0; }
  .ad-dd-search { width: auto; align-self: stretch; min-width: 0; }
  .ad-dd-actions { gap: 12px; }
  .ad-dd-actions .ad-dd-note { flex: 1; }
  .ad-dd-done { display: inline-flex; padding: 8px 18px; }
  /* Backdrop under the sheet (same stacking context, the filter bar): a tap anywhere
     outside closes it, instead of landing on a chart whose touch handlers eat the click. */
  .ad-dd-backdrop:not([hidden]) {
    display: block; position: fixed; inset: 0; z-index: 55; background: rgba(17, 24, 39, 0.35);
  }
  body.ad-dd-open { overflow: hidden; }
  /* The site privacy banner (z-index 9999, fixed to the bottom) would cover the sheet's
     Done button and last rows; it comes back once the sheet closes. */
  body.ad-dd-open #privacy-popup { visibility: hidden; }
  .ad-opt { padding: 10px 8px; }
  .ad-dd-search { font-size: 16px; } /* 16px stops iOS zooming on focus */
  .ad-menu { min-width: 220px; }
  .ad-menu button { padding: 11px 10px; }

  /* Page */
  .ad-main { padding: 14px 12px 24px; }
  .ad-section + .ad-section { margin-top: 16px; }
  .ad-scorecards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .ad-grid { gap: 12px; }
  .ad-sc { padding: 12px 12px 10px; }
  .ad-sc-value { font-size: 21px; }

  .ad-cc-head { flex-wrap: wrap; padding: 12px 12px 4px; }
  .ad-cc-titles { flex-basis: 100%; }
  .ad-cc-title { font-size: 14.5px; }
  .ad-cc-tools { width: 100%; justify-content: flex-end; }
  .ad-range button { padding: 6px 11px; }
  .ad-icon-btn { padding: 6px 9px; }
  .ad-cc-body { height: 290px; padding: 4px 8px 6px; }
  .ad-cc-hint { padding: 0 12px; }
  .ad-cc-action { margin: 2px 8px 6px; }
  .ad-cc-foot { padding: 8px 12px 12px; }
  /* Room for the pinned tabs + filter bar when the browser scrolls to an anchor / focus. */
  html { scroll-padding-top: calc(var(--ad-site-h, 0px) + var(--ad-tabs-h, 56px) + 56px) !important; }

  .ad-table-tools { flex-wrap: wrap; padding: 0 12px 8px; }
  .ad-table-tools input { max-width: none; flex-basis: 100%; font-size: 16px; }
  .ad-table-tools .ad-count { margin-left: 0; }
  .ad-table-wrap { margin: 0 12px; max-height: 480px; -webkit-overflow-scrolling: touch; }
  .ad-pivot th:first-child, .ad-pivot td:first-child { max-width: 150px; }
  .ad-pivot td.cell { min-width: 76px; }
  .ad-pager { padding: 8px 12px 0; }
  .ad-pager button { padding: 6px 10px; }

  .ad-modal-card { padding: 24px 20px 22px; }
}

@media (max-width: 340px) {
  .ad-tab { font-size: 10px; }
  .ad-scorecards { grid-template-columns: minmax(0, 1fr); }
  .ad-cc-body { height: 260px; }
}

/* ---------- Print / PDF (§6.2): one page section per sheet, filters summarised ---------- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .ad-tabs, .ad-filters, .ad-export, .ad-cc-tools, .ad-cc-action, .ad-table-tools, .ad-pager, .ad-modal, .ad-footer { display: none !important; }
  /* Site chrome: header once at the top of the PDF (not fixed over every sheet), no footer / cookie bar. */
  header#header { position: static !important; }
  .header-burger, .header-actions, #footer-sections, #privacy-popup { display: none !important; }
  .ad-root { padding-top: 0; background: none; }
  .ad-filterbar { position: static; border: 0; padding: 0; background: none; }
  .ad-print-summary { display: block; margin: 0 0 8px; font-size: 12px; color: var(--ad-ink); }
  .ad-main { padding: 0; max-width: none; }
  .ad-section { break-after: page; }
  .ad-section:last-child { break-after: auto; }
  .ad-card { box-shadow: none; break-inside: avoid; }
  .ad-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .ad-cc-body { height: 250px; overflow: hidden; }
  /* The canvas keeps its on-screen bitmap; scale it into the print card. */
  .ad-cc-body canvas { width: 100% !important; height: 100% !important; object-fit: contain; }
  .ad-stamp, .ad-cc-hint { display: none !important; }
  .ad-table-wrap { max-height: none; overflow: visible; }
}
