/* Global reset */
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-x: none; /* prevent back behavior on some browsers*/
  padding-top: env(safe-area-inset-top);
  -webkit-tap-highlight-color: transparent;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  
  /* Initialize CSS variables with defaults */
  --input-base-height: 95px;
  --safe-area-bottom: env(safe-area-inset-bottom);
}

/* When keyboard is open, zero out the safe area bottom */
body.keyboard-open {
  --safe-area-bottom: 0px;
}

/* Status notch */
#statusNotch{
  position: fixed;
  top: 0; left: 0; right: 0;
  height: env(safe-area-inset-top);
  pointer-events: none;
  z-index: 9999;
}

/* Simple blur gradient overlay */
#statusNotch::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  mask: linear-gradient(to bottom, 
    rgba(0, 0, 0, 0.8) 0%,
    rgba(0, 0, 0, 0.5) 25%,
    transparent 75%
  );
  -webkit-mask: linear-gradient(to bottom, 
    rgba(0, 0, 0, 0.8) 0%,
    rgba(0, 0, 0, 0.5) 25%,
    transparent 75%
  );
  pointer-events: none;
}

/* Pure CSS: Handle notch behavior based on Condesa state */
body {
  padding-top: var(--safe-area-top, env(safe-area-inset-top));
}

body[data-condesa-collapsed="true"] {
  padding-top: 0 !important;
}

#condesa .messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 4px 20px 4px;
  display: flex;
  margin-top: 0px;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  justify-content: flex-end;
}

body[data-condesa-collapsed="true"] #condesa .messages {
  padding-bottom: calc(env(safe-area-inset-top) + 40px) !important;
}

/* Atlas: Map background using Mapbox */
#atlas {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0px;
  z-index: 1;
}

/* Mapbox controls - base styles */
.mapboxgl-ctrl-logo {
  transform: scale(0.6);
  margin-bottom: 0px !important;
  margin-left: 13px !important;
}

.mapboxgl-ctrl-bottom-left {
  left: -37px !important;
  bottom: calc(var(--input-base-height) - 11px);
}

.mapboxgl-ctrl-attrib-button {
  transform: scale(1.0);
  margin-bottom: 14px !important;
}

.mapboxgl-ctrl-attrib {
  transform: scale(0.7);
  transform-origin: bottom right;
}

.mapboxgl-ctrl-bottom-right {
  bottom: calc(var(--input-base-height) - 7px) !important;
  margin-right: -7px !important;
}

/* Offset Mapbox controls based on dynamic insets */
.mapboxgl-ctrl-top-right {
  right: var(--inset-right, 0px) !important;
  transition: right 220ms ease;
}

.mapboxgl-ctrl-bottom-right {
  right: calc(var(--inset-right, 0px)) !important;
  transition: right 220ms ease;
}

.mapboxgl-ctrl-bottom-left {
  left: calc(var(--inset-left, 0px) - 37px) !important;
}

/* Ensure Mapbox bottom-right controls don't use negative margin when shifting */
.mapboxgl-ctrl-bottom-right {
  margin-right: 0 !important;
}

/* Condesa: Draggable chat card */
#condesa {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(100dvh - var(--input-base-height));
  background: white;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  z-index: 2;
  transform: translateY(calc(100vh - 50px));
  transition: transform 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
  border-bottom-right-radius: 12px;
  border-bottom-left-radius: 12px;
  display: flex;
  flex-direction: column;
}

#condesa .messages::before {
  content: "";
  flex-grow: 1;
  min-height: 40px;
}

/* Details Drawer */
#drawerBackdrop {
  position: fixed;
  top: 0;
  bottom: 0;
  left: var(--inset-left, 0px);
  right: 0;
  background: transparent; /* allow full map interaction */
  pointer-events: none;     /* never intercept clicks */
  opacity: 0;               /* visually inert */
  transition: none;
  z-index: 2; /* under drawer, above map */
}

/* .open no longer used; kept for compatibility */

#detailsDrawer {
  position: fixed;
  z-index: 3;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: #111;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  outline: none;
}

/* Right-docked mode */
#detailsDrawer[data-mode="right"] {
  top: 20px;
  right: 20px;
  bottom: 20px;
  transform: translateX(calc(100% + 40px));
  transition: transform 220ms ease;
}

#detailsDrawer[data-mode="right"].open {
  transform: translateX(0%);
}

/* Bottom-sheet mode */
#detailsDrawer[data-mode="bottom"] {
  left: var(--inset-left, 0px);
  right: 0;
  bottom: 0;
  transform: translateY(100%);
  transition: transform 220ms ease;
  border-radius: 12px 12px 0 0;
  /* Inherit base panel translucency; keep behind input container */
  z-index: 3;
}

#detailsDrawer[data-mode="bottom"].open {
  transform: translateY(0%);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 12px 16px; /* extra top space for grip */
  border-bottom: 1px solid rgba(0,0,0,0.08);
  cursor: ns-resize; /* drag affordance on mobile bottom-sheet */
  touch-action: none;
  position: relative;
}

.drawer-grip {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 5px;
  background: rgba(0,0,0,0.25);
  border-radius: 999px;
}

/* Hide grip on desktop (right-docked mode) */
#detailsDrawer[data-mode="right"] .drawer-grip {
  display: none;
}

.drawer-title {
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0; /* allow ellipsis */
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-close {
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  border: none;
  background: rgba(43, 46, 56, 0.9);
  color: #ffffff;
  width: 32px;
  height: 32px;
  padding: 0;
  box-sizing: border-box;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  box-shadow: 0 6px 18px rgba(17, 31, 62, 0.25);
  flex: 0 0 32px;
  margin-left: 8px;
}
.drawer-close:focus { outline: none; }
.drawer-close:focus-visible { box-shadow: 0 0 0 2px rgba(255,255,255,0.3); }
.drawer-close:hover {
  background: rgba(43, 46, 56, 1);
  transform: scale(1.05);
}
.drawer-close:active {
  transform: scale(0.95);
}

.drawer-content {
  padding: 12px 16px;
  overflow: auto;
  flex: 1 1 auto;          /* allow content to grow and enable scrolling */
  min-height: 0;           /* critical for Safari to allow overflow inside flex */
  -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
}

/* Add extra bottom space on mobile bottom-sheet so content can scroll above input */
@media (max-width: 768px) {
  #detailsDrawer[data-mode="bottom"] .drawer-content {
    padding-bottom: calc(95px + 12px);
  }
}

/* Drawer content layout helpers */
.drawer-section { margin: 8px 0 4px 0; }
.media-layout { display: flex; gap: 12px; align-items: flex-start; }
/* Only portrait images place content next to them (row); landscape stacks (column) */
.media-layout.side-by-side { flex-direction: row; }
.media-layout.stacked { flex-direction: column; }
.media-layout.side-by-side .media-tile { flex: 0 0 200px; max-width: 45%; }
.media-layout.stacked .media-tile { width: 100%; }
.media-tile { flex: 0 0 auto; }
.media-figure { margin: 0; display: block; }
.media-imgwrap { position: relative; display: inline-block; border-radius: 12px; border: 1px solid #e9e9e9; overflow: hidden; }
.media-image {
  display: block;
  max-height: 160px;
  max-width: 100%;
  width: auto; height: auto;
  object-fit: contain;
}
.media-figure { position: relative; }
.media-info-btn {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.45);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
}
.media-credit {
  font-size: 12px;
  color: #666;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.license-badge { background: #eee; color: #333; padding: 0 6px; border-radius: 8px; text-decoration: none; }
.credit-toggle { margin-left: 6px; font-size: 12px; background: transparent; border: none; color: #555; cursor: pointer; }
.credit-details { font-size: 12px; color: #444; margin-top: 6px; }
.media-body { flex: 1 1 auto; min-width: 0; }
.meta-grid { display: grid; grid-auto-rows: minmax(20px, auto); row-gap: 6px; }
.meta-row { display: flex; gap: 8px; align-items: center; font-size: 13px; color: #333; }
.meta-row.address span:last-child { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meta-ico { width: 16px; display: inline-flex; justify-content: center; }
.media-desc { margin-top: 10px; font-size: 13px; color: #333; line-height: 1.5; }

/* On narrow screens, always stack image above text */
@media (max-width: 640px) {
  .media-layout.side-by-side { flex-direction: column; }
  .media-layout.side-by-side .media-tile { flex: 0 0 auto; max-width: 100%; }
}

/* Credit modal inside drawer */
.credit-modal.hidden { display: none; }
.credit-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
}
.credit-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.35); }
.credit-dialog {
  position: relative;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  max-width: 420px;
  width: calc(100% - 40px);
  max-height: 70vh;
  overflow: auto;
}
.credit-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid #eee; font-weight: 600; }
.credit-close { background: transparent; border: none; font-size: 20px; line-height: 1; cursor: pointer; }
.credit-body { padding: 12px 14px; font-size: 13px; color: #333; }
.credit-row { margin: 6px 0; }

#condesa .messages p {
  margin: 0 12px;
  padding: 2px 8px;
}

#condesa .messages .trip-card,
#condesa .messages .itinerary-card {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  flex-shrink: 0;
}

#condesa .handle-bar {
  height: 40px;
  background: none;
  backdrop-filter: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 11px 0 11px;
  cursor: grab;
  user-select: none;
  position: relative;
  touch-action: none;
}

#condesa .handle-bar .hamburger-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #333;
  font-size: 18px;
  width: 32px;
  height: 32px;
  transition: color 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#condesa .handle-bar .hamburger-icon:hover {
  color: #000;
}

#condesa .handle-bar .drag-icon {
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translate(-50%, -50%);
  width: 50px;
  height: 8px;
  background-color: #a7a6a6;
  border-radius: 4px;
}

#condesa .handle-bar .new-chat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #333;
  width: 38px;
  height: 38px;
  margin-bottom: 4px;
  transition: color 0.2s, transform 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#condesa .handle-bar .new-chat-icon svg {
  width: 28px;
  height: 28px;
}

#condesa .handle-bar .new-chat-icon:hover {
  color: #000;
}

#condesa .handle-bar .new-chat-icon:active {
  transform: scale(0.95);
}

#condesa .handle-bar .auth {
  border: 1px solid #aaa;
  border-radius: 18px;
  padding: 4px 8px;
  font-size: 16px;
}

/* Input container - base styles */
#inputContainer {
  box-sizing: border-box;
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: white;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  z-index: 4;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  min-height: var(--input-base-height, 95px);
  transition: box-shadow 0.3s ease;
  overflow: visible;
}

#inputContainer.bookings-open {
  box-shadow: 0 -2px 8px rgba(120, 190, 255, 0.4);
}

/* Bookings container - base styles */
#bookingsContainer {
  position: fixed;
  bottom: calc(var(--input-base-height, 95px) - 20px);
  left: 0;
  width: 100%;
  height: 0;
  overflow: hidden;
  background: white;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.2);
  z-index: 3;
  transition: height 0.3s ease;
  box-sizing: border-box;
}

#bookingsContainer.expanded {
  height: 140px;
}

.bookings-content {
  padding: 10px;
  height: 100%;
  overflow: hidden;
}

.bookings-content p {
  margin: 0;
  color: #666;
  text-align: center;
  font-size: 14px;
}

/* Horizontal scrolling container for booking cards */
.bookings-scroll-container {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 0;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.bookings-scroll-container::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

/* Base booking card styles - ticket-like appearance */
.booking-card {
  flex-shrink: 0;
  width: 220px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 1px solid #e5e5e5;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: all 0.2s ease;
}

.booking-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Booking header with icon and type */
.booking-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px 8px 16px;
}

.booking-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: white;
}

.flight-card .booking-icon {
  background: #007aff;
}

.hotel-card .booking-icon {
  background: #34c759;
}

.booking-type {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Flight card specific styles */
.flight-route {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 4px 12px;
}

.airport-info {
  text-align: left;
  flex: 1;
}

.airport-info:last-child {
  text-align: right;
}

.airport-code {
  font-size: 18px;
  font-weight: 700;
  color: #333;
  margin-bottom: 0px;
}

.city-name {
  font-size: 10px;
  color: #666;
  font-weight: 400;
}

.flight-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #007aff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: white;
  margin: 0 12px;
}

.flight-times {
  display: flex;
  justify-content: space-between;
  padding: 4px 12px 10px 12px;
}

.time-info {
  text-align: center;
  flex: 1;
}

.time-info:first-child {
  text-align: left;
}

.time-info:last-child {
  text-align: right;
}

.time {
  font-size: 12px;
  font-weight: 600;
  color: #333;
  margin-bottom: 2px;
}

.date {
  font-size: 12px;
  color: #666;
  font-weight: 500;
}

/* Hotel card specific styles */
.hotel-info {
  padding: 12px 16px 8px 16px;
}

.hotel-name {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 6px;
}

.hotel-address {
  font-size: 12px;
}

.hotel-address a {
  color: #007aff;
  text-decoration: none;
  font-weight: 500;
}

.hotel-address a:hover {
  text-decoration: underline;
}

.hotel-dates {
  display: flex;
  justify-content: space-between;
  padding: 8px 16px 12px 16px;
}

.date-info {
  text-align: center;
  flex: 1;
}

.date-label {
  font-size: 11px;
  color: #666;
  font-weight: 500;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.date-info .date {
  font-size: 14px;
  font-weight: 600;
  color: #333;
}

/* Input underlay */
#inputUnderlay {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background-color: rgb(248, 248, 248, 1);
  z-index: 1;
  opacity: 0;
  transition: opacity 0.5s ease;
  transition-delay: 0s;
  height: var(--input-base-height);
}

#inputUnderlay.visible {
  opacity: 1;
  transition-delay: 0.15s;
  height: 350px;
}

/* Input bar and controls */
#inputBar {
  display: flex;
  align-items: center;
  padding: 0px;
  width: 100%;
}

#inputBar textarea {
  flex: 1;
  box-sizing: border-box;
  padding: 8px;
  font-size: 18px;
  margin: 4px 6px 0px 6px;
  border: none;
  outline: none;
  resize: none;
  line-height: 1.4;
  height: 41px;
  min-height: 41px;
  max-height: 120px;
  overflow-y: auto;
  background: transparent;
  color: inherit;
  font-family: inherit;
}

#bottomRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 11px 10px 12px;
  overflow: visible;
}

#leftGroup {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: visible;
}

#pillButton {
  height: 30px;
  padding: 0 12px;
  border: 1px solid rgb(181, 181, 181);
  border-radius: 15px;
  background-color: white;
  color: black;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

#pillButton.selected {
  border-color: #78beff;
  color: #0285ff;
  background-color: #daedff;
}

#pillButton.selected .pill-icon {
  filter: brightness(0) saturate(100%) invert(28%) sepia(82%) saturate(1973%) hue-rotate(192deg) brightness(94%) contrast(89%);
}

.pill-icon {
  height: 18px;
  width: auto;
}

.local-icon {
  display: inline-block;
  width: 30px;
  height: 30px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  color: grey;
}

.icon-plus {
  background-image: url("/icons/plus2.svg");
}

.plus-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.plus-wrapper .icon-plus {
  cursor: pointer;
}

.plus-actions-dropdown {
  bottom: calc(100% + 12px);
  top: auto;
  left: 0;
  right: auto;
  min-width: 200px;
  z-index: 2000;
  width: 240px;
  max-width: calc(100vw - 24px);
  background: #fff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

#sendButton {
  cursor: pointer;
  border: none;
  background: none;
  /* Extended touch target */
  padding: 40px;
  margin: -40px;
  position: relative;
}

#sendButton i {
  font-size: 34px;
  color: rgb(176, 176, 176);
}

#sendButton.hasinput i {
  color: black;
}

#sendButton.responding i {
  color: black;
}

#entryButtons {
  display: flex;
  padding: 4px 8px;
}

/* Profile dropdown styles */
.profile-dropdown {
  position: absolute;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 160px;
  z-index: 100;
  display: none;
  overflow: hidden;
}

.user-email {
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  font-size: 14px;
  color: #333;
  background-color: white;
  font-weight: 500;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  max-width: 220px;
}

.profile-dropdown.show {
  display: block;
  animation: fadeIn 0.2s ease-out;
}

.dropdown-item {
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.2s;
  color: #333;
  display: flex;
  align-items: center;
}

.dropdown-item:hover {
  background-color: #f0f0f0;
}

.dropdown-item i {
  margin-right: 8px;
  width: 16px;
  text-align: center;
  color: #666;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInReverse {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.profile-dropdown.dropdown-above.show {
  animation: fadeInReverse 0.2s ease-out;
}

/* PWA Mode (Standalone) Media Query */
@media (display-mode: standalone) {
  #condesa .messages::before {
    min-height: 80px;
  }

  #bookingsContainer {
    bottom: calc(var(--input-base-height) + var(--safe-area-bottom) - 30px);
  }

  #inputContainer {
    min-height: calc(var(--input-base-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
  }
  #inputContainer .bottomRow {
    padding-bottom: 0px !important;
  }

  /* location button position needs to take account of the safe area bottom */
  #locationButton {
    bottom: calc(var(--input-base-height) + 14px + var(--safe-area-bottom));
    /* Ensure smooth transition when input height changes in PWA mode */
    transition: right 220ms ease, bottom 220ms ease, transform 0.2s, box-shadow 0.2s;
  }

  /*Mapbox attributions needs to take account of the safe area bottom */
  /* Mapbox controls - base styles */
  .mapboxgl-ctrl-logo {
    transform: scale(0.6);
    margin-bottom: 0px !important;
    margin-left: 13px !important;
  }

  .mapboxgl-ctrl-bottom-left {
    left: -37px !important;
    bottom: calc(var(--input-base-height) - 15px + var(--safe-area-bottom));
  }

  .mapboxgl-ctrl-attrib-button {
    transform: scale(1.0);
    margin-bottom: 14px !important;
  }

  .mapboxgl-ctrl-attrib {
    transform: scale(0.7);
    transform-origin: bottom right;
  }

  .mapboxgl-ctrl-bottom-right {
    bottom: calc(var(--input-base-height) - 11px + var(--safe-area-bottom) ) !important;
    margin-right: -7px !important;
  }
  
  @supports(padding: max(0px)) {
    #inputContainer {
      padding-bottom: max(var(--safe-area-bottom), 10px);
      min-height: calc(var(--input-base-height) + max(var(--safe-area-bottom), 10px));
    }
  }
  
  #atlas {
    bottom: 0px; /*calc(80px + var(--safe-area-bottom));*/
  }
}

/* Desktop Media Query */
@media screen and (min-width: 768px) {
  /* Condesa positioning */
  #condesa {
    right: auto;
    left: 20px;
    top: 20px;
    height: calc(100dvh - var(--input-base-height) - 40px);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    max-width: 540px;
    min-width: 380px;
    margin-left: auto;
    margin-right: auto;
    width: 33%;
  }
  
  /* Menu bar top corners on desktop */
  #condesa .menu-bar {
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
  }
  
  /* Input container positioning */
  #inputContainer {
    right: auto;
    left: 20px;
    bottom: 20px;
    border-bottom-right-radius: 12px;
    border-bottom-left-radius: 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    max-width: 540px;
    min-width: 380px;
    margin-left: auto;
    margin-right: auto;
    width: 33%;
  }
  
  /* Bookings container positioning */
  #bookingsContainer {
    right: auto;
    left: 20px;
    bottom: calc(20px + var(--input-base-height, 95px) - 20px);
    border-bottom-right-radius: 0px;
    border-bottom-left-radius: 0px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    max-width: 540px;
    min-width: 380px;
    margin-left: auto;
    margin-right: auto;
    width: 33%;
  }
  
  /* Input underlay positioning */
  #inputUnderlay {
    right: auto;
    left: 20px;
    bottom: 20px;
    border-bottom-right-radius: 12px;
    border-bottom-left-radius: 12px;
    box-sizing: border-box;
    max-width: 540px;
    min-width: 380px;
    margin-left: auto;
    margin-right: auto;
    width: 33%;
  }
  
  /* Map takes full screen */
  #atlas {
    bottom: 0px;
  }
  
  /* Desktop mapbox controls */
  .mapboxgl-ctrl-logo {
    transform: scale(0.7);
    margin-bottom: -11px !important;
    margin-left: 0px !important;
  }
  
  .mapboxgl-ctrl-bottom-left {
    left: 0px !important;
    bottom: 0px !important;
  }
  
  .mapboxgl-ctrl-attrib-button {
    transform: scale(0.6);
    margin-bottom: 0px !important;
  }
  
  .mapboxgl-ctrl-attrib {
    transform: scale(0.6);
    transform-origin: bottom right;
  }
  
  .mapboxgl-ctrl-bottom-right {
    bottom: 0px !important;
    margin-right: 0px !important;
  }
  
  /* Profile dropdown positioning */
  .profile-dropdown {
    right: 10px !important;
  }
}

/* Top buttons container - holds both pills with safe area spacing */
.top-buttons-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 12px 12px 0 12px;
  z-index: 10;
  pointer-events: none; /* Allow clicks through container */
}

/* Add extra padding for PWA mode with notch */
@media (display-mode: standalone) {
  .top-buttons-container {
    padding-top: calc(env(safe-area-inset-top) + 36px);
  }
}

/* Individual pill button with liquid glass effect */
.top-pill {
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 18px rgba(17, 31, 62, 0.12);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 2px 8px;
  pointer-events: auto; /* Pills are clickable */
  transition: all 0.2s ease;
}

.top-pill:hover {
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 24px rgba(17, 31, 62, 0.18);
}

/* Left pill with bird logo and model selector */
.left-pill {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 4px 0 2px;
}

.left-pill .logo {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.left-pill .logo img {
  height: 38px;
  width: auto;
  display: block;
  transition: transform 0.2s ease;
}

.left-pill .logo img.is-dancing {
  animation: birdDance 0.8s ease-in-out;
}

@keyframes birdDance {
  0% {
    transform: scale(1) rotate(0deg) translateY(0);
  }
  15% {
    transform: scale(1.05) rotate(-8deg) translateY(-3px);
  }
  35% {
    transform: scale(0.95) rotate(10deg) translateY(2px);
  }
  55% {
    transform: scale(1.05) rotate(-12deg) translateY(-4px);
  }
  75% {
    transform: scale(0.98) rotate(6deg) translateY(1px);
  }
  100% {
    transform: scale(1) rotate(0deg) translateY(0);
  }
}

/* Right pill - profile pic (no background, just the image) */
.right-pill {
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0;
}

.right-pill .profile-pic {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.right-pill .profile-pic:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

.right-pill .profile-pic:active {
  transform: scale(0.95);
}

.right-pill .profile-pic img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Hamburger icon */
.hamburger-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #333;
  font-size: 18px;
  width: 24px;
  height: 24px;
  transition: color 0.2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.hamburger-icon:hover {
  color: #000;
}

/* Vertical divider in left pill */
.pill-divider {
  width: 1px;
  height: 20px;
  background: rgba(0, 0, 0, 0.15);
  margin: 0 4px;
}

/* Model selector styles */
.model-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 0 6px 0 0px; /*right margin 6px*/
  position: relative;
  /* Mobile touch optimization */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.model-name {
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

.model-selector .fas {
  font-size: 12px;
  color: #666;
  transition: transform 0.2s;
}

.model-selector.open .fa-chevron-down {
  transform: rotate(180deg);
}

/* Model dropdown styles */
.model-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 8px 24px rgba(17, 31, 62, 0.15);
  min-width: 260px;
  z-index: 100;
  display: none;
  overflow: hidden;
  /* Fix initial positioning jump */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease-out, visibility 0.2s ease-out;
}

.model-dropdown.show {
  display: block;
  opacity: 1;
  visibility: visible;
}

.model-option {
  padding: 12px 16px;
  cursor: pointer;
  transition: background-color 0.2s;
  border-bottom: 1px solid #f0f0f0;
  /* Mobile touch optimization */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.model-option:last-child {
  border-bottom: none;
}

/* Only apply hover states on non-touch devices */
@media (hover: hover) and (pointer: fine) {
  .model-option:hover {
    background-color: rgba(240, 248, 255, 0.8);
  }
}

.model-option.selected {
  background-color: #f0f8ff;
}

.model-title {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-bottom: 2px;
}

.model-description {
  font-size: 12px;
  color: #666;
  font-weight: 400;
}

/* Premium model styles */
.model-divider {
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #f0f0f0;
  background: #fafafa;
}

.model-option.premium-locked {
  opacity: 0.7;
}

.model-option.premium-locked .model-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.premium-icon {
  color: #f7c948;
  font-size: 14px;
  flex-shrink: 0;
}

@media (hover: hover) and (pointer: fine) {
  .model-option.premium-locked:hover {
    background-color: rgba(247, 201, 72, 0.1);
  }
}

/* New chat action dropdown (plus button) */
.new-chat-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.new-actions-dropdown {
  position: absolute;
  top: calc(100% + 12px);
  right: -6px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 8px 24px rgba(17, 31, 62, 0.15);
  min-width: 260px;
  z-index: 120;
  display: none;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease-out, visibility 0.18s ease-out, transform 0.18s ease-out;
  transform: translateY(-4px);
}

.new-actions-dropdown.show {
  display: block;
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.new-actions-header {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 13px;
  color: #1f2937;
  letter-spacing: 0.01em;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.new-action-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: background-color 0.14s ease;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.new-action-item:last-child {
  border-bottom: none;
}

.new-action-item .action-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.new-action-item .action-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #374151;
  font-size: 16px;
}

.new-action-item .action-copy {
  display: flex;
  flex-direction: column;
  gap: 0px;
}

.new-action-item .action-title {
  font-size: 14px;
  font-weight: 500;
  color: #333;
}

.new-action-item.disabled {
  opacity: 0.85;
  cursor: not-allowed;
}

.new-action-item.disabled:hover {
  background: #fff;
}

.soon-pill {
  font-size: 12px;
  font-weight: 700;
  color: #4b5563;
  background: rgba(15, 23, 42, 0.06);
  border-radius: 999px;
  padding: 6px 10px;
  line-height: 1;
  white-space: nowrap;
}

/* New chat icon styles */
.new-chat-icon {
  cursor: pointer;
  color: #333;
  transition: color 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Mobile touch optimization */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.new-chat-icon:hover {
  color: #000;
}

.new-chat-icon:active {
  transform: scale(0.95);
}

/* Wanderfull branding styles */
.wanderfull-w {
  display: inline-block;
  color: #22c55e; /* Nice green color that matches "wanderfull" branding */
  font-weight: 700;
  font-size: 1.1em;
  margin-right: 4px;
  text-shadow: 0 1px 2px rgba(34, 197, 94, 0.3);
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  position: relative;
}

.wanderfull-w::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  border-radius: 3px;
  opacity: 0.1;
  z-index: -1;
  padding: 1px 3px;
  margin: -1px -3px;
}

/* Adjust spacing in model titles */
.model-title {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
}

/* Adjust the model name in the selector */
.model-name {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  display: flex;
  align-items: center;
}

/* Adjust messages container to account for menu bar */
#condesa .messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 4px 2px 4px;
  display: flex;
  margin-top: 0px;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  justify-content: flex-end;
}

/* ── LOCATION BUTTON ────────────────────────────────────────────────────── */
#locationButton {
  position: fixed;
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1; /* Above map but below other UI elements */
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);

  /* Mobile positioning: above input container */
  bottom: calc(var(--input-base-height) + 14px);
  right: calc(var(--inset-right, 0px) + 20px);

  /* Ensure smooth transition when input height changes */
  transition: right 220ms ease, bottom 220ms ease, transform 0.2s, box-shadow 0.2s;
}

#locationButton img {
  width: 24px;
  height: 24px;
  opacity: 0.8;
}

#locationButton:hover {
  background: rgba(255, 255, 255, 0.7);
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

#locationButton:active {
  transform: scale(0.95);
}

/* Pulse animation when active/loading */
#locationButton.active {
  animation: locationPulse 2s infinite;
}

#locationButton.loading {
  animation: locationPulse 1s infinite;
}

@keyframes locationPulse {
  0%, 100% {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15), 0 0 0 0 rgba(59, 130, 246, 0.4);
  }
  50% {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15), 0 0 0 8px rgba(59, 130, 246, 0);
  }
}

/* Desktop positioning: bottom right corner, away from other UI */
@media screen and (min-width: 768px) {
  #locationButton {
    bottom: 30px;
    right: calc(var(--inset-right, 0px) + 20px);
    width: 52px;
    height: 52px;
  }
  
  #locationButton img {
    width: 26px;
    height: 26px;
  }
}

/* Error toast styling */
.location-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 20px);
  left: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 9999;
  animation: slideDown 0.3s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.location-toast.error {
  background: rgba(220, 38, 38, 0.9);
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media screen and (min-width: 768px) {
  .location-toast {
    left: auto;
    right: 30px;
    max-width: 320px;
    top: 30px;
  }
}

/* ── MARKER POPUP OVERLAY ──────────────────────────────────────────────── */
/* Liquid glass popup container anchored to map markers */
#markerPopupOverlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.marker-popup {
  position: absolute;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 18px rgba(17, 31, 62, 0.12);
  padding: 12px 16px;
  min-width: 200px;
  max-width: 280px;
  pointer-events: auto;
  opacity: 0;
  transform: translate3d(0, 8px, 0) scale(0.96);
  transition: transform 200ms cubic-bezier(0.22, 1, 0.36, 1),
              opacity 200ms cubic-bezier(0.22, 1, 0.36, 1);
}

.marker-popup.marker-popup--visible {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
}

/* Popup content sections */
.marker-popup-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.marker-popup-thumbnail {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.marker-popup-title-group {
  flex: 1;
  min-width: 0;
}

.marker-popup-index {
  display: inline-block;
  width: 20px;
  height: 20px;
  background: #007aff;
  color: white;
  border-radius: 50%;
  text-align: center;
  line-height: 20px;
  font-size: 12px;
  font-weight: 600;
  margin-right: 6px;
  vertical-align: middle;
}

.marker-popup-title {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.marker-popup-time {
  font-size: 13px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 4px;
}

.marker-popup-time i {
  font-size: 11px;
  opacity: 0.7;
}

.marker-popup-description {
  font-size: 13px;
  color: #333;
  line-height: 1.4;
  margin-top: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Route popup variant */
.marker-popup.marker-popup--route .marker-popup-header {
  align-items: center;
}

.marker-popup-transport-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  flex-shrink: 0;
}

.marker-popup-route-label {
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 2px;
}

.marker-popup-route-details {
  font-size: 12px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 8px;
}

.marker-popup-route-details span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Positioning helper classes */
.marker-popup--below {
  transform-origin: top center;
}

.marker-popup--above {
  transform-origin: bottom center;
}

.marker-popup--left {
  transform-origin: center right;
}

.marker-popup--right {
  transform-origin: center left;
}

/* ── ACTION BUBBLE OVERLAY ─────────────────────────────────────────────── */
/* DOM overlay for action bubbles (similar to popups but interactive) */
#action-bubble-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1; /* Same level as popups, below UI */
}

/* Keep overlay non-interactive even when active - only bubbles are interactive */
#action-bubble-overlay.active {
  pointer-events: none;
}

/* Action bubble stack container */
.action-bubble-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none; /* Stack itself is non-interactive */
  transform: translate3d(0, 0, 0);
}

/* Individual action bubble */
.result-bubble.map-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 18px rgba(17, 31, 62, 0.12);
  cursor: pointer;
  transition: transform 200ms cubic-bezier(0.22, 1, 0.36, 1),
              opacity 200ms cubic-bezier(0.22, 1, 0.36, 1),
              background 0.2s ease,
              box-shadow 0.2s ease;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
  opacity: 0;
  transform: translate3d(0, 8px, 0) scale(0.96);
  width: fit-content;
  pointer-events: auto; /* Make bubbles clickable */
}

.result-bubble.map-action.map-action--visible {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
}

.result-bubble.map-action:hover {
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 10px 24px rgba(17, 31, 62, 0.18);
  transform: translate3d(0, -2px, 0) scale(1);
}

.result-bubble.map-action:active {
  transform: translate3d(0, 0, 0) scale(0.98);
}

/* Heading bubble with close button */
.result-bubble.map-action.map-action-heading {
  font-weight: 600;
  cursor: default;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.result-bubble.map-action.map-action-heading:hover {
  transform: translate3d(0, 0, 0) scale(1);
  background: rgba(255, 255, 255, 0.75);
}

.map-action-heading-title {
  pointer-events: none;
}

/* Close button in action bubble heading */
.map-action-close {
  border: none;
  background: rgba(43, 46, 56, 0.9);
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  box-shadow: 0 6px 18px rgba(17, 31, 62, 0.25);
  margin-right: -6px;
  flex-shrink: 0;
}

.map-action-close:hover {
  background: rgba(43, 46, 56, 1);
  transform: scale(1.05);
}

.map-action-close:active {
  transform: scale(0.95);
}

/* Stack orientation helpers */
.action-bubble-stack[data-orientation="left"] {
  align-items: flex-end;
}

.action-bubble-stack[data-orientation="right"] {
  align-items: flex-start;
}

.action-bubble-stack[data-orientation="top"],
.action-bubble-stack[data-orientation="bottom"] {
  align-items: center;
}

/* ── HISTORY SIDEBAR ───────────────────────────────────────────────────── */
/* Sidebar backdrop */
#sidebarBackdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 11; /* Above top pills, below sidebar */
}

#sidebarBackdrop.active {
  opacity: 1;
  visibility: visible;
}

/* History sidebar container */
#historySidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 320px;
  max-width: 85vw;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0);
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 12; /* Above backdrop */
  display: flex;
  flex-direction: column;
}

#historySidebar.open {
  transform: translateX(0);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
}

/* Sidebar header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  /* Account for safe area on mobile */
  padding-top: calc(env(safe-area-inset-top) + 20px);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #1a1a1a;
}

.sidebar-close {
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  border: none;
  background: rgba(43, 46, 56, 0.9);
  color: #ffffff;
  width: 32px;
  height: 32px;
  padding: 0;
  box-sizing: border-box;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  box-shadow: 0 6px 18px rgba(17, 31, 62, 0.25);
}

.sidebar-close:hover {
  background: rgba(43, 46, 56, 1);
  transform: scale(1.05);
}

.sidebar-close:active {
  transform: scale(0.95);
}

/* Sidebar content - scrollable list */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 0;
}

/* Individual conversation item */
.conversation-item {
  padding: 16px 20px;
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  transition: background-color 0.2s ease;
}

.conversation-item:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

.conversation-item:active {
  background-color: rgba(0, 0, 0, 0.06);
}

.conversation-preview {
  font-size: 15px;
  font-weight: 500;
  color: #1a1a1a;
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-date {
  font-size: 13px;
  color: #666;
  font-weight: 400;
}

/* Active conversation state */
.conversation-item.active {
  background-color: rgba(0, 123, 255, 0.08);
  border-left: 3px solid #007bff;
  padding-left: 17px;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.empty-state p {
  margin: 8px 0;
  color: #666;
  font-size: 15px;
}

.empty-state p:first-child {
  font-weight: 500;
  color: #333;
}

.empty-state-hint {
  font-size: 13px !important;
  color: #999 !important;
}
