:root {
  --bg-primary: #0a0a0c;
  --bg-surface: #16161a;
  --bg-elevated: #202027;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --text-main: #f3f4f6;
  --text-muted: #a2a8b3;
  --border: #2d3139;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --z-header: 1200;
  --z-footer: 1200;
  --z-scrim: 2100;
  --z-menu: 2200;
  --z-privacy: 2300;
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg-primary);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-primary);
  color: var(--text-main);
  padding-bottom: calc(58px + env(safe-area-inset-bottom));
}

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

button,
a.button {
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(16px + env(safe-area-inset-top)) 18px 14px;
  background: rgba(10, 10, 12, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.12rem;
}

p {
  color: var(--text-muted);
  line-height: 1.45;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-main);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
}

.icon-button.small {
  width: 36px;
  height: 36px;
  flex-direction: row;
  font-weight: 700;
}

.app-main {
  width: min(980px, 100%);
  margin: 0 auto;
}

.capture-section,
.map-section,
.list-section,
.export-fallback {
  padding: 22px 18px;
  border-bottom: 1px solid var(--border);
}

.capture-section {
  min-height: 46vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
}

.capture-copy p {
  margin-bottom: 0;
}

.capture-controls,
.action-row,
.download-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.heading-control {
  display: grid;
  gap: 6px;
  min-width: min(220px, 100%);
}

.sensor-status {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.sensor-status.active {
  color: var(--success);
}

.sensor-status.pending {
  color: var(--warning);
}

.sensor-status.unavailable {
  color: #fecaca;
}

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

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

.field span {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.field.compact {
  min-width: 150px;
}

select,
input[type="file"],
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-main);
  padding: 12px;
}

textarea {
  resize: vertical;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  width: 50px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-surface);
  position: relative;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform 160ms ease, background 160ms ease;
}

.switch input:checked + span {
  border-color: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(22px);
  background: var(--accent);
}

.button,
a.button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  text-decoration: none;
  cursor: pointer;
}

.button.primary,
a.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.button.danger {
  border-color: rgba(239, 68, 68, 0.75);
  color: #fecaca;
}

.small-button {
  min-height: 38px;
}

.capture-button {
  min-height: 68px;
  flex: 1 1 240px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  font-size: 1.12rem;
  cursor: pointer;
  box-shadow: 0 14px 30px rgba(59, 130, 246, 0.25);
}

.capture-button:disabled,
.button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.stats-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.stats-band div {
  padding: 16px 10px;
  text-align: center;
  border-right: 1px solid var(--border);
}

.stats-band div:last-child {
  border-right: 0;
}

.stats-band span {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
}

.stats-band small {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

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

.section-heading p {
  margin-bottom: 0;
}

.map-container {
  height: 45vh;
  min-height: 290px;
  max-height: 520px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #050506;
}

.map-note {
  margin: 10px 0 0;
  font-size: 0.88rem;
}

.leaflet-container {
  background: #050506;
}

.poi-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.poi-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-surface);
  padding: 12px;
}

.poi-item header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.poi-item h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.poi-item p {
  margin-bottom: 8px;
}

.poi-item code {
  color: #bfdbfe;
  word-break: break-word;
}

.poi-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.83rem;
}

.delete-poi {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 10px;
  color: #fecaca;
}

.app-menu {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: var(--z-menu);
  width: min(360px, 92vw);
  padding: calc(18px + env(safe-area-inset-top)) 18px 18px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform 180ms ease;
  display: grid;
  align-content: start;
  gap: 14px;
}

.app-menu.open {
  transform: translateX(0);
}

.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.session-meta {
  margin: 0;
  display: grid;
  gap: 10px;
}

.session-meta div {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.session-meta dt {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.session-meta dd {
  margin: 2px 0 0;
  word-break: break-word;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-scrim);
  background: rgba(0, 0, 0, 0.5);
}

.export-fallback {
  background: rgba(255, 255, 255, 0.03);
}

#download-fallback-content {
  min-height: 210px;
  margin-top: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
}

.app-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-footer);
  min-height: 58px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(10, 10, 12, 0.96);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  backdrop-filter: blur(16px);
}

.app-footer button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
}

.privacy-panel {
  position: fixed;
  inset: auto 0 0;
  z-index: var(--z-privacy);
  padding: 18px;
  background: rgba(0, 0, 0, 0.55);
  transform: translateY(100%);
  transition: transform 180ms ease;
  isolation: isolate;
  pointer-events: none;
}

.privacy-panel.open {
  transform: translateY(0);
  pointer-events: auto;
}

.privacy-panel > div {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-surface);
  box-shadow: var(--shadow);
}

.privacy-panel .icon-button {
  float: right;
}

@media (min-width: 760px) {
  .app-header {
    padding-left: 28px;
    padding-right: 28px;
  }

  .capture-section,
  .map-section,
  .list-section,
  .export-fallback {
    padding-left: 28px;
    padding-right: 28px;
  }

  .field-grid {
    grid-template-columns: 240px minmax(0, 1fr);
  }
}
