:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0b1020;
  color: #f8fafc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #101827 0%, #0b1020 55%, #080c16 100%);
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.browser-context {
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.browser-context-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.browser-identity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.google-mark { flex-shrink: 0; }
.provider-avatar { flex-shrink: 0; border-radius: 50%; object-fit: cover; }

.browser-logout { display: inline-flex; margin: 0; }

.browser-nav-link {
  appearance: none;
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: transparent;
  font: inherit;
  font-weight: 400;
  line-height: 1.5;
  color: #93c5fd;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.browser-nav-link:hover,
.browser-nav-link:focus-visible { color: #dbeafe; }

.browser-nav-link:focus-visible {
  outline: 2px solid #60a5fa;
  outline-offset: 4px;
}

@font-face {
  font-family: "Google Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/google-sans-button.woff2") format("woff2");
}

.page.auth-page { max-width: 480px; padding-top: clamp(24px, 8vh, 72px); }
.auth-card h1 { margin: 0 0 20px; }
.auth-card .login-denial { color: #f8fafc; }
.provider-options { display: grid; gap: 12px; width: 100%; max-width: 394px; }
.provider-options form { margin: 0; }
.provider-options p { margin: 0; color: #aebbd0; line-height: 1.55; }

.provider-button,
.auth-action {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  gap: 10px;
  border: 1px solid #747775;
  border-radius: 4px;
  background: #fff;
  color: #1f1f1f;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  text-align: left;
}
.provider-button { display: grid; grid-template-columns: 21px minmax(0, 1fr); }
.provider-button--google { font-family: "Google Sans", Arial, sans-serif; }
.provider-button--microsoft { font-family: "Segoe UI", system-ui, sans-serif; font-weight: 600; }
.provider-button img { justify-self: center; object-fit: contain; }
.provider-button span { min-width: 0; }
.provider-button:enabled:not([aria-disabled="true"]),
.auth-card button:enabled:not([aria-disabled="true"]),
.auth-card a[href]:not([aria-disabled="true"]) { cursor: pointer; }
.provider-button:enabled:not([aria-disabled="true"]):hover,
.auth-card button:enabled:not([aria-disabled="true"]):hover {
  background: #f2f2f2;
  border-color: #1f1f1f;
  box-shadow: 0 2px 6px #0003;
}
.provider-button:enabled:not([aria-disabled="true"]):focus-visible,
.auth-card button:enabled:not([aria-disabled="true"]):focus-visible,
.auth-card a[href]:not([aria-disabled="true"]):focus-visible {
  outline: 3px solid #60a5fa;
  outline-offset: 4px;
}
.auth-card a[href]:hover { color: #dbeafe; }
@media (max-width: 360px) {
  .scan-card.auth-card { padding: 24px 16px; }
}

.page {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 24px 18px 48px;
}

.topbar,
.section-heading,
.photo-slot-heading,
.crop-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar { margin-bottom: 28px; }

.eyebrow {
  margin: 0 0 4px;
  color: #94a3b8;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 8vw, 3rem);
  letter-spacing: -0.04em;
}

h2 { margin-bottom: 10px; }
h3 { margin-bottom: 0; }

.badge {
  border: 1px solid #334155;
  border-radius: 999px;
  padding: 7px 10px;
  color: #cbd5e1;
  font-size: 0.78rem;
}

.scan-card,
.library {
  border: 1px solid #253047;
  border-radius: 24px;
  background: rgba(15, 23, 42, 0.82);
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.24);
}

.scan-card {
  padding: 24px;
  margin-bottom: 20px;
}

.scan-card > p {
  color: #aebbd0;
  line-height: 1.55;
}

.scan-icon {
  margin-bottom: 12px;
  font-size: 2.2rem;
}

#scan-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

#image1-input,
#image2-input {
  display: none;
}

.photo-slot {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid #253047;
  border-radius: 18px;
  background: #0b1220;
}

.photo-slot[hidden] { display: none; }

.photo-slot-heading span,
.crop-card-heading span {
  color: #64748b;
  font-size: 0.76rem;
}

.scan-button,
#upload-button,
.primary-action,
.secondary-button,
.save-final-button {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  font-weight: 700;
  cursor: pointer;
}

.scan-button {
  border: 0;
  background: #f8fafc;
  color: #0f172a;
}

.scan-button.secondary {
  border: 1px solid #475569;
  background: #e2e8f0;
}

#upload-button,
.primary-action {
  border: 0;
  background: #2563eb;
  color: #fff;
}

.save-final-button {
  border: 0;
  background: #16a34a;
  color: #fff;
}

.secondary-button {
  border: 1px dashed #475569;
  background: transparent;
  color: #cbd5e1;
}

.text-button {
  width: max-content;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: #94a3b8;
  font-size: 0.82rem;
  cursor: pointer;
}

#upload-button:disabled,
.primary-action:disabled,
.save-final-button:disabled {
  cursor: default;
  opacity: 0.45;
}

.preview {
  display: none;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  border: 1px solid #253047;
  border-radius: 14px;
  background: #020617;
}

.preview.visible { display: block; }

.file-name {
  margin: 0;
  color: #94a3b8;
  font-size: 0.82rem;
  word-break: break-all;
}

.status {
  display: none;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.4;
}

.status:not(:empty) { display: block; }
.status.pending { background: #172554; color: #bfdbfe; }
.status.success { background: #052e2b; color: #a7f3d0; }
.status.error { background: #450a0a; color: #fecaca; }

.scan-result {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid #253047;
}

.scan-result[hidden] { display: none; }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.result-item,
.crop-section,
.medium-correction {
  padding: 14px;
  border-radius: 16px;
  background: #111827;
}

.result-item span,
.field-label {
  display: block;
  margin-bottom: 7px;
  color: #94a3b8;
  font-size: 0.76rem;
}

.result-item strong {
  font-size: 0.96rem;
  word-break: break-word;
}

.crop-section,
.medium-correction {
  margin-bottom: 14px;
}

.section-heading.compact { align-items: flex-start; }

.section-heading.compact span {
  max-width: 52%;
  text-align: right;
  color: #64748b;
  font-size: 0.72rem;
  line-height: 1.35;
}

.crop-help {
  margin: 9px 0 14px;
  color: #94a3b8;
  font-size: 0.84rem;
  line-height: 1.45;
}

.crop-results {
  display: grid;
  gap: 16px;
  margin-bottom: 14px;
}

.crop-card {
  padding: 12px;
  border: 1px solid #253047;
  border-radius: 14px;
  background: #0b1220;
}

.crop-card-heading {
  align-items: baseline;
  margin-bottom: 10px;
}

.crop-card-heading span {
  max-width: 60%;
  text-align: right;
}

.crop-found { color: #86efac !important; }
.crop-missing { color: #fbbf24 !important; }

.selected-preview-wrap,
.crop-editor-wrap {
  margin-top: 8px;
}

.selected-preview-wrap[hidden],
.crop-editor-wrap[hidden],
.crop-card-actions[hidden] {
  display: none;
}

.selected-preview-label {
  margin-bottom: 8px;
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 650;
}

.selected-preview {
  display: block;
  width: 100%;
  max-height: 560px;
  object-fit: contain;
  border: 1px solid #253047;
  border-radius: 12px;
  background: #020617;
}

.editor-help {
  margin: 0 0 10px;
  color: #bfdbfe;
  font-size: 0.82rem;
  line-height: 1.4;
}

.crop-editor {
  position: relative;
  width: 100%;
  overflow: visible;
  border-radius: 12px;
  background: #020617;
  touch-action: none;
}

.crop-editor img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

.crop-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.crop-overlay polygon {
  fill: rgba(37, 99, 235, 0.14);
  stroke: #60a5fa;
  stroke-width: 0.75;
  vector-effect: non-scaling-stroke;
}

.crop-handle {
  position: absolute;
  z-index: 3;
  width: 32px;
  height: 32px;
  padding: 0;
  transform: translate(-50%, -50%);
  border: 3px solid #dbeafe;
  border-radius: 50%;
  background: #2563eb;
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.5);
  cursor: grab;
  touch-action: none;
}

.crop-handle:active { cursor: grabbing; }

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

.small-action {
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #334155;
  border-radius: 12px;
  background: transparent;
  color: #dbeafe;
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
}

.reports-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 14px;
  text-decoration: none;
}

.finalize-section {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #253047;
}

.scan-box-context { overflow-wrap: anywhere; }
#scan-box-recovery { min-inline-size: 0; }
#scan-box-select { max-inline-size: 100%; }

.finalize-help {
  margin: 9px 2px 0;
  color: #94a3b8;
  font-size: 0.78rem;
  line-height: 1.45;
}

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

.medium-buttons button {
  min-height: 44px;
  border: 1px solid #334155;
  border-radius: 12px;
  background: #0b1220;
  color: #e2e8f0;
  font-weight: 650;
  cursor: pointer;
}

.medium-buttons button.selected {
  border-color: #60a5fa;
  background: #172554;
  color: #dbeafe;
}

.save-status {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: #94a3b8;
  font-size: 0.8rem;
  line-height: 1.4;
}

.success-text { color: #a7f3d0; }
.error-text { color: #fecaca; }
.pending-text { color: #bfdbfe; }

details {
  border: 1px solid #253047;
  border-radius: 14px;
  padding: 12px 14px;
  background: #0b1220;
}

summary {
  cursor: pointer;
  color: #cbd5e1;
  font-weight: 600;
}

.ocr-help {
  margin: 10px 0 8px;
  color: #7f8da3;
  font-size: 0.78rem;
  line-height: 1.4;
}

.ocr-result {
  max-height: 290px;
  overflow-y: auto;
  border-top: 1px solid #1e293b;
}

.ocr-line {
  padding: 9px 0;
  border-bottom: 1px solid #172033;
  color: #e2e8f0;
  font-size: 0.95rem;
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.ocr-line:last-child { border-bottom: 0; }

.ocr-empty {
  padding: 12px 0 4px;
  color: #94a3b8;
  font-size: 0.9rem;
}

.library { padding: 20px; }

.section-heading > span {
  color: #94a3b8;
  font-size: 0.9rem;
}

.movie-list {
  display: grid;
  gap: 10px;
}

.movie-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 15px;
  border-radius: 16px;
  background: #111827;
}

.movie-card small {
  display: block;
  margin-top: 4px;
  color: #94a3b8;
}

.movie-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  color: #cbd5e1;
  font-size: 0.86rem;
}

.empty-state {
  padding: 34px 12px;
  text-align: center;
  color: #cbd5e1;
}

.empty-state p { margin-bottom: 6px; }
.empty-state small { color: #64748b; }

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

  .section-heading.compact,
  .crop-card-heading {
    display: block;
  }

  .section-heading.compact span,
  .crop-card-heading span {
    display: block;
    max-width: none;
    margin-top: 4px;
    text-align: left;
  }
}

@media (min-width: 640px) {
  .page { padding-top: 42px; }
  .scan-card { padding: 30px; }
  .provider-options { max-width: 382px; }
  .medium-buttons { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .crop-card-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
