/* ============================================
   FIX CRÍTICO PARA MÓVILES - viewport height
   ============================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* Fix viewport en móviles - CRÍTICO */
html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    height: 100%;
    min-height: 100%;
    min-height: -webkit-fill-available;
    overflow: hidden;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    -webkit-text-size-adjust: 100%;
}

#map {
    flex: 1;
    width: 100%;
    position: relative;
    min-height: 0;
    overflow: hidden;
}

/* BARRA SUPERIOR ESTILO WAZE */
.top-bar {
    position: relative;
    z-index: 2000;
    background: white;
    padding: 10px 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

/* CONTENEDOR SUPERIOR COMPLETO */
.top-section {
    background: white;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    max-height: 40vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* BUSCADOR ESTILO WAZE */
.search-container {
    background: white;
    border-radius: 50px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    padding: 12px 20px;
    margin-bottom: 10px;
}

.search-icon {
    font-size: 20px;
    margin-right: 10px;
    color: #666;
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    color: #000;
    background: transparent;
}

.search-input::placeholder {
    color: #999;
}

.clear-search {
    font-size: 20px;
    color: #999;
    cursor: pointer;
    display: none;
}

.clear-search.show {
    display: block;
}

/* DROPDOWN DE RESULTADOS */
.search-results {
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    max-height: 300px;
    overflow-y: auto;
    display: none;
}

.search-results.show {
    display: block;
}

.search-result-item {
    padding: 15px 20px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:active {
    background: #f5f5f5;
}

.result-line {
    font-size: 16px;
    font-weight: 700;
    color: #000;
    margin-bottom: 2px;
}

.result-route {
    font-size: 13px;
    color: #666;
}

/* CONTROLES COMPACTOS */
.controls-compact {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    background: white;
    border-radius: 12px;
    margin-top: 10px;
}

.control-chip {
    background: white;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.control-chip:active {
    transform: scale(0.95);
}

.control-chip.active {
    background: #0066cc;
    color: white;
}

/* OVERLAY PRÓXIMA PARADA ESTILO WAZE */
.waze-overlay {
    position: relative;
    z-index: 1000;
    padding: 15px;
    background: white;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    flex-shrink: 0;
    max-height: 45vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.waze-card {
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    overflow: hidden;
    margin-bottom: 12px;
}

.waze-header {
    background: #f8f8f8;
    padding: 8px 15px;
    font-size: 11px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.waze-content {
    padding: 15px;
}

.stop-name-large {
    font-size: 22px;
    font-weight: 700;
    color: #000;
    margin-bottom: 12px;
    line-height: 1.2;
}

/* INSTRUCCIÓN SUPERIOR ESTILO WAZE */
.top-instruction {
    padding: 0 15px 10px 15px;
    background: white;
}

.instruction-card {
    background: #1a1a1a;
    border-radius: 20px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    text-align: center;
}

.instruction-icon-large {
    font-size: 48px;
    flex-shrink: 0;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.instruction-content {
    flex: 1;
    color: white;
}

.instruction-text-main {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
    line-height: 1.2;
}

.instruction-text-distance {
    font-size: 16px;
    opacity: 0.9;
    font-weight: 600;
}

/* PANEL INFERIOR ESTILO WAZE */
.waze-bottom-panel {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    padding: 12px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.panel-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.speed-circle {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    order: 1;
}

.speed-value {
    font-size: 28px;
    font-weight: 700;
    color: white;
    line-height: 1;
}

.speed-unit {
    font-size: 10px;
    color: #999;
    margin-top: 2px;
}

.eta-info {
    flex: 1;
    min-width: 0;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    order: 2;
}

.eta-time {
    font-size: 32px;
    font-weight: 700;
    color: #000;
    line-height: 1;
    margin-bottom: 4px;
}

.eta-details {
    font-size: 13px;
    color: #666;
    font-weight: 500;
    margin-bottom: 6px;
}

.next-stop-name {
    font-size: 13px;
    color: #0066cc;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.expand-icon {
    font-size: 10px;
    transition: transform 0.3s;
}

.expand-icon.rotated {
    transform: rotate(180deg);
}

/* Columna de botones de navegación */
.nav-buttons-column {
    display: flex;
    flex-direction: column;
    gap: 6px;
    order: 3;
}

.btn-nav-inline {
    padding: 8px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: white;
    color: #333;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

.btn-nav-inline:hover {
    background: #f5f5f5;
    border-color: #bdbdbd;
}

.btn-nav-inline:active {
    transform: scale(0.98);
}

.btn-nav-inline.btn-simulate {
    color: #9c27b0;
    border-color: #9c27b0;
}

.btn-nav-inline.btn-simulate:hover {
    background: #f3e5f5;
}

.btn-nav-inline.btn-simulate.active {
    background: #9c27b0;
    color: white;
}

.btn-nav-inline.btn-stop {
    color: #f44336;
    border-color: #f44336;
}

.btn-nav-inline.btn-stop:hover {
    background: #ffebee;
}

.btn-nav-inline.btn-skip {
    color: #ff9800;
    border-color: #ff9800;
}

.btn-nav-inline.btn-skip:hover {
    background: #fff3e0;
}

.report-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b35 0%, #ff8c42 100%);
    border: none;
    font-size: 24px;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.report-btn:active {
    transform: scale(0.95);
}

.metrics-waze {
    display: flex;
    gap: 20px;
    margin-bottom: 12px;
}

.metric-waze {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    color: #333;
}

.metric-waze .icon {
    font-size: 18px;
}

.metric-waze .value {
    font-weight: 600;
}

.buttons-waze {
    display: flex;
    gap: 8px;
}

.btn-waze {
    flex: 1;
    padding: 14px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-waze:active {
    transform: scale(0.95);
}

.btn-waze-skip {
    background: #ff9800;
    color: white;
}

.btn-waze-list {
    background: #f0f0f0;
    color: #333;
}

.btn-waze-list.active {
    background: #0066cc;
    color: white;
}

/* LISTA EXPANDIDA */
.stops-list-waze {
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    max-height: 50vh;
    overflow-y: auto;
    display: none;
}

.stops-list-waze.show {
    display: block;
    animation: slideUp 0.3s ease-out;
}

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

.stops-list-header {
    background: #f8f8f8;
    padding: 12px 15px;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stop-item-waze {
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #f0f0f0;
}

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

.stop-item-waze.passed {
    opacity: 0.4;
}

.stop-item-waze.current {
    background: #e3f2fd;
}

.stop-icon-waze {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    flex-shrink: 0;
}

.stop-icon-waze.passed {
    background: #4caf50;
    color: white;
}

.stop-icon-waze.pending {
    background: #e0e0e0;
    color: #999;
}

.stop-icon-waze.current {
    background: #2196f3;
    color: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.stop-name-waze {
    flex: 1;
    font-size: 14px;
    color: #000;
    font-weight: 500;
}

.stop-item-waze.current .stop-name-waze {
    font-weight: 700;
}

/* BOTÓN FLOTANTE PRINCIPAL */
.fab-container {
    position: fixed;
    bottom: 180px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1500;
}

.fab-main {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #00cc66;
    color: white;
    border: none;
    font-size: 24px;
    box-shadow: 0 4px 12px rgba(0,204,102,0.4);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fab-main:active {
    transform: scale(0.9);
}

.fab-main.stop {
    background: #f44336;
}

/* CONTROLES SECUNDARIOS */
.secondary-controls {
    position: fixed;
    top: 100px;
    right: 15px;
    z-index: 1500;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: white;
    border: none;
    font-size: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.control-btn:active {
    transform: scale(0.9);
}

.control-btn.active {
    background: #ff9800;
    color: white;
}

#recenterBtn {
    background: #00cc66;
    color: white;
    animation: pulse 2s infinite;
}

#recenterBtn:hover {
    background: #00aa55;
}

/* ALERTA */
.alert-waze {
    background: white;
    border-left: 4px solid #ff9800;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    padding: 12px 15px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp 0.3s;
}

.alert-waze .icon {
    font-size: 20px;
}

.alert-waze .text {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: #000;
}

/* COMPLETADO */
.completed-waze {
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    padding: 30px;
    text-align: center;
}

.completed-waze .icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.completed-waze .text {
    font-size: 20px;
    font-weight: bold;
    color: #4caf50;
}

/* STATUS BAR */
.status-bar {
    position: fixed;
    top: 10px;
    left: 15px;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 1500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #666;
}

.status-dot.active {
    background: #00cc66;
    animation: pulse 2s infinite;
}

.status-dot.simulating {
    background: #ff9800;
    animation: pulse 2s infinite;
}

/* SCROLLBAR */
.stops-list-waze::-webkit-scrollbar,
.search-results::-webkit-scrollbar {
    width: 4px;
}

.stops-list-waze::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track {
    background: #f5f5f5;
}

.stops-list-waze::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

.hidden {
    display: none;
}

/* Pantalla de recorrido completado */
.completed-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 300px;
}

.btn-completed {
    padding: 16px 24px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-completed:active {
    transform: scale(0.95);
}

.btn-primary {
    background: #2196f3;
    color: white;
}

.btn-primary:hover {
    background: #1976d2;
}

.btn-secondary {
    background: #f5f5f5;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

/* Selectores de dirección y modo */
.direction-selector,
.mode-selector {
    display: flex;
    gap: 8px;
    background: #f5f5f5;
    padding: 4px;
    border-radius: 8px;
}

.btn-direction,
.btn-mode {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #666;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-direction.active,
.btn-mode.active {
    background: white;
    color: #333;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn-direction:hover:not(.active),
.btn-mode:hover:not(.active) {
    color: #333;
}

/* Botón de iniciar */
.btn-start {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    background: #2196f3;
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-start:hover {
    background: #1976d2;
}

.btn-start:active {
    transform: scale(0.98);
}

/* Leaflet fix */
.leaflet-container {
    height: 100% !important;
    width: 100% !important;
}

/* Menú Hamburguesa */
.hamburger-menu {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 2000;
}

.hamburger-btn {
    width: 50px;
    height: 50px;
    background: white;
    border: none;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.15);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: all 0.3s ease;
}

.hamburger-btn:hover {
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.hamburger-btn span {
    width: 24px;
    height: 3px;
    background: #333;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(7px, 7px);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* Panel del Menú */
.menu-panel {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100vh;
    background: white;
    box-shadow: 2px 0 20px rgba(0,0,0,0.1);
    z-index: 2001;
    transition: left 0.3s ease;
    overflow-y: auto;
}

.menu-panel.open {
    left: 0;
}

.menu-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.menu-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

.menu-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-content {
    padding: 20px;
}

.menu-user-info {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: #f5f5f5;
    border-radius: 12px;
    margin-bottom: 15px;
}

.menu-user-avatar {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    font-weight: 700;
}

.menu-user-details {
    flex: 1;
}

.menu-user-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.menu-user-email {
    font-size: 13px;
    color: #666;
}

.menu-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 15px 0;
}

.menu-nav {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 14px 16px;
    color: #333;
    text-decoration: none;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.menu-item:hover {
    background: #f5f5f5;
    color: #333;
}

.menu-item-danger {
    color: #f44336;
}

.menu-item-danger:hover {
    background: #ffebee;
    color: #f44336;
}

.menu-icon {
    font-size: 20px;
}

/* Overlay del Menú */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.menu-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* ============================================
   RESPONSIVE MÓVILES
   ============================================ */

@media (max-width: 768px) {
    .instruction-text-main {
        font-size: 18px;
    }

    .instruction-text-distance {
        font-size: 14px;
    }

    .instruction-icon-large {
        font-size: 40px;
    }

    .instruction-card {
        padding: 15px;
        text-align: center;
    }

    .speed-circle {
        width: 60px;
        height: 60px;
    }

    .speed-value {
        font-size: 24px;
    }

    .eta-time {
        font-size: 28px;
    }

    .eta-details {
        font-size: 12px;
    }

    .next-stop-name {
        font-size: 12px;
    }

    .report-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    .waze-bottom-panel {
        padding: 12px 15px;
        gap: 10px;
    }
    
    .waze-overlay {
        padding: 10px;
        max-height: 40vh;
    }
    
    .top-section {
        max-height: 35vh;
    }
    
    .btn-nav-inline {
        min-height: 44px;
        padding: 10px 14px;
    }
    
    .panel-content {
        gap: 10px;
        padding: 10px;
    }
    
    .btn-direction,
    .btn-mode {
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .menu-panel {
        width: 280px;
        left: -280px;
    }
    
    .hamburger-menu {
        top: 15px;
        left: 15px;
    }
    
    .hamburger-btn {
        width: 45px;
        height: 45px;
    }
}

/* Fix para pantallas pequeñas */
@media (max-height: 700px) {
    .waze-overlay {
        max-height: 35vh;
    }
    
    .top-section {
        max-height: 30vh;
    }
    
    .stops-list-waze {
        max-height: 30vh;
    }
}

@media (max-height: 600px) {
    .waze-overlay {
        max-height: 30vh;
    }
    
    .top-section {
        max-height: 25vh;
    }
    
    .stops-list-waze {
        max-height: 25vh;
    }
}

/* Fix para iPhone con notch */
@supports (padding: max(0px)) {
    body {
        padding-top: max(0px, env(safe-area-inset-top));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
}
