.portal-access-brand {
    background: linear-gradient(145deg, var(--cmh-green-dark), var(--cmh-green) 58%, var(--cmh-success));
}

.access-brand-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.access-brand-link:hover,
.access-brand-link:focus-visible {
    color: white;
    background: #ffffff14;
}

.access-brand-link:focus-visible {
    outline: 2px solid #ffffffcc;
    outline-offset: 3px;
}

.access-return {
    --bs-btn-color: var(--cmh-green-dark);
    --bs-btn-border-color: #b9d4c6;
    --bs-btn-hover-color: var(--cmh-green-dark);
    --bs-btn-hover-bg: var(--cmh-soft);
    --bs-btn-hover-border-color: #8fbca7;
    --bs-btn-active-color: var(--cmh-green-dark);
    --bs-btn-active-bg: #dcefe5;
    --bs-btn-active-border-color: #8fbca7;
    border-radius: 0.6rem;
    font-weight: 600;
}

.portal-header {
    min-height: 4.75rem;
    color: white;
    background: linear-gradient(110deg, var(--cmh-green-dark), var(--cmh-green));
    box-shadow: 0 2px 10px #14382a1a;
}

.portal-header .navbar-brand {
    border-radius: 0.75rem;
    margin-inline: -0.5rem;
    padding-inline: 0.5rem;
    transition: background-color 160ms ease;
}

.portal-header .navbar-brand,
.portal-header .navbar-brand:hover,
.portal-header .navbar-brand:focus-visible {
    color: white;
}

.portal-header .navbar-brand:hover,
.portal-header .navbar-brand:focus-visible {
    background: #ffffff14;
}

.portal-main {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 4.75rem);
    background: var(--cmh-background);
}

.portal-content {
    flex: 1;
    padding: 2rem 2.25rem;
}

.portal-container {
    max-width: 64rem;
    margin: 0 auto;
}

.portal-container .card {
    border: 1px solid var(--cmh-border);
    box-shadow: 0 2px 8px #173b2b08;
}

.portal-container .admin-detail dt {
    font-size: 0.8rem;
    font-weight: 650;
}

.portal-container .admin-detail dd {
    margin-bottom: 1rem;
}

.portal-container .badge {
    white-space: normal;
    text-align: left;
}

.portal-container .feature-icon {
    width: 2.75rem;
    height: 2.75rem;
}

.portal-container .feature-icon .app-icon {
    width: 1.35rem;
    height: 1.35rem;
}

/* Seguimiento de expedientes legales del médico */
.portal-container {
    --state-completed: var(--cmh-success);
    --state-in-progress: #d99a00;
    --state-pending: #8a99ad;
}

.portal-case-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
    gap: 1.25rem;
}

.portal-case-card,
.portal-summary-card {
    background: #fff;
    border: 1px solid var(--cmh-border);
    border-radius: 1rem;
    box-shadow: 0 2px 8px #173b2b08;
}

.portal-case-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-top: 4px solid var(--state-completed);
}

.portal-case-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1.25rem 1.25rem 0.5rem;
}

.portal-case-card-body {
    flex: 1;
    padding: 0.5rem 1.25rem 1rem;
}

.portal-case-card-foot {
    padding: 0.85rem 1.25rem 1.25rem;
}

.portal-chip {
    flex-shrink: 0;
    padding: 0.2rem 0.65rem;
    border: 1px solid #b9d4c6;
    border-radius: 999px;
    background: var(--cmh-soft);
    color: var(--cmh-green-dark);
    font-size: 0.75rem;
    font-weight: 650;
}

.portal-progress-track {
    height: 0.65rem;
    overflow: hidden;
    border-radius: 999px;
    background: #e4ebe7;
}

.portal-progress-bar {
    width: var(--portal-progress, 0%);
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--cmh-accent), var(--state-completed));
}

.portal-progress-text {
    margin: 0.6rem 0 0.4rem;
    font-size: 0.85rem;
    color: var(--cmh-muted);
}

.portal-state-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.8rem;
    color: var(--cmh-muted);
}

.portal-state-dot {
    display: inline-block;
    width: 0.6rem;
    height: 0.6rem;
    margin-right: 0.35rem;
    border-radius: 50%;
    background: var(--state-pending);
}

[data-state='completed'] > .portal-state-dot { background: var(--state-completed); }
[data-state='in_progress'] > .portal-state-dot { background: var(--state-in-progress); }

.portal-summary-card {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 1.5rem;
    padding: 1.5rem;
}

@media (max-width: 767.98px) {
    .portal-summary-card { grid-template-columns: minmax(0, 1fr); }
}

/* Línea de tiempo vertical: nodos alternos a izquierda y derecha de un eje central */
.portal-container {
    --state-in-progress-ink: #7a5200;
    --state-pending-ink: #4f5d70;
}

.portal-timeline-section {
    margin-top: 2rem;
}

.portal-instance {
    --instance-accent: #3d8066;
    --node-size: 2.4rem;
    margin-bottom: 2.25rem;
    padding: 1.25rem 1.25rem 0.25rem;
    background: #fff;
    border: 1px solid var(--cmh-border);
    border-radius: 1rem;
    box-shadow: 0 2px 8px #173b2b08;
}

.portal-instance-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.85rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.9rem;
    border-bottom: 1px solid var(--cmh-border);
}

.portal-instance-head .portal-chip {
    margin-left: auto;
}

.portal-instance-dot {
    flex-shrink: 0;
    width: 0.9rem;
    height: 0.9rem;
    border-radius: 50%;
    background: var(--instance-accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--instance-accent) 20%, transparent);
}

.portal-timeline {
    position: relative;
    margin: 0;
    padding: 0;
    list-style: none;
}

.portal-timeline::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 3px;
    margin-left: -1.5px;
    border-radius: 3px;
    background: color-mix(in srgb, var(--instance-accent) 35%, #e4ebe7);
}

.portal-timeline-item {
    position: relative;
    width: 50%;
    margin-bottom: 1.5rem;
    padding-right: calc(var(--node-size) / 2 + 1.25rem);
}

.portal-timeline-item:nth-child(even) {
    margin-left: 50%;
    padding-right: 0;
    padding-left: calc(var(--node-size) / 2 + 1.25rem);
}

.portal-timeline-node {
    position: absolute;
    top: 0.2rem;
    right: calc(var(--node-size) / -2);
    z-index: 1;
    display: grid;
    place-items: center;
    width: var(--node-size);
    height: var(--node-size);
    border: 3px solid var(--state-pending);
    border-radius: 50%;
    background: #fff;
    color: var(--state-pending-ink);
}

.portal-timeline-item:nth-child(even) .portal-timeline-node {
    right: auto;
    left: calc(var(--node-size) / -2);
}

.portal-timeline-node .app-icon {
    width: 1.15rem;
    height: 1.15rem;
}

.portal-timeline-item[data-state='completed'] .portal-timeline-node {
    border-color: var(--state-completed);
    background: var(--state-completed);
    color: #fff;
}

.portal-timeline-item[data-state='in_progress'] .portal-timeline-node {
    border-color: var(--state-in-progress);
    background: #fff4d6;
    color: var(--state-in-progress-ink);
}

.portal-timeline-card {
    position: relative;
    padding: 0.9rem 1.05rem;
    background: #fff;
    border: 1px solid var(--cmh-border);
    border-top: 3px solid var(--instance-accent);
    border-radius: 0.85rem;
    box-shadow: 0 2px 8px #173b2b0d;
}

.portal-timeline-title {
    margin: 0 0 0.35rem;
    font-size: 1rem;
    font-weight: 650;
    overflow-wrap: anywhere;
}

.portal-timeline-state {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin: 0 0 0.4rem;
    font-size: 0.8rem;
    font-weight: 650;
    color: var(--state-pending-ink);
}

.portal-timeline-state .app-icon {
    width: 0.95rem;
    height: 0.95rem;
}

.portal-timeline-item[data-state='completed'] .portal-timeline-state { color: var(--cmh-success); }
.portal-timeline-item[data-state='in_progress'] .portal-timeline-state { color: var(--state-in-progress-ink); }

.portal-timeline-text {
    margin: 0;
    font-size: 0.88rem;
    color: var(--cmh-muted);
    overflow-wrap: anywhere;
}

@media (max-width: 767.98px) {
    .portal-instance {
        padding: 1rem 0.9rem 0.1rem;
    }

    .portal-timeline::before {
        left: calc(var(--node-size) / 2);
    }

    .portal-timeline-item,
    .portal-timeline-item:nth-child(even) {
        width: 100%;
        margin-left: 0;
        padding-right: 0;
        padding-left: calc(var(--node-size) + 0.9rem);
    }

    .portal-timeline-item .portal-timeline-node,
    .portal-timeline-item:nth-child(even) .portal-timeline-node {
        right: auto;
        left: 0;
    }
}

/* Bitácora reciente: tarjetas con el comentario y su etapa */
.portal-journal-section {
    margin: 0.5rem 0 2rem;
}

.portal-journal {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 21rem), 1fr));
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.portal-journal-item {
    display: flex;
    gap: 0.8rem;
    align-items: flex-start;
}

.portal-journal-icon {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: var(--cmh-soft);
    color: var(--cmh-green-dark);
}

.portal-journal-icon .app-icon {
    width: 1.2rem;
    height: 1.2rem;
}

.portal-journal-card {
    flex: 1;
    min-width: 0;
    padding: 0.9rem 1.05rem;
    background: #fff;
    border: 1px solid var(--cmh-border);
    border-left: 4px solid var(--cmh-green-dark);
    border-radius: 0.85rem;
    box-shadow: 0 2px 8px #173b2b0d;
}

.portal-journal-stage {
    margin: 0 0 0.4rem;
    font-size: 0.95rem;
    font-weight: 650;
    color: var(--cmh-green-dark);
    overflow-wrap: anywhere;
}

.portal-journal-body {
    margin: 0 0 0.6rem;
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.portal-journal-date {
    margin: 0;
    font-size: 0.75rem;
    color: var(--cmh-muted);
}

.portal-journal-note,
.portal-journal-empty {
    margin: 1rem 0 0;
    font-size: 0.85rem;
    color: var(--cmh-muted);
}

/* Avance por instancias y etapas (panel de seguimiento de expedientes) */
.expediente-instances-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.expediente-instance-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--cmh-border);
    border-radius: 999px;
    font-size: 0.78rem;
    color: var(--cmh-muted);
    background: #fff;
}

.expediente-instance-chip-dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: #94a3b8;
}

.expediente-instance-chip.is-completed .expediente-instance-chip-dot { background: var(--cmh-success); }
.expediente-instance-chip.is-active .expediente-instance-chip-dot { background: #0d6efd; }
.expediente-instance-chip.is-pending .expediente-instance-chip-dot { background: #94a3b8; }

.expediente-timeline-item {
    position: relative;
    padding-left: 1.6rem;
    padding-bottom: 1.25rem;
}

.expediente-timeline-item:last-child {
    padding-bottom: 0;
}

.expediente-timeline-item::before {
    content: '';
    position: absolute;
    left: 0.32rem;
    top: 1.5rem;
    bottom: 0;
    width: 2px;
    background: var(--cmh-border);
}

.expediente-timeline-item:last-child::before {
    display: none;
}

.expediente-timeline-dot {
    position: absolute;
    left: 0;
    top: 0.25rem;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background: #94a3b8;
}

.expediente-timeline-item.is-completed .expediente-timeline-dot { background: var(--cmh-success); }
.expediente-timeline-item.is-active .expediente-timeline-dot { background: #0d6efd; }
.expediente-timeline-item.is-pending .expediente-timeline-dot { background: #94a3b8; }

.expediente-progress {
    height: 0.55rem;
    border-radius: 999px;
    background: var(--cmh-border);
    overflow: hidden;
}

.expediente-progress-bar {
    height: 100%;
    border-radius: 999px;
    background: var(--cmh-success);
}

@media (max-width: 991.98px) {
    .portal-content {
        padding: 1.5rem;
    }
}

@media (max-width: 575.98px) {
    .portal-header {
        padding-left: 0.25rem;
        padding-right: 0.25rem;
    }

    .portal-content {
        padding: 1.25rem 1rem;
    }
}
