:root {
    --primary: #4f6b9a;
    --primary-dark: #3d5578;
    --bg-main: #f4f6f8;
    --bg-sidebar: #3d4f6b;
    --text-primary: #2d3436;
    --text-secondary: #5a6c7d;
    --success: #5a9e6f;
    --warning: #c9a227;
    --danger: #b85450;
    --border-color: #dce4eb;
    --sidebar-width: 260px;
    /* Tipografía global (−0.5 pt aprox. vs. 16px/14px): notebook */
    --ui-font-root: 15.5px;
    --ui-font-body: 13.5px;
    --form-font-size: 0.78125rem;
    --form-line-height: 1.35;
}

* { box-sizing: border-box; }

html {
    font-size: var(--ui-font-root);
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    font-size: var(--ui-font-body);
    margin: 0;
}

body.app-body {
    background: var(--bg-main);
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
    position: relative;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    position: relative;
    isolation: isolate;
}

.main-content::before {
    content: '';
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: var(--sidebar-width);
    background: var(--bg-medical-image) center center / 68% no-repeat;
    filter: blur(3px);
    opacity: 0.55;
    z-index: 0;
    pointer-events: none;
}

.main-content::after {
    content: '';
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: var(--sidebar-width);
    background: rgba(244, 246, 248, 0.45);
    z-index: 0;
    pointer-events: none;
}

.content-area {
    position: relative;
    z-index: 1;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 1000;
    transition: transform .3s ease;
}

.sidebar-brand {
    padding: 1rem;
    font-weight: 600;
    font-size: 1rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
    display: flex;
    align-items: center;
    gap: .75rem;
}

.sidebar-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
    padding: 3px;
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    min-width: 0;
    line-height: 1.2;
}

.sidebar-brand-name {
    font-size: .72rem;
    font-weight: 700;
    line-height: 1.25;
    letter-spacing: .01em;
}

.sidebar-brand-tagline {
    font-size: .58rem;
    font-weight: 500;
    line-height: 1.2;
    opacity: .78;
    letter-spacing: .02em;
}

.sidebar-nav { padding: .75rem 0; }

.nav-section {
    padding: .75rem 1rem .25rem;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    opacity: .6;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1rem;
    color: rgba(255,255,255,.85);
    text-decoration: none;
    transition: background .2s;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: rgba(255,255,255,.12);
    color: #fff;
}

.nav-group-toggle {
    display: flex;
    align-items: center;
    gap: .75rem;
    width: 100%;
    padding: .6rem 1rem;
    border: 0;
    background: transparent;
    color: rgba(255,255,255,.85);
    text-align: left;
    font-size: inherit;
    cursor: pointer;
    transition: background .2s;
}

.nav-group-toggle:hover,
.nav-group-toggle[aria-expanded="true"] {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.nav-group-toggle .nav-chevron {
    margin-left: auto;
    font-size: .65rem;
    opacity: .7;
    transition: transform .2s ease;
}

.nav-group-toggle[aria-expanded="true"] .nav-chevron {
    transform: rotate(180deg);
}

.nav-sub .nav-link {
    padding-left: 2.25rem;
    font-size: .9rem;
}

.nav-sub .nav-link i {
    width: 1rem;
    text-align: center;
    font-size: .85rem;
}

.nav-link-standalone {
    margin-top: .15rem;
}

.sidebar .nav-section {
    margin-top: .25rem;
}

.nav-divider {
    height: 1px;
    margin: .65rem 1rem;
    background: rgba(255,255,255,.15);
}

.top-navbar {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.97) 0%, rgba(248, 250, 252, 0.95) 100%);
    border-bottom: 1px solid var(--border-color);
    padding: .65rem 1.35rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, 0 4px 18px rgba(61, 79, 107, .06);
}

.top-navbar::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--primary) 0%, rgba(79, 107, 154, .35) 45%, transparent 100%);
    pointer-events: none;
}

.navbar-title {
    flex: 1;
    min-width: 0;
}

.navbar-kicker {
    display: block;
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--primary);
    opacity: .85;
    line-height: 1.2;
    margin-bottom: .1rem;
}

.navbar-page-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--text-primary);
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-shrink: 0;
}

.navbar-user-card {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .35rem .65rem .35rem .35rem;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(79, 107, 154, .06);
}

.navbar-user-avatar {
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    font-size: .78rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: .02em;
    box-shadow: 0 4px 10px rgba(79, 107, 154, .25);
}

.navbar-user-meta {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.navbar-user-name {
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.navbar-user-role {
    font-size: .68rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.navbar-logout-form {
    margin: 0;
}

.navbar-logout-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem .85rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: .65rem;
    transition: color .15s ease, border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.navbar-logout-btn:hover {
    color: var(--danger);
    border-color: rgba(184, 84, 80, .35);
    background: #fff8f8;
    box-shadow: 0 4px 12px rgba(184, 84, 80, .1);
}

.sidebar-toggle {
    color: var(--primary-dark);
    padding: .35rem .5rem;
    text-decoration: none;
}

.sidebar-toggle:hover {
    color: var(--primary);
}

.card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    background: rgba(255, 255, 255, 0.88);
}

.card-header {
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.stat-card {
    background: linear-gradient(145deg, #fff 0%, #f9fafb 100%);
    border-radius: .875rem;
    padding: 1.5rem 1rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 16px rgba(79, 107, 154, .06);
    min-height: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: transform .15s ease, box-shadow .15s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(79, 107, 154, .11);
}

.stat-card-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: .75rem;
    background: linear-gradient(145deg, #eef1f7 0%, #e3e8f2 100%);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    margin-bottom: .75rem;
}

.stat-card-label {
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-secondary);
    line-height: 1.3;
    margin-bottom: .35rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-dark);
    line-height: 1;
    letter-spacing: -.02em;
}

.table th {
    background: #f8fafb;
    font-weight: 600;
    font-size: .85rem;
}

.form-label { font-weight: 500; font-size: var(--form-font-size); margin-bottom: .25rem; }

/* Formularios estándar (alineado con grillas compactas vía --form-font-size) */
.content-area form,
.form-app {
    font-size: var(--form-font-size);
}

.content-area form .form-label,
.form-app .form-label,
.content-area form .col-form-label,
.form-app .col-form-label {
    font-size: var(--form-font-size);
    font-weight: 500;
    margin-bottom: .12rem;
    line-height: var(--form-line-height);
}

.content-area form .form-control,
.content-area form .form-select,
.form-app .form-control,
.form-app .form-select {
    font-size: var(--form-font-size);
    line-height: var(--form-line-height);
    padding: .18rem .4rem;
    min-height: calc(var(--form-font-size) * var(--form-line-height) + .36rem);
}

.content-area form .form-control-sm,
.content-area form .form-select-sm,
.form-app .form-control-sm,
.form-app .form-select-sm {
    font-size: var(--form-font-size);
    padding: .18rem .4rem;
    min-height: calc(var(--form-font-size) * var(--form-line-height) + .36rem);
}

.content-area form .form-check-label,
.form-app .form-check-label {
    font-size: var(--form-font-size);
}

.content-area form .btn,
.form-app .btn {
    font-size: var(--form-font-size);
    padding: .22rem .55rem;
}

.content-area form .btn-sm,
.form-app .btn-sm {
    font-size: var(--form-font-size);
    padding: .15rem .4rem;
}

.content-area form small,
.form-app small,
.content-area form .text-muted,
.form-app .text-muted {
    font-size: var(--form-font-size);
}

.form-section {
    margin-bottom: .75rem;
    padding-bottom: .55rem;
    border-bottom: 1px solid var(--border-color);
}

.form-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.form-section-title {
    font-size: var(--form-font-size);
    font-weight: 600;
    color: var(--bg-sidebar);
    margin-bottom: .45rem;
    padding-bottom: .25rem;
    border-bottom: 2px solid rgba(79, 107, 154, 0.25);
}

.prestacion-form-single .row.g-2,
.form-app .row.g-2,
.content-area form .row.g-2 {
    --bs-gutter-y: .35rem;
    --bs-gutter-x: .45rem;
}

.prestacion-form-single .row.g-compact,
.form-app .row.g-compact {
    --bs-gutter-y: .2rem;
    --bs-gutter-x: .4rem;
}

.card-form-compact .card-body {
    padding: .5rem .75rem;
}

.form-actions-bar {
    display: flex;
    gap: .4rem;
    margin-top: .5rem;
    padding-top: .45rem;
    border-top: 1px solid var(--border-color);
}

/* Formulario prestaciones — ultra compacto */
.prestacion-form-single .form-section {
    margin-bottom: .45rem;
    padding-bottom: .35rem;
}

.prestacion-form-single .form-section-card {
    padding: .55rem .65rem .6rem;
    border-radius: 6px;
    border: 1px solid transparent;
    margin-bottom: .55rem;
    border-bottom: none;
}

.prestacion-form-single .form-section-paciente {
    background: #eef6fa;
    border-color: #c8dfea;
}

.prestacion-form-single .form-section-paciente .form-section-title {
    color: #2d6a7e;
    border-bottom-color: rgba(45, 106, 126, 0.3);
}

.prestacion-form-single .form-section-estudio {
    background: #edf7f1;
    border-color: #c5e6d4;
}

.prestacion-form-single .form-section-estudio .form-section-title {
    color: #2f6b4f;
    border-bottom-color: rgba(47, 107, 79, 0.3);
}

.prestacion-form-single .form-section-clinicos {
    background: #faf6eb;
    border-color: #e8d9a8;
}

.prestacion-form-single .form-section-clinicos .form-section-title {
    color: #7a6528;
    border-bottom-color: rgba(122, 101, 40, 0.3);
}

.prestacion-form-single .form-section-profesionales {
    background: #f3f0f8;
    border-color: #d5cce8;
}

.prestacion-form-single .form-section-profesionales .form-section-title {
    color: #5a4a78;
    border-bottom-color: rgba(90, 74, 120, 0.3);
}

.prestacion-form-single .form-section-estudio .row + .row {
    padding-top: .15rem;
    border-top: 1px dashed rgba(47, 107, 79, 0.2);
    margin-top: .35rem !important;
}

.prestacion-form-single .form-section-title {
    margin-bottom: .25rem;
    padding-bottom: .12rem;
    font-size: calc(var(--form-font-size) + .02rem);
}

.prestacion-form-single .form-label {
    margin-bottom: .05rem;
    font-size: calc(var(--form-font-size) - .02rem);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.prestacion-form-single .form-control,
.prestacion-form-single .form-select {
    padding: .08rem .35rem;
    min-height: 1.55rem;
    line-height: 1.25;
}

.form-check-inline-group {
    display: flex;
    flex-wrap: wrap;
    gap: .15rem 1rem;
    padding-top: .15rem;
}

.form-check-inline-group .form-check-input {
    margin-top: .15rem;
}

/* Tom Select compacto */
.form-app .ts-wrapper,
.prestacion-form-single .ts-wrapper {
    width: 100%;
}

.form-app .ts-wrapper.single .ts-control,
.prestacion-form-single .ts-wrapper.single .ts-control {
    min-height: 1.55rem;
    padding: .06rem .3rem;
    font-size: var(--form-font-size);
    line-height: 1.25;
    border-color: #ced4da;
    border-radius: .25rem;
    box-shadow: none;
}

.form-app .ts-wrapper.single.input-active .ts-control,
.prestacion-form-single .ts-wrapper.single.input-active .ts-control {
    border-color: #86b7fe;
    box-shadow: 0 0 0 .15rem rgba(13, 110, 253, .15);
}

.form-app .ts-wrapper .ts-control input,
.prestacion-form-single .ts-wrapper .ts-control input {
    font-size: var(--form-font-size);
    min-width: 2rem;
}

.form-app .ts-dropdown,
.prestacion-form-single .ts-dropdown {
    font-size: var(--form-font-size);
    z-index: 1060;
}

.form-app .ts-dropdown .dropdown-input,
.prestacion-form-single .ts-dropdown .dropdown-input {
    padding: .25rem .4rem;
    border-bottom: 1px solid var(--border-color);
}

.form-app .ts-dropdown .dropdown-input input,
.prestacion-form-single .ts-dropdown .dropdown-input input {
    font-size: var(--form-font-size);
    padding: .15rem .35rem;
}

.form-app .ts-dropdown .option,
.prestacion-form-single .ts-dropdown .option {
    padding: .25rem .45rem;
}

.form-app .ts-wrapper.is-invalid .ts-control,
.prestacion-form-single .ts-wrapper.is-invalid .ts-control {
    border-color: var(--danger);
}

.cp-lookup-inline {
    display: contents;
}

.modal-medico-derivante .medico-resultados {
    max-height: 280px;
    overflow-y: auto;
}

.modal-paciente-buscar .paciente-resultados {
    max-height: 280px;
    overflow-y: auto;
}

.modal-medico-derivante .nav-tabs-sm .nav-link,
.modal-paciente-buscar .nav-tabs-sm .nav-link {
    font-size: var(--form-font-size);
    padding: .35rem .75rem;
}

/* Modales fuera del wrapper */
.modal {
    z-index: 1060;
}

.modal-backdrop {
    z-index: 1050;
}

.agenda-shell,
.agenda-layout,
.agenda-form-panel,
.agenda-grid-panel {
    position: relative;
    z-index: 1;
}

.page-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.page-hero {
    background: linear-gradient(135deg, #fff 0%, #f9fafb 55%, #eef1f7 100%);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: 0 4px 24px rgba(61, 90, 108, .06);
}

.page-hero-body {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
}

.page-hero-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    min-width: 0;
}

.page-hero-icon {
    width: 3rem;
    height: 3rem;
    border-radius: .875rem;
    background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
    box-shadow: 0 6px 16px rgba(79, 107, 154, .28);
}

.page-hero-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -.02em;
    color: var(--text-primary);
    line-height: 1.2;
}

.page-hero-subtitle {
    margin: .25rem 0 0;
    font-size: .875rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.page-hero-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-top: .5rem;
}

.page-hero-action[type="button"] {
    cursor: pointer;
    font-family: inherit;
}

.page-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
}

.page-hero-action {
    display: inline-flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1rem;
    border-radius: .75rem;
    text-decoration: none;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
    min-width: 0;
}

.page-hero-action:hover {
    transform: translateY(-1px);
    text-decoration: none;
}

.page-hero-action-icon {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: .5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    flex-shrink: 0;
}

.page-hero-action-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.page-hero-action-text strong {
    font-size: .875rem;
    font-weight: 600;
}

.page-hero-action-text small {
    font-size: .72rem;
    opacity: .75;
    margin-top: .1rem;
}

.page-hero-action-secondary {
    background: #fff;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
}

.page-hero-action-secondary:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
    box-shadow: 0 6px 18px rgba(79, 107, 154, .12);
}

.page-hero-action-secondary .page-hero-action-icon {
    background: #eef1f7;
    color: var(--primary-dark);
}

.page-hero-action-primary {
    background: linear-gradient(145deg, var(--primary) 0%, var(--primary-dark) 100%);
    border: 1px solid transparent;
    color: #fff;
    box-shadow: 0 6px 18px rgba(79, 107, 154, .32);
}

.page-hero-action-primary:hover {
    color: #fff;
    box-shadow: 0 10px 24px rgba(79, 107, 154, .38);
}

.page-hero-action-primary .page-hero-action-icon {
    background: rgba(255,255,255,.18);
    color: #fff;
}

@media (max-width: 575.98px) {
    .page-hero {
        padding: 1rem;
    }
    .page-hero-actions {
        width: 100%;
    }
    .page-hero-action {
        flex: 1 1 100%;
    }
}

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .main-content::before,
    .main-content::after {
        left: 0;
    }
}

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    padding: 1.5rem;
}

.login-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--bg-medical-image) center center / 68% no-repeat;
    filter: blur(2px);
    z-index: 0;
}

.login-page::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(61, 90, 108, 0.42);
    z-index: 1;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.93);
    border-radius: 12px;
    padding: 1.75rem;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    position: relative;
    z-index: 2;
}

.login-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.login-brand-name {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--primary-dark);
}

.login-brand-tagline {
    line-height: 1.35;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.signature-pad {
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    background: #fff;
    touch-action: none;
}

.nav-tabs .nav-link { color: var(--text-secondary); }
.nav-tabs .nav-link.active { color: var(--primary); font-weight: 600; }

/* Agenda de turnos */
.agenda-shell {
    background: rgba(255, 255, 255, 0.96);
    overflow: hidden;
}

.agenda-shell > .card-body {
    padding: .85rem 1.1rem 1.1rem;
}

/* Encabezado sobre la grilla: fecha + tipo de estudio */
.agenda-grid-header {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin-bottom: 0;
    min-height: 0;
}

.agenda-fecha-banner {
    padding: .6rem .85rem .55rem;
    background: linear-gradient(135deg, #f0f6fa 0%, #fff 55%);
    border: 1px solid var(--border-color);
    border-radius: .65rem;
    box-shadow: 0 2px 10px rgba(79, 107, 154, .06);
}

.agenda-fecha-banner-form {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0;
}

.agenda-fecha-banner-main {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
}

.agenda-fecha-banner-card {
    flex: 0 0 220px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    padding: .55rem .7rem .6rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: .55rem;
    box-shadow: 0 1px 6px rgba(79, 107, 154, .08);
    text-align: center;
}

.agenda-fecha-banner-kicker {
    margin: 0;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-secondary);
}

.agenda-fecha-banner-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--primary-dark);
}

.agenda-fecha-banner-label {
    margin: 0;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--primary-dark);
    display: inline-flex;
    align-items: center;
    gap: .35rem;
}

.agenda-fecha-banner-card input[type="date"] {
    width: 100%;
    border-radius: .45rem;
    font-weight: 600;
    text-align: center;
}

.agenda-fecha-banner-hoy {
    margin: 0;
    font-size: .72rem;
    color: var(--text-secondary);
    line-height: 1.3;
}

.agenda-profs-slot {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.agenda-profs-slot .turno-profs {
    flex: 1 1 auto;
    min-height: 100%;
}

.turno-profs-sidebar {
    flex: 1 1 auto;
    height: 100%;
    min-height: 0;
    margin-bottom: 0;
}

.agenda-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: .3rem;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    overflow-x: auto;
}

.agenda-tabs .nav-item {
    flex: 1 1 0;
    min-width: max(140px, 0px);
}

.agenda-tabs--banner {
    margin-top: .45rem;
    padding-top: .45rem;
    border-top: 1px solid rgba(220, 228, 235, .85);
}

.agenda-tabs .nav-link {
    white-space: nowrap;
    font-size: .78rem;
    font-weight: 600;
    color: #4a5f73;
    border: 1px solid transparent;
    border-radius: .45rem;
    margin: 0;
    padding: .4rem .55rem;
    text-align: center;
    transition: background .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.agenda-tabs .nav-link:hover {
    color: var(--primary-dark);
    background: rgba(255, 255, 255, .7);
    border-color: rgba(74, 144, 164, .25);
}

.agenda-tabs .nav-link.active {
    color: #fff;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-color: var(--primary-dark);
    box-shadow: 0 2px 8px rgba(61, 117, 134, .28);
}

.turno-profs {
    display: flex;
    flex-direction: column;
    gap: 0;
    font-size: .8125rem;
    padding: 0;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: .65rem;
    overflow: hidden;
    height: 100%;
}

.turno-profs-title {
    flex-shrink: 0;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-secondary);
    margin: 0;
    padding: .5rem .65rem .4rem;
    border-bottom: 1px solid var(--border-color);
    background: #f8fafb;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem;
}

.turno-profs-title .badge {
    text-transform: none;
    letter-spacing: normal;
    font-size: .65rem;
}

.turno-profs-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
}

.turno-profs-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    text-align: left;
    padding: 1rem .85rem;
    border-right: 1px solid var(--border-color);
    min-height: 100%;
    gap: .45rem;
}

.turno-profs-item:last-child {
    border-right: none;
}

.turno-profs-head {
    display: flex;
    align-items: center;
    gap: .4rem;
}

.turno-profs-icon {
    width: 1.25rem;
    font-size: 1.15rem;
    text-align: center;
    opacity: .85;
}

.turno-profs-item-manana .turno-profs-icon { color: #e6a800; }
.turno-profs-item-tarde .turno-profs-icon { color: #1976d2; }
.turno-profs-item-noche .turno-profs-icon { color: #7b1fa2; }

.turno-profs-item-manana {
    border-top: 3px solid #ffb300;
    background: linear-gradient(180deg, rgba(255, 248, 225, .35) 0%, #fff 55%);
}

.turno-profs-item-tarde {
    border-top: 3px solid #1976d2;
    background: linear-gradient(180deg, rgba(227, 242, 253, .35) 0%, #fff 55%);
}

.turno-profs-item-noche {
    border-top: 3px solid #7b1fa2;
    background: linear-gradient(180deg, rgba(243, 229, 245, .35) 0%, #fff 55%);
}

.turno-profs-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-secondary);
}

.turno-profs-name {
    font-size: .95rem;
    font-weight: 600;
    color: var(--primary-dark);
    line-height: 1.3;
    word-break: break-word;
}

.turno-profs-name.is-empty {
    font-weight: 500;
    font-style: italic;
    color: #9aa8b5;
}

@media (max-width: 991.98px) {
    .agenda-fecha-banner-form {
        flex-direction: column;
        align-items: stretch;
    }

    .agenda-fecha-banner-main {
        text-align: center;
    }

    .agenda-fecha-banner-card {
        flex: 1 1 auto;
        width: 100%;
        max-width: 280px;
        align-self: center;
    }

    .agenda-fecha-banner-title {
        font-size: 1rem;
    }

    .agenda-profs-slot {
        flex: 0 0 auto;
    }

    .turno-profs-grid {
        grid-template-columns: 1fr;
    }

    .turno-profs,
    .turno-profs-sidebar {
        min-height: auto;
        height: auto;
    }

    .turno-profs-item {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        min-height: 3.5rem;
        padding: .65rem .75rem;
    }

    .turno-profs-item:last-child {
        border-bottom: none;
    }
}

.agenda-layout {
    display: grid;
    grid-template-columns: minmax(300px, 340px) 1fr;
    gap: .65rem 1.25rem;
    align-items: stretch;
}

.agenda-layout--with-profs {
    grid-template-rows: auto 1fr;
}

.agenda-layout--with-profs .agenda-profs-slot {
    grid-column: 1;
    grid-row: 1;
}

.agenda-layout--with-profs .agenda-grid-header {
    grid-column: 2;
    grid-row: 1;
}

.agenda-layout--with-profs .agenda-form-panel {
    grid-column: 1;
    grid-row: 2;
}

.agenda-layout--with-profs .agenda-layout-grid {
    grid-column: 2;
    grid-row: 2;
}

.agenda-layout:not(.agenda-layout--with-profs) .agenda-grid-header {
    grid-column: 2;
    grid-row: 1;
}

.agenda-layout:not(.agenda-layout--with-profs) .agenda-form-panel {
    grid-column: 1;
    grid-row: 1 / span 2;
}

.agenda-layout:not(.agenda-layout--with-profs) .agenda-layout-grid {
    grid-column: 2;
    grid-row: 2;
}

.agenda-layout:not(.agenda-layout--with-profs) {
    grid-template-rows: auto 1fr;
}

.agenda-form-panel {
    position: sticky;
    top: 4.75rem;
    display: flex;
    flex-direction: column;
    gap: .65rem;
    align-self: start;
}

.agenda-form-panel > .btn {
    flex-shrink: 0;
}

.agenda-turno-card {
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    border-radius: .85rem;
    background: #fff;
    box-shadow: 0 4px 20px rgba(79, 107, 154, .07);
    overflow: hidden;
}

.agenda-turno-card > .form-app {
    display: block;
    margin: 0;
}

.agenda-turno-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .75rem 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
}

.agenda-turno-card-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .9rem;
    font-weight: 700;
    margin: 0;
}

.agenda-turno-card-title i {
    opacity: .85;
    font-size: .85rem;
}

.agenda-turno-header-hora {
    flex-shrink: 0;
}

.agenda-turno-hora-select {
    width: 5.5rem;
    min-width: 5.5rem;
    padding: .28rem 1.6rem .28rem .5rem;
    font-size: .82rem;
    font-weight: 700;
    line-height: 1.25;
    color: #2d3436;
    background-color: rgba(255, 255, 255, .95);
    border: 1px solid rgba(255, 255, 255, .45);
    border-radius: .45rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .12);
}

.agenda-turno-hora-select:focus {
    border-color: #fff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}

.agenda-turno-hora-select.is-invalid {
    border-color: #f5c2c7;
}

.agenda-turno-prof-franja {
    padding-top: .15rem;
}

.agenda-turno-card-body {
    padding: .85rem 1rem 1rem;
}

.agenda-form-hint {
    display: flex;
    align-items: flex-start;
    gap: .45rem;
    padding: .55rem .65rem;
    margin-bottom: .75rem;
    border-radius: .55rem;
    background: #f0f4fa;
    border: 1px solid rgba(79, 107, 154, .12);
    color: var(--text-secondary);
    font-size: .75rem;
    line-height: 1.35;
}

.agenda-form-section {
    margin-bottom: .75rem;
    padding-bottom: .65rem;
    border-bottom: 1px solid #edf1f5;
}

.agenda-form-section:last-of-type {
    border-bottom: none;
    margin-bottom: .35rem;
    padding-bottom: 0;
}

.agenda-form-section-title {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--primary-dark);
    margin-bottom: .5rem;
}

.agenda-form-section-title i {
    font-size: .68rem;
    opacity: .8;
}

.agenda-form-panel .form-label {
    font-size: .74rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: .2rem;
}

.agenda-form-panel .form-control,
.agenda-form-panel .form-select {
    border-radius: .5rem;
    border-color: #d5dee8;
    font-size: var(--form-font-size);
}

.agenda-form-panel .form-control:focus,
.agenda-form-panel .form-select:focus {
    border-color: rgba(79, 107, 154, .55);
    box-shadow: 0 0 0 .15rem rgba(79, 107, 154, .12);
}

.agenda-form-panel .input-group-sm > .btn {
    border-radius: 0 .5rem .5rem 0;
}

.agenda-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    margin-top: .85rem;
    padding-top: .75rem;
    border-top: 1px solid var(--border-color);
}

.agenda-form-actions .btn-form-submit {
    padding: .4rem .85rem;
    font-weight: 600;
    border-radius: .55rem;
}

.agenda-form-panel .btn-outline-primary.w-100 {
    margin-top: .65rem;
    border-radius: .65rem;
    font-weight: 600;
    padding: .45rem .75rem;
}

.agenda-form-panel .card {
    background: #fff;
}

.agenda-form-panel .card-header {
    background: #f8fafb;
    font-size: .9rem;
}

.agenda-layout-grid {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.agenda-grid-panel {
    min-width: 0;
}

.agenda-scroll {
    max-height: calc(100vh - 280px);
    min-height: 420px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
}

.agenda-grid {
    margin-bottom: 0;
    font-size: var(--form-font-size);
}

.agenda-grid thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #eef3f6 !important;
    box-shadow: 0 1px 0 var(--border-color);
    white-space: nowrap;
}

.agenda-grid tbody tr.agenda-row {
    cursor: pointer;
    user-select: none;
}

.agenda-grid tbody tr.vacio td {
    color: #8a96a3;
    background: #fafbfc;
}

.agenda-grid tbody tr.vacio:hover td {
    background: rgba(79, 107, 154, 0.12);
    color: var(--text-primary);
}

.agenda-grid tbody tr.ocupado td {
    background: #fff;
    color: var(--text-primary);
}

/* Alertas de horario — tonos pastel */
.agenda-grid tbody tr.turno-proximo td {
    background: #fff8e6 !important;
    color: #5c4a1a;
}

.agenda-grid tbody tr.turno-atrasado td {
    background: #fde8e8 !important;
    color: #6b3a3a;
}

.agenda-grid tbody tr.turno-atendido td {
    background: #f8f9fa;
    color: #95a1ad;
}

.agenda-grid tbody tr.turno-sin-prestacion td {
    background: #fff3e0 !important;
    color: #6d4c1a;
    box-shadow: inset 3px 0 0 #ff9800;
}

.agenda-alerta-prestacion-wrap {
    position: sticky;
    top: 0;
    z-index: 12;
    flex-shrink: 0;
    margin-bottom: .5rem;
    background: #fff;
    padding-bottom: 1px;
}

.agenda-alerta-prestacion {
    border-color: #ffc107;
    background: #fff8e1;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .07);
}

.agenda-layout-grid:has(.agenda-alerta-prestacion-wrap) .agenda-scroll {
    flex: 1 1 auto;
    min-height: 0;
}

.agenda-grid tbody tr.turno-proximo:hover td {
    background: #fff3d4 !important;
}

.agenda-grid tbody tr.turno-atrasado:hover td {
    background: #fbdada !important;
}

.agenda-grid tbody tr.turno-atendido:hover td {
    background: #eef1f4;
    color: #7d8794;
}

.agenda-grid tbody tr.turno-sin-prestacion:hover td {
    background: #ffe8c2 !important;
    color: #5c3d10;
}

.agenda-grid tbody tr:hover td {
    background: rgba(79, 107, 154, 0.08);
}

.agenda-grid tbody tr.selected td {
    background: rgba(13, 110, 253, 0.18) !important;
    color: #0a3d62;
    font-weight: 500;
}

.agenda-grid tbody tr.selected td:first-child {
    box-shadow: inset 3px 0 0 #0d6efd;
}

.agenda-actions {
    white-space: nowrap;
}

.agenda-actions .btn {
    padding: .15rem .35rem;
    font-size: .75rem;
}

.lookup-row {
    display: grid;
    grid-template-columns: 72px 38px 1fr;
    gap: .35rem;
    align-items: center;
}

@media (max-width: 1199.98px) {
    .agenda-layout,
    .agenda-layout--with-profs {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .agenda-layout--with-profs .agenda-profs-slot,
    .agenda-layout--with-profs .agenda-grid-header,
    .agenda-layout--with-profs .agenda-form-panel,
    .agenda-layout--with-profs .agenda-layout-grid,
    .agenda-layout:not(.agenda-layout--with-profs) .agenda-grid-header,
    .agenda-layout:not(.agenda-layout--with-profs) .agenda-form-panel,
    .agenda-layout:not(.agenda-layout--with-profs) .agenda-layout-grid {
        grid-column: 1;
        grid-row: auto;
    }

    .agenda-form-panel {
        position: static;
    }

    .agenda-scroll {
        max-height: 520px;
    }
}
