/* App shell in the Medixin language: canvas, greeting bar, bottom nav with
   the raised center "+" (Registrar). Loaded last; tokens only. */
.phone {
  background: var(--canvas);
}

.greet-bar.top-app-bar {
  gap: var(--space-3);
  min-height: 72px;
  padding: var(--space-3) var(--space-5);
}

.greet-bar .top-app-bar-actions { gap: var(--space-2); margin-left: auto; }

.greet-bar .top-app-bar-action {
  background: var(--white);
  box-shadow: var(--elevation-1);
}

.top-app-bar-action .icon-svg { width: 22px; height: 22px; }

/* Bottom nav: white sheet with rounded top and a soft upward shadow. */
.bottom-nav {
  border-top: 0;
  border-radius: 24px 24px 0 0;
  background: var(--white);
  box-shadow: var(--elevation-nav);
}

.nav-item .icon-svg { width: 24px; height: 24px; }

.nav-item.is-active .nav-icon {
  position: relative;
}

.nav-item.is-active .nav-icon::after {
  position: absolute;
  bottom: -6px;
  left: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  transform: translateX(-50%);
}

/* Nurse: two tabs either side of the raised "+". */
.phone[data-role="enfermero"] .bottom-nav {
  column-gap: 96px;
  padding: 0 var(--space-4);
}

.fab-register {
  right: auto;
  bottom: calc(var(--nav-height) - 34px);
  left: 50%;
  justify-content: center;
  width: 64px;
  min-width: 64px;
  height: 64px;
  min-height: 64px;
  padding: 0;
  border: 4px solid var(--white);
  border-radius: 50%;
  background: var(--grad-primary);
  box-shadow: var(--elevation-2);
  transform: translateX(-50%);
}

.fab-register:active { transform: translateX(-50%) scale(0.94); }

.fab-register-icon svg {
  width: 28px;
  height: 28px;
  stroke: var(--on-primary);
  stroke-width: 2.2;
}

.fab-register-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Views are flex columns: nothing in them may shrink (chip rows, heroes). */
.view > * { flex-shrink: 0; }

.view { gap: var(--space-4); }

.section-head { margin: var(--space-2) 0 0; }

.section-head .section-label {
  color: var(--ink);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.hero-stack { margin-bottom: 0; padding-bottom: 18px; }
.urgent-section { display: grid; gap: var(--space-3); }
.urgent-section .section-head { margin-top: 0; }

/* The mascot art has a white ground: keep its disc white in both themes. */
.greet-bar .avatar { background: var(--on-primary); box-shadow: var(--elevation-1); }

/* Legacy section labels speak the Medixin header voice everywhere. */
.section-label,
.detail-section-title {
  color: var(--ink);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

/* Names and task titles wrap; they are never cut with an ellipsis. */
.list-title,
.task-title,
.patient-name {
  overflow: visible;
  white-space: normal;
  text-overflow: clip;
}

/* Centered content must never overflow upward under the app bar. */
.empty-state { justify-content: safe center; padding-top: var(--space-6); }
.top-app-bar { z-index: 8; }

/* Snackbar (Medixin-style toast): check badge, message, quiet undo pill and
   a 5 s countdown line. */
.snackbar {
  overflow: hidden;
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-3);
  border-radius: var(--radius-card);
  background: var(--snackbar-fill);
  color: var(--on-snackbar);
  box-shadow: var(--elevation-2);
}

.snackbar .tray-feedback-line { gap: var(--space-3); }

.snack-check {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--patient);
  color: var(--on-primary);
}

.snack-check .icon-svg { width: 18px; height: 18px; stroke-width: 2.2; }

.snackbar .tray-feedback-line > span:not(.snack-check) {
  flex: 1;
  font-size: var(--text-small);
  font-weight: 500;
}

.snackbar .undo-event-btn {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--on-snackbar) 16%, transparent);
  color: var(--on-snackbar);
  font: 600 var(--text-caption) / 1 var(--font-body);
  cursor: pointer;
}

.snackbar .undo-event-btn:active { transform: scale(0.95); }
.snackbar .undo-event-btn:focus-visible { outline: 2px solid var(--on-snackbar); outline-offset: 2px; }

.snack-timer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--sky);
  transform-origin: left center;
  animation: snack-countdown 5s linear forwards;
}

@keyframes snack-countdown {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* Registrar: a logged card answers with a check that pops in. */
.quick-events [data-quick-event] { position: relative; }

.quick-events .is-logged {
  background: var(--primary-container);
  box-shadow: 0 0 0 2px var(--nurse);
}

.logged-mark {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--nurse);
  color: var(--on-primary);
}

.logged-mark .icon-svg { width: 14px; height: 14px; stroke-width: 2.4; }

/* Dictation: visible listening state with live transcript. */
.dictate-button.is-listening {
  background: var(--grad-primary);
  color: var(--on-primary);
}

.dictate-button.is-listening .mic-bubble {
  animation: mic-breathe 1.2s var(--ease-enter) infinite alternate;
}

@keyframes mic-breathe {
  from { transform: scale(1); }
  to { transform: scale(1.12); }
}

.dictate-live {
  display: block;
  overflow: hidden;
  max-width: 100%;
  font-size: var(--text-caption);
  text-overflow: ellipsis;
  text-transform: none;
  white-space: nowrap;
}

.dictate-note {
  margin: 0;
  color: var(--body);
  font-size: var(--text-caption);
  line-height: 1.5;
}

/* Clinical value: readable lines once revealed, a calm masked block before. */
.clinical-value {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: var(--space-4);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--stone);
  color: var(--ink);
  font: 500 var(--text-body) / 1.45 var(--font-body);
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.clinical-line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.clinical-line::before {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--nurse);
  content: "";
}

.phone[data-role="enfermero"] .is-critical-value .clinical-line::before { background: var(--alert); }
.is-critical-value { background: var(--error-container); color: var(--on-error-container); }

@media (prefers-reduced-motion: reduce) {
  .snack-timer, .dictate-button.is-listening .mic-bubble { animation: none; }
}

/* Nav: the two nurse tabs sit symmetric around the centered "+". */
.phone[data-role="enfermero"] .bottom-nav {
  display: grid;
  grid-template-columns: 1fr 96px 1fr;
  column-gap: 0;
}

.phone[data-role="enfermero"] .bottom-nav .nav-item:nth-child(1) { grid-column: 1; }
.phone[data-role="enfermero"] .bottom-nav .nav-item:nth-child(2) { grid-column: 3; }

/* Patient detail: "Registrar evento" docks just above the bottom bar. */
.phone[data-role="enfermero"] .view[data-view-key="nurse-detail"] { padding-bottom: 0; }

.detail-cta {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin: var(--space-2) 0 0;
  padding: var(--space-5) 0 var(--space-4);
  background: linear-gradient(to top, var(--canvas) 70%, color-mix(in srgb, var(--canvas) 0%, transparent));
}

/* Critical patient: red only as an accent. */
.detail-alert {
  border-radius: var(--radius-card);
  background: var(--grad-critical);
  color: var(--on-primary);
  font-weight: 500;
}

.detail-alert .urgent-icon {
  background: var(--alert);
  color: var(--on-primary);
}

.pulse-dot {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--alert);
}

.pulse-dot::after {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--alert);
  content: "";
  animation: pulse-ring 1.6s var(--ease-enter) infinite;
}

@keyframes pulse-ring {
  from { opacity: 0.7; transform: scale(1); }
  to { opacity: 0; transform: scale(2.6); }
}

/* SBAR actions: generate on its own row, then Copiar | Compartir. */
.ai-sheet .ai-actions [data-handover-generate] { grid-column: 1 / -1; }

@media (prefers-reduced-motion: reduce) {
  .pulse-dot::after { animation: none; }
}

@media (prefers-reduced-motion: reduce) {
  .patient-card,
  .list-card,
  .hero-card { animation: none; }
}

/* "Avisar a la familia" sits under the shift list, quieter than the CTA. */
.family-share { margin-top: var(--space-2); }

/* Confirm checks: white at rest, blue once done. */
.task-card .task-action.tap-confirm {
  border: 1.5px solid var(--stone-border);
  background: var(--white);
  color: var(--nurse-text);
  box-shadow: var(--elevation-1);
}

.task-card .task-action.tap-confirm:hover {
  border-color: var(--nurse);
  background: var(--white);
  filter: none;
}

.task-card.is-confirming .task-action.tap-confirm,
.task-card .task-action.tap-confirm.is-done {
  border-color: transparent;
  background: var(--grad-primary);
  color: var(--on-primary);
  box-shadow: var(--elevation-2);
}

/* Revealed clinical value: vital-sign tiles, not a red slab of text. */
.clinical-value {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  padding: 0;
  background: transparent;
}

.clinical-value.is-critical-value { background: transparent; }

.vital-tile {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--stone-border);
  border-radius: var(--radius-sm);
  background: var(--white);
  text-align: left;
}

.vital-tile.is-wide { grid-column: 1 / -1; }

.vital-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: var(--text-caption);
  font-weight: 500;
}

.vital-value {
  color: var(--ink);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.vital-value small {
  color: var(--muted);
  font-size: var(--text-caption);
  font-weight: 500;
  letter-spacing: 0;
}

.vital-tile.is-alert { border-color: color-mix(in srgb, var(--alert) 55%, var(--stone-border)); }
.vital-tile.is-alert .vital-label { color: var(--alert-text); }

/* Mascot art has a white ground: always on a white disc. */
.avatar { background: var(--on-primary); box-shadow: var(--elevation-1); }

/* Contacto: three blue discs on one line, whatever the label length below. */
.contact-icon.is-visit { background: var(--grad-primary); }
.contact-options .contact-option { justify-content: flex-start; }

.phone[data-role="familia"] .nav-item.is-active { color: var(--ink); }

/* Hidden nav items really leave: the chat bubble must not sit over the detail CTA. */
.phone[data-role] .bottom-nav .nav-item[data-nav][hidden] { display: none; }

/* The clinical toggle sits beside its title, always clear of the docked CTA. */
.clinical-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.clinical-head .detail-section-title { margin: 0; }
.clinical-head .reveal-button { flex: 0 0 auto; align-self: center; }

/* One flow of text inside the visit pill, wrapping as a sentence. */
.pill-copy { min-width: 0; text-align: start; }

/* Asking scrolls the answer into view, clear of the bottom nav. */
.ask-answer { scroll-margin-block-end: 120px; }

/* SBAR draft: the bar lives in the pinned header, so it shows at any scroll. */
.ai-sheet .sheet-header { flex-wrap: wrap; }

.draft-progress {
  display: grid;
  flex: 1 0 100%;
  gap: var(--space-1);
}

.draft-progress[hidden] { display: none; }

.draft-progress-copy {
  color: var(--body);
  font-size: var(--text-caption);
  font-weight: 500;
}

.draft-progress-track {
  display: block;
  overflow: hidden;
  height: 6px;
  border-radius: 999px;
  background: var(--primary-container);
}

.draft-progress-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--grad-primary);
  transform: scaleX(0.06);
  transform-origin: left center;
}

.draft-progress.is-running .draft-progress-fill {
  transform: scaleX(0.9);
  transition: transform var(--duration-draft) var(--ease-draft);
}

.draft-progress.is-done .draft-progress-fill {
  transform: scaleX(1);
  transition: transform 240ms var(--ease-enter);
}

.ai-sheet.is-drafting .handover-field .field-box {
  animation: draft-breathe 1.4s var(--ease-exit) infinite alternate;
}

@keyframes draft-breathe {
  from { opacity: 1; }
  to { opacity: 0.5; }
}

.ai-sheet [data-handover-generate]:disabled { cursor: progress; opacity: 0.6; }

/* The error state: the sent check's opposite, a big X the eye cannot miss. */
.error-layer {
  position: absolute;
  z-index: 95;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: var(--veil-canvas);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity var(--duration-enter) var(--ease-enter), visibility 0s linear var(--duration-enter);
}

.error-layer.is-open {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  transition: opacity var(--duration-enter) var(--ease-enter);
}

.error-card {
  display: flex;
  width: 100%;
  max-width: 320px;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-5) var(--space-5);
  border-radius: var(--radius-card);
  background: var(--white);
  box-shadow: var(--elevation-2);
  text-align: center;
  transform: translateY(18px) scale(0.96);
  transition: transform var(--duration-enter) var(--ease-enter);
}

.error-layer.is-open .error-card { transform: none; }

.error-x {
  display: grid;
  place-items: center;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: var(--grad-alert);
  box-shadow: var(--elevation-2);
  color: var(--on-primary);
}

.error-layer.is-open .error-x { animation: error-nudge 420ms var(--ease-enter) 280ms 1; }

.error-x svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 6;
}

.error-x path { stroke-dasharray: 1; stroke-dashoffset: 1; }

.error-layer.is-open .error-x path { animation: error-draw 260ms var(--ease-enter) 120ms forwards; }
.error-layer.is-open .error-x path + path { animation-delay: 240ms; }

@keyframes error-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes error-nudge {
  25% { transform: translateX(-6px); }
  60% { transform: translateX(4px); }
}

.error-card h2 {
  margin: var(--space-2) 0 0;
  color: var(--ink);
  font-size: var(--text-section);
  line-height: 1.25;
  text-wrap: balance;
}

.error-card p {
  margin: 0;
  color: var(--body);
  text-wrap: pretty;
}

.error-actions {
  display: grid;
  width: 100%;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.error-actions .btn { width: 100%; min-height: 56px; }

@media (prefers-reduced-motion: reduce) {
  .draft-progress.is-running .draft-progress-fill { transform: scaleX(0.6); transition: none; }
  .ai-sheet.is-drafting .handover-field .field-box { animation: none; opacity: 0.5; }
  .error-layer, .error-card { transition: none; }
  .error-layer.is-open .error-x { animation: none; }
  .error-layer.is-open .error-x path { animation: none; stroke-dashoffset: 0; }
}

/* The view's top padding left a strip where scrolled content peeked above the bar. */
.top-app-bar { top: calc(var(--space-2) * -1); }

/* The check draws heavier than the 1.5 icon default. The width sits on the path,
   not the svg, because each path carries its own stroke-width attribute. */
.icon-check path { stroke-width: 2.25; }
.success-check .icon-check path { stroke-width: 2.5; }

/* Same rule as the avatars: mascot art has a white ground, so a white disc. */
.celebration-mascot {
  overflow: hidden;
  border-radius: 50%;
  background: var(--on-primary);
}
