:root {
    --primary: #24C291;
    --primary-light: #3dd4a8;
    --primary-dark: #0F8B68;
    --secondary: #0F8B68;
    --bg-main: #F4F7F6;
    --bg-card: #FFFFFF;
    --text-primary: #333333;
    --text-secondary: #8898AA;
    --text-muted: #A0AEC0;
    --danger: #E74C3C;
    --warning: #F39C12;
    --success: #24C291;
    --border-light: #E2E8F0;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 8px 30px rgba(36, 194, 145, 0.15);
    --radius: 14px;
    --radius-sm: 10px;
    --radius-lg: 18px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', 'Montserrat', 'Roboto', sans-serif;
}

body {
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow-y: auto;
}

/* Sidebar */
nav {
    width: 260px;
    background: var(--primary);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    transition: all 0.3s ease;
    box-shadow: 4px 0 20px rgba(36, 194, 145, 0.2);
}

.logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2.5rem;
    padding: 0 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.logo-img {
    height: 105px;
    width: auto;
    background: white;
    border-radius: 30%;
    padding: 10px 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.logo h1 {
    font-size: 1.05rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.02em;
    text-align: center;
    width: 100%;
}

.logo h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.02em;
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-links li {
    margin-bottom: 0.4rem;
}

.nav-links button {
    width: 100%;
    padding: 0.85rem 1rem;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 0.85rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.25s ease;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
}

.nav-links button:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.nav-links button.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    font-weight: 600;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.nav-links button span {
    font-size: 0.85rem;
}

/* Main Content */
main {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: var(--bg-main);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
    background: var(--bg-card);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

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

#mainDepFilter {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

#mainDepFilter:hover {
    border-color: var(--primary);
}

#mainDepFilter option {
    background: white;
    color: var(--text-primary);
}

.search-bar {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 0.6rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 350px;
    max-width: 100%;
    transition: all 0.2s ease;
}

.search-bar:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(36, 194, 145, 0.1);
}

.search-bar input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 100%;
    outline: none;
    font-size: 0.9rem;
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

/* Summary Section */
.summary-section {
    margin-bottom: 1.5rem;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.summary-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-soft);
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.summary-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-light);
}

.summary-card h4 {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.6rem;
    font-weight: 600;
}

.summary-card .value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-dark);
}

/* Info Panels - Department & IPS Search */
.info-panel {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-light);
}

.department-info {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.department-info .dept-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
    flex-shrink: 0;
}

.department-info .dept-details {
    flex: 1;
}

.department-info .dept-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.department-info .dept-stats {
    display: flex;
    gap: 1.5rem;
    margin-top: 0.5rem;
}

.department-info .dept-stat {
    display: flex;
    flex-direction: column;
}

.department-info .dept-stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.department-info .dept-stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.department-info .dept-actions {
    display: flex;
    gap: 0.5rem;
}

.department-info .btn-action {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.department-info .btn-action:hover {
    background: var(--primary-dark);
}

/* IPS Search Result */
.ips-search-result {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    cursor: pointer;
}

.ips-search-result .ips-icon {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--secondary), var(--primary-dark));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: white;
    flex-shrink: 0;
}

.ips-search-result .ips-details {
    flex: 1;
}

.ips-search-result .ips-name {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.ips-search-result .ips-nit {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: monospace;
}

.ips-search-result .ips-status {
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.ips-search-result .ips-status.vigente {
    background: rgba(36, 194, 145, 0.15);
    color: var(--success);
}

.ips-search-result .ips-status.por-vencer {
    background: rgba(243, 156, 18, 0.15);
    color: var(--warning);
}

.ips-search-result .ips-status.vencida {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger);
}

.ips-search-result .ips-actions {
    display: flex;
    gap: 0.5rem;
}

.ips-search-result .btn-detail {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ips-search-result .btn-detail:hover {
    background: var(--primary-dark);
}

/* Multiple results */
.ips-results-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-soft);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid var(--border-light);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.kpi-card h3 {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.kpi-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.kpi-card .trend {
    font-size: 0.85rem;
    margin-top: 0.5rem;
    color: var(--text-secondary);
}

/* Alerts Section */
.alerts-section {
    margin-bottom: 1.5rem;
}

.subsection-title {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-weight: 600;
}

.alerts-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
}

.alert-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-light);
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.alert-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
}

.alert-card.vigente::before { background: var(--success); }
.alert-card.proxima::before { background: var(--warning); }
.alert-card.vencida::before { background: var(--danger); }

.alert-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover);
}

.alert-card.vigente:hover { border-color: var(--success); }
.alert-card.proxima:hover { border-color: var(--warning); }
.alert-card.vencida:hover { border-color: var(--danger); }

.alert-card h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.6rem;
    font-weight: 600;
}

.alert-card.vigente h3 { color: var(--success); }
.alert-card.proxima h3 { color: var(--warning); }
.alert-card.vencida h3 { color: var(--danger); }

.alert-card .value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.alert-card .days-info {
    font-size: 0.85rem;
    margin-top: 0.25rem;
    font-weight: 500;
}

.alert-card.vigente .days-info { color: var(--success); }
.alert-card.proxima .days-info { color: var(--warning); }
.alert-card.vencida .days-info { color: var(--danger); }

.alert-card .trend {
    font-size: 0.8rem;
    margin-top: 0.6rem;
    color: var(--text-secondary);
}

/* Dashboard Sections */
.dashboard-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.section-title {
    margin-bottom: 1.25rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-primary);
}

#map {
    height: 480px;
    border-radius: var(--radius-lg);
    z-index: 1;
    box-shadow: var(--shadow-soft);
}

/* Tables */
.table-container {
    overflow-x: auto;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-light);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    padding: 1rem 1.25rem;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-light);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-main);
}

td {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

tr:hover {
    background: rgba(36, 194, 145, 0.04);
}

tr.expandable {
    cursor: pointer;
}

tr.expandable:hover {
    background: rgba(36, 194, 145, 0.08);
}

.expand-icon {
    transition: transform 0.3s ease;
    color: var(--text-secondary);
}

tr.expanded .expand-icon {
    transform: rotate(90deg);
}

.muni-row {
    background: var(--bg-main);
}

.muni-row td {
    padding-left: 2.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.muni-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}

.muni-item {
    background: var(--bg-main);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.muni-item .name {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.muni-item .count {
    background: rgba(36, 194, 145, 0.15);
    color: var(--primary-dark);
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-pills {
    display: flex;
    gap: 0.5rem;
}

.pill {
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.pill.success { 
    background: rgba(36, 194, 145, 0.15); 
    color: var(--success); 
}
.pill.warning { 
    background: rgba(243, 156, 18, 0.15); 
    color: var(--warning); 
}
.pill.danger { 
    background: rgba(231, 76, 60, 0.15); 
    color: var(--danger); 
}
.pill.action { 
    background: rgba(15, 139, 104, 0.1); 
    color: var(--primary-dark); 
    cursor: pointer; 
    border: none; 
    transition: all 0.2s ease;
}

.pill.action:hover {
    background: var(--primary);
    color: white;
}

/* Modal */
.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
}

.drill-down-section {
    margin-top: 1.5rem;
}

.drill-down-section h4 {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.municipality-accordion {
    margin-top: 0.5rem;
}

.municipality-header {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.municipality-header:hover {
    background: rgba(36, 194, 145, 0.08);
    border-color: var(--primary-light);
}

.municipality-header .muni-name {
    font-weight: 600;
    color: var(--text-primary);
}

.municipality-header .muni-count {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.municipality-body {
    display: none;
    padding: 0.75rem 1rem 1rem 1rem;
    background: var(--bg-main);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.municipality-body.active {
    display: block;
}

.sede-item {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 0.85rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-light);
}

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

.sede-item h5 {
    color: var(--primary-dark);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.sede-item .services-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.service-tag {
    background: rgba(15, 139, 104, 0.1);
    color: var(--primary-dark);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
}

.status-indicator.vigente {
    background: rgba(36, 194, 145, 0.15);
    color: var(--success);
}

.status-indicator.proxima {
    background: rgba(243, 156, 18, 0.15);
    color: var(--warning);
}

.status-indicator.vencida {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger);
}

.status-indicator .days {
    font-size: 0.85rem;
}

/* Service Detail Panel */
#serviceDetail {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

#serviceMunicipios {
    max-height: 100%;
    overflow-y: auto;
    flex: 1;
}

.service-muni-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border-light);
    transition: all 0.2s ease;
}

.service-muni-item:hover {
    background: rgba(36, 194, 145, 0.04);
}

.service-muni-item:last-child {
    border-bottom: none;
}

.service-muni-item .muni-name {
    font-weight: 500;
    color: var(--text-primary);
}

.service-muni-item .stats {
    display: flex;
    gap: 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.service-muni-item .stats span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Filter selects in IPS view */
#filterDep, #filterNature, #filterStatus, #serviceFilter {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

#serviceFilter option {
    padding: 0.5rem;
    white-space: normal;
    word-wrap: break-word;
}

#filterDep:hover, #filterNature:hover, #filterStatus:hover {
    border-color: var(--primary);
}

#filterDep option, #filterNature option, #filterStatus option {
    background: white;
    color: var(--text-primary);
}

/* Pagination */
#pagination button {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

#pagination button:hover:not(:disabled) {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

#pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#pagination span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Loading screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-light);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Leaflet map custom styles */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-soft);
}

.leaflet-popup-content {
    margin: 0.75rem 1rem;
    font-family: 'Inter', sans-serif;
}

.leaflet-popup-content b {
    color: var(--text-primary);
    font-weight: 600;
}

.leaflet-container a.leaflet-popup-close-button {
    color: var(--text-secondary);
}

/* Mobile optimization */
@media (max-width: 1024px) {
    nav { width: 220px; }
    .logo h1 { display: block; font-size: 0.9rem; }
    .nav-links span { display: inline; font-size: 0.85rem; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .alerts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    body { flex-direction: column; }
    nav { 
        width: 100%; 
        height: auto; 
        padding: 0.75rem 1rem; 
        border-right: none; 
        border-bottom: 1px solid rgba(255,255,255,0.2);
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .logo { 
        margin-bottom: 0; 
        flex-direction: row;
        gap: 0.5rem;
    }
    .logo-img { height: 50px; }
    .logo h1 { 
        display: block; 
        font-size: 0.85rem; 
        text-align: left;
        width: auto;
    }
    .nav-links { 
        display: flex; 
        justify-content: flex-start;
        gap: 0.3rem;
        flex-wrap: wrap;
        flex: 1;
    }
    .nav-links li { margin: 0; }
    .nav-links button { 
        padding: 0.5rem 0.7rem; 
        flex-direction: column;
        gap: 0.2rem;
        font-size: 0.7rem;
    }
    .nav-links button span { 
        display: inline; 
        font-size: 0.65rem;
        text-align: center;
    }
    .nav-links button::before {
        font-size: 1rem;
    }
    main { padding: 1rem; }
    .kpi-grid { grid-template-columns: 1fr; }
    .alerts-grid { grid-template-columns: 1fr; }
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
    .header-controls { width: 100%; flex-direction: column; align-items: stretch; }
    #mainDepFilter { width: 100%; }
    .search-bar { width: 100%; }
    #map { height: 300px; }
    .viewServicios .card { min-height: 400px; }
    table { font-size: 0.85rem; }
    th, td { padding: 0.6rem 0.8rem; }
}
