:root {
  --bg: #0e0e10;
  --panel: #17171b;
  --panel-2: #1f1f25;
  --border: #2a2a31;
  --text: #f2f2f4;
  --muted: #9a9aa3;
  --accent: #4cc38a;
  --accent-ink: #07120c;
  --danger: #e5484d;
  --radius: 14px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: calc(12px + var(--safe-top)) 16px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
}

#app {
  flex: 1;
  padding: 16px 16px calc(var(--nav-h) + var(--safe-bottom) + 24px);
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 4px;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav a .icon { font-size: 22px; line-height: 1; }
.bottom-nav a[aria-current="page"] { color: var(--accent); }

/* --- Cards / generic --- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 12px; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack-lg { display: flex; flex-direction: column; gap: 16px; }

.banner {
  background: #3a2a1a;
  border: 1px solid #5a3b20;
  color: #ffd8a8;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}

/* --- Home: nearest card --- */
.nearest {
  padding: 28px 20px;
  text-align: center;
  background: linear-gradient(180deg, #1a2a22 0%, var(--panel) 100%);
  border: 1px solid #2a4236;
}
.nearest .name {
  font-size: 15px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.nearest .code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: clamp(56px, 18vw, 96px);
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
  margin: 8px 0 14px;
  cursor: pointer;
  user-select: all;
  word-break: break-all;
}
.nearest .address { font-size: 14px; color: var(--text); }
.nearest .distance {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}
.copy-hint { font-size: 12px; color: var(--muted); margin-top: 10px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}
.pager-btn {
  width: 56px;
  height: 48px;
  font-size: 24px;
  padding: 0;
  line-height: 1;
  font-weight: 700;
}
.pager-count {
  flex: 1;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  padding: 60px 20px;
  color: var(--muted);
  text-align: center;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty h2 { color: var(--text); margin: 0 0 8px; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.btn.primary:disabled {
  background: #2b3a33;
  color: #6a7a72;
  border-color: #2b3a33;
  cursor: not-allowed;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: #5a2428;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
}
.btn-block { width: 100%; }

/* --- List --- */
.list-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.list-entry .body { flex: 1; min-width: 0; }
.list-entry .body .name { font-weight: 600; }
.list-entry .body .addr {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-entry .code-chip {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  color: var(--accent);
  background: #132a20;
  border: 1px solid #214e3a;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 16px;
  white-space: nowrap;
}
.list-entry .menu-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
}

/* --- Form --- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.field input[type="text"] {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
}
.field input[type="text"]:focus {
  border-color: var(--accent);
}
.field input.mono {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: 0.02em;
}
.field .hint { font-size: 12px; color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* autocomplete */
.autocomplete { position: relative; }
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 5;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}
.suggestions button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 12px 14px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.suggestions button:last-child { border-bottom: none; }
.suggestions button:hover,
.suggestions button:focus { background: var(--panel-2); outline: none; }
.search-state {
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
}

.address-locked {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #132a20;
  border: 1px solid #214e3a;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
}
.address-locked .label {
  font-size: 12px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
  font-weight: 600;
}
.address-locked button {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
}

.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.form-actions .btn { flex: 1; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  z-index: 30;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
  .toast { animation: none; }
}
