/* ============================================================================
   Import Wizard — styles
   ========================================================================== */
:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ef;
  --text: #1b2033;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-weak: #eef0fe;
  --ok: #12855f;
  --ok-weak: #e4f6ee;
  --warn: #a76a00;
  --warn-weak: #fdf2dc;
  --err: #c62b37;
  --err-weak: #fbe6e8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 24, 60, .04), 0 4px 16px rgba(20, 24, 60, .04);
  --grad-a: rgba(79, 70, 229, .05);
  --grad-b: rgba(139, 123, 255, .05);
  --header-bg: rgba(246, 247, 251, .82);
}
/* Dark theme — when the user explicitly toggles it on. */
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #171a23; --surface-2: #1e222d; --border: #2a2f3d;
  --text: #e7e9f2; --muted: #99a0b3; --primary: #7c74ff; --primary-weak: #24273b;
  --ok: #46d19e; --ok-weak: #16281f; --warn: #e0a94b; --warn-weak: #2c2413;
  --err: #ff6b76; --err-weak: #2c1619;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 20px rgba(0,0,0,.25);
  --grad-a: rgba(124, 116, 255, .08); --grad-b: rgba(70, 209, 158, .05);
  --header-bg: rgba(15, 17, 23, .78);
}
/* ...or follow the OS when the user hasn't explicitly chosen light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #171a23; --surface-2: #1e222d; --border: #2a2f3d;
    --text: #e7e9f2; --muted: #99a0b3; --primary: #7c74ff; --primary-weak: #24273b;
    --ok: #46d19e; --ok-weak: #16281f; --warn: #e0a94b; --warn-weak: #2c2413;
    --err: #ff6b76; --err-weak: #2c1619;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 20px rgba(0,0,0,.25);
    --grad-a: rgba(124, 116, 255, .08); --grad-b: rgba(70, 209, 158, .05);
    --header-bg: rgba(15, 17, 23, .78);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background-color .3s ease, color .3s ease;
  background-color: var(--bg);
  /* light wash confined to the top of the page only — scrolls away with the
     content instead of tracking the viewport, so it never re-appears lower down */
  background-image:
    radial-gradient(900px 420px at 10% 0%, var(--grad-a), transparent 60%),
    radial-gradient(800px 380px at 100% 0%, var(--grad-b), transparent 60%);
  background-repeat: no-repeat;
  background-position: top left, top right;
  min-height: 100vh;
}
.app { max-width: 1240px; margin: 0 auto; padding: 24px 20px 80px; }

/* smooth colour changes when toggling theme */
.panel, .tile, .db-pill, .source, .chip, .btn, .stepper .st, th, td, input, .drop, .filebox, .theme-opt {
  transition: background-color .3s ease, border-color .3s ease, color .3s ease, box-shadow .2s ease, transform .12s ease;
}

/* ---- animations ---- */
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes flashOk { 0% { background: var(--ok-weak); } 60% { background: var(--ok-weak); } 100% { background: transparent; } }
@keyframes tagPop { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: none; } }

/* ---- header ----
   A real full-width sticky app bar living OUTSIDE .app (see index.html), so
   there's no negative-margin bleed trick fighting position:sticky — that
   combination is what made the old header feel glitchy on scroll. */
header.top {
  position: sticky; top: 0; z-index: 40;
  background: var(--header-bg);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.top-inner {
  max-width: 1240px; margin: 0 auto; padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -.2px; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.db-pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow); cursor: pointer;
}
.db-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }

/* ---- stepper ---- */
.stepper { display: flex; gap: 8px; margin: 22px 0 26px; flex-wrap: wrap; }
.stepper .st {
  flex: 1; min-width: 150px; display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; color: var(--muted); font-size: 13.5px; font-weight: 600;
}
.stepper .st .num {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--muted); font-size: 12.5px; flex: none;
}
.stepper .st.active { border-color: var(--primary); color: var(--text); box-shadow: var(--shadow); }
.stepper .st.active .num { background: var(--primary); color: #fff; }
.stepper .st.done .num { background: var(--ok); color: #fff; }
.stepper .st.done { color: var(--text); }

/* ---- cards / panels ---- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px; box-shadow: var(--shadow);
}
.step { display: none; }
.step.active { display: block; animation: fade .25s ease; }
h2.title { margin: 0 0 4px; font-size: 19px; letter-spacing: -.2px; }
p.sub { margin: 0 0 22px; color: var(--muted); }

/* ---- home / wizard heads ---- */
.home-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.wizard-head { margin-bottom: 6px; }
#openWizard { font-size: 15px; padding: 12px 20px; }

/* ---- source cards ---- */
.sources { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.source {
  position: relative; text-align: left; padding: 18px; border-radius: 12px; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--border); transition: .15s;
}
.source:hover:not(.disabled) { border-color: var(--primary); transform: translateY(-1px); }
.source.selected { border-color: var(--primary); background: var(--primary-weak); }
.source.disabled { opacity: .6; cursor: not-allowed; }
.source .name { font-weight: 700; }
.source .desc { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.source .soon {
  position: absolute; top: 12px; right: 12px; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .4px; color: var(--warn);
  background: var(--warn-weak); padding: 3px 8px; border-radius: 999px;
}
.source.selected::after {
  content: "Selected"; position: absolute; top: 12px; right: 12px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: #fff; background: var(--primary); padding: 3px 8px; border-radius: 999px;
}

/* ---- dropzone ---- */
.drop {
  border: 2px dashed var(--border); border-radius: 14px; padding: 30px 20px; text-align: center;
  background: var(--surface-2); cursor: pointer; transition: .15s;
  border-top: 3px solid var(--primary);
}
.drop.hover { border-color: var(--primary); background: var(--primary-weak); }
.drop .hint { color: var(--muted); font-size: 13px; margin-top: 6px; }
.filebox {
  display: none; align-items: center; gap: 12px; margin-top: 16px; padding: 14px 16px;
  border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 12px; background: var(--surface);
}
.filebox.show { display: flex; }
.filebox .meta { flex: 1; }
.filebox .meta b { display: block; }
.filebox .meta span { color: var(--muted); font-size: 12.5px; }

/* consistent vertical rhythm between every block on the dashboard — the
   clients table, the charts panel, and each collapsible all get the same
   guaranteed gap regardless of which two happen to be adjacent */
#view-home > * + * { margin-top: 24px; }

/* ---- stat tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { padding: 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.tile .n { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.tile .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tile.ok .n { color: var(--ok); } .tile.warn .n { color: var(--warn); }
.tile.err .n { color: var(--err); } .tile.info .n { color: var(--primary); }

/* ---- dashboard charts ----
   bar chart (magnitude) takes the wide column; donut (status) sits beside it on
   large screens, stacking below on narrow ones. */
.charts-panel { display: grid; grid-template-columns: 1.7fr 1fr; gap: 30px; align-items: start; }
.chart-box { width: 100%; min-width: 0; }
.chart-box-donut { border-left: 1px solid var(--border); padding-left: 30px; }
.chart-head { margin-bottom: 18px; }
.chart-title { margin: 0 0 2px; font-size: 15px; }
.chart-sub { margin: 0; color: var(--muted); font-size: 12.5px; }
.chart-empty { color: var(--muted); font-size: 13px; margin: 0; }

/* single-hue magnitude bar chart — one series, so no legend (title names it) */
.bar-chart { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr auto; align-items: center; gap: 14px; }
.bar-label {
  font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track { height: 18px; border-radius: 9px; background: var(--surface-2); overflow: hidden; }
.bar-fill {
  height: 100%; min-width: 6px; border-radius: 9px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .22), rgba(255, 255, 255, 0)), var(--primary);
  transform-origin: left center;
  animation: growBar .6s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes growBar { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.bar-row:hover .bar-track { box-shadow: 0 0 0 2px var(--primary-weak); }
.bar-value { font-size: 12.5px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* two-segment status donut — clean vs flagged, legend always shown (>= 2 series) */
.chart-box-donut { display: flex; flex-direction: column; align-items: center; text-align: center; }
.chart-box-donut .chart-head { text-align: left; align-self: stretch; }
.donut-svg { width: 172px; height: 172px; }
.donut-svg circle { transition: stroke-dasharray .6s ease; }
.donut-hero { font-size: 24px; font-weight: 800; fill: var(--text); }
.donut-hero-label { font-size: 10px; fill: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.chart-legend { list-style: none; margin: 16px 0 0; padding: 0; display: flex; gap: 20px; }
.chart-legend li { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.chart-legend b { font-variant-numeric: tabular-nums; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ---- column chips ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 20px; }
.chip { font-size: 12.5px; font-weight: 600; padding: 5px 11px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); }

/* ---- tabs ---- */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 0; }
.tab {
  padding: 11px 16px; cursor: pointer; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; border-top: none;
  border-left: none; border-right: none; font-size: 14px;
}
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.tab .badge {
  font-size: 11.5px; font-weight: 700; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2);
}
.tab.tab-err.active .badge { background: var(--err-weak); color: var(--err); }
.tab.tab-ok.active .badge { background: var(--ok-weak); color: var(--ok); }

/* ---- tables ---- */
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 12px 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 720px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; color: var(--muted); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
td.rep { background: var(--primary-weak); }
tr.fixed-row td { background: var(--ok-weak); }
td input {
  width: 100%; min-width: 90px; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 7px; background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}
/* Needs-attention tables: every column shows normally — only the specific
   field(s) get an outline. Red = hard error to fix, amber = optional missing. */
td input.bad {
  border-color: var(--err);
  outline: 2px solid var(--err);
  outline-offset: 1px;
}
td input.warn {
  border-color: var(--warn);
  outline: 2px solid var(--warn);
  outline-offset: 1px;
}

/* ---- badges / tags ---- */
.tag {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  margin: 1px 3px 1px 0; background: var(--surface-2); color: var(--muted);
}
.tag.rep { background: var(--primary-weak); color: var(--primary); }
.tag.warn { background: var(--warn-weak); color: var(--warn); }
.tag.err { background: var(--err-weak); color: var(--err); }
.tag.new { background: var(--ok-weak); color: var(--ok); }
tr.new-row td { background: var(--ok-weak); }
tr.updated-row td { background: var(--primary-weak); }

/* ---- buttons / actions ---- */
.actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; align-items: center; }
.btn {
  padding: 11px 20px; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); transition: .12s;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.ghost { background: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.sm { padding: 7px 13px; font-size: 13px; }
.spacer { flex: 1; }

/* ---- done / success ---- */
.success { text-align: center; padding: 20px 0 8px; }
.success-badge {
  display: inline-block; padding: 5px 14px; border-radius: 999px; margin-bottom: 14px;
  background: var(--ok-weak); color: var(--ok); font-weight: 700; font-size: 12px;
  letter-spacing: .4px; text-transform: uppercase;
}
.success h2 { margin: 0 0 6px; font-size: 22px; color: var(--ok); }
.note { font-size: 12.5px; color: var(--muted); margin-top: 14px; }
.hidden { display: none !important; }

/* ---- Airtable push status on the Done screen ---- */
.at-sync-status {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 16px;
  padding: 8px 16px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  animation: fade .25s ease;
}
.at-sync-status a { color: inherit; text-decoration: underline; }
.at-sync-status.ok { background: var(--ok-weak); color: var(--ok); border-color: transparent; }
.at-sync-status.err { background: var(--err-weak); color: var(--err); border-color: transparent; }
.at-sync-spinner {
  width: 13px; height: 13px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-top-color: transparent; opacity: .7;
  animation: spin .7s linear infinite;
}
.at-sync-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 10px;
  font-weight: 600; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- header theme switch (segmented Light / Dark, animated slide) ---- */
.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.theme-switch {
  position: relative;
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; box-shadow: var(--shadow);
}
/* the pill that slides behind whichever option is active */
.theme-switch-thumb {
  position: absolute; top: 3px; left: 3px; z-index: 0;
  width: calc(50% - 3px); height: calc(100% - 6px);
  background: var(--primary); border-radius: 999px;
  transition: transform .25s cubic-bezier(.4, 0, .2, 1);
}
.theme-switch-thumb.dark { transform: translateX(100%); }
.theme-opt {
  position: relative; z-index: 1; flex: 1; text-align: center;
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
  transition: color .2s ease;
}
.theme-opt:hover { color: var(--text); }
.theme-opt.active { color: #fff; }

/* ---- animated bits ---- */
#view-home, #view-wizard { animation: fade .3s ease; }
.tiles .tile { animation: popIn .35s ease backwards; }
.tiles .tile:nth-child(1) { animation-delay: .02s; }
.tiles .tile:nth-child(2) { animation-delay: .07s; }
.tiles .tile:nth-child(3) { animation-delay: .12s; }
.tiles .tile:nth-child(4) { animation-delay: .17s; }
.tiles .tile:nth-child(5) { animation-delay: .22s; }
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.status-cell .tag { animation: tagPop .18s ease; }
.new-row td { animation: flashOk 1.4s ease; }

/* ---- toggle switch ----
   Settings-row layout: label text on the LEFT (fills the row), the toggle
   pushed to the RIGHT. DOM order stays input → track → label so the
   `input:checked + .track` sibling selector keeps working; only the visual
   order is flipped with `order`. */
.switch { display: flex; align-items: flex-start; gap: 16px; margin: 4px 0 18px; cursor: pointer; }
.switch input { display: none; }
.switch .track {
  order: 2; flex: none; width: 42px; height: 24px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); position: relative; transition: background .2s; margin-top: 1px;
}
.switch .thumb {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--muted); transition: transform .2s, background .2s;
}
.switch input:checked + .track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .track .thumb { transform: translateX(18px); background: #fff; }
.switch .switch-label { order: 1; flex: 1; font-size: 13.5px; line-height: 1.35; }
.switch .switch-label .note { margin: 2px 0 0; }

/* ---- duplicates / skipped summary ---- */
.summary-box {
  margin-top: 14px; border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: 12px;
  background: var(--surface-2); padding: 14px 16px; animation: fade .3s ease;
}
.summary-box.dupe { border-left-color: var(--primary); }
.summary-box.skip { border-left-color: var(--warn); }
.summary-box h4 { margin: 0 0 8px; font-size: 13.5px; }
.summary-box ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.summary-box li { margin: 2px 0; }

/* ---- Needs-attention: each group is its own card (improve vs invalid) ---- */
.review-sec {
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  background: var(--surface); animation: fade .25s ease;
}
.review-sec + .review-sec { margin-top: 20px; }
.review-sec-head {
  display: flex; align-items: flex-start; gap: 12px; padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.review-sec-improve .review-sec-head { background: var(--warn-weak); border-bottom-color: var(--warn-weak); }
.review-sec-invalid .review-sec-head { background: var(--err-weak); border-bottom-color: var(--err-weak); }
.review-sec-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; flex: none; }
.review-sec-improve .review-sec-dot { background: var(--warn); }
.review-sec-invalid .review-sec-dot { background: var(--err); }
.review-sec-title { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 15px; }
.review-sec-title .badge { font-size: 12px; font-weight: 700; padding: 1px 9px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); }
.review-sec-desc { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
/* the table sits flush inside the card — the card border replaces the wrap's */
.review-sec .tablewrap { border: none; border-radius: 0; }
.status-cell .move-btn { margin-left: 4px; vertical-align: middle; }

/* ---- Airtable sync badge ---- */
.sync-badge {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 13px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 13px; font-weight: 600; color: var(--text); text-decoration: none;
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 var(--ok); }
.sync-badge.live .sync-dot { animation: pulse 1.6s infinite; }
.sync-badge.syncing .sync-dot { background: var(--primary); animation: pulse 0.8s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(70, 209, 158, .5); }
  70% { box-shadow: 0 0 0 7px rgba(70, 209, 158, 0); }
  100% { box-shadow: 0 0 0 0 rgba(70, 209, 158, 0); }
}

/* review row states (live validation).
   Rows stay clean — the coloured field outline + the section card carry the
   meaning. Only the "valid now, ready to move" state gets a soft green wash. */
tr.clean-row td { background: var(--ok-weak); }
tr.att-row { transition: opacity .5s ease, transform .5s ease; }
tr.att-row.row-out { opacity: 0; transform: translateX(28px); }

/* ---- collapsible panels: Airtable settings + sync log ---- */
details.logbox { padding: 0; overflow: hidden; }
.logbox-head {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 18px 22px; list-style: none; font-weight: 700; font-size: 15px; user-select: none;
}
.logbox-head:hover { background: var(--surface-2); }
.logbox-head::-webkit-details-marker { display: none; }
.logbox-title { flex: 1; }
.logbox-count {
  min-width: 22px; text-align: center; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); font-size: 12px; font-weight: 700;
}
.logbox-chevron { color: var(--muted); transition: transform .2s ease; }
details.logbox[open] .logbox-chevron { transform: rotate(180deg); }
details.logbox[open] .logbox-head { border-bottom: 1px solid var(--border); }
.logbox-body { padding: 18px 22px 22px; animation: fade .2s ease; }
.logbox-body .tablewrap { max-height: 340px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }

/* Airtable settings form */
.at-form { display: grid; gap: 14px; }
.at-field { display: grid; gap: 6px; }
.at-label { font-size: 13px; font-weight: 700; }
.at-field input[type="text"], .at-field input[type="password"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font-size: 14px;
}
.at-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }
.at-check { display: flex; align-items: flex-start; gap: 10px; font-weight: 500; }
.at-check input { width: 16px; height: 16px; margin-top: 2px; flex: none; }
.at-check span { line-height: 1.4; }
.at-token { display: flex; gap: 8px; align-items: center; }
.at-token input { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .5px; }

/* field mapping (advanced) */
.at-map {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; background: var(--surface-2);
}
.at-map > summary { cursor: pointer; font-weight: 700; font-size: 13px; }
.at-fields { display: grid; gap: 8px; margin-top: 6px; }
.at-field-row { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 10px; }
.at-field-row > span { font-size: 12.5px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.at-field-row input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 13.5px;
}
.at-field-row input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-weak); }

/* ---- Airtable "live view" card (golden gradient) ---- */
.at-live-card {
  margin-top: 16px;
  position: relative;
  border: 1px solid rgba(212, 175, 55, .45);
  background:
    radial-gradient(680px 220px at 0% 0%, rgba(255, 200, 80, .20), transparent 62%),
    linear-gradient(135deg, rgba(255, 214, 120, .10), transparent 55%),
    var(--surface);
  overflow: hidden;
}
.at-live-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, #f6d365, #e6a817 45%, #b8860b);
}
.at-live-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.at-live-titles { flex: 1 1 260px; min-width: 0; }
.at-live-links { display: flex; gap: 8px; flex: none; margin-left: auto; }
.at-logo {
  width: 52px; height: 52px; border-radius: 14px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #ffe390, #e6a817 58%, #b8860b);
  box-shadow: 0 6px 18px rgba(184, 134, 11, .35), inset 0 1px 0 rgba(255,255,255,.5);
}
.at-logo svg { width: 30px; height: 25px; display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.15)); }
.at-live-dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  background: var(--muted); box-shadow: 0 0 0 0 rgba(230, 168, 23, .5);
}
.at-live-dot.on { background: #e6a817; animation: pulse 1.6s infinite; }
.at-live-meta, #atLiveMeta { color: var(--muted); font-size: 12.5px; }

/* ============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 720px) {
  .app { padding: 16px 14px 60px; }
  .top-inner { padding: 14px; }
  .brand h1 { font-size: 18px; }
  .brand p { font-size: 12px; }
  .header-actions { width: 100%; justify-content: space-between; }
  .home-head { flex-direction: column; align-items: stretch; }
  #openWizard { width: 100%; text-align: center; }
  .panel { padding: 18px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .bar-row { grid-template-columns: 84px 1fr auto; gap: 10px; }
  /* charts stack vertically on narrow screens */
  .charts-panel { grid-template-columns: 1fr; gap: 26px; }
  .chart-box-donut { border-left: none; padding-left: 0; border-top: 1px solid var(--border); padding-top: 26px; }
  .stepper .st { min-width: calc(50% - 4px); }
  .logbox-head { padding: 16px 18px; }
  .logbox-body { padding: 16px 18px 18px; }
  /* stack action rows full-width; primary action (last child) rises to the top */
  .actions { flex-direction: column-reverse; align-items: stretch; }
  .actions .spacer { display: none; }
  .actions .btn { width: 100%; text-align: center; }
}

@media (max-width: 480px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .sources { grid-template-columns: 1fr; }
}

/* reduced motion: respect the user's preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
