html { scrollbar-gutter: stable; }

:root {
  --navy: #0d294b;
  --blue: #1769c2;
  --blue-soft: #eaf3ff;
  --ink: #101820;
  --muted: #627083;
  --line: #d9e1ea;
  --warning: #d97706;
  --success: #17603b;
  --success-soft: #e4f5ec;
  --white: #ffffff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: #f4f7fa; }
button, input, select { font: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.5rem, 3vw, 2rem); }
h2 { margin-bottom: 0; font-size: 1.2rem; color: var(--navy); }
h3 { margin-bottom: 8px; font-size: 0.95rem; color: var(--navy); }
[hidden] { display: none !important; }

/* Encabezado */
.topbar {
  height: 88px; padding: 0 max(32px, calc((100vw - 1760px) / 2));
  display: flex; justify-content: space-between; align-items: center; gap: 20px;
  color: var(--white); background: #0b264d;
}
.brand-lockup { display: flex; align-items: center; gap: 12px; color: var(--white); text-decoration: none; }
.brand-logo { display: block; width: auto; height: 44px; }
.brand-name { font-family: Nunito, system-ui, sans-serif; font-size: 30px; font-weight: 800; line-height: 1; letter-spacing: -.5px; }
.doctor-area { display: flex; align-items: center; gap: 14px; color: #c9d9f2; font-size: .88rem; font-weight: 650; }
.logout-button { padding: 8px 10px; border: 1px solid #a9ccf7; border-radius: 6px; color: var(--white); background: transparent; cursor: pointer; font-weight: 700; }
.logout-button:hover { background: rgba(255, 255, 255, .1); }

/* Estructura de página */
.page { display: grid; gap: 16px; max-width: 1180px; margin: 16px auto 32px; padding: 0 24px; }
.page-narrow { max-width: 980px; }
.page-stage { max-width: 1240px; }
.card { min-width: 0; border: 1px solid var(--line); border-radius: 12px; padding: 20px; background: var(--white); box-shadow: 0 4px 16px rgba(13, 41, 75, .05); }
.card-title { margin-bottom: 16px; }
.card-heading { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; }
.card-heading h2, .card-heading h3 { margin: 0; }
.back-link { justify-self: start; display: inline-flex; align-items: center; gap: 6px; color: var(--blue); font-size: .86rem; font-weight: 750; text-decoration: none; }
.back-link::before { content: ""; width: 7px; height: 7px; border-bottom: 2px solid currentColor; border-left: 2px solid currentColor; transform: rotate(45deg); }
.back-link:hover { text-decoration: underline; }
.muted { margin: 4px 0 0; color: var(--muted); font-size: .88rem; }
.hint { margin: 0; padding: 10px 12px; border-radius: 7px; color: #294663; background: var(--blue-soft); font-size: .84rem; line-height: 1.45; }
.action-bar { max-width: 1180px; margin: -12px auto 32px; padding: 0 24px; }
.action-bar-inner { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding-top: 18px; border-top: 1px solid var(--line); }

/* Formularios */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
label { display: grid; gap: 7px; font-size: .85rem; font-weight: 700; }
input, select { width: 100%; min-height: 42px; padding: 9px 11px; color: var(--ink); border: 1px solid #b8c5d4; border-radius: 9px; background: var(--white); }
input:focus { outline: 3px solid #cfe3fb; border-color: var(--blue); }
input:disabled { color: #77889a; background: #eef2f6; cursor: not-allowed; }
.form-error { margin: 14px 0 0; padding: 10px 12px; border: 1px solid #f0c27a; border-radius: 7px; color: #7a3e00; background: #fff7e8; font-size: .85rem; font-weight: 650; line-height: 1.45; }
.search-form { display: grid; grid-template-columns: minmax(150px, .7fr) minmax(0, 1.3fr) auto; align-items: end; gap: 12px; }

/* Desplegables propios */
.custom-select { position: relative; width: 100%; min-width: 0; }
.custom-select > select { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; pointer-events: none; }
.custom-select__trigger { display: flex; width: 100%; min-height: 42px; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 12px; border: 1px solid #b8c5d4; border-radius: 9px; color: var(--ink); background: var(--white); box-shadow: 0 1px 2px rgba(13, 41, 75, .04); cursor: pointer; text-align: left; transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease; }
.custom-select__trigger:hover, .custom-select.is-open .custom-select__trigger { border-color: #8ea6bd; background: #fbfdff; }
.custom-select__trigger:focus-visible { outline: 0; border-color: var(--blue); box-shadow: 0 0 0 3px #cfe3fb; }
.custom-select__trigger:disabled { cursor: not-allowed; opacity: .55; }
.custom-select__value { min-width: 0; overflow: hidden; font-size: .9rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.custom-select.is-placeholder .custom-select__value { color: var(--muted); font-weight: 600; }
.custom-select__chevron { flex: 0 0 auto; width: 16px; height: 16px; color: var(--navy); transition: transform .16s ease; }
.custom-select.is-open .custom-select__chevron { transform: rotate(180deg); }
.custom-select.is-open .custom-select__trigger { border-bottom-right-radius: 0; border-bottom-left-radius: 0; }
.custom-select__menu { position: absolute; z-index: 30; top: calc(100% - 1px); right: 0; left: 0; display: none; width: 100%; overflow: auto; max-height: 300px; padding: 4px; border: 1px solid #b8c5d4; border-top: 0; border-radius: 0 0 9px 9px; background: var(--white); box-shadow: 0 14px 32px rgba(13, 41, 75, .16); }
.custom-select.is-open .custom-select__menu { display: block; animation: dropdown-in .14s ease-out; }
.custom-select__option { display: block; width: 100%; padding: 10px 11px; border: 0; border-bottom: 1px solid #edf1f5; border-radius: 7px; color: var(--ink); background: transparent; cursor: pointer; text-align: left; font-weight: 600; }
.custom-select__option:last-child { border-bottom: 0; }
.custom-select__option:hover, .custom-select__option:focus-visible { outline: 0; color: var(--navy); background: var(--blue-soft); }
.custom-select__option.is-selected { color: var(--blue); background: #f3f8fe; font-weight: 750; }
@keyframes dropdown-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* Selección segmentada y switches */
.question-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 18px; }
.question-label { font-size: .9rem; font-weight: 750; }
.segmented { display: inline-flex; padding: 4px; border-radius: 9px; background: #edf3f9; }
.segmented label { display: block; }
.segmented input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.segmented span { display: block; min-width: 72px; padding: 8px 14px; border-radius: 6px; color: #506278; font-size: .86rem; font-weight: 750; text-align: center; cursor: pointer; transition: background-color .15s ease, color .15s ease; }
.segmented span:hover { color: var(--navy); }
.segmented input:checked + span { color: var(--navy); background: var(--white); box-shadow: 0 1px 3px rgba(13, 41, 75, .18); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px #cfe3fb; }
.duration-input { display: flex; gap: 10px; }
.duration-input label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .84rem; }
.duration-input input { width: 76px; text-align: center; }
.switch-control { display: inline-flex; align-items: center; gap: 9px; width: fit-content; color: var(--ink); font-size: .86rem; font-weight: 700; cursor: pointer; }
.switch-control input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.switch-slider { position: relative; flex: 0 0 auto; width: 32px; height: 18px; border-radius: 999px; background: #aab8c7; transition: background .15s ease; }
.switch-slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--white); transition: transform .15s ease; }
.switch-control input:checked + .switch-slider { background: var(--blue); }
.switch-control input:checked + .switch-slider::after { transform: translateX(14px); }
.switch-control input:focus-visible + .switch-slider { box-shadow: 0 0 0 3px #cfe3fb; }
.checkbox-label { display: flex; align-items: center; gap: 8px; }
.checkbox-label input { width: 17px; min-height: 17px; margin: 0; accent-color: var(--blue); }

/* Botones */
.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: 9px 16px; border: 1px solid transparent; border-radius: 7px; font-weight: 750; text-decoration: none; cursor: pointer; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.primary { color: var(--white); background: var(--blue); }
.button.secondary { color: var(--navy); border-color: var(--navy); background: var(--white); }
.button.danger { color: var(--white); background: #b42318; }
.button.large { min-height: 50px; padding: 12px 26px; font-size: 1rem; }
.button:hover:not(:disabled) { filter: brightness(.94); }
.button:focus:not(:focus-visible) { outline: 0; box-shadow: none; }
.button:focus-visible { outline: 3px solid #cfe3fb; outline-offset: 1px; }
.text-button { border: 0; padding: 5px; color: var(--blue); background: transparent; cursor: pointer; font-weight: 750; }

/* Estados */
.status { padding: 6px 10px; border-radius: 999px; font-size: .75rem; font-weight: 750; white-space: nowrap; }
.status.neutral { color: #354457; background: #edf1f5; }
.status.working { color: #0d4f96; background: #dcecff; }
.status.ready { color: var(--white); background: var(--blue); }
.status.warning { color: #7a3e00; background: #fff1dc; }

/* Tablas */
.table-scroll { overflow-x: auto; }
.table-scroll.bordered { border: 1px solid var(--line); border-radius: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.data-table th, .data-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: center; vertical-align: middle; }
.data-table th { color: var(--muted); font-size: .78rem; font-weight: 750; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table.compact th, .data-table.compact td { padding: 9px 10px; }
.data-table th:last-child:has(.sr-only), .data-table td.row-actions { width: 1%; border-bottom-color: transparent; }
.cell-strong { font-weight: 700; }
.row-actions { white-space: nowrap; }
.row-actions > * + * { margin-left: 6px; }
.table-empty { color: var(--muted); font-size: .9rem; }
.open-button { min-height: 31px; border: 1px solid var(--blue); border-radius: 5px; padding: 5px 10px; color: var(--blue); background: var(--white); font-weight: 700; cursor: pointer; vertical-align: middle; }
.open-button:hover { color: var(--white); background: var(--blue); }
.updrs-missing-mark { display: inline-block; width: 11px; height: 11px; border-radius: 50%; background: var(--warning); vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

/* Paciente */
.patient-data { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0; }
.patient-data div { min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 9px; background: #fbfdff; }
.patient-data dt { color: var(--muted); font-size: .76rem; font-weight: 650; }
.patient-data dd { margin: 5px 0 0; overflow-wrap: anywhere; color: var(--navy); font-weight: 750; }
.medication-details { display: grid; gap: 16px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.medication-details > .button { justify-self: start; }
.exercise-picker-hint { margin: -6px 0 14px; }
.measurement-heading { gap: 12px; }
.measurement-heading .button { flex: 0 0 auto; }
.exercise-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.exercise-option { display: flex; align-items: flex-start; gap: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: #fbfdff; text-align: left; cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease; }
.exercise-option:hover { border-color: #8ea6bd; }
.exercise-option:focus-visible { outline: 0; box-shadow: 0 0 0 3px #cfe3fb; }
.exercise-option.is-selected { border-color: var(--blue); background: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue); }
.exercise-order { display: grid; flex: 0 0 auto; width: 28px; height: 28px; place-items: center; border: 2px solid #b8c5d4; border-radius: 50%; color: var(--white); font-size: .86rem; font-weight: 800; }
.exercise-option.is-selected .exercise-order { border-color: var(--blue); background: var(--blue); }
.exercise-option-text { display: grid; gap: 3px; }
.exercise-option-text strong { color: var(--navy); font-size: 1rem; }
.exercise-option-text small { color: var(--blue); font-size: .76rem; font-weight: 750; }
.exercise-option-text span { color: var(--muted); font-size: .84rem; line-height: 1.45; }
.plain-list { margin: 14px 0 0; padding-left: 18px; color: #2a4058; font-size: .86rem; line-height: 1.6; }
.plain-list:empty { display: none; }

/* Selección de paciente */
.option-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.option-tab { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fbfdff; text-align: left; cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease; }
.option-tab:hover { border-color: #8ea6bd; }
.option-tab:focus-visible { outline: 0; box-shadow: 0 0 0 3px #cfe3fb; }
.option-tab.is-active { border-color: var(--blue); background: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue); }
.option-tab strong { display: block; color: var(--navy); font-size: .95rem; }
.option-tab small { display: block; margin-top: 3px; color: var(--muted); font-size: .8rem; }
.option-tab-icon { display: grid; flex: 0 0 auto; width: 40px; height: 40px; place-items: center; border-radius: 50%; color: var(--blue); background: var(--white); box-shadow: 0 1px 3px rgba(13, 41, 75, .14); }
.option-tab-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.option-panel { display: grid; gap: 14px; }
.option-panel .form-error { margin: 0; }
.not-found { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border: 1px solid #c7d7e8; border-radius: 9px; background: #f8fbff; }
.not-found p { margin: 0; color: #294663; font-size: .9rem; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.option-panel .form-actions { margin-top: 0; }
.success-note { margin: 0; color: var(--success); font-size: .86rem; font-weight: 750; }
.confirm-name { margin: -10px 0 0; color: var(--navy); font-size: 1.45rem; font-weight: 800; }
.confirm-data { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.confirm-data div { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfdff; }
.confirm-data dt { color: var(--muted); font-size: .74rem; font-weight: 650; }
.confirm-data dd { margin: 4px 0 0; font-weight: 750; }

/* Estado del paciente y medicación en ON */
.motor-state { display: grid; gap: 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.on-medication-field { display: grid; gap: 10px; min-width: 0; margin: 0; padding: 14px; border: 1px solid #c7d7e8; border-radius: 9px; background: #f8fbff; }
.on-medication-field[hidden] { display: none; }
.on-medication-title { margin: 0; color: var(--navy); font-size: .9rem; font-weight: 750; }
.on-medication-field .muted { margin: 0; }
.on-medication-list { display: grid; gap: 8px; }
.on-medication-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
.on-medication-row.is-on { border-color: #9fd6b7; background: var(--success-soft); }
.on-medication-row .checkbox-label { align-items: flex-start; font-weight: 600; cursor: pointer; }
.on-medication-row .checkbox-label input { margin-top: 2px; }
.on-medication-row strong { display: block; color: var(--navy); }
.on-medication-row small { display: block; margin-top: 2px; color: var(--muted); font-size: .78rem; }
.hours-field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .84rem; }
.hours-input { width: 70px; min-height: 36px; padding: 6px 8px; text-align: center; }
.muted-cell { color: var(--muted); }

/* Modales */
.modal { width: min(560px, calc(100vw - 28px)); max-height: min(90vh, 900px); padding: 0; overflow: auto; border: 0; border-radius: 13px; box-shadow: 0 20px 60px rgba(5, 23, 43, .3); }
.modal-wide { width: min(760px, calc(100vw - 28px)); }
.modal::backdrop { background: rgba(13, 41, 75, .52); }
.modal-content { display: grid; gap: 16px; padding: 22px; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-description { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.modal .form-error { margin: 0; }
.dialog-close { width: 32px; height: 32px; border: 0; border-radius: 7px; color: #52677c; background: transparent; cursor: pointer; font-size: 1.6rem; line-height: 1; }
.dialog-close:hover { background: #edf1f5; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 4px; }

/* Medicación (modal) */
.medication-list { display: grid; gap: 12px; }
.medication-item { display: grid; gap: 13px; padding: 14px; border: 1px solid var(--line); border-radius: 9px; background: #fbfdff; }
.medication-item .form-grid { gap: 11px; }
.medication-item .form-grid label { gap: 5px; font-size: .8rem; }
.medication-item-heading, .principles-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.principles-heading h3 { margin: 0; font-size: .84rem; }
.principle-list { display: grid; gap: 7px; }
.principle-row { display: grid; grid-template-columns: minmax(130px, 1.3fr) minmax(90px, .7fr) minmax(110px, .8fr) 34px; gap: 7px; }
.principle-row input { min-height: 37px; padding: 7px 9px; font-size: .82rem; }
.principle-row .principle-name[readonly] { color: #53677b; background: #edf2f7; cursor: default; }
.icon-remove { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 7px; color: #52677c; background: white; cursor: pointer; font-size: 1.2rem; }

/* Medición en vivo */
.stage { display: grid; gap: 16px; }
.stage-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.video-frame { position: relative; aspect-ratio: 16 / 9; overflow: hidden; border-radius: 12px; background: #07121f; }
.video-frame video { display: block; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.stage-video { width: 100%; box-shadow: 0 10px 34px rgba(13, 41, 75, .18); }
.landmarks-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.position-chip { position: absolute; top: 18px; left: 18px; z-index: 2; max-width: min(60%, 520px); margin: 0; padding: 9px 14px; border-radius: 999px; color: var(--white); background: rgba(7, 18, 31, .72); font-size: .88rem; font-weight: 750; }
.position-chip.is-ok { color: #052e16; background: rgba(134, 239, 172, .95); }
.position-chip.is-warning { color: #3d2200; background: rgba(255, 214, 153, .96); }
kbd { margin-left: 8px; padding: 2px 7px; border: 1px solid rgba(255, 255, 255, .55); border-radius: 5px; font-family: inherit; font-size: .74rem; font-weight: 700; }
.exercise-steps { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; padding: 0; list-style: none; }
.exercise-steps li { display: inline-flex; align-items: center; gap: 7px; padding: 5px 12px 5px 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: var(--white); font-size: .82rem; font-weight: 700; }
.exercise-step-number { display: grid; width: 22px; height: 22px; place-items: center; border-radius: 50%; color: var(--white); background: #aab8c7; font-size: .74rem; }
.exercise-steps li.is-current { border-color: var(--blue); color: var(--navy); }
.exercise-steps li.is-current .exercise-step-number { background: var(--blue); }
.exercise-steps li.is-done { color: var(--success); }
.exercise-steps li.is-done .exercise-step-number { background: var(--success); }
.exercise-instruction { margin: 4px 0 0; color: var(--navy); font-size: .92rem; font-weight: 650; }
.tap-counter { position: absolute; top: 18px; right: 18px; display: grid; justify-items: center; min-width: 128px; padding: 12px 18px; border-radius: 12px; color: var(--white); background: rgba(7, 18, 31, .72); backdrop-filter: blur(4px); }
.tap-counter span { font-size: clamp(2.6rem, 6vw, 4.2rem); font-weight: 800; line-height: 1; }
.tap-counter small { margin-top: 4px; color: #c9daee; font-size: .82rem; font-weight: 650; }
.stage-overlay { position: absolute; inset: 0; display: grid; align-content: center; justify-items: center; gap: 10px; padding: 24px; color: var(--white); background: rgba(7, 18, 31, .48); text-align: center; pointer-events: none; }
.stage-overlay strong { font-size: clamp(1.4rem, 3.4vw, 2.3rem); font-weight: 800; }
.stage-overlay strong.is-countdown { font-size: clamp(4rem, 12vw, 8rem); line-height: 1; }
.stage-overlay span { max-width: 640px; color: #e2ecf7; font-size: clamp(.95rem, 1.8vw, 1.15rem); font-weight: 650; line-height: 1.45; }
.stage-message { position: absolute; right: 18px; bottom: 18px; left: 18px; margin: 0 auto; width: fit-content; max-width: calc(100% - 36px); padding: 10px 16px; border-radius: 9px; color: var(--white); background: rgba(7, 18, 31, .72); font-size: .95rem; font-weight: 700; text-align: center; }
.stage-message.is-warning { color: #3d2200; background: rgba(255, 214, 153, .95); }
.hand-progress { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 0; padding: 0; list-style: none; }
.hand-slot { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--white); font-size: .86rem; }
.hand-slot-name { font-weight: 750; }
.hand-slot-state { color: var(--muted); font-weight: 650; }
.hand-slot.is-measuring { border-color: var(--blue); }
.hand-slot.is-measuring .hand-slot-state, .hand-slot.is-analyzing .hand-slot-state { color: var(--blue); }
.hand-slot.is-saved { border-color: #9fd6b7; background: var(--success-soft); }
.hand-slot.is-saved .hand-slot-state { color: var(--success); }
.hand-slot.is-failed .hand-slot-state { color: #b42318; }
.mode-summary { margin: -4px 0 0; color: var(--muted); font-size: .85rem; text-align: center; }
.stage-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.stage .form-error { justify-self: center; margin: 0; }
.modal-content > .switch-control { margin-top: 2px; }

/* Resultados */
.hand-results { display: grid; gap: 16px; }
.hand-result-actions { display: flex; align-items: center; gap: 10px; }
.hand-result-actions .button { padding: 8px 12px; font-size: .82rem; }
.recording-player { display: block; width: min(100%, 720px); max-height: 70vh; margin: 0 auto 16px; border-radius: 10px; background: #101820; }
.recording-player[hidden] { display: none; }
.view-tabs { display: flex; flex-wrap: wrap; gap: 6px; width: fit-content; max-width: 100%; padding: 5px; border-radius: 11px; background: #e6edf5; }
.view-tab { min-height: 38px; padding: 8px 16px; border: 0; border-radius: 8px; color: #506278; background: transparent; font-size: .9rem; font-weight: 750; cursor: pointer; }
.view-tab:hover { color: var(--navy); }
.view-tab:focus-visible { outline: 0; box-shadow: 0 0 0 3px #cfe3fb; }
.view-tab.is-active { color: var(--navy); background: var(--white); box-shadow: 0 1px 3px rgba(13, 41, 75, .18); }
.exercise-tabs .view-tab { min-height: 44px; padding: 10px 20px; font-size: .98rem; }
.hand-tabs { margin-bottom: -6px; }
.updrs-hint { margin: -6px 0 16px; }
.updrs-rows { display: grid; gap: 18px; }
.updrs-rows-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.updrs-group h3 { margin: 0 0 10px; }
.updrs-group + .updrs-group { padding-top: 16px; border-top: 1px solid var(--line); }
.updrs-row label { gap: 8px; }
.updrs-row-hand { color: var(--navy); font-size: .92rem; }
.locked-note { margin: 0; padding: 18px; border: 1px dashed #c4d0dd; border-radius: 12px; color: var(--muted); background: #f8fafc; font-size: .9rem; text-align: center; }
.summary-metrics { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0 0 18px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.main-chart .chart-figure { padding: 4px 0 0; }
.analysis-details { margin-top: 18px; border: 1px solid var(--line); border-radius: 9px; }
.analysis-details summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 16px; border-radius: 9px; color: var(--navy); font-size: .9rem; font-weight: 750; cursor: pointer; list-style: none; }
.analysis-details summary::-webkit-details-marker { display: none; }
.analysis-details summary:hover { background: #f8fbff; }
.analysis-details summary:focus-visible { outline: 0; box-shadow: 0 0 0 3px #cfe3fb; }
.details-chevron { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; transition: transform .16s ease; }
.analysis-details[open] .details-chevron { transform: rotate(180deg); }
.analysis-details[open] summary { border-bottom: 1px solid var(--line); border-bottom-right-radius: 0; border-bottom-left-radius: 0; }
.analysis-details-content { display: grid; gap: 22px; padding: 16px; }
.analysis-details-content .quality-box { margin-top: 0; }
.metric-groups { display: grid; gap: 16px; }
.metric-group h3 { margin-bottom: 8px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.metric { min-height: 88px; padding: 13px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.metric dt { font-size: .75rem; color: var(--muted); }
.metric dd { margin: 7px 0 2px; font-size: 1.2rem; font-weight: 760; color: var(--navy); }
.metric small { color: var(--muted); font-size: .7rem; line-height: 1.35; }
.chart-empty { display: grid; min-height: 180px; place-items: center; margin: 0; padding: 18px; border: 1px dashed #c4d0dd; border-radius: 7px; color: var(--muted); background: #f8fafc; font-size: .86rem; text-align: center; }
.charts { display: grid; gap: 22px; }
.chart-figure { margin: 0; }
.chart-figure + .chart-figure { padding-top: 20px; border-top: 1px solid var(--line); }
.chart-figure h3, .chart-figure h4 { margin: 0 0 3px; color: var(--navy); font-size: .9rem; }
.chart-figure figcaption p { margin: 0 0 8px; color: var(--muted); font-size: .8rem; line-height: 1.45; }
.analysis-chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: #e8edf3; stroke-width: 1; }
.chart-axis { stroke: #91a2b5; stroke-width: 1.2; }
.chart-tick { fill: #627083; font-size: 12px; }
.chart-axis-title { fill: #40546a; font-size: 12px; font-weight: 700; }
.chart-line-signal { fill: none; stroke: #1769c2; stroke-width: 2; stroke-linejoin: round; opacity: .85; }
.chart-line-threshold { stroke: #2f9e6b; stroke-width: 1.5; stroke-dasharray: 6 5; }
.chart-marker-tap { fill: #d64545; stroke: #fff; stroke-width: 1.5; }
.chart-marker-peak { fill: #e8912d; stroke: #fff; stroke-width: 1; }
.chart-band-pause { fill: rgba(124, 92, 196, .16); }
.chart-line-velocity { fill: none; stroke: #e8912d; stroke-width: 2; stroke-linejoin: round; }
.chart-line-trend { fill: none; stroke: #d64545; stroke-width: 1.8; stroke-dasharray: 7 5; }
.chart-bar { fill: #4a7fb5; opacity: .85; }
.chart-bar:hover { opacity: 1; }
.chart-bar.is-flagged { fill: #7c5cc4; }
.chart-label-count { fill: #8a5a12; font-size: 11px; font-weight: 700; }
.chart-line-mean { stroke: #d64545; stroke-width: 1.5; stroke-dasharray: 6 5; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin: 6px 0 0; padding: 0; color: #40546a; font-size: .78rem; list-style: none; }
.chart-legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; width: 18px; height: 0; border-top: 2px solid; }
.legend-swatch.is-signal { border-color: #1769c2; }
.legend-swatch.is-threshold { border-top-style: dashed; border-color: #2f9e6b; }
.legend-swatch.is-velocity { border-color: #e8912d; }
.legend-swatch.is-trend, .legend-swatch.is-mean { border-top-style: dashed; border-color: #d64545; }
.legend-swatch.is-tap { width: 10px; height: 10px; border: 0; border-radius: 50%; background: #d64545; }
.legend-swatch.is-peak { width: 0; height: 0; border-top: 0; border-right: 5px solid transparent; border-bottom: 9px solid #e8912d; border-left: 5px solid transparent; }
.legend-swatch.is-pause { width: 14px; height: 12px; border: 0; border-radius: 2px; background: rgba(124, 92, 196, .3); }
.legend-swatch.is-threshold-neutral { border-top-style: dashed; border-color: #8a99ab; }
.legend-swatch.is-tap-neutral { width: 10px; height: 10px; border: 0; border-radius: 50%; background: #8a99ab; }
.legend-swatch.is-peak-neutral { width: 0; height: 0; border-top: 0; border-right: 5px solid transparent; border-bottom: 9px solid #8a99ab; border-left: 5px solid transparent; }
.chart-figure + .table-scroll { margin-top: 18px; }
.legend-swatch.is-bar-flagged { width: 12px; height: 12px; border: 0; border-radius: 2px; background: #7c5cc4; }
.legend-swatch.is-bar { width: 12px; height: 12px; border: 0; border-radius: 2px; background: #4a7fb5; }
.quality-box { margin-top: 18px; padding: 14px; border-left: 4px solid var(--blue); background: var(--blue-soft); }
.quality-box ul { margin: 0; padding-left: 18px; color: #2a4058; font-size: .83rem; line-height: 1.55; }
.quality-box li + li { margin-top: 4px; }

/* Historial y comparación */
.expand-button { display: flex; width: 100%; align-items: center; justify-content: center; gap: 8px; margin-top: 10px; padding: 10px; border: 1px dashed #c4d0dd; border-radius: 8px; color: var(--blue); background: #f8fbff; font-weight: 750; cursor: pointer; }
.expand-button::after { content: ""; width: 7px; height: 7px; margin-top: -3px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform .16s ease; }
.expand-button[aria-expanded="true"]::after { margin-top: 3px; transform: rotate(-135deg); }
.expand-button:hover { border-color: var(--blue); background: var(--blue-soft); }
.expand-button:focus-visible { outline: 0; box-shadow: 0 0 0 3px #cfe3fb; }
.compare-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: -4px 0 14px; padding: 12px 14px; border: 1px solid #c7d7e8; border-radius: 9px; background: #f8fbff; }
.compare-bar p { margin: 0; color: #294663; font-size: .88rem; font-weight: 650; }
.compare-exercises { display: flex; flex: 1 1 100%; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.compare-exercises-label { color: var(--muted); font-size: .82rem; font-weight: 700; }
.exercise-chip { padding: 6px 12px; border: 1px solid #c7d7e8; border-radius: 999px; background: var(--white); font-size: .84rem; cursor: pointer; }
.visit-exercises { text-align: left; }
.visit-exercise { display: grid; gap: 1px; padding: 3px 0; }
.visit-exercise + .visit-exercise { margin-top: 4px; padding-top: 7px; border-top: 1px dashed var(--line); }
.visit-exercise strong { color: var(--navy); font-size: .88rem; }
.visit-exercise span { color: var(--muted); font-size: .8rem; }
.visit-exercise span.updrs-missing { color: var(--warning); }
.compare-bar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hand-cell { display: inline-grid; gap: 2px; }
.hand-cell > span:first-child { font-weight: 700; }
.updrs-missing { display: inline-flex; align-items: center; justify-content: center; gap: 5px; color: var(--warning); font-size: .8rem; font-weight: 650; }
.compare-checkbox { width: 17px; min-height: 17px; margin: 0; accent-color: var(--blue); cursor: pointer; }
.compare-exercise-tabs { margin: -4px 0 14px; }
.compare-patient { margin: -8px 0 14px; }
.session-legend { display: flex; flex-wrap: wrap; gap: 8px 12px; margin: 0; padding: 0; list-style: none; }
.session-legend li { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fbfdff; font-size: .84rem; }
.session-legend li { border-radius: 10px; align-items: flex-start; }
.session-legend li.is-current { border-color: var(--blue); background: var(--blue-soft); }
.session-legend .session-dot { margin-top: 4px; }
.legend-text { display: grid; gap: 2px; }
.legend-text span { color: var(--muted); font-size: .8rem; }
.context-row td { background: #f8fbff; font-size: .8rem; }
.compare-hint { margin: -8px 0 12px; }
.session-dot { display: inline-block; flex: 0 0 auto; width: 11px; height: 11px; border-radius: 50%; }
.session-heading { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
.compare-table th small { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; font-weight: 600; }
.change-cell { color: var(--navy); font-weight: 750; white-space: nowrap; }

/* Comparación: avisos, resumen y criterios del UPDRS */
.context-facts { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 0; padding: 0; list-style: none; }
.context-fact { display: grid; gap: 3px; min-width: 150px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 9px; background: #fbfdff; }
.context-fact span { color: var(--muted); font-size: .76rem; font-weight: 650; }
.context-fact strong { color: var(--navy); font-size: .95rem; }
.context-fact.is-warning { flex: 1 1 100%; border-color: #f0c27a; color: #7a3e00; background: #fff7e8; font-size: .84rem; font-weight: 650; }
.compare-summary { margin: 0 0 16px; padding: 14px 16px; border-left: 4px solid var(--blue); border-radius: 0 8px 8px 0; color: var(--navy); background: var(--blue-soft); font-size: .95rem; font-weight: 650; line-height: 1.5; }
.criteria-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.criterion-card { display: grid; align-content: start; gap: 10px; min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #fbfdff; }
.criterion-card h3 { margin: 0; font-size: .92rem; }
.criterion-values { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.criterion-values li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 7px; font-size: .84rem; }
.criterion-session { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.criterion-values strong { color: var(--navy); font-size: .98rem; }
.criterion-verdict { margin: 0; padding: 6px 10px; border-radius: 6px; color: #354457; background: #edf1f5; font-size: .8rem; font-weight: 750; }
.criterion-verdict.is-changed { color: #0d4f96; background: #dcecff; }
.criterion-hint { margin: -4px 0 0; color: var(--muted); font-size: .74rem; line-height: 1.4; }
.criteria-note { margin: 10px 0 18px; color: var(--muted); font-size: .76rem; }
#asymmetryCard .compare-summary { margin: 0; }
.tap-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 18px; }
.tap-charts .chart-figure + .chart-figure { padding-top: 0; border-top: 0; }
.tap-line { fill: none; stroke-width: 2.4; stroke-linejoin: round; }
.tap-point { fill: var(--white); stroke-width: 2.2; }
.chart-reference { stroke: #91a2b5; stroke-width: 1.2; stroke-dasharray: 4 4; }

/* Acceso */
.login-layout { max-width: 460px; margin: 60px auto; padding: 0 24px; }
.login-card { padding: 28px; }
.login-card h2 { margin-bottom: 9px; }
.login-description { color: var(--muted); font-size: .9rem; }
.login-form { display: grid; gap: 15px; margin-top: 22px; }
.login-form .form-error { margin: 0; }

@media (max-width: 820px) {
  .page { margin-top: 14px; padding: 0 14px; }
  .patient-data { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-grid, .summary-metrics { grid-template-columns: repeat(2, 1fr); }
  .criteria-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .option-tabs { grid-template-columns: 1fr; }
  .search-form { grid-template-columns: 1fr 1fr; }
  .search-form .button { grid-column: 1 / -1; }
  .updrs-box { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 520px) {
  .card { padding: 16px; }
  .topbar { height: 68px; padding: 0 16px; }
  .brand-logo { height: 34px; }
  .brand-name { font-size: 24px; }
  .doctor-area span { display: none; }
  .form-grid, .search-form, .patient-data, .confirm-data { grid-template-columns: 1fr; }
  .criteria-grid { grid-template-columns: 1fr; }
  .action-bar { padding: 0 14px; }
  .action-bar-inner .button { flex: 1 1 100%; }
  .position-chip { top: 10px; left: 10px; max-width: 70%; font-size: .76rem; }
  .stage-heading { align-items: flex-start; flex-direction: column; }
  .tap-counter { top: 10px; right: 10px; min-width: 96px; padding: 8px 12px; }
  .stage-message { right: 10px; bottom: 10px; left: 10px; max-width: calc(100% - 20px); font-size: .82rem; }
  .stage-controls .button { width: 100%; }
  .principle-row { grid-template-columns: 1fr 1fr 34px; }
  .principle-row .principle-name { grid-column: 1 / -1; }
  .modal-content { padding: 16px; }
}
