/* ---------- Tokens ---------- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e4e7ec;
  --text: #101828;
  --text-2: #475467;
  --text-3: #8a94a6;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8efff;
  --ok: #12b76a;
  --warn: #f79009;
  --err: #f04438;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --code-kw: #7dd3fc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --radius: 16px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1d232c;
    --border: #2a313c;
    --text: #f0f3f7;
    --text-2: #b4bcc8;
    --text-3: #7d8796;
    --accent: #4c8dff;
    --accent-hover: #6aa1ff;
    --accent-soft: #17264a;
    --code-bg: #0a0d12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code {
  font-family: var(--mono);
  font-size: .88em;
  padding: .1em .35em;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

[hidden] { display: none !important; }

.shell {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

main.shell { flex: 1; padding-top: 20px; padding-bottom: 32px; }

/* ---------- Top bar & footer ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
}

.topnav a { color: var(--text-2); font-weight: 500; font-size: 14px; }

.footer {
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 13px;
  padding-bottom: env(safe-area-inset-bottom);
}

.footer-inner { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: space-between; padding-top: 16px; padding-bottom: 16px; }
.footer a { color: var(--text-2); }

/* ---------- Hero ---------- */
.hero { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }

.hero h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -.025em; }

.lede { margin: 6px 0 0; color: var(--text-2); }

.status {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.status.is-busy .status-dot { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.status.is-ok .status-dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.status.is-warn .status-dot { background: var(--warn); }
.status.is-err .status-dot { background: var(--err); }

@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }

/* ---------- Layout ---------- */
.layout { display: grid; gap: 16px; }
.stack { display: grid; gap: 16px; align-content: start; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; min-height: 28px; }

.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* ---------- Map ---------- */
.map-card { padding: 0; overflow: hidden; aspect-ratio: 4 / 3; position: relative; }
.map, .map-placeholder { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.map { animation: fade .4s ease; }

@media (prefers-color-scheme: dark) {
  .map { filter: invert(.9) hue-rotate(180deg) brightness(.95) contrast(.9); }
}

/* ---------- Address ---------- */
.address { display: grid; gap: 4px; }
.address-street { margin: 0; font-size: 20px; font-weight: 600; line-height: 1.3; letter-spacing: -.015em; }
.address-locality { margin: 0; color: var(--text-2); }
.address-country { margin: 6px 0 0; display: flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 500; }
.country-code {
  font: 600 11px var(--mono);
  letter-spacing: .04em;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--border);
  color: var(--text-2);
}
.address-full { margin: 12px 0 0; padding-top: 12px; border-top: 1px dashed var(--border); font-size: 13px; color: var(--text-3); }
.address-empty { margin: 0; color: var(--text-2); }

/* ---------- Coordinates ---------- */
.coords { display: grid; gap: 8px; margin: 0 0 14px; }

.coord {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px 14px;
  min-width: 0;
}
.coord dt { font-size: 13px; font-weight: 500; color: var(--text-2); }
.coord dd { margin: 0; display: flex; flex-direction: column; align-items: flex-end; min-width: 0; text-align: right; }

.mono { font-family: var(--mono); font-weight: 600; font-size: 17px; letter-spacing: -.01em; word-break: break-all; font-variant-numeric: tabular-nums; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.chip {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.code { border-radius: 12px; background: var(--code-bg); overflow: hidden; }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; border-bottom: 1px solid rgba(255, 255, 255, .08); color: #94a3b8; font-size: 12px; font-weight: 500; }
.code pre { margin: 0; padding: 12px 14px 14px; color: var(--code-text); font: 500 13px/1.7 var(--mono); white-space: pre-wrap; word-break: break-all; }
.code .kw { color: var(--code-kw); }
.code .num { color: #fbbf77; }

/* ---------- Buttons ---------- */
.actions { display: grid; gap: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 20px;
  border-radius: 12px;
  border: 1px solid transparent;
  font: 600 15px var(--font);
  cursor: pointer;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled svg { animation: spin 1s linear infinite; }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }

@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: .4; cursor: default; }

.text-btn { background: none; border: 0; padding: 2px 6px; border-radius: 6px; color: #cbd5e1; font: 600 12px var(--font); cursor: pointer; }
.text-btn:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.text-btn:disabled { opacity: .4; cursor: default; }

.meta { margin: 0; text-align: center; font-size: 12px; color: var(--text-3); }

/* ---------- Skeletons, toast ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}
.line { height: 14px; border-radius: 6px; margin: 6px 0; }
.w-80 { width: 80%; height: 20px; } .w-60 { width: 60%; } .w-40 { width: 40%; }

@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Prose pages ---------- */
.prose { max-width: 680px; }
.prose h1 { margin-top: 0; font-size: 24px; letter-spacing: -.02em; }
.prose p { color: var(--text-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Larger screens ---------- */
@media (min-width: 600px) {
  .actions { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 900px) {
  main.shell { padding-top: 36px; }
  .hero { flex-direction: row; align-items: flex-end; justify-content: space-between; margin-bottom: 28px; }
  .hero h1 { font-size: 36px; }
  .status { align-self: auto; }
  .layout { grid-template-columns: 1.25fr 1fr; gap: 20px; align-items: start; }
  .map-card { aspect-ratio: auto; height: 100%; min-height: 520px; position: sticky; top: 76px; }
}
