:root {
    --bg: #f3f5f7;
    --panel: #ffffff;
    --panel-2: #eef2f5;
    --text: #18202a;
    --muted: #647083;
    --line: #d9e0e7;
    --border: var(--line);
    --surface: var(--panel);
    --surface-muted: var(--panel-2);
    --primary: #2454a6;
    --primary-strong: #163b78;
    --danger: #a83232;
    --warn: #b7791f;
    --ok: #24734d;
}
body.dark {
    --bg: #10151c;
    --panel: #151c25;
    --panel-2: #1c2530;
    --text: #eef3f7;
    --muted: #a9b6c5;
    --line: #2a3645;
    --border: var(--line);
    --surface: var(--panel);
    --surface-muted: var(--panel-2);
    --primary: #6ea0ff;
    --primary-strong: #8ab3ff;
    --danger: #ff8585;
    --warn: #f4c36d;
    --ok: #68d391;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Segoe UI, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
.topbar { height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 0 22px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--primary); color: white; font-weight: 800; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.main-nav { display: flex; align-items: center; gap: 10px; }
.main-nav a { padding: 10px 12px; border: 1px solid transparent; }
.main-nav a:hover { border-color: var(--line); background: var(--panel-2); }
.user-area { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.page-shell { padding: 24px; max-width: 1500px; margin: 0 auto; }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
h1, h2 { margin: 0; }
h1 { font-size: 30px; }
h2 { font-size: 20px; margin-bottom: 14px; }
p { margin: 6px 0 0; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); padding: 18px; margin-bottom: 18px; }
.login-panel { min-height: calc(100vh - 120px); display: grid; place-items: center; }
.login-card { width: min(430px, 100%); }
.form-grid { display: grid; gap: 12px; }
.form-grid.one { grid-template-columns: 1fr; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.filters { grid-template-columns: repeat(7, minmax(120px, 1fr)); align-items: end; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form-grid > label > input:not([type="hidden"]),
.form-grid > label > select,
.form-grid > label > textarea,
.login-form > label > input:not([type="hidden"]),
.login-form > label > select,
.company-selector-card select,
.company-switch select {
    width: 100%;
    padding: 10px 11px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    outline: none;
    font: inherit;
}
.form-grid > label > input:not([type="hidden"]):focus,
.form-grid > label > select:focus,
.form-grid > label > textarea:focus,
.login-form > label > input:not([type="hidden"]):focus,
.login-form > label > select:focus,
.company-selector-card select:focus,
.company-switch select:focus { border-color: var(--primary); }
.form-actions { display: flex; align-items: end; gap: 8px; }
.span-2 { grid-column: span 2; }
.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); padding: 9px 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; min-height: 38px; }
.btn:hover { filter: brightness(0.96); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-light { background: var(--panel-2); }
.btn-small { padding: 6px 8px; min-height: 30px; font-size: 12px; }
.alert { padding: 12px 14px; border: 1px solid var(--line); background: var(--panel); margin-bottom: 18px; }
.alert-info { border-left: 4px solid var(--primary); }
.alert-error { border-left: 4px solid var(--danger); }
.alert-success { border-left: 4px solid #1b8f4b; }
.alert-warn { border-left: 4px solid var(--warn); }
.table-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.table-wrap { overflow: auto; max-width: 100%; }
.table-wrap.slim { max-height: 480px; }
.table-wrap > table { width: 100%; border-collapse: collapse; min-width: 960px; }
.table-wrap > table th,
.table-wrap > table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table-wrap > table th { background: var(--panel-2); font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.table-wrap > table tr:hover td { background: color-mix(in srgb, var(--panel-2) 55%, transparent); }
.muted { color: var(--muted); font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions form, .inline-form { display: inline-flex; margin: 0; }
.status { display: inline-flex; padding: 5px 7px; border: 1px solid var(--line); font-size: 12px; font-weight: 700; }
.status.s0 { color: var(--primary); }
.status.s1, .status.s5 { color: var(--warn); }
.status.s2, .status.s6 { color: var(--danger); }
.status.s3 { color: var(--ok); }
.grid.two-cols { display: grid; grid-template-columns: minmax(280px, 420px) 1fr; gap: 18px; }
.list { display: grid; gap: 8px; margin-top: 12px; }
.list-item { display: flex; flex-direction: column; gap: 4px; padding: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.list-item:hover { border-color: var(--primary); }
.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 10px; }
.stats-grid div { border: 1px solid var(--line); background: var(--panel-2); padding: 12px; }
.stats-grid span { display: block; color: var(--muted); font-size: 12px; }
.stats-grid strong { display: block; margin-top: 6px; font-size: 20px; }
@media (max-width: 980px) {
    .topbar { height: auto; flex-wrap: wrap; padding: 12px; }
    .main-nav { order: 3; width: 100%; overflow: auto; }
    .page-shell { padding: 14px; }
    .page-title, .grid.two-cols { display: block; }
    .form-grid.filters, .form-grid.two { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
    .stats-grid { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
}
.brand-logo { width: 42px; max-height: 42px; object-fit: contain; display: block; }
.brand-fallback { width: 38px; height: 38px; display: grid; place-items: center; background: var(--primary); color: white; font-weight: 800; }
.topbar-public { justify-content: center; border-bottom: none; background: transparent; }
.topbar-public .brand { min-width: unset; justify-content: center; }
.page-shell-public { max-width: none; padding-top: 0; }
.clean-login { min-height: calc(100vh - 88px); }
.login-brand { display: flex; justify-content: center; align-items: center; margin-bottom: 16px; }
.login-brand img { max-width: 190px; max-height: 84px; object-fit: contain; }
.login-brand .brand-fallback { width: 68px; height: 68px; font-size: 28px; }
.login-card { text-align: left; padding: 28px; }
.login-card h1 { text-align: center; margin-bottom: 6px; }
.login-card > .muted { text-align: center; margin-bottom: 20px; }
.login-form { margin-top: 16px; }
.btn-block { width: 100%; }
.company-switch select { min-width: 110px; padding: 8px 10px; background: var(--panel-2); }
.user-name { color: var(--text); font-weight: 600; }

.company-select-panel {
    min-height: calc(100vh - 96px);
    display: grid;
    place-items: center;
    padding: 32px 16px;
}

.company-select-card {
    width: min(760px, 100%);
}

.company-grid-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-top: 22px;
}

.company-card-form {
    margin: 0;
}

.company-card-button {
    width: 100%;
    min-height: 108px;
    text-align: left;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    padding: 18px;
    cursor: pointer;
    display: grid;
    gap: 8px;
    transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.company-card-button:hover,
.company-card-button:focus {
    transform: translateY(-1px);
    border-color: var(--primary);
    box-shadow: 0 10px 28px rgba(15, 23, 42, .12);
    outline: none;
}

.company-card-button strong {
    font-size: 1rem;
}

.company-card-button span {
    color: var(--muted);
    font-size: .92rem;
}

.company-card-button em {
    justify-self: start;
    font-style: normal;
    font-size: .78rem;
    padding: 4px 8px;
    border: 1px solid var(--line);
    color: var(--muted);
}

.login-footer-actions {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
}

/* v09: bloqueo visual durante operaciones */
body.is-loading {
    overflow: hidden;
}
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(8, 13, 22, .42);
    backdrop-filter: blur(2px);
}
.loading-overlay.show {
    display: flex;
}
.loading-box {
    min-width: 210px;
    display: grid;
    justify-items: center;
    gap: 12px;
    padding: 24px 28px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 18px 50px rgba(0, 0, 0, .20);
}
.loading-spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--line);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: fomplus-spin .8s linear infinite;
}
@keyframes fomplus-spin {
    to { transform: rotate(360deg); }
}
.login-card select {
    min-height: 42px;
}
.login-card .btn[disabled] {
    opacity: .7;
    cursor: wait;
}

/* v10: flujo simplificado para crear citas */
.agenda-wizard-card { display: grid; gap: 18px; }
.wizard-steps { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 10px; }
.wizard-step { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); }
.wizard-step span { width: 26px; height: 26px; display: grid; place-items: center; border: 1px solid var(--line); background: var(--panel); font-weight: 700; }
.wizard-step strong { font-size: 13px; }
.wizard-step.active { border-color: var(--primary); color: var(--text); }
.wizard-step.active span { border-color: var(--primary); color: var(--primary); }
.wizard-step.done { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); color: var(--text); }
.wizard-step.done span { border-color: var(--ok); color: var(--ok); }
.appointment-filter { grid-template-columns: minmax(220px, 1.4fr) minmax(220px, 1.4fr) minmax(150px, .8fr) auto; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-heading.compact { margin-bottom: 12px; }
.calendar-strip { display: grid; grid-template-columns: repeat(7, minmax(115px, 1fr)); gap: 10px; }
.calendar-day { min-height: 104px; padding: 14px; border: 1px solid var(--line); background: var(--panel-2); display: grid; align-content: start; gap: 7px; }
.calendar-day strong { font-size: 14px; }
.calendar-day span { color: var(--muted); font-size: 13px; }
.calendar-day em { justify-self: start; font-style: normal; font-size: 12px; padding: 4px 8px; border: 1px solid var(--line); color: var(--text); background: var(--panel); }
.calendar-day:not(.disabled):hover { border-color: var(--primary); transform: translateY(-1px); }
.calendar-day.selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.calendar-day.disabled { opacity: .55; }
.appointment-flow-grid { grid-template-columns: minmax(280px, 460px) 1fr; }
.slot-list { display: grid; gap: 10px; }
.slot-card { display: grid; gap: 5px; padding: 12px; border: 1px solid var(--line); background: var(--panel-2); }
.slot-card:hover { border-color: var(--primary); }
.slot-card.selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.slot-card strong { font-size: 16px; }
.slot-card span { color: var(--muted); font-size: 13px; }
.slot-card em { justify-self: start; font-style: normal; color: var(--ok); font-size: 12px; }
.selected-slot-summary { display: grid; gap: 4px; padding: 12px; border: 1px solid var(--primary); background: color-mix(in srgb, var(--primary) 9%, var(--panel)); margin-bottom: 14px; }
.selected-slot-summary span, .confirm-panel span { color: var(--muted); font-size: 12px; }
.selected-slot-summary strong { font-size: 18px; }
.selected-slot-summary em, .confirm-panel em { color: var(--muted); font-style: normal; }
.selected-slot-summary small { color: var(--muted); }
.patient-search-form { margin-bottom: 12px; }
.patient-result-list .list-item.selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.confirm-appointment-form { display: grid; gap: 12px; margin-top: 14px; }
.confirm-panel { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--line); background: var(--panel-2); }
.confirm-panel > div { display: grid; gap: 4px; }
.empty-state { text-align: center; padding: 34px; }
@media (max-width: 1100px) {
    .calendar-strip { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
    .appointment-filter { grid-template-columns: 1fr; }
    .wizard-steps { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
}
@media (max-width: 640px) {
    .calendar-strip, .wizard-steps { grid-template-columns: 1fr; }
}

/* v11: flujo de cita con fecha tipo calendario, combo dependiente y cambio rápido de profesional */
.appointment-filter-v11 {
    grid-template-columns: minmax(220px, 1.4fr) minmax(220px, 1.4fr) minmax(160px, .8fr) auto;
}
.stacked-actions {
    align-self: end;
}
.availability-day-card {
    display: grid;
    gap: 12px;
}
.availability-heading-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}
.professional-summary-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 10px;
}
.professional-summary-card {
    display: grid;
    gap: 4px;
    padding: 12px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
}
.professional-summary-card:hover,
.professional-summary-card.selected {
    border-color: var(--primary);
}
.professional-summary-card strong {
    font-size: 14px;
}
.professional-summary-card span {
    font-size: 12px;
    color: var(--muted);
}
.modal-open {
    overflow: hidden;
}
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background: rgba(8, 13, 22, .48);
    backdrop-filter: blur(2px);
}
.modal-backdrop[hidden] {
    display: none;
}
.modal-card {
    width: min(760px, 100%);
    max-height: min(680px, calc(100vh - 44px));
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: 0 22px 70px rgba(0, 0, 0, .26);
}
.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}
.modal-header h2 {
    margin: 0 0 4px;
}
.modal-header p {
    margin: 0;
    color: var(--muted);
}
.modal-close {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
}
.professional-modal-list {
    overflow: auto;
    display: grid;
    gap: 10px;
    padding: 16px;
}
.professional-modal-item {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
}
.professional-modal-item:hover,
.professional-modal-item.selected {
    border-color: var(--primary);
}
.professional-modal-item div {
    display: grid;
    gap: 3px;
}
.professional-modal-item span,
.professional-modal-item small {
    color: var(--muted);
}
.professional-modal-item em {
    font-style: normal;
    font-weight: 700;
    color: var(--ok);
}
.professional-modal-item b {
    font-size: 12px;
    padding: 5px 8px;
    border: 1px solid var(--line);
    background: var(--panel);
}
@media (max-width: 1100px) {
    .appointment-filter-v11 { grid-template-columns: 1fr; }
    .availability-heading { display: grid; }
    .availability-heading-actions { justify-content: flex-start; }
}
@media (max-width: 720px) {
    .professional-modal-item { grid-template-columns: 1fr; align-items: start; }
    .modal-backdrop { padding: 12px; }
}

/* v12: confirmaciones, mensajes emergentes y fechas dd/MM/yyyy */
.field-hint {
    margin-top: 5px;
    display: block;
    font-size: 12px;
    color: var(--muted);
}
.message-modal-card {
    width: min(520px, 100%);
    grid-template-rows: auto auto;
}
.message-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 18px;
    border-top: 1px solid var(--line);
    background: var(--panel-2);
}
input[type="date"],
input[type="datetime-local"] {
    min-height: 42px;
}

/* v13: flujo tipo calendario mensual para creación de cita */
.agenda-month-wizard .appointment-filter-v13 {
    grid-template-columns: minmax(240px, 1.1fr) minmax(240px, 1.1fr) auto;
}
.month-calendar-card {
    padding: 0;
    overflow: hidden;
}
.month-calendar-header {
    display: grid;
    grid-template-columns: 54px 1fr 54px;
    align-items: center;
    min-height: 92px;
    border-bottom: 2px solid var(--primary);
    text-align: center;
    background: var(--panel);
}
.month-calendar-header h2 {
    margin: 4px 0 0;
    color: var(--primary-strong);
    font-size: 22px;
    letter-spacing: .04em;
}
.month-calendar-header p {
    margin-top: 4px;
    font-size: 13px;
}
.month-calendar-icon {
    color: var(--primary);
    display: inline-flex;
    font-size: 22px;
    line-height: 1;
}
.month-nav {
    height: 92px;
    display: grid;
    place-items: center;
    font-size: 42px;
    color: var(--primary);
    border-right: 1px solid var(--line);
}
.month-nav:last-child {
    border-right: 0;
    border-left: 1px solid var(--line);
}
.month-nav:hover {
    background: var(--panel-2);
}
.month-calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}
.month-calendar-days div {
    min-height: 34px;
    display: grid;
    place-items: center;
    color: var(--primary-strong);
    font-weight: 800;
    font-size: 12px;
    border-bottom: 2px solid var(--primary);
    letter-spacing: .05em;
}
.month-calendar-body {
    background: var(--line);
    gap: 1px;
}
.month-day {
    min-height: 108px;
    background: var(--panel);
    padding: 8px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    color: var(--text);
    border: 0;
}
.month-day.outside {
    color: color-mix(in srgb, var(--muted) 45%, transparent);
    background: repeating-linear-gradient(135deg, var(--panel-2), var(--panel-2) 6px, color-mix(in srgb, var(--panel) 70%, transparent) 6px, color-mix(in srgb, var(--panel) 70%, transparent) 12px);
}
.month-day.weekend:not(.outside) {
    background: color-mix(in srgb, var(--panel-2) 72%, var(--panel));
}
.month-day.has-slots {
    cursor: pointer;
}
.month-day.has-slots:hover {
    outline: 2px solid var(--primary);
    outline-offset: -2px;
}
.month-day.selected {
    background: var(--primary);
    color: #fff;
}
.month-day.today:not(.selected) .day-number {
    color: var(--primary-strong);
    font-weight: 800;
}
.month-day.past {
    opacity: .45;
    cursor: not-allowed;
    background: var(--panel-2);
}
.month-day.past .day-number::after {
    content: " · pasado";
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
}
.day-number {
    font-size: 15px;
    color: inherit;
}
.day-badge {
    align-self: flex-end;
    min-width: 42px;
    min-height: 26px;
    padding: 3px 9px;
    border-radius: 999px;
    background: #22bfe8;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-weight: 800;
    font-size: 13px;
}
.month-day.selected .day-badge {
    background: #fff;
    color: var(--primary-strong);
}
.month-day small {
    margin-top: auto;
    color: var(--muted);
    font-size: 11px;
}
.month-day.selected small {
    color: rgba(255,255,255,.85);
}
.month-appointment-flow {
    grid-template-columns: minmax(360px, 1.1fr) minmax(320px, .9fr);
}
.slot-panel-heading {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 14px;
}
.compact-strip {
    margin: 0 0 14px;
}
.slot-grid-panel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: 8px;
}
.slot-time-button {
    min-height: 88px;
    padding: 10px;
    border: 1px solid var(--line);
    background: #82ca34;
    color: #fff;
    display: grid;
    align-content: center;
    gap: 2px;
    text-align: center;
}
.slot-time-button:hover,
.slot-time-button.selected {
    background: var(--primary);
    border-color: var(--primary);
}
.slot-time-button strong {
    font-size: 18px;
}
.slot-time-button span {
    font-size: 12px;
    opacity: .9;
}
.slot-time-button em {
    font-size: 11px;
    opacity: .95;
    font-style: normal;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.25;
    overflow-wrap: anywhere;
}
.patient-confirm-card.disabled {
    opacity: .86;
}
.patient-confirm-card.enabled {
    border-color: color-mix(in srgb, var(--primary) 40%, var(--line));
}
@media (max-width: 1100px) {
    .agenda-month-wizard .appointment-filter-v13,
    .month-appointment-flow {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 720px) {
    .month-calendar-header {
        grid-template-columns: 44px 1fr 44px;
        min-height: 78px;
    }
    .month-nav {
        height: 78px;
        font-size: 34px;
    }
    .month-day {
        min-height: 82px;
        padding: 6px;
    }
    .month-calendar-header h2 {
        font-size: 17px;
    }
    .day-badge {
        min-width: 34px;
        font-size: 11px;
        padding: 3px 7px;
    }
    .slot-grid-panel {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* v14: flujo de cita en modal, sin recargar la página al escoger día/horario/paciente */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
button.month-day {
    font-family: inherit;
    text-align: left;
}
.appointment-flow-modal {
    z-index: 9200;
}
.appointment-modal-card {
    width: min(920px, 100%);
    max-height: min(760px, calc(100vh - 28px));
}
.appointment-modal-header {
    grid-template-columns: auto 1fr auto;
    display: grid;
    align-items: start;
}
.modal-back {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--primary-strong);
    font-size: 22px;
    cursor: pointer;
}
.appointment-modal-body {
    position: relative;
    overflow: auto;
    padding: 18px;
    min-height: 440px;
}
.appointment-slide {
    display: none;
    animation: appointmentSlideIn .18s ease-out;
}
.appointment-slide.active {
    display: grid;
    gap: 16px;
}
@keyframes appointmentSlideIn {
    from { transform: translateX(22px); opacity: .4; }
    to { transform: translateX(0); opacity: 1; }
}
.appointment-slide-heading {
    display: flex;
    justify-content: space-between;
    gap: 14px;
}
.appointment-slide-heading span {
    color: var(--primary-strong);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.appointment-slide-heading h3 {
    margin: 4px 0;
    font-size: 22px;
}
.appointment-slide-heading p {
    margin: 0;
    color: var(--muted);
}
.professional-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
}
.professional-tab {
    min-width: 220px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    display: grid;
    gap: 3px;
}
.professional-tab:hover,
.professional-tab.selected {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary);
}
.professional-tab strong {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.2;
    overflow-wrap: anywhere;
}
.professional-tab span {
    color: var(--muted);
    font-size: 12px;
}
.appointment-modal-slots {
    max-height: 430px;
    overflow: auto;
    padding-right: 4px;
}
.patient-modal-search {
    grid-template-columns: minmax(260px, 1fr) auto;
    align-items: end;
}
.modal-patient-results {
    max-height: 320px;
    overflow: auto;
}
.patient-modal-item {
    width: 100%;
    text-align: left;
    cursor: pointer;
}
.modal-confirm-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.modal-confirm-panel div {
    padding: 12px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    display: grid;
    gap: 4px;
}
.modal-confirm-panel span {
    color: var(--muted);
    font-size: 12px;
}
.modal-confirm-panel strong {
    font-size: 16px;
}
.modal-confirm-panel em {
    color: var(--muted);
    font-style: normal;
}
.modal-confirm-form {
    display: grid;
    gap: 14px;
}
.modal-inline-loading {
    position: absolute;
    inset: 0;
    z-index: 4;
    background: color-mix(in srgb, var(--panel) 88%, transparent);
    display: grid;
    place-content: center;
    gap: 10px;
    text-align: center;
}
.modal-inline-loading[hidden] {
    display: none;
}
.spinner-dot {
    width: 34px;
    height: 34px;
    border: 4px solid color-mix(in srgb, var(--primary) 25%, transparent);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    justify-self: center;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.modal-alert {
    padding: 12px 14px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    margin-bottom: 14px;
}
.modal-alert.warn {
    border-color: color-mix(in srgb, var(--warn) 60%, var(--line));
    background: color-mix(in srgb, var(--warn) 12%, var(--panel));
}
.modal-alert.error {
    border-color: color-mix(in srgb, var(--danger) 60%, var(--line));
    background: color-mix(in srgb, var(--danger) 10%, var(--panel));
}
.modal-alert.ok {
    border-color: color-mix(in srgb, var(--ok) 60%, var(--line));
    background: color-mix(in srgb, var(--ok) 12%, var(--panel));
}
.modal-alert[hidden] {
    display: none;
}
.modal-empty-state {
    padding: 18px;
    border: 1px dashed var(--line);
    color: var(--muted);
    background: var(--panel-2);
    text-align: center;
}
@media (max-width: 720px) {
    .appointment-modal-body {
        padding: 14px;
    }
    .patient-modal-search,
    .modal-confirm-panel {
        grid-template-columns: 1fr;
    }
    .professional-tab {
        min-width: 190px;
    }
}

/* v15: resumen fijo de cita para reprogramación */
.appointment-current-summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 16px;
}
.appointment-current-summary > div {
    border: 1px solid var(--line);
    background: var(--panel-2);
    padding: 12px;
    display: grid;
    gap: 4px;
    min-height: 74px;
}
.appointment-current-summary span,
.appointment-current-summary em {
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
}
.appointment-current-summary strong {
    color: var(--text);
    font-size: 15px;
}
.reprogram-card {
    margin-bottom: 14px;
}
@media (max-width: 1100px) {
    .appointment-current-summary { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
}
@media (max-width: 680px) {
    .appointment-current-summary { grid-template-columns: 1fr; }
}

/* DevExtreme integration: solo clases propias de la aplicación.
   No se aplican reglas sobre clases internas de DevExtreme; el modo claro/oscuro se maneja con los temas oficiales DevExtreme. */
.table-card-devextreme {
    padding: 14px;
}

.agenda-grid-devextreme {
    min-height: 420px;
}

.agenda-grid-title {
    font-weight: 800;
    color: var(--text);
    padding-left: 4px;
}

@media (max-width: 760px) {
    .table-card-devextreme {
        padding: 8px;
    }

    .agenda-grid-devextreme {
        min-height: 520px;
    }
}

/* v18: confirmación propia por encima de modales de agenda */
.fomplus-confirm-backdrop {
    position: fixed;
    inset: 0;
    z-index: 13000;
    background: rgba(15, 23, 42, .48);
    display: grid;
    place-items: center;
    padding: 18px;
}
.fomplus-confirm-backdrop[hidden] {
    display: none;
}
.fomplus-confirm-card {
    width: min(440px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: 0 22px 70px rgba(15, 23, 42, .28);
}
.fomplus-confirm-header {
    padding: 18px 18px 8px;
}
.fomplus-confirm-header h2 {
    margin: 0;
    font-size: 20px;
    color: var(--text);
}
.fomplus-confirm-body {
    padding: 0 18px 18px;
    color: var(--muted);
    line-height: 1.45;
}
.fomplus-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid var(--line);
    background: var(--panel-2);
}


/* v20: bloqueo de modal al grabar y ajuste de grilla sin scroll horizontal */
.appointment-flow-modal.is-busy .modal-card {
    pointer-events: none;
}
.appointment-flow-modal.is-busy .modal-inline-loading {
    pointer-events: all;
}
.table-card-devextreme {
    overflow: hidden;
}
.agenda-grid-devextreme {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.fomplus-datebox {
    width: 100%;
}


/* v23: disponibilidad dentro del modal */
.modal-date-row {
    display: grid;
    grid-template-columns: minmax(220px, 320px);
    align-items: end;
    margin-bottom: 12px;
}
.modal-date-row label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
}
.modal-datebox-host,
.modal-date-native {
    min-height: 42px;
}
.modal-date-native {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    padding: 9px 10px;
}
@media (max-width: 720px) {
    .modal-date-row {
        grid-template-columns: 1fr;
    }
    .slot-grid-panel {
        grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    }
}

/* v24: Paso 1 más compacto dentro del modal de disponibilidad/reprogramación */
.appointment-slide-heading-compact {
    align-items: end;
    gap: 12px;
    margin-bottom: 2px;
}
.appointment-step-title {
    min-width: 0;
}
.appointment-slide-heading-compact h3 {
    margin: 2px 0 2px;
    font-size: 20px;
    line-height: 1.15;
}
.appointment-slide-heading-compact p {
    font-size: 13px;
    line-height: 1.25;
}
.modal-date-row-header {
    grid-template-columns: minmax(150px, 190px);
    margin: 0;
    justify-self: end;
}
.modal-date-row-header label {
    gap: 4px;
    font-size: 12px;
}
.modal-date-row-header .modal-datebox-host,
.modal-date-row-header .modal-date-native {
    min-height: 36px;
}
.appointment-slide[data-slide="slots"].active {
    gap: 10px;
}
.appointment-slide[data-slide="slots"] .professional-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 6px;
    overflow: visible;
    padding-bottom: 0;
}
.appointment-slide[data-slide="slots"] .professional-tab {
    min-width: 0;
    max-width: none;
    padding: 7px 9px;
    gap: 2px;
}
.appointment-slide[data-slide="slots"] .professional-tab strong {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 34px;
    line-height: 1.15;
    overflow-wrap: anywhere;
}
.appointment-slide[data-slide="slots"] .professional-tab span {
    font-size: 11px;
    line-height: 1.2;
}
.appointment-modal-slots {
    max-height: 390px;
}
.appointment-modal-slots .slot-time-button {
    min-height: 78px;
    padding: 9px 10px;
}
.appointment-modal-slots .slot-time-button strong {
    font-size: 15px;
}
.appointment-modal-slots .slot-time-button span {
    font-size: 12px;
}
.appointment-modal-slots .slot-time-button em {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.15;
    overflow-wrap: anywhere;
}
@media (max-width: 720px) {
    .appointment-slide-heading-compact {
        align-items: stretch;
        display: grid;
        grid-template-columns: 1fr;
    }
    .modal-date-row-header {
        grid-template-columns: 1fr;
        justify-self: stretch;
    }
    .appointment-slide[data-slide="slots"] .professional-tabs {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}


/* Menú compacto de acciones en la grilla de agenda */
.agenda-action-menu-wrap {
    width: 124px;
    max-width: 124px;
    margin: 0 auto;
}

.agenda-action-menu {
    width: 124px;
    min-width: 124px;
    max-width: 124px;
    height: 34px;
    padding: 0 28px 0 10px;
    border: 1px solid var(--border);
    border-radius: 0;
    background: var(--card);
    color: var(--text);
    font-size: .88rem;
    line-height: 34px;
}

.agenda-action-menu:disabled {
    opacity: .65;
    cursor: wait;
}

/* v27: combos con búsqueda y menú de acciones con iconos, sin widgets dentro de celdas */
.native-searchable-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.fomplus-search-select {
    width: 100%;
    min-width: 0;
}

.form-grid > label > .fomplus-search-select {
    width: 100%;
}

.agenda-action-menu-wrap,
.agenda-action-menu-wrap-icons {
    width: 136px;
    min-width: 136px;
    max-width: 136px;
    margin: 0 auto;
}

.agenda-action-trigger {
    width: 136px;
    min-width: 136px;
    max-width: 136px;
    height: 34px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: pointer;
    font: inherit;
    font-size: .86rem;
    padding: 0 10px;
}

.agenda-action-trigger:hover,
.agenda-action-trigger[aria-expanded="true"] {
    border-color: var(--primary);
    background: var(--panel-2);
}

.agenda-action-trigger:disabled {
    opacity: .65;
    cursor: wait;
}

.agenda-action-trigger-icon {
    font-size: 18px;
    line-height: 1;
    color: var(--primary);
    margin-top: -1px;
}

.agenda-action-popover {
    position: fixed;
    z-index: 12000;
    min-width: 198px;
    max-width: min(260px, calc(100vw - 24px));
    padding: 6px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    box-shadow: 0 12px 32px rgba(0,0,0,.20);
}

.agenda-action-popover-item {
    width: 100%;
    min-height: 34px;
    border: 0;
    background: transparent;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 9px;
    text-align: left;
    padding: 7px 9px;
    cursor: pointer;
    font: inherit;
    font-size: .9rem;
}

.agenda-action-popover-item:hover,
.agenda-action-popover-item:focus {
    outline: none;
    background: var(--panel-2);
}

.agenda-action-icon {
    width: 22px;
    min-width: 22px;
    height: 22px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    color: var(--primary);
    font-weight: 700;
    line-height: 1;
}

/* Terapias: programación en bloque */
.therapy-batch-shell {
    display: grid;
    gap: 14px;
}

.therapy-batch-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.therapy-batch-header h2 {
    margin: 0 0 8px;
    font-size: 1.24rem;
}

.therapy-batch-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    color: var(--muted);
    font-size: .92rem;
}

.therapy-batch-kpis {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.therapy-batch-kpis > div {
    min-width: 104px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    padding: 8px 10px;
}

.therapy-batch-kpis span {
    display: block;
    color: var(--muted);
    font-size: .78rem;
}

.therapy-batch-kpis strong {
    display: block;
    font-size: 1.1rem;
    margin-top: 2px;
}

.therapy-batch-toolbar {
    display: grid;
    grid-template-columns: minmax(150px, 190px) minmax(180px, 260px) auto;
    align-items: end;
    gap: 10px;
}

.therapy-batch-toolbar label {
    display: grid;
    gap: 5px;
    font-size: .85rem;
    color: var(--muted);
}

.therapy-batch-toolbar input {
    min-height: 36px;
}

.therapy-batch-progress {
    border: 1px solid var(--line);
    background: var(--panel-2);
    padding: 10px;
}

.therapy-batch-progress-top {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
    font-size: .93rem;
}

.therapy-batch-progress-top span {
    color: var(--muted);
}

.therapy-progress-track {
    height: 10px;
    border: 1px solid var(--line);
    background: var(--panel);
    overflow: hidden;
}

.therapy-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    transition: width .18s ease;
}

.therapy-progress-fill.is-complete {
    background: #1b8f4b;
}

.therapy-progress-fill.is-over-limit {
    background: #c0392b;
}

.therapy-batch-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 14px;
    align-items: start;
}

.therapy-matrix-panel,
.therapy-summary-panel {
    min-width: 0;
}

.therapy-matrix-scroll {
    width: 100%;
    max-height: min(68vh, 720px);
    overflow: auto;
    border: 1px solid var(--line);
    background: var(--panel);
}

.therapy-matrix {
    border-collapse: separate;
    border-spacing: 0;
    width: max-content;
    min-width: 100%;
    font-size: .82rem;
}

.therapy-matrix th,
.therapy-matrix td {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    padding: 4px;
    vertical-align: top;
    min-width: 72px;
    max-width: 92px;
}

.therapy-matrix thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: var(--panel-2);
    text-align: center;
    font-weight: 700;
}

.therapy-hour-col {
    position: sticky;
    left: 0;
    z-index: 4;
    min-width: 72px !important;
    max-width: 72px !important;
    background: var(--panel-2);
    color: var(--text);
    text-align: left;
}

.therapy-matrix tbody .therapy-hour-col {
    font-weight: 700;
}

.therapy-day-number,
.therapy-day-name {
    display: block;
    line-height: 1.15;
}

.therapy-day-name {
    color: var(--muted);
    font-size: .72rem;
    text-transform: capitalize;
}

.therapy-matrix th.is-past {
    opacity: .45;
}

.therapy-cell-empty {
    background: rgba(127,127,127,.05);
}

.therapy-cell-available {
    background: rgba(44, 116, 179, .06);
}

.therapy-slot {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    cursor: pointer;
    display: grid;
    gap: 1px;
    align-content: center;
    text-align: left;
    padding: 5px 6px;
    margin: 0 0 4px;
    font: inherit;
}

.therapy-slot:last-child {
    margin-bottom: 0;
}

.therapy-slot:hover,
.therapy-slot:focus {
    border-color: var(--primary);
    outline: none;
}

.therapy-slot.is-selected {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.therapy-slot.is-over-limit {
    border-color: #c0392b;
    background: #c0392b;
    color: #fff;
}

.therapy-slot-time {
    font-weight: 700;
    line-height: 1.05;
}

.therapy-slot-doctor {
    font-size: .73rem;
    line-height: 1.1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.therapy-summary-panel {
    border: 1px solid var(--line);
    background: var(--panel-2);
    position: sticky;
    top: 84px;
    padding: 12px;
}

.therapy-summary-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.therapy-summary-header span {
    min-width: 34px;
    height: 28px;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    background: var(--panel);
    font-weight: 700;
}

.therapy-summary-list {
    max-height: 430px;
    overflow: auto;
    display: grid;
    gap: 6px;
    padding-right: 2px;
}

.therapy-summary-item {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    display: grid;
    grid-template-columns: 24px 1fr;
    gap: 8px;
    text-align: left;
    padding: 7px 8px;
    cursor: pointer;
    font: inherit;
}

.therapy-summary-item:hover,
.therapy-summary-item:focus {
    border-color: var(--primary);
    outline: none;
}

.therapy-summary-item.is-over-limit {
    border-color: #c0392b;
}

.therapy-summary-check {
    width: 22px;
    height: 22px;
    border: 1px solid var(--line);
    display: inline-grid;
    place-items: center;
    color: var(--primary);
    font-weight: 700;
}

.therapy-summary-item.is-over-limit .therapy-summary-check {
    color: #c0392b;
}

.therapy-summary-item strong,
.therapy-summary-item small {
    display: block;
}

.therapy-summary-item small {
    color: var(--muted);
    font-size: .76rem;
    line-height: 1.25;
    margin-top: 2px;
}

.therapy-summary-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.therapy-summary-actions .btn {
    min-width: 112px;
}

.therapy-batch-shell.is-saving {
    pointer-events: none;
    opacity: .76;
}

@media (max-width: 980px) {
    .therapy-batch-layout {
        grid-template-columns: 1fr;
    }

    .therapy-summary-panel {
        position: static;
    }

    .therapy-batch-toolbar {
        grid-template-columns: 1fr;
    }
}

/* Terapias: selección de especialidad/profesionales antes de matriz */
.therapy-batch-toolbar-selection {
    grid-template-columns: minmax(150px, 190px) minmax(240px, 1fr) auto;
}

.therapy-filter-actions {
    align-self: end;
}

.therapy-professional-selector {
    grid-column: 1 / -1;
    border: 1px solid var(--line);
    background: var(--panel-2);
    padding: 10px;
    display: grid;
    gap: 10px;
}

.therapy-professional-selector-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.therapy-professional-selector-head strong,
.therapy-professional-selector-head small {
    display: block;
}

.therapy-professional-selector-head small {
    color: var(--muted);
    margin-top: 2px;
}

.therapy-professional-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-sm {
    min-height: 30px;
    padding: 5px 9px;
    font-size: .82rem;
}

.therapy-professional-search-row input {
    width: 100%;
    min-height: 34px;
}

.therapy-professional-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
    max-height: 230px;
    overflow: auto;
    padding-right: 2px;
}

.therapy-professional-option {
    border: 1px solid var(--line);
    background: var(--panel);
    padding: 8px;
    display: grid;
    grid-template-columns: 20px 1fr;
    gap: 8px;
    align-items: start;
    cursor: pointer;
    color: var(--text);
}

.therapy-professional-option:hover,
.therapy-professional-option:focus-within {
    border-color: var(--primary);
}

.therapy-professional-option input {
    margin-top: 2px;
}

.therapy-professional-option strong,
.therapy-professional-option small {
    display: block;
}

.therapy-professional-option strong {
    line-height: 1.18;
}

.therapy-professional-option small {
    color: var(--muted);
    font-size: .76rem;
    margin-top: 2px;
}

.empty-state.compact {
    padding: 10px;
    min-height: auto;
}

@media (max-width: 980px) {
    .therapy-batch-toolbar-selection {
        grid-template-columns: 1fr;
    }
}

/* Terapias: búsqueda de paciente */
.therapy-patient-search-card {
    position: relative;
}

.therapy-patient-actions {
    align-items: end;
}

.therapy-patient-results {
    margin-top: 10px;
    border: 1px solid var(--line);
    background: var(--panel);
    max-height: 260px;
    overflow: auto;
}

.therapy-patient-result {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
    display: grid;
    gap: 3px;
}

.therapy-patient-result:last-child {
    border-bottom: 0;
}

.therapy-patient-result:hover,
.therapy-patient-result:focus {
    outline: none;
    background: var(--soft);
}

.therapy-patient-result span,
.therapy-patient-empty {
    color: var(--muted);
    font-size: .88rem;
}

.therapy-patient-empty {
    padding: 12px;
}

.fomplus-search-select {
    min-width: 0;
}

/* v32 - Terapias multi-servicio y matriz mensual de nueva cita */
.therapy-orders-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.therapy-orders-hint {
    margin: .75rem 0 0;
}

tr.is-selection-conflict {
    outline: 2px solid rgba(220, 38, 38, .35);
    outline-offset: -2px;
}

.therapy-service-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .65rem;
    margin: .85rem 0 1rem;
}

.therapy-service-chip {
    display: flex;
    align-items: center;
    gap: .6rem;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--text);
    border-radius: 14px;
    padding: .65rem .75rem;
    text-align: left;
    cursor: pointer;
}

.therapy-service-chip.is-active {
    border-color: var(--service-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--service-color) 18%, transparent);
    background: color-mix(in srgb, var(--service-color) 8%, var(--surface));
}

.therapy-service-chip.is-complete em {
    background: #16a34a;
    color: #fff;
}

.therapy-service-chip.is-over-limit em {
    background: #dc2626;
    color: #fff;
}

.therapy-service-color,
.therapy-summary-check {
    width: 28px;
    min-width: 28px;
    height: 28px;
    border-radius: 999px;
    background: var(--service-color);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.therapy-service-chip span:not(.therapy-service-color) {
    min-width: 0;
    flex: 1;
}

.therapy-service-chip strong,
.therapy-service-chip small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
}

.therapy-service-chip small {
    color: var(--muted);
    margin-top: .15rem;
}

.therapy-service-chip em {
    font-style: normal;
    font-weight: 800;
    border-radius: 999px;
    padding: .2rem .45rem;
    background: var(--surface);
    border: 1px solid var(--border);
}

.therapy-specialty-selector {
    grid-column: 1 / -1;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    border-radius: 14px;
    padding: .8rem;
}

.therapy-specialty-list {
    max-height: 210px;
}

.therapy-slot.is-selected {
    background: var(--slot-service-color, #2563eb);
    border-color: var(--slot-service-color, #2563eb);
    color: #fff;
}

.therapy-slot.is-other-service {
    opacity: .88;
}

.appointment-matrix-card .month-calendar-header {
    margin-bottom: 1rem;
}

.appointment-matrix-scroll {
    max-height: calc(100vh - 260px);
}

.appointment-matrix .therapy-slot-doctor {
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

/* v33 - Terapias: filtros compactos y selección automática */
.therapy-batch-toolbar-selection {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: .75rem;
    align-items: start;
    padding: .7rem;
    margin-bottom: .65rem;
}

.therapy-filter-compact-row {
    display: grid;
    gap: .55rem;
    align-content: start;
}

.therapy-month-field {
    display: grid;
    gap: .25rem;
    font-size: .78rem;
    color: var(--muted);
    font-weight: 700;
}

.therapy-month-field input {
    width: 100%;
}

.therapy-month-field small {
    color: var(--muted);
    font-weight: 600;
    line-height: 1.1;
}

.therapy-filter-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: .55rem;
    min-width: 0;
}

.therapy-filter-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    overflow: clip;
    min-width: 0;
}

.therapy-filter-card summary {
    cursor: pointer;
    display: grid;
    grid-template-columns: minmax(110px, auto) minmax(0, 1fr);
    gap: .45rem;
    align-items: center;
    padding: .55rem .65rem;
    list-style: none;
}

.therapy-filter-card summary::-webkit-details-marker {
    display: none;
}

.therapy-filter-card summary::after {
    content: "▾";
    grid-column: 2;
    justify-self: end;
    color: var(--muted);
    font-size: .72rem;
    margin-left: .3rem;
}

.therapy-filter-card:not([open]) summary::after {
    content: "▸";
}

.therapy-filter-card summary span,
.therapy-filter-card summary em {
    min-width: 0;
}

.therapy-filter-card summary strong,
.therapy-filter-card summary small,
.therapy-filter-card summary em {
    display: block;
}

.therapy-filter-card summary strong {
    font-size: .86rem;
}

.therapy-filter-card summary small {
    color: var(--muted);
    font-size: .72rem;
    margin-top: .05rem;
}

.therapy-filter-card summary em {
    color: var(--text);
    font-style: normal;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 1.1rem;
}

.therapy-filter-card[open] {
    box-shadow: 0 14px 32px rgba(15, 23, 42, .08);
}

.therapy-filter-card[open] .therapy-professional-search-row,
.therapy-filter-card[open] .therapy-professional-actions {
    padding-left: .6rem;
    padding-right: .6rem;
}

.therapy-professional-search-row.compact {
    margin: 0 0 .35rem;
}

.therapy-professional-search-row.compact input {
    min-height: 36px;
    padding: .45rem .65rem;
}

.therapy-professional-actions.compact-actions {
    justify-content: flex-start;
    padding-top: 0;
    margin: 0 0 .35rem;
}

.therapy-filter-card .therapy-professional-list {
    max-height: 138px;
    border-width: 1px 0 0;
    border-radius: 0;
    background: transparent;
    padding: .35rem .45rem;
}

.therapy-filter-card .therapy-specialty-list {
    max-height: 120px;
}

.therapy-professional-option.compact {
    padding: .35rem .45rem;
    gap: .45rem;
    min-height: 0;
}

.therapy-professional-option.compact strong {
    font-size: .82rem;
    line-height: 1.15;
    -webkit-line-clamp: 1;
    line-clamp: 1;
}

.therapy-professional-option.compact small {
    font-size: .7rem;
}

.therapy-service-strip {
    margin-top: .2rem;
    margin-bottom: .55rem;
    max-height: 118px;
    overflow: auto;
}

.therapy-service-chip {
    min-height: 52px;
    padding: .5rem .6rem;
}

.therapy-service-color,
.therapy-summary-check {
    width: 22px;
    min-width: 22px;
    height: 22px;
    font-size: .78rem;
}

.therapy-batch-progress {
    margin-bottom: .65rem;
}

.therapy-auto-modal {
    position: fixed;
    inset: 0;
    z-index: 13000;
    background: rgba(15, 23, 42, .52);
    display: grid;
    place-items: center;
    padding: 1rem;
}

.therapy-auto-modal[hidden] {
    display: none !important;
}

.therapy-auto-card {
    width: min(560px, calc(100vw - 2rem));
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 28px 90px rgba(15, 23, 42, .35);
    padding: 1rem;
}

.therapy-auto-header h2 {
    margin: 0;
    font-size: 1.05rem;
}

.therapy-auto-header p {
    margin: .35rem 0 0;
    color: var(--muted);
    line-height: 1.35;
}

.therapy-auto-options {
    display: grid;
    gap: .55rem;
    margin: 1rem 0;
}

.therapy-auto-options label {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .65rem .75rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-muted);
    font-weight: 700;
}

.therapy-auto-options input[type="number"] {
    width: 72px;
    min-height: 32px;
    padding: .25rem .4rem;
}

.therapy-auto-actions {
    display: flex;
    justify-content: flex-end;
    gap: .55rem;
}

@media (max-width: 980px) {
    .therapy-batch-toolbar-selection {
        grid-template-columns: 1fr;
    }
    .therapy-filter-cards {
        grid-template-columns: 1fr;
    }
}


/* v34 - Terapias: TagBox compacto y modal automático sólido */
.therapy-filter-tagbox-grid {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) minmax(260px, 1.2fr);
    gap: .65rem;
    min-width: 0;
}

.therapy-filter-tagbox-field {
    display: grid;
    gap: .25rem;
    min-width: 0;
}

.therapy-filter-tagbox-field > span {
    color: var(--muted);
    font-size: .78rem;
    font-weight: 800;
}

.therapy-tagbox-host {
    min-width: 0;
}

.therapy-tagbox-fallback[hidden] {
    display: none !important;
}

.therapy-filter-note {
    margin-top: .45rem;
    color: var(--muted);
    font-size: .78rem;
}

.therapy-auto-modal {
    background: rgba(15, 23, 42, .64);
    backdrop-filter: blur(2px);
}

.therapy-auto-card {
    background: var(--panel, #ffffff);
    color: var(--text, #18202a);
    border-color: var(--line, #d9e0e7);
}

.therapy-auto-options label {
    background: var(--panel-2, #eef2f5);
    color: var(--text, #18202a);
    border-color: var(--line, #d9e0e7);
}

.therapy-summary-actions .btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
}

@media (max-width: 980px) {
    .therapy-filter-tagbox-grid {
        grid-template-columns: 1fr;
    }
}

/* v36 - Terapias: órdenes ya cubiertas y TagBox estable */
.therapy-order-complete {
    opacity: .72;
}

.therapy-order-complete td {
    background: color-mix(in srgb, var(--panel-2, #eef2f5) 70%, transparent);
}

.btn.disabled, .btn[aria-disabled="true"] {
    opacity: .55;
    pointer-events: none;
    cursor: not-allowed;
}

.therapy-tagbox-host .dx-tagbox {
    min-height: 38px;
}

/* v40 - Terapias: selección automática por días específicos */
.therapy-auto-weekdays {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
    gap: .4rem;
    padding: .65rem .75rem;
    border: 1px dashed var(--line, #d9e0e7);
    background: var(--panel-2, #eef2f5);
}

.therapy-auto-weekdays[hidden] {
    display: none !important;
}

.therapy-auto-weekdays > span {
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 800;
}

.therapy-auto-options .therapy-auto-weekdays label {
    padding: .35rem .45rem;
    border: 0;
    background: transparent;
    font-size: .82rem;
    font-weight: 700;
}

.therapy-auto-weekdays-trigger {
    align-items: flex-start !important;
}
