:root {
  --bg: #f7f8f4;
  --panel: #ffffff;
  --ink: #1d2a2f;
  --muted: #617076;
  --line: #d9e0dc;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --danger: #b42318;
  --warning-bg: #fff7d6;
  --success-bg: #e8f7ef;
  --danger-bg: #fff0ee;
  --shadow: 0 10px 28px rgba(29, 42, 47, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

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

button,
input,
select,
textarea {
  font: inherit;
}

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

.sidebar {
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 22px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.app-header {
  padding-bottom: 4px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 1.65rem;
  line-height: 1.2;
}

h2 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.lead {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.panel-section {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

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

.count-badge {
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
}

input,
select {
  min-height: 40px;
  padding: 8px 10px;
}

textarea {
  min-height: 98px;
  padding: 10px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus,
button:focus,
.drop-zone:focus {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 1px;
}

button {
  width: 100%;
  min-height: 42px;
  margin-top: 12px;
  border: 0;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

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

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

.secondary-button {
  color: var(--accent-dark);
  background: #dff1ee;
}

.secondary-button:hover {
  background: #cfebe6;
}

.message {
  display: none;
  margin-top: 12px;
  padding: 10px;
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.message.is-success {
  display: block;
  color: #155a32;
  background: var(--success-bg);
}

.message.is-error {
  display: block;
  color: var(--danger);
  background: var(--danger-bg);
}

.message.is-info {
  display: block;
  color: #6a5200;
  background: var(--warning-bg);
}

.search-status {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.search-results {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.search-result-button {
  width: 100%;
  min-height: auto;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fbfcfa;
  font-weight: 600;
  text-align: left;
}

.search-result-button:hover {
  background: #eef5f2;
}

.search-result-title,
.search-result-detail {
  display: block;
  overflow-wrap: anywhere;
}

.search-result-detail {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.layer-list {
  display: grid;
  gap: 12px;
}

.empty-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.layer-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.layer-top-row,
.layer-action-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layer-top-row {
  margin-bottom: 10px;
}

.layer-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.icon-button {
  flex: 0 0 34px;
  width: 34px;
  min-height: 34px;
  margin: 0;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.icon-button:hover {
  background: #eef5f2;
}

.toggle-label,
.range-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.toggle-label input {
  width: 18px;
  min-height: 18px;
}

.opacity-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}

.opacity-control input {
  min-height: 28px;
  padding: 0;
}

.opacity-value {
  min-width: 42px;
  text-align: right;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 96px;
  padding: 16px;
  border: 2px dashed #9db2ae;
  border-radius: 8px;
  color: var(--muted);
  background: #f6faf8;
  text-align: center;
  line-height: 1.5;
}

.drop-zone.is-dragover {
  color: var(--accent-dark);
  border-color: var(--accent);
  background: #e6f5f2;
}

#share-url {
  margin-top: 10px;
  color: var(--muted);
  background: #f6f8f7;
}

.map-area {
  min-width: 0;
  min-height: 0;
}

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

.html-raster-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.html-raster-tile {
  position: absolute;
  display: block;
  max-width: none;
  user-select: none;
}

.maplibregl-popup-content {
  max-width: 320px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.popup-table th,
.popup-table td {
  padding: 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.popup-table th {
  width: 38%;
  color: var(--muted);
}

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

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 44vh) minmax(360px, 56vh);
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    order: 2;
    height: auto;
    border-top: 1px solid var(--line);
    border-right: 0;
    box-shadow: none;
  }

  .map-area {
    order: 1;
  }
}
