﻿/* ========================================
   Dashboard Demanda en Espera
   RAP Metropolitana - rap metro
   ======================================== */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-card: #1c1e2e;
    --bg-card-hover: #22253a;
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-focus: rgba(99, 102, 241, 0.5);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #6366f1;
    --accent-cyan: #22d3ee;
    --accent-purple: #a78bfa;
    --accent-emerald: #34d399;
    --accent-amber: #fbbf24;
    --accent-rose: #fb7185;
    --accent-orange: #fb923c;
    --gradient-blue: linear-gradient(135deg, #6366f1, #8b5cf6);
    --gradient-rose: linear-gradient(135deg, #f43f5e, #fb7185);
    --gradient-emerald: linear-gradient(135deg, #10b981, #34d399);
    --gradient-amber: linear-gradient(135deg, #f59e0b, #fbbf24);
    --glass-bg: rgba(28, 30, 46, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Alturas de capas sticky — ajustar aquí si cambia el diseño */
    --nav-height:    56px;   /* .main-nav height */
    --header-height: 62px;  /* .dashboard-header padding: 1rem 2rem + contenido */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Header === */
.dashboard-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: var(--nav-height);
    z-index: 100;
    backdrop-filter: blur(20px);
}

/* Fila principal del header */
.header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 2rem;   /* padding movido aquí desde el header */
}

/* Segunda fila: filtro */
.header-filter-row {
    border-top: 1px solid rgba(255,255,255,0.05);
    padding: 0 2rem;
    background: rgba(0,0,0,0.15);   /* fondo ligeramente más oscuro para separar */
}

.filter-bar-inner {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: nowrap;
    padding: 0.3rem 0;
}

/* El panel desplegable sale desde la segunda fila */
.filter-dropdown-panel {
    display: none;
    position: absolute;
    left: -2rem;         /* compensa el padding del padre */
    right: -2rem;
    top: 100%;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.08);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    padding: 0.75rem 2rem 0.9rem;
    z-index: 99;
    box-shadow: 0 12px 32px rgba(0,0,0,0.4);
    animation: filterPanelIn 0.15s ease;
}

.filter-dropdown-panel.open { display: block; }

.filter-dropdown-inner {
    max-width: 1600px;
    margin: 0 auto;
}

.filter-dropdown-inner .filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

/* Banner de filtro activo — dentro de la fila también */
.filter-active-banner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0.2rem 0 0.3rem;
    font-size: 0.7rem;
    color: #a5b4fc;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    border-top: 1px solid rgba(99,102,241,0.15);
}

/* Mobile: ajuste del padding en la fila del filtro */
@media (max-width: 768px) {
    .header-content  { padding: 0.5rem 1rem; }
    .header-filter-row { padding: 0 1rem; }

    .filter-dropdown-panel {
        left: -1rem;
        right: -1rem;
        padding: 0.6rem 1rem 0.75rem;
    }
}

/* ============================================
   ANALYSIS SECTION
   ============================================ */
.analysis-section {
    margin-bottom: 0.5rem;
}

.analysis-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-subtle);
    border-left: 4px solid var(--accent-blue);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    animation: fadeInUp 0.5s ease;
}

.analysis-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.analysis-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-primary);
}

    .analysis-title h2 {
        font-size: 1.1rem;
        font-weight: 700;
        margin: 0;
    }

.analysis-badge {
    padding: 0.3rem 0.85rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.analysis-badge-emerald {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.analysis-badge-amber {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.analysis-badge-orange {
    background: rgba(251, 146, 60, 0.15);
    color: #fb923c;
    border: 1px solid rgba(251, 146, 60, 0.3);
}

.analysis-badge-rose {
    background: rgba(251, 113, 133, 0.15);
    color: #fb7185;
    border: 1px solid rgba(251, 113, 133, 0.3);
}

.analysis-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.analysis-block h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 0.4rem 0;
}

.analysis-block p {
    font-size: 0.84rem;
    color: var(--text-muted);
    line-height: 1.65;
    margin: 0;
}

    .analysis-block p strong {
        /*color: var(--text-primary);*/
    }

.text-emerald { color: #34d399; }
.text-amber   { color: #fbbf24; }
.text-orange  { color: #fb923c; }
.text-rose    { color: #fb7185; }

.analysis-footer {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
}

.analysis-timestamp {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.7;
}

/* Collapse behavior */
.analysis-collapse {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

    .analysis-collapse.open {
        max-height: 5000px;
        overflow-y: auto;
    }

.analysis-header {
    margin-bottom: 0;
}

.analysis-collapse.open ~ .analysis-header,
.analysis-card:has(.analysis-collapse.open) .analysis-header {
    margin-bottom: 1.25rem;
}

.analysis-chevron {
    transition: transform 0.3s ease;
    transform: rotate(-90deg);
    margin-left: 0.25rem;
    opacity: 0.5;
}

.analysis-collapse.open ~ .analysis-header .analysis-chevron,
.analysis-card:has(.analysis-collapse.open) .analysis-chevron {
    transform: rotate(0deg);
    opacity: 1;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.update-time {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.btn-refresh {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

    .btn-refresh:hover {
        background: rgba(99, 102, 241, 0.15);
        border-color: var(--accent-blue);
        transform: translateY(-1px);
    }

    .btn-refresh:active {
        transform: translateY(0);
    }

/* === Alert === */
.alert-error {
    max-width: 1600px;
    margin: 1rem auto;
    padding: 1rem 1.5rem;
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.3);
    border-radius: var(--radius-md);
    color: var(--accent-rose);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

/* === Main === */
.dashboard-main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* === KPI Cards === */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

    .kpi-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 3px;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

.kpi-total::before   { background: var(--gradient-blue); }
.kpi-pending::before { background: var(--gradient-rose); }
.kpi-worked::before  { background: var(--gradient-emerald); }
.kpi-progress::before { background: var(--gradient-amber); }

.kpi-card:hover {
    transform: translateY(-2px);
    border-color: var(--glass-border);
    box-shadow: var(--glass-shadow);
}

.kpi-icon { margin-bottom: 0.75rem; }
.kpi-total .kpi-icon   { color: var(--accent-blue); }
.kpi-pending .kpi-icon { color: var(--accent-rose); }
.kpi-worked .kpi-icon  { color: var(--accent-emerald); }
.kpi-progress .kpi-icon { color: var(--accent-amber); }

.kpi-value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
    margin-bottom: 0.3rem;
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.progress-bar-container {
    margin-top: 0.75rem;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--gradient-amber);
    border-radius: 3px;
    transition: width 1s ease;
}

/* === Charts === */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: all 0.3s ease;
    min-width: 0;
}

    .chart-card:hover { border-color: var(--glass-border); }

    .chart-card h3 {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-secondary);
        margin-bottom: 1rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }

.chart-container {
    position: relative;
    height: 320px;
}

.chart-container-square { height: 280px; }

/* === Table === */
.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

    .table-card h3 {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-secondary);
        margin-bottom: 1rem;
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead th {
    background: rgba(99, 102, 241, 0.08);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.75rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

    thead th:first-child {
        text-align: left;
        border-radius: var(--radius-sm) 0 0 0;
    }

    thead th:last-child {
        border-radius: 0 var(--radius-sm) 0 0;
    }

tbody td {
    padding: 0.65rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    transition: background 0.15s ease;
}

tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }

.summary-table tbody td,
.summary-table thead th { white-space: nowrap; }

.td-name {
    text-align: left !important;
    font-weight: 500;
    color: var(--text-primary);
}

.td-worked {
    color: var(--accent-emerald);
    font-weight: 600;
}

.td-pending { color: var(--accent-rose); }

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-ok     { background: rgba(16, 185, 129, 0.15); color: var(--accent-emerald); }
.status-danger { background: rgba(244, 63, 94, 0.15);  color: var(--accent-rose); }

.pct-critical { color: #ef4444; font-weight: 700; }
.pct-high     { color: var(--accent-rose);    font-weight: 600; }
.pct-medium   { color: var(--accent-amber);   font-weight: 600; }
.pct-low      { color: var(--accent-emerald); font-weight: 600; }

tfoot td {
    padding: 0.75rem 1rem;
    text-align: right;
    background: rgba(99, 102, 241, 0.05);
    border-top: 2px solid rgba(99, 102, 241, 0.2);
    color: var(--text-primary);
}

tfoot .td-name { text-align: left !important; }

/* === Footer === */
.dashboard-footer {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
    text-align: center;
}

    .dashboard-footer p {
        font-size: 0.75rem;
        color: var(--text-muted);
        letter-spacing: 0.03em;
    }

/* === Animations === */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

.kpi-card {
    animation: fadeInUp 0.5s ease forwards;
}
    .kpi-card:nth-child(1) { animation-delay: 0.05s; }
    .kpi-card:nth-child(2) { animation-delay: 0.1s; }
    .kpi-card:nth-child(3) { animation-delay: 0.15s; }
    .kpi-card:nth-child(4) { animation-delay: 0.2s; }

.chart-card {
    animation: fadeInUp 0.5s ease forwards;
    animation-delay: 0.25s;
    opacity: 0;
}

.table-card {
    animation: fadeInUp 0.5s ease forwards;
    animation-delay: 0.35s;
    opacity: 0;
}

/* === Mobile Nav Toggle === */
.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

    .nav-toggle:hover {
        background: rgba(255, 255, 255, 0.04);
        border-color: var(--glass-border);
    }

    .nav-toggle .hamburger-icon {
        display: flex;
        flex-direction: column;
        gap: 4px;
        width: 18px;
    }

        .nav-toggle .hamburger-icon span {
            display: block;
            height: 2px;
            background: var(--text-primary);
            border-radius: 1px;
            transition: all 0.3s ease;
        }

.nav-mobile-menu { display: none; }

/* === Navigation Bar === */
.main-nav {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 200;
    backdrop-filter: blur(20px);
}

.nav-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--nav-height);
    gap: 1rem;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.02em;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    position: relative;
}

    .nav-link:hover {
        color: var(--text-primary);
        background: rgba(255, 255, 255, 0.04);
    }

.nav-link-active {
    color: var(--accent-blue);
    background: rgba(99, 102, 241, 0.1);
}

    .nav-link-active::after {
        content: '';
        position: absolute;
        bottom: calc(-1 * var(--nav-height) / 4);
        left: 50%;
        transform: translateX(-50%);
        width: 60%;
        height: 2px;
        background: var(--accent-blue);
        border-radius: 1px;
    }

.nav-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    background: transparent;
    border: 1px solid rgba(244, 63, 94, 0.3);
    border-radius: var(--radius-sm);
    color: var(--accent-rose);
    font-family: var(--font-family);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

    .btn-logout:hover {
        background: rgba(244, 63, 94, 0.1);
        border-color: var(--accent-rose);
    }

/* === Login Page === */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 50%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    padding: 2.5rem;
    box-shadow: var(--glass-shadow);
    backdrop-filter: blur(20px);
    animation: fadeInUp 0.5s ease;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

    .login-header .logo-mark {
        display: inline-block;
        margin-bottom: 1rem;
    }

    .login-header h1 {
        font-size: 1.4rem;
        font-weight: 700;
        color: var(--text-primary);
        margin-bottom: 0.25rem;
    }

.login-error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(244, 63, 94, 0.1);
    border: 1px solid rgba(244, 63, 94, 0.25);
    border-radius: var(--radius-sm);
    color: var(--accent-rose);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
    animation: fadeInUp 0.3s ease;
}

.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

    .password-wrapper input {
        flex: 1;
        padding-right: 2.75rem;
    }

.btn-toggle-password {
    position: absolute;
    right: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s ease;
}

    .btn-toggle-password:hover { color: var(--text-primary); }

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

    .form-group label {
        font-size: 0.8rem;
        font-weight: 500;
        color: var(--text-secondary);
        letter-spacing: 0.02em;
    }

    .form-group input {
        padding: 0.75rem 1rem;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-sm);
        color: var(--text-primary);
        font-family: var(--font-family);
        font-size: 0.9rem;
        transition: all 0.2s ease;
        outline: none;
    }

        .form-group input::placeholder { color: var(--text-muted); }

        .form-group input:focus {
            border-color: var(--accent-blue);
            background: rgba(99, 102, 241, 0.05);
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
        }

.btn-login {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    background: var(--gradient-blue);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
}

    .btn-login:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
    }

    .btn-login:active { transform: translateY(0); }

.login-footer {
    margin-top: 2rem;
    text-align: center;
}

    .login-footer p {
        font-size: 0.7rem;
        color: var(--text-muted);
        letter-spacing: 0.03em;
    }

/* === Search Page === */
.search-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 2rem;
    animation: fadeInUp 0.5s ease;
}

    .search-card h2 {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        font-size: 1.3rem;
        font-weight: 700;
        color: var(--text-primary);
        margin-bottom: 0.3rem;
    }

        .search-card h2 svg { color: var(--accent-blue); }

.search-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.search-form,
.search-input-group {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

    .search-input-group input {
        width: 280px;
        max-width: 100%;
        padding: 0.75rem 1.25rem;
        background: rgba(255, 255, 255, 0.04);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-sm);
        color: var(--text-primary);
        font-family: var(--font-family);
        font-size: 1rem;
        outline: none;
        transition: all 0.2s ease;
    }

        .search-input-group input::placeholder { color: var(--text-muted); }

        .search-input-group input:focus {
            border-color: var(--accent-blue);
            background: rgba(99, 102, 241, 0.05);
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
        }

.btn-search {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.75rem 1.5rem;
    background: var(--gradient-blue);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

    .btn-search:hover {
        transform: translateY(-1px);
        box-shadow: 0 4px 20px rgba(99, 102, 241, 0.35);
    }

    .btn-search:active { transform: translateY(0); }

    .btn-search.loading { pointer-events: none; opacity: 0.8; }

    .btn-search .spinner {
        display: none;
        width: 18px;
        height: 18px;
        border: 2px solid rgba(255, 255, 255, 0.3);
        border-top-color: white;
        border-radius: 50%;
        animation: spin 0.6s linear infinite;
    }

    .btn-search.loading .spinner  { display: inline-block; }
    .btn-search.loading .search-icon { display: none; }

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Results === */
.results-section { animation: fadeInUp 0.4s ease; }

.results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

    .results-header h3 { margin-bottom: 0; }

.results-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.04);
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    font-weight: 500;
}

.patient-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    overflow: hidden;
    transition: all 0.2s ease;
}

    .patient-card:hover {
        border-color: rgba(99, 102, 241, 0.3);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    }

.patient-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: rgba(99, 102, 241, 0.04);
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.patient-name {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
    color: var(--text-primary);
}

    .patient-name svg { color: var(--accent-blue); }

.patient-badges {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-doc {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-blue);
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge-conducta {
    background: rgba(52, 211, 153, 0.12);
    color: var(--accent-emerald);
    border: 1px solid rgba(52, 211, 153, 0.3);
}

.badge-pending {
    background: rgba(251, 191, 36, 0.12);
    color: var(--accent-amber);
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.patient-details { padding: 1rem 1.25rem; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.detail-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
}

.detail-value {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

    .detail-value.highlight {
        color: var(--accent-cyan);
        font-weight: 600;
    }

.detail-full { margin-bottom: 0.6rem; }

    .detail-full .detail-value {
        margin-top: 0.15rem;
        font-size: 0.83rem;
        line-height: 1.5;
    }

.detail-origin {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-subtle);
}

.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

    .no-results svg { margin-bottom: 1rem; opacity: 0.4; }

    .no-results p {
        font-size: 0.95rem;
        color: var(--text-secondary);
    }

.no-results-hint {
    font-size: 0.8rem !important;
    color: var(--text-muted) !important;
    margin-top: 0.5rem;
}

/* === AI Button === */
.btn-ai {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.85rem;
    background: rgba(167, 139, 250, 0.12);
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 20px;
    color: #a78bfa;
    font-family: var(--font-family);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

    .btn-ai:hover {
        background: rgba(167, 139, 250, 0.22);
        border-color: #a78bfa;
        transform: translateY(-1px);
        box-shadow: 0 4px 16px rgba(167, 139, 250, 0.2);
    }

    .btn-ai:active { transform: translateY(0); }

/* === AI Link (subtle) === */
.analysis-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

    .analysis-block-header h4 { margin: 0; }

.btn-ai-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: 0.68rem;
    font-weight: 500;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.2s ease;
}

    .btn-ai-link:hover { opacity: 1; color: var(--accent-purple); }

/* === Inline bar charts in table cells === */
.td-bar-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 100px;
}

.td-bar-value {
    flex-shrink: 0;
    min-width: 2.5rem;
    text-align: right;
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
}

.td-bar-track {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
    min-width: 40px;
}

.td-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}

.td-bar-blue    { background: var(--accent-blue); }
.td-bar-amber   { background: var(--accent-amber); }
.td-bar-emerald { background: var(--accent-emerald); }
.td-bar-rose    { background: var(--accent-rose); }
.td-bar-purple  { background: var(--accent-purple); }

/* === Grupos Legend === */
.grupos-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);
}

.grupos-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.grupos-legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ========================================
   RESPONSIVE — MOBILE FIRST
   ======================================== */

/* ---- Tablet (≤ 1024px) ---- */
@media (max-width: 1024px) {
    .dashboard-main {
        padding: 1rem 1.25rem;
        gap: 1rem;
    }

    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .charts-row { grid-template-columns: 1fr; }
    .nav-title { display: none; }
}

/* ---- Mobile (≤ 768px) ---- */
@media (max-width: 768px) {
    :root {
        --nav-height: 52px;
        --header-height: 52px;   /* header más compacto en mobile */
    }

    .main-nav { padding: 0 1rem; }

    .nav-content {
        height: var(--nav-height);
        position: relative;
        flex-wrap: wrap;
    }

    .nav-content > .nav-links,
    .nav-content > .nav-right { display: none; }

    .nav-toggle { display: flex; }

    .nav-mobile-menu {
        display: none;
        flex-direction: column;
        gap: 0;
        width: 100%;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-subtle);
        padding: 0.75rem 0;
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        z-index: 300;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    }

    .nav-mobile-menu.active { display: flex; }

    .nav-mobile-menu .nav-links {
        flex-direction: column;
        gap: 0;
        padding: 0 0.5rem;
    }

    .nav-mobile-menu .nav-link {
        padding: 0.75rem 1rem;
        border-radius: var(--radius-sm);
        font-size: 0.9rem;
    }

    .nav-mobile-menu .nav-link-active::after { display: none; }

    .nav-mobile-menu .nav-right {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 1.5rem 0.25rem;
        border-top: 1px solid var(--border-subtle);
        margin-top: 0.25rem;
    }

    .dashboard-header {
        padding: 0.6rem 1rem;
        top: var(--nav-height);
    }

    .dashboard-header h1 { font-size: 1rem; }
    .subtitle { font-size: 0.7rem; }

    .update-time span,
    .update-time svg { display: none; }

    .update-time { font-size: 0.7rem; }

    .btn-refresh span { display: none; }

    .btn-refresh {
        padding: 0.5rem;
        min-width: 36px;
        justify-content: center;
    }

    .dashboard-main {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.6rem;
    }

    .kpi-card { padding: 1rem; }
    .kpi-value { font-size: 1.5rem; }
    .kpi-label { font-size: 0.7rem; }

    .kpi-icon svg,
    .kpi-icon i { width: 18px; height: 18px; font-size: 1.1rem; }

    .charts-row { grid-template-columns: 1fr; }
    .chart-card { padding: 1rem; }
    .chart-card h3 { font-size: 0.78rem; margin-bottom: 0.75rem; }
    .chart-container { height: 240px; }
    .chart-container-square { height: 220px; }

    .analysis-card { padding: 1rem; }
    .analysis-title h2 { font-size: 0.95rem; }

    .analysis-block p,
    .analysis-block li { font-size: 0.8rem; line-height: 1.55; }

    .analysis-block h4 { font-size: 0.8rem; }

    .table-card { padding: 0.75rem; }
    .table-card h3 { font-size: 0.78rem; }
    table { font-size: 0.78rem; }

    thead th { font-size: 0.68rem; padding: 0.5rem 0.6rem; }
    tbody td  { padding: 0.5rem 0.6rem; }
    tfoot td  { padding: 0.5rem 0.6rem; }

    .td-bar-cell  { min-width: 70px; }
    .td-bar-track { min-width: 24px; }
    .td-bar-value { min-width: 2rem; font-size: 0.72rem; }

    .search-card { padding: 1rem; }

    .search-form,
    .search-input-group {
        flex-direction: column;
        align-items: stretch;
    }

    .search-input-group input { width: 100%; }
    .btn-search { width: 100%; justify-content: center; }

    .detail-grid { grid-template-columns: 1fr 1fr; }
    .dashboard-footer { padding: 1.25rem 1rem; }

    /* Filtro en mobile */
    .filter-bar { padding: 0.3rem 1rem; }
}

/* ---- Mobile pequeño (≤ 480px) ---- */
@media (max-width: 480px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .kpi-value { font-size: 1.3rem; }
    .dashboard-header h1 { font-size: 0.9rem; }
    .detail-grid { grid-template-columns: 1fr; }

    .analysis-badge {
        font-size: 0.65rem;
        padding: 0.2rem 0.6rem;
    }

    .summary-table thead th:nth-child(n+6),
    .summary-table tbody td:nth-child(n+6) { display: none; }
}

/* ── Filtro por especialidad ── */                                 
.filter-bar {
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    padding: 0.35rem 1.5rem;
    position: sticky;
    top: calc(var(--nav-height) + var(--header-height));  /* apila correctamente */
    z-index: 99;
    backdrop-filter: blur(20px);
}

.filter-bar-inner {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: 1600px;
    margin: 0 auto;
    flex-wrap: nowrap;
}

.filter-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-weight: 600;
    flex-shrink: 0;
}

.filter-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.72rem;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.18);
    color: var(--text-secondary);
    background: transparent;
    font-family: var(--font-family);
    font-weight: 500;
    transition: all 0.15s;
    flex-shrink: 0;
}

.filter-toggle-btn:hover {
    border-color: rgba(255,255,255,0.32);
    color: var(--text-primary);
}

.filter-toggle-btn.has-filter {
    background: rgba(99, 102, 241, 0.18);
    border-color: #6366f1;
    color: #a5b4fc;
    font-weight: 600;
}

.filter-toggle-chevron {
    font-size: 0.6rem;
    transition: transform 0.2s ease;
    opacity: 0.6;
}

.filter-toggle-btn.open .filter-toggle-chevron {
    transform: rotate(180deg);
    opacity: 1;
}

.filter-active-pills {
    display: flex;
    gap: 0.25rem;
    flex-wrap: nowrap;
    overflow: hidden;
    flex: 1;
    min-width: 0;
}

.filter-active-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    background: rgba(99, 102, 241, 0.2);
    border: 1px solid #6366f1;
    color: #a5b4fc;
    white-space: nowrap;
    flex-shrink: 0;
}

.filter-active-pill-count {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99,102,241,0.3);
    color: #818cf8;
    white-space: nowrap;
    flex-shrink: 0;
}

.filter-clear {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
    white-space: nowrap;
    flex-shrink: 0;
    transition: color 0.15s;
}

.filter-clear:hover { color: #fb7185; }

.filter-dropdown-panel {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.08);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    padding: 0.75rem 1.5rem 0.85rem;
    z-index: 98;
    box-shadow: 0 12px 32px rgba(0,0,0,0.4);
    animation: filterPanelIn 0.15s ease;
}

.filter-dropdown-panel.open { display: block; }

@keyframes filterPanelIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.filter-dropdown-inner {
    max-width: 1600px;
    margin: 0 auto;
}

.filter-dropdown-inner .filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.filter-chip {
    display: inline-block;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    font-size: 0.71rem;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-muted);
    background: transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    user-select: none;
    white-space: nowrap;
}

.filter-chip:hover {
    border-color: rgba(255,255,255,0.28);
    color: var(--text-primary);
}

.filter-chip-active {
    background: rgba(99, 102, 241, 0.2);
    border-color: #6366f1;
    color: #a5b4fc;
    font-weight: 600;
}

.filter-active-banner {
    background: rgba(99, 102, 241, 0.08);
    border-bottom: 1px solid rgba(99, 102, 241, 0.2);
    padding: 0.25rem 1.5rem;
    font-size: 0.72rem;
    color: #a5b4fc;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.filter-active-tag {
    background: rgba(99, 102, 241, 0.25);
    border: 1px solid rgba(99, 102, 241, 0.4);
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    color: #c7d2fe;
}

/* Pills y tags de centro (teal para distinguir de especialidad) */
.filter-active-pill-centro {
    background: rgba(45, 212, 191, 0.18);
    border-color: #2dd4bf;
    color: #5eead4;
}

.filter-active-tag-centro {
    background: rgba(45, 212, 191, 0.2);
    border: 1px solid rgba(45, 212, 191, 0.4);
    color: #99f6e4;
}
