:root {
  --navy: #0F172A;
  --slate-700: #334155;
  --slate-500: #64748B;
  --slate-300: #CBD5E1;
  --slate-200: #E2E8F0;
  --surface: #F8FAFC;
  --white: #FFFFFF;
  --amber: #D97706;
  --amber-soft: #FEF3C7;
  --red: #EF4444;
  --red-soft: #FEF2F2;
  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface);
  color: var(--slate-700);
  font-family: var(--font-ui);
}

#app {
  min-height: 100vh;
  width: 100%;
}

.screen { width: 100%; }

/* ── Screen 1: lookup ──────────────────────────────────────────────── */

.screen-lookup {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero {
  position: relative;
  width: 100%;
  background: var(--navy);
  color: var(--white);
  padding: 64px 20px 96px;
  text-align: center;
  overflow: hidden;
}

.hero-scanline {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(217, 119, 6, 0.55), transparent);
  top: 30%;
  animation: scan 6s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .hero-scanline { animation: none; opacity: 0.3; }
}

@keyframes scan {
  0% { top: 10%; opacity: 0; }
  10% { opacity: 1; }
  50% { top: 80%; opacity: 1; }
  90% { opacity: 0; }
  100% { top: 90%; opacity: 0; }
}

.eyebrow {
  position: relative;
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #94A3B8;
}

.hero h1 {
  position: relative;
  margin: 0 0 10px;
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 700;
  letter-spacing: -0.5px;
}

.hero-sub {
  position: relative;
  margin: 0;
  color: #94A3B8;
  font-size: 14px;
}

.lookup-card {
  width: min(420px, calc(100% - 32px));
  background: var(--white);
  border-radius: 14px;
  border: 1px solid var(--slate-200);
  box-shadow: 0 24px 48px -24px rgba(15, 23, 42, 0.35);
  padding: 28px 24px;
  margin-top: -56px;
  position: relative;
}

.code-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--slate-700);
  margin-bottom: 12px;
}

.code-input-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.code-input-group .dash {
  color: var(--slate-300);
  font-family: var(--font-mono);
  font-size: 20px;
  padding: 0 2px;
}

.code-box {
  width: 13%;
  max-width: 38px;
  aspect-ratio: 1;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--navy);
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.code-box:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
  background: var(--white);
}

.code-hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--slate-500);
  text-align: center;
}

.error-banner {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--red-soft);
  border: 1px solid #FECACA;
  color: var(--red);
  border-radius: 8px;
  font-size: 13px;
}

.btn-primary {
  width: 100%;
  margin-top: 18px;
  padding: 13px 16px;
  background: var(--navy);
  color: var(--white);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: background 0.15s;
}

.btn-primary:hover { background: #1E293B; }
.btn-primary:disabled { cursor: wait; opacity: 0.75; }

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.btn-secondary {
  padding: 10px 16px;
  background: var(--surface);
  color: var(--slate-700);
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* ── Screen 2: report ──────────────────────────────────────────────── */

.report-shell {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.report-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.report-card {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 12px;
  overflow: hidden;
}

.report-header {
  background: var(--navy);
  color: var(--white);
  padding: 20px 20px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.report-header .eyebrow { margin-bottom: 4px; }
.report-header h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.report-header .meta { font-size: 13px; color: #94A3B8; margin-top: 4px; }
.report-header .code-badge {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #94A3B8;
  white-space: nowrap;
}

.report-body { padding: 20px; }

.chip-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.chip {
  flex: 1;
  min-width: 70px;
  background: var(--surface);
  border: 1px solid var(--slate-200);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}

.chip .chip-value { font-size: 20px; font-weight: 700; }
.chip .chip-label { font-size: 11px; color: var(--slate-500); }

.section { margin-bottom: 24px; }

.section-head {
  font-size: 12px;
  font-weight: 700;
  color: var(--slate-500);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1.5px solid var(--navy);
  padding-bottom: 6px;
  margin-bottom: 12px;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 640px) {
  .info-grid { grid-template-columns: 1fr; }
}

.info-table { width: 100%; font-size: 13px; border-collapse: collapse; }
.info-table td { padding-bottom: 6px; vertical-align: top; }
.info-table td:first-child { color: var(--slate-500); padding-right: 10px; white-space: nowrap; }
.info-table td:last-child { font-weight: 500; color: var(--slate-700); word-break: break-word; }
.masked-value { font-family: var(--font-mono); letter-spacing: 0.5px; }

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

@media (max-width: 640px) {
  .service-grid { grid-template-columns: 1fr; }
}

.service-box {
  background: var(--surface);
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  padding: 10px 12px;
}
.service-box .label { font-size: 12px; color: var(--slate-500); }
.service-box .value { font-size: 14px; font-weight: 600; color: var(--slate-700); margin-top: 2px; }
.service-box .note { font-size: 12px; color: var(--slate-500); margin-top: 4px; }

.exterior-group { margin-bottom: 18px; }
.exterior-group .group-label,
.part-name {
  font-size: 18px;
  font-weight: 800;
  color: var(--navy);
  line-height: 1.2;
}

@media (max-width: 640px) {
  .exterior-group .group-label,
  .part-name {
    font-size: 16px;
  }
}

.diagram-wrap {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--slate-200);
  cursor: zoom-in;
}

.diagram-wrap img { display: block; width: 100%; height: auto; }

.diagram-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  color: var(--slate-500);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

.diagram-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.diagram-pin {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  transform: translate(-50%, -50%);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.4);
}

.mark-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .mark-grid { grid-template-columns: 1fr; }
}

.mark-card {
  background: var(--surface);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
}

.mark-card .mark-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.mark-card .mark-type { font-weight: 700; }
.mark-card .mark-note { color: var(--slate-500); margin-top: 2px; }

.mark-photo-toggle {
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--slate-300);
  background: var(--white);
  color: var(--slate-700);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.mark-photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.mark-photo-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--slate-200);
  cursor: zoom-in;
}

.post-work-section {
  background: #F8FAFC;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  padding: 14px;
}

.post-work-date {
  margin: -4px 0 12px;
  color: var(--slate-500);
  font-size: 12px;
  font-weight: 700;
}

.post-work-group {
  margin-top: 14px;
}

.post-work-group:first-of-type {
  margin-top: 0;
}

.post-work-group-label {
  color: var(--navy);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
}

.post-work-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 8px;
}

@media (max-width: 760px) {
  .post-work-grid { grid-template-columns: 1fr; }
}

.post-work-card {
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  padding: 10px;
}

.post-work-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--navy);
  font-size: 13px;
  font-weight: 800;
}

.post-work-comment {
  margin-top: 8px;
  color: var(--slate-700);
  font-size: 13px;
  line-height: 1.45;
}

.post-work-comment .label {
  color: var(--slate-500);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 2px;
}

.post-work-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

@media (max-width: 520px) {
  .post-work-compare { grid-template-columns: 1fr; }
}

.post-work-photo-title {
  color: var(--slate-500);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 6px;
}

.post-work-photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.post-work-photo {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--slate-200);
  cursor: zoom-in;
}

.post-work-empty {
  min-height: 40px;
  display: flex;
  align-items: center;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 640px) {
  .gallery-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.gallery-item { text-align: center; }

.gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--slate-200);
  cursor: zoom-in;
}

.gallery-item .gallery-label {
  margin-top: 4px;
  font-size: 11px;
  color: var(--slate-500);
}

.condition-box {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 8px;
  padding: 12px 14px;
  border: 1px solid var(--slate-200);
}

.condition-box-small {
  display: inline-flex;
  gap: 8px;
  padding: 5px 7px;
}

.condition-badge {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  flex-shrink: 0;
}

.condition-badge-small {
  width: 28px;
  height: 26px;
  border-radius: 7px;
  font-size: 14px;
}

.condition-text .label { font-size: 12px; color: var(--slate-500); }
.condition-text .value { font-size: 15px; font-weight: 700; margin-top: 2px; }

.group-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.empty-note {
  color: var(--slate-500);
  font-size: 13px;
  background: var(--surface);
  border: 1px dashed var(--slate-300);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}

.ai-section {
  background: #FFFFFF;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  padding: 14px;
}

.ai-block,
.ai-work-group {
  margin-bottom: 14px;
}

.ai-block:last-child,
.ai-work-group:last-child {
  margin-bottom: 0;
}

.ai-block-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--slate-500);
  margin-bottom: 6px;
}

.ai-text {
  color: var(--slate-700);
  font-size: 14px;
  line-height: 1.45;
}

.ai-list {
  display: grid;
  gap: 6px;
}

.ai-list-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  color: var(--slate-700);
  font-size: 13px;
  line-height: 1.4;
}

.ai-mark {
  font-family: var(--font-mono);
  color: var(--navy);
  font-weight: 700;
  white-space: nowrap;
}

.ai-work-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 640px) {
  .ai-work-grid { grid-template-columns: 1fr; }
}

.ai-estimate {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--slate-200);
  color: var(--navy);
  font-size: 15px;
  font-weight: 700;
}

.ai-debug-section {
  background: #FFFBEB;
  border: 1px solid #F59E0B;
  border-radius: 8px;
  padding: 14px;
}

.logs-toggle {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid #F59E0B;
  border-radius: 7px;
  background: #FFFFFF;
  color: #92400E;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.debug-panel {
  margin-top: 12px;
}

@media (max-width: 899px) {
  .desktop-logs-only {
    display: none;
  }
}

.debug-warning {
  color: #92400E;
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 12px;
}

.debug-details {
  background: var(--white);
  border: 1px solid #FDE68A;
  border-radius: 8px;
  margin-bottom: 10px;
  overflow: hidden;
}

.debug-details summary {
  cursor: pointer;
  padding: 9px 11px;
  color: var(--navy);
  font-size: 13px;
  font-weight: 700;
}

.debug-pre {
  margin: 0;
  padding: 11px;
  max-height: 360px;
  overflow: auto;
  background: #0F172A;
  color: #E2E8F0;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.debug-image-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 12px;
}

.debug-image-card {
  background: var(--white);
  border: 1px solid #FDE68A;
  border-radius: 8px;
  padding: 10px;
}

.debug-image-title {
  color: var(--navy);
  font-size: 14px;
  font-weight: 800;
}

.debug-meta {
  color: var(--slate-500);
  font-size: 12px;
  margin-top: 2px;
}

.debug-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.debug-parts span {
  border: 1px solid #FDE68A;
  border-radius: 999px;
  padding: 3px 7px;
  color: #92400E;
  background: #FFFBEB;
  font-size: 11px;
  font-weight: 700;
}

.debug-image {
  width: 100%;
  margin-top: 10px;
  border: 1px solid var(--slate-200);
  border-radius: 8px;
  background: var(--surface);
  cursor: zoom-in;
}

.debug-marks {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.debug-mark {
  border: 1px solid var(--slate-200);
  border-radius: 7px;
  padding: 7px 8px;
  color: var(--slate-700);
  font-size: 12px;
  line-height: 1.4;
}

.debug-closeups {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 7px;
}

.debug-closeups img {
  width: 84px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--slate-200);
  cursor: zoom-in;
}

.report-footer {
  border-top: 1px solid #F1F5F9;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #94A3B8;
}

/* ── Lightbox ──────────────────────────────────────────────────────── */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  touch-action: none;
}

.lightbox-figure {
  margin: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lightbox-figure img {
  max-width: 100%;
  max-height: calc(100vh - 96px);
  object-fit: contain;
  border-radius: 8px;
  background: var(--white);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}

.lightbox-figure figcaption {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: calc(100% - 112px);
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  color: #E2E8F0;
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 23, 42, 0.72);
  color: var(--white);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

[hidden] { display: none !important; }
