:root {
  color-scheme: light dark;
  --bg: #f3f3f6;
  --surface: #fcfcfd;
  --surface-2: #e9e9ed;
  --text: #131316;
  --muted: #65656b;
  --border: rgba(0, 0, 0, 0.1);
  --accent: #131316;
  --on-accent: #fff;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --shadow: 0 18px 50px rgba(19, 19, 22, 0.1);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --surface: #202024;
    --surface-2: #2d2d32;
    --text: #f5f5f6;
    --muted: #aaaAAF;
    --border: rgba(255, 255, 255, 0.14);
    --accent: #f7f7f8;
    --on-accent: #131316;
    --danger: #ffb4ab;
    --danger-soft: #4f2523;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.56; }

.topbar {
  min-height: 86px;
  padding: 18px max(24px, calc((100vw - 1440px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(20px);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 2.5vw, 1.75rem); letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: 1.25rem; letter-spacing: -0.025em; }
h3 { margin-bottom: 14px; font-size: 1rem; }
.eyebrow { margin-bottom: 4px; color: var(--muted); font-size: 0.72rem; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.viewer { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.88rem; }
.viewer-identity { display: grid; gap: 4px; text-align: right; }
#session-status { font-size: .75rem; }
.session-screen { min-height: 100vh; padding: 24px; display: grid; place-items: center; margin: 0; }
.session-screen[hidden] { display: none; }
.session-card { width: min(100%, 440px); padding: 40px 32px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); }
.session-card img { border-radius: 16px; margin-bottom: 24px; }
.session-card h1 { margin-bottom: 16px; }
.session-card p { line-height: 1.7; }
.session-card a { display: block; text-decoration: none; margin-top: 24px; }
.session-caption { font-size: .8rem; margin: 24px 0 0; }
.session-ended > :not(#session-screen) { display: none !important; }

main { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding: 34px 0 64px; }
section + section { margin-top: 34px; }
.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 16px; }

.summary-grid { display: grid; grid-template-columns: repeat(6, minmax(140px, 1fr)); gap: 12px; }
.summary-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  transition: transform 140ms ease, border-color 140ms ease;
}
.summary-card:hover { transform: translateY(-2px); border-color: var(--muted); }
.summary-card.active { outline: 2px solid var(--text); outline-offset: 2px; }
.summary-card strong { display: block; margin-top: 10px; font-size: 1.7rem; font-variant-numeric: tabular-nums; }

.reports-section { background: var(--surface); border: 1px solid var(--border); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); }
.count-pill, .badge { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; white-space: nowrap; }
.count-pill { min-width: 48px; padding: 7px 11px; background: var(--surface-2); font-size: 0.82rem; font-weight: 700; }

.filters { display: grid; grid-template-columns: 160px 190px 150px minmax(240px, 1fr) auto auto; align-items: end; gap: 12px; margin-bottom: 20px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 0.78rem; font-weight: 700; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 12%, transparent); }
textarea { resize: vertical; line-height: 1.55; }

.primary-button, .secondary-button, .icon-button {
  border: 0;
  border-radius: 12px;
  font-weight: 750;
}
.primary-button { padding: 11px 16px; background: var(--accent); color: var(--on-accent); }
.secondary-button { padding: 10px 14px; background: var(--surface-2); color: var(--text); }
.icon-button { width: 42px; height: 42px; background: var(--surface-2); color: var(--text); font-size: 1.5rem; }
.filter-button { min-height: 42px; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; min-width: 1000px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--bg); font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; position: sticky; top: 0; }
td { font-size: 0.86rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 48%, transparent); }
.cell-primary { display: block; font-weight: 720; }
.cell-secondary { display: block; margin-top: 3px; color: var(--muted); font-size: 0.76rem; }
td:nth-child(5) { min-width: 160px; max-width: 360px; white-space: normal; overflow-wrap: anywhere; }
.detail-button { border: 0; border-radius: 10px; padding: 8px 12px; background: var(--surface-2); color: var(--text); font-weight: 700; }

.badge { padding: 5px 9px; font-size: 0.7rem; font-weight: 800; letter-spacing: 0.02em; background: var(--surface-2); }
.status-new { color: #175cd3; background: #dbeafe; }
.status-triaged { color: #6941c6; background: #ede9fe; }
.status-in-progress { color: #b54708; background: #fef0c7; }
.status-fixed { color: #067647; background: #d1fadf; }
.status-duplicate { color: #475467; background: #eaecf0; }
.status-rejected { color: var(--danger); background: var(--danger-soft); }

.state-panel { padding: 34px 18px; border: 1px dashed var(--border); border-radius: 16px; color: var(--muted); text-align: center; }
.error-panel { color: var(--danger); background: var(--danger-soft); border-style: solid; }

dialog { width: min(1000px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 24px; background: var(--surface); color: var(--text); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(0, 0, 0, 0.46); backdrop-filter: blur(4px); }
.dialog-shell { padding: 24px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { font-size: 1.4rem; }
.dialog-header p:last-child { margin: 8px 0 0; }
.detail-section { margin-top: 24px; }
.metadata-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 0; }
.metadata-entry { padding: 12px; border-radius: 12px; background: var(--bg); min-width: 0; }
.metadata-entry dt { color: var(--muted); font-size: 0.7rem; font-weight: 700; }
.metadata-entry dd { margin: 5px 0 0; font-size: 0.86rem; overflow-wrap: anywhere; }
.items-stack { display: grid; gap: 12px; }
details { border: 1px solid var(--border); border-radius: 14px; background: var(--bg); overflow: hidden; }
summary { padding: 13px 15px; cursor: pointer; font-weight: 720; }
pre { margin: 0; padding: 16px; border-top: 1px solid var(--border); overflow: auto; max-height: 420px; color: var(--text); font: 0.76rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.review-section { padding: 18px; border-radius: 16px; background: var(--bg); }
#review-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
#review-form label:last-of-type { grid-column: 1 / -1; }
.review-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.review-actions p { margin: 0; font-size: 0.76rem; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; max-width: min(520px, calc(100vw - 32px)); padding: 13px 17px; border-radius: 14px; background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow); font-weight: 700; }
.refresh-status { text-align: right; font-size: .8rem; font-variant-numeric: tabular-nums; }
.refresh-status p { margin: 0 0 5px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.image-preview { margin: 0; }
.image-preview img { display: block; width: 100%; height: 220px; object-fit: contain; border-radius: 12px; background: #fff; }
.image-preview figcaption { margin-top: 12px; font-size: .75rem; }
.audio-preview audio { width: 100%; margin: 6px 0 14px; }
.media-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.resource-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; }
.resource-row .mono { min-width: 0; font-size: .8rem; }
.resource-row button { flex-shrink: 0; }
#resources-note, #document-key { margin-top: 18px; line-height: 1.65; }
#limits-day { max-width: 220px; margin-bottom: 14px; }
#resources-more { margin-top: 16px; }
#document-editor { line-height: 1.6; tab-size: 2; }
#document-json, #context-json { margin-top: 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--bg); tab-size: 2; white-space: pre; }
.json-key { color: #175cd3; }
.json-string { color: #067647; }
.json-number { color: #b54708; }
.json-literal { color: #6941c6; }
@media (prefers-color-scheme: dark) {
  .json-key { color: #8cb8ff; } .json-string { color: #75e0a7; }
  .json-number { color: #fec84b; } .json-literal { color: #d6bbfb; }
}
.view-switch { display: flex; gap: 6px; padding: 5px; background: var(--bg); border-radius: 14px; margin-bottom: 14px; }
.view-switch button { flex: 1; padding: 12px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 700; }
.view-switch button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.content-card { border: 1px solid var(--border); border-radius: 16px; padding: 16px; min-width: 0; }
.content-card h4 { margin: 0 0 12px; overflow-wrap: anywhere; }
.parsed-fields { margin: 0; display: grid; gap: 8px; }
.parsed-field { display: grid; grid-template-columns: minmax(110px, 24%) minmax(0, 1fr); gap: 12px; padding: 10px; background: var(--bg); border-radius: 8px; }
.parsed-field dt { font-size: .76rem; color: var(--muted); overflow-wrap: anywhere; }
.parsed-field dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.parsed-group { margin: 8px 0; }
.parsed-group > .parsed-fields, .parsed-group > .parsed-list { padding: 12px; }
.parsed-list { display: grid; gap: 10px; }
.dropdown-label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.custom-select { position: relative; min-width: 0; color: var(--text); }
.select-trigger { display: flex; justify-content: space-between; gap: 12px; width: 100%; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); color: inherit; padding: 10px 12px; text-align: left; }
.select-trigger::after { content: "⌄"; }
.select-options { position: absolute; top: calc(100% + 6px); left: 0; min-width: 100%; max-height: 280px; overflow-y: auto; z-index: 30; padding: 5px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.select-option { display: block; width: 100%; border: 0; border-radius: 8px; background: transparent; color: var(--text); padding: 10px 12px; text-align: left; white-space: nowrap; }
.select-option[aria-selected="true"], .select-option:hover, .select-option:focus { background: var(--surface-2); }
button:focus-visible { outline: 2px solid var(--muted); outline-offset: 3px; }
.message-dialog { width: min(440px, calc(100vw - 32px)); }
.warning-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); font-size: 24px; font-weight: 800; margin-bottom: 18px; }
#message-text { margin: 16px 0 24px; line-height: 1.7; white-space: pre-wrap; }
.message-actions { display: flex; justify-content: flex-end; gap: 10px; }
#json-dialog pre { max-height: 65vh; }
.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; }
[hidden] { display: none !important; }

@media (prefers-color-scheme: dark) {
  .status-new { color: #b2ccff; background: #102a56; }
  .status-triaged { color: #d6bbfb; background: #32235c; }
  .status-in-progress { color: #fec84b; background: #4e3206; }
  .status-fixed { color: #75e0a7; background: #073d2a; }
  .status-duplicate { color: #d0d5dd; background: #344054; }
}

@media (max-width: 1120px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .filters { grid-template-columns: repeat(3, 1fr); }
  .search-field { grid-column: span 3; }
}

@media (max-width: 700px) {
  .topbar { padding: 16px; align-items: flex-start; }
  .viewer { align-items: flex-end; flex-direction: column; }
  #viewer-email { max-width: 44vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { width: calc(100% - 24px); padding-top: 22px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .reports-section { padding: 16px; border-radius: 20px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .metadata-grid { grid-template-columns: 1fr 1fr; }
  #review-form { grid-template-columns: 1fr; }
  #review-form label, #review-form label:last-of-type, .review-actions { grid-column: 1; }
  .review-actions { align-items: stretch; flex-direction: column; }
  .dialog-shell { padding: 18px; }
}

/* Each panel owns its background; the outer layout and unused space are transparent. */
#detail-dialog { width: min(1440px, calc(100vw - 32px)); background: transparent; box-shadow: none; border-radius: 0; }
#detail-dialog > .detail-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; padding: 0; }
.detail-panel { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); }
#report-panel { padding: 24px; }
#detail-dialog .dialog-header > div { min-width: 0; }
#detail-dialog .icon-button { flex-shrink: 0; }
#report-information { min-width: 0; }
#report-information:focus-visible { outline: 2px solid var(--muted); outline-offset: -2px; border-radius: 12px; }
#detail-dialog .review-section { margin: 0; padding: 18px; align-self: start; background: var(--surface); }
#related-section { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.related-report { display: grid; gap: 6px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); text-decoration: none; overflow-wrap: anywhere; font-size: .8rem; }
.related-report:hover, .related-report:focus-visible { background: var(--surface-2); border-color: var(--muted); }
.related-report .mono { font-size: .7rem; }
#related-more { margin-top: 12px; }
.status-picker { border: 0; margin: 0; padding: 0; min-width: 0; grid-column: 1 / -1; }
.status-picker legend { padding: 0; margin-bottom: 9px; color: var(--muted); font-size: .78rem; font-weight: 700; }
.status-buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.status-choice { position: relative; cursor: pointer; display: block; }
#review-form .status-buttons > .status-choice { grid-column: auto; }
.status-choice input { position: absolute; width: 1px; height: 1px; padding: 0; margin: 0; opacity: 0; }
.status-choice > span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 9px 7px; border: 1px solid var(--border); border-radius: 11px; color: var(--muted); background: var(--bg); }
.status-choice input:checked + span { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 800; }
.status-check { visibility: hidden; }
.status-choice input:checked + span .status-check { visibility: visible; }
.status-choice input:focus-visible + span { outline: 2px solid var(--muted); outline-offset: 3px; }
.status-choice input:disabled + span { opacity: .6; }
.report-id-copy { display: inline-block; margin-top: 8px; padding: 6px 9px; border: 1px dashed var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: .8rem; text-align: left; max-width: 100%; }
.report-id-copy:hover { border-color: var(--muted); }
.copy-feedback { display: block; margin-top: 4px; font-size: .74rem; min-height: 1em; }
#duplicate-field { min-width: 0; display: grid; gap: 7px; }
#duplicate-hint { margin: 0; font-size: .74rem; font-weight: 400; line-height: 1.4; }
.duplicate-suggestions { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); padding: 4px; max-height: 200px; overflow: auto; }
.duplicate-option { padding: 9px; border-radius: 8px; cursor: pointer; }
.duplicate-option[aria-selected="true"], .duplicate-option:hover { background: var(--surface-2); }
.duplicate-option .mono { display: block; font-size: .74rem; }
.duplicate-option .muted { display: block; margin-top: 4px; font-size: .72rem; line-height: 1.4; }

/* Short viewports retain normal document flow. Tall ones reserve separate scroll areas. */
@media (min-height: 700px) {
  #detail-dialog { height: calc(100dvh - 32px); max-height: calc(100dvh - 32px); overflow: hidden; }
  #detail-dialog > .detail-layout { height: 100%; min-height: 0; grid-template-rows: minmax(0, 1fr) auto; }
  #report-panel { display: flex; flex-direction: column; min-height: 0; }
  #report-panel > .dialog-header { flex-shrink: 0; }
  #detail-content { flex: 1; min-height: 0; overflow: hidden; display: flex; }
  #report-information { flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; padding: 0 8px 4px 0; }
  #detail-dialog .review-section { min-height: 0; max-height: 42dvh; overflow-y: auto; overscroll-behavior: contain; padding: 14px; }
  #review-heading { margin-bottom: 10px; }
  #review-form { grid-template-columns: 1fr 1fr; gap: 10px; }
  #review-form > * { min-width: 0; }
  #review-form > label:last-of-type, #review-form > .review-actions, #duplicate-field { grid-column: 1 / -1; }
  #reviewer-note { height: 60px; min-height: 48px; }
  #review-form .review-actions { flex-direction: row; align-items: center; }
}
@media (min-width: 1100px) and (min-height: 700px) {
  #detail-dialog > .detail-layout { grid-template-columns: minmax(0, 1fr) 360px; grid-template-rows: minmax(0, 1fr); gap: 24px; }
  #detail-dialog .review-section { max-height: 100%; padding: 18px; }
  #review-form { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  #review-form > * { grid-column: 1; }
  .status-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #review-form .review-actions { flex-direction: column; align-items: stretch; }
  #reviewer-note { height: 150px; }
  #metadata-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  #report-panel { padding: 16px; }
}

