/*
 * style.css
 * Folha de estilos para a aplicação DF Bus (Versão Final com Navegação FAB Estendido)
 */

/* --- 1. Variáveis Globais de Cores e Medidas --- */
:root {
    --primary-color: #7c4bfc;
    --bg-primary: #f7f7f7;
    --bg-secondary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #ced4da;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --header-bg: #333;
    --header-text: #fff;
    --transition-speed: 0.3s;
}

/* --- 2. Definição do Tema Escuro --- */
body.dark-mode {
    --primary-color: #990aff;
    --bg-primary: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --text-primary: #f2f2f7;
    --text-secondary: #8e8e93;
    --border-color: #3a3a3c;
    --shadow-color: rgba(0, 0, 0, 0.4);
    --header-bg: #1c1c1e;
}

body.dark-mode .arriving {
    color: #4CAF50;
}

/* --- 3. Estilos Base e Layout de Views --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    margin: 0;
    padding: 0;
    height: 100svh;
    overflow: hidden;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-speed) ease-in-out;
    display: flex;
    flex-direction: column;
}

.view.active-view {
    opacity: 1;
    pointer-events: auto;
    z-index: 100;
}

/* --- 4. Estilos da Tela de Busca (#search-view) --- */
#search-view header {
    background-color: var(--header-bg);
    color: var(--header-text);
    height: 70px;
    box-shadow: 0 2px 5px var(--shadow-color);
    flex-shrink: 0;
    display: flex;
    justify-content: center;
}

.header-content-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 15px;
}

#search-view header h1 {
    padding-top: 21px;
    font-size: 1.2rem;
    margin: 0;
}

.header-actions {
    padding-top: 21px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.search-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: var(--bg-primary);
    padding-bottom: 100px;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.clear-search-btn {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 5px;
    margin: auto 0;
    z-index: 2;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    font-size: 24px;
    line-height: 1;
    transition: background-color 0.2s, color 0.2s;
}

.clear-search-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.help-btn {
    background: none;
    border: none;
    color: var(--header-text);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.help-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* --- 5. Estilos da Tela de Mapa e Navegação --- */
#map-view {
    background-color: var(--bg-secondary);
}

#map {
    width: 100%;
    height: 100%;
    flex-grow: 1;
    z-index: 500;
}

.map-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));
    color: white;
    pointer-events: none;
}

#map-header-info {
    padding-top: 25px;
    font-size: 0.9rem;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#map-header-info strong {
    font-size: 1rem;
}

/* --- 5.1. Estilo Unificado para Botões Flutuantes (FAB) --- */
.fab {
    position: absolute;
    right: 20px;
    z-index: 1100;
    height: 56px;
    padding: 0 20px;
    background-color: var(--primary-color);
    color: white;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px var(--shadow-color);
    cursor: pointer;
    transition: transform 0.2s ease-in-out, background-color 0.2s;
    bottom: 80px;
}

.fab span {
    font-size: 1.5rem;
}

.fab:hover {
    transform: scale(1.05);
    background-color: #5e1eff; 
}

body.dark-mode .fab:hover {
    background-color: #a94dff;
}

#map-view .fab {
    bottom: 140px;
}


/* --- 5.2. Controles Unificados da Barra Inferior do Mapa --- */
.map-bottom-controls-container {
    position: relative;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 8px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    width: auto;
    max-width: 95%;
    border: 1px solid rgba(0,0,0,0.1);
    transition: all 0.3s ease-in-out;
}
body.dark-mode .map-bottom-controls-container {
    background-color: rgba(44, 44, 46, 0.95);
    border: 1px solid rgba(255,255,255,0.1);
}

.map-bottom-controls-container .map-overlay-btn {
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 24px;
    background-color: #f0f2f5;
    color: #333;
    transition: background-color 0.2s;
}
body.dark-mode .map-bottom-controls-container .map-overlay-btn {
    background-color: #3a3a3c;
    color: #f2f2f7;
}

.map-bottom-controls-container .map-overlay-btn:hover {
    background-color: #e4e6eb;
}
body.dark-mode .map-bottom-controls-container .map-overlay-btn:hover {
    background-color: #555;
}


#toggle-stops-btn img {
    width: 28px;
    height: 28px;
}
#toggle-stops-btn:not(.active) {
    opacity: 0.6;
}

#map-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 0 5px;
}

#direction-filter-container { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.direction-filter-options { display: flex; align-items: center; gap: 5px; }
.direction-filter-options label { cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.direction-filter-options input[type="radio"] { display: none; }
.direction-filter-options input[type="radio"]:checked + label { background-color: var(--primary-color); color: white; font-weight: bold; }
#bus-count-info { font-size: 13px; color: #333; background-color: #eaf3ff; padding: 4px 10px; border-radius: 6px; margin: 0; }
body.dark-mode #bus-count-info { background-color: var(--bg-secondary); color: var(--text-primary); }

/* --- NOVOS ESTILOS PARA A BUSCA NO MAPA --- */

.map-search-wrapper {
    flex-grow: 1; /* Faz a barra de busca ocupar o espaço disponível */
    position: relative;
    display: flex; /* Garante alinhamento interno */
}

#map-route-search {
    width: 100%;
    height: 45px;
    padding: 0 45px 0 15px; /* Espaço à direita para o botão de limpar */
    margin: 0; /* Remove o margin-bottom do estilo geral de input */
    font-size: 0.95rem;
    border: none;
    border-radius: 10px;
    background-color: #f0f2f5;
    color: #333;
    box-sizing: border-box;
    line-height: 45px;
}

body.dark-mode #map-route-search {
    background-color: #3a3a3c;
    color: #f2f2f7;
}

/* Ajusta o botão de limpar (definido na Seção 4) para a busca do mapa */
.map-search-wrapper .clear-search-btn {
    height: 45px; /* Alinha com a altura do input */
    width: 45px;
    top: 0;
    right: 0;
    bottom: auto; /* Reseta o alinhamento vertical */
    margin: 0;
    font-size: 22px;
    border-radius: 0 10px 10px 0;
}

/* Container de sugestões flutuante */
#map-route-suggestions {
    display: none; /* Controlado pelo JS */
    position: absolute;
    bottom: calc(100% + 8px); /* Flutua 8px acima do container de controles */
    left: 0;
    width: 100%;
    z-index: 1001;
    background-color: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 -4px 12px var(--shadow-color);
    max-height: 300px;
    overflow-y: auto;
}

/* Cabeçalho "Linhas" / "Paradas" dentro das sugestões */
#map-route-suggestions .suggestion-header {
    padding: 8px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
}

/* Garante que os itens de sugestão (seção 6) fiquem bem aqui */
#map-route-suggestions .route-item,
#map-route-suggestions .stop-item {
    padding: 10px 12px;
}

/* --- 6. Componentes Gerais --- */
input[type="text"] {
    width: 100%;
    padding: 12px 40px 12px 12px;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 8px;
    box-sizing: border-box;
    font-size: 1rem;
}

#route-suggestions {
    border: 1px solid var(--border-color);
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 10px;
    border-radius: 8px;
}
.route-item, .stop-item {
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}
.route-item:last-child, .stop-item:last-child {
    border-bottom: none;
}
.route-item:hover, .stop-item:hover {
    background-color: var(--bg-secondary);
}

.stop-item::before {
    content: '📍';
    font-size: 1rem;
}

.btn-show-map {
    display: block;
    width: 100%;
    padding: 15px;
    margin-bottom: 20px;
    background-color: var(--primary-color);
    color: white;
    font-size: 1.1rem;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.btn-show-map:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(124, 75, 252, 0.4);
}

.info-box {
    padding: 15px;
    border-radius: 8px;
    background-color: var(--bg-secondary);
}

.loading-spinner {
    border: 4px solid var(--border-color);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
    display: none;
    margin: 20px auto;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.search-mode-toggle {
    display: flex;
    margin-bottom: 15px;
    background-color: var(--bg-secondary);
    border-radius: 8px;
    padding: 4px;
}

.search-mode-btn {
    flex: 1;
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    background-color: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.2s, color 0.2s;
}

.search-mode-btn.active {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 2px 5px rgba(124, 75, 252, 0.3);
}

/* --- 7. Abas e Horários --- */
.tabs-container { display: flex; }
.tab-button { flex-grow: 1; padding: 12px 15px; cursor: pointer; text-align: center; background: none; border: none; font-size: 1rem; color: var(--text-secondary); border-bottom: 3px solid transparent; }
.tab-button.active { color: var(--primary-color); border-bottom-color: var(--primary-color); font-weight: bold; }
.tab-content { display: none; padding-top: 15px; }
.tab-content.active { display: block; }
.day-type-selector { display: flex; justify-content: space-around; margin: 15px 0; }
.day-type-button { padding: 5px 12px; border: 1px solid var(--border-color); border-radius: 20px; background-color: var(--bg-primary); color: var(--text-primary); cursor: pointer; font-size: 0.8rem; }
.day-type-button.active { background-color: var(--primary-color); color: white; border-color: var(--primary-color); }
.departures-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(50px, 1fr)); gap: 10px; }
.departure-time { background-color: var(--bg-secondary); padding: 8px; text-align: center; border-radius: 4px; font-size: 0.9rem; }


/* --- 8. Seção de Favoritos --- */
#favorites-section, .favorites-container { margin-top: 30px; }
#favorites-section h3, .favorites-container h3 { margin-bottom: 15px; }
.favorites-hint { font-size: 0.85em; color: var(--text-secondary); margin: -10px 0 15px 0; }
.no-favorites { text-align: center; padding: 20px; color: var(--text-secondary); background-color: var(--bg-secondary); border: 1px dashed var(--border-color); border-radius: 12px; }
.favorite-item { display: flex; align-items: center; gap: 15px; padding: 12px 15px; background-color: var(--bg-secondary); border-radius: 12px; margin-bottom: 10px; }
.favorite-item-name { flex-grow: 1; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.remove-favorite-btn { background: transparent; border: none; color: var(--text-secondary); font-size: 1.5rem; cursor: pointer; border-radius: 50%; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; transition: background-color 0.2s, color 0.2s, transform 0.2s; flex-shrink: 0; }
.remove-favorite-btn:hover { background-color: #e53935; color: white; transform: scale(1.1); }
.linha-wrapper { display: inline-flex; align-items: center; gap: 8px; }
.favorite-toggle-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); }
.favorite-toggle-btn.is-favorite { color: #ffc107; }
.favorite-item-wrapper { margin-bottom: 15px; }
.favorite-stop-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; padding: 12px 15px; background-color: var(--bg-secondary); border-radius: 12px; }
.header-actions-group { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.alarm-btn { background: transparent; border: none; color: var(--text-secondary); font-size: 1.3rem; cursor: pointer; border-radius: 50%; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.alarm-btn.active { color: var(--primary-color); transform: scale(1.1) rotate(15deg); }
.alarm-btn:hover { background-color: var(--bg-secondary); }


/* --- 9. Componentes do Mapa e Popups --- */
.user-location-marker { width: 18px; height: 18px; background-color: #007bff; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 5px rgba(0,0,0,0.5); position: relative; }
.user-location-marker::after { content: ''; position: absolute; top: 50%; left: 50%; width: 18px; height: 18px; border-radius: 50%; background-color: rgba(0, 123, 255, 0.5); transform: translate(-50%, -50%); animation: pulse 1.5s infinite ease-out; z-index: -1; }
@keyframes pulse { 0% { transform: translate(-50%, -50%) scale(1); opacity: 0.6; } 100% { transform: translate(-50%, -50%) scale(3); opacity: 0; } }
.bus-icon-container .bus-icon-background { width: 100%; height: 100%; border-radius: 50%; border: 2px solid white; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4); display: flex; align-items: center; justify-content: center; transition: transform 0.5s linear; }
.bus-arrow { position: absolute; top: -4px; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 8px solid white; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--bg-primary); color: var(--text-primary); }
.leaflet-control-layers { border-radius: 8px !important; box-shadow: 0 2px 5px var(--shadow-color) !important; border: none !important; }
.leaflet-control-container { pointer-events: none; }
.leaflet-control-container > * { pointer-events: auto; }
.leaflet-top.leaflet-right { top: 60px; right: 10px; }
.leaflet-popup-content { margin: 15px 20px !important; width: 280px !important; }
.stop-popup-content { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; max-height: 250px; overflow-y: auto; padding-right: 10px; }
.stop-popup-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.stop-popup-header .stop-name { font-weight: 600; }
.popup-favorite-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #ccc; padding: 5px; line-height: 1; }
.popup-favorite-btn:hover { color: #ffd700; }
.popup-favorite-btn.is-favorite { color: #ffc107; }
.bus-eta-item { display: flex; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border-color); cursor: pointer; transition: background-color 0.2s; }
.bus-eta-item:last-child { border-bottom: none; }
.bus-eta-item:hover { background-color: var(--bg-secondary); }
.eta-time { flex-shrink: 0; margin-right: 20px; text-align: center; width: 70px; }
.eta-time .time-value { font-size: 1.5rem; font-weight: 700; color: var(--primary-color); line-height: 1; }
.eta-time .time-unit { font-size: 0.8rem; color: var(--text-secondary); }
.eta-time .arriving { font-size: 1.1rem; font-weight: 700; color: #28a745; line-height: 1.2; }
.eta-route-info { flex-grow: 1; overflow: hidden; }
.eta-route-info .route-short-name { font-size: 1rem; font-weight: 600; color: var(--text-primary); display: block; }
.eta-route-info .route-long-name { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; margin-top: 2px; }
.no-buses-message { padding: 15px; text-align: center; color: var(--text-secondary); }


/* --- 10. Modais --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.7); z-index: 2000; opacity: 0; pointer-events: none; transition: opacity var(--transition-speed) ease; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.95); background: var(--bg-primary); color: var(--text-primary); padding: 20px; border-radius: 12px; z-index: 2001; width: 90%; max-width: 500px; box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3); opacity: 0; pointer-events: none; transition: opacity var(--transition-speed) ease, transform var(--transition-speed) ease; max-height: 80vh; display: flex; flex-direction: column; }
.modal-overlay.modal-active, .modal.modal-active { opacity: 1; pointer-events: auto; }
.modal.modal-active { transform: translate(-50%, -50%) scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; margin-bottom: 15px; flex-shrink: 0; }
.modal-header h2 { margin: 0; font-size: 1.3rem; }
.close-modal-btn { background: none; border: none; font-size: 2rem; cursor: pointer; color: var(--text-secondary); }
.modal-content { overflow-y: auto; line-height: 1.6; }
.modal-content h4 { color: var(--primary-color); margin-top: 15px; margin-bottom: 5px; }
.modal-actions { display: flex; gap: 15px; margin-top: 25px; }
.btn { flex: 1; padding: 12px; font-size: 1rem; font-weight: bold; border: none; border-radius: 8px; cursor: pointer; text-align: center; text-decoration: none; transition: transform 0.2s; }
.btn:hover { transform: translateY(-2px); }
.btn-primary { background-color: var(--primary-color); color: white; }
.btn-secondary { background-color: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border-color); }


/* --- 11. Interruptor de Tema --- */
.theme-toggle-container { display: flex; align-items: center; gap: 8px; color: var(--header-text); }
.theme-icon { font-size: 1.1rem; }
.theme-switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #757575; transition: 0.4s; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: 0.4s; }
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(20px); }
.slider.round { border-radius: 24px; }
.slider.round:before { border-radius: 50%; }


/* --- 12. Responsividade --- */
@media (max-width: 600px) {
    .search-content {
        padding: 15px;
        padding-bottom: 100px;
    }
    .modal {
        width: 95%;
    }
}

/* --- 13. Layout para Desktop --- */
@media (min-width: 992px) {
    .search-content { max-width: 1100px; margin: 0 auto; padding: 40px; display: grid; grid-template-columns: 2fr 1fr; gap: 40px; align-items: start; }
    .search-box-container, #route-details-container { grid-column: 1; }
    #favorites-section { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; }
    .header-content-wrapper { max-width: 1100px; padding: 0 40px; }
    #route-details-container { background-color: var(--bg-secondary); border-radius: 12px; padding: 24px; margin-top: 24px; border: 1px solid var(--border-color); }
    .info-box { padding: 0; background-color: transparent; }
    input[type="text"]:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(124, 75, 252, 0.2); }
}

/* Estilo para o tempo estimado no cabeçalho */
.header-eta-badge {
    display: block; /* Força ficar na linha de baixo */
    margin-top: 4px;
    font-size: 0.9rem;
    color: #69f0ae; /* Verde claro neon para contraste alto no fundo escuro */
    font-weight: 600;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 1); /* Sombra forte para ler em cima do mapa */
    letter-spacing: 0.5px;
    animation: fadeIn 0.5s ease-in;
}

/* Animação suave quando o tempo aparece */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Pequeno ajuste no container do título para acomodar duas linhas */
#map-header-info {
    padding-top: 15px; /* Reduzi um pouco o padding original de 25px para subir o texto */
    line-height: 1.3;
}