:root {
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d1d5db;
  --surface: #ffffff;
  --surface-soft: #f3f4f6;
  --primary: #0b84f3;
  --primary-dark: #0964b6;
  --success-bg: #e7f5ee;
  --success-text: #127a4a;
  --error-bg: #fcebea;
  --error-text: #bf2323;
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.18);
  --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: "IBM Plex Sans Thai", "Noto Sans Thai", sans-serif;
  color: var(--text);
  background: #e5e7eb;
  overflow: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: 72px 1fr;
  width: 100%;
  height: 100%;
}

.map-rail {
  background: #f3f4f6;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 14px 10px;
  z-index: 1200;
}

.rail-btn,
.icon-btn,
button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.rail-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
  font-size: 21px;
  line-height: 1;
  color: #374151;
}

.rail-btn:hover {
  background: #eef6ff;
}

.rail-btn-locate {
  background: #e7edf7;
  color: #3f4a5d;
}

.rail-btn-locate:hover {
  background: #dce5f2;
}

.rail-btn-locate svg {
  width: 24px;
  height: 24px;
  display: block;
  margin: 0 auto;
  stroke: currentColor;
  stroke-width: 2.1;
  fill: none;
  stroke-linecap: round;
}

.map-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.28);
  z-index: 1050;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.map-stage.panel-open .sheet-backdrop {
  opacity: 1;
  pointer-events: auto;
}

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

.map-top-stack {
  position: absolute;
  top: 16px;
  left: 16px;
  width: min(680px, calc(100% - 32px));
  z-index: 1000;
  pointer-events: none;
}

.map-stage.panel-open .map-top-stack {
  left: min(462px, calc(100% - 700px));
  width: min(620px, calc(100% - 478px));
}

.search-box,
.status-line,
.side-sheet,
.map-bottom-card {
  pointer-events: auto;
}

.search-box {
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.brand-row strong {
  font-size: 16px;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
}

.domain {
  font-size: 12px;
  color: var(--muted);
}

.policy-links {
  margin-top: 8px;
  display: flex;
  gap: 12px;
}

.policy-links a {
  font-size: 12px;
  color: #1d4ed8;
  text-decoration: none;
}

.policy-links a:hover {
  text-decoration: underline;
}

.search-row {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.search-row input,
.search-row button {
  height: 44px;
}

.search-row input {
  min-width: 0;
}

.search-row button {
  flex: 0 0 auto;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  width: 100%;
  background: #fff;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: #93c5fd;
}

.field-flash {
  animation: fieldFlash 0.95s ease;
}

@keyframes fieldFlash {
  0% {
    box-shadow: 0 0 0 0 rgba(11, 132, 243, 0.38);
    border-color: #60a5fa;
  }
  70% {
    box-shadow: 0 0 0 10px rgba(11, 132, 243, 0);
    border-color: #60a5fa;
  }
  100% {
    box-shadow: none;
  }
}

button {
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  padding: 10px 14px;
  transition: background 0.15s ease, transform 0.05s ease;
}

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

button:active {
  transform: translateY(1px);
}

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

.ghost-btn {
  background: var(--surface-soft);
  color: #334155;
  border: 1px solid #e5e7eb;
}

.ghost-btn:hover {
  background: #e8edf3;
}

.chip-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.filter-chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid #dbe2ea;
  background: #fff;
  color: #334155;
  font-size: 13px;
  white-space: nowrap;
}

.filter-chip:hover {
  background: #eef6ff;
}

.filter-chip.active {
  background: #e8f2ff;
  border-color: #93c5fd;
  color: #0b5eb2;
}

.status-line {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.status-chip,
.point-count {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  backdrop-filter: blur(8px);
}

.status-chip {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid #b4e5ce;
  max-width: 76%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.point-count {
  display: none;
  background: transparent;
  border: 0;
  color: #374151;
  padding-left: 0;
  padding-right: 0;
}

.side-sheet {
  position: absolute;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: min(430px, calc(100% - 32px));
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  z-index: 1100;
  overflow: auto;
  overflow-x: hidden;
  transform: translateX(-120%);
  transition: transform 0.2s ease;
  padding: 12px;
}

.side-sheet.is-open {
  transform: translateX(0);
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 20px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #f1f5f9;
  color: #334155;
}

.sheet-card {
  background: #fff;
  border: 1px solid #ebedf0;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
}

.sheet-card h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

label {
  display: block;
  margin: 8px 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.row-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.result-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  min-height: 56px;
  padding: 8px;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

.map-bottom-card {
  position: absolute;
  left: 16px;
  bottom: 16px;
  width: min(430px, calc(100% - 32px));
  max-height: min(52vh, calc(100vh - 180px));
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 22px;
  box-shadow: 0 10px 26px rgba(17, 24, 39, 0.18);
  z-index: 900;
  padding: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-stage.panel-open .map-bottom-card {
  left: min(462px, calc(100% - 700px));
  width: min(430px, calc(100% - 478px));
}

.map-bottom-card header {
  margin-bottom: 8px;
  flex: 0 0 auto;
}

.map-bottom-card h3 {
  margin: 0;
  font-size: 15px;
}

.point-list {
  margin: 0;
  padding: 0;
  list-style: none;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.point-list li {
  border: 1px solid #dbe3ee;
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  cursor: pointer;
  overflow: hidden;
}

.point-list li:last-child {
  margin-bottom: 0;
}

.point-list li:hover {
  border-color: #93c5fd;
  background: #f8fbff;
}

.point-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.point-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.point-map-icon {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  border: 2px solid #ffffff;
  background: #0b84f3;
  box-shadow: 0 0 0 1px #bfdbfe;
  flex: 0 0 auto;
}

.point-title {
  font-size: 14px;
  font-weight: 700;
  color: #1f2937;
}

.point-id-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
}

.point-meta-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 7px;
}

.point-type-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
}

.point-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.point-distance {
  margin-top: 7px;
  font-size: 12px;
  color: #0b5eb2;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  background: #eef6ff;
  border: 1px solid #d7e8ff;
  border-radius: 999px;
  padding: 4px 9px;
}

.point-actions {
  margin-top: 9px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.point-list .copy-link-btn,
.point-nav-btn {
  width: 100%;
  height: 34px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  padding: 0 10px;
}

.point-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.point-list li.empty-state {
  cursor: default;
  background: #f8fafc;
  color: var(--muted);
}

.map-context-menu {
  min-width: 220px;
}

.map-context-menu button {
  margin-bottom: 8px;
}

.map-context-menu .coord {
  font-size: 12px;
  color: var(--muted);
}

.leaflet-popup-content-wrapper {
  border-radius: 18px !important;
  box-shadow: var(--shadow-lg) !important;
}

.leaflet-popup-content {
  margin: 14px 14px 12px !important;
  min-width: 260px;
}

.place-popup {
  display: grid;
  gap: 8px;
}

.popup-title {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  color: #111827;
}

.popup-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.popup-meta span {
  color: var(--muted);
}

.popup-meta strong {
  color: #1f2937;
  font-weight: 600;
}

.popup-desc {
  font-size: 14px;
  line-height: 1.45;
  color: #374151;
}

.popup-address {
  font-size: 13px;
  color: #475569;
}

.popup-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 2px;
}

.popup-actions .copy-link-btn,
.nav-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  border-radius: 11px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.popup-actions .copy-link-btn {
  margin: 0;
}

.nav-link-btn {
  background: var(--primary);
  color: #ffffff !important;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
}

.nav-link-btn:link,
.nav-link-btn:visited,
.nav-link-btn:hover,
.nav-link-btn:active,
.nav-link-btn:focus-visible {
  color: #ffffff !important;
}

.nav-link-btn:hover {
  background: var(--primary-dark);
}

.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
  width: 38px !important;
  height: 38px !important;
  line-height: 38px !important;
}

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

  .map-rail {
    position: absolute;
    left: 12px;
    bottom: 18px;
    top: auto;
    width: auto;
    border: 0;
    background: transparent;
    flex-direction: row;
    padding: 0;
  }

  .map-top-stack {
    top: 12px;
    left: 12px;
    width: calc(100% - 24px);
  }

  .map-stage.panel-open .map-top-stack {
    left: 12px;
    width: calc(100% - 24px);
  }

  .search-box {
    border-radius: 16px;
  }

  .side-sheet {
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    bottom: auto;
    border-radius: 0;
    padding: 12px;
    transform: translateX(-101%);
  }

  .map-stage.panel-open .sheet-backdrop {
    opacity: 0;
    pointer-events: none;
  }

  .map-bottom-card {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: 74px;
    max-height: min(46vh, calc(100vh - 220px));
  }

  .map-stage.panel-open .map-bottom-card {
    left: 12px;
    width: auto;
  }

  .point-actions {
    grid-template-columns: 1fr;
  }

  .leaflet-popup-content {
    min-width: 220px;
  }

  .popup-actions {
    grid-template-columns: 1fr;
  }
}
