:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --line: #d9e1e8;
  --line-strong: #b9c6d1;
  --text: #17202a;
  --muted: #687583;
  --accent: #1b6f72;
  --accent-dark: #135457;
  --accent-soft: #dcefed;
  --warn: #b86d1f;
  --warn-soft: #f7e8d8;
  --danger: #b44545;
  --danger-soft: #f4dddd;
  --ok: #2d7c48;
  --ok-soft: #dceee3;
  --shadow: 0 18px 48px rgba(34, 48, 62, 0.12);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
}

.app-header,
.brand-lockup,
.header-actions,
.panel-heading,
.section-heading,
.report-actions {
  display: flex;
  align-items: center;
}

.app-header {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.brand-lockup {
  gap: 16px;
}

.plate-mark {
  display: grid;
  width: 138px;
  height: 58px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid #1e2a33;
  border-radius: 7px;
  background:
    linear-gradient(90deg, #265b9d 0 18%, transparent 18%),
    linear-gradient(#ffffff, #f7f9fb);
  box-shadow: inset 0 0 0 4px #ffffff;
}

.plate-mark span {
  margin-left: 18px;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 2.2vw, 2.35rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
}

h3 {
  font-size: 1rem;
}

.eyebrow,
.file-drop span,
.text-control span,
.metric-tile span,
.summary-list dt,
.rule-list dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.eyebrow {
  margin-bottom: 3px;
}

.muted,
.subtle,
.status-message {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
  margin-top: 6px;
}

.field-error {
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 700;
}

.text-control.has-error,
.file-drop.has-error {
  border-color: var(--danger);
}

.upload-progress {
  margin-top: 10px;
}

.upload-progress-track {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.15s ease;
}

.upload-progress-fill.processing {
  width: 100%;
  animation: bar-pulse 1.2s ease-in-out infinite;
}

@keyframes bar-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.upload-progress-label {
  margin: 5px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.header-actions {
  gap: 10px;
}

/* Overrides .primary-button's width:100% for the header's Final Report link — without this
   it stretches to fill .user-actions and crowds its siblings. Capped so it never reads wider
   than a single step chip in the stepper below. Targeted by id: a same-specificity class rule
   would lose to .primary-button's later width:100% declaration in source order. */
#topReportLink {
  width: auto;
  max-width: 150px;
  padding: 0 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.step {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  font-weight: 800;
  text-align: center;
}

.step.active {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
}

.step.complete {
  color: var(--ok);
  background: var(--ok-soft);
}

.workspace {
  display: block;
}

.run-info-panel,
.flow-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.run-info-panel {
  margin-bottom: 16px;
}

.run-info-panel > summary {
  padding: 18px;
  cursor: pointer;
}

.run-info-panel > summary::-webkit-details-marker {
  color: var(--muted);
}

.run-info-panel[open] > summary {
  border-bottom: 1px solid var(--line);
}

.run-info-body {
  padding: 18px;
  display: grid;
  gap: 24px;
}

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

/* Single-column variant of .run-info-body: content stacks top-to-bottom on the left
   (list, then the "add" form below it) instead of splitting into a second column. */
.facility-panel-body {
  padding: 18px;
  display: grid;
  gap: 16px;
}

.panel-heading,
.section-heading,
.report-actions {
  justify-content: space-between;
  gap: 12px;
}

.summary-list,
.rule-list {
  display: grid;
  gap: 12px;
  margin: 14px 0 0;
}

.summary-list div,
.rule-list div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
}

.summary-list dd,
.rule-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.main-flow {
  display: grid;
  gap: 16px;
  min-width: 0;
}

#adminManagementSection {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.flow-card {
  min-width: 0;
  padding: 18px;
}

.flow-card.locked {
  opacity: 0.78;
}

.upload-grid,
.controls-grid,
.metrics-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.upload-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.metadata-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.controls-grid {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  margin-bottom: 14px;
}

.regions-control {
  position: relative;
}

.help-button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.help-button:hover {
  color: var(--text);
  border-color: var(--accent);
}

.help-dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  background: #ffffff;
  color: var(--text);
}

.help-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.help-dialog h3 {
  margin-top: 0;
}

.help-dialog ul {
  padding-left: 20px;
}

.help-dialog code {
  background: var(--surface-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

.dialog-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.dialog-actions .primary-button {
  width: auto;
  padding: 0 20px;
}

.metrics-grid {
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  margin-bottom: 16px;
}

.file-drop,
.text-control,
.toggle-row,
.code-sample,
.notice,
.metric-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.file-drop {
  display: grid;
  gap: 6px;
  padding: 16px;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.file-drop strong {
  color: var(--accent-dark);
  overflow-wrap: anywhere;
}

.text-control {
  display: grid;
  gap: 5px;
  padding: 9px 11px;
}

.text-control input {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
}

.toggle-row {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.service-type-group {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px 12px;
}

.service-type-group .eyebrow {
  width: 100%;
  margin-bottom: 2px;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 2px;
  cursor: pointer;
}

.radio-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.service-options {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(200px, 1fr));
  gap: 12px;
}

.code-sample {
  margin: 14px 0;
  padding: 14px;
}

.code-sample pre {
  margin: 6px 0 0;
  overflow: auto;
}

.notice {
  margin: 14px 0;
  padding: 12px;
  color: var(--warn);
  background: var(--warn-soft);
}

.primary-button,
.ghost-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button,
.icon-button {
  color: var(--text);
  border-color: var(--line);
  background: #ffffff;
}

.ghost-button {
  padding: 0 14px;
}

.icon-button {
  width: 40px;
}

.metric-tile {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.metric-tile strong {
  font-size: clamp(1.35rem, 2vw, 1.9rem);
}

.metric-tile small {
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 880px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f8fafb;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.empty-row td {
  height: 120px;
  color: var(--muted);
  text-align: center;
}

.image-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  width: 480px;
}

.thumbnail {
  position: relative;
  display: grid;
  width: 480px;
  height: 320px;
  overflow: hidden;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  cursor: zoom-in;
}

.pending-review-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  padding: 4px 8px;
  border: 1px solid var(--danger);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--danger);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  pointer-events: none;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
  padding: 24px;
}

.image-lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.file-name,
.plate-text {
  font-weight: 800;
}

.image-cell .file-name,
.image-cell .subtle {
  display: block;
  overflow-wrap: anywhere;
  word-break: break-all;
}

a.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  padding: 0 16px;
  box-sizing: border-box;
}

a.ghost-button {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-sizing: border-box;
}

a.ghost-button[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
}

.report-group-heading {
  margin-top: 24px;
  margin-bottom: 8px;
  font-size: 18px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 4px;
}

@media print {
  .report-group-heading {
    margin-top: 12px;
    font-size: 14px;
    page-break-after: avoid;
  }
}

a.primary-button[aria-disabled="true"] {
  opacity: 0.55;
  pointer-events: none;
  cursor: not-allowed;
}

.override-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}

.override-toggle input {
  margin: 0;
}

.override-row td {
  background: var(--surface-soft);
}

.override-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.override-form .text-control {
  margin: 0;
}

.override-form select {
  border: 0;
  background: transparent;
  color: var(--text);
  min-width: 0;
  font-size: inherit;
}

.override-actions {
  display: flex;
  gap: 8px;
}

.override-actions .primary-button,
.override-actions .ghost-button {
  width: auto;
  padding: 0 16px;
}

@media (max-width: 768px) {
  .override-form {
    grid-template-columns: 1fr;
  }
}

.subtle {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
}

.button-pair {
  display: flex;
  gap: 8px;
}

.review-decision-buttons {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 900;
}

.neutral,
.status-category {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.status-uploaded,
.status-processing {
  color: var(--warn);
  background: var(--warn-soft);
}

.status-needs_review,
.status-wrong {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-completed,
.status-invalid {
  color: var(--ok);
  background: var(--ok-soft);
}

.status-correct {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.status-message {
  min-height: 22px;
  margin: 0;
}

.status-message.error {
  color: var(--danger);
}

.report-actions {
  margin: 10px 0 16px;
}

.review-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}

.review-card {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.review-card img {
  width: 120px;
  height: 82px;
  object-fit: cover;
  border-radius: 7px;
}

@media (max-width: 1050px) {
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 16px;
  }

  .app-header,
  .brand-lockup {
    align-items: stretch;
    flex-direction: column;
  }

  .stepper,
  .upload-grid,
  .controls-grid,
  .metrics-grid,
  .metadata-grid {
    grid-template-columns: 1fr;
  }

  .review-card {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .app-header,
  .stepper,
  .run-info-panel,
  #uploadView,
  #processView,
  #reviewView,
  .report-actions,
  .status-message,
  .no-print {
    display: none !important;
  }

  .app-shell {
    padding: 0;
  }

  .workspace {
    display: block;
  }

  .flow-card {
    box-shadow: none;
    border: 0;
  }

  body:not(.print-with-images) .report-review-media {
    display: none;
  }

  /* Compact layout so the report table fits portrait pages */
  @page {
    margin: 12mm;
  }

  .image-cell {
    width: 180px;
    gap: 4px;
  }

  .thumbnail {
    width: 180px;
    height: 120px;
  }

  table {
    font-size: 11px;
    width: 100%;
    min-width: 0;
    table-layout: fixed;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
  }

  /* Column widths for the report table: image | expected | alpr | category */
  table thead th:nth-child(1),
  table tbody td:nth-child(1) {
    width: 200px;
  }

  table thead th:nth-child(2),
  table tbody td:nth-child(2),
  table thead th:nth-child(3),
  table tbody td:nth-child(3) {
    width: 90px;
  }

  table thead th:nth-child(4),
  table tbody td:nth-child(4) {
    width: 90px;
  }

  th, td {
    padding: 4px 6px;
    word-break: break-word;
    overflow-wrap: anywhere;
    vertical-align: top;
  }

  .file-name {
    font-size: 10px;
    font-weight: 600;
  }

  .subtle {
    font-size: 9px;
  }

  tr {
    page-break-inside: avoid;
  }

  .metrics-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }

  .metric-tile {
    padding: 6px 8px;
  }

  .metric-tile strong {
    font-size: 16px;
  }

  .thumbnail img {
    cursor: default;
  }

  .status-pill {
    font-size: 9px;
    padding: 2px 6px;
  }

  .plate-text {
    font-size: 11px;
  }
}

/* Landing/auth page styles */
.auth-shell {
  min-height: 80vh;
  display: grid;
  place-items: center;
}
.auth-card {
  width: min(560px, 92%);
  padding: 24px;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-actions {
  margin-top: 12px;
}

/* Admin panel (Phase 3) */
.row-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.row-actions .ghost-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 0.82rem;
}
.role-select {
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 700;
}
