/* Reset and base configuration */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

:root {
    /* Colors - Primary */
    --primary-color: #3498db;
    --primary-dark: #2980b9;
    
    /* Colors - Background */
    --header-bg: #2c3e50;
    --sidebar-bg: #f8f9fa;
    --card-bg: #ffffff;
    
    /* Colors - Text */
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --text-light: #95a5a6;
    
    /* Colors - Borders & Shadows */
    --border-color: #dee2e6;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Dark theme variables */
[data-theme="dark"] {
    /* Colors - Primary */
    --primary-color: #2196f3;
    --primary-dark: #1976d2;
    
    /* Colors - Background */
    --header-bg: #1a1a1a;
    --sidebar-bg: #212121;
    --card-bg: #2c2c2c;
    
    /* Colors - Text */
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --text-light: #757575;
    
    /* Colors - Borders & Shadows */
    --border-color: #333333;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* Main layout */
body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background-color: var(--sidebar-bg);
    color: var(--text-primary);
}

header {
    background-color: var(--header-bg);
    color: white;
    padding: 1rem;
    text-align: center;
    flex-shrink: 0;
    z-index: 10;
    position: relative;
}

.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Map components */
#map {
    flex: 2;
    height: 100%;
    z-index: 0;
}

.sidebar {
    flex: 1;
    background-color: var(--sidebar-bg);
    max-width: 400px;
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

/* Search bar */
.search-container {
    padding: 1rem;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    position: sticky;
    top: 0;
    z-index: 1;
    flex-shrink: 0;
    align-items: center;
    gap: 5px;
}

#search-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px 0 0 4px;
    background-color: var(--card-bg);
    color: var(--text-primary);
}

#search-btn {
    padding: 0.5rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
}

#search-btn:hover {
    background-color: var(--primary-dark);
}

#location-btn {
    width: 40px;
    height: 33px;
    padding: 8px;
    background-color: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-left: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

#location-btn:hover {
    background-color: var(--border-color);
}

#location-btn svg {
    width: 18px;
    height: 18px;
}

/* News container */
#news-container {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

/* Components - News Item */
.news-item {
    margin-bottom: 1rem;
    padding: 1rem;
    background-color: var(--card-bg);
    border-radius: 4px;
    box-shadow: var(--card-shadow);
    cursor: pointer;
    transition: transform 0.2s, border-left-color 0.2s;
    border-left: 4px solid var(--border-color);
}

.news-item h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.news-item p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.news-item .date {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

.news-item small strong {
    color: var(--text-secondary);
}

/* Dark Theme Overrides - News Item */
[data-theme="dark"] .news-item {
    border-left-color: var(--border-color);
}

[data-theme="dark"] .news-item[style*="border-left"] {
    border-left-width: 4px;
    border-left-style: solid;
}

.news-item:hover {
    transform: translateY(-2px);
}

/* News item animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.news-item.animate-news {
    animation: fadeIn 0.5s ease forwards;
    opacity: 0;
}

.news-item.animate-news:nth-child(n) {
    animation-delay: calc(0.1s * var(--n, 0));
}

.news-item.animate-news:nth-child(1) {
    --n: 1;
}

.news-item.animate-news:nth-child(2) {
    --n: 2;
}

.news-item.animate-news:nth-child(3) {
    --n: 3;
}

.news-item.animate-news:nth-child(4) {
    --n: 4;
}

.news-item.animate-news:nth-child(5) {
    --n: 5;
}

.news-item.animate-news:nth-child(6) {
    --n: 6;
}

.news-item.animate-news:nth-child(7) {
    --n: 7;
}

.news-item.animate-news:nth-child(8) {
    --n: 8;
}

.news-item.animate-news:nth-child(9) {
    --n: 9;
}

.news-item.animate-news:nth-child(10) {
    --n: 10;
}

/* Components - Map Popup */
.custom-popup .leaflet-popup-content-wrapper,
.leaflet-popup-content-wrapper {
    padding: 0;
    overflow: hidden;
    background-color: var(--card-bg);
    color: var(--text-primary);
}

.leaflet-popup-tip {
    background-color: var(--card-bg);
}

/* Dark Theme Overrides - Map Popup */
[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip {
    background-color: var(--card-bg);
    color: var(--text-primary);
}

[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button {
    color: var(--text-secondary);
}

[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button:hover {
    color: var(--text-primary);
}

/* Components - News Window */
.news-window {
    padding: 10px;
    background-color: var(--card-bg);
    border-radius: 4px;
    max-width: 300px;
}

.news-window h3 {
    margin-bottom: 5px;
    font-size: 16px;
    color: var(--text-primary);
}

.news-window p {
    font-size: 14px;
    margin-bottom: 5px;
    color: var(--text-secondary);
}

.news-window p strong {
    color: var(--text-primary);
}

.news-window a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 14px;
}

.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    animation: fadeIn 0.3s ease forwards;
}

/* Mobile resizer */
.resizer-handle {
    display: none;
    position: absolute;
    width: 100%;
    height: 20px;
    background: var(--sidebar-bg);
    z-index: 10;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    cursor: ns-resize;
    touch-action: none;
}

.handle-icon {
    width: 40px;
    height: 4px;
    background: var(--text-light);
    border-radius: 2px;
    margin: 8px auto;
}

/* Mobile tabs */
.mobile-tabs {
    display: none;
    width: 100%;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    z-index: 5;
}

.tab-btn {
    width: 50%;
    padding: 10px;
    border: none;
    background: none;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
}

/* Tab transitions */
.tab-transition {
    overflow: hidden;
}

.tab-content {
    transition: opacity 0.3s ease, transform 0.3s ease;
    opacity: 1;
    transform: translateX(0);
}

.tab-content.hiding {
    opacity: 0;
    transform: translateX(-20px);
}

.tab-content.showing {
    opacity: 0;
    transform: translateX(20px);
}

/* Transition classes */
body.transitioning #map,
body.transitioning .sidebar {
    position: absolute !important;
    width: 100% !important;
    height: calc(100vh - 80px) !important;
    top: 80px !important;
    left: 0 !important;
    z-index: 1;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

body.transitioning.to-map .sidebar {
    opacity: 0;
    transform: translateX(-20px);
}

body.transitioning.to-map #map {
    opacity: 1;
    transform: translateX(0);
    z-index: 2;
}

body.transitioning.to-news #map {
    opacity: 0;
    transform: translateX(20px);
}

body.transitioning.to-news .sidebar {
    opacity: 1;
    transform: translateX(0);
    z-index: 2;
}

/* Custom marker */
.custom-marker-icon {
    display: block;
    border: none;
    background: transparent;
}

/* Logo styles */
.logo-container {
    position: absolute;
    bottom: 10px;
    left: .5%;
    z-index: 999;
    text-align: center;
    pointer-events: none;
}

.logo-container img {
    max-height: 30px;
}

/* Botão carregar mais */
.load-more-btn.rounded-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    color: white;
    border: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
    margin-bottom: 20px;
}

.load-more-btn.rounded-circle:hover {
    background-color: var(--primary-dark);
}

/* Theme Switch */
.theme-switch-wrapper {
    display: flex;
    align-items: center;
    margin-right: 5px;
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.theme-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked+.theme-slider {
    background-color: var(--primary-color);
}

input:focus+.theme-slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked+.theme-slider:before {
    transform: translateX(20px);
}

.theme-icon {
    margin-right: 8px;
    color: var(--text-secondary);
}

.news-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

[data-theme="dark"] .news-actions {
    border-top-color: #444;
}

.share-link {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background-color: #f0f0f0;
    border-radius: 4px;
    color: #333;
    text-decoration: none;
    font-size: 0.9em;
    transition: background-color 0.2s;
}

[data-theme="dark"] .share-link {
    background-color: #444;
    color: #fff;
}

.share-link:hover {
    background-color: #e0e0e0;
    text-decoration: none;
    color: #333;
}

[data-theme="dark"] .share-link:hover {
    background-color: #555;
    color: #fff;
}

.share-link i {
    margin-right: 5px;
}

/* Botão de compartilhamento na lista de notícias */
.news-item-actions {
    margin-top: 8px;
    text-align: right;
}

.share-news-btn {
    display: inline-flex;
    align-items: center;
    font-size: 0.85em;
    color: #666;
    background: none;
    border: none;
    padding: 4px 8px;
    cursor: pointer;
    text-decoration: none;
    border-radius: 4px;
    transition: background-color 0.2s;
}

[data-theme="dark"] .share-news-btn {
    color: #ccc;
}

.share-news-btn:hover {
    background-color: #f0f0f0;
    color: #333;
    text-decoration: none;
}

[data-theme="dark"] .share-news-btn:hover {
    background-color: #444;
    color: #fff;
}

.share-news-btn i {
    margin-right: 4px;
    font-size: 0.9em;
}

/* Toast de notificação */
.toast-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background-color: rgba(60, 60, 60, 0.95);
    color: white;
    padding: 12px 20px;
    border-radius: 4px;
    z-index: 10000;
    font-size: 0.9em;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    max-width: 90%;
    text-align: center;
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

[data-theme="dark"] .toast-notification {
    background-color: rgba(40, 40, 40, 0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

/* Mobile (≤480px) */
@media (max-width: 480px) {

    /* Redefine o layout base para mobile */
    body {
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .mobile-tabs {
        display: flex !important;
        position: fixed;
        top: 0;
        height: 45px;
        width: 100%;
        z-index: 1000;
    }

    /* Garante que o contêiner principal ocupe todo o espaço disponível */
    .main-container {
        position: fixed;
        top: 45px;
        /* Altura das abas */
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: calc(100% - 45px);
        overflow: hidden;
    }

    /* Configuração mais agressiva para sidebar */
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-width: none;
        border-left: none;
        -webkit-overflow-scrolling: touch;
        visibility: hidden;
        z-index: 5;
        margin: 0;
        padding: 0;
        overflow: hidden;
        /* Importante! */
    }

    /* Solução para o problema de rolagem: 
       Modificar o news-container para ser o elemento com rolagem */
    #news-container {
        position: absolute;
        top: 50px;
        /* Altura da barra de pesquisa + um pouco de margem */
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: calc(100% - 50px);
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
        padding: 0 0 0 1rem;
        /* Remove padding direito */
        margin: 0;
        box-sizing: border-box;
    }

    /* Ajuste para a barra de pesquisa */
    .search-container {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 50px;
        z-index: 10;
        padding: 0.5rem;
        box-sizing: border-box;
    }

    /* Ajuste para os itens de notícia */
    .news-item {
        margin-right: 1rem;
        width: calc(100% - 1rem);
        box-sizing: border-box;
    }

    /* Modificações para o mapa */
    #map {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        visibility: hidden;
        z-index: 1;
    }

    /* Quando a aba de mapa está ativa */
    body.tab-map #map {
        visibility: visible;
        z-index: 2;
    }

    /* Quando a aba de notícias está ativa */
    body.tab-news .sidebar {
        visibility: visible;
        z-index: 2;
    }

    body.tab-news .logo-container {
        display: none !important;
    }

    /* Fazer o scrollbar realmente tocar a borda direita */
    ::-webkit-scrollbar {
        width: 3px;
    }

    ::-webkit-scrollbar-thumb {
        background-color: rgba(0, 0, 0, 0.3);
        border-radius: 4px;
    }
    
    /* Split screen for logo and attribution */
    .leaflet-control-attribution {
        position: fixed !important;
        left: 40% !important;
        right: 0 !important;
        bottom: 0 !important;
        background: transparent !important;
        padding: 2px 5px !important;
        font-size: 10px !important;
        z-index: 1000 !important;
        border: none !important;
        margin: 0 !important;
        text-align: right !important;
    }
    
    .logo-container {
        position: fixed !important;
        left: 0 !important;
        right: 60% !important;
        bottom: 0 !important;
        background: transparent !important;
        padding: 2px 5px !important;
        z-index: 1000 !important;
        border: none !important;
        text-align: left !important;
        display: flex !important;
        align-items: center !important;
        height: 24px !important;
    }
    
    .logo-container img {
        height: 25px !important;
        width: auto !important;
        vertical-align: middle !important;
        max-width: 100% !important;
        object-fit: contain !important;
        margin: 5px !important;
    }
    
    /* Ensure the map controls don't overlap with the split footer */
    .leaflet-control-zoom {
        bottom: 20px !important;
    }
    
    /* Dark theme adjustments for attribution and logo */
    [data-theme="dark"] .leaflet-control-attribution,
    [data-theme="dark"] .logo-container {
        background: transparent !important;
        color: #fff !important;
    }
    
    [data-theme="dark"] .leaflet-control-attribution a {
        color: #fff !important;
    }
}