:root {
  --navy: #172e63;
  --green: #00c354;
  --ink: #152033;
  --muted: #65738a;
  --line: #d9e0ea;
  --paper: #ffffff;
  --bg: #f6f8fb;
  --danger: #b42318;
  --warn: #a15c07;
  --soft-green: #e7f8ee;
  --soft-warn: #fff6df;
  --soft-danger: #fff1ef;
  --green-dark: #087d3d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}

.app-shell {
  min-height: 100dvh;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
}

.capture-panel {
  width: min(760px, 100%);
  display: grid;
  gap: 14px;
}

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

.eyebrow {
  margin: 0 0 3px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  color: var(--navy);
  font-size: 28px;
  line-height: 1.05;
}

.status-pill {
  min-width: 78px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-pill.bad {
  color: var(--danger);
}

.camera-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 260px;
  background: #0b1220;
  border: 1px solid var(--line);
  border-radius: 8px;
}

video,
#preview {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.camera-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: #dbe7ff;
}

.camera-empty strong {
  font-size: 18px;
}

.camera-empty span {
  max-width: 360px;
  color: #aab8d0;
  line-height: 1.35;
}

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

label {
  display: grid;
  gap: 6px;
}

label span,
.label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: var(--paper);
  outline: none;
}

input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(23, 46, 99, 0.12);
}

.gps-panel {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr 0.8fr 1fr;
  gap: 10px;
}

.gps-panel > div {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--paper);
}

.gps-panel strong {
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--navy);
  font-size: 14px;
}

.gps-panel > div.good {
  border-color: rgba(0, 195, 84, 0.42);
  background: var(--soft-green);
}

.gps-panel > div.warn {
  border-color: rgba(161, 92, 7, 0.38);
  background: var(--soft-warn);
}

.gps-panel > div.bad {
  border-color: rgba(180, 35, 24, 0.35);
  background: var(--soft-danger);
}

.runtime-panel {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(161, 92, 7, 0.38);
  border-radius: 8px;
  padding: 12px;
  background: var(--soft-warn);
}

.runtime-panel strong {
  color: var(--warn);
}

.runtime-panel p {
  margin: 0;
  color: var(--ink);
  line-height: 1.35;
}

.runtime-panel button {
  width: fit-content;
  min-height: 40px;
  padding-inline: 16px;
  border-color: var(--warn);
  background: var(--warn);
}

.gps-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(0, 195, 84, 0.42);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--soft-green);
}

.gps-control.needs-permission {
  border-color: rgba(180, 35, 24, 0.35);
  background: var(--soft-danger);
}

.switch-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.switch-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-control strong,
.switch-control small {
  display: block;
}

.switch-control strong {
  color: var(--navy);
  line-height: 1.1;
}

.switch-control small {
  color: var(--muted);
  line-height: 1.25;
  margin-top: 3px;
}

.switch-ui {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 48px;
  border-radius: 999px;
  background: #c8d1df;
  transition: background 0.18s ease;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(21, 32, 51, 0.24);
  transition: transform 0.18s ease;
}

.switch-control input:checked + .switch-ui {
  background: var(--green);
}

.switch-control input:checked + .switch-ui::after {
  transform: translateX(20px);
}

.gps-control.needs-permission .switch-control input:checked + .switch-ui {
  background: var(--danger);
}

.secondary-action {
  min-height: 40px;
  flex: 0 0 auto;
  border-color: var(--danger);
  background: var(--danger);
  color: white;
}

.permission-panel {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(180, 35, 24, 0.35);
  border-radius: 8px;
  padding: 12px;
  background: var(--soft-danger);
}

.permission-panel strong {
  color: var(--danger);
}

.permission-panel p {
  margin: 0;
  color: var(--ink);
  line-height: 1.35;
}

.permission-panel button {
  width: fit-content;
  min-height: 40px;
  padding-inline: 16px;
  background: var(--danger);
  border-color: var(--danger);
}

.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 10px;
}

button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--navy);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--navy);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

.btn-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.btn-icon svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-icon svg circle {
  fill: none;
}

button:disabled {
  cursor: not-allowed;
  border-color: var(--line);
  background: #d7deea;
  color: #7a8698;
}

button.primary-good:not(:disabled) {
  border-color: var(--green);
  background: var(--green);
  color: #04220f;
}

button.whatsapp-action:not(:disabled) {
  border-color: #1fa855;
  background: #1fa855;
  color: #ffffff;
}

.message {
  margin: 0;
  min-height: 24px;
  color: var(--muted);
  line-height: 1.4;
}

@media (max-width: 720px) {
  .app-shell {
    align-items: start;
  }

  h1 {
    font-size: 23px;
  }

  .field-grid,
  .gps-panel,
  .gps-control,
  .actions {
    grid-template-columns: 1fr;
  }

  .gps-control {
    align-items: stretch;
    flex-direction: column;
  }

  .secondary-action {
    width: 100%;
  }

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