:root {
  --ink:      #1a1f1c;
  --sand:     #f0e8d6;
  --sand2:    #e2d5bc;
  --watt:     #5c7a5e;
  --sea:      #3a6b7a;
  --amber:    #c47c2a;
  --rust:     #a84e2a;
  --mist:     #d4e3e8;
  --panel:    #ffffff;
  --radius:   12px;
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: 'Karla', sans-serif;
  font-weight: 300;
  background: var(--sand);
  color: var(--ink);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── HEADER ── */
header {
  background: var(--ink);
  color: var(--sand);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 1000;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

header h1 {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

header .subtitle {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  opacity: 0.45;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-small {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--sand);
  font-family: 'Karla', sans-serif;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-small:hover { background: rgba(255,255,255,0.2); }
.btn-small.active { background: var(--amber); border-color: var(--amber); color: white; }

.select-small {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--sand);
  font-family: 'Karla', sans-serif;
  font-size: 11px;
  font-weight: 500;
  padding: 5px 8px;
  border-radius: 20px;
  cursor: pointer;
  outline: none;
}

/* ── LAYOUT ── */
.app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 340px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--sand2);
  overflow: hidden;
  z-index: 100;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--sand2);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 12px 8px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: center;
  cursor: pointer;
  color: #999;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab.active { color: var(--sea); border-bottom-color: var(--sea); }

.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: flex; flex-direction: column; }

/* ── TRIP FORM TOGGLE (sticky button) ── */
.trip-form-toggle {
  padding: 12px 16px;
  border-bottom: 1px solid var(--sand2);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 10;
}

.btn-add-tour {
  width: 100%;
  background: white;
  border: 1px dashed var(--sea);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Karla', sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--sea);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.5px;
}

.btn-add-tour:hover { background: var(--sea); color: white; border-style: solid; }

/* ── TRIP FORM WRAPPER ── */
.trip-form-wrapper {
  border-bottom: 2px solid var(--sea);
  flex-shrink: 0;
}

/* ── DAY LIST ── */
.day-item {
  border-bottom: 1px solid var(--sand2);
  cursor: pointer;
  transition: background 0.15s;
}

.day-item:hover { background: #fafaf8; }
.day-item.selected { background: #f4f0e8; }

.day-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px 10px;
}

.day-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fraunces', serif;
  font-size: 13px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.day-info { flex: 1; }

.day-title {
  font-family: 'Fraunces', serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
}

.day-meta {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
  letter-spacing: 0.5px;
}

.day-stops {
  padding: 0 16px 12px 60px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stop-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  color: #555;
  line-height: 1.4;
}

.stop-icon { font-size: 13px; flex-shrink: 0; margin-top: 1px; }

.stop-time {
  font-size: 11px;
  color: #999;
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  flex-shrink: 0;
}

/* ── LOCATION LIST ── */
.loc-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--sand2);
  flex-shrink: 0;
}

.loc-search input {
  border: 1px solid var(--sand2);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: 'Karla', sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: var(--sand);
  outline: none;
}

.loc-search input:focus { border-color: var(--sea); }

.loc-list { flex: 1; overflow-y: auto; }

.loc-category {
  padding: 10px 16px 4px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #aaa;
  background: #fafaf8;
  border-bottom: 1px solid var(--sand2);
  position: sticky;
  top: 0;
}

.loc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid #f4f0e8;
  cursor: pointer;
  transition: background 0.15s;
}

.loc-item:hover { background: #f9f6f0; }
.loc-item.highlighted { background: #eef4f0; }

.loc-badge {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  position: relative;
}

.loc-stop-num {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
  color: white;
  border: 1.5px solid white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.loc-name { font-size: 13px; font-weight: 400; color: var(--ink); line-height: 1.3; }
.loc-type { font-size: 11px; color: #999; margin-top: 1px; }
.loc-note { font-size: 11px; color: #999; font-style: italic; margin-top: 1px; }

/* ── ADD TRIP PANEL ── */
.add-trip-panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  overflow-y: auto;
}

.form-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 4px;
  display: block;
}

.form-input {
  width: 100%;
  border: 1px solid var(--sand2);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: 'Karla', sans-serif;
  font-size: 13px;
  color: var(--ink);
  background: white;
  outline: none;
}

.form-input:focus { border-color: var(--sea); }

.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}

.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--ink); }

.stop-selector {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--sand2);
  border-radius: 8px;
}

.stop-selector .loc-item {
  border-bottom: 1px solid #f4f0e8;
  padding: 8px 12px;
}

.stop-selector .loc-item:last-child { border-bottom: none; }

.checkbox {
  width: 16px;
  height: 16px;
  border: 2px solid #ccc;
  border-radius: 4px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: white;
  transition: all 0.15s;
}

.loc-item.checked .checkbox {
  background: var(--sea);
  border-color: var(--sea);
}

.btn-primary {
  background: var(--ink);
  color: var(--sand);
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-family: 'Karla', sans-serif;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.2s;
  width: 100%;
}

.btn-primary:hover { opacity: 0.85; }

.selected-stops-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stop-chip {
  background: var(--sand);
  border: 1px solid var(--sand2);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stop-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}

.stop-chip-num {
  background: var(--sea);
  color: white;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
  flex-shrink: 0;
}

.stop-chip-name {
  flex: 1;
}

.stop-chip-time {
  width: 70px;
  border: 1px solid var(--sand2);
  border-radius: 6px;
  padding: 2px 4px;
  font-family: 'Karla', sans-serif;
  font-size: 11px;
  color: var(--ink);
  background: white;
  outline: none;
  flex-shrink: 0;
}

.stop-chip-time:focus { border-color: var(--sea); }

.stop-chip-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

/* ── MAP ── */
#map {
  flex: 1;
  z-index: 1;
}

/* ── LEAFLET CUSTOM ── */
.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 0.2s, width 0.2s, height 0.2s;
}

.custom-marker .inner {
  transform: rotate(45deg);
  font-size: 14px;
  line-height: 1;
}

.custom-marker.dim {
  opacity: 0.25;
}

.custom-marker.pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
  50% { box-shadow: 0 2px 20px rgba(0,0,0,0.5), 0 0 0 6px rgba(255,255,255,0.3); }
}

.leaflet-locate-btn {
  width: 30px;
  height: 30px;
  background: white;
  border: 2px solid rgba(0,0,0,0.2);
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3a6b7a;
  box-shadow: 0 1px 5px rgba(0,0,0,0.15);
}
.leaflet-locate-btn:hover { background: #f4f4f4; }

.leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  font-family: 'Karla', sans-serif;
}

.popup-title {
  font-family: 'Fraunces', serif;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.popup-type { font-size: 11px; color: #888; margin-bottom: 6px; }
.popup-note { font-size: 11px; color: #888; font-style: italic; margin-bottom: 6px; }
.popup-days { font-size: 11px; color: var(--sea); font-weight: 500; margin-bottom: 6px; }

.popup-gmaps {
  display: inline-block;
  font-size: 11px;
  color: var(--sea);
  text-decoration: none;
  font-weight: 500;
}

.popup-gmaps:hover { text-decoration: underline; }

/* ── MAP LEGEND ── */
.map-legend {
  position: absolute;
  bottom: 24px;
  right: 24px;
  background: white;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12);
  z-index: 500;
  font-size: 11px;
}

.legend-title {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #aaa;
  margin-bottom: 8px;
  font-weight: 500;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: #444;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--sand2); border-radius: 2px; }

/* ── EMPTY STATE ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: #aaa;
  gap: 8px;
}

.empty-state .icon { font-size: 32px; }
.empty-state p { font-size: 13px; line-height: 1.5; }

.divider {
  height: 1px;
  background: var(--sand2);
  margin: 4px 0;
}

.day-item .toggle {
  font-size: 10px;
  color: #bbb;
  transition: transform 0.2s;
}

.btn-filter-trip {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.4;
  transition: opacity 0.15s;
  line-height: 1;
}
.btn-filter-trip:hover { opacity: 0.8; }
.btn-filter-trip.active { opacity: 1; filter: drop-shadow(0 0 3px rgba(92,122,94,0.8)); }

.day-item.expanded .toggle { transform: rotate(180deg); }
.day-stops { display: none; }
.day-item.expanded .day-stops { display: flex; }

/* ── INLINE BUTTONS (Trip actions) ── */
.btn-inline {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  color: #888;
  cursor: pointer;
  font-family: 'Karla', sans-serif;
  transition: all 0.15s;
}

.btn-inline:hover { border-color: #bbb; color: #555; }
.btn-inline-danger:hover { border-color: #d88; color: #a44; }

/* ── LOCATION ACTIONS ── */
.loc-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.loc-item:hover .loc-actions { opacity: 1; }

.loc-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  color: #999;
  text-decoration: none;
  line-height: 1;
  border-radius: 4px;
  transition: background 0.15s;
}

.loc-action-btn:hover { background: rgba(0,0,0,0.05); color: #555; }

/* ── LOCATION FORM ── */
.loc-form {
  padding: 12px 16px;
  border-bottom: 1px solid var(--sand2);
  background: #fafaf8;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.loc-form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.loc-form-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.loc-form-row .form-input { flex: 1; }

.icon-picker-wrap {
  position: relative;
}

.icon-picker-btn {
  width: 44px;
  height: 38px;
  font-size: 20px;
  background: var(--input-bg, #f5f0e8);
  border: 1px solid #d4c9b0;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-picker-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 1000;
  background: white;
  border: 1px solid #d4c9b0;
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  width: 220px;
}

.icon-picker-dropdown .form-input {
  width: 100%;
  margin-bottom: 8px;
  box-sizing: border-box;
}

.icon-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  max-height: 180px;
  overflow-y: auto;
}

.icon-option {
  width: 34px;
  height: 34px;
  font-size: 18px;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-option:hover { background: #f0ebe0; }

.btn-pick {
  width: 36px;
  height: 36px;
  border: 1px solid var(--sand2);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.btn-pick:hover { border-color: var(--sea); }
.btn-pick.active { background: var(--sea); border-color: var(--sea); }

/* ── LOCATION SEARCH ROW ── */
.loc-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.loc-search-row input { flex: 1; }

.btn-add-loc {
  width: 34px;
  height: 34px;
  border: 1px solid var(--sand2);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  font-size: 18px;
  font-weight: 300;
  color: var(--sea);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.btn-add-loc:hover { background: var(--sea); color: white; border-color: var(--sea); }

/* ── SECONDARY BUTTON ── */
.btn-secondary {
  background: white;
  color: #888;
  border: 1px solid var(--sand2);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: 'Karla', sans-serif;
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}

.btn-secondary:hover { border-color: #bbb; color: #555; }

/* ── HEADER SEPARATOR ── */
.header-sep {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.15);
  margin: 0 4px;
}

/* ── SELECT STYLING ── */
select.form-input {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ── PASSWORD OVERLAY ── */
.pw-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(26,31,28,0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pw-box {
  background: white;
  border-radius: 16px;
  padding: 32px;
  width: 320px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.3);
}

.pw-box h2 {
  font-family: 'Fraunces', serif;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--ink);
}

/* ── SHEET HANDLE (desktop: hidden) ── */
.sheet-handle { display: none; }

/* ═══════════════════════════════════════════
   MOBILE  (≤ 768 px)
   Map takes full screen, sidebar = bottom sheet
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Header ── */
  header {
    padding: 0 14px;
    height: 52px;
  }
  header .subtitle { display: none; }
  header h1 { font-size: 1.1rem; }
  .header-actions { gap: 4px; }
  .btn-small { padding: 4px 10px; font-size: 10px; min-height: 32px; }
  .header-sep { display: none; }

  /* ── Layout: map fills remaining viewport ── */
  .app {
    position: relative;
  }

  #map {
    position: absolute;
    inset: 0;
    z-index: 1;
  }

  .map-legend { display: none; }

  /* ── Bottom Sheet ── */
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 72vh;
    border-radius: 18px 18px 0 0;
    border-right: none;
    border-top: 1px solid var(--sand2);
    box-shadow: 0 -6px 28px rgba(0,0,0,0.14);
    /* collapsed: only handle + tab bar peek out */
    transform: translateY(calc(100% - 56px));
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
    overflow: hidden;
  }

  .sidebar.sheet-open {
    transform: translateY(0);
  }

  /* ── Pull handle ── */
  .sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0 6px;
    cursor: pointer;
    flex-shrink: 0;
    background: var(--panel);
  }

  .sheet-handle::before {
    content: '';
    width: 40px;
    height: 4px;
    background: var(--sand2);
    border-radius: 2px;
  }

  /* Tab bar stays at collapsed height, acts as navigation */
  .sidebar-tabs {
    cursor: pointer;
    flex-shrink: 0;
  }

  .tab { padding: 10px 8px; }

  /* ── Location actions: always visible (no hover on touch) ── */
  .loc-actions { opacity: 1; }

  /* ── Larger tap targets ── */
  .loc-item { padding: 12px 16px; min-height: 52px; }
  .day-header { padding: 16px 16px 12px; }
  .loc-action-btn { padding: 6px 8px; font-size: 15px; }
  .btn-inline { padding: 7px 12px; font-size: 12px; }

  /* ── Offline banner above sheet ── */
  #save-banner { bottom: 72px !important; }

  /* ── Login box full-width on small screens ── */
  .pw-box { width: calc(100% - 40px); max-width: 360px; padding: 28px 20px; }
}
