:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --panel: #ffffff;
  --ink: #1d2525;
  --muted: #61706c;
  --line: #d7dfd9;
  --accent: #196f63;
  --accent-strong: #0f544b;
  --warn: #a65b22;
  --soft: #edf4f1;
  --shadow: 0 12px 34px rgba(24, 37, 37, 0.12);
}

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

html, body {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button, input, textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) minmax(460px, 1.1fr);
  gap: 16px;
  min-height: calc(100vh - 60px);
  padding: 16px 16px 76px;
  --work-height: 52;
}

.work-panel,
.map-panel {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.work-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow: hidden;
}

.app-header h1,
.section-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.app-header h1 {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  font-size: 21px;
}

.title-icon {
  display: block;
  width: 27px;
  height: 27px;
  border-radius: 6px;
}

.app-header p {
  margin: 0;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.drop-zone {
  display: flex;
  place-items: center;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 54px;
  border: 2px dashed #92aaa1;
  border-radius: 8px;
  background: var(--soft);
  color: var(--accent-strong);
  cursor: pointer;
  text-align: center;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.drop-zone.is-dragover {
  border-color: var(--accent);
  background: #dff0ea;
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
}

.drop-inline-icon {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 19px;
  line-height: 1;
}

.mode-control {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  margin: 0;
  border: 0;
  padding: 0;
  max-width: none;
}

.mode-label {
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.mode-segment {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 134px;
  min-height: 30px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: #fff;
  overflow: hidden;
}

.mode-slider {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc(50% - 2px);
  border-radius: 999px;
  background: var(--accent);
  transition: transform 160ms ease;
}

.mode-segment.is-replace .mode-slider {
  transform: translateX(100%);
}

.mode-text {
  position: relative;
  z-index: 1;
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  background: transparent;
  color: var(--accent-strong);
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.mode-text.active {
  color: #fff;
}

.result-section {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 10px;
}

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

.actions-only {
  justify-content: flex-end;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.section-head h2 {
  font-size: 16px;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  max-width: 520px;
  flex: 1;
}

.actions-only .result-actions {
  max-width: none;
}

.action-button {
  display: grid;
  place-items: center;
  min-height: 32px;
  min-width: 0;
  border: 1px solid var(--accent);
  border-radius: 7px;
  padding: 0 9px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.action-button.primary {
  background: var(--accent);
  color: #fff;
}

.action-button.secondary {
  background: #fff;
  color: var(--accent-strong);
}

.action-button.google,
.action-button.maps-link {
  border-color: #2563eb;
}

.action-button.google {
  background: #2563eb;
  color: #fff;
}

.action-button.maps-link {
  background: #eff6ff;
  color: #1d4ed8;
}

.action-button:disabled {
  border-color: #aab7b3;
  background: #aab7b3;
  color: #fff;
  cursor: not-allowed;
}

.result-table-wrap {
  min-height: 0;
  height: 260px;
  max-height: 38vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-table {
  width: 100%;
  min-width: 460px;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 14px;
}

.result-table th,
.result-table td {
  border: 1px solid #b9c4bf;
  padding: 6px 8px;
  text-align: left;
  white-space: nowrap;
}

.result-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f2f5f3;
  color: var(--ink);
  font-weight: 700;
  text-align: center;
}

.result-table th:nth-child(1),
.result-table td:nth-child(1) {
  width: 28%;
}

.result-table th:nth-child(2),
.result-table th:nth-child(3) {
  width: 24%;
}

.result-table td:nth-child(2),
.result-table td:nth-child(3) {
  width: 24%;
  text-align: right;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.result-table th:nth-child(4),
.result-table td:nth-child(4) {
  width: 24%;
  font-variant-numeric: tabular-nums;
}

.result-table td:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 700;
}

.result-table tbody tr.has-map-point {
  cursor: pointer;
}

.result-table tbody tr.has-map-point:hover td {
  background: #edf7f4;
}

.result-table tbody tr.is-selected td {
  background: #dff0ea;
}

.result-table .empty-cell {
  color: var(--muted);
  text-align: center;
}

.csv-output {
  display: none;
}

.map-panel {
  display: grid;
  overflow: hidden;
}

.map {
  min-height: 420px;
}

.split-resizer {
  display: none;
}

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

#ad-banner {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1000;
  height: 60px;
  background: #111;
  overflow: hidden;
}

.ad-label {
  position: absolute;
  top: 2px;
  right: 5px;
  z-index: 1;
  color: rgba(255, 255, 255, 0.35);
  font-size: 9px;
  letter-spacing: 0;
  pointer-events: none;
}

#ad-container {
  position: relative;
  display: flex;
  width: 100%;
  height: 60px;
  align-items: center;
  justify-content: center;
}

.ad-frame-wrap {
  position: absolute;
  top: 0;
  left: 50%;
  height: 60px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.6s ease;
}

.ad-frame-wrap.active {
  opacity: 1;
  pointer-events: auto;
}

.ad-frame-wrap a {
  display: grid;
  height: 60px;
  place-items: center;
  line-height: 0;
}

.ad-frame-wrap img {
  display: block;
  width: auto;
  max-width: 100vw;
  max-height: 60px;
}

.ad-frame-wrap .ad-tracker {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.popup-title {
  font-weight: 700;
  margin-bottom: 3px;
}

.popup-meta {
  color: #52625e;
  font-size: 12px;
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows:
      minmax(220px, calc((100svh - 60px) * var(--work-height) / 100))
      12px
      minmax(160px, 1fr);
    gap: 0;
    height: calc(100svh - 60px);
    min-height: 0;
    padding: 0;
  }

  .work-panel,
  .map-panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  .work-panel {
    gap: 8px;
    padding: 10px;
    overflow: auto;
  }

  .app-header h1 {
    font-size: 18px;
  }

  .title-row {
    gap: 7px;
  }

  .title-icon {
    width: 24px;
    height: 24px;
  }

  .app-header p {
    font-size: 8.5px;
  }

  .drop-zone {
    min-height: 44px;
  }

  .input-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
  }

  .mode-control {
    gap: 5px;
  }

  .mode-label {
    font-size: 11px;
  }

  .mode-segment {
    width: 116px;
    min-height: 28px;
  }

  .mode-text {
    min-height: 26px;
    padding: 0 8px;
    font-size: 12px;
  }

  .drop-inline-icon {
    width: 22px;
    height: 22px;
    font-size: 17px;
  }

  .drop-title {
    gap: 6px;
    font-size: 13px;
  }

  .result-table-wrap {
    height: 210px;
    max-height: 32vh;
  }

  .result-table {
    min-width: 0;
    font-size: 12px;
  }

  .result-table th,
  .result-table td {
    padding: 6px 7px;
  }

  .map {
    min-height: 0;
  }

  .split-resizer {
    display: block;
    position: relative;
    z-index: 40;
    background: #d5ddd9;
    border-top: 1px solid #b8c4bf;
    border-bottom: 1px solid #b8c4bf;
    cursor: row-resize;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
  }

  .split-resizer::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 54px;
    height: 4px;
    border-radius: 999px;
    background: #7b8a86;
    transform: translate(-50%, -50%);
  }
}

@media (max-width: 420px) {
  .input-row {
    gap: 5px;
  }

  .drop-title {
    gap: 4px;
    font-size: 11px;
  }

  .drop-inline-icon {
    width: 20px;
    height: 20px;
    font-size: 16px;
  }

  .mode-control {
    gap: 4px;
  }

  .mode-label {
    font-size: 10px;
  }

  .mode-segment {
    width: 86px;
  }

  .mode-text {
    padding: 0 5px;
    font-size: 11px;
  }

  .section-head {
    align-items: center;
    flex-direction: row;
  }

  .result-actions {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    justify-content: stretch;
    max-width: none;
    gap: 4px;
  }

  .action-button {
    min-width: 0;
    min-height: 30px;
    padding: 0 2px;
    font-size: 10px;
  }

  .section-head h2 {
    font-size: 15px;
  }

  .result-table {
    min-width: 0;
    font-size: 11px;
  }

  .result-table th,
  .result-table td {
    padding: 6px 4px;
  }

  .result-table th:nth-child(1),
  .result-table td:nth-child(1) {
    width: 30%;
  }

  .result-table th:nth-child(2),
  .result-table td:nth-child(2),
  .result-table th:nth-child(3),
  .result-table td:nth-child(3) {
    width: 22%;
  }

  .result-table th:nth-child(4),
  .result-table td:nth-child(4) {
    width: 26%;
  }
}
