:root {
  --canvas: #eef1ef;
  --surface: #fbfcfa;
  --surface-subtle: #f8f9f9;
  --surface-quiet: #e4e9e5;
  --surface-soft: #f4f6f4;
  --surface-deep: #d8e0db;
  --ink: #1f2925;
  --muted: #5b6761;
  --faint: #7d8982;
  --line: #c6d0c9;
  --line-strong: #9cac9f;
  --accent: #a94c3e;
  --accent-deep: #74342e;
  --accent-soft: #f2dfda;
  --success: #28704e;
  --success-soft: #dfeee5;
  --running: #28627a;
  --running-soft: #dcebf0;
  --attention: #765913;
  --attention-soft: #f2ead0;
  --danger: #923f3b;
  --danger-soft: #f3dfdd;
  --radius: 6px;
  --sans: "Avenir Next", "Segoe UI", Arial, sans-serif;
  --display: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --panel-pad: 22px;
  --panel-pad-mobile: 16px;
  --layout-gap: 18px;
  --layout-gap-mobile: 14px;
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -50px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 700;
  text-decoration: none;
  transition: top 0.2s ease;
}
.skip-link:focus {
  top: 12px;
}

.screen {
  display: none;
}
.screen.active {
  display: block;
}

.tablewrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

button, input, select, textarea { font: inherit; }
button, input { min-height: 44px; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid #c56d60;
  outline-offset: 2px;
}
a { color: inherit; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 68px;
  padding: 0 clamp(16px, 3.5vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 750;
  letter-spacing: -.02em;
  text-decoration: none;
  color: var(--ink);
}

.mark {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--ink);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 13px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 clamp(16px, 3.5vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-nav a, .app-nav button {
  min-height: 48px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-size: 15px;
  font-weight: 700;
}

.app-nav a.active, .app-nav button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 800;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: clamp(24px, 3.5vw, 48px) clamp(16px, 3.5vw, 40px) 80px;
}

.view-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 28px;
}

.eyebrow {
  color: var(--accent-deep);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.view-heading h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(30px, 4.5vw, 48px);
  line-height: 1.02;
  letter-spacing: -.05em;
}

.lede {
  max-width: 62ch;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary, .secondary, .danger-button, .action-button {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 800;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.primary:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}
.primary[disabled], .primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.secondary {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line-strong);
}
.secondary:hover {
  background: var(--surface-quiet);
}

.danger-button {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #edcaca;
}
.danger-button:hover { background: #f4d9d9; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel-pad {
  padding: var(--panel-pad);
}

.pad,
.panel.pad,
.form-panel {
  padding: var(--panel-pad);
}

/* Workbench & Status Hero */
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(270px, 0.85fr);
  gap: var(--layout-gap);
  align-items: stretch;
  margin-bottom: 24px;
}

.status-hero {
  position: relative;
  overflow: hidden;
  min-height: 250px;
  padding: clamp(20px, 3.5vw, 36px);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: #f4f7f4;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.status-hero:after {
  content: "";
  position: absolute;
  right: 24px;
  bottom: 22px;
  width: 104px;
  height: 104px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  box-shadow: 0 0 0 16px rgba(255, 255, 255, 0.04), 0 0 0 32px rgba(255, 255, 255, 0.035);
  pointer-events: none;
}
.status-hero .eyebrow {
  color: #d8a096;
}
.status-hero h2 {
  max-width: 520px;
  margin: 12px 0 10px;
  font-family: var(--display);
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: -.035em;
  color: #fff;
}
.status-hero p {
  max-width: 52ch;
  margin-bottom: 20px;
  color: #cbd5ce;
  font-size: 15px;
}
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  position: relative;
  z-index: 1;
}

.queue-rail {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.rail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.rail-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
}
.rail-item {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 12px;
  padding: 14px 0 14px 2px;
  border-bottom: 1px solid var(--line);
}
.rail-item:last-child {
  border-bottom: 0;
}
.rail-item:before {
  content: "";
  position: absolute;
  left: 9px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--line-strong);
}
.rail-item:last-child:before {
  bottom: 20px;
}
.rail-marker {
  position: relative;
  z-index: 1;
  width: 16px;
  height: 16px;
  margin-top: 3px;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--surface);
}
.rail-item.done .rail-marker {
  border-color: var(--success);
  background: var(--success);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.rail-item.current .rail-marker {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.rail-item.partial .rail-marker {
  border-color: var(--attention);
  background: var(--attention-soft);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.rail-item.failed .rail-marker {
  border-color: var(--danger);
  background: var(--danger-soft);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.rail-item.waiting .rail-marker {
  border-color: var(--line-strong);
}
.rail-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-weight: 750;
}
.rail-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

/* State texts and badges */
.state-text {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 7px;
  border: 1px solid currentColor;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.state-done { color: var(--success); background: var(--success-soft); }
.state-running { color: var(--running); background: var(--running-soft); }
.state-partial { color: var(--attention); background: var(--attention-soft); }
.state-waiting { color: var(--muted); background: var(--surface-quiet); border-color: var(--line-strong); }
.state-failed { color: var(--danger); background: var(--danger-soft); }

.attention-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin: 20px 0 28px;
  padding: 16px 20px;
  border-left: 5px solid var(--attention);
  background: var(--attention-soft);
  border-radius: var(--radius);
}
.attention-strip strong {
  display: block;
  margin-bottom: 3px;
  color: #4b3600;
}

/* Setup (Add brand layer) */
.setup {
  border-top: 3px solid var(--accent);
  margin-top: 0;
}
.setup h2 {
  margin: 6px 0 5px;
  font-family: var(--display);
  font-size: clamp(26px, 3.2vw, 38px);
  line-height: 1.02;
  letter-spacing: -.04em;
}
.setup-copy {
  max-width: 56ch;
  margin-bottom: 20px;
  color: var(--muted);
}
.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
}
.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 800;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.field input::placeholder {
  color: #69756d;
  opacity: 1;
}
.helper {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.form-message {
  min-height: 21px;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 13px;
}

/* Watchlist Ledger Section */
.section-title {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin: 42px 0 14px;
}
.section-title h2 {
  margin-bottom: 5px;
  font-family: var(--display);
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.02;
  letter-spacing: -.04em;
}
.section-title p {
  margin-bottom: 0;
  color: var(--muted);
}

.watchlist-section {
  margin-top: 36px;
}

.empty-guidance,
.empty-state {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
  padding: 22px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty-guidance h3,
.empty-state h3,
.empty-state h2 {
  margin-bottom: 6px;
  font-family: var(--display);
  font-size: 24px;
}
.empty-guidance p,
.empty-state p {
  max-width: 54ch;
  margin-bottom: 0;
  color: var(--muted);
}

.ledger-wrap,
.ledger {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.ledger-head, .ledger-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.45fr) minmax(100px, .72fr) minmax(112px, .75fr) minmax(118px, .75fr) minmax(190px, 1.22fr);
  gap: 14px;
  align-items: center;
}

.ledger-head {
  padding: 12px 16px;
  color: var(--muted);
  background: var(--surface-quiet);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}

.ledger-row {
  min-height: 92px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  transition: background 0.15s ease;
}
.ledger-row:last-child {
  border-bottom: 0;
}
.ledger-row:hover {
  background: #f5f7f4;
}

.brand-name {
  font-weight: 800;
  overflow-wrap: anywhere;
}
.keywords {
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  overflow-wrap: anywhere;
}
.metric {
  font-family: var(--mono);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.metric small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 12px;
}

.attention,
.attention-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-top: 14px;
  padding: 16px 18px;
  border-left: 5px solid var(--attention);
  background: var(--attention-soft);
  border-radius: var(--radius);
}
.attention strong,
.attention-strip strong {
  display: block;
  margin-bottom: 3px;
  color: #4b3600;
}

/* Check Section (Layer 3) */
.check-section {
  margin-top: 42px;
}
.check-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: clamp(20px, 3vw, 32px);
  background: var(--ink);
  color: #f6f8f5;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
}
.check-panel h2 {
  margin: 5px 0 7px;
  font-family: var(--display);
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.02;
  letter-spacing: -.04em;
  color: #fff;
}
.check-panel p {
  max-width: 58ch;
  margin-bottom: 0;
  color: #d4ddd7;
}
.check-panel .eyebrow {
  color: #e0a79c;
}
.check-panel .primary {
  min-width: 170px;
}
.check-panel .primary:disabled {
  color: #aebbb3;
  background: #43504a;
  border-color: #43504a;
}
.check-action {
  display: grid;
  gap: 8px;
  justify-items: end;
}
.check-help {
  max-width: 210px;
  color: #c6d0c9;
  font-size: 13px;
  text-align: right;
}

.run-strip {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 0;
  margin-bottom: 24px;
}

.run-cell {
  padding: 18px 20px;
  border-right: 1px solid var(--line);
}
.run-cell:last-child { border-right: 0; }

.kicker {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.value {
  margin-top: 4px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.025em;
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.status.done { color: var(--success); background: var(--success-soft); }
.status.running { color: var(--running); background: var(--running-soft); }
.status.attention { color: var(--attention); background: var(--attention-soft); }
.status.error { color: var(--danger); background: var(--danger-soft); }
.status.warn, .status.attention { color: var(--attention); background: var(--attention-soft); }

.partial-result-panel {
  border: 1px solid #e4d19a;
  border-left: 4px solid var(--attention);
  border-radius: var(--radius);
  background: #fffdf7;
  padding: var(--panel-pad);
}
.partial-result-panel h2 { margin: 4px 0 8px; }
.partial-result-count {
  margin: 8px 0 12px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 750;
}
.partial-warning {
  padding: 12px 14px;
  color: var(--attention);
  background: var(--attention-soft);
  border: 1px solid #e4d19a;
  font-weight: 700;
}
.partial-actions { display:flex; flex-wrap:wrap; gap:8px; margin-top:18px; }
.partial-note { max-width: 80ch; margin: 14px 0 0; }

.selection-layout,
.queue-layout,
.progress-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: var(--layout-gap);
  align-items: start;
}
.progress-heading { display:flex; justify-content:space-between; align-items:flex-end; gap:16px; margin-bottom:12px; }
.progress { height:9px; overflow:hidden; background:#dce5e8; border-radius:99px; }
.progress span { display:block; height:100%; background:var(--running); }
.current-brand-progress { margin-top:28px; padding-top:24px; border-top:1px solid var(--line); }
.current-brand-progress h2 { margin:2px 0 0; }
.status-line { min-height:30px; display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.pairs { display:grid; gap:8px; margin-top:18px; }
.pair { display:grid; grid-template-columns:minmax(0,1.2fr) minmax(100px,auto) minmax(0,1fr); gap:10px; align-items:center; padding:12px; border:1px solid var(--line); border-radius:4px; }
.pair strong, .pair span { min-width:0; overflow-wrap:anywhere; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  margin: 34px 0 12px;
}
.section-head h2 { margin: 0; font-family: var(--display); font-size: 22px; letter-spacing: -.025em; }
.section-head p { margin: 0; color: var(--muted); font-size: 14px; }

.brand-list { display: grid; gap: 0; }

.analysis-teaser { min-width: 0; }
.analysis-teaser strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.analysis-teaser span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  align-items: stretch;
}

.action-button {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .1s ease;
}
.action-button:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: var(--ink);
}
.action-button:focus-visible {
  outline: 3px solid #c56d60;
  outline-offset: 3px;
}
.action-button:active:not(:disabled) {
  transform: translateY(1px);
}
.action-button:disabled {
  color: #64716a;
  background: #d9dfda;
  border-color: #c4cec7;
  cursor: not-allowed;
  opacity: 1;
}

.row-actions .action-button {
  flex: 0 1 auto;
  padding: 8px 11px;
}

.row-actions .action-button:nth-child(2),
.row-actions .btn-analyze,
.row-actions .btn-view-analysis {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.row-actions .action-button:nth-child(2):hover:not(:disabled),
.row-actions .btn-analyze:hover:not(:disabled),
.row-actions .btn-view-analysis:hover:not(:disabled) {
  background: var(--accent-deep);
  border-color: var(--accent-deep);
}

.row-actions .action-button:nth-child(2):disabled,
.row-actions .btn-analyze:disabled,
.row-actions .btn-view-analysis:disabled {
  color: #64716a;
  background: #d9dfda;
  border-color: #c4cec7;
  cursor: not-allowed;
  opacity: 1;
}

.row-actions .action-button:last-child,
.row-actions .btn-delete-brand {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #e3b9b5;
}

.row-actions .action-button:last-child:hover:not(:disabled),
.row-actions .btn-delete-brand:hover:not(:disabled) {
  color: #702d2a;
  background: #edcfcc;
  border-color: var(--danger);
}

.callout {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 18px 20px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  margin-bottom: 24px;
}
.callout strong { display: block; }
.callout p { margin: 3px 0 0; color: #68453f; }

.notice {
  padding: 16px 18px;
  background: var(--danger-soft);
  border: 1px solid #edcaca;
  border-radius: var(--radius);
  color: #6e3030;
}
.notice strong { display: block; margin-bottom: 3px; }

.empty-layout {
  max-width: 680px;
  padding: 54px 0 20px;
}
.empty-layout h2 { margin: 0; font-size: 34px; letter-spacing: -.04em; }
.empty-layout p { max-width: 54ch; margin: 12px 0 26px; color: var(--muted); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto;
  gap: 12px;
  align-items: end;
}

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; }
.field input, .field select {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}
.field small { color: var(--muted); font-size: 12px; }

.detail-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}
.detail-top h1 { margin: 0; font-size: 34px; letter-spacing: -.04em; }
.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  display: grid;
  grid-template-columns: auto auto minmax(180px, 1fr) 150px auto;
  gap: 10px;
  align-items: center;
  margin: 24px 0 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  cursor: pointer;
}
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.table-shell {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f7f8f8;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .05em;
  text-transform: uppercase;
}
tbody tr:last-child td { border-bottom: 0; }

.ad-table table { min-width: 900px; }
.ad-table th:nth-child(1), .ad-table td:nth-child(1) { width: 78px; }
.ad-table th:nth-child(2), .ad-table td:nth-child(2) { width: 178px; }
.ad-table th:nth-child(3), .ad-table td:nth-child(3) { width: 160px; }
.ad-table th:nth-child(4), .ad-table td:nth-child(4) { width: 120px; }
.ad-table th:nth-child(5), .ad-table td:nth-child(5) { width: 370px; }
.ad-table th:nth-child(6), .ad-table td:nth-child(6) { width: 130px; }

.ad-copy { max-width: 350px; line-height: 1.65; }
details summary { cursor: pointer; color: var(--ink); font-weight: 700; }
.ad-copy details p { margin: 8px 0 0; color: #464d52; white-space: pre-wrap; word-break: break-word; }

.badge-new, .badge-flagged {
  display: inline-block;
  margin-right: 5px;
  padding: 3px 6px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.badge-new { color: #8e382f; background: var(--accent-soft); }
.link {
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  background: transparent;
  border: 0;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
}
.link:hover { color: var(--accent); text-decoration: underline; }

.analysis-meta {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  margin: 24px 0 30px;
}
.analysis-meta .run-cell { min-height: 88px; }

.analysis-lead h2 { margin: 0 0 12px; font-size: 22px; }
.analysis-table table { min-width: 1060px; }
.analysis-table th, .analysis-table td { min-width: 185px; }
.analysis-table th:first-child, .analysis-table td:first-child { min-width: 170px; }
.analysis-table td { line-height: 1.55; }
.analysis-table th:first-child, .analysis-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
}
.analysis-table th:first-child { z-index: 3; background: #f7f8f8; }

.campaign {
  margin-top: 34px;
  padding-top: 28px;
  border-top: 1px solid var(--line-strong);
}
.campaign h3 { margin: 0 0 14px; font-size: 22px; }

.narrative-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.narrative {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.narrative h4 { margin: 0 0 7px; font-size: 14px; }
.narrative p { max-width: 65ch; margin: 0; color: #464d52; }
.narrative ul { margin: 0; padding-left: 19px; color: #464d52; }

.inferred {
  display: inline-block;
  margin-left: 5px;
  color: var(--attention);
  background: var(--attention-soft);
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 3px;
}

.source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 15px;
  color: var(--muted);
  font-size: 13px;
}

.comparison {
  margin-top: 44px;
  padding: 22px;
  background: #eef3f3;
  border: 1px solid #cbd9db;
  border-radius: var(--radius);
}
.comparison h2 { margin: 0 0 14px; font-size: 21px; }
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.comparison-item {
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.comparison-item strong { display: block; margin-bottom: 5px; }

/* States Gallery specific */
.state-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.state-tabs button {
  min-height: 44px;
  padding: 8px 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.state-tabs button[aria-selected="true"] {
  color: var(--ink);
  border-color: var(--accent);
  font-weight: 700;
}
.state-panel { display: none; }
.state-panel.active { display: block; }

.running-list {
  display: grid;
  gap: 9px;
  max-width: 760px;
}
.running-row {
  display: grid;
  grid-template-columns: 1.2fr 140px 1fr 80px;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.progress-line {
  height: 7px;
  overflow: hidden;
  background: #e2e6e8;
  border-radius: 999px;
}
.progress-line span {
  display: block;
  height: 100%;
  background: var(--running);
  border-radius: inherit;
}
.state-panel .panel { padding: 26px; }

.footer-note {
  margin-top: 48px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
}

/* Batch Analysis v1.7 Styles */
.selection-list {
  display: grid;
  gap: 0;
}
.selection-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 17px 0;
  border-bottom: 1px solid var(--line);
}
.selection-row:last-child {
  border-bottom: 0;
}
.selection-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  min-height: 22px;
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
}
.selection-row input[type="checkbox"]:disabled {
  accent-color: #8c979b;
  cursor: not-allowed;
}
.row-main {
  min-width: 0;
}
.row-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.row-actions {
  text-align: right;
}
.row-warning, .row-reason {
  grid-column: 2 / -1;
  font-size: 14px;
}
.row-warning {
  padding: 10px 12px;
  background: var(--attention-soft);
  color: var(--attention);
  border: 1px solid #e4d19a;
  border-radius: 4px;
  margin-top: 8px;
  font-weight: 600;
}
.row-reason {
  color: var(--muted);
  margin-top: 4px;
}
.selection-summary {
  position: sticky;
  top: 78px;
  height: max-content;
}
.summary-count {
  font-size: 24px;
  font-weight: 750;
  font-family: var(--mono);
  letter-spacing: -.04em;
}
.summary-actions {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}
.announce {
  min-height: 24px;
  margin-top: 12px;
  color: var(--danger);
  font-weight: 700;
}
.progress-rows {
  display: grid;
  gap: 0;
  margin-top: 22px;
}
.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.progress-row:last-child {
  border-bottom: 0;
}
.progress-row small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
}
.current-warning {
  margin-top: 16px;
}
.failure {
  padding: 12px 14px;
  margin-top: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 650;
  border: 1px solid #edcaca;
  border-radius: 4px;
}
.terminal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0;
}
.terminal-stat {
  padding: 16px;
  background: var(--surface-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.terminal-stat strong {
  display: block;
  font-size: 26px;
  font-family: var(--mono);
  margin: 4px 0;
}
.terminal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.status.skip {
  background: #edf0f1;
  color: var(--muted);
}
.scope-warning {
  padding: 12px 14px;
  background: var(--attention-soft);
  border: 1px solid #e4d19a;
  color: var(--attention);
  font-weight: 650;
  border-radius: 4px;
}

/* v1.8 Scrape Queue Styles */
.queue-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}
.queue-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.queue-row.current {
  border-color: var(--running);
  box-shadow: inset 4px 0 var(--running);
}
.queue-row.complete {
  box-shadow: inset 4px 0 var(--success);
}
.queue-row.waiting {
  box-shadow: inset 4px 0 var(--line);
}
.queue-row.warn {
  box-shadow: inset 4px 0 var(--attention);
}
.queue-row.error {
  box-shadow: inset 4px 0 var(--danger);
}
.queue-num {
  font: 750 18px var(--mono);
  color: var(--muted);
}
.queue-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.decision {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: var(--panel-pad);
  background: var(--surface);
}
.decision h2 {
  margin-bottom: 6px;
}
.decision-count {
  font: 750 28px var(--mono);
  margin: 10px 0;
}
.countdown {
  font: 750 20px var(--mono);
  font-variant-numeric: tabular-nums;
}
.warning {
  padding: 12px 14px;
  background: var(--attention-soft);
  border: 1px solid #e4d19a;
  color: #57420c;
  border-radius: 4px;
}
.failure {
  padding: 12px 14px;
  background: var(--danger-soft);
  border: 1px solid #edcaca;
  color: #6b2020;
  border-radius: 4px;
}

/* Responsive queries */
@media (max-width: 980px) {
  .workbench { grid-template-columns: 1fr; }
  .queue-rail { max-width: 100%; }
  .ledger, .ledger-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .ledger-head, .ledger-row { min-width: 760px; }
}

@media (max-width: 700px) {
  .ledger-wrap { overflow: visible; }
  .ledger-head { display: none; }
  .ledger-row {
    min-width: 0;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    padding: 16px;
    align-items: start;
  }
  .ledger-row .actions {
    grid-column: 1 / -1;
    padding-top: 12px;
    border-top: 1px solid var(--line);
  }
  .row-actions .action-button {
    flex: 1 1 112px;
  }
}

@media (max-width: 900px) {
  .app-header { padding: 0 18px; }
  .app-nav { padding: 0 18px; overflow-x: auto; }
  main { padding: 28px 18px 60px; }
  .run-strip, .analysis-meta { grid-template-columns: 1fr 1fr; }
  .run-cell:nth-child(2) { border-right: 0; }
  .run-cell:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .controls { grid-template-columns: 1fr 1fr; }
  .controls .field, .controls .secondary { grid-column: span 2; }
  .narrative-grid, .comparison-grid { grid-template-columns: 1fr; }
  .pair { grid-template-columns: minmax(0, 1fr) auto; }
  .pair .muted { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  :root {
    --panel-pad: var(--panel-pad-mobile);
    --layout-gap: var(--layout-gap-mobile);
  }
  .selection-layout,
  .queue-layout,
  .progress-layout {
    grid-template-columns: 1fr;
    gap: var(--layout-gap-mobile);
  }
  .selection-summary {
    position: static;
  }
  .queue-sidebar {
    order: 2;
  }
  .pad,
  .panel.pad,
  .form-panel,
  .decision,
  .partial-result-panel {
    padding: var(--panel-pad-mobile);
  }
  .terminal-grid {
    grid-template-columns: 1fr 1fr;
  }
  .attention-strip, .empty-state {
    grid-template-columns: 1fr;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .progress-heading { align-items:flex-start; flex-direction:column; }
  .pair { grid-template-columns:1fr; }
  .pair .muted { grid-column:auto; }
  body { font-size: 14px; }
  .app-header { align-items: flex-start; flex-direction: column; gap: 9px; padding: 16px; }
  .header-right { width: 100%; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
  .app-nav { padding: 0 16px; }
  .app-nav a, .app-nav button { padding: 0 9px; }
  main { padding: 24px 14px 48px; }
  .view-heading, .detail-top { flex-direction: column; }
  .view-heading h1, .detail-top h1 { font-size: 30px; }
  .actions, .actions .primary, .actions .secondary { width: 100%; }
  .actions button, .actions a { width: 100%; }
  .status-hero { min-height: 0; }
  .status-hero:after { right: -28px; bottom: -28px; }
  .run-strip, .analysis-meta { grid-template-columns: 1fr; }
  .run-cell { border-right: 0; border-bottom: 1px solid var(--line); }
  .run-cell:last-child { border-bottom: 0; }
  .controls { grid-template-columns: 1fr; }
  .controls .field, .controls .secondary { grid-column: auto; }
  .running-row { grid-template-columns: 1fr 80px; gap: 8px; }
  .running-row .progress-line { grid-column: span 2; }
  .selection-row { grid-template-columns: 30px 1fr; }
  .selection-row .row-actions { grid-column: 2; text-align: left; margin-top: 6px; }
  .queue-row { grid-template-columns: 36px 1fr; }
  .queue-row > .status { grid-column: 2; justify-self: start; }
  .decision .actions { display: grid; gap: 8px; }
  .decision .actions > * { width: 100%; text-align: center; }
  .terminal-grid { grid-template-columns: 1fr; }
  .summary-actions button, .terminal-actions button { width: 100%; }

  /* Ad table stacked cards transformation on phone 390 */
  .ad-table .table-shell { overflow: visible; border: 0; background: transparent; }
  .ad-table table, .ad-table thead, .ad-table tbody, .ad-table tr, .ad-table td {
    display: block;
    width: 100%;
    min-width: 0;
  }
  .ad-table thead { display: none; }
  .ad-table tr {
    margin-bottom: 10px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .ad-table td {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
  .ad-table td:last-child { border-bottom: 0; }
  .ad-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .05em;
    text-transform: uppercase;
  }
  .ad-table .ad-copy { max-width: none; }
  .ad-table .ad-copy details p { margin-top: 8px; }

  .analysis-table { margin-right: -14px; border-left: 0; border-right: 0; border-radius: 0; }
  .analysis-table table { min-width: 940px; }
  .analysis-table th:first-child, .analysis-table td:first-child { position: sticky; left: 0; }
}

/* Text wrapping and overflow safeguards */
h1, h2, h3, h4, h5, h6,
p, strong, span, small,
.brand-name, .value, .mono,
.summary-count, .decision-count, .countdown,
.queue-meta, .row-meta, .row-main,
.warning, .failure, .notice, .partial-warning, .scope-warning {
  overflow-wrap: break-word;
  word-break: break-word;
}

.brand-row, .queue-row, .selection-row, .progress-row, .pair {
  min-width: 0;
}

.brand-name, .queue-meta, .row-main, .pair strong, .pair span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.empty-list {
  padding: 26px 20px;
  color: var(--muted);
  background: var(--surface-subtle);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty-list strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 16px;
}
.analysis-index table { min-width: 720px; }
.analysis-index td:last-child { width: 90px; }
.empty-analysis { padding: 28px 20px; color: var(--muted); }
.empty-analysis strong { display: block; margin-bottom: 4px; color: var(--ink); font-size: 16px; }
.state-card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.state-card h3 { margin: 0 0 7px; font-size: 17px; }
.state-card p { margin: 0; color: var(--muted); }
.state-card .actions { margin-top: 17px; }
.back-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  margin-bottom: 18px;
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
}
.back-link:hover { color: var(--accent); }

@media print {
  .app-header, .app-nav, .actions, .controls, .footer-note, .state-tabs { display: none !important; }
  main { padding: 0; max-width: 100%; }
  .panel, .narrative, .comparison { border: 1px solid #ccc !important; break-inside: avoid; }
  .campaign { break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  .action-button:active {
    transform: none;
  }
}
