/* MAXIMA UI: shared tokens, reset and components.
   Surface files own page-specific layouts in the surfaces layer.
   Keep shared component rules here so all three surfaces use the same scale. */
@layer reset, surfaces, components;


@layer reset {
  /* A button with the close cross holds the soft red fill of its hover (components, "Icon micro-motion").
     Kept in this weakest layer so a button placed absolutely by its own surface keeps its position. */
  :is(a, button):has(> svg .icon-x-a) { position: relative; isolation: isolate; overflow: hidden; }
  /* Self-hosted: no request ever leaves the portal. Onest is licensed under the OFL (fonts/OFL.txt). */
  @font-face { font-family:"Onest"; src:url("fonts/onest-latin.woff2") format("woff2"); font-weight:100 900; font-display:optional; unicode-range:U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD; }
  @font-face { font-family:"Onest"; src:url("fonts/onest-latin-ext.woff2") format("woff2"); font-weight:100 900; font-display:optional; unicode-range:U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF; }
  @font-face { font-family:"Onest"; src:url("fonts/onest-cyrillic.woff2") format("woff2"); font-weight:100 900; font-display:optional; unicode-range:U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116; }

  :root {
    color-scheme: light;
    --font-sans: "Onest", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Arial, sans-serif;
    --font-caption: .8125rem;
    --font-small: .875rem;
    --font-body: .9375rem;
    --font-title: 1.125rem;
    --font-section: 1.375rem;
    --font-heading: clamp(2rem, 3vw, 2.75rem);
    --font-display: clamp(2.5rem, 4.6vw, 4.25rem);
    --weight-medium: 500;
    --weight-bold: 600;
    --weight-brand: 800;
    --leading-body: 1.5;
    --leading-heading: 1.12;

    /* Graphite on white, on a grey desk. Brand red is the only accent: the route, the X, alerts. */
    --navy0: #0f2a66;
    --navy1: #1557e6;
    --navy2: #0f46c2;
    --navy3: #0f46c2;
    --navy: #0f2a66;
    --red: #e11d2e;
    --cyan: #b9d0ff;
    --blue: #1557e6;
    --bg: #e4ebf7;
    --white: #fff;
    --card: var(--white);
    --surface: var(--white);
    --surface-soft: #f1f5fc;
    --surface-blue: #e2ebfb;
    --text: #0f1b33;
    --muted: #46546c;
    --faint: #5f6d85;
    --line: #dde5f2;
    --line2: #bcc8dc;
    --green: #0f7a4f;
    --amber: #a35a00;
    --success-bg: #e7f6ef;
    --success-line: #b5e2cd;
    --danger: #c01525;
    --danger-bg: #fdecee;
    --danger-line: #f6c4c9;
    --warning-bg: #fdf3e4;
    --warning-line: #f0d5a8;
    --on-dark: #fff;
    --on-dark-muted: #dce7ff;
    --on-dark-faint: #c2d3f7;
    --dark-line: rgba(255, 255, 255, .16);
    --dark-surface: rgba(255, 255, 255, .08);
    --accent-soft: rgba(255, 255, 255, .12);
    --sidebar-bg: transparent;
    --hero-bg: #1557e6;
    --logo-bg: #0b1f52;
    --logo-x: var(--red);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    /* Radius follows nesting: sheet 20, tiles 18, fields 12, small marks 8; actions and tags are pills. */
    --radius-sm: 8px;
    --radius-control: 12px;
    --radius-card: 18px;
    --radius-lg: 24px;
    --radius-pill: 999px;
    --control-height: 44px;
    --control-compact: 36px;
    --sidebar: 248px;
    --topbar: 64px;
    --content-width: 1280px;
    --page-gutter: 40px;
    --panel-padding: 24px;
    --shadow-y: 1px;
    --shadow-blur: 2px;
    --shadow-color: rgba(15, 42, 102, .12);
    --focus-color: rgba(21, 87, 230, .22);
    --shadow: 0 var(--shadow-y) var(--shadow-blur) var(--shadow-color);
    --shadow-float: 0 2px 6px rgba(15, 42, 102, .08), 0 20px 48px rgba(15, 42, 102, .2);
    --focus-ring: 0 0 0 3px var(--focus-color);
    --focus-outline: #1557e6;
    --glass-bg: color-mix(in srgb, var(--surface) 82%, transparent);
    --floating-bg: color-mix(in srgb, var(--surface) 86%, transparent);
    --primary-bg: #1557e6;
    --primary-hover: #0f46c2;
    --primary-text: var(--white);
    --switch-track: #bcc8dc;
    --scrollbar-thumb: #aebcd3;
    --scrollbar-hover: #5f6d85;
    --danger-solid: #c01525;
    --list-width: 1040px;
    --list-bg: var(--surface);
    --list-border: var(--line);
    --list-hover: var(--surface-soft);
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --logo-bg: var(--white);
    --red: #e0263a;
    --blue: #86aeff;
    --bg: #0a1324;
    --surface: #111d34;
    --card: var(--surface);
    --surface-soft: #182843;
    --surface-blue: #21355a;
    --text: #eaf0fb;
    --muted: #b1bfd6;
    --faint: #98a8c2;
    --line: #233350;
    --line2: #3e5275;
    --green: #5fd6a3;
    --amber: #f3b566;
    --success-bg: #14332a;
    --success-line: #27624d;
    --danger: #ff8a94;
    --danger-bg: #3a1c24;
    --danger-line: #74343f;
    --warning-bg: #36291a;
    --warning-line: #6f5230;
    --hero-bg: #1d4cb8;
    --primary-bg: #2563eb;
    --primary-hover: #1d4fd0;
    --primary-text: #fff;
    --switch-track: #3e5275;
    --scrollbar-thumb: #3e5275;
    --scrollbar-hover: #98a8c2;
    --list-bg: var(--surface-soft);
    --danger-solid: #d42a3c;
    --list-border: #2c3f60;
    --list-hover: var(--surface-blue);
    --shadow-color: rgba(0, 0, 0, .4);
    --shadow-float: 0 2px 6px rgba(0, 0, 0, .3), 0 20px 48px rgba(0, 0, 0, .5);
    --focus-color: rgba(134, 174, 255, .28);
    --focus-outline: #86aeff;
  }

  /* The page keeps its width whether or not it is long enough to scroll. */
  html { scrollbar-gutter: stable; }

  *, *::before, *::after { box-sizing: border-box; }
  html { min-width: 320px; scroll-behavior: smooth; }
  body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--font-body);
    line-height: var(--leading-body);
  }
  button, input, select, textarea { font: inherit; }
  button, select { cursor: pointer; }
  button { touch-action: manipulation; }
  /* Normal interaction transitions; theme commits bypass them together. */
  :where(html[data-theme-ready] body, html[data-theme-ready] body *) {
    transition: background-color .12s ease, border-color .12s ease, box-shadow .12s ease;
  }
  a { color: inherit; text-decoration: none; }
  img { max-width: 100%; }
  h1, h2, h3 { line-height: var(--leading-heading); overflow-wrap: anywhere; }
  input, select, textarea { min-width: 0; }
  [hidden] { display: none !important; }

  @media (max-width: 1180px) {
    :root { --page-gutter: 28px; }
  }
  @media (max-width: 680px) {
    :root { --page-gutter: 16px; --panel-padding: 20px; --topbar: 64px; }
  }
}

@layer components {
  /* Capture complete themes; never interpolate foreground against background.
     The guard covers native controls, SVG, nested components and pseudo-elements. */
  html[data-theme-snapshot],
  html[data-theme-snapshot] *,
  html[data-theme-snapshot] *::before,
  html[data-theme-snapshot] *::after,
  html[data-theme-snapshot] dialog::backdrop {
    transition: none !important;
  }
  /* Theme switch only: page-to-page navigation keeps the short crossfade set at the end of this file. */
  :root[data-theme-snapshot]::view-transition-group(root) { animation: none; }
  :root[data-theme-snapshot]::view-transition-old(root), :root[data-theme-snapshot]::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
  }
  :root[data-theme-snapshot]::view-transition-new(root) {
    /* Slightly slower with a soft start, so the switch is easier on the eyes. */
    animation: theme-reveal .9s cubic-bezier(.45, 0, .2, 1) both;
  }
  @keyframes theme-reveal {
    from { clip-path: circle(0px at var(--theme-x, 50%) var(--theme-y, 50%)); }
    to { clip-path: circle(var(--theme-radius, 150vmax) at var(--theme-x, 50%) var(--theme-y, 50%)); }
  }
  @media (prefers-reduced-motion: reduce) {
    ::view-transition-group(root), ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
  }
  /* Native scrolling, with a quiet rounded rail shared by every surface. */
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
  }
  @supports selector(::-webkit-scrollbar) {
    /* Chromium's standard properties otherwise override its pseudo-elements. */
    * { scrollbar-width: auto; scrollbar-color: auto; }
    *::-webkit-scrollbar { width: 10px; height: 10px; }
    *::-webkit-scrollbar-track { background: transparent; margin: 8px; }
    *::-webkit-scrollbar-thumb {
      min-height: 32px;
      min-width: 32px;
      border: 2px solid transparent;
      border-radius:var(--radius-pill);
      background: var(--scrollbar-thumb);
      background-clip: padding-box;
    }
    *::-webkit-scrollbar-thumb:hover { background-color: var(--scrollbar-hover); }
    *::-webkit-scrollbar-thumb:active { background-color: var(--blue); }
    *::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
    *::-webkit-scrollbar-corner { background: transparent; }
  }
  @media (forced-colors: active) {
    * { scrollbar-color: auto; scrollbar-width: auto; }
    *::-webkit-scrollbar-thumb { background-color: ButtonText; }
    *::-webkit-scrollbar-track { background-color: Canvas; }
  }

  /* Shared application shell */
  .sidebar, .portal-sidebar {
    width: var(--sidebar);
    background: var(--sidebar-bg);
    color: var(--on-dark);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  /* No visible scrollbar in either sidebar: a scrollbar only in the longer admin menu narrowed its footer. Wheel, touch and keyboard scrolling still work. */
  .sidebar, .portal-sidebar { scrollbar-width: none; border-right: 1px solid rgba(255, 255, 255, .06); }
  .sidebar::-webkit-scrollbar, .portal-sidebar::-webkit-scrollbar { display: none; }
  .portal-sidebar { padding: 0 12px 12px; }
  .main, .portal-main { min-width: 0; }
  .topbar, .portal-topbar {
    min-height: var(--topbar);
    height: auto;
    padding: 12px var(--page-gutter);
    gap: 16px;
    border-bottom: 1px solid var(--line);
    background: var(--glass-bg);
  }
  .topbar-title, .topbar-context { min-width: 0; }
  .topbar-context { align-items: flex-start; flex-direction: column; gap: 2px; }
  .topbar-title small, .topbar-context span {
    color: var(--faint);
    font-size: var(--font-caption);
    font-weight: var(--weight-medium);
    letter-spacing: .06em;
  }
  .topbar-title strong, .topbar-context b {
    margin: 0;
    font-size: var(--font-small);
    font-weight: var(--weight-bold);
  }
  .page, .portal-content {
    width: min(var(--content-width), 100%);
    margin: 0 auto;
    padding: var(--space-8) var(--page-gutter) 64px;
  }
  .brand, .portal-brand {
    min-height: var(--topbar);
    padding: 16px 20px;
  }
  /* Same height and vertical centring as the admin sidebar header, so switching areas does not shift the logo. */
  .portal-brand { display: flex; align-items: center; margin: 0 -12px 12px; border-bottom: 1px solid var(--dark-line); }
  /* Logo mark on the left spanning both text lines of the wordmark. */
  .brand-lockup { display: grid; grid-template-columns: auto auto; justify-content: start; align-items: center; column-gap: 12px; line-height: 1; }
  .brand-lockup > :not(.brand-logo) { grid-column: 2; justify-self: start; }
  .brand-logo { grid-row: 1 / span 2; display: block; width: 38px; height: 38px; border-radius:var(--radius-card); box-shadow: 0 0 0 1px var(--dark-line); }
  .brand-main, .maxima {
    font-size: 1.25rem;
    font-weight: var(--weight-brand);
    letter-spacing: .12em;
    color: var(--on-dark);
  }
  .brand-main span, .maxima span { color: var(--red); }
  .brand-lockup small, .sub {
    margin-top: 6px;
    color: var(--on-dark-muted);
    font-size: var(--font-caption);
    letter-spacing: .16em;
  }

  .nav-link, .portal-nav-item {
    min-height: var(--control-height);
    padding: 10px 12px;
    border-radius:var(--radius-control);
    color: var(--on-dark-muted);
    font-size: var(--font-small);
    font-weight: var(--weight-medium);
    line-height: 1.4;
  }
  .portal-nav-item { grid-template-columns: 24px minmax(0, 1fr) auto; gap: 8px; }
  .portal-nav-item > b { font-size: inherit; font-weight: inherit; }
  .nav-link.active, .portal-nav-item.active {
    background: var(--accent-soft);
    box-shadow: inset 3px 0 0 var(--cyan);
    color: var(--on-dark);
  }
  .nav-label, .nav-group-label, .portal-nav-item > span, .portal-nav-item > small,
  .profile-copy small { color: var(--on-dark-faint); font-size: var(--font-caption); }
  .nav-label, .nav-group-label { letter-spacing: .08em; }
  .portal-nav-item.disabled { opacity: 1; }
  /* Navigation icons (ui_icon) look the same in portal and admin: muted, brighter on hover, cyan when active. */
  .nav-symbol, .portal-nav-item > span { display: grid; place-items: center; }
  .nav-symbol { width: 20px; flex: 0 0 20px; }
  .nav-symbol, .portal-nav-item > span { color: var(--on-dark-faint); transition: color .16s ease; }
  .nav-link:hover .nav-symbol, a.portal-nav-item:hover > span { color: var(--on-dark); }
  .nav-link.active .nav-symbol, .portal-nav-item.active > span { color: var(--cyan); }
  .profile-copy strong { font-size: var(--font-small); }
  .avatar, .profile-avatar {
    width: 36px;
    height: 36px;
    border-radius:var(--radius-control);
    background: var(--accent-soft);
    color: var(--cyan);
    font-size: var(--font-small);
  }
  .portal-profile, .sidebar-footer .profile {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 44px;
    align-items: center;
    gap: 8px;
    padding: 10px;
    margin: 0;
    border: 1px solid var(--dark-line);
    border-radius:var(--radius-card);
    background: var(--dark-surface);
  }
  .profile-logout { margin: 0; }
  .portal-sidebar-footer { margin: 16px -12px 0; padding: 12px 12px 0; border-top: 1px solid var(--dark-line); }
  .favorites-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
  .favorites-head > div { min-width: 0; }
  .favorites-edit { flex-shrink: 0; }
  .favorites-list { display: grid; gap: 10px; }
  .favorite-link { display: grid; grid-template-columns: 40px minmax(0, 1fr) 20px; align-items: center; gap: 12px; min-height: 64px; padding: 12px; border: 1px solid var(--line); border-radius:var(--radius-card); }
  .favorite-link strong { font-size: var(--font-small); }
  .favorite-link > span:last-child { color: var(--blue); }
  .favorite-link:hover { background: var(--surface-blue); border-color: var(--line2); }
  .favorite-code { display: grid; place-items: center; height: 40px; border-radius:var(--radius-control); background: var(--surface-blue); color: var(--blue); font-size: var(--font-caption); font-weight: var(--weight-bold); }
  .favorites-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 220px; padding: 24px 12px; text-align: center; }
  .favorites-empty svg { color: var(--blue); margin-bottom: 16px; }
  .favorites-empty p { max-width: 320px; margin: 8px 0 0; color: var(--muted); font-size: var(--font-small); }
  .favorites-picker { min-width: 0; border: 0; margin: 0; padding: 0; }
  .favorites-picker legend { padding: 0 0 12px; color: var(--muted); font-size: var(--font-small); }
  .favorite-choice { display: flex; align-items: center; gap: 12px; padding: 12px; min-height: 52px; border: 1px solid var(--line); border-radius:var(--radius-control); margin-bottom: 8px; cursor: pointer; }
  .favorite-choice:hover, .favorite-choice:has(input:checked) { background: var(--surface-blue); border-color: var(--line2); }
  .favorite-choice input { width: 20px; height: 20px; flex-shrink: 0; margin: 0; accent-color: var(--blue); }
  .favorite-choice span { font-size: var(--font-small); }
  .favorite-group + .favorite-group { margin-top: 16px; }
  .favorite-choice-parent span { font-weight: 700; }
  .favorite-choice-child { position: relative; margin-left: 28px; }
  .favorite-choice-child::before { content: ''; position: absolute; left: -18px; top: -9px; width: 10px; height: 35px; border-left: 1px solid var(--line2); border-bottom: 1px solid var(--line2); border-bottom-left-radius: 6px; pointer-events: none; }
  .favorites-status { margin: 12px 0 0; color: var(--danger); font-size: var(--font-small); }
  .logout, .logout-link { color: var(--on-dark-muted); }

  /* The same headings and panel scale on every screen */
  .heading, .portal-page-heading { gap: var(--space-6); margin-bottom: var(--space-6); }
  .heading > div, .portal-page-heading > div { min-width: 0; }
  .heading h1, .portal-page-heading h1, .instruction-article h1, .form-heading h2 {
    font-size: var(--font-heading);
    line-height: var(--leading-heading);
    letter-spacing: -.035em;
  }
  .heading p, .portal-page-heading p, .instruction-lead, .form-heading p {
    font-size: var(--font-body);
    line-height: 1.6;
  }
  .eyebrow, .portal-eyebrow {
    font-size: var(--font-caption);
    font-weight: var(--weight-bold);
    letter-spacing: .1em;
  }
  .panel-head h2, .section-title h2, .security-action h2, .portal-section-head h2,
  .card-head h2, .profile-strip h2 {
    font-size: var(--font-section);
    line-height: 1.3;
  }
  .panel, .stat, .audit-stat, .workspace-card, .department-card {
    border-radius:var(--radius-card);
    padding: var(--panel-padding);
    background: var(--surface);
  }
  .form-panel, .security-actions { padding: 0; }
  .brand-panel, .security-panel { background: var(--hero-bg); }
  .brand-copy p, .security-panel p { color: var(--on-dark-muted); }
  .form-section { padding: var(--panel-padding); }
  .form-actions { padding: var(--space-4) var(--panel-padding); }
  .instruction-content, .instruction-public-text { font-size: var(--font-body); line-height: 1.75; }
  .instruction-public-text { overflow-wrap: anywhere; }
  .empty-state p { font-size: var(--font-small); }
  .instruction-featured { color: var(--blue); }

 /* Controls: one height, radius and type size */
  .primary, .secondary, .login-card button {
    min-height: var(--control-height);
    height: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius:var(--radius-control);
    font-size: var(--font-small);
    font-weight: var(--weight-bold);
    line-height: 1.4;
    text-align: center;
    cursor: pointer;
  }
  .primary, .login-card button { background: var(--primary-bg); color: var(--primary-text); }
  .primary:hover, .login-card button:hover { background: var(--primary-hover); }
  .secondary { border-color: var(--line2); background: var(--surface); color: var(--text); }
  .secondary:hover { background: var(--surface-blue); }
  .field input, .field select, .inline-form input, .login-card input, .instruction-filterbar select, .audit-filter input, .audit-filter select {
    width: 100%;
    height: var(--control-height);
    padding: 0 12px;
    border: 1px solid var(--line2);
    border-radius:var(--radius-control);
    background: var(--surface);
    color: var(--text);
    font-size: var(--font-body);
  }
  .field input[type="file"] { height: auto; min-height: var(--control-height); padding: 8px; }
  .field textarea, .instruction-language-card textarea, .instruction-editor-block textarea {
    font-size: var(--font-body);
    border-color: var(--line2);
    border-radius:var(--radius-control);
    line-height: var(--leading-body);
  }
  .field > span, .login-card label span, .audit-filter > span { color: var(--muted); font-size: var(--font-small); font-weight: var(--weight-medium); }
  .search, .instruction-search {
    min-height: var(--control-height);
    height: auto;
    border: 1px solid var(--line2);
    border-radius:var(--radius-control);
    background: var(--surface);
    color: var(--muted);
    font-size: var(--font-small);
  }
  .search input, .instruction-search input {
    min-height: 40px;
    font-size: var(--font-body);
  }
  .info-box { height: auto; min-height: var(--control-height); padding-top: 6px; padding-bottom: 6px; }
  .topbar-right a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--control-height);
    padding: 8px 12px;
    border: 1px solid var(--line2);
    border-radius:var(--radius-control);
    background: var(--surface);
    color: var(--text);
    font-size: var(--font-small);
    font-weight: var(--weight-medium);
  }
  .icon-btn { width: var(--control-height); height: var(--control-height); flex-shrink: 0; }
  .block-icon-button { width: var(--control-compact); height: var(--control-compact); }

  .language-switcher, .portal-language, .login-language form {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--dark-line);
    border-radius:var(--radius-control);
    background: var(--dark-surface);
  }
  .language-switcher button, .portal-language button, .login-language button {
    width: 100%;
    height: var(--control-compact);
    margin: 0;
    padding: 0 10px;
    border: 0;
    border-radius:var(--radius-sm);
    background: transparent;
    color: var(--on-dark-muted);
    font-size: var(--font-caption);
    font-weight: var(--weight-bold);
    letter-spacing: normal;
    line-height: 1;
    cursor: pointer;
    transition: background-color .18s ease, color .18s ease, box-shadow .18s ease;
  }
  .language-switcher button:hover, .portal-language button:hover {
    background: var(--accent-soft);
    color: var(--cyan);
    box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--cyan) 35%,transparent);
  }
  .language-switcher button.active, .portal-language button.active {
    background: var(--accent-soft);
    color: var(--cyan);
    box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--cyan) 25%,transparent);
  }
  .login-language form { border-color: var(--line); background: var(--surface); }
  .login-language button { color: var(--muted); }
  .login-language button.active { background: var(--accent-soft); color: var(--blue); box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--cyan) 25%,transparent); }
  .login-language form button:hover { background: var(--accent-soft); color: var(--blue); box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--cyan) 35%,transparent); }
  :root[data-theme="dark"] .login-language button.active,
  :root[data-theme="dark"] .login-language form button:hover { color: var(--cyan); }
  [data-language-slider] { position: relative; isolation: isolate; }
  [data-language-slider]::before {
    content: "";
    position: absolute;
    top: 5px;
    bottom: 5px;
    left: 5px;
    width: calc((100% - 18px) / 3);
    border-radius:var(--radius-sm);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px color-mix(in srgb,var(--cyan) 25%,transparent);
    transform: translateX(calc(var(--language-index, 0) * (100% + 4px)));
    transition: transform .22s cubic-bezier(.2, .7, .2, 1), background-color .24s ease;
    pointer-events: none;
  }
  [data-language-slider] button { position: relative; z-index: 1; }
  [data-language-slider] button.active,
  .login-language [data-language-slider] button.active:hover { background: transparent; box-shadow: none; }
  
  
  

  /* Language and theme preferences share one compact row. */
  .interface-preferences { display: grid; grid-template-columns: minmax(0, 1fr) 46px; align-items: center; gap: 8px; margin-bottom: 12px; }
  .interface-preferences .language-switcher, .interface-preferences .portal-language { margin: 0; }
  .login-language { display: flex; align-items: center; gap: 8px; }
  .theme-toggle {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    padding: 0;
    border: 1px solid var(--dark-line);
    border-radius:var(--radius-control);
    background: var(--dark-surface);
    color: var(--on-dark-muted);
    cursor: pointer;
    transition: background .18s ease, color .18s ease, border-color .18s ease;
  }
  .theme-toggle:hover { background: var(--accent-soft); color: var(--cyan); border-color: color-mix(in srgb,var(--cyan) 35%,transparent); }
  .theme-toggle[aria-pressed="true"] { color: var(--cyan); background: var(--accent-soft); }
  .theme-toggle svg { grid-area: 1 / 1; transition: opacity .2s ease, transform .24s ease; }
  .theme-sun { opacity: 0; transform: rotate(-45deg) scale(.75); }
  [data-theme="dark"] .theme-sun { opacity: 1; transform: rotate(0) scale(1); }
  [data-theme="dark"] .theme-moon { opacity: 0; transform: rotate(45deg) scale(.75); }
  .login-language .theme-toggle { width: 46px; height: 46px; padding: 0; border-color: var(--line); background: var(--surface); color: var(--blue); }
  .login-language .theme-toggle:hover { background: var(--surface-blue); }
  .logout-link { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius:var(--radius-control); background: transparent; cursor: pointer; }
  .logout-link:hover { background: var(--accent-soft); color: var(--cyan); }
  .form-grid + .toggle-grid { margin-top: var(--space-6); }
  .toggle-card { min-height: 88px; padding: 18px; gap: 16px; grid-template-columns: minmax(0, 1fr) auto; }
  .toggle-card strong { font-size: var(--font-body); }
  .toggle-card small { font-size: var(--font-small); line-height: var(--leading-body); }
  .toggle-card:hover { background: var(--surface-soft); border-color: var(--line2); }
  .switch { width: 52px; height: 30px; flex-shrink: 0; background: var(--switch-track); }
  .switch::after { width: 24px; height: 24px; background: var(--white); }
  .toggle-card input:checked + .switch { background: var(--primary-bg); }
  .toggle-card input:checked + .switch::after { transform: translateX(22px); }
  .ui-number { display: grid; grid-template-columns: minmax(0, 1fr) 44px 44px; gap: 8px; min-width: 0; }
  .ui-number input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
  .ui-number input::-webkit-inner-spin-button, .ui-number input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
  .ui-number-step {
    display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
    border: 1px solid var(--line2); border-radius:var(--radius-control);
    background: var(--surface-soft); color: var(--muted);
    transition: background-color .18s ease, color .18s ease, border-color .18s ease;
  }
  .ui-number-step:hover:not(:disabled) { background: var(--surface-blue); color: var(--blue); border-color: var(--blue); }
  .ui-number-step:active:not(:disabled) { background: var(--surface-blue); box-shadow: inset 0 0 0 1px var(--blue); }
  .ui-number-step:disabled { opacity: .4; cursor: not-allowed; }
  .quick-code { color: var(--blue); }
  ::selection { background: var(--surface-blue); color: var(--text); }
  input::placeholder, textarea::placeholder { color: var(--faint); opacity: 1; }

  /* Feedback and keyboard access */
  .flash-success { border-color: var(--success-line); background: var(--success-bg); color: var(--green); }
  .flash-error, .form-errors, .error { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger); }
  :where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 3px;
  }
  :where(.sidebar, .portal-sidebar, .brand-panel) :focus-visible { outline-color: var(--cyan); }
  :where(input, select, textarea):focus { border-color: var(--blue); box-shadow: var(--focus-ring); }
  .search:focus-within, .instruction-search:focus-within { box-shadow: var(--focus-ring); border-color: var(--blue); }
  .search input:focus, .instruction-search input:focus { box-shadow: none; }
  .instruction-search input:focus-visible, .search input:focus-visible { outline: none; }
  .instruction-search input { border-radius:var(--radius-sm); }
  .ui-select { position: relative; min-width: 0; }
  .ui-select-trigger {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    width: 100%; min-height: var(--control-height); padding: 0 12px;
    border: 1px solid var(--line2); border-radius:var(--radius-control);
    background: var(--surface); color: var(--text); text-align: left;
    font-size: var(--font-small);
  }
  .ui-select-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ui-select-trigger svg { flex-shrink: 0; transition: transform .18s ease; }
  .ui-select-trigger[aria-expanded="true"] { border-color: var(--blue); box-shadow: var(--focus-ring); }
  .ui-select-trigger[aria-expanded="true"] svg { transform: rotate(180deg); }
  .ui-select-trigger:disabled { opacity: .55; cursor: not-allowed; }
  .ui-select-trigger[aria-invalid="true"] { border-color: var(--danger); }
  .ui-select-error { margin-top: 6px; color: var(--danger); font-size: var(--font-small); }
  .ui-select-list {
    position: fixed; z-index: 100;
    margin: 0; padding: 6px; max-height: min(320px, 45dvh); overflow-y: auto;
    border: 1px solid var(--line2); border-radius:var(--radius-card);
    background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  }
  .ui-select-option { padding: 9px 10px; border-radius:var(--radius-control); font-size: var(--font-small); cursor: pointer; overflow-wrap: anywhere; }
  .ui-select-option[aria-selected="true"] { color: var(--blue); background: var(--surface-blue); font-weight: var(--weight-medium); }
  .ui-select-option.is-highlighted { box-shadow: inset 0 0 0 1px var(--blue); background: var(--surface-blue); }
  .ui-select-option[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
  .toggle-card input:focus-visible + .switch { outline: 2px solid var(--blue); outline-offset: 3px; }
  button:disabled { cursor: not-allowed; }
  .admin-table th { font-size: var(--font-caption); }
  .admin-table td { font-size: var(--font-small); }
  .admin-table td, .field, .instruction-language-card { overflow-wrap: anywhere; }
  .instruction-editor-block-head { flex-wrap: wrap; }
  .instruction-editor-block-head > div:first-child { min-width: 0; }
  .instruction-block-actions { flex-shrink: 0; }

  @media (max-width: 1180px) {
    .profile-strip { grid-template-columns: 1fr; }
    .department-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .security-action { grid-template-columns: 1fr; }
  }
  @media (max-width: 900px) {
    .main, .portal-main { margin-left: 0; }
    .portal-content { padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)); }
    .portal-sidebar { max-width: calc(100vw - 32px); }
    .sidebar { max-width: calc(100vw - 32px); }
    .topbar-context span { display: none; }
  }
  @media (max-width: 680px) {
    .page, .portal-content { padding-top: var(--space-6); }
    .topbar, .portal-topbar { gap: 8px; }
    .topbar-title small, .topbar-right a { display: none; }
    .heading, .portal-page-heading { align-items: stretch; flex-direction: column; }
    .department-grid { grid-template-columns: 1fr; }
    .login-language { top: 16px; right: 16px; }
    .instruction-article-head, .instruction-content, .instruction-language-note { padding-left: var(--panel-padding); padding-right: var(--panel-padding); }
    .instruction-article-meta, .department-card-top { flex-wrap: wrap; }
  }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
  }
}

/* Phone navigation shared by the portal and the admin area (app/ui.php mobile_nav, mobile-nav.js):
   a bottom bar with Home, Search/Portal and Menu; Menu opens a dark sheet with every section. */
@layer components {
  .mobile-tabbar, .mobile-sheet { display:none; }

  @media(max-width:900px) {
    .mobile-tabbar {
      position:fixed;
      inset:auto 10px calc(10px + env(safe-area-inset-bottom, 0px));
      z-index:45;
      /* Equal tabs; the last one opens the Menu sheet. */
      display:flex;
      gap:2px;
      padding:5px;
      border:1px solid var(--line);
      border-radius:var(--radius-card);
      background:var(--floating-bg);
      box-shadow:0 15px 40px rgba(13,36,52,.13);
      backdrop-filter:blur(14px)
    }

    .mobile-tab {
      flex:1 1 0;
      min-width:0;
      min-height:52px;
      display:flex;
      flex-direction:column;
      align-items:center;
      justify-content:center;
      gap:3px;
      padding:4px 6px;
      border:0;
      border-radius:var(--radius-control);
      background:transparent;
      color:var(--faint);
      font:inherit;
      cursor:pointer;
      -webkit-tap-highlight-color:transparent;
      transition:color .16s ease, background-color .16s ease
    }

    .mobile-tab:active { transform:scale(.96); }

    .mobile-tab-icon, .mobile-sheet-tile > span { position:relative; display:grid; place-items:center; }

    .mobile-nav-dot {
      position:absolute;
      top:-2px;
      right:-4px;
      width:9px;
      height:9px;
      border:2px solid var(--floating-bg);
      border-radius:50%;
      background:var(--red)
    }

    .mobile-nav-dot[hidden] { display:none; }

    .mobile-tab b {
      max-width:100%;
      overflow:hidden;
      font-size:10.5px;
      letter-spacing:-.01em;
      font-weight:var(--weight-bold);
      white-space:nowrap;
      text-overflow:ellipsis
    }

    /* "Menu" sheet: slides up from the bottom, dark like the desktop sidebar so shared controls fit. */
    .mobile-sheet {
      position:fixed;
      inset:0;
      z-index:60;
      display:block
    }

    .mobile-sheet[hidden] { display:none; }

    .mobile-sheet-backdrop {
      position:absolute;
      inset:0;
      width:100%;
      border:0;
      background:rgba(4,16,26,.5);
      backdrop-filter:blur(2px);
      animation:sheet-backdrop-in .22s ease both
    }

    .mobile-sheet-panel {
      position:absolute;
      inset:auto 0 0;
      max-height:calc(100dvh - 48px);
      overflow-y:auto;
      overscroll-behavior:contain;
      padding:6px 16px calc(16px + env(safe-area-inset-bottom, 0px));
      border-radius:var(--radius-card) var(--radius-card) 0 0;
      background:var(--surface);
      color:var(--on-dark);
      box-shadow:0 -20px 60px rgba(0,0,0,.3);
      animation:sheet-panel-in .3s cubic-bezier(.16,1,.3,1) both;
      transition:transform .22s cubic-bezier(.16,1,.3,1)
    }

    .mobile-sheet-panel.is-dragging { transition:none; }
    .mobile-sheet.is-closing { pointer-events:none; }
    .mobile-sheet.is-closing .mobile-sheet-backdrop { animation:sheet-backdrop-out .2s ease-in both; }
    .mobile-sheet.is-closing .mobile-sheet-panel { animation:sheet-panel-out .2s ease-in both; }

    .mobile-sheet-grip { display:grid; place-items:center; height:22px; touch-action:none; }
    .mobile-sheet-grip span { width:40px; height:5px; border-radius:var(--radius-card); background:var(--on-dark-faint); opacity:.6; }

    .mobile-sheet-head {
      display:flex;
      align-items:center;
      justify-content:space-between;
      gap:12px;
      margin:2px 0 14px
    }

    .mobile-sheet-head h2 { margin:0; font-size:var(--font-section); }

    .mobile-sheet-close {
      width:40px;
      height:40px;
      display:grid;
      place-items:center;
      border:1px solid var(--dark-line);
      border-radius:var(--radius-control);
      background:var(--dark-surface);
      color:var(--on-dark-muted);
      cursor:pointer
    }

    .mobile-sheet-grid {
      display:grid;
      grid-template-columns:repeat(2,minmax(0,1fr));
      gap:10px
    }

    .mobile-sheet-tile {
      position:relative;
      min-height:92px;
      display:flex;
      flex-direction:column;
      align-items:flex-start;
      justify-content:space-between;
      gap:12px;
      padding:14px;
      border:1px solid var(--dark-line);
      border-radius:var(--radius-card);
      background:var(--dark-surface);
      color:var(--on-dark);
      font:inherit;
      text-align:left;
      cursor:pointer;
      -webkit-tap-highlight-color:transparent;
      transition:background-color .16s ease, border-color .16s ease, transform .12s ease
    }

    .mobile-sheet-tile:active:not(.disabled) { transform:scale(.97); }

    .mobile-sheet-tile > span {
      width:38px;
      height:38px;
      display:grid;
      place-items:center;
      border-radius:var(--radius-control);
      background:var(--accent-soft);
      color:var(--cyan)
    }

    .mobile-sheet-tile b { font-size:var(--font-small); }

    .mobile-sheet-tile.active { border-color:color-mix(in srgb,var(--cyan) 45%,transparent); }

    .mobile-sheet-tile.disabled { opacity:.55; cursor:default; }

    .mobile-sheet-tile small {
      position:absolute;
      top:12px;
      right:12px;
      color:var(--on-dark-faint);
      font-size:var(--font-caption);
      font-weight:var(--weight-bold);

    }

    .mobile-sheet-footer {
      margin:16px -16px 0;
      padding:14px 16px 0;
      border-top:1px solid var(--dark-line)
    }

    @keyframes sheet-backdrop-in { from { opacity:0 } }
    @keyframes sheet-backdrop-out { to { opacity:0 } }
    @keyframes sheet-panel-in { from { transform:translateY(100%) } }
    @keyframes sheet-panel-out { to { transform:translateY(100%) } }
    .mobile-sheet-tile .mobile-nav-dot { top:-3px; right:-3px; border-color:var(--surface-soft); }

    /* Reopened after a language switch: appear in place instead of sliding in again. */
    .mobile-sheet.is-instant .mobile-sheet-backdrop, .mobile-sheet.is-instant .mobile-sheet-panel { animation:none; }
  }

  @media(max-width:900px) and (prefers-reduced-motion:reduce) {
    .mobile-sheet-backdrop, .mobile-sheet-panel, .mobile-sheet.is-closing .mobile-sheet-backdrop, .mobile-sheet.is-closing .mobile-sheet-panel { animation:none; }
    .mobile-sheet-panel { transition:none; }
  }

  /* The admin "Today" tile keeps the "on dark" tokens: it is the one solid rack-blue tile on the board. */
}

/* ---------------------------------------------------------------------------
   Sheet and route. A white sheet lies on a grey desk, the menu sits on the desk itself.
   Graphite does the work, brand red marks the route, the X and anything urgent.
   Rules here win over the older component rules above because they come last.
   --------------------------------------------------------------------------- */
@layer components {
  body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
  h1, h2, h3 { font-weight: var(--weight-bold); letter-spacing: -.025em; line-height: var(--leading-heading); text-wrap: balance; }
  p, li { text-wrap: pretty; }
  td time, .admin-table td { font-variant-numeric: tabular-nums; }
  .visually-hidden { position:absolute; width:1px; height:1px; margin:-1px; padding:0; overflow:hidden; clip:rect(0,0,0,0); white-space:nowrap; border:0; }

  .eyebrow, .portal-eyebrow, .nav-label, .nav-group-label, .admin-table th, .stat-label, .stat > span, .catalog-badge, .instruction-category, .instruction-featured, .module-status, .update-badge, .profile-facts span, .topbar-title small, .topbar-context span, .portal-nav-item > small, .mobile-sheet-tile small, .brand-lockup small, .sub, .calendar-weekdays {
    letter-spacing: 0;
    text-transform: none;
  }
  .eyebrow, .portal-eyebrow { color: var(--muted); font-size: var(--font-small); font-weight: var(--weight-medium); }
  .end-all-sessions .eyebrow { color: var(--danger); }

  /* ---- Desk and sheet (desktop) ---- */
  @media (min-width: 901px) {
    .portal-main, body.admin-body:not(.admin-embedded) .main {
      margin: 8px 8px 8px var(--sidebar);
      min-height: calc(100vh - 16px);
      border-radius: 20px;
      background: var(--surface);
    }
    /* Keeps the sheet's rounded frame in place while the page scrolls under it, with normal document scrolling. */
    body.portal-body::before, body.admin-body:not(.admin-embedded)::before {
      content: "";
      position: fixed;
      z-index: 30;
      inset: 8px 8px 8px var(--sidebar);
      border-radius: 20px;
      box-shadow: 0 0 0 24px var(--bg);
      pointer-events: none;
    }
    .portal-topbar, .topbar { top: 8px; border-radius: 20px 20px 0 0; }
  }
  @media (max-width: 900px) {
    body.portal-body, body.admin-body { background: var(--surface); }
  }

  /* ---- Menu on the desk ---- */
  .sidebar, .portal-sidebar {
    --on-dark: var(--text);
    --on-dark-muted: var(--muted);
    --on-dark-faint: var(--muted);
    --dark-line: var(--line2);
    --dark-surface: color-mix(in srgb, var(--text) 6%, transparent);
    --accent-soft: color-mix(in srgb, var(--text) 6%, transparent);
    --cyan: var(--text);
    z-index: 40;
    width: var(--sidebar);
    padding: 0 12px 12px;
    border: 0;
    background: transparent;
    color: var(--text);
  }
  .brand, .portal-brand { min-height: 72px; margin: 0; padding: 0 12px; display: flex; align-items: center; border: 0; background: none; }
  .brand-lockup { column-gap: 10px; }
  .brand-logo { width: 32px; height: 32px; border-radius: 9px; box-shadow: none; }
  .brand-main, .maxima { font-size: 1.0625rem; font-weight: var(--weight-brand); letter-spacing: -.01em; line-height: 1.1; color: var(--text); }
  .brand-main span, .maxima span { color: var(--red); }
  .brand-lockup small, .sub { margin-top: 1px; color: var(--muted); font-size: .75rem; font-weight: 400; line-height: 1.2; }
  .sidebar nav, .portal-nav { padding: 4px 0 8px; overflow: visible; flex: 1; }
  .nav-label, .nav-group-label { display: block; margin: 0; padding: 14px 12px 6px; color: var(--muted); font-size: var(--font-caption); font-weight: var(--weight-medium); }
  .nav-label.second, .nav-group-second { margin-top: 8px; }
  .nav-link, .portal-nav-item {
    min-height: 40px;
    margin: 1px 0;
    padding: 6px 12px;
    border-radius: var(--radius-control);
    color: var(--muted);
    font-size: var(--font-body);
    font-weight: var(--weight-medium);
    line-height: 1.2;
    transition: background-color .14s ease, color .14s ease, transform .12s ease;
  }
  .nav-link { gap: 10px; }
  .portal-nav-item { grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; }
  .portal-nav-item > b { font-size: inherit; font-weight: inherit; }
  .nav-symbol, .portal-nav-item > span { color: inherit; }
  .nav-symbol svg, .portal-nav-item > span svg { width: 18px; height: 18px; }
  a.portal-nav-item:hover, .nav-link:hover { background: var(--dark-surface); color: var(--text); }
  a.portal-nav-item:hover > span, .nav-link:hover .nav-symbol { color: inherit; }
  .nav-link.active, .portal-nav-item.active, a.portal-nav-item.active:hover, .nav-link.active:hover {
    background: var(--primary-bg);
    box-shadow: none;
    color: var(--primary-text);
    font-weight: var(--weight-bold);
  }
  .nav-link.active .nav-symbol, .portal-nav-item.active > span,
  .nav-link.active:hover .nav-symbol, a.portal-nav-item.active:hover > span { color: inherit; }
  .portal-nav-item > small { padding: 1px 7px; border: 0; border-radius: var(--radius-pill); background: var(--dark-surface); color: var(--muted); font-size: .75rem; font-weight: var(--weight-medium); }
  .portal-nav-item.disabled { color: var(--faint); }
  .portal-nav-item.admin-link > span { color: inherit; }

  .sidebar-footer, .portal-sidebar-footer { margin: 12px 0 0; padding: 0; border: 0; }
  .interface-preferences { grid-template-columns: minmax(0, 1fr) 40px; gap: 6px; margin-bottom: 6px; }
  .language-switcher, .portal-language { gap: 2px; padding: 3px; border: 0; border-radius: var(--radius-pill); background: var(--dark-surface); }
  .language-switcher button, .portal-language button { height: 34px; border-radius: var(--radius-pill); color: var(--muted); font-size: var(--font-caption); font-weight: var(--weight-medium); }
  .language-switcher button, .portal-language button { transition: color .14s ease; }
  .language-switcher button:hover, .portal-language button:hover { background: transparent; color: var(--text); box-shadow: none; }
  .language-switcher button.active, .portal-language button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  [data-language-slider]::before {
    top: 3px; bottom: 3px; left: 3px;
    width: calc((100% - 10px) / 3);
    border-radius: var(--radius-pill);
    background: var(--surface);
    box-shadow: var(--shadow);
    transform: translateX(calc(var(--language-index, 0) * (100% + 2px)));
    transition: none;
  }
  [data-language-slider][data-language-moving]::before { transition: transform .22s cubic-bezier(.2, .7, .2, 1); }
  [data-language-slider] button.active, [data-language-slider] button.active:hover { background: transparent; color: var(--blue); font-weight: var(--weight-bold); box-shadow: none; }
  .theme-toggle { width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--dark-surface); color: var(--muted); }
  .theme-toggle[aria-pressed="true"] { border: 0; background: var(--dark-surface); color: var(--muted); }
  .theme-toggle:hover { border: 0; background: var(--dark-surface); color: var(--text); }
  .portal-profile, .sidebar-footer .profile {
    grid-template-columns: 34px minmax(0, 1fr) 18px;
    gap: 10px;
    padding: 8px;
    border: 0;
    border-radius: var(--radius-control);
    background: transparent;
    color: var(--text);
    text-align: left;
    transition: background-color .14s ease;
  }
  .portal-profile:hover, .sidebar-footer .profile:hover { background: var(--dark-surface); }
  .avatar, .profile-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-bg); color: var(--primary-text); font-weight: var(--weight-bold); }
  .profile-copy { min-width: 0; }
  .profile-copy strong, .profile-copy small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .profile-copy strong { font-size: var(--font-small); font-weight: var(--weight-bold); }
  .profile-copy small { color: var(--muted); font-size: .75rem; }
  .account-profile-arrow { color: var(--faint); }

  /* ---- Top of the sheet ---- */
  .topbar, .portal-topbar { min-height: var(--topbar); padding: 10px var(--page-gutter); border-bottom: 1px solid var(--line); background: var(--glass-bg); backdrop-filter: blur(14px) saturate(1.4); }
  .topbar-title small { display: none; }
  .topbar-title strong, .topbar-context b { font-size: var(--font-small); font-weight: var(--weight-medium); color: var(--muted); }
  .portal-topbar .topbar-colleagues { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); }
  .portal-topbar .topbar-colleagues:hover, .portal-topbar .topbar-colleagues[aria-expanded="true"] { background: var(--surface-soft); color: var(--text); }
  .portal-topbar .topbar-colleagues svg { width: 22px; height: 22px; }
  /* A top-bar button that leads to a page (Notes) shows that page is open, like the current menu item. */
  .portal-topbar .topbar-colleagues[aria-current="page"] { background: var(--surface-blue); color: var(--blue); }
  .admin-pill { padding: 3px 10px; border-radius: var(--radius-pill); background: var(--surface-soft); color: var(--muted); font-size: .75rem; font-weight: var(--weight-medium); letter-spacing: 0; }

  .page, .portal-content { padding: var(--space-8) var(--page-gutter) 64px; }
  .heading, .portal-page-heading { align-items: flex-end; margin-bottom: var(--space-8); }
  .heading h1, .portal-page-heading h1, .instruction-article h1, .form-heading h2 { margin: 0 0 var(--space-2); font-size: var(--font-heading); font-weight: var(--weight-bold); letter-spacing: -.035em; line-height: 1.08; }
  .heading p, .portal-page-heading p { max-width: 62ch; margin: 0; color: var(--muted); font-size: var(--font-body); line-height: 1.5; }
  /* "Back to …" above a page title (ui_back_link()): a pill with a round arrow. On hover the pill turns cobalt
     and the arrow steps toward where it leads; a press gives way slightly, like the other buttons. */
  .back-link {
    display: flex;
    width: fit-content;
    max-width: 100%;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    margin: 0 0 var(--space-3) -4px;
    padding: 4px 14px 4px 4px;
    border-radius: var(--radius-pill);
    color: var(--muted);
    font-size: var(--font-small);
    font-weight: var(--weight-medium);
    line-height: 1.2;
    transition: background-color .1s ease, color .1s ease, transform .12s ease;
  }
  .back-link > span:last-child { min-width: 0; overflow-wrap: anywhere; }
  .back-link-arrow {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--text);
    transition: background-color .1s ease, color .1s ease;
  }
  .back-link-arrow svg { width: 16px; height: 16px; transition: transform .2s cubic-bezier(.2, .9, .3, 1.4); }
  @media (hover: hover) {
    .back-link:hover { background: var(--surface-blue); color: var(--blue); }
    .back-link:hover .back-link-arrow { background: var(--primary-bg); color: var(--primary-text); }
    .back-link:hover .back-link-arrow svg { transform: translateX(-2px); }
  }
  .back-link:focus-visible { color: var(--blue); }
  .back-link:active { transform: scale(.97); }

  /* ---- Panels and tiles ---- */
  .panel, .form-panel, .security-actions { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: none; }
  .workspace-card { padding: 20px; border: 0; border-radius: var(--radius-card); background: var(--surface-soft); }
  .panel-head h2, .section-title h2, .security-action h2, .portal-section-head h2, .card-head h2, .profile-strip h2,
  .dashboard-updates h2, .audit-retention-note h2, .department-card-add h2, .audit-insight header h2, .excel-step h2,
  .department-card h2, .department-card-body h2, .account-profile-header h2, .mobile-sheet-head h2,
  .reminders-calendar-head h2, .reminders-day h2, .reminders-mine h2, .audit-section-title {
    font-size: var(--font-section);
    font-weight: var(--weight-bold);
    letter-spacing: -.025em;
    line-height: 1.2;
    color: var(--text);
  }
  .panel-head a { color: var(--blue); font-size: var(--font-small); font-weight: var(--weight-medium); text-decoration: underline; text-decoration-color: var(--line2); text-underline-offset: 4px; }
  .panel-head a:hover { text-decoration-color: currentColor; }
  .section-title > span, .excel-step span { border-radius: 50%; background: var(--surface-blue); color: var(--blue); font-size: var(--font-caption); font-weight: var(--weight-bold); }
  .excel-step { align-items: center; }
  .excel-step h2 { margin: 0; }

  /* Admin overview: filled tiles without frames; the live figure is the dark one. */
  .stats.stats-sections { gap: 8px; }
  .stats-sections .stat { min-height: 148px; border: 0; border-radius: var(--radius-card); }
  .stat strong { font-size: 2.75rem; font-weight: var(--weight-bold); letter-spacing: -.04em; line-height: 1; }
  .stat small { font-size: var(--font-small); line-height: 1.35; }
  .audit-stat { border-color: transparent; background: var(--surface-soft); }
  .audit-stat > span { color: var(--muted); font-size: var(--font-small); font-weight: var(--weight-medium); }
  .audit-stat strong { font-size: 2.25rem; font-weight: var(--weight-bold); letter-spacing: -.04em; line-height: 1.05; }
  .activity-row i { border-radius: 50%; }
  .activity-row small { text-transform: none; }
  .department-card { border-color: var(--line); border-radius: var(--radius-card); }
  .department-number { font-size: var(--font-section); font-weight: var(--weight-bold); letter-spacing: -.02em; color: var(--text); }

 /* ---- Controls ---- */
  .primary, .secondary, .login-card button {
    padding: 10px 20px;
    border-radius: var(--radius-pill);
    font-size: var(--font-body);
    font-weight: var(--weight-bold);
    line-height: 1.2;
    transition: background-color .1s ease, border-color .1s ease, color .1s ease, transform .12s ease;
  }
  .secondary { border: 1px solid var(--line2); background: var(--surface); color: var(--text); }
  .secondary:hover { border-color: var(--text); background: var(--surface); }
  .field input, .field select, .inline-form input, .login-card input, .instruction-filterbar select, .audit-filter input, .audit-filter select, .field textarea, .instruction-language-card textarea, .instruction-editor-block textarea, .ui-select-trigger {
    border: 1px solid var(--line2);
    border-radius: var(--radius-control);
    background: var(--surface);
    transition: border-color .14s ease, box-shadow .14s ease;
  }
  .ui-select-trigger { font-size: var(--font-body); }
  .ui-select-list { border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--shadow-float); }
  .ui-select-option { border-radius: var(--radius-sm); font-size: var(--font-body); }
  .ui-select-option[aria-selected="true"] { color: var(--text); font-weight: var(--weight-bold); }
  .ui-select-option.is-highlighted { box-shadow: none; }
  .field > span, .login-card label span, .audit-filter > span { color: var(--text); font-size: var(--font-small); font-weight: var(--weight-medium); }
  .search, .instruction-search { border: 0; border-radius: var(--radius-pill); background: var(--surface-soft); }
  .search > svg, .instruction-search > svg { flex-shrink: 0; color: var(--muted); }

  :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline: 2px solid var(--focus-outline); outline-offset: 2px; }
  :where(.sidebar, .portal-sidebar, .mobile-sheet-panel, .brand-panel) :focus-visible { outline-color: var(--focus-outline); }
  :where(input, select, textarea):focus { border-color: var(--text); box-shadow: var(--focus-ring); }
  .search:focus-within, .instruction-search:focus-within { box-shadow: var(--focus-ring); }
  .ui-select-trigger[aria-expanded="true"] { border-color: var(--text); box-shadow: var(--focus-ring); }
  ::selection { background: var(--primary-bg); color: #fff; }

  .switch { border-radius: 999px; }
  .switch::after { border-radius: 50%; }
  .toggle-card { border-radius: var(--radius-card); }
  .toggle-card input:checked + .switch { background: var(--primary-bg); }
  .favorite-link, .favorite-choice { border-radius: var(--radius-control); }
  .favorite-link > span:last-child { color: var(--faint); }
  .favorite-code { border-radius: 50%; width: 40px; background: var(--surface-blue); color: var(--blue); font-size: .75rem; font-weight: var(--weight-bold); }

  /* ---- Tables ---- */
  .admin-table th { padding: 10px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: var(--font-small); font-weight: var(--weight-medium); }
  .admin-table td { font-size: var(--font-small); }
  .admin-table tbody tr:hover { background: var(--surface-soft); }
  .pill { padding: 2px 10px; border-radius: var(--radius-pill); background: var(--surface-blue); }
  .pill-admin { background: var(--primary-bg); color: var(--primary-text); }

  /* ---- Lists and tags ---- */
  .catalog-badge, .instruction-category, .excel-file-label { padding: 2px 10px; border-radius: var(--radius-pill); background: var(--surface-blue); color: var(--blue); font-size: var(--font-caption); font-weight: var(--weight-medium); letter-spacing: 0; }
  .instruction-featured { color: var(--danger); font-size: var(--font-caption); font-weight: var(--weight-bold); }
  .instruction-featured { padding: 1px 8px; border-radius: var(--radius-pill); background: var(--danger-bg); color: var(--danger); font-family: var(--font-sans); font-size: var(--font-caption); font-weight: var(--weight-medium); letter-spacing: 0; vertical-align: 2px; }

  /* Lists to read: grouped under plain headings, framed, a line between rows. */
  .instruction-groups { display: grid; gap: var(--space-8); max-width: var(--list-width); }
  .instruction-group h2 { margin: 0 0 var(--space-3); font-size: var(--font-section); }
  .instruction-group h2 span { margin-left: 4px; color: var(--muted); font-size: var(--font-body); font-weight: var(--weight-medium); letter-spacing: 0; }
  .instruction-grid { border: 1px solid var(--list-border); border-radius: var(--radius-card); background: var(--list-bg); overflow: hidden; }
  .instruction-card { display: grid; grid-template-columns: minmax(0, 1fr) 20px; align-items: center; gap: var(--space-4); padding: 16px 18px; color: var(--text); transition: background-color .14s ease; }
  .instruction-card + .instruction-card { border-top: 1px solid var(--list-border); }
  .instruction-card:hover { background: var(--list-hover); }
  .instruction-card:focus-visible { outline-offset: -3px; border-radius: var(--radius-card); }
  .instruction-card h3 { margin: 0; font-size: var(--font-title); font-weight: var(--weight-bold); letter-spacing: -.015em; line-height: 1.3; }
  .instruction-card p { max-width: 75ch; margin: 3px 0 0; color: var(--muted); font-size: var(--font-body); line-height: 1.45; }
  .instruction-card-date { display: block; margin-top: 6px; color: var(--muted); font-size: var(--font-small); }
  .instruction-card-chevron { color: var(--faint); transition: transform .14s ease, color .14s ease; }
  .instruction-card:hover .instruction-card-chevron { color: var(--text); transform: translateX(2px); }
  .instruction-heading-count { display: flex; align-items: baseline; gap: 6px; flex-shrink: 0; min-width: 0; color: var(--muted); font-size: var(--font-body); text-align: left; }
  .instruction-heading-count strong { color: var(--text); font-size: var(--font-title); font-weight: var(--weight-bold); letter-spacing: 0; }
  .instruction-heading-count span { color: var(--muted); font-size: var(--font-body); }
  .instruction-filterbar { display: flex; flex-wrap: wrap; gap: var(--space-2); padding: 0; margin-bottom: var(--space-6); }
  .instruction-filterbar > .instruction-search { flex: 1 1 280px; }
  .instruction-filterbar > .ui-select, .instruction-filterbar > select { flex: 0 1 220px; }
  .instruction-search { height: var(--control-height); padding: 0 14px; grid-template-columns: 22px 1fr; }
  .instruction-search input { background: transparent; }
  .instruction-article-meta { margin-bottom: var(--space-3); }


  /* ---- Phones ---- */
  @media (max-width: 900px) {
    .mobile-tabbar { inset: auto 12px calc(12px + env(safe-area-inset-bottom, 0px)); padding: 5px; border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--floating-bg); box-shadow: var(--shadow-float); backdrop-filter: blur(16px) saturate(1.4); }
    .mobile-tab { min-height: 48px; padding-inline: 2px; border-radius: var(--radius-pill); color: var(--muted); }
    .mobile-tab b { font-size: .75rem; font-weight: var(--weight-medium); letter-spacing: 0; }
    .mobile-tab.active { background: var(--primary-bg); color: var(--primary-text); }
    .mobile-sheet-panel {
      --on-dark: var(--text);
      --on-dark-muted: var(--muted);
      --on-dark-faint: var(--muted);
      --dark-line: var(--line);
      --dark-surface: var(--surface-soft);
      --accent-soft: var(--surface-soft);
      --cyan: var(--text);
      border-radius: var(--radius-lg) var(--radius-lg) 0 0;
      background: var(--surface);
      box-shadow: var(--shadow-float);
    }
    .mobile-sheet-backdrop { background: rgba(10, 30, 70, .35); backdrop-filter: blur(4px); }
    .mobile-sheet-close { border: 0; border-radius: 50%; }
    .mobile-sheet-grid { gap: 6px; }
    .mobile-sheet-tile { min-height: 84px; border: 0; border-radius: var(--radius-card); background: var(--surface-soft); color: var(--text); }
    .mobile-sheet-tile > span { width: auto; height: auto; background: transparent; color: var(--muted); }
    .mobile-sheet-tile b { font-size: var(--font-body); font-weight: var(--weight-bold); }
    .mobile-sheet-tile.active { background: var(--primary-bg); color: var(--primary-text); }
    .mobile-sheet-tile.active > span { color: inherit; }
    .mobile-sheet-tile .mobile-nav-dot { border-color: var(--surface-soft); }
    .mobile-sheet-footer { margin: 12px 0 0; padding: 12px 0 0; }
    .topbar, .portal-topbar { position: sticky; top: 0; padding-left: var(--page-gutter); padding-right: var(--page-gutter); }
    .portal-content { padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)); }
  }
  @media (max-width: 760px) {
    .heading, .portal-page-heading { align-items: stretch; margin-bottom: var(--space-6); }
    .instruction-filterbar { display: grid; grid-template-columns: 1fr; }
  }
}

/* Instruction delete: a danger button in the editor and the dialog, a text action in the list. */
@layer components {
  .button-danger, .button-danger:hover { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger); }
  .button-danger:hover { border-color: var(--danger); }
  .form-actions .instruction-delete-open { margin-right: auto; }
  /* Row actions in admin lists: real buttons, so they can be found at a glance. The motion answers the pointer:
     the button lifts and fills with colour, the pencil tilts, the bin opens its lid. */
  .table-action, td.actions { white-space: nowrap; text-align: right; }
  .row-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 6px 14px 6px 11px;
    border: 0;
    border-radius: var(--radius-pill);
    background: var(--surface-blue);
    color: var(--blue);
    font: inherit;
    font-size: var(--font-small);
    font-weight: var(--weight-bold);
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .16s ease, color .16s ease, box-shadow .16s ease, transform .16s cubic-bezier(.2, .9, .3, 1.3);
  }
  .row-action + .row-action { margin-left: 6px; }
  .row-action svg { flex-shrink: 0; width: 17px; height: 17px; transition: transform .22s cubic-bezier(.2, .9, .3, 1.5); }
  .row-action:hover, .row-action:focus-visible {
    background: var(--primary-bg);
    color: var(--primary-text);
    box-shadow: 0 6px 16px color-mix(in srgb, var(--primary-bg) 35%, transparent);
    transform: translateY(-1px);
  }
  .row-action:hover svg, .row-action:focus-visible svg { transform: rotate(-12deg) scale(1.08); }
  .row-action:active { box-shadow: none; transform: scale(.96); }

  .row-action-danger { background: var(--danger-bg); color: var(--danger); }
  .row-action-danger:hover, .row-action-danger:focus-visible {
    background: var(--danger-solid);
    color: #fff;
    box-shadow: 0 6px 16px color-mix(in srgb, var(--danger-solid) 35%, transparent);
  }
  .row-action-danger:hover svg, .row-action-danger:focus-visible svg { transform: none; }
  .icon-lid { transform-box: fill-box; transform-origin: 15% 100%; transition: transform .22s cubic-bezier(.2, .9, .3, 1.5); }
  .row-action-danger:hover .icon-lid, .row-action-danger:focus-visible .icon-lid,
  .button-danger:hover .icon-lid, .button-danger:focus-visible .icon-lid { transform: translateY(-1.5px) rotate(-14deg); }
  .button-danger svg { flex-shrink: 0; width: 17px; height: 17px; }

  /* Narrow screens: the actions stay in view at the edge of the table while the rest scrolls under them.
     Where two buttons would not fit, they shrink to their icons; the label stays as a tooltip and for screen readers. */
  @media (max-width: 1400px) {
    .table-action, td.actions { position: sticky; right: 0; z-index: 1; background: var(--surface); }
    .table-action .row-action { width: 36px; padding: 0; justify-content: center; }
    .table-action .row-action span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  }
  @media (max-width: 760px) {
    td.actions .row-action { width: 36px; padding: 0; justify-content: center; }
    td.actions .row-action span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
    .table-action, td.actions { padding-left: 8px; padding-right: 4px; box-shadow: -10px 0 10px -10px var(--shadow-color); }
  }

  /* Short labels in table cells never break into letters when the action buttons take their room. */
  .admin-table .pill, .admin-table .status, .instruction-lang-badges span, .instruction-admin-date strong { overflow-wrap: normal; white-space: nowrap; }
  .instruction-lang-badges { flex-wrap: nowrap; }
  .instruction-lang-badges span { flex-shrink: 0; }
  .instruction-admin-table th, .instruction-admin-table td { padding-left: 8px; padding-right: 8px; }

  .department-card-footer .row-action { flex-shrink: 0; }
  details[open] > summary .category-edit-label { background: var(--primary-bg); color: var(--primary-text); }
  .instruction-delete-dialog { width: min(480px, calc(100% - 32px)); }
  .instruction-delete-dialog[open] > form { display: flex; flex-direction: column; min-height: 0; }
  .instruction-delete-name { display: block; font-size: var(--font-title); font-weight: var(--weight-bold); line-height: 1.3; overflow-wrap: anywhere; }
  .instruction-delete-dialog p { margin: var(--space-2) 0 0; color: var(--muted); line-height: 1.5; }
}


/* Search in the top bar: a real field that widens in place and drops a list under itself.
   No backdrop and no page lock: the person never loses sight of the page they are on. */
@layer components {
  .global-search { position: relative; flex: 0 1 auto; width: 240px; min-width: 0; transition: width .24s cubic-bezier(.2, .8, .2, 1); }
  .global-search.is-open { width: min(460px, 46vw); }
  .topbar > .global-search { margin-left: auto; }
  .topbar > .global-search + .topbar-right { margin-left: 0; }

  .global-search-field {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 6px 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    background: var(--surface-soft);
    color: var(--muted);
    cursor: text;
    transition: background-color .14s ease, border-color .14s ease, box-shadow .14s ease;
  }
  .global-search-field:hover { background: var(--surface-blue); }
  .global-search.is-open .global-search-field { border-color: var(--blue); background: var(--surface); box-shadow: var(--focus-ring); }
  .global-search-field > svg { flex-shrink: 0; }
  .global-search-field input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    box-shadow: none;
    color: var(--text);
    font-size: var(--font-small);
    appearance: none;
  }
  .global-search-field input:focus, .global-search-field input:focus-visible { border: 0; outline: 0; box-shadow: none; }
  .global-search-field input::-webkit-search-cancel-button { display: none; }
  .global-search-field kbd { flex-shrink: 0; padding: 3px 8px; border: 0; border-radius: var(--radius-pill); background: var(--surface); color: var(--muted); font-family: var(--font-sans); font-size: .75rem; white-space: nowrap; }
  .global-search.is-open .global-search-field kbd { display: none; }
  .global-search-close { display: none; }

  .global-search-panel {
    position: absolute;
    z-index: 60;
    top: calc(100% + 8px);
    right: 0;
    width: 100%;
    min-width: 340px;
    max-height: min(520px, calc(100dvh - 96px));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    background: var(--surface);
    box-shadow: var(--shadow-float);
    transform-origin: top center;
  }
  .global-search.is-open .global-search-panel { animation: global-search-drop .26s cubic-bezier(.16, 1, .3, 1) both; }
  .global-search.is-closing .global-search-panel { animation: global-search-rise .15s ease-in both; pointer-events: none; }
  @keyframes global-search-drop { from { opacity: 0; transform: translateY(-10px) scaleY(.92); } }
  @keyframes global-search-rise { to { opacity: 0; transform: translateY(-6px) scaleY(.97); } }

  .global-search-group + .global-search-group { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--line); }
  .global-search-label { display: block; padding: 8px 10px 4px; color: var(--muted); font-size: var(--font-caption); font-weight: var(--weight-medium); }
  .global-search-item {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--radius-control);
    color: var(--text);
    scroll-margin: 6px;
  }
  .global-search-item[hidden] { display: none; }
  a.global-search-item:hover, .global-search-item.is-active { background: var(--surface-blue); }
  .global-search-item.is-disabled { color: var(--muted); }
  .global-search-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-blue); color: var(--blue); }
  a.global-search-item:hover .global-search-icon, .global-search-item.is-active .global-search-icon { background: var(--primary-bg); color: var(--primary-text); }
  .global-search-icon svg { width: 18px; height: 18px; }
  .global-search-copy { min-width: 0; }
  .global-search-copy strong, .global-search-copy small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .global-search-copy strong { font-size: var(--font-small); font-weight: var(--weight-bold); line-height: 1.35; }
  .global-search-copy small { color: var(--muted); font-size: var(--font-caption); line-height: 1.35; }
  .global-search-copy mark { border-radius: 2px; background: var(--surface-blue); color: var(--blue); }
  a.global-search-item:hover mark, .global-search-item.is-active mark { background: transparent; }
  .global-search-soon { padding: 1px 8px; border-radius: var(--radius-pill); background: var(--surface-soft); color: var(--muted); font-size: .75rem; font-weight: var(--weight-medium); }
  .global-search-more { display: block; padding: 8px 10px; border-radius: var(--radius-control); color: var(--blue); font-size: var(--font-small); font-weight: var(--weight-medium); }
  .global-search-more:hover { background: var(--surface-blue); }
  .global-search-status { padding: 14px 10px; color: var(--muted); font-size: var(--font-small); }

  /* Phones: the field covers the top bar while open, the list hangs under the bar at full width. */
  @media (max-width: 900px) {
    .global-search, .global-search.is-open { position: static; width: auto; transition: none; }
    .global-search:not(.is-open):not(.is-closing) { display: none; }
    .global-search.is-open ~ * { visibility: hidden; }
    .global-search.is-closing .global-search-field { display: none; }
    .global-search-field { position: absolute; z-index: 2; inset: 12px var(--page-gutter) auto; }
    .global-search-field input { font-size: 1rem; }
    .global-search-close { display: grid; place-items: center; flex-shrink: 0; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: var(--surface-soft); color: var(--muted); cursor: pointer; }
    .global-search-panel { top: calc(100% + 6px); left: var(--page-gutter); right: var(--page-gutter); width: auto; min-width: 0; max-height: calc(100dvh - var(--topbar) - 104px); }
    .global-search-item { padding: 9px 10px; }
  }
}

/* Search on list pages: the same field as in the top bar, the list below it updates while typing. */
@layer components {
  .portal-page-heading:has(~ .list-results), .heading:has(~ .list-results), .instruction-filterbar:has(~ .list-results), .list-results > .instruction-empty { max-width: var(--list-width); }
  .instruction-filterbar { flex-wrap: wrap; }
  .instruction-filterbar > .instruction-search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 6px 0 14px; border: 1px solid transparent; transition: background-color .14s ease, border-color .14s ease, box-shadow .14s ease; }
  .instruction-filterbar > .instruction-search:hover { background: var(--surface-blue); }
  .instruction-filterbar > .instruction-search:focus-within { border-color: var(--blue); background: var(--surface); box-shadow: var(--focus-ring); }
  .instruction-search input { flex: 1 1 auto; width: 100%; min-width: 0; height: 100%; min-height: 0; padding: 0; border: 0; background: transparent; box-shadow: none; color: var(--text); font-size: var(--font-body); appearance: none; }
  .instruction-search input:focus, .instruction-search input:focus-visible { border: 0; outline: 0; box-shadow: none; }
  .instruction-search input::-webkit-search-cancel-button { display: none; }
  .instruction-search-clear { display: grid; place-items: center; flex-shrink: 0; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
  .instruction-search-clear:hover { background: var(--surface-blue); color: var(--text); }
  .instruction-search-clear[hidden] { display: none; }
  [data-live-region] { transition: opacity .12s ease; }
  /* Only slow answers dim the list, so fast typing does not make it flicker. */
  [data-live-region].is-updating { opacity: .7; transition: opacity .2s ease .4s; }
  [data-live-region] mark { border-radius: 2px; background: var(--surface-blue); color: var(--blue); }
  .audit-toolbar { align-items: center; gap: var(--space-4); }
  .audit-reset { margin-right: auto; color: var(--blue); font-size: var(--font-small); font-weight: var(--weight-medium); }
  .audit-reset:hover { text-decoration: underline; text-underline-offset: 3px; }
}

/* Small motion across the site. Rules for all of it: only transform and opacity, each effect plays once
   and stops, nothing runs while the page is idle, hover effects only on devices with a real pointer. */
@layer components {
  /* A slow answer from the server: a line at the top, shown only after a delay (motion.js sets the flag). */
  :root[data-navigating] body::after {
    content: "";
    position: fixed;
    inset: 0 0 auto;
    z-index: 300;
    height: 3px;
    background: var(--blue);
    transform-origin: left;
    pointer-events: none;
    animation: nav-progress 8s cubic-bezier(.08, .7, .2, 1) .18s both;
  }
  @keyframes nav-progress { from { transform: scaleX(0); } to { transform: scaleX(.94); } }

  /* How far through an instruction the reader is. Scrolling drives it, so it costs nothing at rest. */
  @supports (animation-timeline: scroll()) {
    .instruction-article::before {
      content: "";
      position: fixed;
      inset: 0 0 auto;
      z-index: 40;
      height: 3px;
      background: var(--blue);
      transform: scaleX(0);
      transform-origin: left;
      pointer-events: none;
      animation: reading-progress linear both;
      animation-timeline: scroll(root);
    }
    @keyframes reading-progress { to { transform: scaleX(1); } }
  }

  /* A press answers at once, on any device. */
  .primary:active:not(:disabled), .secondary:active:not(:disabled) { transform: scale(.97); }
  .nav-link:active, a.portal-nav-item:active { transform: scale(.985); }

  /* Things that open. */
  .ui-select-list:not([hidden]) { animation: menu-drop .14s cubic-bezier(.2, .8, .2, 1); }
  .reminders-completed[open] > :not(summary), .notification-snooze[open] > :not(summary), .category-item[open] > :not(summary) { animation: reveal-in .18s ease-out; }
  @keyframes menu-drop { from { opacity: 0; transform: translateY(-4px); } }
  @keyframes reveal-in { from { opacity: 0; transform: translateY(4px); } }

  /* The result of an action: success arrives, an error shakes once. */
  .flash { animation: reveal-in .26s cubic-bezier(.2, .8, .2, 1); }
  .flash-error, .form-errors { animation: notice-shake .42s ease-out; }
  @keyframes notice-shake {
    20% { transform: translateX(-6px); }
    45% { transform: translateX(5px); }
    70% { transform: translateX(-3px); }
    88% { transform: translateX(2px); }
  }

  .nav-symbol svg, .portal-nav-item > span svg { transition: transform .18s cubic-bezier(.2, .9, .3, 1.4); }
  .brand-logo { transition: transform .22s cubic-bezier(.2, .9, .3, 1.4); }
  .topbar-notifications svg { transform-origin: 50% 10%; }
  /* A new notification rings the bell whatever the pointer does. */
  .topbar-notifications:has(.notification-badge.is-new) svg { animation: bell-ring .6s ease-in-out; }
  @keyframes bell-ring {
    20% { transform: rotate(14deg); }
    45% { transform: rotate(-11deg); }
    70% { transform: rotate(6deg); }
    88% { transform: rotate(-3deg); }
  }
  @media (hover: hover) {
    .nav-link:hover .nav-symbol svg, a.portal-nav-item:hover > span svg { transform: scale(1.12); }
    .brand-lockup:hover .brand-logo { transform: rotate(-6deg) scale(1.04); }
    .topbar-notifications:hover svg { animation: bell-ring .6s ease-in-out; }
  }

  /* Every opening of a page (motion.js sets data-intro): the title and the lists to read rise into place once.
     The back link sits inside the heading and rises with it. */
  :root[data-intro] :is(.heading, .portal-page-heading, .form-heading) { animation: rise-in .32s cubic-bezier(.2, .8, .2, 1) backwards; }
  /* A list the live search refills rises as one piece: the region itself is never replaced, so typing does not replay it. */
  :root[data-intro] .list-results[data-live-region] { animation: rise-in .34s cubic-bezier(.2, .8, .2, 1) .07s backwards; }
  @keyframes rise-in { from { opacity: 0; transform: translateY(8px); } }

  /* The phone menu sheet: its tiles follow the panel up, one after another. */
  .mobile-sheet:not(.is-closing, .is-instant) .mobile-sheet-tile { animation: rise-in .28s cubic-bezier(.2, .8, .2, 1) .04s backwards; }
  .mobile-sheet:not(.is-closing, .is-instant) .mobile-sheet-tile:nth-child(2) { animation-delay: .07s; }
  .mobile-sheet:not(.is-closing, .is-instant) .mobile-sheet-tile:nth-child(3) { animation-delay: .1s; }
  .mobile-sheet:not(.is-closing, .is-instant) .mobile-sheet-tile:nth-child(4) { animation-delay: .13s; }
  .mobile-sheet:not(.is-closing, .is-instant) .mobile-sheet-tile:nth-child(n+5) { animation-delay: .16s; }

  /* Icons inside buttons and links answer the pointer; the button itself stays still. */
  /* An icon keeps its size when a long label or a narrow row squeezes the button. */
  :is(.primary, .secondary, .with-icon) > svg { flex: none; }
  :is(.primary, .secondary, .with-icon) > svg, .favorite-code, .favorite-link > span:last-child, .global-search-icon svg { transition: transform .18s cubic-bezier(.2, .9, .3, 1.4); }
  .favorite-link:active, .toggle-card:active, a.global-search-item:active { transform: scale(.985); }
  .favorite-link, .toggle-card, a.global-search-item { transition: background-color .12s ease, border-color .12s ease, transform .12s ease; }
  @media (hover: hover) {
    :is(.primary, .secondary, .with-icon):hover:not(:disabled) > svg { transform: scale(1.12); }
    .favorite-link:hover .favorite-code { transform: scale(1.08); }
    .favorite-link:hover > span:last-child { transform: translateX(2px); }
    a.global-search-item:hover .global-search-icon svg, .global-search-item.is-active .global-search-icon svg { transform: scale(1.1); }
  }
  /* "Customise" in the overview: the gear turns by one tooth. */
  .favorites-edit:is(:hover, :focus-visible) svg { transform: rotate(45deg); }
}

/* Moving between pages: the old page holds until the new one is ready, then the content simply fades in.
   The menu and the top bar stay put; the menu highlight changes items in the same short crossfade.
   Movement comes from the page entrance itself (data-intro), so nothing slides here. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; types: page-change; }
  /* Unlayered, so it must exclude the theme switch or it would override the slow reveal above. */
  :root:not([data-theme-snapshot])::view-transition-old(root), :root:not([data-theme-snapshot])::view-transition-new(root) { animation-duration: .12s; }
  /* The names exist only while moving between pages, so the theme switch still captures the page as one piece. */
  :root:active-view-transition-type(page-change) :is(.portal-content, .page) { view-transition-name: page-content; }
  /* Both bars swap their blur for a solid fill for this moment: blur is the costliest effect, and the browser would draw it as a square behind the rounded bar. */
  :root:active-view-transition-type(page-change) :is(.portal-topbar, .topbar) { view-transition-name: page-topbar; backdrop-filter: none; background: var(--surface); }
  :root:active-view-transition-type(page-change) .mobile-tabbar { view-transition-name: page-tabbar; backdrop-filter: none; background: var(--surface); }
  ::view-transition-group(page-content), ::view-transition-group(page-topbar), ::view-transition-group(page-tabbar) { animation: none; }
  ::view-transition-old(page-content), ::view-transition-old(page-topbar), ::view-transition-old(page-tabbar) { display: none; }
  ::view-transition-new(page-topbar), ::view-transition-new(page-tabbar) { animation: none; }
  ::view-transition-new(page-content) { animation: page-in .16s ease-out both; }
  @keyframes page-in { from { opacity: 0; } }
}

/* Icon micro-motion. The moving parts are classed in the markup (ui_icon() in app/ui.php and a few inline icons):
   the flag cloth, the pen of the notes icon, each person of the people icons, the plus and the two strokes of
   the close cross, and in the file actions the arrows, the two links of the chain, the circle of arrows, the pupil
   and the undo arrow. A hover or keyboard focus on the link or button plays the effect once; at rest every icon
   looks as before. Only transform and opacity move; reduced motion switches it all off above. */
@layer components {
  .icon-flag-cloth, .icon-pen-ink, .icon-person-mid, .icon-person-left, .icon-person-right, .icon-plus, .icon-x-a, .icon-x-b,
  .icon-arrow-up, .icon-arrow-down, .icon-link-a, .icon-link-b, .icon-spin, .icon-pupil, .icon-undo,
  .icon-check, .icon-minus, .icon-send, .icon-arrow-in, .icon-arrow-out, .icon-key, .icon-check-a, .icon-check-b { transform-box: fill-box; }
  /* Each stroke of the tick grows from its own start. */
  .icon-check-a, .icon-check-b { transform-origin: 0 50%; }
  /* The cloth waves from its edge on the pole; the ink is drawn from its start. */
  .icon-flag-cloth, .icon-pen-ink { transform-origin: 0 50%; }
  .icon-person-mid, .icon-person-left, .icon-person-right { transform-origin: 50% 100%; }
  .icon-plus, .icon-x-a, .icon-x-b, .icon-spin, .icon-pupil, .icon-undo, .icon-check, .icon-minus { transform-origin: 50% 50%; }
  /* The key turns around its bow; the clock hand around the centre of the dial. */
  .icon-key { transform-origin: 20% 80%; }
  .icon-clock-hand { transform-box: view-box; transform-origin: 12px 12px; }
  /* The pen and its ink are hidden at rest (their opacity attribute does the same without CSS) and fade on leave. */
  .icon-pen, .icon-pen-ink { opacity: 0; transition: opacity .12s ease; }

  :is(a, button:not(:disabled)):focus-visible .icon-flag-cloth { animation: icon-flag-wave .8s ease-in-out; }
  :is(a, button:not(:disabled)):focus-visible :is(.icon-pen, .icon-pen-ink) { opacity: 1; }
  :is(a, button:not(:disabled)):focus-visible .icon-pen { animation: icon-pen-write .62s ease-in-out; }
  :is(a, button:not(:disabled)):focus-visible .icon-pen-ink { animation: icon-pen-ink .62s ease-in-out; }
  :is(a, button:not(:disabled)):focus-visible .icon-person-mid { animation: icon-person-hop .6s ease-out; }
  :is(a, button:not(:disabled)):focus-visible .icon-person-left { animation: icon-person-lean-in .6s ease-out .06s; }
  :is(a, button:not(:disabled)):focus-visible .icon-person-right { animation: icon-person-lean-in-mirror .6s ease-out .06s; }
  /* The close cross stays still and turns red at once, while its whole button fills with soft red: a circle under the
     content grows from the middle until it covers the button (only its scale moves; the button's rounded edge clips
     it). The circle is wider than the button by 24px, enough to reach the corners of a square close button too.
     Leaving does not play it backwards: the fill only fades out, and its size resets once it is gone.
     Red here is the one agreed exception to "red only for alarms". */
  :is(a, button):has(> svg .icon-x-a)::before { content: ""; position: absolute; top: 50%; left: 50%; z-index: -1; width: calc(100% + 24px); aspect-ratio: 1; border-radius: 50%; background: var(--danger-bg); opacity: 0; transform: translate(-50%, -50%) scale(0); transition: opacity .12s ease-out, transform 0s .12s; pointer-events: none; }
  :is(a, button:not(:disabled)):has(> svg .icon-x-a):focus-visible::before { transform: translate(-50%, -50%) scale(1); opacity: 1; transition: transform .5s cubic-bezier(.4, 0, .2, 1), opacity 0s; }
  :is(a, button:not(:disabled)):has(> svg .icon-x-a):focus-visible { border-color: var(--danger-line); }
  :is(a, button:not(:disabled)):focus-visible :is(.icon-x-a, .icon-x-b) { stroke: var(--danger); }
  /* Buttons and links with an icon: .primary, .secondary and .with-icon (chips, the login button, block arrows).
     A file picker is a label; its hidden input holds the focus. */
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-plus, .icon-minus) { animation: icon-plus-pop .4s cubic-bezier(.2, .9, .3, 1.4); }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg .icon-check-a { animation: icon-check-draw-a .46s linear; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg .icon-check-b { animation: icon-check-draw-b .46s linear; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-arrow-up) { animation: icon-arrow-up .5s ease-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-arrow-down) { animation: icon-arrow-down .5s ease-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-link-a) { animation: icon-link-a .45s ease-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-link-b) { animation: icon-link-b .45s ease-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-spin) { animation: icon-spin .55s cubic-bezier(.3, .8, .3, 1); }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-pupil) { animation: icon-pupil-glance .6s ease-in-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-undo) { animation: icon-undo-turn .45s ease-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-send) { animation: icon-send-fly .5s ease-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-arrow-in, .icon-arrow-out) { animation: icon-nudge-x .45s ease-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-key) { animation: icon-key-turn .5s ease-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg :is(.icon-clock-hand) { animation: icon-clock-spin .7s ease-in-out; }
  :is(:is(.primary, .secondary, .with-icon):not(:disabled):focus-visible, label:has(input:focus-visible)) > svg .icon-lid { transform: translateY(-1.5px) rotate(-14deg); }
  @media (hover: hover) {
    :is(a, button:not(:disabled)):hover .icon-flag-cloth { animation: icon-flag-wave .8s ease-in-out; }
    :is(a, button:not(:disabled)):hover :is(.icon-pen, .icon-pen-ink) { opacity: 1; }
    :is(a, button:not(:disabled)):hover .icon-pen { animation: icon-pen-write .62s ease-in-out; }
    :is(a, button:not(:disabled)):hover .icon-pen-ink { animation: icon-pen-ink .62s ease-in-out; }
    :is(a, button:not(:disabled)):hover .icon-person-mid { animation: icon-person-hop .6s ease-out; }
    :is(a, button:not(:disabled)):hover .icon-person-left { animation: icon-person-lean-in .6s ease-out .06s; }
    :is(a, button:not(:disabled)):hover .icon-person-right { animation: icon-person-lean-in-mirror .6s ease-out .06s; }
    :is(a, button:not(:disabled)):hover :is(.icon-x-a, .icon-x-b) { stroke: var(--danger); }
    /* The cross itself stays still: no shared icon growth on it, only the colour and the fill. */
    :is(.primary, .secondary, .with-icon):hover:not(:disabled) > svg:has(.icon-x-a) { transform: none; }
    :is(a, button:not(:disabled)):has(> svg .icon-x-a):hover::before { transform: translate(-50%, -50%) scale(1); opacity: 1; transition: transform .5s cubic-bezier(.4, 0, .2, 1), opacity 0s; }
    :is(a, button:not(:disabled)):has(> svg .icon-x-a):hover { border-color: var(--danger-line); }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-plus, .icon-minus) { animation: icon-plus-pop .4s cubic-bezier(.2, .9, .3, 1.4); }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg .icon-check-a { animation: icon-check-draw-a .46s linear; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg .icon-check-b { animation: icon-check-draw-b .46s linear; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-arrow-up) { animation: icon-arrow-up .5s ease-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-arrow-down) { animation: icon-arrow-down .5s ease-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-link-a) { animation: icon-link-a .45s ease-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-link-b) { animation: icon-link-b .45s ease-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-spin) { animation: icon-spin .55s cubic-bezier(.3, .8, .3, 1); }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-pupil) { animation: icon-pupil-glance .6s ease-in-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-undo) { animation: icon-undo-turn .45s ease-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-send) { animation: icon-send-fly .5s ease-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-arrow-in, .icon-arrow-out) { animation: icon-nudge-x .45s ease-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-key) { animation: icon-key-turn .5s ease-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg :is(.icon-clock-hand) { animation: icon-clock-spin .7s ease-in-out; }
    :is(.primary, .secondary, .with-icon):not(:disabled):hover > svg .icon-lid { transform: translateY(-1.5px) rotate(-14deg); }
  }
  /* "Copy link" answers a successful copy once (files.js sets the class for two seconds). */
  .file-copy.is-copied > svg { animation: icon-plus-pop .4s cubic-bezier(.2, .9, .3, 1.4); }

  /* Two waves run along the cloth, then it settles. */
  @keyframes icon-flag-wave {
    15% { transform: skewY(-7deg) scaleX(.94); }
    35% { transform: skewY(5deg) scaleX(1.02); }
    55% { transform: skewY(-4deg) scaleX(.97); }
    75% { transform: skewY(2deg); }
  }
  /* The pen comes in along its own slant to the start of a new line, then writes it while the ink appears. */
  @keyframes icon-pen-write {
    0% { opacity: 0; transform: translate(1.5px, -4px); }
    40% { opacity: 1; transform: translate(-2.5px, 0); }
    100% { opacity: 1; transform: none; }
  }
  @keyframes icon-pen-ink {
    0%, 40% { transform: scaleX(0); }
    100% { transform: none; }
  }
  /* The middle person hops, the ones at the sides lean in towards it. */
  @keyframes icon-person-hop {
    30% { transform: translateY(-2.5px); }
    55% { transform: none; }
    75% { transform: translateY(-1px); }
  }
  @keyframes icon-person-lean-in {
    35% { transform: rotate(9deg); }
    65% { transform: rotate(-3deg); }
    85% { transform: rotate(1deg); }
  }
  @keyframes icon-person-lean-in-mirror {
    35% { transform: rotate(-9deg); }
    65% { transform: rotate(3deg); }
    85% { transform: rotate(-1deg); }
  }
  /* The tick is drawn like a pen stroke: the short stroke speeds up from its start, the long one carries on from
     the corner at that speed and slows to its end. The easing sits in the keyframes, so the pen never pauses. */
  @keyframes icon-check-draw-a {
    0% { transform: scaleX(0); animation-timing-function: cubic-bezier(.5, 0, 1, 1); }
    32%, 100% { transform: none; }
  }
  @keyframes icon-check-draw-b {
    0% { transform: scaleX(0); }
    32% { transform: scaleX(0); animation-timing-function: cubic-bezier(0, 0, .3, 1); }
    100% { transform: none; }
  }
  /* The plus ducks a little and pops back, larger for a moment. */
  @keyframes icon-plus-pop {
    35% { transform: scale(.8); }
    75% { transform: scale(1.15); }
  }
  /* Upload: the arrow lifts out of the tray and settles; download: it drops into the tray. */
  @keyframes icon-arrow-up {
    40% { transform: translateY(-3px); }
    70% { transform: translateY(.5px); }
  }
  @keyframes icon-arrow-down {
    40% { transform: translateY(2.5px); }
    70% { transform: translateY(-.5px); }
  }
  /* The two links of the chain pull apart and click back together. */
  @keyframes icon-link-a {
    40% { transform: translate(1.5px, -1.5px); }
    75% { transform: translate(-.3px, .3px); }
  }
  @keyframes icon-link-b {
    40% { transform: translate(-1.5px, 1.5px); }
    75% { transform: translate(.3px, -.3px); }
  }
  /* Replace: the circle of arrows makes half a turn; it looks the same at the end, so nothing jumps back. */
  @keyframes icon-spin {
    from { transform: none; }
    to { transform: rotate(180deg); }
  }
  /* Preview: the eye glances to one side and the other. */
  @keyframes icon-pupil-glance {
    25% { transform: translateX(-2px); }
    65% { transform: translateX(2px); }
  }
  /* Undo: the arrow swings back a little and returns. */
  @keyframes icon-undo-turn {
    40% { transform: rotate(-24deg); }
    75% { transform: rotate(4deg); }
  }
  /* Send: the plane darts forward a little and comes back. */
  @keyframes icon-send-fly {
    40% { transform: translate(2.5px, -2.5px); }
    70% { transform: translate(-.5px, .5px); }
  }
  /* Sign in and sign out: the arrow pushes through the door once. */
  @keyframes icon-nudge-x {
    40% { transform: translateX(2.5px); }
    70% { transform: translateX(-.5px); }
  }
  /* Password: the key turns in the lock and back. */
  @keyframes icon-key-turn {
    40% { transform: rotate(-20deg); }
    75% { transform: rotate(4deg); }
  }
  /* Snooze: the hand goes round the dial once; a full turn ends where it started. */
  @keyframes icon-clock-spin {
    from { transform: none; }
    to { transform: rotate(360deg); }
  }
}

/* Checkbox (.ui-check on a native input[type=checkbox]): a rounded square that fills with cobalt when checked, while
   its tick is drawn like the tick icon: two strokes (::before short, ::after long), each laid along its own direction,
   grow from their start with scaleX, the long one after the short. Unchecking is instant, without a reverse play.
   The input stays native, so the label, keyboard, form and screen readers work as before. */
@layer components {
  .ui-check { appearance: none; -webkit-appearance: none; position: relative; width: 20px; height: 20px; flex: none; border: 1.5px solid var(--line2); border-radius: calc(var(--radius-sm) - 2px); background: var(--surface); color: var(--primary-text); vertical-align: middle; cursor: pointer; transition: transform .12s ease; }
  .ui-check::before, .ui-check::after { content: ""; position: absolute; height: 2px; border-radius: 1px; background: currentColor; transform-origin: 0 50%; }
  /* Measured inside the border: the short stroke from (3.5, 8.5) down to the corner, the long one up to (13, 5.5). */
  .ui-check::before { left: 3.5px; top: 7.5px; width: 5.2px; transform: rotate(45deg) scaleX(0); }
  .ui-check::after { left: 6.3px; top: 11.3px; width: 9.5px; transform: rotate(-45deg) scaleX(0); }
  .ui-check:checked { border-color: var(--primary-bg); background: var(--primary-bg); }
  .ui-check:checked::before { transform: rotate(45deg) scaleX(1); transition: transform .1s cubic-bezier(.5, 0, 1, 1); }
  .ui-check:checked::after { transform: rotate(-45deg) scaleX(1); transition: transform .2s cubic-bezier(0, 0, .3, 1) .1s; }
  .ui-check:disabled { border-color: var(--line); background: var(--surface-soft); cursor: default; }
  /* Not the text-field focus ring (it would stay after a mouse click); the keyboard gets the usual outline. */
  .ui-check:focus { box-shadow: none; }
  .ui-check:focus-visible { outline: 2px solid var(--focus-outline); outline-offset: 2px; }
  .ui-check:not(:disabled):active { transform: scale(.9); }
  @media (hover: hover) {
    :is(.ui-check:hover, label:hover > .ui-check):not(:disabled, :checked) { border-color: var(--blue); }
  }
}
