:root {
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --coral: #f97316;
  --ink: #1e293b;
  --muted: #64748b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* editing controls only show once logged in */
body:not(.authed) .auth-only { display: none !important; }

.view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ===== Trips list ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 20px) 20px 12px;
  background: linear-gradient(135deg, var(--teal), var(--teal-dark));
  color: #fff;
}
.app-header .lock-btn {
  background: rgba(255, 255, 255, 0.18);
  font-size: 1rem;
}
.trip-lock { font-size: 1rem; }
.login-error { color: var(--danger); font-size: 0.85rem; margin: 0 0 12px; }

/* ===== Login gate ===== */
.login-view {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--teal), var(--teal-dark));
  padding: 24px;
}
.login-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.25);
  padding: 30px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo { font-size: 3rem; }
.login-card h1 { margin: 6px 0 4px; font-size: 1.5rem; }
.login-hint { margin: 0 0 18px; color: var(--muted); font-size: 0.9rem; }
.login-card input {
  width: 100%;
  padding: 13px;
  font-size: 1rem;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  margin-bottom: 12px;
}
.login-card input:focus { outline: 2px solid var(--teal); border-color: transparent; }
.login-card .btn-primary { width: 100%; }
.app-header h1 { margin: 0; font-size: 1.6rem; }
.app-header .subtitle { margin: 2px 0 0; opacity: 0.85; font-size: 0.9rem; }

.trips-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 96px;
}

.trip-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.trip-card .trip-emoji {
  font-size: 1.6rem;
  background: #ccfbf1;
  border-radius: 12px;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.trip-card .trip-info { flex: 1; min-width: 0; }
.trip-card h3 { margin: 0 0 2px; font-size: 1.05rem; }
.trip-card p { margin: 0; font-size: 0.82rem; color: var(--muted); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 24px;
  font-size: 0.95rem;
}
.empty-state .big { font-size: 2.6rem; display: block; margin-bottom: 8px; }

/* ===== Trip detail ===== */
.trip-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  z-index: 500;
}
.trip-header-text { min-width: 0; flex: 1; }
.trip-edit { font-size: 1rem; }
.trip-header h2 {
  margin: 0;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trip-header p { margin: 0; font-size: 0.78rem; color: var(--muted); }

.icon-btn {
  border: none;
  background: var(--bg);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 1.15rem;
  cursor: pointer;
  flex-shrink: 0;
}

#map {
  height: 42dvh;
  flex-shrink: 0;
  z-index: 1;
}
#map.pin-mode { cursor: crosshair; }

.pin-banner {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 1000;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.filter-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.chip.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.places-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 96px;
}

.day-header {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--teal-dark);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 6px 2px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.day-rule {
  flex: 1;
  height: 1px;
  background: var(--border);
}
.day-header-muted { color: var(--muted); }
.day-route {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  width: 32px;
  height: 30px;
  font-size: 0.95rem;
  cursor: pointer;
}
.day-route:active { background: var(--bg); }

.place-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.place-card.visited { opacity: 0.6; }
.place-card.visited .place-name { text-decoration: line-through; }
.place-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.place-icon { font-size: 1.3rem; margin-top: 1px; }
.place-info { flex: 1; min-width: 0; }
.place-name { font-weight: 600; font-size: 0.98rem; }
.place-addr {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.place-when {
  display: block;
  width: fit-content;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--teal-dark);
  background: #ccfbf1;
  border-radius: 8px;
  padding: 3px 8px;
  margin-top: 4px;
}
.place-room {
  display: block;
  width: fit-content;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 8px;
  margin-top: 4px;
}
/* itinerary shown on the card */
.itin-toggle {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 0;
  background: none;
  border: none;
  color: var(--teal-dark);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.itin-table {
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.itin-line {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px;
  padding: 8px 10px;
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}
.itin-line:first-child { border-top: none; }
.itin-line-date { color: var(--muted); font-weight: 600; }
.itin-line-port { font-weight: 600; }
.itin-line-times { color: var(--teal-dark); font-size: 0.74rem; margin-top: 1px; }
.place-notes {
  position: relative;
  font-size: 0.8rem;
  color: var(--coral);
  margin-top: 2px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  cursor: pointer;
}
.place-notes.expanded { display: block; -webkit-line-clamp: unset; }
/* fade the tail of the 2nd line so it's obvious there's more */
.place-notes.has-more:not(.expanded)::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 45%;
  height: 1.15em;
  background: linear-gradient(to right, rgba(255, 255, 255, 0), var(--card));
  pointer-events: none;
}
.notes-toggle {
  display: inline-block;
  margin-top: 4px;
  padding: 3px 0;
  background: none;
  border: none;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.place-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 0;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: #fff;
}
.nav-walk { background: var(--teal); }
.nav-drive { background: var(--ink); }
.mini-btn {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  width: 42px;
  font-size: 1rem;
  cursor: pointer;
}
.mini-btn.danger { color: var(--danger); }

/* ===== FAB ===== */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--coral);
  color: #fff;
  font-size: 1.9rem;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(249, 115, 22, 0.45);
  cursor: pointer;
  z-index: 600;
}

/* ===== Bottom sheets ===== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1100;
  display: flex;
  align-items: flex-end;
}
.sheet {
  background: var(--card);
  width: 100%;
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px);
  max-height: 86dvh;
  overflow-y: auto;
  animation: slideUp 0.22s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(40%); opacity: 0.5; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 4px auto 10px;
}
.sheet h3 { margin: 0 0 14px; font-size: 1.15rem; }

.sheet label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 12px;
}
.sheet input {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.sheet input:focus { outline: 2px solid var(--teal); border-color: transparent; }
.when-optional { font-weight: 400; color: var(--muted); opacity: 0.7; }

/* itinerary editor in the place sheet */
#itinerary-section { margin-bottom: 12px; }
.itin-head {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}
.itin-row {
  background: var(--bg);
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 8px;
}
.itin-row-top { display: flex; gap: 8px; }
.itin-row-top .itin-port {
  flex: 1;
  margin-top: 0;
  background: var(--card);
}
.itin-del {
  flex-shrink: 0;
  width: 38px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 10px;
  color: var(--danger);
  font-size: 0.9rem;
  cursor: pointer;
}
.itin-row-times {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.itin-row-times input {
  flex: 1;
  min-width: 0;
  margin-top: 0;
  background: var(--card);
  font-size: 0.85rem;
  padding: 9px 8px;
}
#btn-add-stop { margin-bottom: 4px; }
.sheet textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  resize: vertical;
  min-height: 90px;
}
.sheet textarea:focus { outline: 2px solid var(--teal); border-color: transparent; }
.row { display: flex; gap: 10px; }
.row label { flex: 1; }

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}
.btn-primary, .btn-secondary, .btn-outline {
  flex: 1;
  padding: 13px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
}
.btn-primary { background: var(--teal); color: #fff; border: none; }
.btn-secondary { background: var(--bg); color: var(--ink); border: none; }
.btn-outline {
  display: block;
  width: 100%;
  background: var(--card);
  border: 1.5px dashed var(--teal);
  color: var(--teal-dark);
  margin-bottom: 14px;
}

/* type selector */
.type-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.type-toggle button {
  flex: 1 1 28%;
  border: 1px solid var(--border);
  background: var(--card);
  padding: 9px 6px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.type-toggle button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

/* search */
.search-wrap { position: relative; margin-bottom: 14px; }
.search-wrap input {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.search-results { margin-top: 6px; }
.search-result {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  cursor: pointer;
}
.search-result:active { background: var(--bg); }
.search-result .sr-name { font-weight: 600; }
.search-result .sr-addr { color: var(--muted); font-size: 0.78rem; margin-top: 1px; }
.search-hint { color: var(--muted); font-size: 0.82rem; padding: 8px 2px; }

.picked-summary {
  background: #ccfbf1;
  color: var(--teal-dark);
  font-size: 0.82rem;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
}
.change-loc-btn {
  background: none;
  border: none;
  color: var(--teal-dark);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 2px 0 12px;
  cursor: pointer;
}

/* toast */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 1200;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

/* map marker */
.poi-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: var(--card);
  border: 2px solid var(--teal);
  border-radius: 50% 50% 50% 4px;
  box-shadow: var(--shadow);
}
.poi-marker.restaurant { border-color: var(--coral); }
.leaflet-popup-content { margin: 12px 14px; }
.popup-name { font-weight: 700; margin-bottom: 8px; }
.popup-actions { display: flex; gap: 6px; }
.popup-actions a {
  text-decoration: none;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 8px;
}

/* slightly roomier on tablets/desktop */
@media (min-width: 700px) {
  .trips-list, .places-list { max-width: 680px; margin: 0 auto; width: 100%; }
  .sheet { max-width: 560px; margin: 0 auto; border-radius: 20px; margin-bottom: 24px; }
  .sheet-backdrop { align-items: center; }
}
