/* Base Settings */
:root {
    --bg-color: #f8fafc;        /* Slate 50 */
    --text-main: #1e293b;       /* Slate 800 */
    --text-muted: #64748b;      /* Slate 500 */
    
    /* Accents - adjusted for light background */
    --accent-blue: #0ea5e9;     /* Sky 500 */
    --accent-emerald: #10b981;  /* Emerald 500 */
    --accent-pink: #f43f5e;     /* Rose 500 */
    --accent-indigo: #6366f1;   /* Indigo 500 */

    /* Glass Effects for Light Mode */
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, rgba(14, 165, 233, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(99, 102, 241, 0.05) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    line-height: 1.5;
}

/* Utilities */
.hidden {
    display: none !important;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: 0 4px 20px -5px rgba(0, 0, 0, 0.1);
}

/* Layout */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
.main-header {
    margin-bottom: 2rem;
    padding: 1.5rem 2rem;
    position: sticky;
    top: 1rem;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.main-nav {
    display: flex;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 1);
    padding: 0.5rem;
    border-radius: 14px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.nav-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.7rem 1.4rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.nav-btn:hover {
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.03);
}

.nav-btn.active {
    background: var(--accent-blue);
    color: white;
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
}

.title-group {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.logo-container {
    width: 64px;
    height: 64px;
    background: white;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease;
}

.logo-container:hover {
    transform: scale(1.05);
}

.header-logo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--text-main);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.file-upload-btn {
    background: linear-gradient(135deg, #38bdf8 0%, #1d4ed8 100%);
    color: #fff;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(56, 189, 248, 0.3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.file-upload-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(56, 189, 248, 0.4);
}

.file-upload-btn input {
    display: none;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.loader-content h2 {
    color: var(--text-main);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.loader-content p {
    color: var(--text-muted);
    font-weight: 500;
}

.spinner {
    width: 70px;
    height: 70px;
    border: 5px solid rgba(0, 0, 0, 0.05);
    border-left-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    box-shadow: 0 10px 20px rgba(56, 189, 248, 0.1);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Placeholder */
.placeholder-container {
    display: flex;
    justify-content: center;
    margin-top: 4rem;
}

.placeholder-content {
    text-align: center;
    padding: 4rem;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.placeholder-content.hidden {
    display: none;
}

.security-note {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--accent-emerald);
    background: rgba(52, 211, 153, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
}

/* Dashboard Content */
.dashboard-content.hidden {
    display: none;
}

/* KPI Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.kpi-card {
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1.25rem;
    transition: transform 0.3s ease;
}

.kpi-card:hover {
    transform: translateY(-5px);
}

.kpi-icon {
    width: 50px;
    height: 50px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: rgba(255,255,255,0.05);
}

.kpi-icon.blue { color: var(--accent-blue); box-shadow: inset 0 0 20px rgba(56, 189, 248, 0.2); border: 1px solid rgba(56,189,248,0.3); }
.kpi-icon.emerald { color: var(--accent-emerald); box-shadow: inset 0 0 20px rgba(52, 211, 153, 0.2); border: 1px solid rgba(52,211,153,0.3); }
.kpi-icon.pink { color: var(--accent-pink); box-shadow: inset 0 0 20px rgba(244, 114, 182, 0.2); border: 1px solid rgba(244,114,182,0.3); }
.kpi-icon.indigo { color: var(--accent-indigo); box-shadow: inset 0 0 20px rgba(129, 140, 248, 0.2); border: 1px solid rgba(129,140,248,0.3); }

.kpi-info h3 {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

.kpi-subtext {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-top: 0.25rem;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.chart-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.chart-wide {
    grid-column: span 2;
}

.chart-header {
    margin-bottom: 1.5rem;
}

.chart-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.chart-header p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.chart-body {
    flex: 1;
    position: relative;
    min-height: 350px;
    width: 100%;
}

.doughnut-container, .polar-container {
    min-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Table Section */
.table-section {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.table-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.glass-select {
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-main);
    border: 1px solid var(--accent-blue);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    outline: none;
    font-family: inherit;
    cursor: pointer;
}

.glass-select option {
    background: var(--bg-color);
}

.table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 600px;
    width: 100%;
    border-radius: 0.5rem;
    border: 1px solid var(--glass-border);
}

#beneficiaryTable {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

#beneficiaryTable th, #beneficiaryTable td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

#beneficiaryTable th {
    background: #f1f5f9;
    font-weight: 700;
    color: var(--accent-blue);
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

#beneficiaryTable tr:last-child td {
    border-bottom: none;
}

#beneficiaryTable tr:hover td {
    background: #f8fafc;
}

/* Badges */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.prio-1 { background: rgba(244, 63, 94, 0.08); color: var(--accent-pink); border: 1px solid rgba(244, 63, 94, 0.2); }
.prio-2 { background: rgba(99, 102, 241, 0.08); color: var(--accent-indigo); border: 1px solid rgba(99, 102, 241, 0.2); }
.prio-3 { background: rgba(16, 185, 129, 0.08); color: var(--accent-emerald); border: 1px solid rgba(16, 185, 129, 0.2); }
.prio-4 { background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.prio-5 { background: #f8fafc; color: #94a3b8; border: 1px solid #f1f5f9; }

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.btn-paginate {
    background: #fff;
    border: 1px solid #e2e8f0;
    color: var(--text-main);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-paginate:hover:not(:disabled) {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.btn-paginate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#pageInfo {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 1024px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .chart-wide {
        grid-column: span 1;
    }
}

/* Action Button */
.btn-action {
    background: rgba(56, 189, 248, 0.1);
    color: var(--accent-blue);
    border: 1px solid var(--accent-blue);
    padding: 0.4rem 0.8rem;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-action:hover {
    background: var(--accent-blue);
    color: #fff;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: #fff;
    width: 100%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1rem;
    transform: scale(0.95);
    transition: transform 0.3s ease;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.modal-overlay:not(.hidden) .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #fff;
}

.modal-body {
    padding: 1.5rem;
}

/* Dossier Grid */
.dossier-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.dossier-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem;
}

.program-badges {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.program-badge {
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.05);
    color: #94a3b8;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.program-badge.active {
    background: rgba(52, 211, 153, 0.1);
    color: #34d399;
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.discrepancy-card {
    grid-column: 1 / -1;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    padding: 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.discrepancy-card h4 {
    color: #f59e0b !important;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.discrepancy-card ul {
    list-style: none;
    padding-left: 0;
}

.discrepancy-card li {
    font-size: 0.9rem;
    color: #fcd34d;
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(245, 158, 11, 0.1);
}

.discrepancy-card li:last-child {
    border-bottom: none;
}

.dossier-card h4 {
    color: var(--accent-blue);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
}

.dossier-item {
    margin-bottom: 0.75rem;
}

.dossier-item:last-child {
    margin-bottom: 0;
}

.dossier-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.dossier-value {
    font-size: 0.95rem;
    font-weight: 500;
    color: #f8fafc;
}

@media (max-width: 640px) {
    .dossier-grid {
        grid-template-columns: 1fr;
    }
}

/* Eligibility Criteria Highlights */
.eligibility-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.elig-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    text-align: center;
}

.elig-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.elig-status {
    width: 100%;
    padding: 0.4rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.elig-status.active {
    background: rgba(52, 211, 153, 0.1);
    border-color: var(--accent-emerald);
    color: var(--accent-emerald);
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.1);
    animation: pulse-emerald 2s infinite;
}

@keyframes pulse-emerald {
    0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(52, 211, 153, 0); }
    100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}

/* Table in Modal */
.modal-table-container {
    margin-top: 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--glass-border);
    overflow: hidden;
}

.modal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.modal-table th {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.75rem;
    text-align: left;
    color: var(--accent-blue);
    font-weight: 600;
}

.modal-table td {
    padding: 0.75rem;
    border-top: 1px solid var(--glass-border);
    color: var(--text-main);
}

.modal-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}


/* Top 10 CEPs List */
.ceps-detail-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 500px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.ceps-detail-list::-webkit-scrollbar {
    width: 6px;
}

.ceps-detail-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.cep-detail-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: all 0.3s ease;
}

.cep-detail-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--accent-pink);
    transform: translateX(5px);
}

.cep-badge-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cep-number-badge {
    background: var(--accent-pink);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.8rem;
    box-shadow: 0 0 15px rgba(244, 114, 182, 0.3);
}

.cep-score-tag {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.cep-address-main {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}

.cep-address-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.loading-small {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-style: italic;
    animation: pulse-op 1.5s infinite;
}

@keyframes pulse-op {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Map Styles */
.leaflet-container {
    background: var(--bg-color) !important;
    font-family: 'Inter', sans-serif !important;
}

.leaflet-popup-content-wrapper {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border) !important;
    color: var(--text-main) !important;
    border-radius: 12px !important;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1) !important;
    padding: 0.2rem !important;
}

.leaflet-popup-tip {
    background: rgba(255, 255, 255, 0.95) !important;
}

.map-popup-header {
    border-bottom: 1px solid rgba(0,0,0,0.05);
    margin-bottom: 8px;
    padding-bottom: 6px;
}

.map-popup-title {
    font-weight: 800;
    color: var(--accent-blue);
    font-size: 1.1rem;
    margin: 0;
}

.map-popup-body {
    font-size: 0.9rem;
    color: var(--text-main);
    line-height: 1.4;
}

.map-popup-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 600;
    display: block;
    margin-top: 4px;
}

.map-popup-count {
    display: inline-block;
    background: var(--accent-pink);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 700;
    margin-top: 10px;
    font-size: 0.85rem;
    box-shadow: 0 4px 12px rgba(244, 63, 94, 0.2);
}
