/* Link 虚拟卡 · foundation additions on top of design A (tokens.css + components.css):
   boot splash, shell glue (mobile overflow button, offline strip, sidebar 今日剩余 meter), popover +
   menu (§13 account menu), top-centre status toast, toast close/leave, live indicator, sync control,
   modal extras, skeleton rows, login extras, placeholder pages. Same tokens, same restraint. */

:root {
  --toast-warn: #E9BC66;
}
:root[data-theme="dark"] {
  --toast-warn: #7F4E00;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --toast-warn: #7F4E00;
  }
}

/* ---------------------------------------------------------------------------------------------
   Boot splash (index.html) and boot error
   --------------------------------------------------------------------------------------------- */
.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
}
.boot .seal { opacity: 0; animation: fade-in var(--dur-slow) var(--ease-out) 400ms forwards; }

.boot-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-8) var(--page-pad-x);
  text-align: center;
}
.boot-error__title {
  margin-top: var(--space-4);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--weight-heading);
  letter-spacing: var(--tracking-tight);
}
.boot-error__text { max-width: 28em; color: var(--text-2); }
.boot-error .btn { margin-top: var(--space-3); }

/* Programmatic focus targets (page headings after navigation) need no ring. */
[tabindex="-1"]:focus { outline: none; }

/* ---------------------------------------------------------------------------------------------
   Shell glue
   --------------------------------------------------------------------------------------------- */
@media (min-width: 1024px) { .topbar__mobile { display: none !important; } }

.nav__text { min-width: 0; }

button.link-pill { font-family: inherit; }
.link-pill[aria-expanded="true"] { border-color: var(--border-strong); background: var(--surface-muted); }
.link-pill[data-state="disconnected"][aria-expanded="true"] { background: var(--warning-soft); }

.offline-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: var(--z-sticky);
}

/* Sidebar foot: 今日剩余 with a thin meter (graft from B), then who is signed in. */
.side-limit {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-3);
  text-decoration: none;
}
.side-limit:hover { color: var(--text-3); }
.side-limit:hover .side-limit__value { color: var(--accent-text); }
.side-limit__row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); }
.side-limit__value {
  color: var(--text);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  transition: color var(--dur-fast) var(--ease-standard);
}
.side-limit__foot { font-variant-numeric: tabular-nums; }
.side-limit .meter { margin: 2px 0; }
.side-limit__note { display: flex; align-items: center; gap: 6px; color: var(--text-3); }
.side-limit__note .icon { color: var(--warning-dot); }
.side-limit__note a { color: var(--accent-text); }
.side-user {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px var(--space-2);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.side-user__meta { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------------------------------
   Popover + menu (account menu, overflow menu)
   --------------------------------------------------------------------------------------------- */
.popover {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-overlay);
  min-width: 232px;
  max-width: min(340px, calc(100vw - 16px));
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: pop-in var(--dur-base) var(--ease-out);
}
.popover:focus { outline: none; }

.menu__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 6px;
  padding: 10px 10px 12px;
  border-bottom: 1px solid var(--border);
}
.menu__avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-muted);
  color: var(--text-2);
}
.menu__avatar .icon { width: 18px; height: 18px; }
.menu__who { display: flex; flex-direction: column; min-width: 0; line-height: 1.4; }
.menu__email { overflow: hidden; font-weight: var(--weight-medium); text-overflow: ellipsis; white-space: nowrap; }
.menu__sub { overflow: hidden; color: var(--text-3); font-size: var(--text-xs); text-overflow: ellipsis; white-space: nowrap; }
.menu__list { display: flex; flex-direction: column; gap: 1px; }
.menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: var(--text-sm);
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-standard);
}
.menu__item:hover, .menu__item:focus-visible { background: var(--surface-muted); color: var(--text); outline: none; }
.menu__item:focus-visible { box-shadow: inset 0 0 0 1.5px var(--focus-ring); }
.menu__item > .icon { color: var(--text-3); }
.menu__item--danger, .menu__item--danger:hover, .menu__item--danger:focus-visible { color: var(--danger-text); }
.menu__item--danger > .icon { color: currentColor; }
.menu__item[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.menu__text { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; }
.menu__desc { color: var(--text-3); font-size: var(--text-xs); }
.menu__item > .menu__check { margin-left: auto; color: var(--accent); }
.menu__sep { height: 1px; margin: 6px 4px; background: var(--border); }
.menu__heading { padding: 6px 10px 2px; color: var(--text-3); font-size: var(--text-xs); letter-spacing: var(--tracking-label); }
@media (pointer: coarse) { .menu__item { min-height: var(--tap); } }

/* ---------------------------------------------------------------------------------------------
   Toasts: close button, leave transition, warning tone, top-centre status toast (graft from B)
   --------------------------------------------------------------------------------------------- */
.toast__close {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  margin-left: auto;
  border-radius: 7px;
  color: var(--toast-muted);
}
.toast__close:hover { background: rgba(127, 127, 127, 0.16); color: var(--toast-fg); }
.toast--warning .toast__icon { background: rgba(224, 166, 58, 0.18); color: var(--toast-warn); }
.toast--leaving { opacity: 0; transform: translateY(6px); transition: opacity 160ms var(--ease-in), transform 160ms var(--ease-in); }
/* stacked corner toasts share one left edge instead of a ragged column */
@media (min-width: 1024px) { .toast-region:not(.toast-region--top) .toast { min-width: min(300px, 100%); } }
.toast-region.toast-region--top {
  top: calc(env(safe-area-inset-top, 0px) + var(--space-4));
  right: auto;
  bottom: auto;
  left: 50%;
  width: min(440px, calc(100vw - 2 * var(--space-4)));
  align-items: stretch;
  transform: translateX(-50%);
}
.toast--status { padding: 14px 12px 14px 16px; animation: toast-drop var(--dur-slow) var(--ease-out); }
.toast--status .toast__title { font-size: var(--text-base); }
.toast-region--top .toast--leaving { transform: translateY(-6px); }

/* ---------------------------------------------------------------------------------------------
   Live indicator (「实时」 / 「重连中…」, graft from C) and sync control
   --------------------------------------------------------------------------------------------- */
.live {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-3);
  font-size: var(--text-xs);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.live__dot { position: relative; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--text-disabled); }
.live[data-state="live"] { color: var(--accent-text); }
.live[data-state="live"] .live__dot { background: var(--accent); }
.live[data-state="live"] .live__dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  animation: ripple var(--dur-pulse) var(--ease-out) infinite;
}
.live[data-state="reconnecting"] { color: var(--warning-text); }
.live[data-state="reconnecting"] .live__dot { background: var(--warning-dot); animation: blink 1.2s var(--ease-standard) infinite; }
.live[data-state="offline"] .live__dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-3); }

.sync-control { display: inline-flex; align-items: center; gap: var(--space-3); color: var(--text-3); font-size: var(--text-sm); }
.sync-control__time { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------------------------------------------------
   Modal extras
   --------------------------------------------------------------------------------------------- */
.modal--wide { width: min(640px, calc(100vw - 2 * var(--space-4))); }
.modal__heading { flex: 1 1 auto; min-width: 0; }
.modal__head .modal__close { flex: none; }
.modal__error { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--danger-soft); }
/* confirm dialogs without body content: only a short gap between the text and the buttons */
.modal__body:not(:has(> :not([hidden]))) { padding-top: var(--space-3); padding-bottom: var(--space-4); }
@media (max-width: 599px) {
  .modal--wide { width: 100%; }
  html.modal-open { overflow: hidden; }
  /* a tall sheet scrolls its body under the buttons: a hairline keeps fields from touching them */
  .modal__body:has(> :not([hidden])) + .modal__foot { padding-top: var(--space-4); border-top: 1px solid var(--border); }
}

/* ---------------------------------------------------------------------------------------------
   Loading / empty / placeholder
   --------------------------------------------------------------------------------------------- */
.skeleton-row { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-5) var(--space-6); }
.skeleton-row__end { flex: none; width: 72px; }
.empty__icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-2);
  border-radius: 50%;
  background: var(--danger-soft);
  color: var(--danger-text);
}
.coming-soon .empty { padding-top: var(--space-12); padding-bottom: var(--space-12); }

/* Off-screen textarea for the copy fallback (no inline styles allowed) */
.clipboard-scratch { position: fixed; top: 0; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* ---------------------------------------------------------------------------------------------
   Login extras
   --------------------------------------------------------------------------------------------- */
.auth__alert { margin-bottom: var(--space-6); }
.auth__alert:empty { display: none; }
.auth__alert .banner__text code { padding: 1px 5px; border-radius: 4px; background: var(--surface); font-size: 0.9em; }
.login-caps { display: inline-flex; align-items: center; gap: 4px; color: var(--warning-text); }
.auth .input:disabled { cursor: not-allowed; }
/* a disabled control inside an input group greys the whole group, like .input:disabled */
.input-group:has(> .input:disabled),
.input-group:has(> .input:disabled):hover { border-color: var(--border-strong); background: var(--surface-muted); box-shadow: none; color: var(--text-3); }

/* ---------------------------------------------------------------------------------------------
   Motion
   --------------------------------------------------------------------------------------------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes toast-drop { from { opacity: 0; transform: translateY(-10px) scale(0.98); } to { opacity: 1; transform: none; } }
