/* ============================================
   RESET & BASE
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   LAYOUT: base_layout.html
   ============================================ */
.body-layout {
    background-color: #F9FAFB;
    min-height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.header-main {
    background-color: #fff;
    border-bottom: 1px solid #E5E7EB;
    color: #000;
    padding: 1rem;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.header-main .header-container {
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.header-main .header-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.main-content {
    max-width: 1280px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: 1rem;
    flex-grow: 1;
}

.footer-main {
    background-color: #fff;
    border-top: 1px solid #E5E7EB;
    color: #000;
    padding: 0.5rem;
    margin-top: 2rem;
    flex-shrink: 0;
}

.footer-main .footer-container {
    max-width: 1280px;
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

/* ============================================
   UTILITY: Clase base reutilizable para cards
   ============================================ */
.card {
    background-color: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 0.375rem;
    padding: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    user-select: none;
}

.card span {
    font-weight: bold;
    color: #666;
}

/* ============================================
   DASHBOARD: dashboard.html
   ============================================ */
.dashboard-main {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.content-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.content-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

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

.section-dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.activities-row {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 1rem;
    scroll-behavior: smooth;
}

.activities-row::-webkit-scrollbar {
    height: 8px;
}

.activities-row::-webkit-scrollbar-track {
    background: #E5E7EB;
    border-radius: 4px;
}

.activities-row::-webkit-scrollbar-thumb {
    background: #9CA3AF;
    border-radius: 4px;
}

.activities-row::-webkit-scrollbar-thumb:hover {
    background: #6B7280;
}

.activities-row>* {
    scroll-snap-align: start;
    flex: 0 0 auto;
    width: 320px;
}

.empty-activities {
    height: 10rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.empty-activities p {
    color: #6B7280;
}

.details-row {
    width: 100%;
    display: flex;
    gap: 1rem;
}

/* ============================================
   COMPONENT: label_section.html
   ============================================ */
.label-section-container {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-bottom: 0.625rem;
}

.label-section-content {
    width: 100%;
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

.label-section {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: #9CA3AF;
    user-select: none;
}

.label-section-link {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
    font-weight: 500;
    padding-inline: 0.5rem;
    background: rgb(38, 139, 223);
    border-radius: 0.375rem;
    padding-block: 0.25rem;
}

/* ============================================
   COMPONENT: kpi.html
   ============================================ */
.kpi-card {
    display: flex;
    justify-content: space-between;
    /* border: 1px solid #E5E7EB; */
    border-radius: 0.375rem;
    padding: 1rem;
    user-select: none;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    background-color: var(--kpi-bg, #fff);
}

.kpi-card .kpi-text {
    display: flex;
    flex-direction: column;
}

.kpi-card .kpi-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--kpi-text-color, #4B5563);
}

.kpi-card .kpi-value {
    font-size: 1.875rem;
    font-weight: 600;
    color: var(--kpi-text-color, #4B5563);
}

.kpi-card .kpi-subtitle {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--kpi-text-color, #4B5563);
}

.kpi-card .kpi-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}

.kpi-card .kpi-icon {
    font-size: 3.75rem;
    color: var(--kpi-icon-color, #9CA3AF);
}

/* ============================================
   COMPONENT: card_details.html
   Usa clase base .card + .card-details
   ============================================ */
.card-details {
    width: 320px;
}

.card-details .card-inner {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card-details .status-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-details .status-dot {
    width: 0.5rem;
    height: 0.5rem;
    background-color: #22C55E;
    border-radius: 50%;
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.card-details .status-text {
    font-size: 0.875rem;
    color: #6B7280;
}

.card-details .card-body {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.card-details .card-header-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.card-details .card-icon-box {
    height: min-content;
    display: flex;
    align-items: center;
    padding: 0.5rem;
    color: #6B7280;
    background-color: #E5E7EB;
    border-radius: 0.375rem;
}

.card-details .card-meta {
    display: flex;
    flex-direction: column;
}

.card-details .card-meta-label {
    font-size: 0.875rem;
    color: #6B7280;
}

.card-details .card-meta-value {
    font-size: 1rem;
    font-weight: 600;
}

.card-details .dates-row {
    display: flex;
    gap: 0.5rem;
}

.card-details .date-badge {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: #374151;
    background-color: #E5E7EB;
    border-radius: 9999px;
    padding: 0.25rem 0.5rem;
    white-space: nowrap;
}

.card-details .btn-row {
    margin-top: auto;
    display: flex;
    gap: 0.5rem;
}

.card-details .btn-details {
    flex-grow: 1;
    background-color: #334155;
    color: #fff;
    border: none;
    border-radius: 0.375rem;
    padding: 0.5rem;
    margin-top: 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    transition: background-color 0.15s ease;
}

.card-details .btn-details:hover {
    background-color: rgba(51, 65, 85, 0.8);
}

/* ============================================
   COMPONENT: card_generos.html
   Usa clase base .card + .card-generos
   ============================================ */
.card-generos {
    height: min-content;
}

.card-generos-title {
    text-align: center;
    margin-bottom: 10px;
    font-weight: bold;
    color: #666;
}

.card-generos .generos-wrapper {
    display: flex;
    justify-content: space-around;
    margin-block: auto;
}

.card-generos .genero-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.genero-col.femenino {
    color: #E5007E;
}

.genero-col.masculino {
    color: #00B3FF;
}

.card-generos .genero-label {
    font-weight: 900;
}

.card-generos .genero-icon-wrapper {
    display: flex;
    gap: 0.5rem;
    position: relative;
}

.card-generos .genero-icon {
    font-size: 6rem;
}

.card-generos .bar-container {
    display: flex;
    align-items: flex-end;
    height: 100%;
    width: 19px;
    padding: 1px;
    border: 1px solid #E5E7EB;
    border-radius: 9999px;
    position: absolute;
    top: 0;
}

.card-generos .bar-container.right {
    right: -2rem;
}

.card-generos .bar-container.left {
    left: -2rem;
}

.card-generos .bar-fill-femenino {
    height: 50%;
    width: 100%;
    background-color: #E5007E;
    border-radius: 9999px;
}

.card-generos .bar-fill-masculino {
    height: 66.67%;
    width: 100%;
    background-color: #00B3FF;
    border-radius: 9999px;
}

.card-generos .genero-total {
    font-weight: 900;
    font-size: 1rem;
    color: #9CA3AF;
}

.card-generos .genero-percentage {
    font-weight: 900;
    font-size: 1.5rem;
}

/* ============================================
   COMPONENT: diagrama_gantt.html
   Usa clase base .card + .gantt-card
   ============================================ */
.gantt-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-radius: 0.75rem;
    padding: 1.5rem;
    grid-column: span 4;
}

.gantt-card p {
    text-align: center;
    color: #9CA3AF;
    margin-top: 1rem;
}

.gantt-title {
    margin-top: 0.4rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #222;
    user-select: none;
}

/* ============================================
   COMPONENT: table_details.html
   Usa clase base .card + .table-card
   ============================================ */
.table-card {
    flex-grow: 1;
}

.table-card .table-main {
    width: 100%;
    border: 1px solid #E5E7EB;
    border-radius: 0.375rem;
}

.container-table :is(#tabla-actividades_filter, #tabla-actividades_length, #tabla-instituciones_filter, #tabla-instituciones_length) {
    margin-bottom: 1rem;
}

.container-table tbody tr td {
    padding: 1rem;
}

/* ============================================
   COMPONENT: table search bar
   ============================================ */
.table-search-wrapper {
    margin-bottom: 1rem;
}

.table-search-form {
    position: relative;
    display: flex;
    align-items: center;
}

.table-search-icon {
    position: absolute;
    left: 0.75rem;
    display: flex;
    align-items: center;
    color: #9CA3AF;
    pointer-events: none;
    transition: color 0.2s ease;
}

.table-search-input {
    width: 100%;
    padding: 0.625rem 0.75rem 0.625rem 2.5rem;
    font-size: 0.875rem;
    font-family: inherit;
    color: #374151;
    background-color: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 0.5rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.table-search-input::placeholder {
    color: #9CA3AF;
}

.table-search-input:hover {
    border-color: #D1D5DB;
    background-color: #fff;
}

.table-search-input:focus {
    border-color: rgb(38, 139, 223);
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(38, 139, 223, 0.15);
}

.table-search-input:focus+.table-search-icon,
.table-search-form:focus-within .table-search-icon {
    color: rgb(38, 139, 223);
}

/* Clear button inside search input */
.table-search-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2'%3E%3Cpath d='M18 6L6 18M6 6l12 12'/%3E%3C/svg%3E") center/contain no-repeat;
    cursor: pointer;
}

/* HTMX loading indicator */
.table-search-input.htmx-request {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239CA3AF' stroke-width='2'%3E%3Cpath d='M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 18px;
}

/*  ============================================
    COMPONENT: base_proportions.html
    Usa clase base .card + .proportions-card
    ============================================*/
.proportions-card {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    align-items: center;
    justify-content: center;
}

/*  ============================================
    COMPONENT: card_shirt.html
    ============================================*/
.card-shirt {
    display: flex;
    flex-direction: column;
    text-align: center;
}

.card-shirt i {
    font-size: 2rem;
}

/* ============================================
   COMPONENT: CARD ALLERGY
   ============================================ */
.allergy-card__icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 7rem; /* 80px */
  height: 7rem; /* 80px */
  background-color: #fef2f2;
  color: #ef4444;
  font-size: 4rem; /* 36px */
  border-radius: 50%;
  margin: 1.50rem auto; /* Centrado automático y separación vertical */
  margin-top: 2rem;
}

/* =========================================
   Estado y Textos
   ========================================= */
.allergy-card__status {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 0.5rem; /* 8px */
}

.status__labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem; /* 12px */
}

.status__label-text {
  color: #6b7280;
  font-weight: 500;
}

.status__label-value--high {
  color: #ef4444;
  font-weight: 700;
}

/* =========================================
   Barra de Progreso
   ========================================= */
.progress-bar {
  width: 100%;
  height: 0.5rem; /* 8px */
  background-color: #f3f4f6;
  border-radius: 9999px;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  width: 75%;
  background-color: #ef4444;
  border-radius: 9999px;
  transition: all 0.5s ease-in-out;
}

.progress-bar__labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  font-size: 0.7rem;
}

.label-yes {
  color: #ef4444;
  font-weight: 600;
}

.label-no {
  color: #9ca3af;
  font-weight: 500;
}

/* ============================================
   COMPONENT: CARD MEDICAL CONDITION
   ============================================ */
.medical_card__header :is(span, i) {
    font-weight: bold;
    font-size: 2.629rem;
    color: #1F2937;
}

.medical_card__header small {
    display: block;
}

.medical_card_content {
    align-self: center;
    position: relative;
    right: 2rem;
}

.medical_card__legend {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 1rem;
}

.medical_card {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    height: 100%;
}

/* ============================================
   FIX: Desbordamiento móvil en gráficos
   ============================================ */

/* Permite que las columnas del grid se encojan */
.content-grid-2>*,
.content-grid-4>* {
    min-width: 0;
}

/* La tarjeta de gráficos no debe forzar ancho mínimo */
.proportions-card {
    min-width: 0;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Los gráficos inyectados (SVG, Plotly, etc.) se adaptan al contenedor */
.proportions-card svg,
.proportions-card canvas,
.proportions-card img,
.proportions-card .js-plotly-plot,
.proportions-card .plotly,
.proportions-card .plotly-graph-div {
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    display: block;
}

/* ============================================
   RESPONSIVE: Media queries
   ============================================ */
@media (max-width: 1227px) {
    .medical_card_content {
        right: 0;
    }
}
@media (max-width: 1060px) {
    .medical_card__legend {
        flex-direction: row;
        gap: 1rem;
        justify-content: center;
        margin-top: 0;
    }

    .medical_card {
        flex-direction: column;
    }
}

@media (max-width: 1095px) {
    .institutions-responsive-1 {
        grid-template-columns: repeat(1, 1fr);
    }
}

/* Tablet: <= 1024px */
@media (max-width: 1024px) {
    .content-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .gantt-card {
        grid-column: span 2;
    }

    .details-row {
        flex-direction: column;
    }

    .card-details {
        width: 100%;
    }

    .activities-row>* {
        width: 280px;
    }
}

/* Móvil: <= 640px */
@media (max-width: 640px) {
    .header-main .header-title {
        font-size: 1rem;
        text-align: center;
    }

    .main-content {
        padding: 0.75rem;
    }

    .content-grid-4,
    .content-grid-2 {
        grid-template-columns: 1fr;
    }

    .gantt-card {
        grid-column: span 1;
    }

    .kpi-card .kpi-value {
        font-size: 1.5rem;
    }

    .kpi-card .kpi-icon {
        font-size: 2.5rem;
    }

    .card {
        padding: 1rem;
    }

    .activities-row>* {
        width: 260px;
    }

    .card-generos .genero-icon {
        font-size: 4rem;
    }

    .label-section {
        font-size: 1rem;
    }

    .gantt-card,
    .table-card,
    .proportions-card {
        overflow-x: auto;
    }

    .card-details .dates-row {
        flex-wrap: wrap;
    }
}