:root {
  --ink: #17211d;
  --muted: #66736d;
  --paper: #f7f5ef;
  --panel: #fffef9;
  --line: #dedfd8;
  --green: #176b52;
  --green-soft: #dcece6;
  --orange: #d26a35;
  --blue: #2f6f91;
  --shadow: 0 16px 40px rgb(22 41 34 / 14%);
}

* { box-sizing: border-box; }

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

body {
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

button, input, select { font: inherit; }

.app-shell { display: grid; grid-template-columns: 340px 1fr; overflow: hidden; }

.sidebar {
  z-index: 1001;
  display: flex;
  min-height: 0;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  box-shadow: 6px 0 24px rgb(36 56 48 / 8%);
}

.brand { display: flex; align-items: center; gap: 12px; padding: 22px 22px 18px; }

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  color: white;
  background: var(--green);
  border-radius: 14px 14px 14px 4px;
  font-family: serif;
  font-size: 21px;
}

.brand h1 { margin: 0; font-family: serif; font-size: 25px; letter-spacing: .08em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; letter-spacing: .08em; }
.language-link { flex: 0 0 auto; margin-left: auto; padding: 6px 8px; color: var(--green); border: 1px solid #9ac0b3; border-radius: 7px; font-size: 11px; font-weight: 800; text-decoration: none; white-space: nowrap; }
.language-link:hover { background: var(--green-soft); }
.mobile-close { display: none; margin-left: auto; border: 0; color: var(--muted); background: transparent; font-size: 30px; }
.language-link + .mobile-close { margin-left: 0; }

.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 18px;
  padding: 14px 4px;
  background: var(--green-soft);
  border-radius: 14px;
}

.summary div { display: flex; flex-direction: column; align-items: center; border-right: 1px solid rgb(23 107 82 / 16%); }
.summary div:last-child { border: 0; }
.summary strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.summary span { margin-top: 3px; color: var(--muted); font-size: 10px; }

.controls { min-height: 0; padding: 20px 22px; overflow-y: auto; }
.field { display: block; margin-bottom: 16px; }
.field > span, .filter-group legend { display: block; margin-bottom: 7px; color: #44514b; font-size: 12px; font-weight: 700; letter-spacing: .08em; }

input[type="search"], select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: none;
}

input[type="search"]:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgb(23 107 82 / 12%); }
.region-field > label { display: block; margin-bottom: 7px; color: #44514b; font-size: 12px; font-weight: 700; letter-spacing: .08em; }
.region-search-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.region-search-row button {
  padding: 0 14px;
  color: white;
  background: var(--green);
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}
.region-search-row button:disabled { cursor: wait; opacity: .65; }
.field-message { min-height: 16px; margin: 5px 2px 0; color: var(--orange); font-size: 11px; line-height: 1.4; }
.field-message.success { color: var(--green); }
.geocoder-credit { margin: 1px 2px 0; color: #8a948f; font-size: 9px; }

.nearby-section { margin: 4px 0 20px; padding: 14px; background: #f0f6f3; border: 1px solid #d2e3dc; border-radius: 12px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading span { color: var(--muted); font-size: 10px; letter-spacing: .06em; }
.section-heading h2 { margin: 2px 0 0; font-family: serif; font-size: 18px; }
.section-heading .nearby-pin { display: grid; width: 30px; height: 30px; place-items: center; color: white; background: var(--green); border-radius: 50% 50% 50% 4px; font-size: 12px; font-weight: 800; }
.nearby-location { margin: 9px 0 8px; color: #516059; font-size: 10px; line-height: 1.45; }
.nearby-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; counter-reset: nearby; }
.nearby-list li { counter-increment: nearby; }
.nearby-place {
  display: grid;
  width: 100%;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 8px;
  text-align: left;
  background: white;
  border: 1px solid #d8e2dd;
  border-radius: 8px;
  cursor: pointer;
}
.nearby-place::before { display: grid; width: 20px; height: 20px; place-items: center; color: white; background: var(--green); border-radius: 50%; content: counter(nearby); font-size: 9px; font-weight: 800; }
.nearby-place:hover { border-color: #76a795; }
.nearby-place-name { min-width: 0; overflow: hidden; font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.nearby-place-distance { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.filter-group { margin: 0 0 18px; padding: 0; border: 0; }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }

.type-chip { position: relative; }
.type-chip input { position: absolute; opacity: 0; pointer-events: none; }
.type-chip span {
  display: flex;
  min-height: 37px;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #4d5953;
  background: white;
  cursor: pointer;
  font-size: 12px;
}
.type-chip span::before { width: 8px; height: 8px; flex: 0 0 auto; background: var(--chip-color); border-radius: 50%; content: ""; }
.type-chip input:checked + span { color: var(--ink); background: #eff7f3; border-color: #7aac9b; }

.toggle-row { display: flex; align-items: center; gap: 8px; min-height: 32px; color: #3f4d46; font-size: 13px; cursor: pointer; }
.toggle-row input { accent-color: var(--green); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; }
.status-dot.confirmed, .legend-marker.confirmed { background: var(--green); }
.status-dot.unknown, .legend-marker.unknown { background: white; border: 2px solid var(--orange); }

.reset-button {
  width: 100%;
  padding: 10px;
  color: var(--green);
  background: transparent;
  border: 1px solid #9ac0b3;
  border-radius: 9px;
  cursor: pointer;
}
.reset-button:hover { background: var(--green-soft); }

.sidebar-footer { margin-top: auto; padding: 13px 22px 18px; color: var(--muted); border-top: 1px solid var(--line); font-size: 10px; line-height: 1.55; }
.sidebar-footer p { margin: 3px 0; }

.map-panel, #map { position: relative; width: 100%; height: 100%; }
.map-toolbar { position: absolute; z-index: 800; top: 16px; right: 16px; display: flex; gap: 8px; }
.map-toolbar button {
  padding: 9px 14px;
  color: var(--ink);
  background: rgb(255 254 249 / 94%);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 5px 16px rgb(25 43 36 / 14%);
  cursor: pointer;
}
#open-sidebar { display: none; }

.recommendation-card {
  position: absolute;
  z-index: 790;
  top: 16px;
  left: 16px;
  width: min(460px, calc(100% - 220px));
  padding: 16px 17px;
  background: rgb(255 254 249 / 96%);
  border: 1px solid rgb(222 223 216 / 92%);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgb(25 43 36 / 17%);
  backdrop-filter: blur(7px);
}
.recommendation-meta { display: flex; align-items: center; gap: 8px; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: .08em; }
.recommendation-meta time { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; letter-spacing: 0; }
.recommendation-card h2 { margin: 7px 0 5px; font-family: serif; font-size: 20px; line-height: 1.35; }
.recommendation-card > p { margin: 0; color: #48564f; font-size: 12px; line-height: 1.58; }
.recommendation-source { display: inline-block; margin-top: 7px; color: var(--blue); font-size: 9px; line-height: 1.4; text-decoration: none; }
.recommendation-source[hidden] { display: none; }
.recommendation-source::before { content: "↗ "; }
.recommendation-actions { display: flex; gap: 7px; margin-top: 11px; }
.recommendation-actions button { padding: 7px 11px; border-radius: 7px; cursor: pointer; font-size: 10px; font-weight: 700; }
.recommendation-actions button:first-child { color: white; background: var(--green); border: 1px solid var(--green); }
.recommendation-actions button:last-child { color: var(--green); background: transparent; border: 1px solid #9ac0b3; }

.map-legend {
  position: absolute;
  z-index: 800;
  right: 16px;
  bottom: 24px;
  display: flex;
  gap: 14px;
  padding: 9px 12px;
  color: #47544e;
  background: rgb(255 254 249 / 94%);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 5px 16px rgb(25 43 36 / 12%);
  font-size: 11px;
}
.map-legend span { display: flex; align-items: center; gap: 6px; }
.legend-marker { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

.place-marker { display: grid; width: 19px; height: 19px; place-items: center; background: var(--marker-color); border: 3px solid white; border-radius: 50% 50% 50% 0; box-shadow: 0 2px 7px rgb(0 0 0 / 28%); transform: rotate(-45deg); }
.place-marker.unknown { background: white; border-color: var(--orange); }
.place-marker.closed { background: #7b8580; border-color: white; opacity: .75; }
.search-location-marker { display: grid; width: 26px; height: 26px; place-items: center; color: white; background: var(--blue); border: 3px solid white; border-radius: 50%; box-shadow: 0 2px 9px rgb(0 0 0 / 30%); font-size: 10px; font-weight: 800; }
.nearby-map-marker { display: grid; width: 25px; height: 25px; place-items: center; color: white; background: var(--green); border: 2px solid white; border-radius: 50%; box-shadow: 0 2px 8px rgb(0 0 0 / 28%); font-size: 10px; font-weight: 800; }

.marker-cluster-small, .marker-cluster-medium, .marker-cluster-large { background-color: rgb(23 107 82 / 22%); }
.marker-cluster-small div, .marker-cluster-medium div, .marker-cluster-large div { color: white; background-color: var(--green); font-weight: 700; }

.empty-state { position: absolute; z-index: 800; top: 50%; left: 50%; padding: 14px 18px; color: var(--muted); background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); transform: translate(-50%, -50%); }
.leaflet-control-attribution { font-size: 9px; }

.place-dialog {
  width: min(92vw, 470px);
  padding: 28px;
  color: var(--ink);
  background: var(--panel);
  border: 0;
  border-radius: 18px;
  box-shadow: 0 24px 70px rgb(10 30 22 / 30%);
}
.place-dialog::backdrop { background: rgb(12 27 21 / 52%); backdrop-filter: blur(2px); }
.dialog-close { position: absolute; top: 12px; right: 14px; padding: 2px 7px; color: var(--muted); background: transparent; border: 0; cursor: pointer; font-size: 27px; }
.dialog-eyebrow { margin: 0 32px 7px 0; color: var(--green); font-size: 11px; font-weight: 800; letter-spacing: .08em; }
.place-dialog h2 { margin: 0 28px 8px 0; font-family: serif; font-size: 25px; line-height: 1.35; }
.dialog-address { margin: 0 0 18px; color: #52605a; font-size: 13px; line-height: 1.55; }
.dialog-details { display: grid; gap: 1px; margin: 0; overflow: hidden; background: var(--line); border: 1px solid var(--line); border-radius: 10px; }
.dialog-details div { display: grid; grid-template-columns: 82px 1fr; gap: 10px; padding: 10px 12px; background: white; font-size: 12px; line-height: 1.45; }
.dialog-details dt { color: var(--muted); }
.dialog-details dd { margin: 0; }
.dialog-confirmation { margin: 14px 0; color: var(--muted); font-size: 11px; }
.dialog-actions { display: grid; grid-template-columns: 1fr 1.45fr; gap: 8px; }
.dialog-actions button, .dialog-actions a { display: grid; min-height: 43px; place-items: center; padding: 9px 12px; border-radius: 9px; cursor: pointer; font-size: 12px; font-weight: 700; text-decoration: none; }
.dialog-actions button { color: var(--green); background: white; border: 1px solid #9ac0b3; }
.dialog-actions a { color: white; background: var(--green); border: 1px solid var(--green); }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: absolute; inset: 0 auto 0 0; width: min(88vw, 350px); transition: transform .22s ease; }
  .sidebar:not(.is-open) { transform: translateX(-105%); }
  .mobile-close, #open-sidebar { display: block; }
  .map-toolbar { top: 12px; right: 12px; }
  .recommendation-card { top: 64px; right: 12px; left: 12px; width: auto; padding: 14px 15px; }
  .recommendation-card h2 { font-size: 18px; }
  .recommendation-card > p { font-size: 11px; }
  .map-legend { right: 12px; bottom: 20px; }
  .place-dialog { padding: 24px 20px 20px; }
}

@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
