:root {
  --navy: #0F1F3D; --teal: #0D9488; --teal-dark: #0B7A70; --slate: #475569; --muted: #64748B;
  --card: #FFFFFF; --bg: #F1F5F9; --rule: #E2E8F0; --red: #DC2626; --green: #16A34A; --amber-bg: #FEF3C7; --amber: #92400E;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* sections use display:grid, which would otherwise override `hidden` */
body { margin: 0; background: var(--bg); color: var(--navy); font: 15px/1.5 Arial, "Helvetica Neue", Helvetica, sans-serif; }
a { color: var(--teal-dark); }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

.top { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--rule); border-top: 4px solid #8BC53F; position: sticky; top: 0; z-index: 2; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand span { color: var(--teal); }
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav a { text-decoration: none; color: var(--slate); padding: 6px 12px; border-radius: 6px; font-weight: 600; }
nav a.active, nav a:hover { background: var(--bg); color: var(--navy); }

main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }
section { display: grid; gap: 20px; }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px 24px; min-width: 0; }
h2 { margin: 0 0 4px; font-size: 18px; }
.muted { color: var(--muted); }
small { display: block; margin-top: 4px; font-size: 12px; }
.row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

form { margin-top: 12px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; }
.span2 { grid-column: span 2; }
label { display: block; font-weight: 600; font-size: 14px; color: var(--slate); }
input, select, textarea { display: block; width: 100%; margin-top: 6px; padding: 9px 11px; font: inherit; color: var(--navy); background: #fff; border: 1px solid #CBD5E1; border-radius: 8px; }
input[type=color] { height: 42px; padding: 4px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; margin: 0; }
input[type=file] { padding: 7px; }
input[type=radio], input[type=checkbox] { display: inline-block; width: 16px; height: 16px; margin: 3px 0 0; padding: 0; flex: none; accent-color: var(--teal); cursor: pointer; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
a:focus-visible, summary:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
[tabindex="-1"]:focus { outline: none; }
.card, fieldset, input, select, textarea { scroll-margin-top: 84px; }
details { margin-top: 16px; }
summary { cursor: pointer; font-weight: 600; color: var(--slate); margin-bottom: 12px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

button { font: inherit; font-weight: 600; border-radius: 8px; padding: 9px 16px; cursor: pointer; border: 1px solid transparent; }
button.primary { background: var(--teal); color: #fff; }
button.primary:hover { background: var(--teal-dark); }
button.ghost { background: #fff; color: var(--navy); border-color: #CBD5E1; }
button.ghost:hover { background: var(--bg); }
button.link { background: none; border: none; color: var(--teal-dark); padding: 4px 6px; }
button.danger { color: var(--red); }
button:disabled { opacity: .6; cursor: wait; }

.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--slate); font-weight: 600; border-bottom: 2px solid var(--rule); padding: 8px 10px; white-space: nowrap; }
td { border-bottom: 1px solid var(--rule); padding: 8px 10px; vertical-align: middle; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions-cell { white-space: nowrap; text-align: right; }

#preview { width: 100%; aspect-ratio: 16 / 9.6; border: 1px solid var(--rule); border-radius: 8px; margin-top: 14px; background: var(--bg); }
#propFilter { max-width: 280px; margin-top: 0; }

.list { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 10px; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 8px; flex-wrap: wrap; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 8px; }
.badge.ok { background: #DCFCE7; color: #166534; }
.badge.bad { background: #FEE2E2; color: #991B1B; }

.warn { background: var(--amber-bg); color: var(--amber); padding: 10px 14px; border-radius: 8px; margin: 12px 0 0; }
.setup { background: var(--bg); border-radius: 8px; padding: 14px 16px; margin-top: 14px; }
.setup ol { margin: 8px 0 0; padding-left: 20px; }
.copy { display: flex; gap: 8px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.copy code { word-break: break-all; }

#flash:empty { display: none; }
#flash { margin-bottom: 16px; }
.flash { padding: 12px 16px; border-radius: 8px; font-weight: 600; }
.flash.ok { background: #DCFCE7; color: #166534; }
.flash.err { background: #FEE2E2; color: #991B1B; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.grow { flex: 1 1 260px; min-width: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* New report form */
fieldset { border: 1px solid var(--rule); border-radius: 8px; margin: 16px 0 0; padding: 10px 16px 16px; min-width: 0; }
fieldset.invalid { border-color: var(--red); }
legend { font-weight: 700; color: var(--navy); padding: 0 6px; }
legend .muted { font-weight: 400; font-size: 13px; }
.basics { margin-top: 16px; }
.field { min-width: 0; font-weight: 600; font-size: 14px; color: var(--slate); }
.field > label .muted { font-weight: 400; }
.field-error { color: var(--red); font-size: 13px; font-weight: 600; margin: 6px 0 0; overflow-wrap: anywhere; }
[aria-invalid="true"] { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.note { margin: 0 0 12px; font-size: 14px; }
#rankCsvClear { margin-top: 4px; padding-left: 0; font-size: 13px; }

.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-top: 4px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid #CBD5E1; border-radius: 8px; background: #fff; cursor: pointer; font-weight: 400; }
.choice:hover { border-color: var(--teal); }
.choice.selected { border-color: var(--teal); background: #F0FDFA; box-shadow: inset 0 0 0 1px var(--teal); }
.choice-body { min-width: 0; }
.choice-title { display: block; font-weight: 700; color: var(--navy); }

.src-groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 20px; margin-top: 4px; }
.src-group { min-width: 0; }
.src-head { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 4px 0 6px; }
.sec-item { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 10px; padding: 8px 10px; border: 1px solid transparent; border-radius: 8px; }
.sec-item + .sec-item { margin-top: 4px; }
.sec-item.selected { background: #F0FDFA; border-color: #99F6E4; }
.sec-item label { color: var(--navy); cursor: pointer; }
.sec-item small { grid-column: 2; margin-top: 2px; }
.slide-tag { font-size: 12px; font-weight: 400; color: var(--muted); white-space: nowrap; }

.form-error { background: #FEE2E2; color: #991B1B; padding: 10px 14px; border-radius: 8px; margin: 16px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.form-error a { color: inherit; }
.actions .status { margin: 0 auto 0 0; align-self: center; font-size: 14px; }
.actions .status:empty { display: none; }

/* Result card */
.meta { display: flex; flex-wrap: wrap; align-items: center; row-gap: 4px; margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.meta > * + *::before { content: "·"; margin: 0 8px; color: #94A3B8; }
.warn ul { margin: 4px 0 0; padding-left: 20px; }
.warn li + li { margin-top: 2px; }
.warn { overflow-wrap: anywhere; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.seg button, .chip { background: #fff; color: var(--slate); border: 1px solid #CBD5E1; font-size: 14px; padding: 6px 12px; }
.seg button[aria-pressed="false"]:hover, .chip[aria-pressed="false"]:hover { background: var(--bg); color: var(--navy); }
.seg button[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.seg button[aria-pressed="true"] .slide-tag { color: #CBD5E1; }
.preview-status { margin: 10px 0 0; font-size: 13px; }
.preview-status:empty { display: none; }
.preview-status.error { color: var(--red); font-weight: 600; }
#preview { min-height: 240px; }

/* Saved reports */
.chip-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.chip-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-right: 4px; }
.chip { border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: #fff; }
.reports-status { margin: 12px 0 0; font-size: 13px; }
.reports-status:empty { display: none; }
#reportsEmpty { margin: 12px 0 0; }
#reportsTable td { overflow-wrap: break-word; }
.badge.type { margin-left: 0; white-space: nowrap; }
.t-full { background: #CCFBF1; color: #115E59; }
.t-ga4 { background: #DBEAFE; color: #1E40AF; }
.t-rank { background: #EDE9FE; color: #5B21B6; }
.t-birdeye { background: var(--amber-bg); color: var(--amber); }
.t-custom { background: #E2E8F0; color: #334155; }

dialog { border: none; border-radius: var(--radius); padding: 24px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(15, 31, 61, .25); }
dialog::backdrop { background: rgba(15, 31, 61, .35); }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .top .brand { flex: 1; }
  .top nav { order: 3; flex-basis: 100%; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .card { padding: 16px; }
  #propFilter { max-width: none; }
  .card, fieldset, input, select, textarea { scroll-margin-top: 120px; }
  fieldset { padding: 8px 12px 14px; }
  .choices, .src-groups { grid-template-columns: minmax(0, 1fr); }
  .chip-label { flex-basis: 100%; }
  .actions .status { flex-basis: 100%; }
  .btn-row { width: 100%; }

  /* Saved reports: one block per report instead of a wide table */
  #reportsTable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #reportsTable, #reportsTable tbody, #reportsTable tr, #reportsTable td { display: block; width: 100%; }
  #reportsTable tr { border: 1px solid var(--rule); border-radius: 8px; padding: 6px 12px; margin-bottom: 10px; }
  #reportsTable td { border: 0; padding: 4px 0; display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 8px; white-space: normal; overflow-wrap: anywhere; }
  #reportsTable td::before { content: attr(data-label); font-weight: 600; color: var(--slate); }
  #reportsTable td.actions-cell { display: flex; flex-wrap: wrap; gap: 4px 12px; text-align: left; border-top: 1px solid var(--rule); margin-top: 4px; padding-top: 6px; }
  #reportsTable td.actions-cell::before { content: none; }
  #reportsTable td.actions-cell button { padding-left: 0; }
}

/* automatic client lookup */
.detected { margin: 4px 0 0; padding: 8px 12px; background: var(--bg); border-radius: 8px; font-size: 14px; overflow-wrap: anywhere; }
.detected-box { padding: 10px 12px; background: var(--bg); border-radius: 8px; font-size: 14px; margin-bottom: 10px; overflow-wrap: anywhere; }
.detected-box p { margin: 0 0 6px; }
.detected-box p:last-child { margin-bottom: 0; }
.pick-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; }
.pick-list label { font-weight: 500; color: var(--navy); }
.warn-text { color: var(--amber); background: var(--amber-bg); padding: 8px 10px; border-radius: 6px; }
