:root {
  --bg: #f4f7f2;
  --surface: #ffffff;
  --surface-2: #eef4ec;
  --text: #172018;
  --muted: #617066;
  --line: #d9e2d6;
  --primary: #1f7a4d;
  --primary-strong: #145a38;
  --accent: #c5522f;
  --warning: #b68421;
  --review: #6f5aa8;
  --shadow: 0 14px 35px rgba(25, 40, 28, 0.13);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: block;
  object-fit: cover;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.mobile-tabs {
  display: none;
}

.primary-button,
.ghost-button,
.icon-button {
  border: 0;
  border-radius: 7px;
  min-height: 38px;
}

.primary-button {
  padding: 0 15px;
  color: #fff;
  background: var(--primary);
  font-weight: 700;
}

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

.ghost-button {
  padding: 0 12px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.link-button {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.icon-button {
  width: 36px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 20px;
}

.full {
  width: 100%;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(420px, 1fr) minmax(310px, 390px);
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.detail-panel {
  background: var(--surface);
  min-height: 0;
  overflow: auto;
}

.sidebar {
  border-right: 1px solid var(--line);
}

.detail-panel {
  border-left: 1px solid var(--line);
}

.search-panel {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.search-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

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

textarea {
  padding: 10px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 122, 77, 0.15);
}

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

.reset-button {
  width: 100%;
  margin-top: 12px;
}

.viewport-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--text);
  font-size: 13px;
}

.viewport-toggle input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}

.summary-strip div {
  padding: 12px;
  border-right: 1px solid var(--line);
}

.summary-strip div:last-child {
  border-right: 0;
}

.summary-strip strong {
  display: block;
  font-size: 22px;
}

.summary-strip span {
  color: var(--muted);
  font-size: 12px;
}

.location-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.location-card {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.location-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 122, 77, 0.13);
}

.location-card h3,
.detail-panel h2 {
  margin: 0;
  font-size: 16px;
}

.location-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.badge.collected {
  color: #fff;
  background: var(--primary);
}

.badge.paused {
  color: #fff;
  background: var(--warning);
}

.badge.review {
  color: #fff;
  background: var(--review);
}

.badge.approximate {
  color: #fff;
  background: #737373;
}

.badge.stopped-known {
  color: #fff;
  background: #6f7d86;
}

.badge.stopped-unknown {
  color: #fff;
  background: #8b9298;
}

.badge.geocode-failed {
  color: #fff;
  background: #7b7486;
}

.badge.memo {
  color: #fff;
  background: #1d5f99;
}

.map-area {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #dbe7ef;
}

.map-toolbar {
  position: absolute;
  z-index: 20;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.pin-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.shape-dot {
  width: 13px;
  height: 13px;
  display: inline-grid;
  place-items: center;
  font-size: 13px;
  font-style: normal;
  line-height: 1;
}

.pin-dot.uncollected {
  background: var(--accent);
}

.pin-dot.collected {
  background: var(--primary);
}

.pin-dot.paused {
  background: var(--warning);
}

.pin-dot.review {
  background: var(--review);
}

.shape-dot.stopped-known {
  color: #6f7d86;
}

.shape-dot.stopped-unknown {
  color: #8b9298;
}

.shape-dot.geocode-failed {
  color: #7b7486;
}

.pin-dot.approximate {
  background: #737373;
}

.pin-dot.current {
  background: #1e63b6;
}

.map-canvas {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.locate-button.active {
  color: #fff;
  background: #1e63b6;
  border-color: #1e63b6;
}

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

.map-popup-card {
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.map-popup-image {
  display: block;
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  border-radius: 6px;
  margin-bottom: 8px;
  background: var(--surface-2);
}

.map-popup-title {
  display: block;
  margin: 0 0 4px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.map-popup-subtitle {
  display: block;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.detail-panel {
  padding: 18px;
}

.empty-state {
  min-height: 70vh;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.detail-head {
  display: grid;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.card-image {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.card-image.detail {
  display: grid;
  place-items: center;
  min-height: 180px;
}

.card-image img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ghost-button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.68;
}

.inline-copy,
.inline-source-link {
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: #1d5f99;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.inline-copy:hover,
.inline-source-link:hover {
  color: var(--primary-strong);
}

.inline-disabled,
.inline-hint {
  color: var(--muted);
}

.inline-hint {
  font-size: 12px;
}

.info-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
}

.info-table th,
.info-table td {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

.info-table th {
  width: 92px;
  color: var(--muted);
  font-weight: 700;
}

.memo-box {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.modal {
  width: min(440px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.modal.wide {
  width: min(760px, calc(100vw - 28px));
}

.modal::backdrop {
  background: rgba(12, 20, 14, 0.42);
}

.modal form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal h2 {
  margin: 0;
  font-size: 18px;
}

.my-page {
  display: grid;
  gap: 14px;
}

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

.memo-list h3 {
  margin: 0;
  font-size: 16px;
}

.memo-list-item {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.memo-list-item span,
.memo-list-item small {
  color: var(--muted);
}

.memo-list-item small {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.progress-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.progress-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.progress-card strong {
  display: block;
  font-size: 24px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 60;
  transform: translateX(-50%);
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100dvh;
    height: auto;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 330px 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    overflow: visible;
  }

  .map-area {
    min-height: 560px;
  }

  .map-canvas {
    min-height: 560px;
  }

  .detail-panel {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }
}

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

  .app-shell {
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
  }

  .topbar {
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
  }

  .brand {
    gap: 9px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
  }

  .brand h1 {
    font-size: 16px;
  }

  .brand p {
    display: none;
  }

  .top-actions button {
    width: auto;
    min-height: 34px;
    padding: 0 11px;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
  }

  .mobile-tab {
    min-height: 42px;
    border: 0;
    border-right: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    font-weight: 700;
  }

  .mobile-tab:last-child {
    border-right: 0;
  }

  .mobile-tab.active {
    color: #fff;
    background: var(--primary);
  }

  .workspace {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar,
  .map-area,
  .detail-panel {
    display: none;
    border: 0;
    min-height: 0;
    overflow: auto;
  }

  body[data-mobile-panel="list"] .sidebar,
  body[data-mobile-panel="map"] .map-area,
  body[data-mobile-panel="detail"] .detail-panel {
    display: block;
    flex: 1 1 auto;
  }

  .map-area {
    height: auto;
  }

  .map-canvas {
    min-height: 0;
    height: 100%;
  }

  .sidebar {
    max-height: none;
  }

  .detail-panel {
    padding: 14px;
  }

  .map-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .legend {
    max-height: 92px;
    overflow: auto;
  }

  .filter-grid,
  .detail-actions,
  .progress-grid {
    grid-template-columns: 1fr;
  }
}
