:root {
  --bg: #f8fafc; --panel: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #0f766e; --accent-text: #ffffff; --danger: #b91c1c; --warn: #b45309;
  --hover: rgba(15, 118, 110, .07); --selected: rgba(15, 118, 110, .13);
  --radius: 12px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1220; --panel: #111a2e; --text: #e2e8f0; --muted: #94a3b8; --line: #1e293b;
          --accent: #14b8a6; --accent-text: #042f2e; --danger: #f87171; --warn: #fbbf24;
          --hover: rgba(20, 184, 166, .08); --selected: rgba(20, 184, 166, .16); }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
       -webkit-text-size-adjust: 100%; }
#app { min-height: 100%; display: flex; flex-direction: column; }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.warn { color: var(--warn); }
.spacer { flex: 1; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
       color: var(--text); padding: 8px 14px; border-radius: 999px; font: inherit; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.linkish { all: unset; cursor: pointer; }
.linkish:hover { text-decoration: underline; }
.linkish:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
       border-radius: 8px; padding: 9px 10px; font-size: 16px; /* 16px stops iOS zooming on focus */ }
@media (pointer: fine) { input, select, textarea { font-size: 15px; padding: 7px 10px; } }
label { display: block; margin: 10px 0; font-size: .85rem; color: var(--muted); }
label input, label select, label textarea { margin-top: 4px; }
.row { display: flex; gap: 10px; } .row > * { flex: 1; }

.bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
       background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.bar .btn { white-space: nowrap; flex-shrink: 0; padding-inline: 8px; }
.bar .title { flex: 1; min-width: 0; display: grid; }
.bar .title h1, .bar .title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page { padding: 16px; max-width: 720px; width: 100%; margin: 0 auto; }

.center-card { margin: 15vh auto 0; max-width: 360px; width: calc(100% - 32px); background: var(--panel); padding: 24px;
               border-radius: var(--radius); border: 1px solid var(--line); text-align: center; display: grid; gap: 12px; }

.trip-list { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 10px; }
.trip-list a { display: grid; gap: 2px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line);
               border-radius: var(--radius); color: inherit; text-decoration: none; }
.empty { color: var(--muted); padding: 20px 0; }

/* ── Trip page ─────────────────────────────────────────────────────────────
   Phone (default): sticky header + Plan/Map tabs + day chips; the page scrolls; the place panel is a full-screen sheet.
   Desktop (≥900px): day nav | itinerary | map, each scrolling on its own; the panel sits over the map's left edge. */
.trip-top { position: sticky; top: 0; z-index: 5; background: var(--panel); }
.trip-top .bar { position: static; }
.tabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 10px; border: 0; background: none; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.daychips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; border-bottom: 1px solid var(--line);
            scrollbar-width: none; }
.daychips::-webkit-scrollbar { display: none; }
.daychips button { flex-shrink: 0; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
                   background: var(--bg); color: var(--text); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .85rem; }
.daychips button.active { border-color: var(--accent); background: var(--selected); font-weight: 600; }
#app:has(.trip-layout[data-tab="map"]) .daychips { display: none; }

.trip-layout { flex: 1; display: flex; min-height: 0; }
.daynav { display: none; }
.plan { flex: 1; overflow-y: auto; padding: 12px 12px 80px; }
.resizer { display: none; }
.map-wrap { flex: 1; position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }
#map.picking .maplibregl-canvas { cursor: crosshair; }
.trip-layout[data-tab="plan"] .map-wrap { display: none; }
.trip-layout[data-tab="map"] .plan { display: none; }
.trip-layout[data-tab="map"] .map-wrap { height: calc(100dvh - 105px); }

.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot.none { background: transparent; }

.overview { padding: 4px 4px 12px; }
.overview h2 { font-size: 1.35rem; margin-bottom: 2px; }
.overview p { margin: 4px 0; }

.day { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px;
       scroll-margin-top: 12px; }
.day h2 { display: flex; align-items: center; gap: 8px; border-left: 4px solid var(--c, var(--muted)); padding-left: 6px; }
.day h2 .day-title { flex: 1; min-width: 0; }
.chev { all: unset; cursor: pointer; color: var(--muted); width: 22px; text-align: center; transition: transform .15s; }
.day.collapsed .chev { transform: rotate(-90deg); }
.day.collapsed h2 { margin-bottom: 0; }
.day.collapsed .places, .day.collapsed .add { display: none; }
.places { list-style: none; padding: 0; margin: 0; min-height: 8px; }
.place { display: block; padding: 10px 6px; border-top: 1px solid var(--line); cursor: pointer;
         border-radius: 8px; }
.place:first-child { border-top: 0; }
.place.hl { background: var(--hover); }
.place.selected { background: var(--selected); }
.place-main { display: flex; gap: 10px; align-items: flex-start; }
.place .body, .res .body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.place .notes { margin: 4px 0 0; font-size: .88rem; white-space: pre-wrap; }
.num { flex: 0 0 26px; height: 26px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.handle { color: var(--muted); padding: 2px 6px; cursor: grab; touch-action: none; font-size: 1.1rem; }
.sortable-ghost { opacity: .4; }
.add { margin-top: 8px; position: relative; }
.results { display: grid; }
.results button { all: unset; display: grid; padding: 8px; border-bottom: 1px solid var(--line); cursor: pointer; }
.results button:hover { background: var(--hover); }
.notes-section textarea { min-height: 120px; }

/* Place panel: full-screen sheet on phones. */
.panel { position: fixed; inset: 0; z-index: 20; background: var(--panel); overflow-y: auto; }
.panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
              border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.panel-head h2 { flex: 1; margin: 0; font-size: 1.1rem; min-width: 0; overflow-wrap: anywhere; }
.panel-body { padding: 4px 16px 24px; }
.panel-body textarea { resize: vertical; }
.saved { margin-top: 12px; }

.pin-wrap { cursor: pointer; }
.pin { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff; color: #fff; font-weight: 700; font-size: .8rem;
       box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: pointer; padding: 0; transition: transform .12s; display: block; }
.pin-wrap.hl, .pin-wrap.selected { z-index: 2; }
.pin-wrap.hl .pin { transform: scale(1.25); }
.pin-wrap.selected .pin { transform: scale(1.35); box-shadow: 0 0 0 3px var(--accent), 0 2px 6px rgba(0,0,0,.45); }
#pin-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: var(--panel); padding: 8px 12px;
              border-radius: 999px; box-shadow: 0 2px 8px rgba(0,0,0,.25); z-index: 4; white-space: nowrap; }

@media (min-width: 900px) {
  .tabs, .daychips { display: none; }
  #app:has(.trip-layout) { height: 100dvh; }
  /* Itinerary width is draggable (--plan-w, saved per browser); the map takes the rest. */
  .trip-layout { display: grid; grid-template-columns: 196px minmax(340px, var(--plan-w, 520px)) 6px minmax(320px, 1fr); overflow: hidden; }
  .trip-layout .plan, .trip-layout .map-wrap { display: block !important; }
  .trip-layout .map-wrap { height: auto !important; grid-column: 4; grid-row: 1; }
  .resizer { display: block; grid-column: 3; grid-row: 1; cursor: col-resize; background: var(--line); position: relative; touch-action: none; }
  .resizer::after { content: ''; position: absolute; inset: 0 -4px; }
  .resizer:hover, .trip-layout.resizing .resizer { background: var(--accent); }
  .trip-layout.resizing { user-select: none; cursor: col-resize; }
  .trip-layout.resizing #map { pointer-events: none; }

  .daynav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; padding: 12px 8px; border-right: 1px solid var(--line);
            background: var(--panel); }
  .daynav button { all: unset; display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; cursor: pointer; }
  .daynav button:hover { background: var(--hover); }
  .daynav button.active { background: var(--selected); font-weight: 600; }
  .daynav button:focus-visible { outline: 2px solid var(--accent); }
  .daynav .label { flex: 1; min-width: 0; display: grid; }
  .daynav .label .small { font-weight: 400; }
  .daynav .count { font-size: .75rem; color: var(--muted); background: var(--bg); border-radius: 999px; padding: 1px 7px; }

  .plan { padding: 16px 20px 60vh; }
  .trip-layout:has(.panel:not([hidden])) .map-search { left: calc(min(360px, 100%) + 10px); }
  .plan > section { max-width: 900px; margin-inline: auto; }
  .place .handle { opacity: 0; }
  .place:hover .handle, .place.selected .handle { opacity: 1; }

  .panel { position: relative; inset: auto; grid-column: 4; grid-row: 1; justify-self: start; width: min(360px, 100%); height: 100%;
           z-index: 3; border-right: 1px solid var(--line); box-shadow: 4px 0 16px rgba(0,0,0,.12); }
  .panel-head { padding-top: 12px; }
}

dialog { border: 0; border-radius: var(--radius); padding: 20px; width: min(480px, calc(100% - 24px)); background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.members { list-style: none; padding: 0; margin: 0; }
.members li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }

#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, calc(100% + 40px));
         background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; transition: transform .2s; z-index: 50; max-width: 90vw; }
#toast.show { transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

/* ── Travel time between stops ── */
.leg { display: flex; align-items: center; gap: 6px; margin: -4px 0 8px 5px; padding-left: 14px; border-left: 2px dotted var(--line); }
.leg-mode { all: unset; cursor: pointer; font-size: .9rem; padding: 1px 4px; border-radius: 6px; line-height: 1.2; }
.leg-mode:hover { background: var(--hover); outline: 1px solid var(--line); }

/* ── Reservations ── */
.res-list { list-style: none; padding: 0; margin: 0; }
.res { display: flex; gap: 10px; align-items: flex-start; padding: 10px 6px; border-top: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.res:first-child { border-top: 0; }
.res:hover { background: var(--hover); }
.res.selected { background: var(--selected); }
.res-icon { flex: 0 0 26px; text-align: center; font-size: 1.1rem; line-height: 26px; }
.res-icon.big { font-size: 1.3rem; }
.empty-res { padding: 4px 6px 8px; }
.add-res { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.day.collapsed .res-list, .day.collapsed .add-res, .day.collapsed .day-bookings { display: none; }
.day-bookings { list-style: none; margin: 0 0 6px; padding: 6px 8px; background: var(--bg); border-radius: 8px; display: grid; gap: 4px; }
.day-bookings li { display: flex; gap: 8px; font-size: .88rem; cursor: pointer; border-radius: 6px; padding: 2px 4px; }
.day-bookings li:hover { background: var(--hover); }
.day-bookings .time { font-variant-numeric: tabular-nums; font-weight: 600; }
.dot.icon { width: auto; height: auto; background: none; font-size: .8rem; }
.res-pin .pin { background: var(--panel); color: var(--text); border-color: var(--accent); font-size: .85rem; }

/* ── Google details in the panel ── */
.gd { padding: 12px 16px 4px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
.gd-photo { margin: 0; }
.ph { background: var(--bg); border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 10; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gd-photo figcaption { margin-top: 2px; }
.gd-line { font-size: .9rem; }
.stars { color: #d97706; font-weight: 600; }
.open { color: #16a34a; font-weight: 600; }
.closed { color: var(--danger); font-weight: 600; }
.gd-hours summary { cursor: pointer; color: var(--muted); }
.gd-hours ul { margin: 4px 0; padding-left: 18px; font-size: .85rem; }
.gd-links, .gd-more { display: flex; flex-wrap: wrap; gap: 12px; }
.gd-links a, .gd-more .linkish { color: var(--accent); }
.gd-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; margin-bottom: 8px; }
.gd-strip .ph { aspect-ratio: 1; }
.gd-reviews .review { border-top: 1px solid var(--line); padding-top: 6px; }
.gd-reviews p { margin: 4px 0 8px; white-space: pre-wrap; }
.gd-attr { font-size: .72rem; color: var(--muted); margin: 4px 0 8px; }

/* ── "Find on Google" inside the panel ── */
.lookup { margin: 12px 0; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; display: grid; gap: 6px; }
.lookup-bar { display: flex; gap: 6px; }
.lookup-bar input { flex: 1; }

/* ── Map search ── */
.map-search { position: absolute; top: 10px; left: 10px; z-index: 3; width: min(340px, calc(100% - 70px)); display: grid; gap: 6px; }
.ms-bar { position: relative; }
.ms-bar input { background: var(--panel); box-shadow: 0 2px 8px rgba(0,0,0,.2); border-radius: 999px; padding-left: 14px; padding-right: 34px; }
.ms-clear { all: unset; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); cursor: pointer; color: var(--muted); }
.ms-again { justify-self: center; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.ms-results { background: var(--panel); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.2); max-height: min(60vh, 520px);
              overflow-y: auto; padding: 4px 0; }
.ms-results[hidden], .ms-again[hidden] { display: none; }
.ms-head { display: flex; justify-content: space-between; padding: 6px 12px; }
.ms-note { padding: 8px 12px; margin: 0; }
.ms-item { border-top: 1px solid var(--line); }
.ms-row { all: unset; display: flex; gap: 10px; align-items: flex-start; padding: 8px 12px; cursor: pointer; width: 100%; box-sizing: border-box; }
.ms-row:hover, .ms-item.open .ms-row { background: var(--hover); }
.ms-row .body { display: grid; gap: 2px; min-width: 0; }
.ms-letter { flex: 0 0 22px; height: 22px; border-radius: 50%; border: 2px solid var(--text); display: grid; place-items: center;
             font-size: .72rem; font-weight: 700; }
.ms-detail { padding: 0 12px 10px 44px; display: grid; gap: 6px; }
.ms-detail a { color: var(--accent); }
.ms-add { display: flex; gap: 6px; }
.ms-add select { flex: 1; }
.results a { color: var(--accent); }
.ms-results .gd-attr { padding: 0 12px; }
.ms-pin button { width: 24px; height: 24px; border-radius: 50%; background: #fff; color: #0f172a; border: 2px solid #0f172a; font-weight: 700;
                 font-size: .72rem; cursor: pointer; padding: 0; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.ms-pin.open { z-index: 3; }
.ms-pin.open button { background: #0f172a; color: #fff; transform: scale(1.2); }
.ms-pin.added button { border-color: #16a34a; color: #16a34a; }
@media (max-width: 899px) {
  .map-search { width: calc(100% - 64px); }
  .ms-results { max-height: 40vh; }
}
