:root {
  --bg: #f4f7f2;
  --bg-strong: #e7efe1;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --surface-soft: #f8faf6;
  --line: #d8e2d0;
  --line-strong: #bfceb3;
  --text: #1f2a1f;
  --muted: #5f6f61;
  --brand: #2f7d4a;
  --brand-strong: #1f6337;
  --approved: #2f9e59;
  --approved-soft: #e6f6ea;
  --rejected: #d84949;
  --rejected-soft: #ffe9e7;
  --review: #cc9a06;
  --review-soft: #fff6d7;
  --pending: #738172;
  --pending-soft: #eff3ee;
  --shadow: 0 18px 50px rgba(64, 87, 58, 0.12);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

html {
  font-size: 15px;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(89, 154, 89, 0.12), transparent 22%),
    radial-gradient(circle at bottom right, rgba(233, 189, 85, 0.12), transparent 18%),
    linear-gradient(180deg, #fbfcf8 0%, #f2f6ef 100%);
  font-family: "Segoe UI", "Inter", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  min-height: 100vh;
  width: min(100%, 1540px);
  margin: 0 auto;
}

.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem;
  background: rgba(239, 245, 235, 0.9);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand-block {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 1rem 1.1rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(239, 246, 232, 0.96));
  box-shadow: var(--shadow);
}

.brand-block strong,
.brand-block small {
  display: block;
}

.brand-block small,
.sidebar-caption,
.section-subtitle,
.table-subtext,
.kpi-trend,
.field-caption,
.history-card-subtitle,
.topbar-kicker,
.topbar-search input::placeholder,
.loading-subtle,
.lead,
.result-meta,
.empty-state,
.instruction-banner,
.stacked-metric span,
.capture-frame-label {
  color: var(--muted);
}

.brand-mark,
.nav-tile-icon,
.mobile-nav-icon,
.profile-chip-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 700;
}

.brand-mark {
  width: 3rem;
  height: 3rem;
  background: linear-gradient(135deg, var(--brand), #4ca364);
  color: #fff;
}

.sidebar-nav {
  display: grid;
  gap: 0.5rem;
}

.sidebar-caption {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.12rem;
  margin: 0 0 0.35rem 0.5rem;
}

.nav-tile {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius-md);
  color: var(--muted);
  transition: background-color 140ms ease, color 140ms ease, transform 140ms ease;
}

.nav-tile:hover,
.nav-tile.is-active {
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: 0 8px 20px rgba(88, 107, 77, 0.08);
  transform: translateY(-1px);
}

.nav-tile-icon,
.mobile-nav-icon {
  width: 2.25rem;
  height: 2.25rem;
  background: var(--bg-strong);
  color: var(--brand-strong);
  font-size: 0.72rem;
  letter-spacing: 0.05rem;
}

.sidebar-card,
.surface-card,
.hero-side-card,
.surface-subcard,
.kpi-card,
.history-card,
.reference-card {
  background: var(--surface);
  border: 1px solid rgba(216, 226, 208, 0.9);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.sidebar-card {
  margin-top: auto;
  padding: 1.25rem;
}

.sidebar-card h2,
.surface-card h2,
.surface-card h3,
.hero-side-card h3,
.surface-subcard h3,
.kpi-card h3 {
  margin-top: 0;
}

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 420px) auto;
  align-items: start;
  gap: 1rem;
  padding: 1.5rem 2rem 1rem;
}

.topbar-title-block {
  min-width: 0;
}

.topbar-kicker {
  margin: 0 0 0.2rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.12rem;
}

.topbar-title {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.3rem);
}

.topbar-actions,
.button-row,
.dashboard-actions,
.section-header,
.history-card-meta,
.reference-card-meta,
.candidate-card-footer,
.decision-bar,
.hero-actions,
.action-row,
.admin-toolbar,
.preview-decision-row,
.preview-decision-group,
.search-form,
.tab-row,
.pagination-row,
.result-meta {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-form-inline {
  flex-wrap: nowrap;
  align-items: center;
}

.search-form-field {
  width: min(100%, 680px);
  flex: 0 1 680px;
}

.topbar-actions {
  grid-column: 3;
  justify-content: flex-end;
  align-content: flex-start;
  align-items: flex-start;
}

.topbar-search {
  grid-column: 2;
  width: 100%;
  justify-self: center;
}

.topbar-search .form-control {
  min-height: 2.9rem;
}

.content-container {
  padding: 0 2rem 2rem;
}

.content-panel {
  padding: 1.35rem;
  background: var(--surface);
  border: 1px solid rgba(216, 226, 208, 0.9);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.upload-master-panel {
  width: min(100%, 980px);
}

.main-content {
  display: grid;
  gap: 1.5rem;
}

.app-alert {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2100;
  width: min(calc(100vw - 2rem), 640px);
  padding: 1.2rem 1.4rem;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  border: 2px solid rgba(47, 125, 74, 0.28);
  color: var(--brand-strong);
  background: var(--approved-soft);
  border-radius: var(--radius-md);
  box-shadow: 0 28px 80px rgba(31, 42, 31, 0.24);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-alert.is-hiding {
  opacity: 0;
  transform: translate(-50%, calc(-50% - 8px));
}

.profile-chip {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 0.15rem;
}

.profile-chip-main {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.55rem 0.85rem;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.profile-chip-main strong,
.profile-chip-main small {
  display: block;
  line-height: 1.1;
}

.profile-chip-avatar {
  width: 2.2rem;
  height: 2.2rem;
  background: var(--brand);
  color: #fff;
}

.hero-surface,
.dashboard-layout,
.scan-layout,
.history-layout,
.admin-surface-grid,
.detail-layout,
.prepare-grid {
  display: grid;
  gap: 1.5rem;
}

.hero-surface {
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.85fr);
  padding: 2rem;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(236, 244, 229, 0.92));
  border: 1px solid var(--line);
  border-radius: 32px;
  box-shadow: var(--shadow);
}

.hero-copy h2 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.05;
  max-width: 12ch;
}

.auth-surface {
  align-items: stretch;
}

.auth-card {
  width: 100%;
  max-width: 560px;
  justify-self: end;
  padding: 1.6rem;
}

.lead {
  margin: 1rem 0 0;
  max-width: 62ch;
  font-size: 1.04rem;
}

.feature-list,
.step-list,
.timeline-list,
.ocr-diff-list {
  margin: 1rem 0 0;
  padding-left: 1.2rem;
}

.dashboard-intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  flex-wrap: wrap;
}

.dashboard-layout,
.scan-layout,
.history-layout,
.detail-layout,
.admin-surface-grid {
  grid-template-columns: minmax(0, 1fr) 320px;
}

.admin-surface-grid {
  grid-template-columns: 320px minmax(0, 1fr);
  align-items: start;
}

.dashboard-main,
.history-main,
.detail-main {
  display: grid;
  gap: 1.5rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.kpi-card,
.surface-card,
.hero-side-card,
.surface-subcard,
.reference-card,
.history-card {
  padding: 1.35rem;
}

.kpi-card {
  min-height: 10.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.kpi-card-primary {
  background: linear-gradient(135deg, #2f7d4a, #3f9258);
  color: #fff;
}

.kpi-card-primary .kpi-label,
.kpi-card-primary .kpi-trend {
  color: rgba(255, 255, 255, 0.78);
}

.kpi-label {
  font-size: 0.95rem;
}

.kpi-value {
  font-size: clamp(2rem, 3vw, 2.8rem);
  line-height: 1;
}

.section-header {
  justify-content: space-between;
}

.surface-card .section-header h3,
.surface-card .section-header h2 {
  margin-bottom: 0.1rem;
}

.quick-actions,
.analysis-list,
.stacked-metrics,
.candidate-list,
.history-card-list,
.reference-card-list {
  display: grid;
  gap: 0.9rem;
}

.masters-overview-card {
  overflow: hidden;
}

.masters-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.masters-filter-panel {
  display: grid;
  gap: 1rem;
  align-self: start;
}

.masters-list-panel {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.masters-pagination {
  justify-content: space-between;
  margin-top: 0.5rem;
 }

.quick-action,
.analysis-item,
.stacked-metric,
.candidate-card {
  display: block;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.quick-action strong,
.quick-action span,
.analysis-item span,
.analysis-item strong,
.stacked-metric strong,
.stacked-metric span {
  display: block;
}

.quick-action strong,
.analysis-item strong,
.stacked-metric strong {
  margin-bottom: 0.25rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.38rem 0.8rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.status-approved {
  color: var(--approved);
  background: var(--approved-soft);
}

.status-rejected {
  color: var(--rejected);
  background: var(--rejected-soft);
}

.status-review {
  color: var(--review);
  background: var(--review-soft);
}

.status-pending {
  color: var(--pending);
  background: var(--pending-soft);
}

.app-table {
  --bs-table-bg: transparent;
  --bs-table-border-color: var(--line);
  margin-bottom: 0;
}

.app-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
}

.scan-stage,
.scan-sidebar,
.dashboard-side,
.detail-side,
.history-filters {
  display: grid;
  gap: 1.5rem;
}

.scan-capture-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.9fr);
  gap: 1rem;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, rgba(238, 245, 234, 0.7), rgba(255, 255, 255, 0.95));
}

.capture-preview,
.capture-actions,
.prepare-canvas {
  min-width: 0;
}

.capture-frame {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 1.5rem;
  text-align: center;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(241, 246, 235, 0.86));
}

.capture-frame-button {
  width: 100%;
  appearance: none;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.capture-frame-button:focus-visible {
  outline: 3px solid rgba(47, 125, 74, 0.3);
  outline-offset: 4px;
}

.capture-frame-button p,
.capture-frame-button .capture-frame-label {
  position: relative;
  z-index: 1;
}

.capture-frame-thumbnail {
  width: 100%;
  height: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: calc(var(--radius-lg) - 6px);
  border: 1px solid rgba(216, 226, 208, 0.9);
  background: #fff;
  margin-bottom: 0.9rem;
  box-shadow: 0 12px 28px rgba(64, 87, 58, 0.12);
}

.capture-frame-button.has-preview {
  align-content: start;
}

.btn:disabled,
.btn.disabled {
  opacity: 1;
  cursor: not-allowed;
}

.btn-primary:disabled,
.btn-primary.disabled {
  background: linear-gradient(135deg, #b9c4b7, #aab6a8);
  color: rgba(255, 255, 255, 0.92);
  box-shadow: none;
}

.capture-frame-label {
  display: block;
  margin-bottom: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 0.12rem;
  font-size: 0.78rem;
}

.scan-form-grid,
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.validation-strip {
  border-radius: var(--radius-md);
  border: 1px solid #f0c9c5;
  background: #fff4f3;
  color: #8f3028;
  padding: 0.85rem 1rem;
}

.prepare-layout,
.admin-layout {
  display: grid;
  gap: 1.5rem;
}

.instruction-banner {
  margin-top: 1rem;
  padding: 1rem 1.1rem;
  background: var(--pending-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.instruction-banner-danger {
  background: var(--rejected-soft);
  border-color: #f1cbc7;
  color: #8f3028;
}

.surface-subcard {
  align-self: start;
}

.corner-editor,
.zone-editor,
.cropper-shell {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fff;
  user-select: none;
}

.corner-editor-image,
.zone-editor-image,
.cropper-image {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}

.corner-overlay,
.zone-overlay,
.zone-draft,
.master-preview-overlay {
  position: absolute;
  inset: 0;
}

.master-preview-frame {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.preview-master-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 560px;
  height: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #fff;
}

.master-preview-overlay {
  pointer-events: none;
}

.corner-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.corner-lines polygon {
  fill: rgba(249, 115, 22, 0.16);
  stroke: #f97316;
  stroke-width: 1.2;
}

.corner-handle {
  position: absolute;
  width: 28px;
  height: 28px;
  margin-left: -14px;
  margin-top: -14px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: #f97316;
  box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.22);
  cursor: grab;
  z-index: 2;
  touch-action: none;
}

.corner-handle::before {
  content: "";
  position: absolute;
  inset: -14px;
}

.corner-handle:active {
  cursor: grabbing;
}

.zone-box,
.zone-draft,
.master-preview-zone {
  position: absolute;
  border: 2px solid #f97316;
  background: rgba(249, 115, 22, 0.14);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
  z-index: 2;
}

.zone-box span,
.master-preview-zone span {
  position: absolute;
  top: 0.18rem;
  left: 0.3rem;
  font-size: 0.76rem;
  color: #fff;
  background: rgba(31, 42, 31, 0.76);
  border-radius: 999px;
  padding: 0.12rem 0.36rem;
  pointer-events: none;
}

.zone-actions {
  position: absolute;
  top: 0.2rem;
  right: 0.2rem;
  display: flex;
  gap: 0.25rem;
}

.zone-rename,
.zone-remove,
.zone-type-select {
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  min-height: 1.9rem;
  padding: 0 0.55rem;
}

.zone-type-select {
  border-radius: 999px;
}

.zone-resize {
  position: absolute;
  right: -0.45rem;
  bottom: -0.45rem;
  width: 1rem;
  height: 1rem;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #f97316;
  cursor: nwse-resize;
}

.zone-list,
.field-note-list,
.field-compare-grid,
.field-preview-grid,
.results-grid {
  display: grid;
  gap: 0.75rem;
}

.zone-list-item,
.field-compare-card,
.result-card,
.reason-box,
.decision-panel,
.stat-card {
  padding: 0.95rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.status-hero {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  padding: 1.5rem;
  border-radius: var(--radius-xl);
  border: 1px solid transparent;
}

.status-hero.status-approved {
  background: linear-gradient(135deg, #eff9f0, #dff2e4);
  border-color: #cee6d3;
}

.status-hero.status-rejected {
  background: linear-gradient(135deg, #fff2f0, #ffe7e4);
  border-color: #f3d0ca;
}

.status-hero.status-review {
  background: linear-gradient(135deg, #fff8df, #fff2c7);
  border-color: #ead7a1;
}

.status-hero h2 {
  margin: 0.1rem 0;
  font-size: clamp(1.9rem, 3vw, 2.6rem);
}

.status-hero p,
.status-hero-meta {
  margin: 0;
}

.status-hero-meta {
  display: grid;
  gap: 0.35rem;
  text-align: right;
  color: var(--muted);
}

.detail-tab-row {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.detail-tab-row a {
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.image-panel {
  display: grid;
  gap: 0.75rem;
}

.image-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.comparison-image {
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #fff;
}

.diff-inline {
  display: grid;
  gap: 0.5rem;
}

.verification-image-frame {
  position: relative;
  display: inline-block;
  width: 100%;
}

.verification-image-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.verification-zone {
  position: absolute;
  border: 2px solid #f97316;
  background: rgba(249, 115, 22, 0.12);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.verification-zone span {
  position: absolute;
  top: 0.18rem;
  left: 0.3rem;
  font-size: 0.76rem;
  color: #fff;
  background: rgba(31, 42, 31, 0.76);
  border-radius: 999px;
  padding: 0.12rem 0.36rem;
}

.field-table {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.field-table-head,
.field-table-cell {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: #fff;
}

.field-table-head {
  font-weight: 700;
  background: var(--surface-soft);
}

.field-table-name {
  font-weight: 700;
}

.field-table > :nth-last-child(-n+5) {
  border-bottom: 0;
}

.field-table > :nth-child(5n) {
  border-right: 0;
}

.field-table-with-debug .field-table-debug-row {
  grid-column: 1 / -1;
  padding: 0 1rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.field-table-with-debug > :nth-last-child(-n+6) {
  border-bottom: 0;
}

.field-debug-inline summary {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

.field-debug-inline summary::-webkit-details-marker {
  display: none;
}

.candidate-thumb {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
}

.candidate-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.history-card,
.reference-card {
  display: grid;
  gap: 0.9rem;
}

.history-card-top,
.reference-card-main {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.history-card h3,
.reference-card h4 {
  margin: 0;
}

.reference-card-title {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-width: 0;
}

.reference-thumb {
  width: 84px;
  height: 84px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
}

.history-category {
  margin-bottom: 0.3rem;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1rem;
}

.history-note {
  padding: 0.85rem 1rem;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--muted);
}

.history-card-meta,
.reference-card-meta {
  color: var(--muted);
  font-size: 0.92rem;
}

.empty-state {
  padding: 1.15rem 1.2rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.6);
}

.mobile-nav {
  display: none;
}

.form-control,
.form-select {
  min-height: 3rem;
  border-color: var(--line-strong);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus,
.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus {
  border-color: rgba(47, 125, 74, 0.5);
  box-shadow: 0 0 0 0.2rem rgba(47, 125, 74, 0.14);
}

.btn {
  border-radius: 999px;
  padding: 0.65rem 1rem;
  font-weight: 600;
}

.btn-primary {
  border: 0;
  background: linear-gradient(135deg, var(--brand), #46945b);
}

.btn-success {
  border-color: var(--approved);
  background: var(--approved);
}

.btn-danger {
  border-color: var(--rejected);
  background: var(--rejected);
}

.btn-outline-secondary,
.btn-outline-light,
.btn-outline-info {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.72);
}

.autocomplete-root {
  position: relative;
}

.autocomplete-results {
  display: none;
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.autocomplete-results.is-open {
  display: block;
}

.autocomplete-option {
  width: 100%;
  text-align: left;
  padding: 0.85rem 1rem;
  background: transparent;
  border: 0;
  color: var(--text);
}

.autocomplete-option:hover,
.autocomplete-option:focus {
  background: rgba(63, 146, 88, 0.1);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(245, 248, 242, 0.78);
  backdrop-filter: blur(6px);
  z-index: 2000;
}

.loading-overlay.is-visible {
  display: flex;
}

.loading-card {
  width: min(100%, 480px);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.loading-spinner {
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  border: 4px solid rgba(47, 125, 74, 0.14);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}

.loading-progress {
  height: 10px;
  background: rgba(47, 125, 74, 0.12);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 1rem;
}

.loading-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3b864f, #5dac6f, #91c28d);
  transition: width 220ms ease-out;
}

.pdf-frame {
  width: 100%;
  min-height: 720px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
}

.narrow-panel {
  max-width: 760px;
  margin: 0 auto;
}

.table {
  --bs-table-bg: transparent;
  --bs-table-border-color: var(--line);
}

.list-group-item {
  padding-left: 0;
  padding-right: 0;
}

.timeline-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.timeline-list li {
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}

.diff-preview img,
.field-preview-grid img {
  width: 100%;
  max-height: 220px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #fff;
  object-fit: contain;
}

.preview-field-image {
  width: 112px;
  height: 112px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
}

.preview-field-image-large {
  width: min(100%, 220px);
  height: auto;
  max-height: 180px;
}

.field-debug-toggle {
  width: 100%;
}

.field-debug-toggle summary {
  cursor: pointer;
  color: var(--brand-strong);
  font-size: 0.9rem;
  font-weight: 600;
}

.field-debug-card {
  margin-top: 0.6rem;
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.diff-preview.large img {
  max-height: 320px;
}

.ocr-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: Consolas, "Courier New", monospace;
  margin: 0.75rem 0 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1199px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 991px) {
  .app-shell,
  .dashboard-layout,
  .scan-layout,
  .history-layout,
  .detail-layout,
  .admin-surface-grid,
  .masters-shell,
  .hero-surface,
  .scan-capture-card,
  .scan-form-grid,
  .comparison-grid,
  .prepare-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    display: block;
    width: 100%;
  }

  .app-sidebar {
    display: none;
  }

  .content-container,
  .topbar {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .main-content {
    padding-bottom: 5.75rem;
  }

  .app-alert {
    width: min(calc(100vw - 1.5rem), 520px);
    padding: 1rem 1.1rem;
    font-size: 1rem;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0.8rem calc(0.75rem + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(14px);
  }

  .mobile-nav-link {
    display: grid;
    flex: 1 1 0;
    justify-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.25rem;
    color: var(--muted);
    font-size: 0.8rem;
  }

  .mobile-nav-link.is-active {
    color: var(--brand-strong);
    background: rgba(47, 125, 74, 0.12);
    border-radius: 18px;
  }

  .mobile-nav-link.is-active .mobile-nav-icon {
    background: linear-gradient(135deg, var(--brand), #46945b);
    color: #fff;
    box-shadow: 0 12px 25px rgba(47, 125, 74, 0.28);
  }

  .topbar {
    align-items: start;
    grid-template-columns: 1fr;
  }

  .topbar-search,
  .topbar-actions,
  .profile-chip {
    width: 100%;
  }

  .topbar-search,
  .topbar-actions {
    grid-column: auto;
    justify-self: stretch;
  }

  .profile-chip {
    justify-content: space-between;
  }

  .kpi-grid,
  .field-table {
    grid-template-columns: 1fr;
  }

  .field-table-head {
    display: none;
  }

  .field-table-cell {
    border-right: 0;
  }

  .field-table > :nth-last-child(-n+4) {
    border-bottom: 1px solid var(--line);
  }

  .field-table > :last-child {
    border-bottom: 0;
  }

  .status-hero {
    align-items: start;
    flex-direction: column;
  }

  .status-hero-meta {
    text-align: left;
  }

  .search-form .form-control,
  .search-form .btn,
  .tab-row .btn,
  .decision-bar .btn,
  .button-row .btn {
    width: 100%;
  }

  .search-form-inline {
    flex-wrap: wrap;
  }

  .search-form-field {
    width: 100%;
    flex-basis: 100%;
  }

  .decision-bar {
    align-items: stretch;
  }

  .corner-handle {
    width: 38px;
    height: 38px;
    margin-left: -19px;
    margin-top: -19px;
  }
}

@media (max-width: 575px) {
  .content-container,
  .topbar {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .surface-card,
  .hero-side-card,
  .kpi-card,
  .history-card,
  .reference-card,
  .sidebar-card {
    padding: 1rem;
    border-radius: 20px;
  }

  .hero-copy h2 {
    max-width: none;
  }
}
