/* Prevent horizontal overflow on small screens and use border-box sizing */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #fafbfc;
    color: #1f2937;
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Lexend Deca', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #111827;
}

/* Container adjustments */
.container {
    background-color: transparent;
    padding: 1rem;
}

main.home-page .container,
main.home-page .container-fluid {
    background-color: transparent;
    padding: 0;
    box-shadow: none;
}

.container-fluid {
    padding: 0;
}

/* Non-home pages get white background */
main:not(.home-page) .container {
    background-color: transparent;
    border-radius: 0;
    box-shadow: none;
}

/* Features Section Container */
.features-section,
.content-section {
    max-width: 1140px;
    margin-left: auto;
    margin-right: auto;
    padding: 0 15px;
}

/* Navbar Styles */
#navbar {
    background-color: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 0.35rem 0;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.05);
}

#navbar .container {
    align-items: center;
    padding: 0 1.5rem;
}

#navbar .navbar-collapse {
    align-items: center;
    gap: 0.75rem;
}

#navbar .navbar-brand {
    font-weight: 500;
    color: #111827;
    font-size: 0.9rem;
    letter-spacing: -0.01em;
}

#navbar .navbar-brand:hover {
    color: #0d6efd;
}

#navbar .navbar-brand img {
    filter: grayscale(20%);
    transition: filter 0.2s ease;
}

#navbar .navbar-brand:hover img {
    filter: grayscale(0%);
}

#navbar .nav-link {
    font-size: 0.9rem;
    color: #6b7280;
    font-weight: 400;
    padding: 0.35rem 0.75rem;
    transition: color 0.2s ease, background-color 0.2s ease;
    border-radius: 999px;
}

#navbar .nav-link:hover {
    color: #0d6efd;
    background-color: rgba(13, 110, 253, 0.08);
}

#navbar .nav-link.active {
    font-weight: 600;
    color: #0d6efd;
}

#navbar .nav-link i {
    font-size: 1rem;
}

@media (max-width: 575.98px) {
    #navbar .container {
        padding: 0 1rem;
    }
}

/* Navbar Search */
.nav-search {
    width: 100%;
    display: flex;
}

.nav-search-wrapper {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    border: 1px solid #e5e7eb;
    border-radius: 999px;
    padding: 0.25rem 0.85rem;
    background-color: #f9fafb;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.nav-search-wrapper:focus-within {
    border-color: #e5e7eb; /* keep subtle, no highlight */
    box-shadow: none;
}

.nav-search-wrapper i {
    color: #6b7280;
    font-size: 1rem;
    line-height: 1;
}

.nav-search-input {
    border: none;
    background: transparent;
    font-size: 0.95rem;
    color: #111827;
    padding: 0.15rem 0;
    width: 100%;
    min-width: 0;
}

.nav-search-input:focus {
    outline: none;
    box-shadow: none !important;
    border-color: transparent !important;
}

/* Keep input background matching the capsule and prevent it turning white on focus/autofill */
.nav-search-input,
.nav-search-input:focus,
.nav-search-wrapper .form-control {
    background-color: transparent !important;
}

/* Chrome autofill: force the same inset background color to avoid yellow/white fill */
.nav-search-input:-webkit-autofill,
.nav-search-input:-webkit-autofill:focus,
.nav-search-input:-webkit-autofill:hover {
    -webkit-text-fill-color: #111827 !important;
    -webkit-box-shadow: 0 0 0 1000px #f9fafb inset !important;
    box-shadow: 0 0 0 1000px #f9fafb inset !important;
}

@media (min-width: 992px) {
    .nav-search {
        width: auto;
        min-width: 200px;
    }

    .nav-search-input {
        width: 150px;
        transition: width 0.25s ease;
    }

    .nav-search-input:focus {
        width: 260px;
    }
}

/* Hero Section - Home Page */
.hero-section {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    padding: 100px 0 120px;
    margin: 0 0 4rem 0;
    position: relative;
}

@media (max-width: 768px) {
    .hero-section {
        padding: 60px 0 80px;
    }
}

.hero-content {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
    animation: fadeInUp 0.8s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hero-title {
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
    letter-spacing: -0.02em;
    color: #fff;
}

@media (max-width: 768px) {
    .hero-title {
        font-size: 2.5rem;
    }
}

.hero-subtitle {
    font-size: 1.25rem;
    margin-bottom: 2.5rem;
    opacity: 0.95;
}

@media (max-width: 768px) {
    .hero-subtitle {
        font-size: 1rem;
    }
}

/* Search Box */
.search-box-container {
    max-width: 700px;
    margin: 0 auto;
}

.search-box .input-group {
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    border-radius: 50px;
    overflow: hidden;
}

.search-box .search-input {
    border: none;
    padding: 1.2rem 1.5rem;
    font-size: 1.1rem;
    border-radius: 50px 0 0 50px;
}

.search-box .search-input:focus {
    box-shadow: none;
    border-color: transparent;
}

.search-box .search-button {
    border: none;
    padding: 1.2rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    background-color: #0d6efd;
    border-radius: 0 50px 50px 0;
    transition: background-color 0.3s ease;
}

.search-box .search-button:hover {
    background-color: #0b5ed7;
}

@media (max-width: 768px) {
    .search-box .search-input,
    .search-box .search-button {
        font-size: 1rem;
        padding: 1rem 1.2rem;
    }
}

/* Features Section */
.features-section {
    margin-top: 4rem;
    margin-bottom: 4rem;
}

.feature-card {
    padding: 2rem;
    border-radius: 12px;
    height: 100%;
    background: white;
    border: 1px solid #e9ecef;
}

.feature-icon {
    font-size: 3rem;
    color: #0d6efd;
    margin-bottom: 1rem;
}

.feature-card h3 {
    margin-top: 1rem;
    margin-bottom: 0.75rem;
    color: #212529;
}

.feature-card p {
    margin-bottom: 1rem;
    min-height: 48px;
}

.feature-card .stats-number {
    font-size: 2rem;
    font-weight: 700;
    color: #0d6efd;
    margin-bottom: 1rem;
}

.content-section {
    margin-top: 4rem;
    padding-top: 4rem;
    border-top: 1px solid #e9ecef;
}

/* Updates Section */
.updates-section {
    margin: 4rem auto;
    max-width: 1140px;
    padding: 0 15px;
}

.section-title {
    font-size: 1.75rem;
    font-weight: 600;
    color: #212529;
    margin-bottom: 2rem;
}

.section-title i {
    color: #0d6efd;
    margin-right: 0.5rem;
}

.update-card {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 1.25rem;
    height: 100%;
}

.update-card-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: #212529;
    text-decoration: none;
    display: block;
    line-height: 1.4;
}

.update-card-title:hover {
    color: #0d6efd;
    text-decoration: none;
}

.update-card-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.update-card-meta .badge {
    font-size: 0.75rem;
    font-weight: 500;
}

.update-card-meta small {
    font-size: 0.8rem;
}

/* Busca Page Styles */
.busca-page .search-box-container {
    max-width: 800px;
    margin: 2rem auto;
}

.busca-page .search-box .input-group {
    border-radius: 12px;
}

.busca-page .search-box .search-input {
    border-radius: 12px 0 0 12px;
}

.busca-page .search-box .search-button {
    border-radius: 0 12px 12px 0;
}

/* Main content spacing */
main.flex-shrink-0 {
    padding-top: 2rem;
    padding-bottom: 2rem;
}

main.flex-shrink-0.home-page {
    padding-top: 0;
    padding-bottom: 0;
}

/* Compact layout for small screens */
@media (max-width: 575.98px) {
    /* Reduce side paddings on main containers */
    .container {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    main:not(.home-page) .container {
        border-radius: 0;
        box-shadow: none;
    }

    /* Tighten hero and sections on mobile */
    .hero-section {
        margin-bottom: 2.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .features-section,
    .content-section,
    .updates-section,
    .busca-page .search-box-container {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Reduce footer padding on small screens */
    .footer .container,
    .footer .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* Footer */
.footer {
    background-color: #f9fafb;
    border-top: 1px solid #e5e7eb;
}

.footer a {
    color: #6b7280;
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer a:hover {
    color: #0d6efd;
}

/* Breadcrumb */
.breadcrumb {
    background-color: #f9fafb;
    border: none;
}

.breadcrumb-item a {
    color: #0d6efd;
    text-decoration: none;
    transition: color 0.2s ease;
}

.breadcrumb-item a:hover {
    color: #0b5ed7;
}

.breadcrumb-item.active {
    color: #6b7280;
}

/* Cards and Panels */
.card {
    border: none;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.agregado-title-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

/* Page-specific card refinements */
.assuntos-card .card-title {
    font-size: 1.8rem;
    line-height: 1.3;
    min-height: 3rem;
}

.assuntos-card .card-body {
    padding: 1.5rem;
}

.hover-card .card-title {
    font-size: 1.8rem;
    line-height: 1.3;
    min-height: 3rem;
}

.pesquisas-list .card-body {
    padding: 1.5rem;
}

.pesquisas-list .card-title {
    font-size: 1.8rem;
    line-height: 1.3;
}

.pesquisas-list .badge {
    font-size: 0.75rem;
}

.pesquisas-list .small {
    font-size: 0.875rem;
}

@media (max-width: 768px) {
    .assuntos-card .card-title {
        font-size: 1.4rem;
        min-height: auto;
    }

    .hover-card .card-title {
        font-size: 1.4rem;
        min-height: auto;
    }

    .assuntos-card .card-body,
    .pesquisas-list .card-body {
        padding: 1.25rem;
    }
}

@media (max-width: 576px) {
    .pesquisas-list .card-body {
        padding: 1rem;
    }

    .pesquisas-list .card-title {
        font-size: 1.4rem;
    }
}

/* Badges */
.badge {
    font-weight: 500;
    padding: 0.35em 0.65em;
    border-radius: 6px;
}

/* Buttons */
.btn {
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.2s ease;
    border-width: 1px;
}

.btn-outline-primary {
    border-color: #d1d5db;
    color: #374151;
}

.btn-outline-primary:hover {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: white;
}

/* Alerts */
.alert {
    border-radius: 8px;
    border: 1px solid;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

table .right {
    text-align: right;
}
table .center {
    text-align: center;
}

table span.english {
    font-size: 0.85em;
    font-style: italic;
    color: #6c757d;
}

.agregado-info-details {
    display: flex;
    flex-flow: row wrap;
    justify-content: center;
    gap: 15px;
    margin: 2.5rem 0;
}
.agregado-info-details a.external {
    color: #dc3545;
    text-decoration: none;
    font-weight: 500;
}
.agregado-info-details a.external:hover {
    color: #c82333;
    text-decoration: underline;
}

.access-ibge-sidra {
    display: block;
    margin: 1.5em auto;
    max-width: 800px;
    padding: 1.2em;
    text-align: center;
    border: 1px solid #007bff;
    color: #007bff;
    background-color: #e7f3ff;
    border-radius: 6px;
    font-weight: 500;
}

/* Periodos */
.periodos-timeline {
    display: flex;
    flex-flow: row wrap;
    justify-content: center;
    gap: 8px;
    text-align: center;
    margin: 1em 0;
    font-size: 0.85em;
}

/* New Timeline Styles */
.timeline-year-group {
    display: flex;
    flex-direction: row; /* Year header and periods grid side-by-side */
    align-items: flex-start; /* Align items to the top */
    gap: 0.5rem; /* Space between year header and its periods grid */
    margin-bottom: 0.5rem; /* Small vertical spacing between year groups */
}

.timeline-year-header {
    font-weight: bold;
    padding: 0.5rem;
    min-width: 60px; /* Ensure year header has some width */
    text-align: right; /* Align year text to the right for a cleaner look */
}

.timeline-periods-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(40px, 1fr)); /* Mobile: 3 columns */
    gap: 5px; /* Small gap between period blocks */
    flex-grow: 1; /* Allow grid to take remaining space */
}

@media (min-width: 768px) {
    .timeline-periods-grid {
        grid-template-columns: repeat(5, minmax(40px, 1fr)); /* Tablet: 5 columns */
    }
}

@media (min-width: 1200px) {
    .timeline-periods-grid {
        grid-template-columns: repeat(10, minmax(40px, 1fr)); /* Desktop/Large: 10 columns */
    }
}

.timeline-periods-grid.twelve-periods {
    grid-template-columns: repeat(6, minmax(40px, 1fr));
}

@media (min-width: 1200px) {
    .timeline-periods-grid.twelve-periods {
        grid-template-columns: repeat(12, minmax(40px, 1fr));
    }
}

/* Small screens: keep year header at left */
@media (max-width: 767.98px) {
    .timeline-year-group {
        gap: 0.5rem;
        margin-bottom: 0.75rem; /* Add vertical spacing between year groups */
    }

    .timeline-year-header {
        text-align: left;
        min-width: auto;
    }

    .timeline-periods-grid {
        width: 100%;
    }
}

.timeline-period-block {
    font-size: 0.8em;
    padding: 0.5rem;
    border-radius: 4px;
    text-align: center;
    min-height: 30px; /* Ensure blocks have a minimum height */
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent; /* Base border */
}

.timeline-period-block.available {
    background-color: #28a745; /* Green for available, Bootstrap success color */
    color: white;
    border-color: #218838; /* Darker green border */
}

.timeline-period-block.unavailable {
    background-color: #e9ecef; /* Light gray for unavailable, Bootstrap bg-light */
    color: #6c757d; /* Muted text color */
    border-color: #ced4da; /* Gray border */
}


/* Classificações */
.classicacoes-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px;
    margin: 1em 0;
}

.classificacoes-list {
    display: flex;
    flex-direction: column;
}

.classificacao-card {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
}

.classificacao-card:last-child {
    border-bottom: none;
}

.classificacao-card-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

@media (min-width: 768px) {
    .classificacao-card-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }
}

.classificacao-nome {
    font-weight: 600;
    font-size: 1rem;
}

.classificacao-descricao {
    margin-top: 0.75rem;
    font-size: 0.95rem;
    color: #374151;
}

/* Modificações pages */
.stat-card {
    background-color: #fff;
    border: none;
    border-radius: 10px;
    padding: 1.1rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
    height: 100%;
}

.stat-label {
    font-size: 0.85rem;
    text-transform: uppercase;
    color: #6b7280;
    letter-spacing: 0.05em;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 600;
    color: #0d6efd;
}

.modificacoes-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modificacao-card {
    border: none;
    border-radius: 10px;
    padding: 1.1rem;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.modificacao-card-header {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

@media (min-width: 768px) {
    .modificacao-card-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.modificacao-card-metrics {
    display: flex;
    gap: 1rem;
}

.modificacao-metric {
    background-color: #f9fafb;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    min-width: 120px;
}

.mod-metric-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #6b7280;
    letter-spacing: 0.04em;
}

.mod-metric-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 600;
    color: #111827;
}

.modificacao-card-actions {
    margin-top: 1rem;
}

.modificacao-info-summary {
    border: none;
    border-radius: 12px;
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background-color: #fff;
}

@media (min-width: 768px) {
    .modificacao-info-summary {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.mod-info-metric {
    text-align: left;
}

.tabelas-mod-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.pesquisa-group {
    border-left: 3px solid #0d6efd;
    padding-left: 1rem;
}

.pesquisa-group-header {
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e5e7eb;
}

.pesquisa-group-header h6 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #111827;
}

.pesquisa-group-header a {
    color: #0d6efd;
    transition: color 0.2s ease;
}

.pesquisa-group-header a:hover {
    color: #0a58ca;
}

.research-list {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.research-names {
    margin-top: 0.25rem;
}

.research-names li {
    display: block;
    margin-bottom: 0.25rem;
}

.research-names li:last-child {
    margin-bottom: 0;
}

.modificacao-card h3 a:hover {
    text-decoration: underline !important;
}

.tabela-mod-card {
    border: none;
    border-radius: 10px;
    padding: 1rem 1.25rem;
    background-color: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.tabela-mod-card-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

@media (min-width: 576px) {
    .tabela-mod-card-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.tabela-mod-count {
    text-align: center;
}

.count-value {
    display: block;
    font-size: 2rem;
    font-weight: 600;
    color: #0d6efd;
    line-height: 1;
}

.count-label {
    font-size: 0.85rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tabela-mod-card-actions {
    margin-top: 0.75rem;
}

/* Atualizacoes task list */
.updates-task-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.task-card {
    border: none;
    border-radius: 10px;
    padding: 1.15rem;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.task-card-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

@media (min-width: 576px) {
    .task-card-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.task-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.task-card-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
}

.task-card-metrics .metric-label {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
}

.task-card-metrics .metric-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #111827;
}

.task-card-actions {
    margin-top: 1rem;
}

/* Mapa de localidades styles */
.agregado-mapa .legend .badge {
    margin-right: 8px;
    font-size: 0.75em;
}

#map-loading {
    position: relative;
    z-index: 1000;
}

.leaflet-popup-content {
    font-size: 14px;
    line-height: 1.4;
}

.leaflet-popup-content .badge {
    font-size: 0.75em;
}

/* Responsive map adjustments */
@media (max-width: 768px) {
    #map {
        height: 400px !important;
    }

    .agregado-mapa .row {
        flex-direction: column;
    }

    .agregado-mapa .legend {
        margin-top: 10px;
        text-align: center;
    }
}
