/* MiFarmaciaData Design System 2.1 — base, shell and components. */

/* ================================================================ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + 12px); }
body {
  margin: 0; min-height: 100vh; font-family: var(--font); font-size: var(--fs-md); line-height: var(--lh);
  color: var(--text); background-color: var(--bg); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  transition: background-color var(--d-3) var(--ease), color var(--d-3) var(--ease);
}
/* MiConsultorio "ambiente": a faint wash in the page background only. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60rem 32rem at 12% -8%, var(--wash-1), transparent 70%),
    radial-gradient(48rem 30rem at 100% 0%, var(--wash-2), transparent 70%);
}
img, svg { display: block; max-width: 100%; }
a { color: var(--link); text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:hover { color: var(--link-hover); }
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-title); color: var(--text); font-weight: var(--fw-semi); letter-spacing: -.005em; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 var(--s-3); }
p:last-child { margin-bottom: 0; }
code, .mono { font-family: var(--mono); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--s-4) 0; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--primary-soft-2); }
.icon { width: var(--icon); height: var(--icon); flex: none; fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 22px; height: 22px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; left: var(--s-4); top: -80px; z-index: 200; background: var(--primary); color: var(--on-primary);
  padding: var(--s-2) var(--s-4); border-radius: var(--r-md); font-weight: var(--fw-medium); }
.skip-link:focus { top: var(--s-3); color: var(--on-primary); }
[hidden] { display: none !important; }
.muted { color: var(--text-3); }
.small { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.wrap-any { overflow-wrap: anywhere; word-break: normal; }
.row { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; }
.stack > * + * { margin-top: var(--s-3); }
.spacer { flex: 1; }
.mt-2 { margin-top: var(--s-2); } .mt-4 { margin-top: var(--s-4); } .mb-4 { margin-bottom: var(--s-4); }

/* Section label with dot — MiConsultorio "● AGENDA" pattern. */
.eyebrow { display: flex; align-items: center; gap: 8px; font-size: var(--fs-2xs); font-weight: var(--fw-semi);
  letter-spacing: var(--tracking-label); text-transform: uppercase; color: var(--text-3); margin: 0 0 var(--s-2); }
.eyebrow::before { content: ""; width: 7px; height: 7px; border-radius: 2px; background: var(--primary); }

/* ================================================================ shell */
.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh;
  transition: grid-template-columns var(--d-3) var(--ease); }
.app[data-rail="open"] { grid-template-columns: var(--rail-w-open) minmax(0, 1fr); }

/* Rail: MiConsultorio's floating blue navigation, adapted to the left and expandable. */
.rail { position: sticky; top: 0; height: 100vh; padding: 12px 0 12px 12px; z-index: var(--z-rail); }
.rail__inner { height: 100%; display: flex; flex-direction: column; gap: 4px; background: var(--rail-bg); color: var(--rail-icon);
  border-radius: var(--r-xl); padding: 10px; box-shadow: var(--shadow-float); }
:root[data-theme="dark"] .rail__inner { border: 1px solid var(--line); }
.rail__nav { display: flex; flex-direction: column; gap: 4px; min-height: 0; overflow: hidden auto; scrollbar-width: none; margin: 0 -4px; padding: 0 4px; }
.rail__brand { display: flex; align-items: center; gap: 10px; height: 44px; padding: 0 5px; margin-bottom: 6px; border-radius: var(--r-md);
  color: inherit; text-decoration: none; flex: none; }
.rail__brand img { width: 36px; height: 36px; flex: none; background: #fff; border-radius: 10px; padding: 4px; }
.rail__brand span { font-weight: var(--fw-semi); color: #fff; white-space: nowrap; font-size: var(--fs-md); line-height: 1.1; }
.rail__brand small { display: block; font-weight: var(--fw-regular); font-size: 11px; opacity: .8; }
:root[data-theme="dark"] .rail__brand span { color: var(--text); }
.rail__sep { height: 1px; background: var(--rail-sep); margin: 6px 4px; flex: none; }
.rail__group-label { font-size: 11px; letter-spacing: var(--tracking-label); text-transform: uppercase; opacity: .78;
  padding: 6px 12px 2px; white-space: nowrap; }
.rail__link { position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--r-md);
  color: var(--rail-icon); text-decoration: none; font-weight: var(--fw-medium); font-size: var(--fs-sm); white-space: nowrap; flex: none;
  transition: background-color var(--d-1) var(--ease), color var(--d-1) var(--ease), transform var(--d-1) var(--ease); }
.rail__link .icon { width: 22px; height: 22px; }
.rail__link:hover { background: var(--rail-hover); color: #fff; }
:root[data-theme="dark"] .rail__link:hover { color: var(--text); }
.rail__link:active { transform: scale(.97); }
.rail__link[aria-current="page"] { background: var(--rail-active-bg); color: var(--rail-active-icon); box-shadow: var(--shadow-sm); }
.rail__link:focus-visible { outline-color: #fff; outline-offset: -3px; }
:root[data-theme="dark"] .rail__link:focus-visible { outline-color: var(--focus); }
.rail__count { margin-left: auto; min-width: 22px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); display: inline-grid; place-items: center;
  background: rgba(255, 255, 255, .24); color: #fff; font-size: 11px; font-weight: var(--fw-bold); }
.rail__link[aria-current="page"] .rail__count { background: var(--primary); color: var(--on-primary); }
:root[data-theme="dark"] .rail__count { background: var(--surface-3); color: var(--text); }
.rail__foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding-top: 6px; }
button.rail__link { border: 0; background: none; cursor: pointer; width: 100%; text-align: left; font: inherit; font-weight: var(--fw-medium); font-size: var(--fs-sm); }
/* Collapsed rail: icons only; labels shown as tooltips. */
@media (min-width: 1024px) {
  /* Collapsed: labels hidden visually but kept as the accessible name (never display:none). */
  .app:not([data-rail="open"]) .rail__label, .app:not([data-rail="open"]) .rail__brand span {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .app:not([data-rail="open"]) .rail__group-label { display: none; }
  .app:not([data-rail="open"]) .rail__link { justify-content: center; padding: 0; }
  .app:not([data-rail="open"]) .rail__count { position: absolute; top: 2px; right: 2px; margin: 0; min-width: 18px; height: 18px; padding: 0 4px; }
  .app:not([data-rail="open"]) .rail__brand { justify-content: center; padding: 0; }
  .app:not([data-rail="open"]) .rail__nav { overflow: visible; }
  .rail__tip { position: absolute; left: calc(100% + 14px); top: 50%; transform: translate(-4px, -50%); opacity: 0; pointer-events: none;
    background: #0f172a; color: #f8fafc; font-size: var(--fs-xs); padding: 6px 10px; border-radius: 6px; white-space: nowrap;
    transition: opacity var(--d-1) var(--ease), transform var(--d-1) var(--ease); z-index: var(--z-tooltip); box-shadow: var(--shadow-float); }
  .app[data-rail="open"] .rail__tip { display: none; }
  .rail__link:hover .rail__tip, .rail__link:focus-visible .rail__tip { opacity: 1; transform: translate(0, -50%); }
  .rail__toggle .icon { transition: transform var(--d-3) var(--ease); }
  .app[data-rail="open"] .rail__toggle .icon { transform: rotate(180deg); }
}

.app-main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: var(--z-topbar); height: var(--topbar-h); display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--gutter); background: color-mix(in srgb, var(--bg) 84%, transparent); backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid transparent;
  transition: border-color var(--d-2) var(--ease), box-shadow var(--d-2) var(--ease); }
.topbar.is-scrolled { border-bottom-color: var(--line); box-shadow: var(--shadow-xs); }
.topbar__menu { display: none; }
/* Breadcrumb pill (MiConsultorio context chip) */
.crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 4px 6px 4px 4px; box-shadow: var(--shadow-xs); font-size: var(--fs-sm); }
.crumbs a, .crumbs span { padding: 4px 10px; border-radius: var(--r-pill); color: var(--text-2); text-decoration: none; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 32ch; }
.crumbs a:hover { background: var(--surface-2); color: var(--text); }
.crumbs [aria-current="page"] { color: var(--text); font-weight: var(--fw-medium); }
.crumbs .sep { color: var(--text-disabled); padding: 0; }
.crumbs__home { display: inline-flex !important; align-items: center; gap: 8px; }
.crumbs__home img { height: 22px; width: auto; }
.topbar__tools { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }

.user-menu { position: relative; }
.user-menu > summary { list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 12px 4px 4px; min-height: 42px;
  border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-xs);
  transition: border-color var(--d-1) var(--ease); }
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover { border-color: var(--line-strong); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: var(--fw-semi); font-size: var(--fs-xs);
  background: var(--primary-soft); color: var(--primary-ink); flex: none; }
.user-menu__name { display: flex; flex-direction: column; line-height: 1.15; font-size: var(--fs-sm); font-weight: var(--fw-medium); max-width: 22ch; }
.user-menu__name > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu__name small { color: var(--text-3); font-size: 11px; font-weight: var(--fw-regular); }

/* Floating menu (dropdowns) */
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 250px; background: var(--surface-raised); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-float); padding: 6px; z-index: var(--z-menu);
  transform-origin: top right; animation: pop-in var(--d-2) var(--ease-out); }
.menu a, .menu button { display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px 12px; border: 0; background: none;
  color: var(--text); font-size: var(--fs-sm); text-decoration: none; border-radius: var(--r-sm); cursor: pointer; text-align: left; }
.menu a:hover, .menu button:hover { background: var(--surface-2); color: var(--text); }
.menu hr { margin: 6px 0; }
.menu__head { padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu__head b { display: block; font-weight: var(--fw-semi); overflow-wrap: anywhere; }
.menu__head span { color: var(--text-3); font-size: var(--fs-xs); }

.page { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--s-3) var(--gutter) var(--s-8); }
.page--reading { max-width: var(--reading-max); }
.page-head { display: flex; align-items: flex-end; gap: var(--s-3) var(--s-4); flex-wrap: wrap; margin-bottom: var(--s-5); }
.page-head > div:first-child { min-width: min(100%, 22rem); flex: 1 1 22rem; }
.page-head h1 { overflow-wrap: anywhere; }
.page-head p { margin: 6px 0 0; color: var(--text-2); max-width: 72ch; font-size: var(--fs-sm); }
.page-head__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }
.app-footer { color: var(--text-3); font-size: var(--fs-xs); }
.app-footer__inner { max-width: var(--content-max); margin: 0 auto; padding: var(--s-4) var(--gutter); display: flex; gap: var(--s-2) var(--s-4); flex-wrap: wrap;
  border-top: 1px solid var(--line); }
.app-footer a { color: inherit; }

/* Tablet/mobile: the rail becomes a drawer. */
.scrim { position: fixed; inset: 0; background: rgba(8, 15, 30, .42); z-index: calc(var(--z-drawer) - 1); opacity: 0; pointer-events: none;
  transition: opacity var(--d-3) var(--ease); }
.scrim.is-visible { opacity: 1; pointer-events: auto; }
@media (max-width: 1023.98px) {
  .app, .app[data-rail="open"] { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; left: 0; top: 0; bottom: 0; height: 100dvh; width: min(300px, 86vw); padding: 10px; z-index: var(--z-drawer);
    transform: translateX(-105%); transition: transform var(--d-3) var(--ease), visibility 0s linear var(--d-3); visibility: hidden; }
  .rail.is-open { transform: none; visibility: visible; transition: transform var(--d-3) var(--ease), visibility 0s; }
  .rail__tip, .rail__toggle { display: none !important; }
  .topbar__menu { display: inline-grid; }
  .user-menu__name { display: none; }
  .user-menu > summary { padding: 4px; }
}
@media (max-width: 599.98px) {
  :root { --topbar-h: 56px; }
  .crumbs > :not(.crumbs__home) { display: none; }
  .crumbs { padding: 3px 10px 3px 3px; }
}

/* ================================================================ buttons */
.btn { --btn-h: var(--control-h); display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--btn-h); min-width: var(--btn-h);
  padding: 0 18px; border-radius: var(--r-pill); border: 1px solid var(--control-border); background: var(--surface); color: var(--text);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); line-height: 1; cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none;
  transition: background-color var(--d-1) var(--ease), border-color var(--d-1) var(--ease), color var(--d-1) var(--ease),
    box-shadow var(--d-1) var(--ease), transform var(--d-1) var(--ease); }
.btn:hover { background: var(--surface-2); border-color: var(--control-border-hover); color: var(--text); }
.btn:active { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-primary); }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); }
.btn--primary:active { background: var(--primary-press); }
.btn--soft { background: var(--primary-soft); border-color: transparent; color: var(--primary-ink); }
.btn--soft:hover { background: var(--primary-soft-2); border-color: transparent; color: var(--primary-ink); }
.btn--danger { color: var(--danger); border-color: var(--danger-line); background: var(--surface); }
.btn--danger:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.btn--danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn--danger-solid { color: #1a0d0b; }
.btn--ghost { border-color: transparent; background: transparent; }
.btn--ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn--sm { --btn-h: var(--control-h-sm); padding: 0 14px; font-size: var(--fs-xs); }
.btn--lg { --btn-h: var(--control-h-lg); padding: 0 24px; font-size: var(--fs-md); }
.btn--icon { padding: 0; width: var(--btn-h); }
.btn--block { width: 100%; }
.btn .spinner { width: 15px; height: 15px; }
.btn[aria-busy="true"] { pointer-events: none; }
.icon-btn { --btn-h: 36px; display: inline-grid; place-items: center; width: var(--btn-h); height: var(--btn-h); border-radius: var(--r-md); flex: none;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
  transition: background-color var(--d-1) var(--ease), color var(--d-1) var(--ease), transform var(--d-1) var(--ease); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(.9); }
.icon-btn[aria-pressed="true"] { color: var(--primary-ink); background: var(--primary-soft); }
.icon-btn:disabled { opacity: .45; cursor: not-allowed; }
@media (pointer: coarse) { .icon-btn { --btn-h: 44px; } }
.fav-btn[aria-pressed="true"] { color: #b7791f; background: transparent; }
:root[data-theme="dark"] .fav-btn[aria-pressed="true"] { color: #f2c46d; }
.fav-btn[aria-pressed="true"] .icon { fill: currentColor; animation: star-pop var(--d-3) var(--ease-spring); }
.link-btn { border: 0; background: none; padding: 0; color: var(--primary-ink); cursor: pointer; font-size: inherit;
  text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
:root[data-theme="dark"] .link-btn { color: var(--primary); }

/* ================================================================ forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: var(--fw-medium); font-size: var(--fs-sm); color: var(--text); }
.hint { font-size: var(--fs-xs); color: var(--text-3); }
.field-error { color: var(--danger); font-size: var(--fs-xs); }
.input, .select, textarea.input { width: 100%; height: var(--control-h); padding: 0 14px; border: 1px solid var(--control-border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); font-size: var(--fs-sm);
  transition: border-color var(--d-1) var(--ease), box-shadow var(--d-1) var(--ease), background-color var(--d-1) var(--ease); }
textarea.input { height: auto; min-height: 96px; padding: 10px 14px; resize: vertical; line-height: var(--lh); }
.input::placeholder { color: var(--text-3); opacity: 1; }
.input:hover, .select:hover { border-color: var(--control-border-hover); }
.input:focus, .select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled { background: var(--surface-2); color: var(--text-disabled); }
.input--sm, .select--sm { height: var(--control-h-sm); font-size: var(--fs-xs); }
.select { padding-right: 36px; appearance: none; cursor: pointer; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; }
:root[data-theme="dark"] .select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cfcadc' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); }
@media (pointer: coarse) { .input, .select { font-size: var(--fs-lg); } }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: var(--fs-sm); line-height: 1.35; min-width: 0; }
.check input, input.cb { appearance: none; width: 18px; height: 18px; margin: 1px 0 0; flex: none; border: 1.5px solid var(--control-border); border-radius: 5px;
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
  transition: background-color var(--d-1) var(--ease), border-color var(--d-1) var(--ease); }
.check input::after, input.cb::after { content: ""; width: 10px; height: 6px; border: 2px solid var(--on-primary); border-top: 0; border-right: 0;
  transform: rotate(-45deg) scale(0); margin-top: -2px; transition: transform var(--d-1) var(--ease-spring); }
.check input:checked, input.cb:checked { background: var(--primary); border-color: var(--primary); }
.check input:checked::after, input.cb:checked::after { transform: rotate(-45deg) scale(1); }
.check input:hover, input.cb:hover { border-color: var(--control-border-hover); }
.check input:disabled, input.cb:disabled { opacity: .45; cursor: not-allowed; }
@media (pointer: coarse) { .check input, input.cb { width: 22px; height: 22px; } }
.form-grid { display: grid; gap: var(--s-4); }
.form-actions { display: flex; gap: var(--s-2); justify-content: flex-end; flex-wrap: wrap; }
.password-field { position: relative; }
.password-field .input { padding-right: 52px; }
.password-field .icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.password-field .icon-btn:active { transform: translateY(-50%) scale(.92); }

/* Segmented control */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: var(--fw-medium);
  color: var(--text-2); cursor: pointer; transition: background-color var(--d-1) var(--ease), color var(--d-1) var(--ease); min-height: 32px; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* ================================================================ search box + combobox */
.searchbox { position: relative; display: flex; align-items: center; z-index: 30; min-width: 0; }
.searchbox > .icon { position: absolute; left: 16px; color: var(--text-3); pointer-events: none; }
.searchbox .input { height: var(--control-h-lg); padding-left: 46px; padding-right: 92px; border-radius: var(--r-lg); font-size: var(--fs-md);
  box-shadow: var(--shadow-xs); text-overflow: ellipsis; }
.searchbox .input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.searchbox__actions { position: absolute; right: 6px; display: flex; align-items: center; gap: 4px; }
.kbd { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 6px; font-family: var(--mono); font-size: 11px; color: var(--text-3); background: var(--surface); }
@media (pointer: coarse) { .searchbox .kbd { display: none; } }
.listbox { position: absolute; left: 0; right: 0; top: calc(100% + 6px); background: var(--surface-raised); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-float); max-height: min(60vh, 440px); overflow: auto; padding: 6px; margin: 0; list-style: none;
  z-index: var(--z-menu); transform-origin: top center; animation: drop-in var(--d-2) var(--ease-out); overscroll-behavior: contain; }
.listbox__group { padding: 8px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-3);
  font-weight: var(--fw-semi); }
.listbox [role="option"] { display: flex; gap: 12px; align-items: baseline; padding: 9px 10px; border-radius: var(--r-sm); cursor: pointer; font-size: var(--fs-sm); }
.listbox [role="option"] .opt-text { min-width: 0; overflow-wrap: anywhere; }
.listbox [role="option"] .count { margin-left: auto; color: var(--text-3); font-size: var(--fs-2xs); white-space: nowrap; }
.listbox [role="option"][aria-selected="true"], .listbox [role="option"]:hover { background: var(--primary-soft); }
.listbox__foot { border-top: 1px solid var(--line); margin-top: 6px; padding: 8px 10px 4px; font-size: 11px; color: var(--text-3); display: flex; gap: 12px; flex-wrap: wrap; }
mark { background: var(--mark); color: inherit; padding: 0 1px; border-radius: 3px; }

/* ================================================================ badges, tags, chips */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-2xs); font-weight: var(--fw-semi); padding: 1px 9px 1px 8px;
  border-radius: var(--r-pill); border: 1px solid; white-space: nowrap; line-height: 20px; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.badge--success { color: var(--success); background: var(--success-soft); border-color: var(--success-line); }
.badge--warning { color: var(--warning); background: var(--warning-soft); border-color: var(--warning-line); }
.badge--danger { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-line); }
.badge--neutral { color: var(--neutral); background: var(--neutral-soft); border-color: var(--neutral-line); }
.badge--info { color: var(--info); background: var(--info-soft); border-color: var(--info-line); }
.badge--warning::before { background: linear-gradient(90deg, currentColor 50%, transparent 50%); border: 1.5px solid currentColor; width: 9px; height: 9px; }
.badge--neutral::before { background: transparent; border: 1.5px solid currentColor; width: 9px; height: 9px; }
.badge--danger::before { border-radius: 1px; transform: rotate(45deg); }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-2xs); padding: 1px 8px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2); line-height: 20px; max-width: 100%; overflow-wrap: anywhere; }
.tag--atc { font-family: var(--mono); font-size: 11.5px; letter-spacing: .02em; border-radius: 6px; background: var(--info-soft); border-color: var(--info-line); color: var(--info); white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; min-height: 30px; padding: 2px 4px 2px 12px; border-radius: var(--r-pill); max-width: 100%;
  background: var(--primary-soft); color: var(--primary-ink); font-size: var(--fs-xs); font-weight: var(--fw-medium);
  animation: chip-in var(--d-2) var(--ease-out); }
:root[data-theme="dark"] .chip { color: var(--text); }
.chip b { font-weight: var(--fw-regular); white-space: nowrap; }
.chip span { overflow-wrap: anywhere; }
.chip button { width: 26px; height: 26px; border-radius: 50%; border: 0; background: transparent; color: inherit; display: grid; place-items: center; cursor: pointer; flex: none; }
.chip button:hover { background: var(--primary-soft-2); }
@media (pointer: coarse) { .chip button { width: 34px; height: 34px; } }

/* ================================================================ panels, alerts, toasts */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-xs); min-width: 0; }
.panel--accent { position: relative; overflow: hidden; }
.panel--accent::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: linear-gradient(90deg, var(--primary), var(--accent-teal)); }
.panel__head { display: flex; align-items: center; gap: var(--s-2) var(--s-3); padding: var(--s-3) var(--s-5); border-bottom: 1px solid var(--line); min-height: 52px; flex-wrap: wrap; }
.panel__head h2 { font-size: var(--fs-lg); }
.panel__body { padding: var(--s-4) var(--s-5); }
@media (max-width: 599.98px) { .panel__head, .panel__body { padding-left: var(--s-4); padding-right: var(--s-4); } }
.section-title { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: var(--tracking-label); color: var(--text-3);
  font-weight: var(--fw-semi); margin: 0 0 var(--s-2); }
.alert { display: flex; gap: 12px; padding: 12px 16px; border-radius: var(--r-md); border: 1px solid; font-size: var(--fs-sm); align-items: flex-start; }
.alert > .icon { margin-top: 1px; }
.alert--info { background: var(--info-soft); border-color: var(--info-line); } .alert--info > .icon { color: var(--info); }
.alert--warning { background: var(--warning-soft); border-color: var(--warning-line); } .alert--warning > .icon { color: var(--warning); }
.alert--danger { background: var(--danger-soft); border-color: var(--danger-line); } .alert--danger > .icon { color: var(--danger); }
.alert--success { background: var(--success-soft); border-color: var(--success-line); } .alert--success > .icon { color: var(--success); }
.flash { margin-bottom: var(--s-4); animation: drop-in var(--d-3) var(--ease-out); }
.toasts { position: fixed; right: var(--s-4); bottom: var(--s-4); z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px;
  max-width: min(420px, calc(100vw - 32px)); }
body.has-tray .toasts { bottom: 96px; }
.toast { display: flex; gap: 12px; align-items: center; padding: 12px 12px 12px 16px; border-radius: var(--r-lg); background: #0f172a; color: #f8fafc;
  box-shadow: var(--shadow-float); font-size: var(--fs-sm); animation: toast-in var(--d-3) var(--ease-out); }
:root[data-theme="dark"] .toast { background: #f7f3f7; color: #141414; }
.toast.is-leaving { animation: toast-out var(--d-2) var(--ease-in) forwards; }
.toast--error { background: #b42318; color: #fff; }
:root[data-theme="dark"] .toast--error { background: #ff9c92; color: #1a0d0b; }
.toast .btn { --btn-h: 30px; margin-left: auto; color: inherit; border-color: currentColor; background: transparent; padding: 0 12px; box-shadow: none; }
.toast .btn:hover { background: rgba(127, 127, 127, .18); color: inherit; }

/* ================================================================ states */
.empty { padding: var(--s-7) var(--s-6); max-width: 680px; }
.empty__icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-ink); margin-bottom: var(--s-3); }
.empty h2 { margin-bottom: var(--s-2); font-size: var(--fs-xl); overflow-wrap: anywhere; }
.empty ul { margin: var(--s-2) 0 var(--s-4); padding-left: 20px; color: var(--text-2); font-size: var(--fs-sm); }
.progress { position: relative; height: 2px; overflow: hidden; }
.progress[data-active="true"]::after { content: ""; position: absolute; inset: 0; width: 30%; background: var(--primary); border-radius: 2px;
  animation: progress 900ms var(--ease) infinite; }
.spinner { display: inline-block; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.skeleton { display: block; border-radius: 6px; height: 12px; background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 40%, var(--surface-2) 80%);
  background-size: 300% 100%; animation: shimmer 1.3s linear infinite; }

/* ================================================================ tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.table th { text-align: left; font-size: 11px; font-weight: var(--fw-semi); text-transform: uppercase; letter-spacing: var(--tracking-label);
  color: var(--text-3); background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr { transition: background-color var(--d-1) var(--ease); }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .col-actions { width: 1%; white-space: nowrap; }
.cell-title { font-weight: var(--fw-semi); color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
a.cell-title:hover { color: var(--primary-ink); text-decoration: underline; }
button.cell-title { border: 0; background: none; padding: 0; cursor: pointer; text-align: left; font-size: inherit; }
.cell-sub { display: block; color: var(--text-3); font-size: var(--fs-xs); margin-top: 2px; overflow-wrap: anywhere; }
.dash { color: var(--text-3); }
@media (max-width: 719.98px) {
  .table--stack thead { display: none; }
  .table--stack, .table--stack tbody, .table--stack tr, .table--stack td { display: block; width: 100%; }
  .table--stack tr { border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .table--stack td { border: 0; padding: 3px 0; }
  .table--stack td[data-label]::before { content: attr(data-label); display: block; color: var(--text-3); font-size: 11px;
    text-transform: uppercase; letter-spacing: var(--tracking-label); font-weight: var(--fw-semi); }
  .table--stack td.col-actions { padding-top: 10px; width: 100%; }
  .table--stack td.col-actions .row { flex-wrap: wrap; }
}

/* ================================================================ tabs, pagination, disclosure */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: var(--s-4); overflow-x: auto; scrollbar-width: thin; }
.tabs [role="tab"] { position: relative; border: 0; background: none; padding: 10px 14px; font-weight: var(--fw-medium); font-size: var(--fs-sm); color: var(--text-2);
  cursor: pointer; white-space: nowrap; display: inline-flex; gap: 8px; align-items: center; min-height: 44px; }
.tabs [role="tab"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--primary);
  transform: scaleX(0); transition: transform var(--d-2) var(--ease); }
.tabs [role="tab"]:hover { color: var(--text); }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); }
.tabs [role="tab"][aria-selected="true"]::after { transform: scaleX(1); }
.tab-count { font-size: 11px; background: var(--surface-2); color: var(--text-2); border-radius: var(--r-pill); padding: 0 7px; line-height: 18px; font-weight: var(--fw-semi); }
[role="tabpanel"] { animation: fade-in var(--d-2) var(--ease-out); }
.pagination { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pagination .btn { --btn-h: 36px; min-width: 36px; padding: 0 10px; border-color: transparent; background: transparent; box-shadow: none; }
.pagination .btn:hover { background: var(--surface-2); }
.pagination .btn[aria-current="page"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
@media (pointer: coarse) { .pagination .btn { --btn-h: 44px; min-width: 44px; } }
.disclosure > summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: var(--fw-medium); font-size: var(--fs-sm);
  color: var(--primary-ink); padding: 8px 0; min-height: 40px; }
:root[data-theme="dark"] .disclosure > summary { color: var(--primary); }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary .chev { transition: transform var(--d-2) var(--ease); }
.disclosure[open] > summary .chev { transform: rotate(180deg); }
.disclosure[open] > :not(summary) { animation: drop-in var(--d-2) var(--ease-out); }

/* ================================================================ dialogs */
dialog { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 0; background: var(--surface-raised); color: var(--text); box-shadow: var(--shadow-modal);
  width: min(560px, calc(100vw - 24px)); max-height: min(86vh, 900px); overflow: hidden; }
dialog[open] { display: flex; flex-direction: column; animation: dialog-in var(--d-3) var(--ease-out); }
dialog::backdrop { background: rgba(8, 15, 30, .45); backdrop-filter: blur(2px); }
.dialog__head { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--line); }
.dialog__head h2 { font-size: var(--fs-xl); }
.dialog__body { padding: var(--s-5); overflow: auto; min-height: 0; }
.dialog__foot { padding: var(--s-3) var(--s-5); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: var(--s-2); flex-wrap: wrap;
  background: var(--surface-2); }
@media (max-width: 599.98px) {
  dialog { width: 100vw; max-width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: var(--r-xl) var(--r-xl) 0 0; }
  dialog[open] { animation: sheet-in var(--d-3) var(--ease-out); }
  .dialog__foot .btn { flex: 1; }
}
.choice-list { list-style: none; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: var(--r-md); max-height: 300px; overflow: auto; }
.choice-list li + li { border-top: 1px solid var(--line); }
.choice-list button { width: 100%; text-align: left; padding: 12px 14px; background: none; border: 0; color: var(--text); cursor: pointer; display: flex; gap: 10px;
  align-items: center; font-size: var(--fs-sm); min-height: 48px; }
.choice-list button:hover { background: var(--primary-soft); }
.choice-list button > span:nth-child(2) { min-width: 0; overflow-wrap: anywhere; }

/* Tooltips (click/keyboard; never hover-only) */
.info { position: relative; display: inline-flex; vertical-align: middle; }
.info > button { border: 0; background: none; padding: 4px; color: var(--text-3); cursor: pointer; border-radius: 50%; display: grid; place-items: center; min-width: 26px; min-height: 26px; }
.info > button:hover { color: var(--primary-ink); background: var(--surface-2); }
.info [role="tooltip"] { position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); width: max-content; max-width: min(320px, 80vw);
  background: #0f172a; color: #f8fafc; padding: 10px 12px; border-radius: var(--r-md); font-size: var(--fs-xs); font-weight: var(--fw-regular); line-height: 1.45;
  z-index: var(--z-tooltip); box-shadow: var(--shadow-float); text-transform: none; letter-spacing: 0; animation: fade-in var(--d-1) var(--ease-out); white-space: normal; }
:root[data-theme="dark"] .info [role="tooltip"] { background: #f7f3f7; color: #141414; }

/* ================================================================ definition lists */
.dl-wrap { container-type: inline-size; }
.dl { display: grid; grid-template-columns: minmax(8.5rem, 38%) minmax(0, 1fr); margin: 0; font-size: var(--fs-sm); }
.dl dt, .dl dd { padding: 9px 0; border-bottom: 1px solid var(--line); margin: 0; }
.dl dt { color: var(--text-3); padding-right: var(--s-3); }
.dl dd { color: var(--text); overflow-wrap: anywhere; min-width: 0; }
.dl > :nth-last-child(-n+2) { border-bottom: 0; }
@container (max-width: 360px) {
  .dl { grid-template-columns: minmax(0, 1fr); }
  .dl dt { border: 0; padding-bottom: 0; font-size: var(--fs-2xs); }
}
.absent { color: var(--text-3); font-style: italic; }
.source-line { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 12px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; color: var(--text-2); }

/* ================================================================ compare tray */
.compare-tray { position: fixed; left: 50%; bottom: 14px; z-index: var(--z-tray); width: min(940px, calc(100vw - 24px));
  background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--shadow-modal);
  transform: translateX(-50%); animation: tray-in var(--d-3) var(--ease-out); }
@media (min-width: 1024px) { .compare-tray { left: calc(50% + var(--rail-w) / 2); width: min(940px, calc(100vw - var(--rail-w) - 48px)); } }
.compare-tray__inner { display: flex; gap: var(--s-2) var(--s-3); align-items: center; padding: 8px 8px 8px 16px; flex-wrap: wrap; }
.compare-tray__items { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; flex: 1; }
.compare-tray__item { display: inline-flex; align-items: center; gap: 2px; max-width: 230px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 2px 2px 2px 10px; font-size: var(--fs-2xs); animation: chip-in var(--d-2) var(--ease-out); }
.compare-tray__item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-tray__item button { border: 0; background: none; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; color: var(--text-2); flex: none; }
.compare-tray__item button:hover { background: var(--surface-3); }
.compare-tray__count { font-weight: var(--fw-semi); font-size: var(--fs-sm); white-space: nowrap; display: inline-flex; gap: 8px; align-items: center; }
body.has-tray .page { padding-bottom: 120px; }
@media (max-width: 719.98px) {
  .compare-tray { bottom: 8px; border-radius: var(--r-lg); }
  .compare-tray__items { display: none; }
  .compare-tray__inner { padding: 8px 8px 8px 14px; flex-wrap: nowrap; }
}

/* ================================================================ motion keyframes */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes drop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: scale(.96) translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes tray-in { from { opacity: 0; translate: 0 16px; } to { opacity: 1; translate: 0 0; } }
@keyframes chip-in { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: none; } }
@keyframes star-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes row-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes progress { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* Cross-document view transitions (progressive enhancement): short cross-fade between pages. */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 160ms; animation-timing-function: var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .progress[data-active="true"]::after, .skeleton, .spinner { animation: none !important; }
}
@media print {
  .rail, .topbar, .app-footer, .compare-tray, .toasts, .no-print { display: none !important; }
  .app { display: block; } body { background: #fff; } body::before { display: none; }
  .page { padding: 0; max-width: none; }
}
.narrow-panel { max-width: 560px; }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain > li + li { margin-top: 8px; }

/* Buttons whose label is data (may be long): allowed to wrap instead of overflowing. */
.btn--wrap { white-space: normal; height: auto; min-height: var(--btn-h); padding-top: 8px; padding-bottom: 8px; text-align: left; line-height: 1.3; }
@media (max-width: 400px) {
  .tabs [role="tab"] { padding: 10px 8px; font-size: var(--fs-xs); gap: 6px; }
  .btn { padding: 0 14px; }
}
:root[data-theme="dark"] mark { background: #5c4300; color: #fff4d6; }
/* WCAG 2.5.8 (Target Size, minimum 24x24): list/row links and small controls. */
@media (pointer: coarse) { .check input, input.cb { width: 24px; height: 24px; } }
.link-btn { min-height: 24px; display: inline-flex; align-items: center; }
.app-footer a { display: inline-block; padding: 3px 0; }
.cell-title { line-height: 24px; }
