body {
    margin: 0;
    background: #f5f5f5;
    overflow-x: hidden;
}

* {
    box-sizing: border-box;
}

.main-content-wrapper {
    padding: 20px;
}

.controls {
    background: white;
    padding: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    border-radius: 14px;
    margin-bottom: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
}

.controls>div {
    flex: 1 1 220px;
}

.mode-btn,
#playBtn,
.gallery-btn {
    min-height: 44px;
}

.mode-btn {
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    background: #ddd;
}

.mode-btn.active {
    background: #3D95CE;
    color: white;
}

#map {
    width: 100%;
    height: 72vh;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .15);
}

.timeline {
    background: white;
    padding: 15px;
    border-radius: 14px;
    margin-top: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);

    -webkit-overflow-scrolling: touch;
}

.timeline-item {
    padding: 8px 10px;
    border-radius: 8px;
    background: #eee;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.timeline-item.active {
    background: #3D95CE;
    color: white;
}

.side-panel {
    position: absolute;
    top: 240px;
    right: 30px;
    z-index: 999;
    width: 320px;
    max-height: 65vh;
    overflow: auto;
    background: white;
    padding: 15px;
    border-radius: 14px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .25);
    display: none;
}

.side-panel.active {
    display: block;
}

.current-marker {
    background: #ff5722;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 4px solid white;
    box-shadow: 0 0 18px rgba(255, 87, 34, .8);
    animation: pulse 1.5s infinite;
}

.standard-marker {
    background: #3D95CE;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid white;
}

.journey-marker {
    background: #28a745;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid white;
}

.dashboard-marker {
    background: #6f42c1;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 2px solid white;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 12px;
}

.photo-grid img {
    width: 100%;
    display: block;
    border-radius: 10px;
    cursor: pointer;
    transition: transform .2s ease;
}

.photo-grid img:hover {
    transform: scale(1.03);
}

.stats {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.stat-card {
    background: #f2f2f2;
    padding: 10px;
    border-radius: 10px;
    font-size: 14px;
}

.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .92);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    flex-direction: column;
    padding: 20px;
}

.lightbox-overlay.active {
    display: flex;
}

.lightbox-image {
    max-width: 90vw;
    max-height: 78vh;
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(0, 0, 0, .5);
    position: relative;
    z-index: 1000000;
}

.lightbox-controls {
    margin-top: 18px;
    display: flex;
    gap: 12px;
}

.lightbox-btn {
    background: #3D95CE;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.lightbox-close {
    position: absolute;
    top: 18px;
    right: 24px;
    color: white;
    font-size: 34px;
    cursor: pointer;
    font-weight: bold;
}

body.lightbox-open #mobileSheet,
body.lightbox-open #mobileDayCard,
body.lightbox-open #timeline {
    display: none;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

.mobile-close-btn {
    display: none;
}

/* =====================================
   PHONE RESPONSIVE
   ===================================== */

@media (max-width: 640px) {
    .mobile-close-btn {
        display: block;
    }

    .main-content-wrapper {
        padding: 10px;
    }

    .home-hero {
        text-align: center;
    }

    .controls {
        flex-direction: column;
        gap: 18px;
        padding: 14px;
    }

    .controls>div {
        width: 100%;
        min-width: unset;
    }

    .mode-btn,
    #playBtn,
    .gallery-btn {
        width: 100%;
        margin-top: 8px;
    }

    #map {
        height: 52vh;
        min-height: 320px;
        border-radius: 12px;
    }

    .timeline {
        padding: 12px;
        gap: 8px;
    }

    .timeline-item {
        padding: 10px 12px;
        font-size: 14px;
    }

    .side-panel {
        position: fixed;
        top: auto;
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: auto;
        max-height: 55vh;
        padding: 14px;
    }

    .photo-grid {
        grid-template-columns: 1fr;
    }

    .stats {
        flex-direction: column;
    }

    .lightbox-image {
        max-width: 95vw;
        max-height: 70vh;
    }

    .lightbox-controls {
        width: 100%;
    }

    .lightbox-btn {
        flex: 1;
    }
}

.trip-media {
    width: 100%;
    border-radius: 8px;
    margin-top: 10px;
    object-fit: cover;
}

.trip-media video {
    display: block;
}

/* ====================================================
   MOBILE APP REDESIGN - TRIPMAP ONLY
   ==================================================== */
.mobile-controls-btn {
    display: none;
}

@media (max-width:640px) {

    .home-hero {
        margin-bottom: 8px;
        text-align: center;
    }

    .mobile-controls-btn {
        display: block;
        position: fixed;
        right: 14px;
        bottom: 90px;
        z-index: 4000;
        border: none;
        border-radius: 999px;
        padding: 14px 18px;
        background: #3D95CE;
        color: #fff;
        font-weight: bold;
        box-shadow: 0 4px 18px rgba(0, 0, 0, .25);
    }

    .controls {
        position: fixed;
        left: 10px;
        right: 10px;
        top: 80px;
        z-index: 4500;
        display: none;
        max-height: 70vh;
        overflow: auto;
    }

    .controls.mobile-controls-open {
        display: flex;
        flex-direction: column;
    }

    #map {
        height: 82vh !important;
        min-height: 550px;
        border-radius: 18px;
    }

    .timeline {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: 10px;
        z-index: 3500;
        margin: 0;
        border-radius: 18px;
        backdrop-filter: blur(8px);
    }

    .timeline-item {
        min-width: max-content;
        padding: 12px 16px;
    }

    .side-panel {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 58px !important;
        top: auto !important;
        width: 100% !important;
        max-height: 68vh !important;
        border-radius: 24px 24px 0 0 !important;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, .28) !important;
    }

    .side-panel::before {
        content: '';
        display: block;
        width: 64px;
        height: 6px;
        border-radius: 999px;
        background: #cfcfcf;
        margin: 0 auto 12px;
    }

    .photo-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .photo-grid img {
        aspect-ratio: 1/1;
        object-fit: cover;
    }

    .stats {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .lightbox-btn,
    .mode-btn,
    #playBtn,
    .gallery-btn {
        min-height: 50px;
    }
}


/* ======================================================
   TRIPMAP V2 MOBILE BRANCH
   ====================================================== */

.mobile-day-card,
.mobile-sheet,
.mobile-fab {
    display: none;
}

@media (max-width:640px) {

    .controls .mode-btn,
    .controls strong+br+.mode-btn {
        display: none !important;
    }

    .mobile-day-card {
        display: block;
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 84px;
        z-index: 3600;
        background: #fff;
        border-radius: 18px;
        padding: 14px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, .2);
    }

    .mobile-sheet {
        display: block;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: 18vh;
        background: #fff;
        border-radius: 24px 24px 0 0;
        z-index: 3550;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, .2);
    }

    .mobile-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        width: 54px;
        height: 54px;
        border: none;
        border-radius: 50%;
        background: #3D95CE;
        color: #fff;
        font-size: 22px;
        z-index: 4000;
    }

    .mobile-menu-fab {
        left: 14px;
        bottom: 220px;
    }

    .mobile-recenter-fab {
        right: 14px;
        bottom: 220px;
    }
}

/* STEP 3 MOBILE APP */

@media (max-width:640px) {

    .controls div:nth-child(2) {
        display: none !important;
    }

    .mobile-day-card {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 90px;
        z-index: 3600;
        background: #fff;
        padding: 14px;
        border-radius: 18px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, .2);
    }

    .mobile-sheet {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: 16vh;
        background: #fff;
        border-radius: 24px 24px 0 0;
        z-index: 3550;
        transition: height .3s ease;
        overflow: hidden;
    }

    .mobile-sheet.open {
        height: 72vh;
    }

    .mobile-sheet-handle {
        width: 60px;
        height: 6px;
        margin: 10px auto;
        background: #ccc;
        border-radius: 999px;
    }

    .mobile-tabs {
        display: flex;
        border-bottom: 1px solid #eee;
    }

    .mobile-tab {
        flex: 1;
        padding: 12px;
        border: none;
        background: #fff;
    }

    #mobileSheetContent {
        padding: 16px;
        overflow: auto;
        height: calc(100% - 60px);
    }

    .mobile-fab {
        position: fixed;
        width: 54px;
        height: 54px;
        border-radius: 50%;
        border: none;
        background: #3D95CE;
        color: white;
        z-index: 4000;
    }

    .mobile-menu-fab {
        left: 14px;
        bottom: 220px;
    }

    .mobile-recenter-fab {
        right: 14px;
        bottom: 220px;
    }
}

/* STEP 7 */
@media (max-width:640px) {
    .leaflet-popup {
        display: none !important;
    }

    .mobile-version {
        position: fixed;
        right: 12px;
        bottom: 12px;
        z-index: 5000;
        background: rgba(0, 0, 0, .7);
        color: white;
        font-size: 11px;
        padding: 4px 8px;
        border-radius: 999px;
    }

    .mobile-day-card {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 88px;
        z-index: 3800;
        background: #fff;
        padding: 12px;
        border-radius: 16px;
        box-shadow: 0 4px 20px rgba(0, 0, 0, .2);
    }
}

/* V2.8 */
@media (max-width:640px) {
    .mobile-version::after {
        content: "";
    }

    .controls .mode-btn {
        display: none !important;
    }
}


/* ===== V2.9 CLEANUP ===== */
@media (max-width:640px) {
    #mobileControlsBtn {
        display: none !important;
    }

    .mobile-version {
        z-index: 9999 !important;
    }
}


/* V8.9 PHOTO GRID NORMALIZATION */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.photo-grid img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    display: block;
    border-radius: 10px;
}

/* V10.5 Mobile Sheet UX */
@media (max-width:640px){
  .sheet-hint{
    text-align:center;
    font-size:12px;
    color:#777;
    font-weight:600;
    padding:4px 0 8px 0;
  }

  #mobileSheet.sheet-collapsed .mobile-tabs{
    display:none !important;
  }

  #mobileSheet.sheet-collapsed #mobileSheetContent{
    display:none !important;
  }

  #mobileSheet.sheet-collapsed{
    height:72px !important;
  }
}


/* V11.6 Mobile layout fix */
@media (max-width:640px){

  /* Reserve space for collapsed drawer */
  body{
    padding-bottom: 180px !important;
    box-sizing:border-box;
  }

  #mobileSheet{
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1000 !important;
  }

  /* Pull map up so its bottom aligns with drawer top */
  #map,
  .map-container,
  #mapContainer{
    margin-bottom: 180px !important;
  }
}


/* V12.0 Mobile timeline moved into drawer */
@media (max-width:640px){
  #timeline{
    display:none !important;
  }

  .mobile-timeline-list{
    margin:12px 0;
    max-height:220px;
    overflow-y:auto;
    border:1px solid #ddd;
    border-radius:10px;
    padding:6px;
  }

  .mobile-timeline-item{
    padding:8px;
    border-bottom:1px solid #eee;
    cursor:pointer;
  }

  .mobile-timeline-item.active{
    background:#e8f5e9;
    font-weight:bold;
  }

  #debugPanel{
    font-size:11px;
    color:#666;
    border-top:1px dashed #ccc;
    margin-top:8px;
    padding-top:6px;
  }
}
