:root {
  color-scheme: light;
  --ink: #172027;
  --muted: #62717d;
  --panel: #f7f9f8;
  --line: #d8e0df;
  --accent: #1b78a6;
  --accent-strong: #105a7d;
  --danger: #b43b3b;
  --paper: #ffffff;
  --shadow: 0 18px 42px rgba(30, 44, 48, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: #e9efed;
}

button,
input {
  font: inherit;
}

button,
.file-button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) 1fr;
  min-height: 100vh;
}

.control-panel {
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
  padding: 22px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.35rem;
  line-height: 1.15;
}

h2 {
  font-size: 0.95rem;
  letter-spacing: 0;
}

.brand-row p,
.small-copy,
#resultDetail {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.address-form,
.panel-section {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  color: #33424b;
  font-size: 0.82rem;
  font-weight: 750;
}

input[type="search"],
input[type="text"] {
  min-width: 0;
  width: 100%;
  height: 42px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid #cbd7d6;
  border-radius: 6px;
  outline: none;
}

input[type="search"]:focus,
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 120, 166, 0.18);
}

input[type="color"] {
  width: 100%;
  height: 42px;
  padding: 3px;
  background: var(--paper);
  border: 1px solid #cbd7d6;
  border-radius: 6px;
}

.input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.input-row button,
.primary-button {
  padding: 0 14px;
  min-height: 42px;
  color: white;
  background: var(--accent);
}

.input-row button:hover,
.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.file-button {
  display: inline-grid;
  min-height: 38px;
  place-items: center;
  padding: 0 12px;
  color: #17323f;
  background: #dceae8;
}

.secondary-button:hover,
.file-button:hover {
  background: #cfe1de;
}

.danger-button {
  min-height: 38px;
  padding: 0 12px;
  color: white;
  background: var(--danger);
}

.icon-button {
  display: grid;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  place-items: center;
  color: white;
  background: #23343c;
  font-size: 1.25rem;
}

.result-card {
  display: grid;
  gap: 5px;
  padding: 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
}

.result-card strong {
  font-size: 1.1rem;
}

.eyebrow {
  color: #63727b;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-grid,
.button-grid {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 10px;
}

.button-grid {
  grid-template-columns: 1fr 1fr;
}

.trace-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #dce7e4;
  border: 1px solid #cbd7d6;
  border-radius: 8px;
}

.segmented-control label {
  display: grid;
  min-height: 34px;
  place-items: center;
  color: #33424b;
  border-radius: 6px;
  cursor: pointer;
}

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

.segmented-control label:has(input:checked) {
  color: white;
  background: var(--accent);
}

.trace-actions button {
  min-height: 38px;
  padding: 0 12px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button-grid .danger-button {
  grid-column: 1 / -1;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.congregation-list {
  display: grid;
  gap: 8px;
}

.congregation-item {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.congregation-item.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 120, 166, 0.14);
}

.color-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
}

.congregation-item button {
  min-height: 30px;
  padding: 0 9px;
  color: #17323f;
  background: #edf3f2;
}

.congregation-name {
  display: grid;
  gap: 2px;
}

.congregation-name small {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 650;
}

.map-stage {
  position: relative;
  min-width: 0;
}

#map {
  width: 100%;
  height: 100%;
}

.map-toast {
  position: absolute;
  right: 18px;
  bottom: 20px;
  z-index: 600;
  max-width: min(420px, calc(100% - 36px));
  padding: 10px 12px;
  color: white;
  background: rgba(23, 32, 39, 0.88);
  border-radius: 6px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.map-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.leaflet-popup-content {
  margin: 10px 12px;
}

.leaflet-draw-toolbar a {
  width: 30px;
  height: 30px;
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(58vh, 1fr);
  }

  .control-panel {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand-row {
    align-items: center;
  }
}

@media (max-width: 430px) {
  .control-panel {
    padding: 16px;
  }

  .field-grid,
  .button-grid,
  .input-row {
    grid-template-columns: 1fr;
  }
}
