/* =============================================================================
   澄 Lucid — shell（外殼）: app bar, vitals deck, page bar, drawer, phone bars,
   the #modal frame, toast, quick command, change-password and the sign-in page.
   Unlayered on purpose: it sits above foundation.css (all in @layer ui.*).
   Desktop > 900px (matches app.js innerWidth checks); phone ≤ 900px.
   ============================================================================= */

/* ----- Page skeleton ----- */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.app-shell { min-height: 100dvh; }
.content { width: 100%; max-width: var(--page-max); min-width: 0; margin: 0 auto; padding: var(--sp-4) var(--gutter) var(--sp-9); }
.view { display: none; min-width: 0; }
.view.active { display: block; }
.view[data-entering] { animation: ui-rise var(--t-slow) var(--ease) both; }
.app-shell[data-entering] { animation: ui-fade var(--t-slow) var(--ease) both; }

/* ----- Brand lockup ----- */
.shell-brand { display: inline-flex; align-items: center; gap: 10px; min-width: 0; color: var(--ink); text-decoration: none; }
button.shell-brand { --btn-bg: transparent; --btn-line: transparent; --btn-bg-hover: transparent; --btn-line-hover: transparent; min-height: 44px; padding: 0 6px 0 0; justify-content: flex-start; }
.shell-brand-mark { width: 36px; height: 36px; flex: none; border-radius: 10px; box-shadow: var(--sh-2); }
.shell-brand-text { display: grid; line-height: 1.15; text-align: left; }
.shell-brand-text strong { color: var(--ink); font-size: var(--fs-16); font-weight: 800; letter-spacing: -.01em; }
.shell-brand-text small { color: var(--ink-3); font-size: var(--fs-12); font-weight: 650; letter-spacing: .02em; }

/* ----- Theme switch: 淺色／深色／跟隨系統 ----- */
.shell-theme { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-3); }
.shell-theme > button {
  --btn-bg: transparent; --btn-line: transparent; --btn-ink: var(--ink-3); --btn-bg-hover: var(--hover-veil); --btn-line-hover: transparent;
  width: 34px; min-width: 34px; min-height: 32px; padding: 0; border-radius: 7px;
}
.shell-theme > button > svg { width: 17px; height: 17px; }
.shell-theme > button > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.shell-theme > button[aria-checked="true"] { --btn-bg: var(--raise); --btn-ink: var(--brand-ink); --btn-bg-hover: var(--raise); box-shadow: var(--sh-1), 0 0 0 1px var(--line); }
.shell-theme.is-labelled { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
.shell-theme.is-labelled > button { width: auto; min-height: 44px; gap: 8px; padding: 0 10px; font-size: var(--fs-14); font-weight: 650; }
.shell-theme.is-labelled > button > span { position: static; width: auto; height: auto; overflow: visible; clip: auto; }

/* ----- Desktop app bar ----- */
.shell-appbar { position: sticky; top: 0; z-index: var(--z-deck); background: var(--deck); border-bottom: 1px solid var(--line-2); }
.shell-appbar-inner { display: flex; align-items: center; gap: var(--sp-4); max-width: var(--page-max); height: var(--appbar-h); margin: 0 auto; padding: 0 var(--gutter); }
.shell-tabs { display: flex; align-items: center; gap: 2px; min-width: 0; }
.shell-tabs > button {
  --btn-bg: transparent; --btn-line: transparent; --btn-ink: var(--ink-2); --btn-bg-hover: var(--hover-veil); --btn-line-hover: transparent;
  position: relative; gap: 7px; min-height: 40px; padding: 0 12px; font-size: var(--fs-15); font-weight: 650; white-space: nowrap;
}
.shell-tabs > button > svg { width: 19px; height: 19px; }
.shell-tabs > button[aria-current="page"] { --btn-bg: var(--brand-soft); --btn-ink: var(--brand-ink); --btn-bg-hover: var(--brand-soft); }
.shell-tabs .ui-badge { margin-left: 2px; }
.shell-tools { display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-2); flex: 1; min-width: 0; }
.shell-search {
  --btn-bg: var(--surface-2); --btn-line: var(--line); --btn-ink: var(--ink-3); --btn-bg-hover: var(--surface); --btn-line-hover: var(--line-strong);
  justify-content: flex-start; flex: 1 1 240px; max-width: 300px; min-width: 0; gap: 8px; padding: 0 8px 0 12px; font-size: var(--fs-14); font-weight: 500;
}
.shell-search > span { flex: 1; min-width: 0; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.shell-search > kbd { flex: none; }
.live-status { display: inline-flex; align-items: center; gap: 7px; min-width: 0; max-width: 200px; padding: 0 4px; color: var(--ink-3); font-size: var(--fs-13); font-weight: 600; white-space: nowrap; }
.live-status > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.live-status > i { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--ok-solid); box-shadow: 0 0 0 3px var(--ok-soft); }
.live-status.is-syncing > i { background: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); animation: ui-live 1.8s ease-out infinite; color: var(--brand); }
.live-status.is-error > i { background: var(--warn-solid); box-shadow: 0 0 0 3px var(--warn-soft); }
.live-status.is-error { color: var(--warn); }
/* Icon-only tool button; the label stays for screen readers and comes back as text while busy. */
.shell-icon-button { --btn-bg: transparent; --btn-line: var(--line); --btn-ink: var(--ink-2); position: relative; flex: none; min-width: 40px; gap: 6px; padding: 0 10px; font-size: var(--fs-14); white-space: nowrap; }
.shell-icon-button > svg + span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.shell-menu-button { --btn-bg: transparent; --btn-line: var(--line); --btn-ink: var(--ink-2); flex: none; gap: 6px; padding: 0 8px 0 10px; font-size: var(--fs-14); white-space: nowrap; }
.shell-menu-button[aria-expanded="true"] { --btn-bg: var(--brand-soft); --btn-ink: var(--brand-ink); --btn-line: var(--brand-line); }
.shell-menu-chevron { width: 16px; height: 16px; transition: transform var(--t-mid) var(--ease); }
.shell-menu-button[aria-expanded="true"] .shell-menu-chevron { transform: rotate(180deg); }

/* ----- Vitals deck: 全部金幣 · 即將到期 · 需重新登入 · 下一場 ----- */
.shell-vitals { position: sticky; top: var(--appbar-h); z-index: var(--z-deck); background: var(--deck); border-bottom: 1px solid var(--line); box-shadow: var(--sh-deck); }
.shell-vitals[data-entering] { animation: ui-fade var(--t-slow) var(--ease) both; }
@media (min-width: 901px) { .shell-vitals[data-hero-visible] { display: none; } }
.shell-vitals-inner { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: var(--page-max); margin: 0 auto; padding: 0 var(--gutter); }
.shell-vital {
  --btn-bg: transparent; --btn-line: transparent; --btn-bg-hover: var(--surface-2); --btn-line-hover: transparent;
  position: relative; justify-content: flex-start; gap: var(--sp-3); min-width: 0; min-height: var(--vitals-h); margin: 4px 0; padding: 6px 14px;
  border-radius: 10px; font-weight: 400; text-align: left;
}
.shell-vital:first-child { margin-left: -14px; }
.shell-vital + .shell-vital::before { content: ""; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 1px; background: var(--line); }
/* Tone variables come from data-tone (foundation, layered): read them with fallbacks, never re-declare them here. */
.shell-vital-icon { position: relative; display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 11px; color: var(--tone-ink, var(--ink-2)); background: var(--tone-soft, var(--surface-3)); }
.shell-vital-icon > svg.icon { width: 21px; height: 21px; }
.shell-vital-icon > .shell-vital-ring { position: absolute; inset: -4px; width: 48px; height: 48px; transform: rotate(-90deg); }
.shell-vital-ring circle { fill: none; stroke-width: 3; }
.shell-vital-ring .track { stroke: transparent; }
.shell-vital-ring .progress { stroke: var(--brand); stroke-linecap: round; transition: stroke-dashoffset 1s linear; }
.shell-vital-body { display: grid; gap: 0; min-width: 0; }
.shell-vital-label { overflow: hidden; color: var(--ink-3); font-size: var(--fs-13); font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.shell-vital-value { display: flex; align-items: baseline; gap: 5px; color: var(--tone-value, var(--ink)); white-space: nowrap; }
.shell-vital-value b { font-family: var(--font-num); font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; letter-spacing: -.02em; }
.shell-vital-value small { color: var(--ink-2); font-size: var(--fs-14); font-weight: 650; }
.shell-vital-sub { overflow: hidden; color: var(--ink-2); font-size: var(--fs-13); line-height: 1.45; text-overflow: ellipsis; white-space: nowrap; }
.shell-vital-sub .up { color: var(--ok); font-weight: 700; }
.shell-vital-go { width: 16px; height: 16px; margin-left: auto; color: var(--ink-4); opacity: 0; transform: translateX(-4px); transition: opacity var(--t-fast), transform var(--t-fast) var(--ease); }
.shell-vital:hover .shell-vital-go, .shell-vital:focus-visible .shell-vital-go { opacity: 1; transform: none; }
.shell-vital .digit-tick { display: inline-block; animation: ui-tick 260ms var(--ease) both; }

/* ----- Page bar: breadcrumb + sibling pages ----- */
.shell-pagebar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3) var(--sp-5); max-width: var(--page-max); margin: 0 auto; padding: var(--sp-5) var(--gutter) 0; }
.topbar { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.topbar-eyebrow { color: var(--ink-3); font-size: var(--fs-14); font-weight: 650; white-space: nowrap; }
.topbar-eyebrow:not(:empty)::after { content: "›"; margin-left: 8px; color: var(--ink-4); }
.topbar-eyebrow:empty { display: none; }
#page-title { color: var(--ink); font-size: var(--fs-16); font-weight: 750; line-height: 1.35; letter-spacing: 0; }
#page-title:focus { outline: none; }
.shell-subnav { flex: none; }
.shell-subnav > button > svg { width: 17px; height: 17px; }
.shell-subnav .ui-badge { margin-left: 2px; }

/* ----- Drawer / dropdown (#sidebar) ----- */
.drawer-head, .drawer-theme { display: none; }
.drawer-section-label { display: block; padding: 4px 10px; color: var(--ink-3); font-size: var(--fs-13); font-weight: 700; }
.nav-group { display: grid; gap: 2px; }
.nav-group-label { display: block; padding: 4px 10px; color: var(--ink-3); font-size: var(--fs-13); font-weight: 700; }
#main-nav button[data-view] {
  --btn-bg: transparent; --btn-line: transparent; --btn-ink: var(--ink); --btn-bg-hover: var(--hover-veil); --btn-line-hover: transparent;
  justify-content: flex-start; gap: 12px; min-height: 44px; padding: 0 10px; font-size: var(--fs-15); font-weight: 600;
}
#main-nav button[data-view] > svg { width: 20px; height: 20px; color: var(--ink-3); }
#main-nav button[data-view].active { --btn-bg: var(--brand-soft); --btn-ink: var(--brand-ink); --btn-bg-hover: var(--brand-soft); }
#main-nav button[data-view].active > svg { color: var(--brand-ink); }
.sidebar-footer { display: grid; gap: 2px; }
.sidebar-action {
  --btn-bg: transparent; --btn-line: transparent; --btn-ink: var(--ink); --btn-bg-hover: var(--hover-veil); --btn-line-hover: transparent;
  justify-content: flex-start; align-items: center; gap: 12px; min-height: 52px; padding: 6px 10px; font-weight: 400; text-align: left;
}
.sidebar-action > svg { width: 20px; height: 20px; color: var(--ink-3); }
.sidebar-action > span { display: grid; gap: 1px; min-width: 0; }
.sidebar-action strong { color: var(--ink); font-size: var(--fs-15); font-weight: 650; }
.sidebar-action small { color: var(--ink-3); font-size: var(--fs-13); line-height: 1.4; }
.sidebar-action.is-danger strong, .sidebar-action.is-danger > svg { color: var(--bad); }
.nav-backdrop { position: fixed; inset: 0; z-index: var(--z-backdrop); background: transparent; }

@media (min-width: 901px) {
  .mobile-header, .tabbar { display: none; }
  /* Desktop: the drawer element doubles as the「管理」dropdown under the app bar. */
  .sidebar {
    position: fixed; top: var(--menu-top, calc(var(--appbar-h) - 4px)); right: var(--menu-right, var(--gutter)); z-index: var(--z-menu);
    width: 320px; max-height: calc(100dvh - var(--appbar-h) - 24px); overflow: auto; padding: var(--sp-2);
    border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--surface); box-shadow: var(--sh-3);
    opacity: 0; visibility: hidden; transform: translateY(-6px);
    transition: opacity var(--t-fast) var(--ease), transform var(--t-mid) var(--ease), visibility 0s linear var(--t-mid);
  }
  .sidebar.open { opacity: 1; visibility: visible; transform: none; transition: opacity var(--t-fast) var(--ease), transform var(--t-mid) var(--ease), visibility 0s; }
  .sidebar #main-nav { display: none; }
}

/* ----- Phone: top bar, ribbon, tab bar, bottom-sheet drawer ----- */
@media (max-width: 900px) {
  .shell-appbar { display: none; }
  .app-shell { padding-top: calc(var(--mobile-header-h) + var(--mobile-vitals-h) + env(safe-area-inset-top)); padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--sp-4)); }
  .app-shell:has(> .shell-vitals[hidden]) { padding-top: calc(var(--mobile-header-h) + env(safe-area-inset-top)); }
  .mobile-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: var(--z-mobilebar);
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
    height: calc(var(--mobile-header-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0 14px;
    border-bottom: 1px solid var(--line-2); background: var(--deck);
  }
  .mobile-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .mobile-brand .shell-brand-mark { width: 32px; height: 32px; border-radius: 9px; }
  .mobile-brand > div { display: grid; min-width: 0; line-height: 1.25; }
  .mobile-brand strong { overflow: hidden; color: var(--ink); font-size: 17px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-brand small { overflow: hidden; color: var(--ink-3); font-size: var(--fs-12); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-brand small.sync-error { color: var(--warn); }
  .mobile-actions { display: flex; align-items: center; gap: 2px; flex: none; }
  .mobile-icon-button { --btn-bg: transparent; --btn-line: transparent; --btn-ink: var(--ink-2); --btn-bg-hover: var(--hover-veil); width: 44px; min-width: 44px; min-height: 44px; padding: 0; border-radius: 10px; }
  .mobile-icon-button > svg { width: 22px; height: 22px; }
  #nav-toggle[aria-expanded="true"] { --btn-bg: var(--brand-soft); --btn-ink: var(--brand-ink); }

  .shell-vitals { position: fixed; top: calc(var(--mobile-header-h) + env(safe-area-inset-top)); left: 0; right: 0; z-index: var(--z-mobilebar); border-bottom: 1px solid var(--line); box-shadow: var(--sh-deck); }
  .shell-vitals-inner { padding: 0 6px; }
  .shell-vital { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; min-height: var(--mobile-vitals-h); margin: 0; padding: 4px 8px; border-radius: 0; }
  .shell-vital:first-child { margin-left: 0; }
  .shell-vital + .shell-vital::before { top: 12px; bottom: 12px; }
  .shell-vital-icon, .shell-vital-sub, .shell-vital-go { display: none; }
  .shell-vital-label { font-size: var(--fs-12); }
  .shell-vital-value b { font-size: 19px; }
  .shell-vital-value small { display: none; }

  .shell-pagebar { padding: var(--sp-3) var(--gutter) 0; }
  .topbar { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .shell-subnav {
    display: flex; flex-wrap: nowrap; width: 100%; overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity;
  }
  .shell-subnav::-webkit-scrollbar { display: none; }
  .shell-subnav > button { flex: none; scroll-snap-align: center; }
  .shell-subnav.has-more-r { -webkit-mask-image: linear-gradient(90deg, var(--mask-solid) 86%, transparent); mask-image: linear-gradient(90deg, var(--mask-solid) 86%, transparent); }
  .shell-subnav.has-more-l { -webkit-mask-image: linear-gradient(90deg, transparent, var(--mask-solid) 14%); mask-image: linear-gradient(90deg, transparent, var(--mask-solid) 14%); }
  .shell-subnav.has-more-l.has-more-r { -webkit-mask-image: linear-gradient(90deg, transparent, var(--mask-solid) 14%, var(--mask-solid) 86%, transparent); mask-image: linear-gradient(90deg, transparent, var(--mask-solid) 14%, var(--mask-solid) 86%, transparent); }
  .content { padding: var(--sp-3) var(--gutter) var(--sp-6); }

  .nav-backdrop { background: var(--scrim); opacity: 0; transition: opacity var(--t-mid) var(--ease); }
  .nav-backdrop.visible { opacity: 1; }
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-drawer);
    display: grid; gap: var(--sp-3); max-height: min(88dvh, 760px); overflow-y: auto; overscroll-behavior: contain;
    padding: 6px var(--sp-3) calc(var(--sp-4) + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line); border-radius: var(--r-sheet) var(--r-sheet) 0 0; background: var(--surface); box-shadow: var(--sh-3);
    transform: translateY(104%); visibility: hidden;
    transition: transform var(--t-slow) var(--ease-out), visibility 0s linear var(--t-slow);
  }
  .sidebar.open { transform: none; visibility: visible; transition: transform var(--t-slow) var(--ease-out), visibility 0s; }
  .sidebar::before { content: ""; justify-self: center; width: 38px; height: 4px; border-radius: var(--r-round); background: var(--line-strong); }
  .drawer-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 0 2px 0 10px; }
  .drawer-head strong { color: var(--ink); font-size: var(--fs-18); font-weight: 800; }
  .drawer-theme { display: grid; gap: 6px; }
  #main-nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-2); }
  .nav-group { grid-column: 1 / -1; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  /* One-page groups (總覽, 帳號) sit side by side instead of each taking a half-empty row. */
  .nav-group:has(> button[data-view]:only-of-type) { grid-column: span 1; grid-template-columns: minmax(0, 1fr); }
  .nav-group-label { grid-column: 1 / -1; padding: 0 4px; }
  #main-nav button[data-view] {
    --btn-bg: var(--surface); --btn-line: var(--line); --btn-bg-hover: var(--surface-2);
    flex-direction: column; justify-content: center; gap: 6px; min-height: 72px; padding: 8px 4px; font-size: var(--fs-13); font-weight: 650; line-height: 1.3; text-align: center;
  }
  #main-nav button[data-view] > svg { width: 22px; height: 22px; color: var(--brand-ink); }
  #main-nav button[data-view].active { --btn-line: var(--brand); }
  .sidebar-footer { padding-top: var(--sp-2); border-top: 1px solid var(--line-2); }
  .sidebar-footer > .drawer-section-label { padding-inline: 4px; }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-tabbar);
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--line); background: var(--deck); box-shadow: var(--sh-tabbar);
  }
  .tabbar > button {
    --btn-bg: transparent; --btn-line: transparent; --btn-ink: var(--ink-3); --btn-bg-hover: transparent; --btn-line-hover: transparent;
    flex-direction: column; gap: 3px; min-height: var(--tabbar-h); padding: 6px 2px 4px; border-radius: 0; font-size: var(--fs-12); font-weight: 700;
  }
  .tabbar > button > svg { width: 24px; height: 24px; }
  .tabbar > button.active { --btn-ink: var(--brand-ink); }
  .tabbar-fab {
    display: grid; place-items: center; width: 54px; height: 54px; margin-top: -26px; border: 4px solid var(--deck); border-radius: 18px;
    color: var(--on-brand); background: linear-gradient(160deg, var(--hero-a), var(--hero-b)); box-shadow: var(--sh-2);
  }
  .tabbar-fab > svg { width: 24px; height: 24px; }
  .tabbar > .tabbar-scan { --btn-ink: var(--ink-2); gap: 2px; }
}

/* ----- Back to top ----- */
.scroll-to-top {
  --btn-bg: var(--surface); --btn-line: var(--line); --btn-ink: var(--ink-2);
  position: fixed; right: max(var(--sp-5), env(safe-area-inset-right)); bottom: max(var(--sp-5), env(safe-area-inset-bottom)); z-index: var(--z-float);
  width: 44px; min-width: 44px; height: 44px; padding: 0; border-radius: 12px; box-shadow: var(--sh-2);
}
@media (max-width: 900px) { .scroll-to-top { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--sp-3)); right: var(--sp-3); } }

/* ----- Toast (popover in the top layer) ----- */
.toast {
  position: fixed; inset: auto max(var(--sp-5), env(safe-area-inset-right)) max(var(--sp-5), env(safe-area-inset-bottom)) auto;
  z-index: 100; display: none; align-items: flex-start; gap: var(--sp-3);
  width: max-content; max-width: min(420px, calc(100vw - 32px)); margin: 0; padding: 12px 16px 12px 12px;
  border: 1px solid var(--toast-line); border-radius: var(--r-lg); background: var(--toast-bg); color: var(--toast-ink);
  box-shadow: var(--sh-3); font-size: var(--fs-15); line-height: 1.55; overflow-wrap: anywhere;
}
.toast.show, .toast:popover-open { display: flex; }
.toast.show { animation: ui-pop var(--t-slow) var(--ease-spring) both; }
.toast-icon { display: grid; place-items: center; width: 26px; height: 26px; flex: none; border-radius: 8px; color: var(--on-ok); background: var(--ok-solid); }
.toast-icon > svg { width: 16px; height: 16px; }
.toast.error .toast-icon { color: var(--on-bad); background: var(--bad-solid); }
.toast-text { padding-top: 2px; font-weight: 600; white-space: pre-line; }
@media (max-width: 900px) {
  .toast { left: var(--sp-3); right: var(--sp-3); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--sp-3)); width: auto; max-width: none; }
}

/* ----- The operations dialog #modal ----- */
#modal {
  width: min(var(--modal-w, 720px), calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px);
  overflow: hidden; padding: 0; border: 1px solid var(--line); border-radius: var(--r-xl);
  background: var(--surface); color: var(--ink); box-shadow: var(--sh-3);
}
#modal[open] { animation: ui-pop var(--t-mid) var(--ease) both; }
#modal::backdrop { background: var(--scrim); }
#modal:has(.modal-body [data-modal-size="sm"]) { --modal-w: 480px; }
#modal:has(.modal-body [data-modal-size="lg"]) { --modal-w: 960px; }
#modal:has(.modal-body [data-modal-size="full"]) { --modal-w: 1180px; }
.modal-card { display: flex; flex-direction: column; min-width: 0; max-height: calc(100dvh - 32px); }
.modal-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 14px 16px 12px 24px; border-bottom: 1px solid var(--line-2); }
.modal-head h2 { min-width: 0; margin: 0; color: var(--ink); font-size: var(--fs-18); font-weight: 750; line-height: 1.35; overflow-wrap: anywhere; }
.modal-close { --btn-line: transparent; --btn-bg-hover: var(--surface-3); flex: none; border-radius: 10px; }
.modal-close > svg { width: 20px; height: 20px; }
.modal-body {
  --modal-pad-x: var(--sp-6); --modal-pad-b: var(--sp-6);
  flex: 1; min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain;
  padding: var(--sp-5) var(--modal-pad-x) var(--modal-pad-b);
}
.modal-body > * + * { margin-top: var(--sp-4); }
/* Side panel (desktop): content opts in with data-modal-layout="side"; the page stays visible behind. */
@media (min-width: 901px) {
  #modal:has(.modal-body [data-modal-layout="side"]) {
    width: min(var(--modal-side-w, 760px), 100vw); height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto;
    border-width: 0 0 0 1px; border-radius: var(--r-xl) 0 0 var(--r-xl); animation-name: ui-drawer;
  }
  #modal:has(.modal-body [data-modal-layout="side"]) .modal-card { height: 100%; max-height: 100dvh; }
  /* Short content: the footer still sits on the panel's bottom edge (the auto margin goes on the element before it,
     so long content keeps the footer's own top margin). */
  .modal-body > [data-modal-layout="side"]:has(> .ui-dialog-foot) { display: flex; flex-direction: column; min-height: 100%; }
  .modal-body > [data-modal-layout="side"] > :has(+ .ui-dialog-foot) { margin-bottom: auto; }
}
/* Phones: every dialog is a bottom sheet with a grab handle. */
@media (max-width: 600px) {
  #modal, #modal:has(.modal-body [data-modal-size]) {
    width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0;
    border-width: 1px 0 0; border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  }
  #modal[open] { animation-name: ui-sheet; }
  .modal-card { max-height: 94dvh; }
  .modal-head { position: relative; padding: 18px 10px 10px 18px; }
  .modal-head::before { content: ""; position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; border-radius: var(--r-round); background: var(--line-strong); transform: translateX(-50%); }
  .modal-body { --modal-pad-x: var(--sp-4); --modal-pad-b: calc(var(--sp-5) + env(safe-area-inset-bottom)); padding-top: var(--sp-4); }
}

/* ----- Quick command (Ctrl K) ----- */
.command-panel { display: grid; gap: var(--sp-4); }
.command-search {
  position: relative; display: flex; align-items: center; gap: 0;
}
.command-search > svg { position: absolute; left: 14px; width: 20px; height: 20px; color: var(--ink-3); pointer-events: none; }
.command-search > input { min-height: 52px; padding-left: 46px; padding-right: 56px; font-size: var(--fs-18); }
.command-search > kbd { position: absolute; right: 12px; }
.command-results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4) var(--sp-5); }
.command-group { display: grid; align-content: start; gap: 2px; min-width: 0; }
.command-group:not(:has(> button:not([hidden]))) { display: none; }
.command-group > h3 { padding: 0 8px 4px; color: var(--ink-3); font-size: var(--fs-13); font-weight: 700; }
.command-group > button {
  --btn-bg: transparent; --btn-line: transparent; --btn-bg-hover: var(--row-hover); --btn-line-hover: transparent;
  display: grid; grid-template-columns: 36px minmax(0, 1fr) 16px; align-items: center; gap: 2px 10px;
  min-height: 52px; padding: 6px 8px; font-weight: 400; text-align: left;
}
.command-group > button > svg:first-child { grid-row: span 2; display: grid; width: 36px; height: 36px; padding: 8px; border-radius: 10px; color: var(--brand-ink); background: var(--brand-soft); }
.command-group > button > .command-title { color: var(--ink); font-size: var(--fs-15); font-weight: 700; }
.command-group > button > small { grid-column: 2; color: var(--ink-3); font-size: var(--fs-13); line-height: 1.45; }
.command-group > button > .command-go { grid-column: 3; grid-row: 1 / span 2; width: 16px; height: 16px; color: var(--ink-4); }
.command-group > .command-tutorial > svg:first-child { color: var(--ok); background: var(--ok-soft); }
.command-group > button:focus-visible, .command-group > button:hover { --btn-bg: var(--brand-soft); }
.command-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--line-2); }
.command-foot p { color: var(--ink-3); font-size: var(--fs-13); }
.command-foot p kbd { margin: 0 2px; }
.command-theme { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--ink-3); font-size: var(--fs-13); font-weight: 650; }
@media (max-width: 600px) {
  .command-results { grid-template-columns: minmax(0, 1fr); }
  .command-search > input { font-size: var(--fs-16); }
  .command-search > kbd { display: none; }
  .command-foot p { display: none; }
}

/* ----- Change administrator password ----- */
.admin-password-form .field-shell > input { padding-right: 48px; }

/* ----- View render failure (renderViewSafely) ----- */
.view-render-error { min-height: 300px; }

/* ----- Sign-in page ----- */
.login-shell { position: relative; display: grid; grid-template-rows: auto 1fr auto; min-height: 100dvh; overflow: hidden; isolation: isolate; }
.login-flow { position: absolute; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.login-flow svg { width: 100%; height: 100%; }
.login-flow .flow-line { fill: none; stroke: var(--brand); stroke-width: 1.4; opacity: .16; }
.login-flow .flow-run { fill: none; stroke: var(--brand); stroke-width: 2.4; stroke-linecap: round; stroke-dasharray: 14 320; opacity: .9; animation: login-flow 5.5s linear infinite; }
.login-flow .flow-node { fill: var(--surface); stroke: var(--brand-line); stroke-width: 2; }
.login-flow .flow-coin { fill: var(--coin); stroke: var(--coin-line); stroke-width: 2; }
.login-flow::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse 36% 46% at 50% 52%, var(--bg) 30%, transparent 100%); }
@keyframes login-flow { from { stroke-dashoffset: 334; } to { stroke-dashoffset: 0; } }
.login-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); max-width: var(--page-max); width: 100%; margin: 0 auto; padding: var(--sp-5) var(--gutter); }
.login-top-actions { display: flex; align-items: center; gap: var(--sp-2); }
.login-stage { display: grid; place-items: center; padding: var(--sp-5) var(--gutter); }
.login-card {
  width: min(456px, 100%); padding: var(--sp-7) var(--sp-7) var(--sp-6);
  border: 1px solid var(--line); border-radius: var(--r-2xl); background: var(--surface); box-shadow: var(--sh-3);
}
.login-card > * + * { margin-top: var(--sp-4); }
.login-steps > li:first-child { color: var(--ink); }
.login-steps > li:first-child > b { border-color: var(--brand); color: var(--on-brand); background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.login-card:has(#login-two-factor-step:not([hidden])) .login-steps > li:first-child { color: var(--ink-2); }
.login-card:has(#login-two-factor-step:not([hidden])) .login-steps > li:first-child > b { border-color: var(--ok-solid); color: transparent; background: var(--ok-solid) var(--check-glyph) center / 14px no-repeat; box-shadow: none; }
.login-card:has(#login-two-factor-step:not([hidden])) .login-steps > li:last-child { color: var(--ink); }
.login-card:has(#login-two-factor-step:not([hidden])) .login-steps > li:last-child::before { background: var(--ok-solid); }
.login-card:has(#login-two-factor-step:not([hidden])) .login-steps > li:last-child > b { border-color: var(--brand); color: var(--on-brand); background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.login-card h1 { color: var(--ink); font-size: var(--fs-28); font-weight: 800; }
.login-lead { color: var(--ink-2); font-size: var(--fs-15); line-height: var(--lh-long); }
.login-step { display: grid; gap: var(--sp-4); }
.login-step-heading { display: flex; align-items: flex-start; gap: var(--sp-3); }
.login-step-heading h2 { font-size: var(--fs-20); }
.login-step-heading .muted { font-size: var(--fs-14); line-height: 1.6; }
.login-step-icon { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 12px; color: var(--brand-ink); background: var(--brand-soft); }
.login-step-icon > svg { width: 22px; height: 22px; }
.login-challenge-expiry { margin-top: 4px; color: var(--ink-3); font-size: var(--fs-13); }
.login-challenge-expiry:empty { display: none; }
.login-code-tabs { display: flex; width: 100%; }
.login-code-tabs > button { flex: 1; }
.login-caps { display: flex; align-items: center; gap: 8px; margin-top: -6px; color: var(--warn); font-size: var(--fs-14); font-weight: 600; }
.login-caps > svg { width: 18px; height: 18px; }
.login-submit, .login-step-actions > .primary { width: 100%; }
.login-step-actions { display: grid; gap: var(--sp-2); }
.login-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px var(--sp-2); padding-top: var(--sp-4); border-top: 1px solid var(--line-2); }
.login-foot-label { color: var(--ink-3); font-size: var(--fs-14); }
.login-tutorial-link { --btn-bg: transparent; --btn-line: transparent; --btn-ink: var(--brand-ink); --btn-bg-hover: var(--brand-soft); --btn-line-hover: transparent; padding: 0 10px; font-size: var(--fs-15); }
.login-trust { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-2) var(--sp-6); padding: var(--sp-5) var(--gutter) max(var(--sp-6), env(safe-area-inset-bottom)); color: var(--ink-2); font-size: var(--fs-14); font-weight: 600; }
.login-trust > span { display: inline-flex; align-items: center; gap: 8px; }
.login-trust svg { width: 18px; height: 18px; color: var(--ok); }
@media (max-width: 600px) {
  .login-top { padding: var(--sp-4) var(--gutter); }
  .login-top .shell-brand-text small, .login-top-tutorial > span { display: none; }
  .login-top-tutorial { width: 44px; padding: 0; }
  .login-stage { align-items: start; padding: var(--sp-2) var(--gutter) var(--sp-4); }
  .login-card { padding: var(--sp-6) var(--sp-5) var(--sp-5); border-radius: var(--r-xl); }
  .login-card h1 { font-size: var(--fs-24); }
  .login-trust { flex-direction: column; align-items: center; gap: var(--sp-2); padding-top: var(--sp-3); }
}

/* ----- Theme change: a circle of the new theme grows from the switch (View Transitions) ----- */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
/* Browsers without View Transitions get a short colour cross-fade instead. */
html.is-theme-fading, html.is-theme-fading *, html.is-theme-fading *::before, html.is-theme-fading *::after {
  transition: background-color var(--t-slow) var(--ease), border-color var(--t-slow) var(--ease), color var(--t-slow) var(--ease), fill var(--t-slow) var(--ease), stroke var(--t-slow) var(--ease) !important;
}

/* ----- Compact desktops ----- */
@media (min-width: 901px) and (max-width: 1280px) {
  .live-status > span { display: none; }
  .shell-search { flex-basis: 200px; }
}
@media (min-width: 901px) and (max-width: 1100px) {
  .shell-appbar-inner { gap: var(--sp-2); }
  .shell-brand-text { display: none; }
  .shell-tabs > button { padding: 0 9px; gap: 6px; }
  .shell-search { flex: 0 0 44px; width: 44px; padding: 0; justify-content: center; }
  .shell-search > span, .shell-search > kbd { display: none; }
  .shell-menu-button > span { display: none; }
  .shell-vital { padding-inline: 10px; gap: 10px; }
  .shell-vital-icon { width: 34px; height: 34px; }
  .shell-vital-value b { font-size: 21px; }
}
