:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #dfe3e8;
  --line-soft: #edf0f3;
  --blue: #1877f2;
  --blue-hover: #166fe5;
  --blue-soft: #e7f3ff;
  --green: #13795b;
  --green-soft: #e8f5ef;
  --red: #e41e3f;
  --shadow: 0 1px 2px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body:has(dialog[open]) { overflow: hidden; }

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

main {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 64px;
}

h1, h2, h3, p { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 21px; line-height: 1.3; }
h3 { font-size: 15px; line-height: 1.35; }
p { color: var(--muted); }

.page-head {
  display: grid;
  gap: 14px;
  margin-bottom: 22px;
}

.page-head > div > p { margin-top: 4px; }

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 13px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.nav-btn:hover { background: var(--line-soft); color: var(--ink); }
.nav-btn.active { background: var(--blue-soft); color: var(--blue); }

.section-heading,
.results-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading p,
.results-head p { margin-top: 3px; font-size: 14px; }

.data-status {
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
}

.data-status.is-error,
.idea-status.is-error { color: var(--red); }

.page-list {
  display: grid;
  gap: 12px;
}

.page-card {
  width: 100%;
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr) 36px;
  gap: 18px;
  align-items: center;
  min-height: 190px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.page-card:hover {
  border-color: #b6c8de;
  box-shadow: 0 4px 12px rgba(16, 24, 40, .10);
  transform: translateY(-1px);
}

.page-card > img {
  width: 138px;
  height: 138px;
  display: block;
  margin-left: 16px;
  border: 1px solid var(--line);
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
}

.page-card-body {
  min-width: 0;
  display: grid;
  gap: 5px;
  padding: 16px 0;
}

.page-card-kicker {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.page-card-body > strong { font-size: 23px; }
.page-card-arrow { color: var(--blue); font-size: 24px; font-weight: 700; }

.page-overview {
  display: grid;
  gap: 4px;
  margin-top: 4px;
  color: #475467;
  font-size: 14px;
}

.page-overview > span { overflow-wrap: anywhere; }
.page-overview b { color: var(--ink); }
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  margin-bottom: 12px;
  padding: 6px 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  cursor: pointer;
}

.back-button:hover { background: var(--blue-soft); }
.back-button span { font-size: 20px; line-height: 1; }

.competitor-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.competitor-identity {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 13px;
}

.competitor-identity > img {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  object-fit: cover;
  object-position: top center;
}

.competitor-identity h2 { margin-top: 1px; font-size: 25px; }
.competitor-identity p { margin-top: 2px; font-size: 14px; }

.header-actions { align-self: start; }

.page-metrics {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line-soft);
  padding-top: 13px;
}

.page-metrics > span {
  display: grid;
  gap: 1px;
  padding: 0 14px;
  border-right: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
}

.page-metrics > span:first-child { padding-left: 0; }
.page-metrics > span:last-child { border-right: 0; }
.page-metrics strong { color: var(--ink); font-size: 20px; }

.audit-strip {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #c9d8ed;
  border-left: 3px solid var(--blue);
  background: #f4f8fd;
  color: #344054;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.45;
}

.audit-strip.is-incomplete {
  border-color: #f0c4c5;
  border-left-color: var(--red);
  background: #fff7f7;
  color: #7a271a;
}

.detail-toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin: 14px 0 20px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f7f8fa;
  color: var(--ink);
  padding: 9px 11px;
}

input { min-height: 40px; }
textarea { min-height: 86px; resize: vertical; }

input:focus, textarea:focus {
  outline: 0;
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 3px var(--blue-soft);
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  padding: 3px;
  border-radius: 7px;
  background: #eef0f3;
}

.segment {
  min-height: 36px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.segment.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }

.research-list { display: grid; gap: 14px; }

.research-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.research-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.research-heading { display: flex; min-width: 0; gap: 10px; align-items: flex-start; }
.research-heading h2 { font-size: 22px; overflow-wrap: anywhere; }
.research-meta { margin-top: 3px; font-size: 13px; font-weight: 600; }
.ad-library-meta { margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 700; overflow-wrap: anywhere; }

.rank-pill {
  min-width: 38px;
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  flex: 0 0 auto;
  padding: 8px 14px;
  border: 0;
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.action:hover { background: var(--blue-hover); }
.action:disabled { cursor: wait; opacity: .65; }

.source-unavailable {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8f9fa;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.source-notice {
  margin: -3px 0 0;
  padding: 9px 11px;
  border-left: 3px solid #98a2b3;
  background: #f8f9fa;
  color: #475467;
  font-size: 13px;
  line-height: 1.45;
}

.facebook-metrics {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 35px;
  padding: 7px 0;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 13px;
}

.reaction-count { display: inline-flex; align-items: center; gap: 6px; }
.reaction-bubbles { display: inline-flex; align-items: center; }
.reaction-bubbles i {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  font-style: normal;
}

.reaction-bubbles i + i { margin-left: -5px; background: var(--red); }
.metric-spacer { flex: 1; }
.unavailable-metrics { color: var(--muted); }

.performance-callout {
  display: grid;
  gap: 6px;
  padding: 11px 13px;
  border-left: 3px solid var(--blue);
  background: #f7faff;
}

.performance-callout p { color: #344054; font-size: 14px; }

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 22px;
  row-gap: 18px;
}

.analysis-block {
  display: grid;
  align-content: start;
  gap: 7px;
  min-width: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.analysis-block h3 { font-size: 16px; }
.analysis-block p { color: #344054; font-size: 14px; white-space: pre-wrap; }
.analysis-block .muted-text { color: var(--muted); }
.application-block { grid-column: 1 / -1; }

.application-angles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}

.application-angles > div { display: grid; align-content: start; gap: 6px; padding-right: 18px; }
.application-angles > div + div { padding: 0 0 0 18px; border-left: 1px solid var(--line-soft); }
.application-angles strong { color: var(--green); font-size: 13px; text-transform: uppercase; }

.original-copy {
  border-top: 1px solid var(--line-soft);
  padding-top: 11px;
}

.original-copy summary {
  color: var(--blue);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.original-copy > div { display: grid; gap: 6px; margin-top: 9px; }
.original-copy p { color: #344054; font-size: 14px; }

.image-section {
  display: grid;
  gap: 9px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.image-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.image-head span { color: var(--muted); font-size: 12px; font-weight: 700; }

.image-grid {
  display: grid;
  grid-template-columns: minmax(0, 760px);
  gap: 10px;
}

.image-tile {
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  cursor: zoom-in;
}

.image-tile img {
  width: 100%;
  aspect-ratio: 64 / 45;
  display: block;
  object-fit: contain;
  background: var(--line-soft);
  transition: transform .18s;
}

.image-tile:hover img { transform: scale(1.02); }

.idea-form {
  display: grid;
  gap: 7px;
  padding-top: 13px;
  border-top: 1px solid var(--line-soft);
}

.idea-form > label { color: var(--ink); font-size: 15px; font-weight: 800; }
.idea-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: end; }
.idea-status { min-height: 18px; font-size: 12px; font-weight: 700; }

.empty {
  padding: 16px;
  border: 1px dashed #c8ced6;
  border-radius: 8px;
  background: #f8f9fa;
  color: var(--muted);
  font-weight: 700;
}

.image-lightbox {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(0, 0, 0, .88);
}

.image-lightbox::backdrop { background: rgba(0, 0, 0, .88); }

.lightbox-shell {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 10px;
  padding: 48px 24px 20px;
}

.lightbox-shell img {
  max-width: min(1180px, 100%);
  max-height: calc(100vh - 100px);
  display: block;
  object-fit: contain;
}

.lightbox-shell p { color: #fff; font-size: 14px; text-align: center; }

.lightbox-close {
  position: fixed;
  top: 14px;
  right: 16px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

@media (max-width: 760px) {
  main { width: min(100% - 20px, 1220px); padding-top: 12px; }
  h1 { font-size: 24px; }
  .nav-btn { flex: 1 1 auto; padding: 7px 9px; font-size: 13px; }
  .section-heading, .results-head { align-items: flex-start; }
  .page-card { grid-template-columns: 84px minmax(0, 1fr) 20px; gap: 8px; min-height: 190px; align-items: start; }
  .page-card > img { width: 72px; height: 72px; margin: 14px 0 0 10px; }
  .page-card-body { padding: 10px 0; }
  .page-card-body > strong { font-size: 19px; }
  .page-overview { font-size: 12px; }
  .page-card-arrow { padding-top: 14px; }
  .competitor-header { grid-template-columns: 1fr; }
  .header-actions { width: 100%; }
  .header-actions .action { width: 100%; }
  .page-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 12px; }
  .page-metrics > span:nth-child(2) { border-right: 0; }
  .page-metrics > span:nth-child(3) { padding-left: 0; }
  .audit-strip { font-size: 12px; }
  .detail-toolbar, .analysis-grid, .application-angles, .idea-entry { grid-template-columns: 1fr; }
  .application-block { grid-column: auto; }
  .application-angles { gap: 14px; }
  .application-angles > div { padding-right: 0; }
  .application-angles > div + div { padding: 12px 0 0; border-top: 1px solid var(--line-soft); border-left: 0; }
  .research-top { display: grid; }
  .research-top > .action { width: 100%; }
  .source-unavailable { width: 100%; }
  .research-heading h2 { font-size: 19px; }
  .facebook-metrics { flex-wrap: wrap; gap: 8px 11px; }
  .metric-spacer { display: none; }
  .image-grid { grid-template-columns: 1fr; }
  .idea-entry .action { width: 100%; }
  .lightbox-shell { padding: 52px 10px 16px; }
}
