/* Tokens from the Nala design system (D31); values live only here. */
:root {
  --surface-100: #faf8fc; --surface-200: #ffffff; --brand-tint: #efe7f5;
  --ink: #23192b; --ink-muted: #5e5468; --brand: #56008a; --on-brand: #ffffff;
  --line: #ddd5e4; --control-border: #857a91; --alert: #b42318; --alert-tint: #fdecea;
  --display: "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --text: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --space-1: 4px; --space-2: 8px; --space-3: 16px; --space-4: 24px;
  --touch-min: 44px;
  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 16px; --radius-pill: 999px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-100: #151219; --surface-200: #1f1a24; --brand-tint: #2e2338;
    --ink: #eee9f2; --ink-muted: #b3a9bc; --brand: #c39be0; --on-brand: #24132f;
    --line: #3a3242; --control-border: #857a91; --alert: #ff8f85; --alert-tint: #3a1c1d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --surface-100: #151219; --surface-200: #1f1a24; --brand-tint: #2e2338;
  --ink: #eee9f2; --ink-muted: #b3a9bc; --brand: #c39be0; --on-brand: #24132f;
  --line: #3a3242; --control-border: #857a91; --alert: #ff8f85; --alert-tint: #3a1c1d;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  /* 100dvh: the visible height on phones, without the address bar (T6); 100vh before it
     for older browsers. */
  margin: 0; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--surface-100); color: var(--ink);
  font: 16px/24px var(--text);
}
h1, h2 { font-family: var(--display); color: var(--ink); margin: 0 0 var(--space-3); }
h1 { font-size: 28px; line-height: 36px; font-weight: 800; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-2) var(--space-3); background: var(--surface-200);
  border-bottom: 1px solid var(--line);
}
main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: var(--space-4) var(--space-3); }
.panel {
  background: var(--surface-200); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: var(--space-4);
}
.narrow { max-width: 420px; margin: var(--space-4) auto; }
label { display: block; font-weight: 600; margin: var(--space-3) 0 var(--space-1); }
input[type=text], input[type=password] {
  width: 100%; min-height: var(--touch-min); padding: 0 var(--space-2);
  font: inherit; color: var(--ink); background: var(--surface-200);
  border: 1px solid var(--control-border); border-radius: var(--radius-sm);
}
.help { color: var(--ink-muted); font-size: 14px; margin: var(--space-1) 0 0; }
button {
  min-height: var(--touch-min); padding: 0 var(--space-3); font: inherit; font-weight: 600;
  border-radius: var(--radius-md); cursor: pointer;
  background: transparent; color: var(--brand); border: 1px solid var(--control-border);
}
button.primary { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
.actions { margin-top: var(--space-4); }
.error {
  background: var(--alert-tint); color: var(--alert); border: 1px solid var(--alert);
  border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); margin: 0 0 var(--space-3);
}
footer { color: var(--ink-muted); font-size: 14px; text-align: center; padding: var(--space-3); }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.page-head h1, .page-head h2 { margin: 0; }
h2 { font-size: 20px; line-height: 28px; font-weight: 800; }
h3 { font-family: var(--display); font-size: 17px; margin: var(--space-3) 0 var(--space-2); }
.button {
  display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--touch-min);
  padding: 0 var(--space-3); border-radius: var(--radius-md); font-weight: 600; text-decoration: none;
  color: var(--brand); border: 1px solid var(--control-border); background: transparent;
}
.button.primary { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
kbd {
  font: 600 12px/1 var(--text); padding: 2px 6px; border-radius: var(--radius-sm);
  border: 1px solid currentColor;
}
input.search { margin-bottom: var(--space-3); }
input[type=search], input[type=email], input[type=tel], input[type=date] {
  width: 100%; min-height: var(--touch-min); padding: 0 var(--space-2);
  font: inherit; color: var(--ink); background: var(--surface-200);
  border: 1px solid var(--control-border); border-radius: var(--radius-sm);
}
input[aria-invalid=true], fieldset[aria-invalid=true] { border-color: var(--alert); }
.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.rows li { border-bottom: 1px solid var(--line); }
.rows a, .row-pick {
  display: grid; grid-template-columns: 1fr; gap: 0 var(--space-3); padding: var(--space-2) var(--space-2);
  min-height: var(--touch-min); color: var(--ink); text-decoration: none; cursor: pointer;
}
@media (min-width: 720px) { .rows a { grid-template-columns: 1.2fr 1fr 1.5fr auto; align-items: center; } }
.rows a:hover, .rows a:focus-visible, .row-pick:hover { background: var(--brand-tint); }
.row-pick { grid-template-columns: auto 1fr; align-items: center; }
.row-pick .row-sub { grid-column: 2; }
.row-main { font-weight: 700; }
.row-sub, .caption, .optional { color: var(--ink-muted); }
.caption { font-size: 14px; margin: 0 0 var(--space-1); }
.optional { font-weight: 400; }
.empty { color: var(--ink-muted); padding: var(--space-3) 0; }
.tag {
  display: inline-block; font: 600 13px/20px var(--text); padding: 0 var(--space-2);
  border-radius: var(--radius-pill); background: var(--surface-100); border: 1px solid var(--line); color: var(--ink-muted);
}
.panel + .panel { margin-top: var(--space-3); }
.form h2 { margin-top: var(--space-4); }
.form h2:first-of-type { margin-top: 0; }
fieldset.choice { border: 0; padding: 0; margin: var(--space-3) 0 0; }
fieldset.choice legend { font-weight: 600; margin-bottom: var(--space-1); padding: 0; }
.pill {
  display: inline-flex; align-items: center; gap: var(--space-1); min-height: var(--touch-min);
  margin: 0 var(--space-2) var(--space-2) 0; padding: 0 var(--space-3); font-weight: 400;
  border: 1px solid var(--control-border); border-radius: var(--radius-pill); cursor: pointer;
}
.pill:has(input:checked) { background: var(--brand-tint); border-color: var(--brand); font-weight: 600; }
.check { display: flex; align-items: center; gap: var(--space-2); font-weight: 600; min-height: var(--touch-min); }
.check input, .pill input, .row-pick input { width: 20px; height: 20px; accent-color: var(--brand); }
.inline-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 160px)); gap: var(--space-3); }
.inline-fields .field-error { grid-column: 1 / -1; }
.field-error { color: var(--alert); font-weight: 600; margin: var(--space-1) 0 0; }
.error ul { margin: var(--space-1) 0 0; padding-left: var(--space-4); }
.error p { margin: 0; }
.notice {
  background: var(--surface-200); border: 1px solid var(--line); border-left: 4px solid var(--brand);
  border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); margin: 0 0 var(--space-3);
}
.facts { display: grid; grid-template-columns: minmax(110px, max-content) 1fr; gap: var(--space-1) var(--space-3); margin: 0; }
.facts dt { color: var(--ink-muted); }
.facts dd { margin: 0; }
.crumb { margin: 0 0 var(--space-2); }
dialog {
  border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4);
  background: var(--surface-200); color: var(--ink); max-width: 480px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
@media (pointer: coarse) { main kbd, .topbar kbd { display: none; } }
.search-box { position: relative; margin-bottom: var(--space-3); }
.search-box input.search, .search-box input[type=search] { margin: 0; padding-right: 96px; }
.search-box .clear {
  position: absolute; right: 40px; top: 50%; transform: translateY(-50%);
  min-height: var(--touch-min); min-width: var(--touch-min); padding: 0; border: 0; color: var(--ink-muted); font-size: 18px;
}
.search-box .search-key { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); }
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
html[data-keys=off] kbd.k1 { display: none; }
button.link { border: 0; min-height: var(--touch-min); padding: 0 var(--space-2); color: var(--brand); }
.empty .button { margin-top: var(--space-2); }
.empty p { margin: 0 0 var(--space-1); }
.date-field { display: flex; gap: var(--space-2); align-items: center; position: relative; max-width: 320px; }
.date-field input[type=text] { flex: 1; }
.date-picker { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
/* --- Top bar as in the prototype (spec 003, UI-A) --- */
.topbar { flex-wrap: nowrap; justify-content: flex-start; }
.topbar .brand { display: inline-flex; align-items: center; min-height: var(--touch-min); font-family: var(--display); font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.topbar .screen { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.screen-title { font-family: var(--display); font-weight: 800; font-size: 20px; line-height: 26px; }
.screen-title { align-self: flex-start; max-width: 100%; }
.screen-title:focus { outline: none; }
.screen-title:focus-visible { outline: 3px solid var(--brand); }
.screen-sub { color: var(--ink-muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-actions { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.button.icon { min-width: var(--touch-min); justify-content: center; padding: 0; font-weight: 800; }
.user-menu { position: relative; }
.user-button { gap: var(--space-2); padding: 0 var(--space-2); min-width: var(--touch-min); justify-content: center; }
.menu-who { display: flex; flex-direction: column; padding: var(--space-2) 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.menu-who span { color: var(--ink-muted); }
.initials {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border-radius: var(--radius-pill); background: var(--brand-tint); color: var(--ink); font-size: 13px; font-weight: 700;
}
.menu {
  position: absolute; right: 0; top: calc(100% + var(--space-1)); z-index: 20; min-width: 240px;
  display: flex; flex-direction: column; padding: var(--space-1);
  background: var(--surface-200); border: 1px solid var(--line); border-radius: var(--radius-md);
}
.menu[hidden] { display: none; }
.menu form { margin: 0; }
.menu [role=menuitem] {
  display: flex; align-items: center; width: 100%; min-height: var(--touch-min); padding: 0 var(--space-3);
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink);
  font: inherit; font-weight: 400; text-align: left; text-decoration: none; cursor: pointer;
}
.menu [role=menuitem]:hover, .menu [role=menuitem]:focus-visible { background: var(--brand-tint); }
.search-row { display: flex; gap: var(--space-3); align-items: center; margin-bottom: var(--space-3); }
.search-row .search-box { flex: 1; margin: 0; }
.toast {
  position: fixed; left: 50%; bottom: var(--space-4); transform: translateX(-50%); z-index: 30;
  max-width: calc(100% - 32px); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  background: var(--ink); color: var(--surface-200); font-weight: 600; visibility: hidden;
}
.toast.show { visibility: visible; }
#help .actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
#help .actions span { margin-right: auto; }
/* --- Patient history (spec 003, UI-B, C, E, F, H), laid out as the prototype --- */
main.wide { max-width: none; padding: 0; }
.patient-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-3) var(--space-4);
  padding: var(--space-3) var(--space-4) 12px; background: var(--surface-200);
}
.patient-head h1 { margin: 0; }
.patient-id { display: flex; flex-direction: column; gap: 2px; }
.patient-line { color: var(--ink-muted); }
.patient-tutor { display: flex; flex-direction: column; padding-left: var(--space-4); border-left: 1px solid var(--line); }
.patient-tutor a { display: inline-flex; align-items: center; min-height: var(--touch-min); color: var(--ink); font-weight: 700; text-decoration: none; }
.patient-tutor a:hover { text-decoration: underline; }
.patient-actions { margin-left: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-100); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.strip-label { font-weight: 700; font-size: 14px; margin-right: var(--space-1); }
.strip-empty { color: var(--ink-muted); }
.strip-open { margin-left: auto; }
.chip {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 var(--space-3);
  border-radius: var(--radius-pill); background: var(--surface-200); color: var(--ink);
  border: 1px solid var(--control-border);
}
.chip-allergy, .chip-allergy-severe { color: var(--alert); border-color: var(--alert); font-weight: 700; }
.chip-allergy-severe { background: var(--alert-tint); }
.chip-behavior { border: 2px solid var(--ink); font-weight: 700; }
.history-cols { display: flex; flex-wrap: wrap; gap: var(--space-4); align-items: flex-start; padding: var(--space-3) var(--space-4); }
.history-main { flex: 2 1 420px; min-width: 0; }
.history-side { flex: 1 1 300px; min-width: 0; }
.history-cols h2 { font-size: 18px; margin-bottom: var(--space-2); }
.applications { list-style: none; margin: 0 0 var(--space-3); padding: 0; border-top: 1px solid var(--line); }
.applications li { display: flex; flex-direction: column; padding: var(--space-2) 0; border-bottom: 1px solid var(--line); }
.application-form { padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-200); }
.application-form select, .panel-dialog select {
  width: 100%; min-height: var(--touch-min); padding: 0 var(--space-2); font: inherit; color: var(--ink);
  background: var(--surface-200); border: 1px solid var(--control-border); border-radius: var(--radius-sm);
}
.panel-dialog {
  margin: 0 0 0 auto; height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh; width: min(560px, 100%); max-width: 100%;
  border: 0; border-left: 1px solid var(--line); border-radius: 0; overflow: auto;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.panel-head h2 { margin: 0; }
.panel-head h2:focus { outline: none; }
.ante-group h3 { margin-top: var(--space-3); }
.ante-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--line); }
.ante-row .ante-text { flex: 1; display: flex; flex-direction: column; }
.ante-allergy { color: var(--alert); font-weight: 700; }
.ante-resolved { color: var(--ink-muted); }
.proposed { color: var(--ink-muted); font-size: 14px; }
input.short { max-width: 120px; }
.row-flags { display: flex; gap: var(--space-1); flex-wrap: wrap; justify-content: flex-end; }
.tag-alert { color: var(--alert); border-color: var(--alert); font-weight: 700; }
.tag-ink { color: var(--ink); border: 2px solid var(--ink); font-weight: 700; }
.panel-dialog .actions, .application-form .actions { display: flex; justify-content: space-between; gap: var(--space-2); }
/* Patient list rows as in the prototype: name over its description, tutor, last visit, markers */
#results .rows { border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface-200); }
#results .rows li:last-child { border-bottom: 0; }
#results .rows a { min-height: 64px; padding: 10px var(--space-3); gap: var(--space-1) var(--space-3); }
@media (min-width: 720px) {
  #results .rows a { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1.3fr) minmax(0, 0.8fr) minmax(0, 0.7fr); align-items: center; }
}
.row-name { display: flex; flex-direction: column; min-width: 0; }
.row-name .row-main { font-family: var(--display); font-size: 18px; line-height: 24px; }
.row-desc { font-size: 14px; line-height: 20px; color: var(--ink-muted); overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; }
.row-tutor { font-size: 14px; line-height: 20px; min-width: 0; }
.row-last { font-size: 14px; line-height: 20px; color: var(--ink-muted); }
main.list-page { max-width: none; padding: var(--space-3) var(--space-4); }
#results .rows a:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; border-radius: var(--radius-sm); }

/* --- Spec 004: consultation in the history (UI-B6, UI-E3) --- */
.patient-actions form { display: contents; }
.button.danger { color: var(--alert); border-color: var(--alert); font-weight: 700; }
.draft-box {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3);
  padding: 12px var(--space-3); border: 2px dashed var(--brand); border-radius: var(--radius-md);
  background: var(--surface-200); margin-bottom: var(--space-2);
}
.draft-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-left: auto; }
.draft-actions[hidden] { display: none; }
.consult-list { display: flex; flex-direction: column; gap: var(--space-2); }
.consult-card {
  display: flex; flex-direction: column; gap: 2px; padding: 12px var(--space-3); color: var(--ink); text-decoration: none;
  background: var(--surface-200); border: 1px solid var(--line); border-radius: var(--radius-md);
}
.consult-card-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); }
.see-detail { margin-left: auto; color: var(--brand); font-weight: 600; font-size: 14px; }

/* --- Spec 004: the consultation (producto/vista-consulta.md) --- */
.lbl-short { display: none; }
@media (max-width: 1199px) { .lbl-long { display: none; } .lbl-short { display: inline; } }
.topbar:has([data-save-consultation]) .screen-title { white-space: nowrap; }
body:has(main.consultation-page) { height: 100vh; height: 100dvh; overflow: hidden; }
body:has(main.consultation-page) > footer { display: none; }
main.consultation-page { max-width: none; padding: 0; min-height: 0; display: flex; flex-direction: column; }
.consultation { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.consult-head {
  flex-shrink: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) 20px;
  padding: 10px var(--space-4); background: var(--surface-200); border-bottom: 1px solid var(--line);
}
.consult-patient { display: flex; flex-direction: column; }
.consult-name { margin: 0; font-family: var(--display); font-weight: 800; font-size: 22px; line-height: 28px; }
.consult-weight { display: flex; align-items: center; gap: var(--space-2); }
.consult-weight label { font-weight: 600; font-size: 14px; }
.consult-weight input { width: 80px; }
.consult-weight .unit { color: var(--ink-muted); }
.consult-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.draft-status { margin-left: auto; font-size: 13px; color: var(--ink-muted); }
.consult-body { flex: 1; min-height: 0; display: flex; }
.consult-index {
  flex-shrink: 0; width: 232px; overflow-y: auto; padding: var(--space-3) 12px;
  display: flex; flex-direction: column; gap: 2px; background: var(--surface-200); border-right: 1px solid var(--line);
}
.index-title { font-size: 13px; color: var(--ink-muted); padding: 0 10px var(--space-1); }
.consult-index a {
  min-height: var(--touch-min); display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: 0 10px; border-radius: var(--radius-sm); color: var(--ink); text-decoration: none;
}
.consult-index a[aria-current="location"] { background: var(--brand-tint); font-weight: 700; }
.index-status { font-size: 13px; color: var(--ink-muted); white-space: nowrap; }
.consult-main { flex: 1; min-width: 0; overflow-y: auto; padding: var(--space-1) 28px 72px; scroll-padding-top: var(--space-2); }
.consult-section { padding: var(--space-3) 0 var(--space-2); border-bottom: 1px solid var(--line); }
.section-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-2); }
.section-head h2 { margin: 0; font-size: 20px; line-height: 28px; }
.section-status { font-size: 13px; color: var(--ink-muted); }
.consult-section .field { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-2) 0; }
.consult-section .field label { font-weight: 600; font-size: 14px; }
.consult-section textarea, .consult-section .field input:not([type=checkbox]) { width: 100%; }
.pending { color: var(--ink-muted); font-style: italic; }
.keys-bar {
  flex-shrink: 0; display: flex; flex-wrap: wrap; gap: var(--space-1) 20px; padding: 6px var(--space-4);
  font-size: 13px; color: var(--ink-muted); background: var(--surface-200); border-top: 1px solid var(--line);
}
:root[data-keys="off"] .keys-bar { display: none; }
@media (pointer: coarse) { .keys-bar { display: none; } }
.history-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); z-index: 20; overflow-y: auto;
  padding: var(--space-4); background: var(--surface-200); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.history-panel[hidden] { display: none; }
.history-panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.history-panel-head h2 { margin: 0; font-size: 20px; }
.history-panel-item { display: flex; flex-direction: column; gap: 2px; padding: var(--space-2) 0; border-bottom: 1px solid var(--line); }
@media (max-width: 999px) {
  .consult-index { width: 176px; }
  .consult-index a { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; padding: 4px 10px; }
  .index-status { white-space: normal; }
  .consult-main { padding: var(--space-1) var(--space-3) 72px; }
}
.consultation textarea {
  width: 100%; min-height: 64px; padding: 10px var(--space-2); resize: vertical;
  font: inherit; color: var(--ink); background: var(--surface-200);
  border: 1px solid var(--control-border); border-radius: var(--radius-sm);
}
@media (max-width: 999px) { .topbar:has([data-save-consultation]) .brand { display: none; } }
/* Room after the last section, so every section can reach the top when the index goes to it. */
.consult-main::after { content: ""; display: block; height: 50vh; }

/* --- Spec 004, part B: exam rows (UI-CD), vitals (UI-CF) and pain (UI-CG) --- */
.exam-row {
  display: grid; grid-template-columns: minmax(180px, 250px) minmax(0, 1fr); gap: 6px var(--space-4);
  padding: 10px 0 10px 10px; margin-left: -13px; border-bottom: 1px solid var(--line); border-left: 3px solid transparent;
}
.exam-row[data-state="abnormal"]:not([data-counts-abnormal="no"]) { border-left-color: var(--ink); }
.exam-row[hidden] { display: none; }
.row-label { display: flex; flex-direction: column; gap: 2px; padding-top: 10px; }
.row-name { font-weight: 600; }
.row-ref { font-size: 13px; line-height: 18px; color: var(--ink-muted); margin: 0; }
.row-answer { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.opts { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.opt {
  position: relative; display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--touch-min);
  padding: 0 14px; border: 1px solid var(--control-border); border-radius: var(--radius-pill);
  background: var(--surface-200); color: var(--ink); cursor: pointer; font-size: 15px; line-height: 20px;
}
.opt:has(input:checked) { border: 2px solid var(--brand); padding: 0 13px; background: var(--brand-tint); font-weight: 700; }
.opt:has(input:focus-visible) { outline: 3px solid var(--brand); outline-offset: 2px; }
.opt input.sr { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.mk { flex-shrink: 0; width: 14px; height: 14px; border: 2px solid var(--control-border); }
.mk.radio { border-radius: var(--radius-pill); }
.mk.checkbox { border-radius: 3px; }
.opt:has(input:checked) .mk { border-color: var(--brand); }
.opt:has(input:checked) .mk.radio { background: radial-gradient(var(--brand) 45%, transparent 50%); }
.opt:has(input:checked) .mk.checkbox { background: var(--brand); }
.prop { font-size: 13px; font-weight: 400; color: var(--ink-muted); }
.abn-hint { font-size: 13px; color: var(--ink-muted); }
.row-abn, .row-side, .row-note { display: flex; flex-direction: column; gap: var(--space-1); }
.row-abn[hidden], .row-side[hidden], .row-note[hidden] { display: none; }
.row-note label { font-size: 13px; color: var(--ink-muted); }
.vitals { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 var(--space-4); }
.vitals .exam-row { grid-template-columns: 1fr; margin-left: 0; padding-left: 0; border-left: 0; }
.vitals .row-label { padding-top: 0; }
.number-field { display: flex; align-items: center; gap: var(--space-2); }
.number-field input { width: 110px; }
.range-help { font-size: 13px; color: var(--ink-muted); }
.range-help.out, .index-status.out, .section-status.out { color: var(--alert); font-weight: 700; }
.sub-title { font-size: 17px; margin: var(--space-3) 0 var(--space-1); }
.hydration-sum { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: 12px 0; }
.hydration-sum .button[aria-pressed="true"] { background: var(--brand-tint); border-color: var(--brand); }
.pain-block { border: 0; padding: 0; margin: var(--space-2) 0; }
.pain-block legend { font-weight: 600; padding: 0; margin-bottom: var(--space-1); }
.score-opt { min-width: 52px; justify-content: center; padding: 0; font-variant-numeric: tabular-nums; }
.opt.score-opt:has(input:checked) { padding: 0; }
.pain-face { display: flex; flex-direction: column; gap: var(--space-3); }
.pain-face .opt.face-opt { border-radius: var(--radius-md); }
.pain-face .opt.face-opt:has(input:checked) { padding: 7px; }
.pain-total { font-weight: 700; margin: var(--space-2) 0 0; }
.pain-foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-2) 0; }
.pain-foot .button[hidden] { display: none; }
.undo-toast { visibility: visible; display: flex; align-items: center; gap: var(--space-3); bottom: 88px; }
.undo-toast[hidden] { display: none; }
.undo-toast .button { min-height: 36px; background: var(--surface-200); }
@media (max-width: 999px) {
  .exam-row { grid-template-columns: minmax(0, 1fr); }
  .row-label { padding-top: 0; }
}
.undo-key { font-weight: 400; }
.abn-hint.error { color: var(--alert); font-weight: 700; }
.check-line { display: flex; align-items: center; gap: var(--space-2); min-height: var(--touch-min); font-size: 14px; font-weight: 400; }
.check-line input { width: 20px; height: 20px; accent-color: var(--brand); }
.detail {
  max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-4); background: var(--surface-200); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.detail .muted { color: var(--ink-muted); }
.detail-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2) var(--space-3); margin-bottom: var(--space-2); }
.detail-head h1 { margin: 0; font-size: 22px; line-height: 28px; }
.detail-head h1:focus { outline: none; }
.detail .detail-sub { font-size: 16px; line-height: 24px; margin: var(--space-3) 0 0; }
.detail p { margin: 0; }
.out-word { color: var(--alert); font-weight: 700; }
/* Follow-up (D81, D82): brand-tint fill, bold ink, 2 px dashed border; the word says what it is. */
.chip-follow { background: var(--brand-tint); border: 2px dashed var(--ink); font-weight: 600; }
.follow-text { font-weight: 600; }
.tag-muted { color: var(--ink-muted); border-color: var(--control-border); }
.list-filter { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-2); }
/* D86: neutral bar under the face scale total; no colored zones or labels (D45). */
.pain-bar { width: min(320px, 100%); height: 10px; margin-top: var(--space-1); border: 1px solid var(--control-border); border-radius: var(--radius-pill); overflow: hidden; }
.pain-bar[hidden] { display: none; }
.pain-bar span { display: block; height: 100%; width: 0; background: var(--ink); }

/* --- 0.4.1: corrections from the UI/UX review (specs/004-1-correcciones) --- */
/* B13: placeholders with the muted ink, 4.5:1 in both themes */
::placeholder { color: var(--ink-muted); opacity: 1; }
.keys-bar { color: var(--ink-muted); }
/* B1: a title focused on entering shows its ring only to keyboard users */
:root:not([data-modality="keyboard"]) [tabindex="-1"]:focus-visible { outline: none; }
/* C9: no double line at the end of a section */
.consult-section > .exam-row:last-child { border-bottom: 0; }
/* C12: the index status goes under its section from 1200 px down */
@media (max-width: 1199px) {
  .consult-index a { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; padding: 4px 10px; }
  .index-status { white-space: normal; }
}
/* C13: toasts stay clear of the bottom of the consultation */
body:has(main.consultation-page) .toast:not(.undo-toast) { bottom: auto; top: 72px; }
button:disabled { opacity: .55; cursor: not-allowed; }
/* D90: our own confirmation */
.confirm-dialog h2 { margin-bottom: var(--space-2); }
.confirm-dialog p { margin: 0; }
.confirm-dialog .actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; }
.panel-dialog .actions, .application-form .actions { justify-content: flex-start; }
/* A8: down to 320 px without horizontal scroll (WCAG 1.4.10) */
@media (max-width: 600px) {
  .topbar { flex-wrap: wrap; padding: var(--space-2); gap: var(--space-2); }
  .topbar .screen { flex-basis: calc(100% - 140px); }
  .bar-actions { flex-wrap: wrap; flex-shrink: 1; width: 100%; }
  .screen-sub { white-space: normal; }
  .patient-head, .strip, .history-cols { padding-left: var(--space-3); padding-right: var(--space-3); }
  .patient-tutor { padding-left: 0; border-left: 0; }
  .patient-actions { margin-left: 0; }
  .detail { padding: var(--space-3); }
  main { padding: var(--space-3) var(--space-2); }
  main.list-page { padding: var(--space-3) var(--space-2); }
  .facts { grid-template-columns: 1fr; }
  body:has(main.consultation-page) { height: auto; overflow: visible; }
  .consult-head { padding: var(--space-2) var(--space-3); }
  .consult-body { flex-direction: column; }
  .consult-index {
    width: 100%; flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: var(--space-1) var(--space-2);
    border-right: 0; border-bottom: 1px solid var(--line);
  }
  .consult-index a { flex: 0 0 auto; }
  .index-title { display: none; }
  .consult-main { overflow: visible; padding: var(--space-1) var(--space-3) 72px; }
  .consult-main::after { height: 0; }
  .section-head .button { white-space: nowrap; }
  .exam-row { margin-left: 0; }
  .vitals { grid-template-columns: 1fr; }
  .search-row { flex-wrap: wrap; }
  .search-row .search-box { flex-basis: 100%; } /* the search box keeps its width at 360 px */
  .inline-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* --- Spec 005: applied medicines (UI-CH5) and prescription (UI-CH6, CH7) --- */
.med-block { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-2) 0; }
.med-title { font-weight: 600; font-size: 14px; }
.med-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-3); }
.med-head .sub-title { margin: var(--space-2) 0 0; }
.med-line { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2) var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--line); }
.rx-line { flex-direction: column; align-items: stretch; }
.med-grid { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2) var(--space-3); }
.med-field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.med-field label { font-weight: 600; font-size: 14px; margin: 0; }
.med-name { flex: 1 1 220px; }
.med-name select, .med-name input[type=text] { width: 100%; max-width: 100%; }
.med-field select { max-width: 100%; }
.med-short input { width: 96px; }
.med-field select, .med-field input[type=text] {
  min-height: var(--touch-min); padding: 0 var(--space-2); font: inherit; color: var(--ink);
  background: var(--surface-200); border: 1px solid var(--control-border); border-radius: var(--radius-sm);
}
.med-field select[aria-invalid=true], .med-field input[aria-invalid=true] { border-color: var(--alert); }
.med-new { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2) var(--space-3); }
.med-foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.med-foot > span { flex: 1 1 260px; }
.med-block > .button { align-self: flex-start; }
.med-line > .med-remove { align-self: flex-end; }
.detail-list { margin: 0; padding-left: var(--space-4); }
.consult-section .field .ante-from, .med-foot .button { align-self: flex-start; }
.detail-edit { margin-left: auto; }
/* D97: what the assistant sees of the consultations, read only */
.consult-list.inactive { list-style: none; margin: 0; padding: 0; }
.consult-card.inactive { color: var(--ink); background: var(--surface-100); border-style: dashed; }
.draft-box.inactive { border-color: var(--control-border); }
/* --- Spec 006: what the tutor sees on the phone (360 × 800) --- */
body.tutor-page { background: var(--surface-100); }
.tutor-main { max-width: 560px; margin: 0 auto; padding: var(--space-4) var(--space-3); display: flex; flex-direction: column; gap: var(--space-3); }
.tutor-main h1 { font-size: 24px; line-height: 30px; margin: 0; }
.tutor-main p { margin: 0; }
.tutor-sub, .tutor-muted { color: var(--ink-muted); }
.tutor-tag { align-self: flex-start; font-size: 13px; color: var(--ink-muted); border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 0 var(--space-2); }
.tutor-card { background: var(--surface-200); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); }
.tutor-card h2 { font-size: 18px; margin: 0; }
.tutor-consult { border-top: 1px solid var(--line); padding-top: var(--space-2); display: flex; flex-direction: column; gap: var(--space-1); }
.tutor-consult h3 { font-size: 16px; margin: 0; }
.tutor-consult ul { margin: 0; padding-left: var(--space-4); }
.tutor-alert { color: var(--alert); font-weight: 700; }
.tutor-rx-line { border-top: 1px solid var(--line); padding-top: var(--space-2); }
.tutor-rx-med { font-weight: 700; }
.tutor-code { display: flex; flex-direction: column; gap: var(--space-2); }
.tutor-code input[type=text] { font-size: 20px; letter-spacing: 4px; max-width: 200px; text-transform: uppercase; }
.tutor-code button { align-self: flex-start; }
.tutor-foot { color: var(--ink-muted); font-size: 14px; text-align: center; padding: var(--space-3); }
/* Spec 006: send screen */
.send { display: flex; flex-direction: column; gap: var(--space-3); max-width: 720px; margin: 0 auto; }
.send p { margin: 0; }
.send-message { white-space: pre-wrap; word-break: break-word; margin: 0; padding: var(--space-3); font: inherit; background: var(--surface-100); border: 1px solid var(--line); border-radius: var(--radius-md); }
.send-notes { margin: 0; padding-left: var(--space-4); color: var(--ink-muted); }
.send-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0; }
.send-replace summary { cursor: pointer; min-height: var(--touch-min); display: flex; align-items: center; font-weight: 600; color: var(--brand); }
.send-replace p { margin: 0 0 var(--space-2); }
.detail-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }

/* Chore 0.6.1, P16: the tutors found by the search, under the patients */
.list-sub { font-size: 1rem; margin: var(--space-4) 0 var(--space-2); }
#results .tutor-rows a { min-height: 56px; }
@media (min-width: 720px) { #results .tutor-rows a { grid-template-columns: minmax(0, 1.7fr) minmax(0, 2.8fr); } }

/* Chore 0.6.1, P15: correct and annul an antecedent or an application */
.row-actions { display: flex; flex-wrap: wrap; gap: 0 var(--space-3); }
.link-button { background: none; border: 0; padding: 0 var(--space-1); min-height: 44px; min-width: 44px;
  color: var(--brand); text-decoration: underline; font: inherit; cursor: pointer; }
.link-button:hover { color: var(--brand-strong, var(--brand)); }
.annulled .row-main, .annulled .row-sub:not(.annul-reason), .ante-annulled { text-decoration: line-through; color: var(--ink-muted); }
.annul-reason { color: var(--ink-muted); font-style: italic; }

/* Chore 0.6.3, P25: the clinic's logo in the top bar, one per theme. Without the logo of
   the theme in use, the name shows. The name stays for screen readers. */
.brand img { display: none; height: 40px; width: auto; max-width: 220px; object-fit: contain; }
.brand.has-logo .logo-light { display: block; }
.brand.has-logo .brand-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:root[data-theme="dark"] .brand .logo-light { display: none; }
:root[data-theme="dark"] .brand.has-logo-dark .logo-dark { display: block; }
:root[data-theme="dark"] .brand.has-logo:not(.has-logo-dark) .brand-name { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand .logo-light { display: none; }
  :root:not([data-theme="light"]) .brand.has-logo-dark .logo-dark { display: block; }
  :root:not([data-theme="light"]) .brand.has-logo:not(.has-logo-dark) .brand-name { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
}
@media (max-width: 600px) { .brand img { height: 32px; max-width: 200px; } .topbar .brand.has-logo { flex-basis: 100%; } }

/* Chore 0.6.6, D102: the sign-in (proposal A), the legal page and the terms acceptance */
main.entry-page { max-width: none; padding: 0; margin: 0; display: flex; }
.entry { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; min-height: 100dvh; width: 100%; }
.entry-brand { background: #56008a; color: #fff; display: flex; flex-direction: column; justify-content: center;
  gap: var(--space-4); padding: 48px 56px; }
.entry-cat { width: 150px; height: auto; }
.entry-name { font-family: var(--display); font-weight: 800; font-size: 40px; line-height: 44px; margin: 0; }
.entry-tagline { font-size: 20px; line-height: 28px; margin: 4px 0 0; color: #efe7f5; }
.entry-points { margin: 0; padding-left: 20px; color: #efe7f5; line-height: 30px; }
.entry-side { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: var(--space-4);
  padding: var(--space-4) var(--space-3); background: var(--surface-100); }
.entry-card { width: 100%; max-width: 380px; background: var(--surface-200); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: var(--space-4); }
.entry-card h1 { font-size: 24px; line-height: 30px; }
.entry-card form { display: flex; flex-direction: column; }
.entry-card .actions { margin-top: var(--space-3); }
.entry-card .primary { width: 100%; justify-content: center; }
.entry-version { color: var(--ink-muted); font-size: 13px; margin: 0; }
.legal-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 var(--space-3); font-size: 14px; }
.legal-links a { color: var(--ink-muted); min-height: 44px; display: inline-flex; align-items: center; }
@media (max-width: 760px) {
  .entry { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .entry-brand { flex-direction: row; align-items: center; gap: var(--space-3); padding: 24px 20px; }
  .entry-cat { width: 64px; }
  .entry-name { font-size: 28px; line-height: 32px; }
  .entry-tagline { font-size: 16px; line-height: 22px; }
  .entry-points { display: none; }
  .entry-side { justify-content: flex-start; padding-top: var(--space-4); }
}
main.legal-page { max-width: 1040px; }
.legal-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.legal-head h1 { margin: 0; }
.legal-cat { width: 48px; height: auto; }
:root[data-theme="dark"] .legal-cat { content: url("brand/cat-lilac.png"); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .legal-cat { content: url("brand/cat-lilac.png"); } }
.legal { display: grid; grid-template-columns: 220px 1fr; gap: var(--space-4); align-items: start; }
.legal-index { position: sticky; top: var(--space-3); display: flex; flex-direction: column; }
.legal-index a { padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); text-decoration: none; min-height: 44px;
  display: flex; align-items: center; }
.legal-index a:hover { background: var(--brand-tint); }
.legal-body section { background: var(--surface-200); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: var(--space-4); margin-bottom: var(--space-3); scroll-margin-top: var(--space-3); }
.legal-body section:target { border-color: var(--brand); }
.legal-body h2 { font-size: 22px; line-height: 28px; }
.legal-body p, .legal-body li { max-width: 72ch; }
@media (max-width: 760px) { .legal { grid-template-columns: 1fr; } .legal-index { position: static; flex-direction: row; flex-wrap: wrap; } }
.accept-links { padding-left: 20px; line-height: 32px; }
.accept-terms .check { align-items: flex-start; }
.accept-logout { margin-top: var(--space-2); }
footer a { color: var(--ink-muted); }
.tutor-foot p { margin: 0 0 var(--space-1); }
.legal-head .legal-back { margin-left: auto; }
.legal-dialog { width: min(1000px, calc(100vw - 32px)); height: min(86vh, 900px); max-width: none; padding: 0;
  display: none; flex-direction: column; overflow: hidden; }
.legal-dialog[open] { display: flex; }
.legal-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
.legal-dialog-head h2 { margin: 0; }
.legal-dialog-body { overflow: auto; padding: var(--space-3) var(--space-4); flex: 1; }
.legal-dialog .legal { grid-template-columns: 200px 1fr; }
.legal-dialog .legal-index { top: 0; }
.legal-dialog .legal-body section { scroll-margin-top: 0; }
@media (max-width: 760px) { .legal-dialog .legal { grid-template-columns: 1fr; } .legal-dialog-body { padding: var(--space-3); } }
.tutor-foot .tutor-clinic { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.tutor-foot a, .tutor-privacy a { display: inline-flex; align-items: center; min-height: 44px; }
.tutor-privacy { margin: var(--space-2) 0 0; font-size: 14px; }
