:root {
  --bg: #f5f6fa; --surface: #ffffff; --surface-2: #eef0f6; --ink: #101828; --muted: #667085;
  --line: #e4e7ec; --brand: #2563eb; --brand-ink: #ffffff; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
  --c-transit: #2563eb; --c-lodging: #7c3aed; --c-car: #d97706; --c-event: #db2777;
  --c-sight: #059669; --c-food: #dc2626; --c-place: #64748b;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --surface: #141a2e; --surface-2: #1c2440; --ink: #eef1fb; --muted: #98a2b8;
    --line: #262f4d; --brand: #5b8cff; --brand-ink: #0b1020; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.35);
    --c-transit: #60a5fa; --c-lodging: #a78bfa; --c-car: #fbbf24; --c-event: #f472b6;
    --c-sight: #34d399; --c-food: #f87171; --c-place: #94a3b8;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 76px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }

.topbar { position: sticky; top: 0; z-index: 1000; display: flex; align-items: center; gap: 14px; padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; letter-spacing: -.02em; color: var(--ink); text-decoration: none; font-size: 17px; }
.brand-mark { display: inline-block; margin-right: 4px; vertical-align: -6px; border-radius: 7px; }
.topbar-trip { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#app { max-width: 1280px; margin: 0 auto; padding: 16px 16px 120px; }

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: default; }
input, select, textarea { width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

/* Home */
.home-head { display: flex; align-items: end; gap: 12px; margin: 8px 0 18px; }
.home-head h1 { font-size: 28px; letter-spacing: -.03em; }
.trip-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.trip-card { padding: 18px; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 10px; transition: transform .12s; position: relative; overflow: hidden; }
.trip-card:hover { transform: translateY(-2px); }
.trip-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 5px; background: linear-gradient(90deg, var(--c-transit), var(--c-lodging), var(--c-event)); }
.trip-card h3 { font-size: 19px; }
.trip-card .when { font-size: 13px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); font-size: 12px; font-weight: 700; }
.empty { text-align: center; padding: 56px 20px; }
.empty .big { font-size: 54px; }

/* Hero */
.hero { padding: 22px; margin-bottom: 14px; position: relative; overflow: hidden; background: linear-gradient(135deg, #1e3a8a 0%, #6d28d9 55%, #be185d 100%); color: #fff; border: 0; }
.hero a, .hero .btn { color: #fff; }
.hero .btn { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.28); }
.hero .btn:hover { background: rgba(255,255,255,.24); }
.hero-top { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.hero h1 { font-size: clamp(26px, 5vw, 38px); letter-spacing: -.03em; }
.hero .sub { opacity: .88; margin-top: 4px; }
.countdown { text-align: right; }
.countdown b { font-size: 40px; line-height: 1; display: block; letter-spacing: -.03em; }
.countdown span { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-top: 18px; }
.tile { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22); border-radius: 12px; padding: 10px 12px; }
.tile b { display: block; font-size: 22px; letter-spacing: -.02em; }
.tile span { font-size: 12px; opacity: .85; }
.bar { height: 6px; background: rgba(255,255,255,.25); border-radius: 9px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: #fff; border-radius: 9px; }

/* Day strip */
.daystrip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 12px; margin-bottom: 4px; scrollbar-width: thin; }
.day-chip { flex: 0 0 auto; min-width: 58px; text-align: center; padding: 8px 8px 7px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: inherit; }
.day-chip small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.day-chip b { font-size: 18px; display: block; }
.day-chip .dots { display: flex; gap: 3px; justify-content: center; min-height: 8px; margin-top: 2px; flex-wrap: wrap; }
.day-chip .dots i { width: 7px; height: 7px; border-radius: 50%; }
.day-chip.today { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 25%, transparent); }
.day-chip.empty-day { opacity: .55; }

/* Dashboard grid */
.dash { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 1000px) {
  .dash { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; }
  .dash > .left { grid-column: 1; }
  .dash > .map-card { grid-column: 2; grid-row: 1 / span 4; position: sticky; top: 64px; }
}
.section-head { display: flex; align-items: center; gap: 10px; margin: 6px 2px 10px; flex-wrap: wrap; }
.section-head h2 { font-size: 19px; letter-spacing: -.02em; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 4px 11px; font-size: 13px; font-weight: 600; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Up next */
.upnext { padding: 14px 16px; display: grid; gap: 10px; }
.upnext h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.live { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.live .ico { font-size: 22px; }
.live b { display: block; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); }
.badge.ok, .badge.landed { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.active { background: color-mix(in srgb, var(--brand) 18%, transparent); color: var(--brand); }
.badge.delayed { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.badge.cancelled { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

/* Itinerary */
.day { margin-bottom: 14px; }
.day-title { display: flex; align-items: baseline; gap: 8px; margin: 0 2px 6px; }
.day-title h3 { font-size: 15px; }
.day-title small { color: var(--muted); }
.entry { display: grid; grid-template-columns: 68px 1fr auto; gap: 10px; padding: 10px 12px; border-left: 4px solid var(--cat); border-radius: 12px; background: var(--surface); border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 6px; cursor: pointer; align-items: start; }
.entry:hover { background: var(--surface-2); }
.entry.derived { opacity: .72; border-style: dashed; border-left-style: solid; }
.entry .time { font-size: 13px; white-space: nowrap; font-weight: 700; color: var(--muted); padding-top: 1px; }
.entry .name { font-weight: 700; }
.entry .meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; }
.entry .ico { font-size: 18px; }
.entry .actions { display: flex; gap: 4px; align-items: center; }
.entry .status-line { margin-top: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.entry[data-cat="transit"] { --cat: var(--c-transit); } .entry[data-cat="lodging"] { --cat: var(--c-lodging); }
.entry[data-cat="car"] { --cat: var(--c-car); } .entry[data-cat="event"] { --cat: var(--c-event); }
.entry[data-cat="sight"] { --cat: var(--c-sight); } .entry[data-cat="food"] { --cat: var(--c-food); }
.entry[data-cat="place"] { --cat: var(--c-place); }
.ideas { border: 1.5px dashed var(--line); border-radius: 12px; padding: 10px 10px 4px; }

/* Packing */
.bags { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.bag { padding: 12px 14px; }
.bag header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bag header h3 { font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bag .kind { font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 700; letter-spacing: .05em; }
.ring { --p: 0; width: 34px; height: 34px; border-radius: 50%; background: conic-gradient(var(--ok) calc(var(--p) * 1%), var(--surface-2) 0); display: grid; place-items: center; flex: none; }
.ring::after { content: attr(data-label); width: 26px; height: 26px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-size: 10px; font-weight: 800; }
.bag.unassigned { border-style: dashed; }
.pk { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.pk input[type=checkbox] { width: 18px; height: 18px; flex: none; accent-color: var(--ok); }
.pk .pk-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pk.done .pk-name { text-decoration: line-through; color: var(--muted); }
.pk select.move { width: 28px; padding: 2px; border: 0; background: transparent; color: var(--muted); font-size: 13px; text-align: center; appearance: none; cursor: pointer; }
.pk .x { border: 0; background: transparent; color: var(--muted); padding: 0 4px; font-size: 16px; }
.qty { font-size: 12px; font-weight: 700; color: var(--muted); }
.add-line { display: flex; gap: 6px; margin-top: 6px; }
.add-line input { padding: 6px 9px; font-size: 14px; }

/* Map */
.map-card { overflow: hidden; display: flex; flex-direction: column; }
.map-tools { padding: 10px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.map-tools .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.map-tools .chip { white-space: nowrap; }
#map { height: 56vh; min-height: 360px; width: 100%; z-index: 0; }
@media (min-width: 1000px) { #map { height: calc(100vh - 360px); min-height: 360px; } }
.results { max-height: 200px; overflow: auto; border-top: 1px solid var(--line); }
.res { display: flex; gap: 8px; align-items: center; padding: 7px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.res .t { flex: 1; min-width: 0; cursor: pointer; }
.res .t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res .t small { color: var(--muted); }
.pin { width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--cat, #64748b); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); display: grid; place-items: center; }
.pin span { transform: rotate(45deg); color: #fff; font-size: 12px; font-weight: 800; }
.pin.found { background: #fff; border-color: var(--cat); } .pin.found span { color: var(--cat); }
.leaflet-popup-content { margin: 10px 12px; font: 14px/1.4 system-ui, sans-serif; color: #101828; }
.leaflet-popup-content b { display: block; }
.popup-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.popup-actions a, .popup-actions button { font-size: 12px; padding: 4px 9px; border-radius: 8px; border: 1px solid #d0d5dd; background: #fff; color: #101828; text-decoration: none; font-weight: 600; cursor: pointer; }
.popup-actions .go { background: #2563eb; border-color: #2563eb; color: #fff; }

/* FAB + modal */
.fab { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 1100; border: 0; width: 58px; height: 58px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); font-size: 30px; box-shadow: 0 8px 24px rgba(37,99,235,.45); }
.modal-bg { position: fixed; inset: 0; z-index: 2000; background: rgba(8,12,24,.55); display: flex; align-items: flex-end; justify-content: center; padding: 0; }
@media (min-width: 640px) { .modal-bg { align-items: center; padding: 20px; } }
.modal { width: 100%; max-width: 560px; max-height: 94vh; overflow: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 18px; box-shadow: var(--shadow); }
@media (min-width: 640px) { .modal { border-radius: 20px; } }
.modal h2 { font-size: 20px; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 480px) { .form-grid { grid-template-columns: 1fr; } }
.type-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.type-pick button { border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 2px; font-size: 12px; font-weight: 700; display: grid; gap: 2px; justify-items: center; }
.type-pick button span { font-size: 20px; }
.type-pick button.on { border-color: var(--cat); background: color-mix(in srgb, var(--cat) 14%, var(--surface)); }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.suggest { position: relative; }
.suggest-list { position: absolute; z-index: 5; inset: 100% 0 auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 200px; overflow: auto; }
.suggest-list button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; font-size: 13px; }
.suggest-list button:hover { background: var(--surface-2); }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 99px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 3000; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.login { max-width: 360px; margin: 14vh auto; padding: 24px; display: grid; gap: 12px; }

.day-title .btn.ghost { color: var(--brand); }
.day-empty { padding: 12px; border: 1.5px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: 13px; cursor: pointer; text-align: center; }
.day-empty:hover { background: var(--surface-2); }
.pk .pk-name { cursor: pointer; } .pk .pk-name:hover { text-decoration: underline dotted; }
.pin-state { font-size: 12px; margin-top: 4px; min-height: 0; color: var(--muted); overflow-wrap: anywhere; }
.pin-state.ok { color: var(--ok); } .pin-state.warn { color: var(--warn); }
.pin-state:empty { display: none; }

.route-panel { padding: 10px; border: 1.5px dashed var(--line); border-radius: 12px; background: var(--surface-2); }
.route-panel .row > * { min-width: 0; }
.rt-results { margin-top: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; max-height: 220px; overflow: auto; }
.rt-results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 8px 10px; }
.rt-results button:hover { background: var(--surface-2); }
.rt-results small { display: block; color: var(--muted); }
.rt-chip { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 8px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
details.stops { margin-top: 6px; font-size: 13px; }
details.stops summary { cursor: pointer; color: var(--brand); font-weight: 600; }
details.stops ol { margin: 6px 0 4px; padding: 0 0 0 18px; border-left: 2px solid var(--c-transit); list-style: none; }
details.stops li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0 2px 10px; position: relative; }
details.stops li::before { content: ""; position: absolute; left: -6px; top: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--surface); border: 2px solid var(--c-transit); }
details.stops li.end { font-weight: 700; } details.stops li.end::before { background: var(--c-transit); }
details.stops time { color: var(--muted); white-space: nowrap; }

.pin-wrap { position: relative; width: 28px; height: 28px; }
.pin-badge { position: absolute; top: -9px; right: -13px; background: #101828; color: #fff; font-style: normal; font-size: 10px; font-weight: 800; line-height: 1; padding: 3px 5px; border-radius: 99px; border: 1.5px solid #fff; }
ol.visits { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; }
ol.visits li button { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: #101828; text-align: left; cursor: pointer; text-decoration: underline dotted; }
ol.visits li i { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; text-align: center; background: #2563eb; color: #fff; font-style: normal; font-size: 11px; border-radius: 50%; margin-right: 6px; }
ol.visits li span { display: block; font-size: 12px; color: #667085; margin-left: 24px; }

.org { margin: 10px 0 0; padding: 8px 10px 6px; border: 1px solid var(--line); border-left: 4px solid var(--c-lodging); border-radius: 10px; background: var(--surface-2); }
.org-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 14px; }
.org .ring { width: 28px; height: 28px; } .org .ring::after { width: 21px; height: 21px; font-size: 9px; }
.add-org { margin-top: 8px; color: var(--brand); }

.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.person { display: flex; gap: 12px; padding: 12px 14px; cursor: pointer; align-items: flex-start; }
.person:hover { background: var(--surface-2); }
.person-body { min-width: 0; flex: 1; }
.person-name { font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.person .meta { font-size: 13px; color: var(--muted); display: flex; gap: 4px 12px; flex-wrap: wrap; margin-top: 2px; overflow-wrap: anywhere; }
.person .meta a { color: var(--brand); text-decoration: none; }
.avatar { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; font-weight: 800; font-size: 14px; color: #fff; background: hsl(var(--h) 55% 45%); }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; border: 2px solid var(--surface); }
.entry .who { display: flex; margin-top: 6px; }
.entry .who .avatar { margin-left: -6px; } .entry .who .avatar:first-child { margin-left: 0; }
#who .chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 4px; }
#who .chip[data-all] { padding-left: 10px; }
#who .chip.on .avatar.sm { border-color: var(--ink); }
