:root {
  --bg: #faf6ef;
  --card: #ffffff;
  --text: #4a2c1a;
  --text-soft: #8a6f5c;
  --accent: #e8590c;
  --accent-soft: #fff1e6;
  --green: #2f9e44;
  --green-soft: #e9f7ef;
  --line: #eadfce;
  --shadow: 0 4px 18px rgba(74, 44, 26, .12);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ---------- header ---------- */
#topbar {
  flex: 0 0 auto; height: 60px;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: linear-gradient(135deg, #fff8f0, #ffefdd);
  border-bottom: 1px solid var(--line);
  z-index: 1000;
}
.title-wrap { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
#topbar h1 { margin: 0; font-size: 20px; letter-spacing: .5px; white-space: nowrap; }
.subtitle { margin: 0; font-size: 12px; color: var(--text-soft); white-space: nowrap; }

.icon-btn {
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-size: 18px; cursor: pointer; flex: 0 0 auto;
}
.icon-btn:active { transform: scale(.94); }

/* ---------- layout ---------- */
#main { flex: 1 1 auto; display: flex; position: relative; min-height: 0; }
#map { flex: 1 1 auto; min-width: 0; z-index: 0; background: #efe6d8; }

/* ---------- sidebar ---------- */
#sidebar {
  flex: 0 0 360px; width: 360px;
  background: var(--bg); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
  transition: margin-right .25s ease;
  z-index: 900;
}
#main.sidebar-collapsed #sidebar { margin-right: -360px; }
#main.sidebar-collapsed .sheet-handle { display: none; }

.sheet-handle {
  display: none; width: 44px; height: 5px; border-radius: 3px;
  background: #d8c6b2; margin: 8px auto 2px; cursor: pointer;
}

.controls { padding: 12px 14px 8px; flex: 0 0 auto; }
#search {
  width: 100%; padding: 10px 14px; font-size: 15px;
  border: 1.5px solid var(--line); border-radius: 24px;
  background: var(--card); color: var(--text); outline: none;
}
#search:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; margin-top: 10px; }
.row select {
  flex: 1; min-width: 0; padding: 8px 6px; font-size: 13px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); outline: none;
}
.stats { margin-top: 10px; font-size: 12.5px; color: var(--text-soft); }

.spot-list { flex: 1 1 auto; overflow-y: auto; padding: 4px 14px 18px; }
.spot-card {
  display: flex; gap: 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; margin: 10px 0; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.spot-card:active { transform: scale(.98); }
.spot-thumb {
  width: 64px; height: 64px; border-radius: 10px; flex: 0 0 auto;
  object-fit: cover; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.spot-info { min-width: 0; flex: 1; }
.spot-name { font-weight: 700; font-size: 15px; margin: 0 0 2px; }
.spot-loc { font-size: 12px; color: var(--text-soft); }
.spot-dish { font-size: 13px; color: var(--accent); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 10px;
  margin-top: 6px; font-weight: 600;
}
.badge.todo { background: var(--accent-soft); color: var(--accent); }
.badge.done { background: var(--green-soft); color: var(--green); }

/* ---------- map pins ---------- */
.fm-pin {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
  border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
  cursor: pointer;
}
.fm-pin.todo { background: var(--accent); }
.fm-pin.done { background: var(--green); }
.fm-pin::after {
  content: ""; position: absolute; left: 50%; bottom: -9px;
  transform: translateX(-50%);
  border: 6px solid transparent; border-top-color: inherit;
}

/* ---------- popup ---------- */
.fm-popup .leaflet-popup-content { margin: 14px 16px; font-size: 14px; line-height: 1.5; }
.fm-popup .leaflet-popup-content-wrapper { border-radius: var(--radius); }
.pp-shop { font-size: 17px; font-weight: 800; margin: 0 0 6px; }
.pp-dish {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  font-weight: 700; padding: 3px 10px; border-radius: 8px; margin: 4px 0;
}
.pp-meta { font-size: 12.5px; color: var(--text-soft); margin: 6px 0; }
.pp-note { font-size: 13px; margin: 6px 0 0; }
.pp-photos { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.pp-photos img {
  width: 72px; height: 72px; object-fit: cover; border-radius: 10px; cursor: zoom-in;
}
.pp-toggle {
  display: block; width: 100%; margin-top: 8px; padding: 10px;
  border: none; border-radius: 10px; font-size: 14px; font-weight: 700;
  cursor: pointer; background: var(--accent); color: #fff;
}
.pp-toggle.is-done { background: var(--green); }
.pp-toggle:active { transform: scale(.97); }

/* ---------- empty state ---------- */
.empty-state {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(250, 246, 239, .92);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.empty-state.hidden { display: none; }
.empty-card {
  background: var(--card); border-radius: 20px; box-shadow: var(--shadow);
  padding: 40px 36px; text-align: center; max-width: 340px;
  border: 1px solid var(--line);
}
.empty-emoji { font-size: 52px; margin-bottom: 12px; }
.empty-card h2 { margin: 0 0 8px; font-size: 19px; }
.empty-card p { margin: 0; font-size: 14px; color: var(--text-soft); line-height: 1.6; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(30, 18, 10, .92);
  display: flex; align-items: center; justify-content: center;
}
.lightbox.hidden { display: none; }
.lightbox img {
  max-width: 92vw; max-height: 88vh; border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.lightbox .icon-btn {
  position: absolute; top: 18px; right: 18px;
  background: rgba(255,255,255,.18); color: #fff;
}

/* ---------- mobile ---------- */
@media (max-width: 768px) {
  #topbar { height: 54px; }
  #topbar h1 { font-size: 17px; }
  .subtitle { display: none; }

  #sidebar {
    position: absolute; left: 0; right: 0; bottom: 0; top: auto;
    width: auto; flex: none; height: 46%;
    border-left: none; border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    transform: translateY(calc(100% - 44px));
    transition: transform .28s ease;
    box-shadow: 0 -4px 20px rgba(74,44,26,.15);
  }
  #main.sidebar-collapsed #sidebar { margin-right: 0; transform: translateY(calc(100% - 44px)); }
  #sidebar.sheet-open { transform: translateY(0); }
  .sheet-handle { display: block; }
  #sidebarToggle { display: none; }
}
