:root {
  --bg: #faf7f2; --surface: #ffffff; --text: #2b2420; --muted: #7a6e66; --line: #e8e0d6;
  --accent: #c2410c; --accent-soft: #fde7da;
  --confirmed: #15803d; --confirmed-soft: #dcfce7;
  --tentative: #b45309; --tentative-soft: #fef3c7;
  --danger: #b91c1c;
  --radius: 12px; --shadow: 0 6px 24px rgba(43, 36, 32, .12);
  --topbar: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1714; --surface: #26201c; --text: #f3ece5; --muted: #a8998d; --line: #3a312b;
    --accent: #fb923c; --accent-soft: #4a2a17;
    --confirmed: #4ade80; --confirmed-soft: #173523;
    --tentative: #fbbf24; --tentative-soft: #3d2f10;
    --danger: #f87171; --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.error { color: var(--danger); margin: 0; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.link { border: 0; background: none; padding: 6px 8px; color: var(--muted); }
button.link:hover { color: var(--text); }
button.danger { color: var(--danger); }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; }
label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- login ---------- */
.login-page { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--surface); padding: 28px; border-radius: var(--radius);
  box-shadow: var(--shadow); display: grid; gap: 14px; }
.login-card h1 span, .brand span { color: var(--accent); }

/* ---------- layout ---------- */
.topbar { height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--line); position: relative; z-index: 1000; }
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin: 0 auto; background: var(--bg); padding: 3px; border-radius: 999px; }
.tabs button { border: 0; background: none; padding: 6px 16px; }
.tabs button.active { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.who { display: flex; align-items: center; gap: 4px; }
.view { display: none; height: calc(100dvh - var(--topbar)); position: relative; }
.view.active { display: block; }
@media (max-width: 560px) { .brand { display: none; } .tabs { margin-left: 0; } .who .muted { display: none; } }

/* ---------- map view ---------- */
#map { position: absolute; inset: 0; right: 380px; z-index: 0; }
.panel { position: absolute; top: 0; right: 0; bottom: 0; width: 380px; background: var(--surface);
  border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; z-index: 500; }
.panel-handle { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
.panel-head p { margin: 2px 0 0; font-size: .85rem; }
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-row select { flex: 1; min-width: 0; }
.filter-row button { white-space: nowrap; }
.list-section { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 4px 0 8px; }

/* trip header in the list: tap to open the trip */
.trip-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; width: 100%; text-align: left; border: 0;
  border-left: 4px solid var(--trip); border-radius: 6px; background: var(--bg); padding: 7px 10px; margin-bottom: 4px; }
.trip-head .name { font-weight: 650; }
.trip-head .sub { flex-basis: 100%; font-size: .8rem; color: var(--muted); }
.trip-head:hover { filter: brightness(.97); }

/* trip panel: numbered stages joined by legs */
.stages { margin: 14px 0; }
.stage { display: flex; align-items: center; gap: 6px; }
.stage .num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--trip); color: #fff;
  display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.stage .place-item { flex: 1; min-width: 0; }
.stage .reorder { display: flex; flex-direction: column; }
.stage .reorder button { padding: 0 6px; line-height: 1.3; }
.stage .reorder button:disabled { opacity: .25; cursor: default; }
.leg { display: flex; align-items: center; gap: 8px; margin: 2px 0 2px 12px; padding: 4px 0 4px 20px;
  border-left: 2px dashed var(--trip); }
.leg select { width: auto; padding: 4px 8px; font-size: .85rem; }
.add-stage { width: 100%; }
.trip-link { padding: 0; color: var(--accent); }
.trip-head { flex-wrap: nowrap; }
.trip-text { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; min-width: 0; }
.trip-thumb { flex: none; width: 40px; height: 40px; border-radius: 6px; background: var(--bg) center/cover; }
.trip-cover { display: block; width: calc(100% + 32px); margin: -16px -16px 12px; height: 160px; object-fit: cover; }
@media (max-width: 800px) { .trip-cover { margin-top: -6px; height: 120px; } }
.drive-link { display: inline-block; margin: 4px 0 8px; color: var(--accent); text-decoration: none; font-weight: 600; }
.drive-link:hover { text-decoration: underline; }

/* gallery: ★ on the cover photo */
.gallery-item { position: relative; display: block; }
.cover-badge { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.55); color: #fde047; border-radius: 999px;
  width: 22px; height: 22px; display: grid; place-items: center; font-size: 13px; pointer-events: none; }
.lb-bar button:disabled { opacity: .7; cursor: default; color: #fde047; }

/* "From photos" in the pick banner */
.from-photos { display: flex; align-items: center; justify-content: center; gap: 6px; border: 1.5px dashed var(--accent);
  border-radius: 10px; padding: 10px; cursor: pointer; color: var(--accent); font-weight: 600; font-size: .9rem; }
.from-photos:hover { background: var(--accent-soft); }
.from-photos input { display: none; }

.stage-marker span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: #fff;
  font-weight: 700; font-size: .8rem; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.leg-badge { display: grid; place-items: center; font-size: 14px; background: var(--surface); border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.trip-group { margin-bottom: 14px; }
.trip-group > h4 { margin: 0 0 6px; font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.place-item { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 10px; cursor: pointer; width: 100%;
  text-align: left; border: 0; background: none; }
.place-item:hover, .place-item:focus-visible { background: var(--bg); }
.place-item .thumb { width: 48px; height: 48px; border-radius: 8px; background: var(--accent-soft) center/cover; flex: none;
  display: grid; place-items: center; color: var(--accent); font-size: 1.2rem; }
.place-item .meta { min-width: 0; }
.place-item .meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place-item .meta span { font-size: .82rem; color: var(--muted); }
.empty { text-align: center; padding: 24px 8px; color: var(--muted); }

.detail-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.detail-head h2 { flex: 1; }
.detail-notes { white-space: pre-wrap; margin: 8px 0 12px; }
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 12px 0; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: pointer; background: var(--bg); }
.upload-label { display: flex; align-items: center; justify-content: center; gap: 6px; border: 1.5px dashed var(--line);
  border-radius: 10px; padding: 14px; cursor: pointer; color: var(--muted); }
.upload-label:hover { border-color: var(--accent); color: var(--accent); }
.upload-label input { display: none; }
.detail-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.heart-marker { background: var(--accent); border: 2px solid #fff; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  width: 26px !important; height: 26px !important; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.heart-marker.has-photos::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: #fff; }
/* stages of a trip that hasn't happened yet: outlined instead of filled */
.heart-marker.planned { background: var(--surface); border: 3px dashed var(--accent); }
.heart-marker.planned.has-photos::after { background: var(--accent); }
.leaflet-popup-content { margin: 10px 12px; }
.popup-img { width: 180px; height: 120px; object-fit: cover; border-radius: 6px; display: block; margin-top: 6px; }

.pick-banner { position: absolute; top: 12px; left: 12px; width: min(340px, calc(100% - 24px)); z-index: 900;
  background: var(--surface); padding: 12px; border-radius: var(--radius); box-shadow: var(--shadow); display: grid; gap: 6px; }
.pick-banner p { margin: 0; }
#search-results button { display: block; width: 100%; text-align: left; border: 0; border-radius: 6px; padding: 6px 8px; font-size: .88rem; }
#search-results button:hover { background: var(--bg); }
#view-map.picking #map { cursor: crosshair; }

@media (max-width: 800px) {
  #map { right: 0; bottom: 38dvh; }
  .panel { top: auto; left: 0; width: auto; height: 38dvh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0; box-shadow: var(--shadow); padding-top: 6px; transition: height .2s; }
  .panel.expanded { height: calc(100dvh - var(--topbar) - 60px); }
  .panel-handle { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; cursor: pointer; }
}

/* ---------- plans view ---------- */
#view-plans { overflow-y: auto; }
.plans-wrap { max-width: 960px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }
.next-card { background: linear-gradient(135deg, var(--accent), #e11d48); color: #fff; border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); }
.next-card .big { font-size: 2rem; font-weight: 750; line-height: 1.1; }
.next-card p { margin: 4px 0 0; opacity: .92; }
.plans-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.plans-head h2 { margin-right: auto; }
.legend { display: flex; gap: 6px; }
.pill { font-size: .78rem; padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.pill.confirmed { background: var(--confirmed-soft); color: var(--confirmed); }
.pill.tentative { background: var(--tentative-soft); color: var(--tentative); border: 1px dashed var(--tentative); }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav h3 { min-width: 160px; text-align: center; }
.cal-nav button:not(.link) { width: 34px; height: 34px; padding: 0; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--line); gap: 1px;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.cal-dow { background: var(--surface); text-align: center; font-size: .75rem; color: var(--muted); padding: 6px 0; font-weight: 600; }
.cal-day { background: var(--surface); min-height: 92px; padding: 4px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal-day.other { background: var(--bg); } .cal-day.other .num { opacity: .45; }
.cal-day .num { font-size: .8rem; color: var(--muted); padding: 1px 4px; align-self: flex-start; border-radius: 999px; }
.cal-day.today .num { background: var(--accent); color: #fff; font-weight: 700; }
.cal-ev { font-size: .74rem; padding: 1px 5px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; border: 0; text-align: left; width: 100%; }
.cal-ev.confirmed { background: var(--confirmed); color: #fff; }
.cal-ev.tentative { background: var(--tentative-soft); color: var(--tentative); outline: 1px dashed var(--tentative); outline-offset: -1px; }
.cal-ev.cont { opacity: .75; }
@media (max-width: 560px) {
  .cal-day { min-height: 58px; padding: 2px; }
  .cal-ev { font-size: 0; height: 6px; padding: 0; }   /* dots-only on phones; tap a day's bar to open */
}
.event-card { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; width: 100%; text-align: left; }
.event-card.tentative { border-style: dashed; border-color: var(--tentative); }
.event-card .date { text-align: center; min-width: 48px; }
.event-card .date b { display: block; font-size: 1.3rem; line-height: 1; }
.event-card .date span { font-size: .72rem; text-transform: uppercase; color: var(--muted); }
.event-card .body { flex: 1; min-width: 0; }
.event-card .body small { color: var(--muted); }
details summary { cursor: pointer; padding: 6px 0; }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(460px, calc(100% - 24px)); background: var(--surface);
  color: var(--text); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(20, 14, 10, .45); }
dialog form { padding: 20px; display: grid; gap: 12px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.spacer { flex: 1; }
fieldset.status-choice { border: 0; padding: 0; margin: 0; display: flex; gap: 16px; }
fieldset.status-choice legend { font-size: .9rem; color: var(--muted); margin-bottom: 4px; }
fieldset.status-choice label { display: flex; align-items: center; gap: 6px; color: var(--text); }
fieldset.status-choice input { width: auto; }
.lightbox { width: min(1100px, calc(100% - 16px)); background: #000; }
.lightbox img { display: block; max-width: 100%; max-height: calc(100dvh - 120px); margin: 0 auto; }
.lb-bar { display: flex; align-items: center; gap: 8px; padding: 8px; background: #111; }
.lb-bar .muted { margin-right: auto; color: #aaa; }
.lb-bar button { background: none; color: #eee; border-color: #333; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; z-index: 3000; box-shadow: var(--shadow); font-size: .9rem; }
