:root {
  --bg: #10140f;
  --bg-elev: #1a2118;
  --bg-input: #0c100b;
  --line: #2c3828;
  --text: #f4efe4;
  --muted: #9aa892;
  --copper: #d9923a;
  --copper-deep: #b06e1f;
  --signal: #3cba7a;
  --signal-dim: rgba(60, 186, 122, 0.16);
  --danger: #e25c4a;
  --danger-dim: rgba(226, 92, 74, 0.14);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --tap: 48px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(217, 146, 58, 0.12), transparent 50%),
    radial-gradient(900px 480px at 100% 0%, rgba(60, 186, 122, 0.08), transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

button,
input,
textarea {
  font: inherit;
}

.app {
  max-width: 760px;
  margin: 0 auto;
}

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

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(160deg, var(--copper), var(--copper-deep));
  display: grid;
  place-items: center;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0;
  box-shadow: var(--shadow);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.icon-btn,
.ghost-btn,
.primary-btn,
.danger-btn {
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 14px;
  padding: 0 14px;
  cursor: pointer;
}

.icon-btn {
  width: var(--tap);
  padding: 0;
  font-size: 1.1rem;
}

.primary-btn {
  background: linear-gradient(180deg, #e3a24a, var(--copper-deep));
  border-color: transparent;
  color: #1a1206;
  font-weight: 650;
}

.ghost-btn {
  color: var(--text);
}

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

.danger-btn {
  background: var(--danger-dim);
  border-color: rgba(226, 92, 74, 0.35);
  color: #ffd2cb;
}

.stack {
  display: grid;
  gap: 16px;
}

.card {
  background: color-mix(in srgb, var(--bg-elev) 92%, black);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.notes-head {
  margin-bottom: 10px;
}

.notes-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.parse-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.parse-hint strong {
  color: var(--text);
  font-weight: 550;
}

.status {
  min-height: 1.4em;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status.ok {
  color: var(--signal);
}

.status.err {
  color: #ffb4aa;
}

.transcript {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  line-height: 1.45;
}

.parse-row {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.parse-btn {
  min-height: var(--tap);
  padding: 0 14px;
  font-size: 0.95rem;
}

.aux-actions,
.row-actions,
.field-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.aux-actions .ghost-btn,
.aux-actions .primary-btn {
  flex: 1 1 6.5rem;
}

.save-actions .primary-btn {
  flex: 1 1 100%;
  min-height: 48px;
}

.save-choices {
  display: grid;
  gap: 8px;
}

.save-choices .ghost-btn,
.save-choices .primary-btn {
  width: 100%;
  min-height: 48px;
}

.places-kicker {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.88rem;
}

.contact-fields {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

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

@media (min-width: 560px) {
  .grid-city {
    grid-template-columns: 1.4fr 0.7fr 0.8fr;
  }
}

@keyframes field-flash {
  0% {
    border-color: rgba(60, 186, 122, 0.85);
    background: color-mix(in srgb, var(--bg-input) 72%, #3cba7a);
    box-shadow: 0 0 0 3px var(--signal-dim);
  }
  100% {
    border-color: var(--line);
    background: var(--bg-input);
    box-shadow: none;
  }
}

@keyframes card-flash {
  0%,
  35% {
    border-color: rgba(60, 186, 122, 0.7);
    box-shadow: 0 0 0 3px var(--signal-dim), var(--shadow);
  }
  100% {
    border-color: var(--line);
    box-shadow: var(--shadow);
  }
}

.field input.flash,
.field textarea.flash {
  animation: field-flash 0.85s ease;
}

.chip.flash {
  animation: field-flash 0.85s ease;
}

.notes-card.parse-flash,
.places-card.parse-flash,
.contact-card.parse-flash {
  animation: card-flash 0.85s ease;
}

.fields {
  display: grid;
  gap: 10px;
}

.field label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

.field input,
.field textarea {
  width: 100%;
  min-height: var(--tap);
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

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

.grid-2 {
  display: grid;
  gap: 10px;
}

@media (min-width: 560px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 40px;
  cursor: pointer;
}

.chip.on {
  background: var(--signal-dim);
  border-color: rgba(60, 186, 122, 0.5);
  color: #d9ffe9;
}

.history {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.history-item {
  display: grid;
  gap: 4px;
  text-align: left;
  width: 100%;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
}

.history-item strong {
  font-size: 0.98rem;
}

.history-item span {
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--mono);
}

.empty {
  color: var(--muted);
  padding: 18px 8px;
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 6, 0.72);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}

.overlay.open {
  display: flex;
}

.sheet {
  width: min(560px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.sheet h2 {
  margin: 0 0 8px;
}

.sheet p {
  margin: 0 0 14px;
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
}

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

.auth-who {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.auth-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--line);
}

.auth-pill.approved {
  color: #d9ffe9;
  border-color: rgba(60, 186, 122, 0.5);
  background: var(--signal-dim);
}

.auth-pill.pending {
  color: #f0c27a;
  border-color: rgba(217, 146, 58, 0.45);
}

.auth-pill.revoked {
  color: #ffd2cb;
  border-color: rgba(226, 92, 74, 0.45);
  background: var(--danger-dim);
}

.fields,
.grid-2,
.field {
  overflow: visible;
}

.suggest-wrap {
  position: relative;
  z-index: 4;
}

.suggest-wrap.is-open {
  z-index: 20;
}

.suggest-list {
  display: none;
  margin-top: 6px;
  background: #1a2118;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.suggest-list.is-open {
  display: grid;
}

.suggest-item {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  cursor: pointer;
}

.suggest-item:first-child {
  border-top: 0;
}

.suggest-item span {
  color: var(--muted);
  font-size: 0.8rem;
}

.suggest-item:hover {
  background: #24301f;
}

.suggest-item.suggest-msg {
  color: var(--muted);
  cursor: default;
}

.suggest-item.suggest-msg.err {
  color: #ffd2cb;
}

.admin-card {
  margin-top: 16px;
}

.admin-user {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.admin-user:first-child {
  border-top: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(120%);
  background: #24301f;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 999px;
  z-index: 30;
  transition: transform 0.25s ease;
  max-width: calc(100% - 24px);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.capture-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  flex-direction: column;
  background: #050705;
}

.capture-overlay.open {
  display: flex;
}

.capture-stage {
  position: relative;
  flex: 1;
  min-height: 220px;
  overflow: hidden;
  background: #000;
}

.capture-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.capture-overlay:not(.has-camera) video {
  visibility: hidden;
}

.capture-fallback {
  display: none;
  position: absolute;
  inset: 0;
  place-content: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
  background: #0b0f0a;
}

.capture-overlay:not(.has-camera) .capture-fallback {
  display: grid;
}

.capture-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.capture-frame {
  position: absolute;
  left: 50%;
  top: 44%;
  width: min(88vw, 540px);
  aspect-ratio: 1.75 / 1;
  transform: translate(-50%, -50%);
  border-radius: 16px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.55);
  outline: 2px solid rgba(240, 194, 122, 0.9);
}

.capture-hint {
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(44% + min(26vw, 160px));
  margin: 0;
  text-align: center;
  color: #f4efe4;
  font-size: 0.95rem;
  text-shadow: 0 1px 8px #000;
}

.capture-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  background: #10140f;
  border-top: 1px solid var(--line);
}

.capture-bar h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.capture-bar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

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

.capture-shot {
  min-width: 148px;
  min-height: 56px;
}

@media (max-width: 640px) {
  .capture-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .capture-actions {
    justify-content: stretch;
  }

  .capture-actions .primary-btn,
  .capture-actions .ghost-btn {
    flex: 1;
  }
}
