:root {
  --brand: #003c5b;
  --brand-dark: #002a41;
  --active: #2563eb;
  --active-soft: #e7f0ff;
  --surface: #ffffff;
  --surface-muted: #f6f8fb;
  --surface-subtle: #eef4f8;
  --text: #111827;
  --text-soft: #4b5563;
  --text-muted: #6b7280;
  --border: #d9e1e8;
  --border-strong: #b8c5d1;
  --accent-green: #13795b;
  --accent-gold: #9a6700;
  --accent-rose: #b42318;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

html {
  background: var(--surface-muted);
}

body {
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: var(--brand);
  color: #ffffff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.18);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.14);
  font-weight: 800;
}

.eyebrow,
.section-label {
  margin: 0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.eyebrow {
  margin-bottom: 2px;
  color: rgba(255, 255, 255, 0.78);
  line-height: 1.1;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.1;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.header-link {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 999px;
  padding: 8px 12px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.header-link:focus-visible,
button:focus-visible,
input:focus,
select:focus {
  outline: 3px solid rgba(37, 99, 235, 0.26);
  outline-offset: 2px;
}

.hex-workspace {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}

.info-card {
  z-index: 5;
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 18px;
  box-shadow: 8px 0 24px rgba(15, 23, 42, 0.08);
}

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

.section-label {
  color: var(--accent-green);
}

.panel-heading h2,
.selected-card h3 {
  margin: 4px 0 0;
  color: var(--brand);
  line-height: 1.15;
}

.panel-heading h2 {
  font-size: 28px;
}

.api-status {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--surface-muted);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.api-status.is-loading {
  border-color: rgba(37, 99, 235, 0.3);
  background: var(--active-soft);
  color: var(--active);
}

.api-status.is-error {
  border-color: rgba(180, 35, 24, 0.32);
  background: #fff1f0;
  color: var(--accent-rose);
}

.api-status.is-stale {
  border-color: rgba(154, 103, 0, 0.3);
  background: #fff8e1;
  color: var(--accent-gold);
}

.control-stack {
  display: grid;
  gap: 12px;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(118px, 0.55fr);
  gap: 10px;
}

.field {
  min-width: 0;
}

label,
.toggle span {
  display: block;
  margin-bottom: 6px;
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

input {
  padding: 9px 11px;
}

select {
  padding: 9px 34px 9px 11px;
}

.input-with-icon {
  position: relative;
}

.input-with-icon svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.input-with-icon input {
  padding-left: 38px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-subtle);
  white-space: nowrap;
}

.toggle input {
  width: 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--brand);
}

.toggle span {
  margin: 0;
  color: var(--text);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.button svg {
  width: 18px;
  height: 18px;
}

.button-primary {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #ffffff;
}

.button-primary:hover {
  background: var(--brand-dark);
}

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

.stats-grid div,
.selected-card,
.api-chip {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-muted);
}

.stats-grid div {
  padding: 12px;
}

dt {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 3px 0 0;
  color: var(--text);
  font-weight: 800;
}

.stats-grid dd {
  color: var(--brand-dark);
  font-size: 24px;
  line-height: 1.15;
}

.selected-card {
  padding: 14px;
}

.selected-card h3 {
  font-size: 18px;
}

.selected-card dl {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.selected-card dl div {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: baseline;
  gap: 10px;
}

.selected-card dd {
  overflow-wrap: anywhere;
}

.api-chip {
  display: grid;
  gap: 5px;
  margin-top: auto;
  padding: 12px;
}

.api-chip span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.api-chip code {
  color: var(--brand-dark);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  font-weight: 700;
}

.map-shell {
  position: relative;
  min-width: 0;
  min-height: calc(100vh - 76px);
  background: #cfdde6;
}

#map {
  position: absolute;
  inset: 0;
}

.map-message {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 900;
  max-width: 620px;
  border: 1px solid rgba(180, 35, 24, 0.32);
  border-radius: 8px;
  background: #fff1f0;
  padding: 12px 14px;
  color: var(--accent-rose);
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.leaflet-popup-content-wrapper {
  border-radius: 8px;
}

.hex-popup {
  min-width: 220px;
}

.hex-popup h3 {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 16px;
  line-height: 1.2;
}

.hex-popup dl {
  display: grid;
  gap: 6px;
  margin: 0;
}

.hex-popup div {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 8px;
}

.hex-popup dd {
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .hex-workspace {
    grid-template-columns: 1fr;
  }

  .info-card {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
  }

  .map-shell {
    min-height: 62vh;
  }
}

@media (max-width: 640px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .hex-workspace,
  .map-shell {
    min-height: 68vh;
  }

  .control-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .api-status {
    align-self: flex-start;
  }
}
