:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --brand-50: #f0f7ff;
  --brand-100: #e0f0fe;
  --brand-400: #3388e6;
  --brand-500: #0066cc;
  --brand-600: #0050a0;
  --brand-900: #002850;

  --cat-transit: #3b82f6;
  --cat-hotel: #8b5cf6;
  --cat-food: #ef4444;
  --cat-activity: #f59e0b;
  --cat-info: #64748b;
}

/* Base Body Styles & iOS Elastic Drag Lock / PWA Chin Gap & Full Viewport Fill Fix */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --vh: 1vh;
}

/* Hide all scrollbars globally across all elements & browsers */
* {
  -ms-overflow-style: none !important; /* IE & Edge */
  scrollbar-width: none !important; /* Firefox */
}

::-webkit-scrollbar,
*::-webkit-scrollbar,
html::-webkit-scrollbar,
body::-webkit-scrollbar,
div::-webkit-scrollbar,
section::-webkit-scrollbar,
main::-webkit-scrollbar,
textarea::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
  -webkit-appearance: none !important;
}

html {
  background-color: #f8fafc;
  height: 100%;
  min-height: 100%;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  width: 100%;
  width: 100vw;
  margin: 0;
  padding: 0;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: transparent;
  color: #1e293b;
  min-height: 100%;
  min-height: -webkit-fill-available;
  min-height: 100dvh;
  height: 100%;
  height: -webkit-fill-available;
  height: 100dvh;
  width: 100%;
  width: 100vw;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
  position: fixed;
  inset: 0;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

/* Dedicated Fixed Background Element for Flawless Gradient on iOS & Desktop */
#app-bg {
  position: fixed;
  inset: 0;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  height: -webkit-fill-available;
  z-index: -10;
  pointer-events: none;
  background-color: #f8fafc;
  background-image: 
    radial-gradient(circle at 0% 0%, rgba(191, 219, 254, 0.6) 0%, transparent 60%),
    radial-gradient(circle at 100% 0%, rgba(254, 243, 199, 0.6) 0%, transparent 60%),
    radial-gradient(circle at 100% 100%, rgba(186, 230, 253, 0.6) 0%, transparent 60%),
    radial-gradient(circle at 0% 100%, rgba(254, 215, 170, 0.6) 0%, transparent 60%);
  background-repeat: no-repeat;
  background-size: cover;
}

/* Mobile Landscape & Short Height Header Padding */
@media (max-height: 520px) {
  header.app-header {
    padding-top: max(0.25rem, var(--sat));
    padding-bottom: 0.25rem;
  }
}

/* Touch & iOS Native UX Tweaks */
button, input, select, a {
  -webkit-tap-highlight-color: transparent;
}

.no-select {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Safe Area Insets Header & Footer Adjustments */
#offline-banner {
  padding-top: max(0.5rem, var(--sat)) !important;
  padding-bottom: 0.35rem !important;
  padding-left: max(0.75rem, var(--sal)) !important;
  padding-right: max(0.75rem, var(--sar)) !important;
}

#offline-banner:not(.hidden) + header.app-header {
  padding-top: 0.35rem !important;
}

header.app-header {
  padding-top: max(0.5rem, var(--sat));
  padding-left: max(0.75rem, var(--sal));
  padding-right: max(0.75rem, var(--sar));
}

/* PWA Installed Standalone Header Spacing (20px extra spacing for PWA mode) */
@media all and (display-mode: standalone), (display-mode: fullscreen) {
  header.app-header {
    padding-top: calc(max(0.5rem, var(--sat)) + 20px) !important;
  }
  #offline-banner {
    padding-top: calc(max(0.5rem, var(--sat)) + 20px) !important;
  }
  #offline-banner:not(.hidden) + header.app-header {
    padding-top: 0.35rem !important;
  }
}

.pwa-standalone header.app-header,
html.pwa-standalone header.app-header,
body.pwa-standalone header.app-header {
  padding-top: calc(max(0.5rem, var(--sat)) + 20px) !important;
}

.pwa-standalone #offline-banner,
html.pwa-standalone #offline-banner,
body.pwa-standalone #offline-banner {
  padding-top: calc(max(0.5rem, var(--sat)) + 20px) !important;
}

.pwa-standalone #offline-banner:not(.hidden) + header.app-header,
html.pwa-standalone #offline-banner:not(.hidden) + header.app-header,
body.pwa-standalone #offline-banner:not(.hidden) + header.app-header {
  padding-top: 0.35rem !important;
}

@media (max-height: 520px) {
  @media (display-mode: standalone), (display-mode: fullscreen) {
    header.app-header {
      padding-top: calc(max(0.25rem, var(--sat)) + 20px) !important;
    }
  }
  .pwa-standalone header.app-header,
  html.pwa-standalone header.app-header,
  body.pwa-standalone header.app-header {
    padding-top: calc(max(0.25rem, var(--sat)) + 20px) !important;
  }
}

main.app-main {
  padding-left: max(0.75rem, var(--sal));
  padding-right: max(0.75rem, var(--sar));
  padding-bottom: 0;
}

/* Custom Scrollbar — Fully Hidden Across Browsers */
.custom-scroll {
  -ms-overflow-style: none !important;
  scrollbar-width: none !important;
}
.custom-scroll::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  background: transparent !important;
  -webkit-appearance: none !important;
}

/* View Transitions */
.view-transition {
  transition: opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1), transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity, transform;
}
.view-hidden {
  opacity: 0;
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  transform: translateY(10px);
  z-index: 0;
}
.view-visible {
  opacity: 1;
  pointer-events: auto;
  position: relative;
  transform: translateY(0);
  z-index: 10;
}

/* Calendar Grid Layout */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background-color: rgba(226, 232, 240, 0.6);
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 1rem;
  overflow: hidden;
}

@media (max-width: 768px) {
  .calendar-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    background-color: transparent;
    border: none;
  }
}

.calendar-cell {
  background-color: #ffffff;
  min-height: 110px;
  padding: 0.5rem;
  transition: all 0.2s ease;
}

.event-pill {
  font-size: 0.75rem;
  padding: 0.35rem 0.6rem;
  border-radius: 9999px;
  margin-bottom: 0.35rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.event-pill:hover {
  transform: translateY(-1px) scale(1.02);
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

/* Dotted Line for Timeline */
.dotted-line {
  background-image: linear-gradient(to bottom, #cbd5e1 50%, rgba(255, 255, 255, 0) 0%);
  background-position: left;
  background-size: 2px 12px;
  background-repeat: repeat-y;
}

/* Animations */
@keyframes fadeInUp {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}

.animate-fade-in-up {
  animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Native iOS Spring Scale Modal Entrance Transition */
.ios-modal-spring,
#modal-panel,
.modal-panel-safe {
  transition: transform 0.38s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
  will-change: transform, opacity;
  transform-origin: center bottom;
}

@media (min-width: 640px) {
  .ios-modal-spring,
  #modal-panel,
  .modal-panel-safe {
    transform-origin: center center;
  }
}

/* Small Mobile Portrait Adjustment (iPhone 13 Mini / <= 385px)
   Pushes navbar and filter pips onto new lines and stretches all buttons evenly across full width */
@media (max-width: 385px) and (orientation: portrait), (max-width: 385px) {
  #header-top-flex {
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: center !important;
    width: 100% !important;
    gap: 0.5rem !important;
  }

  #header-top-flex > div:first-child {
    justify-content: center !important;
  }

  #nav-controls-desktop {
    width: 100% !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
    box-sizing: border-box !important;
  }

  #nav-controls-desktop > button {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }

  #nav-controls-desktop > div.w-px {
    flex: 0 0 auto !important;
    margin-left: 0.125rem !important;
    margin-right: 0.125rem !important;
  }

  #header-controls-flex {
    flex-direction: column !important;
    align-items: stretch !important;
    width: 100% !important;
    gap: 0.5rem !important;
  }

  #header-controls-flex > div:first-child {
    max-width: 100% !important;
    width: 100% !important;
  }

  #header-controls-flex > div:last-child {
    width: 100% !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
    box-sizing: border-box !important;
  }

  #header-controls-flex .cat-chip,
  #header-controls-flex > div:last-child > button {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }
}

/* Modal Overlay Backdrop Blur */
#modal-overlay {
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Print Styles — Text-Only Trip Backup (Itinerary + Logistics) */
#print-area {
  display: none;
}

@media print {
  * {
    -webkit-print-color-adjust: economy !important;
    print-color-adjust: economy !important;
  }

  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    height: auto !important;
    width: 100% !important;
    overflow: visible !important;
    position: static !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Hide all interactive chrome and views */
  header.app-header,
  #offline-banner,
  .cat-chip,
  #nav-controls-desktop,
  #nav-controls-mobile,
  #event-modal,
  #currency-modal,
  #weather-modal,
  button,
  #search-input,
  main.app-main {
    display: none !important;
  }

  /* Show text-only print container */
  #print-area {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    width: 100% !important;
    background: #ffffff !important;
    color: #000000 !important;
  }
}

/* Ensure form select elements fit strictly within their container and have a modern custom dropdown arrow */
select {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 0.85rem auto;
  padding-right: 2rem !important;
}

/* Modal and form overflow containment */
.custom-scroll {
  overflow-x: hidden !important;
}

form {
  max-width: 100% !important;
  box-sizing: border-box !important;
}

/* iPhone 13 Mini & Small Screen Mobile Optimizations (<= 390px) */
@media (max-width: 390px) {
  header.app-header {
    padding-left: max(0.5rem, var(--sal));
    padding-right: max(0.5rem, var(--sar));
  }

  main.app-main {
    padding-left: max(0.35rem, var(--sal));
    padding-right: max(0.35rem, var(--sar));
  }

  /* Compact header typography and buttons */
  #app-header-title {
    font-size: 0.95rem;
  }

  .cat-chip {
    padding-left: 0.45rem;
    padding-right: 0.45rem;
    font-size: 0.65rem;
  }

  /* Touch-scrolling list and modal overflow optimizations */
  .custom-scroll {
    -webkit-overflow-scrolling: touch;
  }

  /* Compact modal panels on iPhone 13 Mini */
  #modal-panel {
    max-height: 88dvh;
    border-radius: 1.25rem;
  }
}

/* Modal safe area insets for iPhone Dynamic Island & Notch */
.modal-safe-wrapper {
  padding-top: max(calc(env(safe-area-inset-top, 0px) + 1.5rem), 3.5rem) !important;
  padding-bottom: max(calc(env(safe-area-inset-bottom, 0px) + 1.25rem), 1.5rem) !important;
  padding-left: max(calc(env(safe-area-inset-left, 0px) + 0.5rem), 0.75rem) !important;
  padding-right: max(calc(env(safe-area-inset-right, 0px) + 0.5rem), 0.75rem) !important;
}

@media (max-width: 639px) {
  .modal-safe-wrapper {
    align-items: flex-end !important;
  }

  .modal-panel-safe {
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 3.5rem) !important;
    margin-top: auto !important;
    border-bottom-left-radius: 1.25rem !important;
    border-bottom-right-radius: 1.25rem !important;
  }
}

/* Toast Notification Container with iPhone 16 / Dynamic Island Safe Area Offset */
#toast-container {
  top: max(1rem, calc(env(safe-area-inset-top, 0px) + 0.75rem)) !important;
  right: max(1rem, env(safe-area-inset-right, 0px)) !important;
  z-index: 9999 !important;
}

@media (max-width: 640px) {
  #toast-container {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: calc(100% - 2rem) !important;
    max-width: 24rem !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
}

/* Interactive Transit Map Custom Leaflet Marker & Popup Styling */
.leaflet-container {
  font-family: inherit !important;
  border-radius: 1rem;
}

.custom-map-pin {
  display: flex !important;
  align-items: center;
  justify-content: center;
  position: relative;
  background: white;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  border: 2px solid white;
  transition: transform 0.2s ease-in-out;
}

.custom-map-pin:hover {
  transform: scale(1.15);
  z-index: 999 !important;
}

.custom-map-pin-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: #1e293b;
  color: white;
  font-size: 10px;
  font-weight: 800;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.leaflet-popup-content-wrapper {
  border-radius: 1rem !important;
  padding: 0 !important;
  overflow: hidden !important;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.1) !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  line-height: 1.4 !important;
}

.leaflet-popup-tip {
  background: white !important;
}

/* Real-time User Location Marker Pulsing Pin */
.user-location-pin {
  width: 20px;
  height: 20px;
  background-color: #2563eb;
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(37, 99, 235, 0.7);
  position: relative;
}

.user-location-pulse {
  position: absolute;
  top: -8px;
  left: -8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background-color: rgba(37, 99, 235, 0.35);
  animation: user-loc-pulse 2s infinite ease-out;
  pointer-events: none;
}

@keyframes user-loc-pulse {
  0% {
    transform: scale(0.5);
    opacity: 1;
  }
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

/* Country Map Marker Styling */
.country-leaflet-pin {
  background: transparent !important;
  border: none !important;
}

/* Tactile Checkbox & Card Animations for "Where Have I Been" Checklist */
@keyframes checkPop {
  0% {
    transform: scale(0.6) rotate(-12deg);
    opacity: 0.4;
  }
  50% {
    transform: scale(1.35) rotate(6deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

@keyframes checkUnpop {
  0% {
    transform: scale(1.25);
  }
  50% {
    transform: scale(0.8);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes cardTactileBounce {
  0% {
    transform: scale(0.96);
  }
  50% {
    transform: scale(1.025);
  }
  100% {
    transform: scale(1);
  }
}

.animate-check-pop {
  animation: checkPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.animate-check-unpop {
  animation: checkUnpop 0.22s cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
}

.animate-card-bounce {
  animation: cardTactileBounce 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.2) forwards;
}

