/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ── */
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #1a1a1a;
  background: #f2f2f4;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: #12122a;
  color: #fff;
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* ── Data mode badge ── */
.data-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: #3d2e00;
  color: #ffc107;
  border: 1px solid #7a5c00;
  border-radius: 4px;
  padding: 3px 8px;
  white-space: nowrap;
}

.data-mode-detail {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 10px;
  color: #d4a800;
  border-left: 1px solid #7a5c00;
  margin-left: 7px;
  padding-left: 7px;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.window-label {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #ccc;
}

.window-label select {
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #444;
  background: #1e1e40;
  color: #fff;
  cursor: pointer;
}

.export-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 16px;
  background: #0057b8;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.export-btn:hover { background: #004494; }

/* ── Main layout ── */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Cards (section containers) ── */
.card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 16px;
}

/* ── Section labels ── */
.section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #888;
  margin-bottom: 12px;
}

.section-sublabel {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 11px;
  color: #aaa;
  margin-left: 4px;
}

/* ── Brand selector ── */
.brand-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.brand-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid #ccc;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  background: #f8f8f8;
  color: #444;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.brand-toggle.active {
  background: #12122a;
  color: #fff;
  border-color: #12122a;
}
.brand-toggle input { display: none; }

/* ── Brand block (within signals section) ── */
.brand-block {
  margin-bottom: 20px;
}
.brand-block:last-child { margin-bottom: 0; }

.brand-name {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #333;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid #ebebeb;
}

/* ── Signal columns ── */
.signal-columns {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ── Signal card ── */
.signal-card {
  flex: 1;
  min-width: 200px;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  overflow: hidden;
}

.signal-card-header {
  background: #f0f0f2;
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #555;
}

.signal-card-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Signal record ── */
.signal-record {
  padding: 10px;
  border-radius: 4px;
  border: 1px solid #e8e8e8;
  background: #fff;
}

.signal-record.status-partial {
  background: #fffcf0;
  border-color: #f5d87a;
}

.signal-record.status-unavailable {
  background: #f6f6f6;
  border-color: #ddd;
  color: #999;
}

/* ── Status badges ── */
.badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 2px 7px;
  border-radius: 3px;
  margin-bottom: 7px;
}
.badge-available   { background: #e6f4ea; color: #1e6e35; }
.badge-partial     { background: #fff3cd; color: #7d5200; }
.badge-unavailable { background: #ececec; color: #888; }

/* ── Record fields ── */
.record-headline {
  font-size: 13px;
  font-weight: 600;
  color: #111;
  margin-bottom: 4px;
}
.status-unavailable .record-headline { color: #aaa; }

.record-detail {
  font-size: 12px;
  color: #555;
  line-height: 1.5;
  margin-bottom: 4px;
}

.record-urgency {
  font-size: 11px;
  font-weight: 600;
  color: #b71c1c;
  margin-bottom: 4px;
}

.record-note {
  font-size: 11px;
  color: #777;
  font-style: italic;
  margin-bottom: 4px;
}

.record-source {
  font-size: 11px;
  color: #999;
  margin-top: 6px;
  margin-bottom: 2px;
}

.record-captured {
  font-size: 10px;
  color: #bbb;
}

.tag-manual {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  background: #e3f0fd;
  color: #1a5fa8;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
}

.unavailable-legend {
  font-size: 11px;
  color: #bbb;
  margin-top: 12px;
}

/* ── MIS context ── */
.mis-card {
  background: #f5f8fc;
  border-color: #ccd8e8;
}

.mis-list {
  list-style: disc;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mis-list li {
  font-size: 13px;
  color: #2c3e50;
  line-height: 1.55;
}

.mis-date {
  font-size: 11px;
  color: #8e9faf;
  margin-left: 4px;
}

/* ── Evidence toggle button ── */
.evidence-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  background: transparent;
  color: #aaa;
  border: 1px solid #444;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.02em;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.evidence-btn:hover         { color: #fff; border-color: #888; }
.evidence-btn.active        { background: #1a2e40; color: #7ec8e3; border-color: #7ec8e3; }

/* ── Record tag row (availability + provenance side by side) ── */
.record-tags {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 7px;
  flex-wrap: wrap;
}
.record-tags .badge { margin-bottom: 0; }

/* ── Entry provenance tags (SEED / MANUAL / FETCHED) ── */
.entry-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 2px 6px;
  border-radius: 3px;
}
.tag-seed     { background: #efefef; color: #888; border: 1px solid #ddd; }
.tag-manual   { background: #e3f0fd; color: #1a5fa8; border: 1px solid #b8d6f5; }
.tag-automated{ background: #edf7ee; color: #2e7d32; border: 1px solid #b4deb6; }

/* ── Source URL link (always visible) ── */
.record-source-url {
  font-size: 10px;
  margin-bottom: 2px;
  word-break: break-all;
}
.source-link {
  color: #0057b8;
  text-decoration: none;
}
.source-link:hover { text-decoration: underline; }
.no-url { color: #ccc; font-style: italic; }

/* ── Fetch log panel (hidden until Evidence mode) ── */
.fetch-log-panel { display: none; }
body.evidence-mode .fetch-log-panel { display: block; }

.fetch-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  margin-bottom: 8px;
}
.fetch-log-table th {
  background: #f0f0f2;
  text-align: left;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #555;
  border: 1px solid #e0e0e0;
}
.fetch-log-table td {
  padding: 5px 10px;
  border: 1px solid #e8e8e8;
  vertical-align: top;
}
.log-row-ok   { background: #fafffe; }
.log-row-fail { background: #fff8f8; }

.log-url {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #333;
}
.log-ts     { color: #666; white-space: nowrap; }
.log-status { text-align: center; font-weight: 600; }

.result-ok   { color: #2e7d32; font-weight: 700; }
.result-fail { color: #b71c1c; font-weight: 700; }

.log-empty {
  text-align: center;
  color: #bbb;
  font-style: italic;
  padding: 12px;
}

.fetch-log-count {
  font-size: 11px;
  color: #999;
  text-align: right;
}

/* ── Fetch log seed notice ── */
.fetch-log-seed-notice {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 12px;
  color: #5d4037;
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ── Utility ── */
.screen-only { }
.print-only  { display: none; }

/* ── Filter panel ── */
.filter-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
}

.filter-master {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #222;
  cursor: pointer;
}

.filter-items {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding-left: 2px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  white-space: nowrap;
}

.filter-item input:disabled { opacity: 0.35; }
.filter-item:has(input:disabled) { color: #bbb; cursor: default; }

.filter-group-view { border-left: 1px solid #e8e8e8; padding-left: 20px; }

/* ── Confidence view ── */
.confidence-group {
  margin-bottom: 22px;
}
.confidence-group:last-child { margin-bottom: 0; }

.confidence-group-header {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  padding: 4px 10px;
  border-radius: 3px;
  margin-bottom: 10px;
}
.confidence-header-available { background: #e6f4ea; color: #1e6e35; }
.confidence-header-partial    { background: #fff3cd; color: #7d5200; }
.confidence-header-fetched    { background: #e8f0fb; color: #1a5098; }
.confidence-header-seed       { background: #ececec; color: #666; }

.confidence-records {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.confidence-record {
  flex: 1 1 260px;
  max-width: 420px;
}

.confidence-record-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.confidence-brand-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #333;
}

.confidence-signal-label {
  font-size: 10px;
  color: #999;
}

.confidence-empty {
  font-size: 12px;
  color: #bbb;
  font-style: italic;
  padding-left: 2px;
}


/* ════════════════════════════════════════════
   PRINT
   ════════════════════════════════════════════ */
@media print {

  @page {
    size: A4;
    margin: 1.8cm 2cm;
  }

  /* Visibility */
  .screen-only { display: none !important; }
  .print-only  { display: block !important; }

  body {
    background: #fff;
    font-size: 10.5pt;
    color: #000;
  }

  main {
    max-width: 100%;
    padding: 0;
    gap: 14pt;
  }

  /* Print document header */
  .print-header {
    margin-bottom: 16pt;
    padding-bottom: 8pt;
    border-bottom: 2pt solid #12122a;
  }

  .print-title {
    font-size: 18pt;
    font-weight: 700;
    color: #12122a;
    margin-bottom: 4pt;
  }

  .print-meta {
    font-size: 8.5pt;
    color: #555;
  }
  .print-meta span { margin-right: 14pt; }

  /* Cards */
  .card {
    border: 0.5pt solid #ccc;
    background: #fff;
    padding: 10pt 12pt;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .section-label { color: #555; margin-bottom: 8pt; }
  .section-sublabel { color: #888; }

  .brand-name {
    font-size: 9pt;
    border-bottom-color: #ddd;
    margin-bottom: 8pt;
    padding-bottom: 4pt;
  }

  .signal-card {
    border: 0.5pt solid #ccc;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .signal-card-header {
    background: #ebebeb;
    padding: 5pt 9pt;
  }

  .signal-card-body { padding: 8pt; gap: 8pt; }

  .signal-record {
    padding: 7pt;
    border: 0.5pt solid #ddd;
    page-break-inside: avoid;
    break-inside: avoid;
  }

  .signal-record.status-unavailable { background: #f4f4f4; }
  .signal-record.status-partial     { background: #fffdf0; border-color: #e8d080; }

  /* Ensure badge colours survive print */
  .badge-available   { background: #e6f4ea; color: #1e6e35; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge-partial     { background: #fff3cd; color: #7d5200; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge-unavailable { background: #ececec; color: #888;    -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .record-headline { font-size: 10pt; }
  .record-detail   { font-size: 9pt; }
  .record-urgency  { font-size: 9pt; }
  .record-note     { font-size: 8.5pt; }
  .record-source   { font-size: 8.5pt; }
  .record-captured { font-size: 8pt; }

  .tag-manual {
    background: #e3f0fd; color: #1a5fa8;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }

  /* MIS */
  .mis-card {
    background: #f5f8fc;
    border-color: #ccd8e8;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .mis-list li { font-size: 10pt; }
  .mis-date    { font-size: 8.5pt; }

  /* Fetch log is screen-only — never appears in the PDF */
  .fetch-log-panel { display: none !important; }

  /* Data mode badge in print header */
  .print-data-mode {
    font-weight: 700;
    color: #7a5c00;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Entry provenance tags survive print */
  .entry-tag { font-size: 8pt; }
  .tag-seed      { background: #efefef; color: #888; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tag-manual    { background: #e3f0fd; color: #1a5fa8; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tag-automated { background: #edf7ee; color: #2e7d32; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Source URL: show as plain text in PDF (links are still clickable in PDF readers) */
  .record-source-url { font-size: 8pt; word-break: break-all; }
  .source-link { color: #0057b8; text-decoration: none; }
  .no-url { display: none; }  /* suppress "No URL recorded" in print — silence is cleaner */
}

/* ── View slider (National | Retailer | Map) ── */
.view-slider {
  display: inline-flex;
  background: #eef2f7;
  border: 1px solid #d5deea;
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}
.view-slider-option {
  position: relative;
  font-size: 12px;
  font-weight: 600;
  color: #55647a;
  padding: 5px 14px;
  border-radius: 5px;
  cursor: pointer;
  user-select: none;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.view-slider-option input { position: absolute; opacity: 0; pointer-events: none; }
.view-slider-option:hover { color: #1a3350; }
.view-slider-option.is-active {
  background: #0057b8;
  color: #fff;
  box-shadow: 0 1px 2px rgba(0,40,90,.25);
}

/* ── Competitor map ── */
.map-caption {
  font-size: 12px;
  color: #55647a;
  margin: 0 0 10px;
}
#competitor-map {
  height: 560px;
  width: 100%;
  border: 1px solid #d5deea;
  border-radius: 8px;
  overflow: hidden;
  z-index: 0;
}

/* Map popups */
.map-popup { font-size: 12px; line-height: 1.45; }
.map-popup-head {
  font-weight: 700;
  color: #12233b;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}
.map-popup-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,.15);
}
.map-popup-sub { color: #6a7788; font-size: 11px; margin-bottom: 7px; }
.map-offer-link { display: block; text-decoration: none; }
.map-offer {
  padding: 5px 7px;
  margin-bottom: 5px;
  background: #f4f7fb;
  border: 1px solid #e2e9f2;
  border-radius: 5px;
  color: #23364e;
}
.map-offer-link:hover .map-offer { border-color: #0057b8; background: #eef4fc; }
.map-offer-apr {
  font-weight: 700;
  color: #0057b8;
  margin-right: 4px;
}

/* Map is interactive — omit from PDF export */
@media print {
  #competitor-map, .map-caption { display: none !important; }
}

/* ── Results grid (2–3 brand cards per row, scannable above the fold) ── */
.brand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  align-items: start;
}
.brand-grid .brand-block { margin-bottom: 0; }

/* ── Export dropdown (PDF / CSV) ── */
.export-menu { position: relative; display: inline-block; }
.export-menu-items {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid #cdd7e4;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,30,70,.14);
  overflow: hidden;
  z-index: 10;
  min-width: 140px;
}
.export-menu.open .export-menu-items { display: block; }
.export-menu-items button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  background: none;
  border: none;
  font-size: 13px;
  color: #1a3350;
  cursor: pointer;
}
.export-menu-items button:hover { background: #eef4fc; }

@media print {
  /* Keep the grid compact in the PDF too */
  .brand-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .export-menu { display: none !important; }
}
