/* Table styles */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 0; /* Adjusted for card context */
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.table th {
    background-color: #343a40;
    color: #FFFFFF;
    font-weight: bold;
}

.table tr:last-child td {
    border-bottom: none;
}

.table td:nth-child(4) {
    width: 30%;
}

/* Progress bar styles */
.progress-container {
    display: flex;
    align-items: center;
}

.progress-bar-container {
    flex-grow: 1;
    background-color: #e0e0e0;
    border-radius: 4px;
    position: relative;
    width: 100%;
}

.progress-bar {
    height: 18px;
    background-color: var(--accent-color);
    border-radius: 4px;
    transition: width 1.2s ease-in-out;
}

.progress-bar.has-progress {
    min-width: 16px;
}

.progress-bar-text {
    margin-left: 10px;
    color: var(--text-color);
    font-weight: bold;
}

/* Conditional Background Colors */
.bg-red-light {
    background-color: var(--red-light-bg);
}

.bg-orange-light {
    background-color: var(--orange-light-bg);
}

.bg-light-green-light {
    background-color: var(--light-green-light-bg);
}

.bg-green-light {
    background-color: var(--green-light-bg);
}

.bg-dark-green-light {
    background-color: var(--dark-green-light-bg);
}

/* Conditional Progress Bar Colors */
.progress-bar-red {
    background-color: var(--red-bright);
}

.progress-bar-orange {
    background-color: var(--orange);
}

.progress-bar-light-green {
    background-color: var(--light-green);
}

.progress-bar-green {
    background-color: var(--green);
}

.progress-bar-dark-green {
    background-color: var(--dark-green);
}

/* Flicker Animation */
@keyframes flicker {
    0%,
    100% {
        background-color: var(--red-bright);
    }

    50% {
        background-color: var(--red-dark);
    }
}

.flicker {
    animation: flicker 2s infinite;
}

/* Expandable row styles */
.expandable-content td {
    padding: 0 !important;
    border: 0;
}

.expandable-wrapper {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out;
}

.expandable-details {
    display: flex;
    padding: 20px;
    gap: 20px;
    background-color: #f9f9f9;
}

.expandable-content.show .expandable-wrapper {
    max-height: 400px;
}

.details-text {
    flex: 1;
}

.details-chart {
    flex: 1;
    position: relative;
    height: 300px;
    width: 600px;
}

/* --- Page Header Layout --- */

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 25px;
    gap: 20px;
}

.page-header h1 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--secondary-color);
}

/* Header Controls (Dept/Bimester) */
.header-controls {
    display: flex;
    gap: 20px;
}

.context-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.context-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.context-select {
    width: 220px;
}


/* --- Content Card Layout --- */

.content-card {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    overflow: hidden;
    margin-bottom: 30px;
}

/* Card Toolbar */
.card-toolbar {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    background-color: #fff;
    flex-wrap: wrap;
    gap: 15px;
}

/* All filters are now on the left (toolbar-left) */
.toolbar-left {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    flex: 1; /* Allow it to take available space */
}

/* Removed unused toolbar-right */

.filter-select {
    width: 200px;
    height: 38px;
}

.filter-select .option {
    min-height: 38px;
    line-height: 36px;
}

.search-input {
    height: 38px;
}

/* Card Body */
.card-body {
    padding: 20px;
}


/* --- Shared Component Styles (Inputs & Selects) --- */

/* Custom Select Styling */
.select-wrapper {
    position: relative;
    height: 40px;
}

.select-wrapper.context-select {
    width: 220px;
}

.select-wrapper.filter-select {
    width: 200px;
}

.custom-select {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    height: auto;
    min-height: 40px;
    width: 100%;
    z-index: 20;
    background-color: #fff;
    border-radius: 6px;
}

/* Inherit height for filter-select case if needed, but min-height handles it generally */

.custom-select .option {
    padding: 0 45px 0 15px; /* Increased right padding to prevent text overlap with arrow */
    min-height: 40px;
    display: block;
    line-height: 38px;
    background: #fff;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    position: absolute;
    top: 0;
    width: 100%;
    pointer-events: none;
    order: 2;
    z-index: 10;
    transition: all 0.2s ease;
    box-sizing: border-box;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis; /* Truncate long text */
    cursor: pointer;
}

.custom-select .option:hover {
    background: #f8f9fa;
    border-color: #bbb;
}

.custom-select:focus {
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-radius: 6px;
    background-color: #fff;
}

.custom-select:focus .option {
    position: relative;
    pointer-events: all;
    border-top: none;
    border-radius: 0;
}

.custom-select:focus .option:first-of-type {
    border-top: 1px solid var(--border-color);
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

.custom-select:focus .option:last-of-type {
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
}

/* Hide inputs */
.custom-select input.selectopt {
    opacity: 0;
    position: absolute;
    left: -9999px;
}

/* Checked State */
.custom-select input.selectopt:checked + label {
    order: 1;
    z-index: 11;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    position: relative;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Arrow Icon */
.custom-select input.selectopt:checked + label:after {
    content: '';
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #666;
    position: absolute;
    right: 15px;
    top: calc(50% - 2px);
    pointer-events: none;
    transition: transform 0.2s ease;
}

.custom-select:focus {
    outline: none;
}

.custom-select:focus input.selectopt:checked + label {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
    z-index: 12;
}

.custom-select:focus input.selectopt:checked + label:after {
    transform: rotate(180deg);
}

/* Search Input Styling */
.search-wrapper {
    position: relative;
    width: 250px;
}

.search-input {
    width: 100%;
    padding: 0 15px 0 40px;
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-sizing: border-box;
    background-color: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: var(--font-family);
    height: 40px;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    opacity: 0.6;
}

.search-input:focus + .search-icon path {
    fill: var(--accent-color);
    opacity: 1;
}

/* Responsive adjustments */
@media (max-width: 992px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-controls {
        width: 100%;
        flex-wrap: wrap;
    }

    .context-select {
        width: 100%;
    }

    .card-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-left {
        width: 100%;
    }

    .filter-select, .search-wrapper {
        width: 100%;
    }

    /* Table scroll fix */
    #estatisticas-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .table {
        min-width: 800px; /* Ensure table has minimum width to trigger scroll */
    }
}
