/* =====================================================================
   MedX polish v4 "Calm": short functional transitions only, plus the
   clinical-safety components (patient banner, hard stop, critical banner,
   two-identifier check, destructive confirm). No gradients, glows, shimmer
   or decorative motion. Loaded after components.css.
   ===================================================================== */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; translate: 0 6px; } to { opacity: 1; translate: 0 0; } }
@keyframes slide-in-right { from { translate: 100% 0; } to { translate: 0 0; } }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
@keyframes toast-in { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }
@keyframes pulse-ring { 0% { box-shadow: 0 0 0 0 currentColor; } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ---------------- Brand mark ---------------- */
.brand__logo { display: grid; place-items: center; color: #fff; border-radius: 10px; background: var(--brand-mark); }
.brand__name { font-weight: 700; }

/* ---------------- Interactive surfaces: border and shadow only, no lift ---------------- */
.card { transition: border-color var(--t-fast), box-shadow var(--t-fast); }
a.card:hover, a.kpi:hover, .token-card:hover { border-color: var(--c-primary); box-shadow: var(--shadow-md); text-decoration: none; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--c-text-3); }
.input::placeholder, .textarea::placeholder { color: var(--c-text-3); opacity: 1; }
.check input, input[type="radio"] { accent-color: var(--c-primary); }
.switch input::after { transition: transform var(--t-med) var(--ease); }
.pill--critical::before, .pill--live::before { animation: pulse-ring 2s infinite; }

/* ---------------- Skeleton (real loading states) ---------------- */
.skeleton {
  display: block; border-radius: 8px; min-height: 12px;
  background: linear-gradient(100deg, var(--skel-base) 30%, var(--skel-shine) 50%, var(--skel-base) 70%) var(--skel-base);
  background-size: 250% 100%; animation: shimmer 1.3s linear infinite;
}
.skeleton--text { height: 12px; margin: 6px 0; }
.skeleton--title { height: 20px; width: 55%; }
.skeleton--circle { border-radius: 50%; width: 40px; height: 40px; flex: none; }
.skeleton--block { height: 120px; border-radius: var(--r-md); }
[aria-busy="true"] { cursor: progress; }

/* ---------------- Overlays ---------------- */
.modal:target .modal__box, .cmdk:target .cmdk__box { animation: pop-in .18s var(--ease); }
.drawer:target .drawer__panel { animation: slide-in-right .22s var(--ease); }
.modal__box { border: 1px solid var(--c-border); border-radius: var(--r-xl); }

/* ---------------- Tooltip (data-tip="…") ---------------- */
[data-tip] { position: relative; }
[data-tip]::before {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; z-index: 60;
  translate: -50% 0; padding: 6px 10px; border-radius: 8px; white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--c-surface); background: var(--c-text);
  opacity: 0; pointer-events: none; transition: opacity var(--t-fast);
}
[data-tip]:hover::before, [data-tip]:focus-visible::before { opacity: 1; }

/* ---------------- Toast ---------------- */
.toast {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; min-width: 280px; max-width: 400px;
  border-radius: var(--r-md); background: var(--c-surface); border: 1px solid var(--c-border);
  box-shadow: var(--shadow-lg); font-size: 15px; animation: toast-in .2s var(--ease) both;
}
.toast__icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; color: var(--c-surface); background: var(--c-success); flex: none; }
.toast--danger .toast__icon { background: var(--c-danger); }
.toast-stack { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 250; }

/* ---------------- Live indicator ---------------- */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c-success); color: var(--c-success); flex: none; }

/* ---------------- Accessibility & print ---------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
@media print {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------------- Clinical safety ---------------- */
/* Patient banner: persistent identity + allergy on every clinical screen (sticky under the topbar) */
.patient-banner {
  position: sticky; top: calc(var(--topbar-h) + 8px); z-index: 15;
  display: flex; align-items: center; gap: 12px 18px; flex-wrap: nowrap; min-width: 0;
  padding: 12px 16px 12px 20px; border-radius: var(--r-lg);
  background: var(--c-surface); border: 1px solid var(--c-border); box-shadow: var(--shadow-md);
}
.patient-banner::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 4px; border-radius: 0 4px 4px 0; background: var(--blue-400); }
.patient-banner > .avatar { width: 44px; height: 44px; font-size: 15px; }
.pb__id { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.pb__name { font-weight: 700; font-size: 19px; color: var(--c-text); white-space: nowrap; }
.pb__name:hover { color: var(--c-link); }
.pb__meta { display: flex; gap: 10px; font-size: 14px; color: var(--c-text-2); white-space: nowrap; }
.pb__meta > span + span::before { content: "·"; margin-right: 10px; color: var(--c-text-3); }
.pb__chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }
.pb-allergy {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: var(--r-full);
  font-size: 14px; font-weight: 700; white-space: nowrap;
  background: var(--st-crit); color: var(--c-on-danger);
}
.pb-allergy--none { background: var(--st-ok-bg); color: var(--st-ok); font-weight: 650; }
.pb-allergy--sm { height: 24px; padding: 0 9px; font-size: 13px; }
.pb-chip { display: inline-flex; align-items: center; height: 28px; padding: 0 11px; border-radius: var(--r-full); font-size: 13.5px; font-weight: 650; white-space: nowrap; background: var(--c-surface-3); color: var(--c-text-2); }
.pb-chip--warn { background: var(--st-warn-bg); color: var(--st-warn); }
.pb-chip--crit { background: var(--st-crit-bg); color: var(--st-crit); }
.pb-chip--info { background: var(--st-info-bg); color: var(--st-info); }
.pb-chip--payer { background: var(--st-pending-bg); color: var(--st-pending); }
.pb-enc { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; font-weight: 600; color: var(--c-text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-enc .live-dot { flex: none; }
.pb-enc__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.patient-banner > .avatar, .pb__id, .pb__chips, .pb__switch { flex-shrink: 0; }
.pb-allergy__short { display: none; }
@media (max-width: 1320px) and (min-width: 1025px) { .patient-banner { flex-wrap: wrap; } .pb-enc { flex: 1 1 200px; justify-content: flex-end; } }
.pb__switch { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 650; color: var(--c-link); white-space: nowrap; padding: 6px 10px; border-radius: var(--r-full); }
.pb__switch:hover { background: var(--c-surface-3); text-decoration: none; }
@media (max-width: 1024px) {
  .patient-banner { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 10px; padding: 10px 14px 10px 18px; top: calc(var(--topbar-h) + 4px); }
  .patient-banner::-webkit-scrollbar { display: none; }
  .pb__chips { flex-wrap: nowrap; }
  .pb-enc { margin-left: 0; flex-shrink: 0; overflow: visible; }
  .patient-banner > .avatar { width: 36px; height: 36px; }
  .pb__name { font-size: 17px; }
  .pb__meta > span:last-child { display: none; }
}
@media (max-width: 600px) {
  .pb-allergy__lbl { display: none; }
  .pb-allergy__short { display: inline; }
  .pb-allergy:not(.pb-allergy--none) { padding: 0 10px; }
}

/* Hard-stop dialog (allergy conflict) + shared danger header */
.modal--hardstop { background: color-mix(in srgb, var(--st-crit) 18%, rgba(15, 29, 36, .6)); }
.modal--hardstop .modal__box { border: 2px solid var(--st-crit); }
.hardstop__head { display: flex; align-items: center; gap: 14px; padding: 18px 22px; color: var(--c-on-danger); background: var(--st-crit); border-radius: calc(var(--r-xl) - 2px) calc(var(--r-xl) - 2px) 0 0; }
.hardstop__head h3 { color: var(--c-on-danger); font-size: 19px; }
.hardstop__head--soft { color: var(--c-text); background: var(--st-crit-bg); border-bottom: 1px solid color-mix(in srgb, var(--st-crit) 25%, var(--c-border)); }
.hardstop__head--soft h3 { color: var(--c-text); font-size: 18px; }
.hardstop__icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 12px; background: rgba(255, 255, 255, .18); }
.hardstop__head--soft .hardstop__icon { background: var(--st-crit); color: var(--c-on-danger); }
.hardstop__kicker { font-size: 13px; font-weight: 700; opacity: .95; }
.hardstop__head--soft .hardstop__kicker { color: var(--st-crit); opacity: 1; }
.hardstop__lead { font-size: 16px; color: var(--c-text); }
.hardstop__fact { padding: 14px 16px; border-radius: var(--r-md); background: var(--c-surface-2); border: 1px solid var(--c-border); }
.hardstop__label { font-size: 13.5px; font-weight: 700; color: var(--c-text-2); margin-bottom: 6px; }
.hardstop__list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 15px; color: var(--c-text-2); list-style: disc; }
.hardstop__override { padding: 14px 16px; border-radius: var(--r-md); border: 1px dashed color-mix(in srgb, var(--st-crit) 45%, var(--c-border-strong)); }
.alt-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.alt-chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: var(--r-full); font-size: 14px; font-weight: 650; color: var(--st-ok); background: var(--st-ok-bg); border: 1px solid color-mix(in srgb, var(--st-ok) 30%, transparent); }
.alt-chip span { font-weight: 500; font-size: 13px; }
.alt-chip:hover { text-decoration: none; border-color: var(--st-ok); }

/* Medicine search suggestions with allergy flag */
.rx-search { position: relative; display: flex; flex-direction: column; gap: 6px; }
.rx-suggest { border: 1px solid var(--c-border); border-radius: var(--r-md); background: var(--c-surface); box-shadow: var(--shadow-md); padding: 4px; }
.rx-suggest__item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--c-text); font-size: 15px; }
.rx-suggest__item:hover { background: var(--c-surface-3); text-decoration: none; }
.rx-suggest__item--conflict { background: color-mix(in srgb, var(--st-crit-bg) 60%, transparent); }
.rx-suggest__hint { padding: 6px 12px 4px; font-size: 13px; color: var(--c-text-3); }

/* Critical-value banner: persistent, no dismiss; only logging the call clears it */
.crit-banner {
  position: relative; display: flex; align-items: center; gap: 14px 18px; flex-wrap: wrap;
  padding: 16px 18px 16px 22px; border-radius: var(--r-lg); overflow: hidden;
  background: var(--st-crit-bg);
  border: 1px solid color-mix(in srgb, var(--st-crit) 40%, var(--c-border));
}
.crit-banner::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--st-crit); }
.crit-banner__icon { width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 12px; background: var(--st-crit); color: var(--c-on-danger); }
.crit-banner__text { flex: 1 1 320px; min-width: 0; }
.crit-banner__title { font-weight: 700; font-size: 16px; color: var(--c-text); }
.crit-banner__sub { font-size: 14px; color: var(--c-text-2); margin-top: 2px; }
.crit-timer { flex: 0 1 220px; min-width: 180px; }
.crit-timer__label { font-size: 13px; font-weight: 700; color: var(--st-crit); }
.crit-timer__bar { height: 6px; margin: 5px 0 4px; border-radius: 99px; background: color-mix(in srgb, var(--st-crit) 18%, transparent); overflow: hidden; }
.crit-timer__bar span { display: block; height: 100%; border-radius: inherit; background: var(--st-crit); }
.crit-timer__time { font-size: 13.5px; color: var(--c-text-2); }
.readback { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); background: var(--st-warn-bg); color: var(--c-text); font-size: 15px; cursor: pointer; }
.readback input { margin-top: 4px; accent-color: var(--st-crit); width: 18px; height: 18px; }
.readback:has(input:checked) { background: var(--st-ok-bg); }

/* Two-identifier check (pure CSS gate on the print buttons) */
.id-check { margin-top: 14px; padding: 14px 16px; border-radius: var(--r-md); border: 1px solid var(--c-border); background: var(--c-surface-2); display: flex; flex-direction: column; gap: 8px; }
.id-check__head { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.id-check__icon { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 10px; background: var(--st-info-bg); color: var(--st-info); }
.id-check__item { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--c-surface); border: 1px solid var(--c-border); font-size: 15px; cursor: pointer; transition: border-color var(--t-fast), background var(--t-fast); }
.id-check__item input { width: 18px; height: 18px; accent-color: var(--st-ok); flex: none; }
.id-check__item:has(input:checked) { border-color: color-mix(in srgb, var(--st-ok) 45%, var(--c-border)); background: color-mix(in srgb, var(--st-ok-bg) 60%, var(--c-surface)); }
.id-check__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.id-check__status { font-size: 14px; font-weight: 650; color: var(--c-text-3); }
.when-ready { display: none; align-items: center; gap: 5px; color: var(--st-ok); }
.id-check:not(:has(input:not(:checked))) .when-ready { display: inline-flex; }
.id-check:not(:has(input:not(:checked))) .when-pending { display: none; }
.id-check:not(:has(input:not(:checked))) { border-color: color-mix(in srgb, var(--st-ok) 40%, var(--c-border)); }
body:has(.id-check input:not(:checked)) .needs-id-check,
.danger-confirm:has(:invalid) .needs-confirm { opacity: .42; pointer-events: none; filter: saturate(.4); box-shadow: none; }

/* Destructive confirm: consequences list + type-to-confirm */
.consequences { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.consequences li { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; color: var(--c-text-2); }
.consequences .icon { color: var(--st-crit); margin-top: 3px; flex: none; }
.confirm-type input:valid { border-color: var(--st-ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--st-ok) 20%, transparent); }
@media (max-width: 600px) { .crit-banner { align-items: flex-start; } .crit-banner__icon { width: 36px; height: 36px; } .crit-banner__text { flex-basis: calc(100% - 54px); } .crit-timer { flex: 1 1 100%; } }
