:root {
  color-scheme: light;
  --ink: #10201f;
  --muted: #667270;
  --line: #d7dfdc;
  --surface: #ffffff;
  --page: #f4f7f5;
  --primary: #143d3a;
  --primary-strong: #0d2f2c;
  --accent: #c46a35;
  --accent-soft: #f3dfd2;
  --teal-soft: #dcecea;
  --shadow: 0 16px 44px rgba(18, 44, 41, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-height: 100%;
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(196, 106, 53, 0.15), transparent 30rem),
    linear-gradient(180deg, #eef5f2 0%, var(--page) 42%, #eef1ed 100%);
}

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

button {
  cursor: pointer;
}

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

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.pin-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.pin-card {
  width: min(420px, 100%);
  border: 1px solid rgba(20, 61, 58, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 22px;
  display: grid;
  gap: 12px;
}

.pin-card h1 {
  margin-bottom: 8px;
}

.pin-card label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.pin-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 12px;
  color: var(--ink);
  background: #fff;
  font-size: 1.15rem;
}

.pin-input {
  -webkit-text-security: disc;
  text-security: disc;
}

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

.topbar-actions,
.section-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(2rem, 7vw, 4.2rem);
}

h2 {
  font-size: 1.15rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.scanner-panel,
.history-panel {
  border: 1px solid rgba(20, 61, 58, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.muted {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.counter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 34px;
  border-radius: 999px;
  background: var(--teal-soft);
  color: var(--primary);
  font-weight: 800;
}

.camera-frame {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101a19;
}

.camera-frame.can-capture {
  cursor: pointer;
}

.camera-frame.can-capture:active {
  border-color: var(--accent);
}

.camera-frame video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.72);
  background: linear-gradient(135deg, #163d3b, #28322f);
}

.camera-placeholder svg {
  width: 72px;
  height: 72px;
  fill: currentColor;
}

.action-grid,
.scan-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 12px;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.file-picker,
.icon-btn {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-weight: 800;
  text-decoration: none;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.primary-btn:active {
  background: var(--primary-strong);
}

.secondary-btn {
  background: var(--accent-soft);
  color: #733c1d;
}

.ghost-btn {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--line);
}

.icon-btn {
  width: 46px;
  min-width: 46px;
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--line);
}

.compact {
  min-height: 38px;
  padding: 0 12px;
}

.wide {
  width: 100%;
}

.primary-btn svg,
.secondary-btn svg,
.ghost-btn svg,
.file-picker svg,
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  flex: 0 0 auto;
}

.file-picker {
  width: 100%;
  margin-top: 10px;
  color: var(--primary);
  border: 1px dashed rgba(20, 61, 58, 0.42);
  background: rgba(220, 236, 234, 0.55);
}

.file-picker input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

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

.thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #e9efec;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: rgba(16, 32, 31, 0.82);
  color: #fff;
  font-weight: 900;
}

.status {
  min-height: 24px;
  margin: 12px 0 0;
  color: var(--primary);
  font-weight: 700;
}

.status.error {
  color: #a53026;
}

.modal-open {
  overflow: hidden;
}

.editor-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 32, 31, 0.56);
  backdrop-filter: blur(5px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: min(92vh, 900px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 28px 80px rgba(16, 32, 31, 0.28);
}

.modal-header,
.modal-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
}

.modal-header {
  border-bottom: 1px solid var(--line);
}

.modal-footer {
  align-items: center;
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  background: #f8fbf9;
}

.modal-footer .primary-btn,
.modal-footer .ghost-btn {
  min-width: 176px;
  padding: 0 14px;
}

.modal-body {
  overflow: auto;
  padding: 16px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label,
.contacts-editor > label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea,
.contact-row input,
.contact-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.contacts-editor {
  display: grid;
  gap: 10px;
}

.saved-photos {
  display: grid;
  gap: 10px;
}

.saved-photos > label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

.saved-photo {
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e9efec;
}

.saved-photo img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.contact-row {
  display: grid;
  grid-template-columns: minmax(94px, 0.7fr) 1fr 1.3fr 40px;
  gap: 8px;
  align-items: center;
}

.contact-row button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #a53026;
  font-weight: 900;
}

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

.contact-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: stretch;
  overflow: hidden;
}

.contact-open,
.contact-delete {
  border: 0;
  background: transparent;
}

.contact-open {
  min-width: 0;
  text-align: left;
  padding: 13px;
  display: grid;
  gap: 8px;
}

.contact-card strong {
  font-size: 1rem;
}

.contact-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.contact-delete {
  display: grid;
  place-items: center;
  color: #a53026;
  border-left: 1px solid var(--line);
}

.contact-delete svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.contact-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--teal-soft);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

.hidden {
  display: none !important;
}

@media (min-width: 680px) {
  .action-grid,
  .scan-actions,
  .field-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
    align-items: start;
  }
}

@media (max-width: 460px) {
  .editor-panel {
    align-items: end;
    padding: 0;
  }

  .modal-card {
    width: 100%;
    max-height: 94vh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 8px 8px 0 0;
  }

  .modal-header,
  .modal-footer,
  .modal-body {
    padding: 14px;
  }

  .modal-footer {
    display: grid;
    grid-template-columns: 1fr;
  }

  .modal-footer .primary-btn,
  .modal-footer .ghost-btn {
    width: 100%;
    min-width: 0;
  }

  .contact-row {
    grid-template-columns: 1fr 40px;
  }

  .contact-row select,
  .contact-row input {
    grid-column: span 2;
  }

  .contact-row button {
    grid-column: 2;
  }
}
