:root {
  --paper: #f3efe2;
  --ink: #1b231f;
  --muted: #596359;
  --line: #cabf9e;
  --surface: #fffdf6;
  --surface-2: #f6f0df;
  --teal: #14454d;
  --teal-bright: #1f7986;
  --teal-soft: #dbe9e6;
  --amber: #b5601c;
  --amber-soft: #f7e6d2;
  --ready: #2c6b45;
  --ready-soft: #e2efe3;
  --danger: #a23a33;
  --danger-soft: #f7e2df;
  --draft: #7c7566;
  --draft-soft: #ece7d9;
  --radius-card: 10px;
  --radius-control: 6px;
  --shadow: 0 18px 45px rgba(23, 33, 36, 0.08);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141813;
    --ink: #ece7d6;
    --muted: #9a9c8c;
    --line: #34372c;
    --surface: #1b1f19;
    --surface-2: #20241c;
    --teal: #7bc4cb;
    --teal-bright: #9ad9de;
    --teal-soft: rgba(123, 196, 203, 0.14);
    --amber: #e2914f;
    --amber-soft: rgba(226, 145, 79, 0.16);
    --ready: #74cf92;
    --ready-soft: rgba(116, 207, 146, 0.16);
    --danger: #e2867d;
    --danger-soft: rgba(226, 134, 125, 0.16);
    --draft: #b8b5a0;
    --draft-soft: rgba(184, 181, 160, 0.14);
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 100% 0%, rgba(20, 69, 77, 0.12), transparent 32rem),
    linear-gradient(180deg, var(--surface-2) 0%, var(--paper) 100%);
  color: var(--ink);
}

@media (prefers-reduced-motion: no-preference) {
  .flow-rail a,
  label.ocr-filled {
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  }
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(100%, 840px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(96px, env(safe-area-inset-bottom));
}

.topbar,
.section-head,
.readiness-panel,
.capture-title-row,
.queue-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.backup-status {
  margin: -4px 0 12px;
  border-left: 3px solid var(--teal);
  background: var(--teal-soft);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.backup-status.warning {
  border-color: var(--amber);
  background: var(--amber-soft);
  color: var(--ink);
}

.topbar {
  align-items: flex-start;
  border-bottom: 1px solid var(--line);
  padding: 2px 2px 14px;
}

.topbar h1,
.section-head h2,
.capture-panel h2,
.readiness-panel h2 {
  margin: 0;
  font-size: clamp(24px, 6vw, 36px);
  font-weight: 800;
  line-height: 1.02;
  letter-spacing: -0.04em;
}

.topbar-copy,
.section-copy {
  max-width: 560px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.status-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

/* Stamp language — reserved for verdicts/status (never plain metadata). */
.status-pill,
.capture-review {
  --stamp: var(--draft);
  --stamp-tint: var(--draft-soft);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 2px solid var(--stamp);
  border-radius: 3px;
  background: var(--stamp-tint);
  color: var(--stamp);
  padding: 5px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  transform: rotate(-1.4deg);
  white-space: nowrap;
}

.status-pill::before,
.capture-review::before {
  content: "";
  width: 5px;
  height: 5px;
  flex: none;
  border-radius: 50%;
  background: currentColor;
}

.status-pill.neutral {
  --stamp: var(--muted);
  --stamp-tint: var(--surface-2);
}

.status-pill.ready,
.capture-review.verified {
  --stamp: var(--ready);
  --stamp-tint: var(--ready-soft);
}

.status-pill.busy,
.capture-review.needs_review {
  --stamp: var(--amber);
  --stamp-tint: var(--amber-soft);
}

.capture-review.rejected {
  --stamp: var(--danger);
  --stamp-tint: var(--danger-soft);
}

.capture-review.draft {
  --stamp: var(--draft);
  --stamp-tint: var(--draft-soft);
}

/* Flat data tags — counts and metadata, deliberately NOT stamp-styled. */
.counter,
.capture-id,
.capture-tags span {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 5px 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Flow rail — wayfinding for the capture sequence (a real sequence: order carries meaning). */
.flow-rail {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.flow-rail a {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px;
  border-radius: 7px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
}

.flow-step-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: none;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-size: 9px;
}

.flow-rail a.is-active {
  background: var(--surface);
  color: var(--teal);
  box-shadow: 0 1px 0 var(--line);
}

.flow-rail a.is-active .flow-step-index {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--surface);
}

.flow-rail a:focus-visible {
  outline: 2px solid var(--teal-bright);
  outline-offset: 2px;
}

.perf-divider {
  height: 0;
  margin: 18px 0;
  border: 0;
  border-top: 3px dotted var(--line);
  opacity: 0.9;
}

.readiness-panel,
.capture-panel,
.queue-panel,
.sync-credential-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: rgba(255, 253, 248, 0.94);
  padding: 14px;
  box-shadow: var(--shadow);
}

@media (prefers-color-scheme: dark) {
  .readiness-panel,
  .capture-panel,
  .queue-panel,
  .sync-credential-panel {
    background: rgba(27, 31, 25, 0.94);
  }
}

.sync-credential-panel {
  padding: 0;
  overflow: clip;
}

.sync-credential-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
}

.sync-credential-panel summary::-webkit-details-marker {
  display: none;
}

.sync-credential-panel summary strong {
  color: var(--ink);
  font-size: 13px;
}

.sync-credential-body {
  border-top: 1px solid var(--line);
  padding: 14px;
}

.sync-credential-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  margin-top: 12px;
}

@media (max-width: 560px) {
  .sync-credential-form {
    grid-template-columns: 1fr;
  }
}

.readiness-panel {
  align-items: center;
  background: linear-gradient(135deg, var(--teal) 0%, #235963 100%);
  color: var(--surface);
}

@media (prefers-color-scheme: dark) {
  .readiness-panel {
    background: linear-gradient(135deg, #1a3a3d 0%, #0f2224 100%);
    color: #eef7f6;
  }
}

.readiness-panel .eyebrow,
.readiness-panel .section-copy {
  color: rgba(255, 255, 255, 0.72);
}

.readiness-panel h2 {
  font-size: 19px;
  letter-spacing: -0.02em;
}

.readiness-panel.is-ready {
  flex-direction: row;
  padding: 9px 12px;
}

.readiness-panel.is-ready .eyebrow {
  display: none;
}

.readiness-panel.is-ready h2 {
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.readiness-panel.is-ready .section-copy {
  display: none;
}

.capture-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

label.ocr-filled {
  padding-left: 9px;
  border-left: 3px solid var(--teal-bright);
  background: linear-gradient(to right, var(--teal-soft), transparent 55%);
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--teal-bright);
  box-shadow: 0 0 0 3px rgba(31, 121, 134, 0.2);
}

.choice-grid,
.tag-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  border: 0;
  padding: 0;
}

.choice-grid legend,
.tag-strip legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.choice-grid label,
.tag-strip label {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  padding: 9px;
  color: var(--ink);
  text-align: center;
}

.choice-grid label:has(input:checked),
.tag-strip label:has(input:checked) {
  border-color: var(--teal);
  background: var(--teal-soft);
  color: var(--teal);
}

.choice-grid input,
.tag-strip input {
  min-height: 0;
  width: 17px;
  height: 17px;
  margin: 0;
  padding: 0;
}

.flow-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-margin-top: 76px;
}

.photo-drop {
  min-height: 190px;
  justify-content: center;
  border: 2px dashed var(--amber);
  border-radius: var(--radius-card);
  background:
    linear-gradient(135deg, rgba(251, 236, 221, 0.92), rgba(255, 253, 248, 0.96)),
    var(--amber-soft);
  color: var(--ink);
  padding: 18px;
}

@media (prefers-color-scheme: dark) {
  .photo-drop {
    background:
      linear-gradient(135deg, rgba(226, 145, 79, 0.14), rgba(27, 31, 25, 0.9)),
      var(--amber-soft);
  }
}

.photo-drop input {
  border: 1px solid rgba(184, 99, 37, 0.35);
  min-height: 48px;
  background: var(--surface);
}

.photo-drop select {
  max-width: 260px;
}

.photo-label-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.photo-icon {
  width: 30px;
  height: 30px;
  flex: none;
  color: var(--amber);
}

.photo-label {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.photo-help {
  max-width: 480px;
  color: var(--amber);
  opacity: 0.82;
  font-size: 12px;
  line-height: 1.45;
}

.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 9px;
}

.photo-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  padding: 6px;
}

.photo-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 4px;
  background: var(--teal-soft);
}

.photo-card span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  text-transform: uppercase;
}

.feedback {
  border-left: 3px solid var(--teal);
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  background: var(--teal-soft);
  padding: 10px 12px;
  color: var(--teal);
  font-size: 12px;
  line-height: 1.4;
}

.feedback.error {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.feedback.warning,
.capture-follow-up {
  border-left: 3px solid var(--orange, #b7612b);
  background: rgba(183, 97, 43, 0.12);
  color: var(--ink);
}

.dossier-status {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.attachment-icon {
  display: grid;
  min-height: 72px;
  place-items: center;
  background: var(--surface-2);
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-weight: 800;
}

.capture-follow-up {
  margin: 10px 0 0;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
}

.supplier-link,
.ocr-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface-2);
  padding: 12px;
  scroll-margin-top: 76px;
}

.supplier-link h3,
.ocr-fields h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.compact-head {
  align-items: flex-start;
}

.supplier-matches {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.supplier-match,
.linked-supplier {
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  padding: 10px;
}

.supplier-match {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.supplier-match strong,
.linked-supplier strong {
  display: block;
  font-size: 13px;
}

.supplier-match span,
.linked-supplier p {
  display: block;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.linked-supplier {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.grid-two,
.grid-three,
.field-tools {
  display: grid;
  gap: 10px;
}

.grid-two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-three {
  grid-template-columns: 1fr 1fr 130px;
}

.commercial-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 12px;
}

.commercial-block legend {
  padding: 0 6px;
  color: var(--ink);
  font-weight: 800;
}

.field-hint {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.field-tools {
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
}

.tag-strip {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 10px;
}

.sinais-block {
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-margin-top: 76px;
}

details {
  color: var(--muted);
  font-size: 12px;
}

summary {
  cursor: pointer;
  font-weight: 800;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.sticky-actions {
  position: sticky;
  z-index: 10;
  bottom: max(8px, env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: rgba(255, 253, 248, 0.94);
  padding: 9px;
  box-shadow: 0 12px 30px rgba(23, 33, 36, 0.16);
  backdrop-filter: blur(12px);
}

@media (prefers-color-scheme: dark) {
  .sticky-actions {
    background: rgba(27, 31, 25, 0.94);
  }
}

button {
  min-height: 48px;
  border: 1px solid var(--teal);
  border-radius: var(--radius-control);
  padding: 11px 14px;
  background: transparent;
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

button.primary {
  background: var(--teal);
  color: var(--surface);
}

button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

button.ghost {
  border-color: transparent;
  color: var(--muted);
}

button.compact {
  min-height: 38px;
  padding: 8px 10px;
  font-size: 9px;
}

.queue-summary {
  flex-wrap: wrap;
  justify-content: flex-start;
  margin: 12px 0;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  text-transform: uppercase;
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.queue-day-divider {
  margin: 16px 0 2px;
  padding-bottom: 5px;
  border-bottom: 1px dashed var(--line);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.queue-day-divider:first-child {
  margin-top: 0;
}

.capture-item {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  padding: 10px;
}

.thumb {
  width: 104px;
  height: 104px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--teal-soft);
}

.capture-copy {
  min-width: 0;
}

.capture-title-row {
  align-items: flex-start;
}

.capture-title {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
}

.capture-id-row,
.capture-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  line-height: 1.4;
}

.capture-note {
  margin: 7px 0 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
}

.capture-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.capture-tags span {
  padding: 4px 6px;
  background: var(--surface-2);
  color: var(--muted);
}

.edit-capture {
  margin-top: 9px;
}

@media (max-width: 680px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }

  .app-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  .topbar {
    flex-direction: column;
  }

  .status-stack {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .readiness-panel,
  .section-head {
    align-items: flex-start;
  }

  .readiness-panel {
    flex-direction: column;
  }

  .readiness-panel button,
  .queue-panel .section-head button {
    width: 100%;
  }

  .grid-two,
  .grid-three,
  .field-tools {
    grid-template-columns: 1fr;
  }

  .choice-grid,
  .tag-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-actions {
    display: grid;
    grid-template-columns: 1fr 1.4fr;
  }

  .sticky-actions {
    position: static;
    bottom: auto;
    grid-template-columns: 1fr 1fr;
    box-shadow: none;
    backdrop-filter: none;
  }

  .sticky-actions .primary {
    grid-column: 1 / -1;
  }

  .capture-item {
    grid-template-columns: 82px minmax(0, 1fr);
  }

  .thumb {
    width: 82px;
    height: 96px;
  }

  .flow-rail a {
    gap: 4px;
    padding: 6px 3px;
    font-size: 9px;
  }
}

@media (max-width: 410px) {
  .choice-grid,
  .tag-strip,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .capture-title-row {
    flex-direction: column;
  }
}
