/* ==========================================================================
   Krisp dashboard - design system
   Warm paper, amber accent, editorial serif headings on a calm sans body.

   Contents
     1  Tokens              8  Tabs                 15 Modal and menu
     2  Base                9  Tables and lists     16 Banner
     3  Typography + utils  10 Avatar               17 Meter
     4  Layout primitives   11 Metric               18 Code, snippet, kbd
     5  Buttons             12 Empty / error state  19 Scroll areas
     6  Cards               13 Skeleton, spinner    20 App shell
     7  Forms               14 Toasts               21 Auth screen
        Badges, chips, dots                         22 Motion, print, forced colours

   Conventions
     - Component classes are flat and prefixed by component (.btn, .btn-primary).
     - State classes start with is- (.is-active, .is-loading, .is-invalid).
     - View-specific CSS lives in /assets/views/<id>.css and must scope every
       selector under .view-<id> (the class the shell puts on the view root).
     - Breakpoints: 640 / 768 / 1024 / 1280 (min-width, mobile first).
   ========================================================================== */

/* -- 1. Tokens ------------------------------------------------------------- */

:root {
  /* Modern Minimalist Tokens */
  /* Paper */
  --bg: #F3F5F9;
  --surface: #FFFFFF;
  --card: rgba(255, 255, 255, 0.9);
  --sunken: #E2E8F0;
  --sunken-strong: #CBD5E1;
  --dark: #0F172A;
  --dark-raised: #1E293B;

  /* Ink */
  --ink: #0F172A;
  --ink-2: #475569;
  --muted: #64748B;
  --faint: #94A3B8;
  --placeholder: #94A3B8;
  --on-dark: #F8FAFC;
  --on-dark-muted: #94A3B8;

  /* Lines */
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --border-control: #94A3B8;

  /* Vibrant Accent */
  --accent: #4F46E5; /* Indigo */
  --accent-hover: #4338CA;
  --accent-active: #3730A3;
  --accent-ink: #312E81;
  --accent-soft: #E0E7FF;
  --accent-on-dark: #818CF8;
  --focus: rgba(79, 70, 229, 0.5);

  /* Semantic */
  --success: #3C8A5B;
  --success-ink: #2A6B45;
  --success-soft: #E2EFE3;
  --warning: #B58210;
  --warning-ink: #855600;
  --warning-soft: #FAEBC6;
  --danger: #B3402E;
  --danger-ink: #A63A28;
  --danger-soft: #F8E2DB;
  --info: #2B6A8E;
  --info-ink: #245F82;
  --info-soft: #DFEBF1;
  --violet: #6B46C1;
  --violet-ink: #5A3BA8;
  --violet-soft: #EAE4F6;

  /* Chart series (validated for colour-vision separation on --card).
     Fixed order: 1 amber, 2 teal, 3 violet. Never reuse semantic colours. */
  --chart-1: #BF7A30;
  --chart-2: #108F82;
  --chart-3: #6B46C1;
  --chart-grid: #ECE4D5;
  --chart-axis: #CFC3AC;

  /* Type */
  --font-display: "Outfit", "Inter", system-ui, sans-serif;
  --font-body: "Inter", "Roboto", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", monospace;

  --text-xs: 0.75rem;     /* 12 */
  --text-sm: 0.8125rem;   /* 13 */
  --text-base: 0.9375rem; /* 15 */
  --text-md: 1rem;        /* 16 */
  --text-lg: 1.125rem;    /* 18 */
  --text-xl: 1.375rem;    /* 22 */
  --text-2xl: 1.75rem;    /* 28 */
  --text-3xl: 2.25rem;    /* 36 */

  /* Space: 4px rhythm */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;

  /* Shape, depth, motion */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --shadow-1: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-2: 0 10px 15px -3px rgba(0, 0, 0, 0.05), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-3: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 10px 10px -5px rgba(0, 0, 0, 0.02);
  --ring: 0 0 0 3px var(--focus);
  --ring-danger: 0 0 0 3px rgba(220, 38, 38, 0.24);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --t: 200ms;

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h: 64px;
  --content-max: 1200px; /* 1440 max width minus the sidebar */
  --page-pad: 16px;
  --control-h: 40px;

  color-scheme: light;
}

@media (min-width: 768px) {
  :root { --page-pad: 24px; }
}

@media (min-width: 1280px) {
  :root { --page-pad: 32px; }
}

/* -- 2. Base --------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd {
  margin: 0;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

h4, h5, h6 {
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.35;
}

ul, ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

a {
  color: var(--accent-ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--t) var(--ease);
}

a:hover {
  color: var(--ink);
}

img, svg, video, canvas {
  display: block;
  max-width: 100%;
}

svg.icon {
  flex: none;
  display: inline-block;
  vertical-align: -0.2em;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  margin: 0;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: inherit;
}

button:disabled {
  cursor: not-allowed;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--s-4) 0;
}

[hidden] {
  display: none !important;
}

::selection {
  background: rgba(200, 133, 63, 0.3);
  color: var(--ink);
}

/* One focus language everywhere: a deep-amber ring, only for keyboard users. */
:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 2000;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--on-dark);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--t) var(--ease);
}

.skip-link:focus {
  transform: none;
  color: var(--on-dark);
}

/* -- 3. Typography and utilities ------------------------------------------- */

.display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

.title-xl { font-size: var(--text-3xl); }
.title-lg { font-size: var(--text-2xl); }
.title-md { font-size: var(--text-xl); }
.title-sm { font-size: var(--text-lg); }

.eyebrow {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.lede {
  font-size: var(--text-md);
  color: var(--ink-2);
  line-height: 1.55;
}

.muted { color: var(--muted); }
.subtle { color: var(--ink-2); }
.small { font-size: var(--text-sm); }
.tiny { font-size: var(--text-xs); }
.strong { font-weight: 600; }
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.tabular { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-success { color: var(--success-ink); }
.text-warning { color: var(--warning-ink); }
.text-danger { color: var(--danger-ink); }
.text-info { color: var(--info-ink); }
.text-accent { color: var(--accent-ink); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.clamp-2 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.break-anywhere {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.link {
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.link:hover {
  color: var(--ink);
  text-decoration: underline;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.hidden { display: none !important; }

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: var(--s-4) 0;
}

/* -- 4. Layout primitives -------------------------------------------------- */

/* Page: the padded, width-capped column a normal view renders into. The shell
   adds this class to the view root for layout: 'page' views. */
.page {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-6) var(--page-pad) var(--s-16);
}

.page-narrow { max-width: 760px; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-6);
}

.page-heading {
  font-size: var(--text-2xl);
}

.page-sub {
  margin-top: 6px;
  color: var(--muted);
  max-width: 64ch;
  text-wrap: pretty;
}

.page-header > :first-child {
  flex: 1 1 320px;
  min-width: 0;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}

.section {
  margin-top: var(--s-8);
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}

.section-title {
  font-size: var(--text-lg);
}

/* Vertical rhythm */
.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack-xs { gap: var(--s-1); }
.stack-sm { gap: var(--s-2); }
.stack-lg { gap: var(--s-6); }
.stack-xl { gap: var(--s-8); }
.stack > * { min-width: 0; }

/* Horizontal cluster */
.row { display: flex; align-items: center; gap: var(--s-3); min-width: 0; }
.row-sm { gap: var(--s-2); }
.row-lg { gap: var(--s-4); }
.row-wrap { flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.row-top { align-items: flex-start; }
.row-baseline { align-items: baseline; }
.grow { flex: 1 1 0; min-width: 0; }
.spacer { flex: 1 1 auto; }
.shrink-0 { flex: none; }

/* Grids: one column on phones, widening at the breakpoints. */
.grid {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: minmax(0, 1fr);
}

.grid > * { min-width: 0; }

.grid-auto {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--grid-min, 260px)), 1fr));
}

@media (min-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 1280px) {
  .grid { gap: var(--s-5); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* Main + aside. Stacks below 1280 (the sidebar already took 240px). */
.split {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

.split > * { min-width: 0; }

@media (min-width: 1280px) {
  .split { gap: var(--s-5); grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
  .split-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* -- 5. Buttons ------------------------------------------------------------ */

.btn {
  --btn-bg: var(--card);
  --btn-fg: var(--ink);
  --btn-border: var(--border-control);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--control-h);
  padding: 0 var(--s-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  transition:
    transform var(--t) var(--ease),
    box-shadow var(--t) var(--ease),
    background-color var(--t) var(--ease),
    border-color var(--t) var(--ease),
    color var(--t) var(--ease);
}
.btn:active { transform: scale(0.97); }

.btn:hover { color: var(--btn-fg); }
.btn:focus-visible { border-radius: var(--radius); }

/* Primary: white on indigo gradient. Lifts on hover. */
.btn-primary {
  --btn-bg: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  --btn-fg: #fff;
  --btn-border: transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 4px 12px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover {
  --btn-bg: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent-active) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 6px 16px rgba(79, 70, 229, 0.4);
  transform: translateY(-2px);
}

.btn-primary:active {
  --btn-bg: var(--accent-active);
  transform: none;
  box-shadow: inset 0 1px 2px rgba(42, 39, 35, 0.18);
}

/* Secondary: outlined on paper. */
.btn-secondary {
  box-shadow: var(--shadow-1);
}

.btn-secondary:hover {
  --btn-bg: var(--surface);
  --btn-border: var(--ink-2);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(42, 39, 35, 0.1);
}

.btn-secondary:active {
  --btn-bg: var(--sunken);
  transform: none;
  box-shadow: none;
}

/* Ghost: text only until hovered. */
.btn-ghost {
  --btn-bg: transparent;
  --btn-fg: var(--ink-2);
  --btn-border: transparent;
}

.btn-ghost:hover {
  --btn-bg: rgba(42, 39, 35, 0.07);
  --btn-fg: var(--ink);
}

.btn-ghost:active {
  --btn-bg: rgba(42, 39, 35, 0.12);
}

.btn-danger {
  --btn-bg: var(--danger);
  --btn-fg: #FFFFFF;
  --btn-border: #99331F;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 1px 2px rgba(42, 39, 35, 0.16);
}

.btn-danger:hover {
  --btn-bg: #BD4835;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(179, 64, 46, 0.3);
}

.btn-danger:active {
  --btn-bg: #A23826;
  transform: none;
  box-shadow: none;
}

/* Quiet destructive action: reads as text, turns red on hover. */
.btn-danger-ghost {
  --btn-bg: transparent;
  --btn-fg: var(--danger-ink);
  --btn-border: transparent;
}

.btn-danger-ghost:hover {
  --btn-bg: var(--danger-soft);
}

/* For dark cards. */
.btn-on-dark {
  --btn-bg: transparent;
  --btn-fg: var(--on-dark);
  --btn-border: rgba(246, 241, 232, 0.35);
}

.btn-on-dark:hover {
  --btn-bg: rgba(246, 241, 232, 0.1);
  --btn-border: rgba(246, 241, 232, 0.6);
}

.btn-sm {
  min-height: 32px;
  padding: 0 var(--s-3);
  font-size: var(--text-sm);
  gap: 6px;
}

.btn-lg {
  min-height: 48px;
  padding: 0 var(--s-6);
  font-size: var(--text-base);
}

.btn-block {
  display: flex;
  width: 100%;
}

/* Icon button: 40px circle (32px with .btn-sm). Always give it an aria-label. */
.btn-icon {
  width: var(--control-h);
  min-width: var(--control-h);
  padding: 0;
  border-radius: 50%;
}

.btn-icon:focus-visible { border-radius: 50%; }
.btn-icon.btn-sm { width: 32px; min-width: 32px; }
.btn-icon.btn-lg { width: 48px; min-width: 48px; }

.btn:disabled,
.btn[aria-disabled="true"],
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  pointer-events: none;
}

/* Loading: keeps its width, hides the label, shows a spinner. */
.btn.is-loading {
  color: transparent !important;
  pointer-events: none;
  opacity: 1;
}

.btn.is-loading > * {
  visibility: hidden;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border: 2px solid var(--btn-fg);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

/* -- 6. Cards -------------------------------------------------------------- */

.card {
  background: rgba(255, 254, 252, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(226, 217, 200, 0.6);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: var(--s-5);
  min-width: 0;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.card-flush { padding: 0; overflow: hidden; }
.card-pad-sm { padding: var(--s-4); }
.card-pad-lg { padding: var(--s-6); }

@media (min-width: 1280px) {
  .card-pad-lg { padding: var(--s-8); }
}

.card-hover,
a.card,
button.card {
  transition:
    transform var(--t) var(--ease),
    box-shadow var(--t) var(--ease),
    border-color var(--t) var(--ease);
}

a.card,
button.card {
  display: block;
  width: 100%;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.card-hover:hover,
a.card:hover,
button.card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
}

a.card:focus-visible,
button.card:focus-visible {
  border-radius: var(--radius-lg);
}

.card-sunken {
  background: var(--surface);
  box-shadow: none;
}

.card-accent {
  background: linear-gradient(180deg, #FDF4E4 0%, var(--card) 70%);
  border-color: #E8D2AE;
}

/* The dark card: featured integration, onboarding hero, upsell. */
.card-dark {
  background: var(--dark);
  border-color: var(--dark);
  color: var(--on-dark);
  box-shadow: var(--shadow-2);
}

.card-dark .muted,
.card-dark .card-sub,
.card-dark .eyebrow { color: var(--on-dark-muted); }
.card-dark a:not(.btn) { color: var(--accent-on-dark); }
.card-dark a:not(.btn):hover { color: var(--on-dark); }
.card-dark :focus-visible { outline-color: var(--accent-on-dark); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}

.card-flush > .card-header {
  padding: var(--s-5) var(--s-5) 0;
}

.card-title {
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.005em;
}

.card-sub {
  margin-top: 2px;
  font-size: var(--text-sm);
  color: var(--muted);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin-top: var(--s-4);
  padding-top: var(--s-3);
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
}

.card-flush > .card-footer {
  margin-top: 0;
  padding: var(--s-3) var(--s-5);
}

/* -- 7. Forms -------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
}

.label-optional {
  font-weight: 400;
  color: var(--muted);
}

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--s-3);
  border: 1px solid var(--border-control);
  border-radius: var(--radius);
  background-color: #FFFFFF;
  color: var(--ink);
  font-size: 0.9375rem;
  line-height: 1.4;
  transition:
    border-color var(--t) var(--ease),
    box-shadow var(--t) var(--ease),
    background-color var(--t) var(--ease);
  appearance: none;
  -webkit-appearance: none;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--ink-2);
}

.input:focus,
.select:focus,
.textarea:focus,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  outline: 2px solid transparent; /* visible in forced-colours mode */
  outline-offset: 0;
  border-color: var(--focus);
  border-radius: var(--radius);
  box-shadow: var(--ring);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  background-color: var(--sunken);
  color: var(--muted);
  border-color: var(--border-strong);
  cursor: not-allowed;
}

.input[readonly] {
  background-color: var(--surface);
}

.textarea {
  min-height: 96px;
  padding: 10px var(--s-3);
  line-height: 1.5;
  resize: vertical;
}

.select {
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23454A44' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9.5 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

.input-sm,
.select-sm {
  min-height: 32px;
  font-size: var(--text-sm);
  padding-left: 10px;
}

.input-lg {
  min-height: 48px;
  font-size: var(--text-md);
  padding: 0 var(--s-4);
}

.input.is-invalid,
.select.is-invalid,
.textarea.is-invalid,
.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.input.is-invalid:focus,
.textarea.is-invalid:focus,
.input[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus {
  box-shadow: var(--ring-danger);
}

.hint {
  font-size: var(--text-sm);
  color: var(--muted);
}

.field-error {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--danger-ink);
}

.field-error .icon { margin-top: 2px; }

/* Input with a leading icon: <div class="input-group">icon + input</div> */
.input-group {
  position: relative;
  display: block;
}

.input-group > .icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.input-group > .icon + .input {
  padding-left: 38px;
}

/* A trailing control inside the input (show password, clear). */
.input-group > .input-affix {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
}

.input-group.has-affix > .input {
  padding-right: 44px;
}

.form-row {
  display: grid;
  gap: var(--s-4);
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 640px) {
  .form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
  margin-top: var(--s-2);
}

.fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.fieldset > legend {
  padding: 0;
  margin-bottom: var(--s-3);
  font-weight: 600;
}

/* Toggle switch, 48x24.
   <label class="toggle"><input type="checkbox" role="switch"><span class="toggle-track"></span><span class="toggle-label">Text</span></label> */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 24px;
  cursor: pointer;
  user-select: none;
}

.toggle > input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  position: relative;
  flex: none;
  width: 48px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: #958B76;
  transition: background-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(42, 39, 35, 0.3);
  transition: transform var(--t) var(--ease);
}

.toggle > input:checked + .toggle-track {
  background: var(--accent);
}

.toggle > input:checked + .toggle-track::after {
  transform: translateX(24px);
}

.toggle > input:focus-visible + .toggle-track {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.toggle > input:disabled + .toggle-track {
  opacity: 0.5;
}

.toggle:has(> input:disabled) {
  cursor: not-allowed;
}

.toggle-label {
  font-size: 0.9375rem;
  font-weight: 500;
}

/* Setting row: text on the left, control on the right. */
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--border);
}

.setting:last-child { border-bottom: 0; }
.setting-title { font-weight: 600; }
.setting-text { font-size: var(--text-sm); color: var(--muted); margin-top: 2px; }

.checkbox,
.radio {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  cursor: pointer;
}

.checkbox > input,
.radio > input {
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  accent-color: var(--accent-ink);
  cursor: pointer;
}

/* -- Badges, chips, pills, dots -------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 var(--s-2);
  border-radius: var(--radius-pill);
  background: var(--sunken);
  color: var(--ink-2);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}

.badge .icon { margin-left: -2px; }
.badge-lg { height: 26px; padding: 0 10px; font-size: var(--text-sm); }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge-success { background: var(--success-soft); color: var(--success-ink); }
.badge-warning { background: var(--warning-soft); color: var(--warning-ink); }
.badge-danger { background: var(--danger-soft); color: var(--danger-ink); }
.badge-info { background: var(--info-soft); color: var(--info-ink); }
.badge-violet { background: var(--violet-soft); color: var(--violet-ink); }
.badge-dark { background: var(--dark); color: var(--on-dark); }
.badge-amber { background: var(--accent); color: var(--ink); }
.badge-outline { background: transparent; box-shadow: inset 0 0 0 1px var(--border-strong); color: var(--ink-2); }

/* Chip: a toggleable filter. Use <button class="chip" aria-pressed="true|false">. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: var(--card);
  color: var(--ink-2);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color var(--t) var(--ease),
    border-color var(--t) var(--ease),
    color var(--t) var(--ease);
}

.chip:hover {
  border-color: var(--ink-2);
  color: var(--ink);
}

.chip:focus-visible { border-radius: var(--radius-pill); }

.chip.is-active,
.chip[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--on-dark);
}

.chip-count {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

/* Pill: a count. */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--ink);
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.pill-muted { background: var(--sunken-strong); color: var(--ink-2); }
.pill-danger { background: var(--danger); color: #FFFFFF; }
.pill-dark { background: var(--ink); color: var(--on-dark); }

/* Status dot. Always pair with a text label (never colour alone). */
.dot {
  display: inline-block;
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.dot-lg { width: 10px; height: 10px; }
.dot-online, .dot-success { background: var(--success); }
.dot-away, .dot-warning { background: var(--warning); }
.dot-danger { background: var(--danger); }
.dot-info { background: var(--info); }
.dot-accent { background: var(--accent); }
.dot-violet { background: var(--violet); }
.dot-offline, .dot-neutral { background: transparent; box-shadow: inset 0 0 0 2px var(--faint); }

.dot-pulse {
  position: relative;
}

.dot-pulse::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: inherit;
  animation: pulse 2s var(--ease) infinite;
}

/* -- 8. Tabs --------------------------------------------------------------- */

/* Underline tabs: <div class="tabs" role="tablist"><button class="tab" role="tab" aria-selected="true">…
   Link tabs work too: <a class="tab" aria-current="page">. */
.tabs {
  display: flex;
  align-items: stretch;
  gap: var(--s-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
  min-height: var(--control-h);
  padding: 0 var(--s-3);
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--t) var(--ease), border-color var(--t) var(--ease), background-color var(--t) var(--ease);
}

.tab:hover { color: var(--ink); }
.tab:focus-visible { outline-offset: -2px; }

.tab.is-active,
.tab[aria-selected="true"],
.tab[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.tab-count {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--sunken);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

/* Segmented control: .tabs.tabs-pill */
.tabs-pill {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 0;
  border-radius: 10px;
  background: var(--sunken);
  max-width: 100%;
}

.tabs-pill .tab {
  min-height: 32px;
  margin: 0;
  border: 0;
  border-radius: 7px;
  font-size: var(--text-sm);
}

.tabs-pill .tab:focus-visible { outline-offset: 0; border-radius: 7px; }

.tabs-pill .tab.is-active,
.tabs-pill .tab[aria-selected="true"],
.tabs-pill .tab[aria-current="page"] {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(42, 39, 35, 0.14);
}

.tabs-block { display: flex; }
.tabs-block .tab { flex: 1 1 0; justify-content: center; }

/* -- 9. Tables and lists --------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-1);
  -webkit-overflow-scrolling: touch;
}

.card .table-wrap,
.table-wrap.is-plain {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.table {
  width: 100%;
  font-size: 0.875rem;
}

.table th {
  padding: 10px var(--s-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: left;
  white-space: nowrap;
}

.table td {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color var(--t) var(--ease); }
.table tbody tr:hover { background: rgba(200, 133, 63, 0.05); }
.table tr.is-selected { background: var(--accent-soft); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-compact th { padding: var(--s-2) var(--s-3); }
.table-compact td { padding: var(--s-2) var(--s-3); }
.table caption { caption-side: bottom; padding: var(--s-3) var(--s-4); text-align: left; color: var(--muted); font-size: var(--text-sm); }

.list {
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.list-item:last-child { border-bottom: 0; }
.list-plain > .list-item { padding-left: 0; padding-right: 0; }

a.list-item,
button.list-item,
.list-item-interactive {
  width: 100%;
  cursor: pointer;
  transition: background-color var(--t) var(--ease);
}

a.list-item:hover,
button.list-item:hover,
.list-item-interactive:hover {
  background: var(--surface);
  color: inherit;
}

a.list-item:focus-visible,
button.list-item:focus-visible,
.list-item-interactive:focus-visible {
  outline-offset: -2px;
}

.list-item.is-active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.list-item-main {
  flex: 1 1 0;
  min-width: 0;
}

.list-item-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-sub {
  font-size: var(--text-sm);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-meta {
  flex: none;
  font-size: var(--text-xs);
  color: var(--muted);
  white-space: nowrap;
  text-align: right;
}

/* Key / value rows */
.kv {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-4);
  font-size: 0.875rem;
}

.kv-key { color: var(--muted); flex: 1 1 auto; min-width: 0; }
.kv-value { flex: 0 1 auto; font-weight: 500; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.kv-value.tabular, .kv-value.nowrap { flex: none; white-space: nowrap; }

/* -- 10. Avatar ------------------------------------------------------------ */

.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--avatar-bg, var(--accent));
  color: #FFFFFF;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  user-select: none;
}

.avatar-on-light { color: var(--ink); }
.avatar-xs { width: 20px; height: 20px; font-size: 0.5625rem; }
.avatar-sm { width: 28px; height: 28px; font-size: 0.6875rem; }
.avatar-lg { width: 48px; height: 48px; font-size: 1rem; }
.avatar-xl { width: 64px; height: 64px; font-size: 1.375rem; }

.avatar-presence {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border: 2px solid var(--card);
  box-shadow: none;
}

.avatar-presence.dot-offline { background: var(--faint); }

.avatar-group { display: inline-flex; }
.avatar-group > .avatar { box-shadow: 0 0 0 2px var(--card); }
.avatar-group > .avatar + .avatar { margin-left: -8px; }

/* -- 11. Metric ------------------------------------------------------------ */

/* <div class="card metric"><div class="metric-top"><span class="metric-label">…</span><span class="metric-icon">icon</span></div>
     <div class="metric-value">128<span class="metric-unit">open</span></div><div class="metric-meta">…</div></div> */
.metric {
  display: flex;
  flex-direction: column;
  min-height: 132px;
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.metric-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
}

.metric-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.metric-value {
  margin-top: var(--s-3);
  font-size: 2rem;
  font-weight: 650;
  line-height: 1.1;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.metric-value.is-empty { color: var(--faint); }

.metric-unit {
  margin-left: 6px;
  font-size: var(--text-base);
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
}

.metric-meta {
  margin-top: auto;
  padding-top: var(--s-3);
  font-size: var(--text-sm);
  color: var(--muted);
}

.metric-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 600;
}

.metric-delta.is-up { color: var(--success-ink); }
.metric-delta.is-down { color: var(--danger-ink); }

/* -- 12. Empty and error states --------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--s-12) var(--s-6);
}

.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: var(--s-4);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.empty-title {
  font-size: var(--text-lg);
}

.empty-text {
  margin-top: 6px;
  max-width: 46ch;
  color: var(--muted);
  font-size: 0.875rem;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-2);
  margin-top: var(--s-5);
}

.empty-compact { padding: var(--s-6) var(--s-4); }
.empty-compact .empty-icon { width: 40px; height: 40px; margin-bottom: var(--s-3); }
.empty-compact .empty-title { font-size: var(--text-md); }
.empty-compact .empty-actions { margin-top: var(--s-3); }
.empty-error .empty-icon { background: var(--danger-soft); color: var(--danger-ink); }

/* Full-view state (missing view, 404, crash): a centred card. */
.state-page {
  display: grid;
  place-items: center;
  min-height: min(70vh, 640px);
}

.state-card {
  width: 100%;
  max-width: 560px;
}

.state-card > .empty { padding-bottom: var(--s-6); }
.state-card > .empty-actions { margin-top: 0; padding-bottom: var(--s-6); }

.state-detail {
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
  max-width: 100%;
  text-align: center;
}

/* -- 13. Skeleton and spinner ----------------------------------------------- */

.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--sunken) 0%, #F7F1E5 45%, var(--sunken) 90%);
  background-size: 220% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton-text { height: 12px; margin: 6px 0; }
.skeleton-title { height: 28px; }
.skeleton-circle { width: 36px; height: 36px; border-radius: 50%; flex: none; }
.skeleton-block { height: 120px; border-radius: var(--radius-lg); }
.skeleton-lines { display: flex; flex-direction: column; }
.skeleton-row { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) 0; }
.skeleton-row-lines { flex: 1 1 0; min-width: 0; }

.spinner {
  display: inline-block;
  flex: none;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -0.2em;
}

/* Content being refreshed in place: hold the previous render, dimmed. */
.is-refreshing {
  opacity: 0.6;
  transition: opacity var(--t) var(--ease);
}

/* -- 14. Toasts ------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  right: var(--s-5);
  bottom: var(--s-5);
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3) var(--s-3) 14px;
  border-radius: var(--radius-lg);
  background: var(--dark);
  color: var(--on-dark);
  box-shadow: var(--shadow-3);
  pointer-events: auto;
  animation: toast-in 240ms var(--ease) both;
}

.toast.is-leaving { animation: toast-out 180ms ease-in both; }
.toast-icon { flex: none; margin-top: 1px; color: var(--accent-on-dark); }
.toast-success .toast-icon { color: #86CFA2; }
.toast-error .toast-icon { color: #F2A392; }
.toast-body { flex: 1 1 0; min-width: 0; padding-top: 1px; }
.toast-title { font-weight: 600; font-size: 0.875rem; }
.toast-message { font-size: 0.875rem; line-height: 1.45; overflow-wrap: anywhere; }
.toast-title + .toast-message { color: var(--on-dark-muted); }

.toast-action {
  flex: none;
  align-self: center;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--accent-on-dark);
  font-size: var(--text-sm);
  font-weight: 700;
}

.toast-action:hover { background: rgba(246, 241, 232, 0.1); }

.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 28px;
  height: 28px;
  margin: -3px -2px 0 0;
  border-radius: 50%;
  color: var(--on-dark-muted);
  transition: background-color var(--t) var(--ease), color var(--t) var(--ease);
}

.toast-close:hover { background: rgba(246, 241, 232, 0.12); color: var(--on-dark); }
.toast :focus-visible { outline-color: var(--accent-on-dark); border-radius: 50%; }
.toast .toast-action:focus-visible { border-radius: var(--radius-sm); }

@media (max-width: 639px) {
  .toast-stack {
    left: var(--s-4);
    right: var(--s-4);
    bottom: var(--s-4);
    width: auto;
  }
}

/* -- 15. Modal and menu ------------------------------------------------------ */

.has-modal { overflow: hidden; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: var(--s-4);
  overflow-y: auto;
  background: rgba(31, 36, 33, 0.48);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade-in 160ms ease-out both;
}

.modal-backdrop.is-leaving { animation: fade-out 140ms ease-in both; }

.modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  border-radius: var(--radius-lg);
  background: rgba(255, 254, 252, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(226, 217, 200, 0.8);
  box-shadow: var(--shadow-3);
  animation: modal-in 300ms var(--ease) both;
}

.modal:focus-visible { outline: none; }
.modal-sm { max-width: 420px; }
.modal-lg { max-width: 760px; }

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-5) var(--s-5) 0 var(--s-6);
}

.modal-title {
  padding-top: 4px;
  font-size: var(--text-xl);
}

.modal-close { margin: -2px -4px 0 0; }

.modal-body {
  padding: var(--s-3) var(--s-6) var(--s-5);
  overflow-y: auto;
  min-height: 0;
}

.modal-body:empty { padding-bottom: var(--s-2); }
.modal-text { color: var(--ink-2); }

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-6);
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

@media (max-width: 479px) {
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }
}

.menu {
  position: fixed;
  z-index: 1100;
  min-width: 208px;
  max-width: min(320px, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-2);
  animation: menu-in 140ms var(--ease) both;
}

.menu:focus-visible { outline: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}

.menu-item .icon { color: var(--muted); }

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--sunken);
  color: var(--ink);
  outline: none;
}

.menu-item.is-danger,
.menu-item.is-danger .icon { color: var(--danger-ink); }
.menu-item.is-danger:hover,
.menu-item.is-danger:focus-visible { background: var(--danger-soft); }
.menu-item:disabled { opacity: 0.5; cursor: not-allowed; }
.menu-item-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item-hint { flex: none; color: var(--muted); font-size: var(--text-xs); }
.menu-separator { height: 1px; margin: 6px 4px; background: var(--border); }
.menu-header { padding: var(--s-2) 10px; }

/* -- 16. Banner -------------------------------------------------------------- */

.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  background: var(--info-soft);
  border-color: #C2D8E4;
  color: var(--ink);
}

.banner-icon { flex: none; margin-top: 1px; color: var(--info-ink); }
.banner-body { flex: 1 1 0; min-width: 0; }
.banner-title { font-weight: 600; }
.banner-text { font-size: 0.875rem; color: var(--ink-2); overflow-wrap: anywhere; }
.banner-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); flex: none; align-self: center; }
.banner-close { margin: -4px -6px -4px 0; }
.banner-warning { background: var(--warning-soft); border-color: #EBD293; }
.banner-warning .banner-icon { color: var(--warning-ink); }
.banner-critical { background: var(--danger-soft); border-color: #E9BDB1; }
.banner-critical .banner-icon { color: var(--danger-ink); }
.banner-success { background: var(--success-soft); border-color: #BFDCC4; }
.banner-success .banner-icon { color: var(--success-ink); }

@media (max-width: 639px) {
  .banner { flex-wrap: wrap; }
  .banner-actions { flex-basis: 100%; padding-left: 32px; }
}

/* -- 17. Meter / progress ----------------------------------------------------- */

/* <div class="meter" role="meter" aria-valuenow="42" aria-valuemin="0" aria-valuemax="100" aria-label="…">
     <div class="meter-fill" style="width:42%"></div></div>
   The track is a lighter step of the fill's own colour so state reads across the bar. */
.meter {
  --meter-fill: var(--accent);
  --meter-track: #F0E0C6;
  position: relative;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--meter-track);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  min-width: 0;
  max-width: 100%;
  border-radius: inherit;
  background: var(--meter-fill);
  transition: width 400ms var(--ease);
}

.meter-sm { height: 4px; }
.meter-lg { height: 12px; }
.meter-success { --meter-fill: var(--success); --meter-track: #D5E8D8; }
.meter-warning { --meter-fill: var(--warning); --meter-track: #F5E3B4; }
.meter-danger { --meter-fill: var(--danger); --meter-track: #F3D3CA; }
.meter-info { --meter-fill: var(--info); --meter-track: #D2E3EC; }
.meter-neutral { --meter-fill: var(--ink-2); --meter-track: var(--sunken-strong); }

.meter-indeterminate .meter-fill {
  width: 40%;
  animation: meter-slide 1.4s ease-in-out infinite;
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  margin-top: 6px;
  font-size: var(--text-sm);
  color: var(--muted);
}

/* -- 18. Code, snippet, kbd ---------------------------------------------------- */

.code {
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.86em;
  overflow-wrap: anywhere;
}

/* <div class="snippet"><pre>…</pre><button class="snippet-copy" aria-label="Copy">icon</button></div> */
.snippet {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  border-radius: var(--radius-lg);
  background: var(--dark);
  color: #F3EDE0;
}

.snippet pre {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  padding: 14px var(--s-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.65;
  white-space: pre;
  tab-size: 2;
  scrollbar-width: thin;
  scrollbar-color: #6B645A transparent;
}

.snippet pre:focus-visible { outline-color: var(--accent-on-dark); outline-offset: -2px; }

.snippet-wrap pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.snippet-light pre { scrollbar-color: var(--border-strong) transparent; }

/* Icon only (with an aria-label), or icon and a short word such as "Copy". */
.snippet-copy {
  flex: none;
  margin: 8px 8px 8px 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
  border-radius: var(--radius);
  background: var(--dark-raised);
  color: var(--on-dark-muted);
  transition: background-color var(--t) var(--ease), color var(--t) var(--ease);
}

.snippet-copy:hover { background: #46413A; color: var(--on-dark); }
.snippet-copy:focus-visible { outline-color: var(--accent-on-dark); border-radius: var(--radius); }

.snippet-light {
  background: var(--sunken);
  color: var(--ink);
}

.snippet-light .snippet-copy { background: var(--card); color: var(--ink-2); box-shadow: var(--shadow-1); }
.snippet-light .snippet-copy:hover { background: #FFFFFF; color: var(--ink); }
.snippet-light .snippet-copy:focus-visible { outline-color: var(--focus); }

.kbd {
  display: inline-block;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 19px;
  text-align: center;
  vertical-align: middle;
}

/* -- 19. Scroll areas ----------------------------------------------------------- */

.scroll-y,
.scroll-x,
.scroll {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  -webkit-overflow-scrolling: touch;
}

.scroll-y { overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; min-height: 0; }
.scroll-x { overflow-x: auto; overflow-y: hidden; }
.scroll { overflow: auto; overscroll-behavior: contain; min-height: 0; }

.scroll-y::-webkit-scrollbar,
.scroll-x::-webkit-scrollbar,
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }

.scroll-y::-webkit-scrollbar-thumb,
.scroll-x::-webkit-scrollbar-thumb,
.scroll::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  background-clip: content-box;
}

/* -- Charts (lib/chart.js) and bar lists ------------------------------------------- */

.chart {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  min-width: 0;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px var(--s-5);
  font-size: var(--text-sm);
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--ink-2);
}

.chart-legend-value {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Series key: a short stroke of the series colour. Text never wears the colour. */
.chart-key {
  display: inline-block;
  flex: none;
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.chart-stage {
  position: relative;
  min-width: 0;
}

.chart-plot {
  min-height: 120px;
  border-radius: var(--radius);
  touch-action: pan-y;
  cursor: crosshair;
}

.chart-plot:focus-visible { outline-offset: 4px; border-radius: var(--radius); }
.chart-svg { display: block; overflow: visible; }
.chart-grid line { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-grid .chart-baseline { stroke: var(--chart-axis); }
.chart-tick { fill: var(--muted); font-family: var(--font-body); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { opacity: 0.1; stroke: none; }
.chart-marker { stroke: var(--card); stroke-width: 2; }
.chart-cross-line { stroke: var(--border-control); stroke-width: 1; shape-rendering: crispEdges; }

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 148px;
  padding: 10px var(--s-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-2);
  font-size: var(--text-sm);
  pointer-events: none;
  white-space: nowrap;
}

.chart-tooltip-title {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
}

.chart-tooltip-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  line-height: 1.7;
}

.chart-tooltip-value {
  min-width: 2ch;
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip-label { color: var(--muted); }

/* Ranked list with magnitude bars (top intents, cost by model...).
   <ul class="barlist"><li class="barlist-row"><span class="barlist-label">…</span><span class="barlist-value">12</span>
     <span class="barlist-bar"><span class="barlist-fill" style="width:60%"></span></span></li></ul> */
.barlist {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.barlist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 6px var(--s-3);
  font-size: 0.875rem;
}

.barlist-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.barlist-value {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.barlist-sub {
  color: var(--muted);
  font-weight: 400;
}

.barlist-bar {
  grid-column: 1 / -1;
  display: block;
  height: 6px;
  border-radius: var(--radius-pill);
  background: #F0E0C6;
  overflow: hidden;
}

.barlist-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: var(--chart-1);
  transition: width 400ms var(--ease);
}

/* -- 20. App shell ---------------------------------------------------------------- */

#app {
  min-height: 100vh;
  min-height: 100dvh;
}

.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--s-6);
}

.boot-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  color: var(--muted);
  font-size: 0.875rem;
}

.boot-mark { animation: breathe 1.8s ease-in-out infinite; }

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  min-height: 0;
  padding: var(--s-4) var(--s-3) var(--s-3);
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: 2px 6px var(--s-4);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--radius);
}

.brand:hover { color: var(--ink); }

.brand-name {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1;
}

.sidebar-close { display: none; }

/* -- Workspace switcher (top of the sidebar) ------------------------------------
   One account, any number of workspaces. The mark is a gradient tile tinted by
   the workspace id (--ws-hue), so each window is recognisable at a glance. */
.ws-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px 6px 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-lg, 12px);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t) var(--ease), border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.ws-switch:hover { background: var(--card); border-color: var(--border); box-shadow: var(--shadow-1); }
.ws-switch[aria-expanded="true"] { background: var(--card); border-color: var(--border-strong); box-shadow: var(--shadow-1); }
.ws-switch > .icon { flex: none; color: var(--muted); transition: transform var(--t) var(--ease); }
.ws-switch[aria-expanded="true"] > .icon { transform: rotate(180deg); }

.ws-mark {
  --ws-hue: 248;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, hsl(var(--ws-hue) 78% 62%), hsl(calc(var(--ws-hue) + 34) 72% 48%));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 2px 6px hsl(var(--ws-hue) 60% 40% / 0.28);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
}

.ws-switch-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.ws-switch-name {
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 0.96875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-switch-sub {
  overflow: hidden;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ws-switch-dot {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  animation: ws-pulse 2.4s var(--ease) infinite;
}
@keyframes ws-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(79, 70, 229, 0); }
}
@media (prefers-reduced-motion: reduce) { .ws-switch-dot { animation: none; } }

.ws-menu-head {
  padding: 4px 10px 2px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 6px var(--s-2);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-decoration: none;
}
.sidebar-brand:hover { color: var(--ink); }

/* "Install the desktop app": offered only when the browser can install. */
.sidebar-install {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0 0 var(--s-2);
  padding: 10px;
  border: 1px solid rgba(200, 133, 63, 0.35);
  border-radius: var(--radius-lg, 12px);
  background: linear-gradient(135deg, rgba(200, 133, 63, 0.14), rgba(79, 70, 229, 0.08));
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease), border-color var(--t) var(--ease);
}
.sidebar-install[hidden] { display: none; }
.sidebar-install:hover { transform: translateY(-1px); border-color: rgba(200, 133, 63, 0.6); box-shadow: var(--shadow-1); }
.sidebar-install-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #C8853F, #A9672A);
  color: #fff;
}
.sidebar-install-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sidebar-install-text strong { font-size: var(--text-xs); font-weight: 700; }
.sidebar-install-text span { color: var(--muted); font-size: 0.6875rem; }

.install-steps { display: grid; gap: 8px; margin: 0; padding-left: 1.3em; color: var(--ink-2); }
.install-steps li::marker { color: var(--accent); font-weight: 700; }

.device-heading { margin: var(--s-2) 0 0; font-size: var(--text-sm, 0.875rem); font-weight: 700; }
.device-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.device-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.device-row > .icon { flex: none; color: var(--muted); }
.device-main { display: flex; flex: 1 1 auto; flex-direction: column; min-width: 0; }
.device-main strong { overflow: hidden; font-size: var(--text-sm, 0.875rem); text-overflow: ellipsis; white-space: nowrap; }
.device-main span { color: var(--muted); font-size: var(--text-xs); }
.device-empty { color: var(--muted); font-size: var(--text-sm, 0.875rem); }

/* -- Join-link page (/join/<token>) ---------------------------------------------- */
.join-mark {
  --ws-hue: 248;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  margin-bottom: var(--s-4);
  border-radius: 16px;
  background: linear-gradient(135deg, hsl(var(--ws-hue) 78% 62%), hsl(calc(var(--ws-hue) + 34) 72% 48%));
  box-shadow: 0 10px 24px hsl(var(--ws-hue) 60% 40% / 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  color: #fff;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  animation: join-pop 420ms var(--ease) both;
}
@keyframes join-pop { from { opacity: 0; transform: scale(0.85) translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .join-mark { animation: none; } }

.join-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: var(--s-4);
  border-radius: 14px;
  background: var(--accent-soft, rgba(79, 70, 229, 0.1));
  color: var(--accent-ink, var(--accent));
}
.join-icon.is-ended { background: rgba(42, 39, 35, 0.06); color: var(--muted); }

.join-facts {
  display: grid;
  gap: 8px;
  margin: var(--s-4) 0 var(--s-5, 20px);
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  background: var(--surface-2, rgba(42, 39, 35, 0.025));
  list-style: none;
}
.join-facts li { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: var(--text-sm, 0.875rem); }
.join-facts .icon { flex: none; color: var(--accent-ink, var(--accent)); }

.join-who {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  background: var(--card);
}
.join-who > div { display: flex; flex-direction: column; min-width: 0; }
.join-who strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.join-who span { overflow: hidden; color: var(--muted); font-size: var(--text-xs); text-overflow: ellipsis; white-space: nowrap; }
.join-note { margin-top: var(--s-3); text-align: center; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-height: var(--control-h);
  padding: 0 10px 0 var(--s-3);
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink-2);
  font-size: 0.90625rem;
  font-weight: 500;
  text-decoration: none;
  transition:
    background-color var(--t) var(--ease),
    color var(--t) var(--ease),
    border-color var(--t) var(--ease),
    box-shadow var(--t) var(--ease);
}

.nav-item .icon {
  color: var(--muted);
  transition: color var(--t) var(--ease);
}

.nav-item:hover {
  background: rgba(42, 39, 35, 0.055);
  color: var(--ink);
}

.nav-item:hover .icon { color: var(--ink-2); }
.nav-item:focus-visible { border-radius: var(--radius); outline-offset: 1px; }

.nav-item[aria-current="page"] {
  background: var(--card);
  border-color: var(--border);
  box-shadow: var(--shadow-1);
  color: var(--ink);
  font-weight: 600;
}

.nav-item[aria-current="page"] .icon { color: var(--accent-ink); }

.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 50%;
  width: 3px;
  height: 18px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  transform: translateY(-50%);
}

.nav-label { flex: 1 1 auto; min-width: 0; }
.nav-badge { flex: none; }

/* A second group of links under its own heading (Platform, for the people who run the server). */
.nav-group {
  margin-top: var(--s-3);
  padding-top: var(--s-3);
  border-top: 1px solid var(--border);
}

.nav-heading {
  margin: 0 0 var(--s-1);
  padding: 0 var(--s-3);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Said above every page while it holds, such as a suspended workspace. */
.shell-notice { flex: none; }
.shell-notice[hidden] { display: none; }

.shell-notice-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-3) var(--page-pad) 0;
}

.shell-body.is-fill .shell-notice-inner { max-width: none; padding-bottom: var(--s-3); }

.sidebar-foot {
  margin-top: auto;
  padding: var(--s-3) var(--s-2) var(--s-1);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--text-xs);
}

.sidebar-foot-button {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 32px;
  padding: 0 6px;
  border-radius: var(--radius);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 500;
  transition: background-color var(--t) var(--ease), color var(--t) var(--ease);
}

.sidebar-foot-button:hover { background: rgba(42, 39, 35, 0.055); color: var(--ink); }
.sidebar-foot-button .kbd { margin-left: auto; }

/* Right-hand column: sticky top bar over a scrolling main. */
.shell-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  flex: none;
  height: var(--topbar-h);
  background: rgba(246, 241, 232, 0.82);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--page-pad);
}

.topbar-menu { display: none; margin-left: -8px; }

.topbar-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-xl);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex: none;
}

/* Realtime indicator */
.rt-status {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--success-soft);
  color: var(--success-ink);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
  transition: background-color var(--t) var(--ease), color var(--t) var(--ease);
}

.rt-status[data-status="connecting"] { background: var(--warning-soft); color: var(--warning-ink); }
.rt-status[data-status="offline"] { background: var(--danger-soft); color: var(--danger-ink); }

.workspace-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-width: 0;
  padding: 0 var(--s-2);
}

.workspace-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
  font-weight: 600;
}

.presence-toggle .dot { width: 9px; height: 9px; }

/* Alerts: the bell in the top bar, and its settings dialog (lib/alerts.js). */
.topbar-alerts { position: relative; }

.topbar-alerts-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 8px;
  height: 8px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
}

.alerts-settings { display: grid; gap: var(--s-4); }
.alerts-intro { margin: 0; color: var(--muted); font-size: var(--text-sm); }

.alerts-group {
  display: grid;
  gap: var(--s-3);
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.alerts-group > legend {
  margin-bottom: var(--s-2);
  padding: 0;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.alerts-toggle { align-items: flex-start; }
.alerts-toggle .toggle-track { flex: none; margin-top: 2px; }
.alerts-toggle .toggle-label { display: grid; gap: 2px; }
.alerts-toggle-hint { color: var(--muted); font-size: var(--text-sm); font-weight: 400; }

.alerts-status,
.alerts-foot,
.alerts-tried {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.alerts-try { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); }

.user-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 3px;
  border-radius: var(--radius-pill);
  color: var(--ink-2);
  transition: background-color var(--t) var(--ease);
}

.user-button:hover,
.user-button[aria-expanded="true"] { background: rgba(42, 39, 35, 0.07); }
.user-button:focus-visible { border-radius: var(--radius-pill); }

/* The avatar's presence dot stands in for the presence toggle on phones. */
.user-button .avatar-presence { display: none; border-color: var(--bg); }

.user-card {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}

.user-card-name { font-weight: 600; font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card-email { color: var(--muted); font-size: var(--text-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main:focus-visible { outline: none; }

.view {
  flex: 1 0 auto;
  min-width: 0;
  animation: view-in 220ms var(--ease) both;
}

/* layout: 'fill' views own the whole area under the top bar and scroll
   internally (the inbox). The page itself does not scroll. */
.shell-body.is-fill { overflow: hidden; scrollbar-gutter: auto; }
.shell-body.is-fill .topbar-inner { max-width: none; }
.shell-body.is-fill .main { flex: 1 1 0; min-height: 0; }

.view-fill {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

/* A fill view must not grow its container while it animates in: fade only. */
.view-fill { animation-name: fade-in; }

.drawer-scrim { display: none; }

/* Below 1024: the sidebar becomes a drawer behind a hamburger. */
@media (max-width: 1023px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    width: min(288px, 86vw);
    padding-top: var(--s-3);
    box-shadow: var(--shadow-3);
    transform: translateX(-104%);
    visibility: hidden;
    transition: transform 260ms var(--ease), visibility 0s linear 260ms;
  }

  .shell.is-drawer-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform 260ms var(--ease), visibility 0s linear 0s;
  }

  .drawer-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(31, 36, 33, 0.44);
    opacity: 0;
    visibility: hidden;
    transition: opacity 260ms var(--ease), visibility 0s linear 260ms;
  }

  .shell.is-drawer-open .drawer-scrim {
    opacity: 1;
    visibility: visible;
    transition: opacity 260ms var(--ease), visibility 0s linear 0s;
  }

  .sidebar-close { display: inline-flex; }
  .topbar-menu { display: inline-flex; }
  .nav-item { min-height: 44px; }
  .sidebar-foot-button .kbd { display: none; }
}

@media (max-width: 767px) {
  :root { --topbar-h: 56px; }
  .topbar-title { font-size: var(--text-lg); }
  .workspace-chip { display: none; }
  .topbar-actions { gap: var(--s-1); }
}

@media (max-width: 639px) {
  .rt-status { width: 28px; padding: 0; justify-content: center; }
  .rt-status .rt-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  /* Presence moves into the account menu; the avatar shows the state. */
  .presence-toggle { display: none; }
  .user-button .avatar-presence { display: block; }
  .user-button .icon { display: none; }
  .user-button { padding: 6px; }
  .metric { min-height: 0; }
  .metric-value { margin-top: var(--s-2); font-size: 1.75rem; }
  .metric-meta { padding-top: var(--s-2); }
}

/* Touch: every control reaches 44px. */
@media (pointer: coarse), (max-width: 767px) {
  .btn { min-height: 44px; }
  .btn-icon, .btn-icon.btn-sm { width: 44px; min-width: 44px; }
  .input, .select { min-height: 44px; font-size: 1rem; }
  .textarea { font-size: 1rem; }
  .chip { min-height: 44px; padding: 0 var(--s-4); }
  .tab { min-height: 44px; }
  .tabs-pill .tab { min-height: 44px; }
  .menu-item { min-height: 44px; }
  .toggle { min-height: 44px; }
  .checkbox, .radio { min-height: 44px; }
  .snippet-copy { min-width: 44px; height: 44px; }
  .toast-close { width: 36px; height: 36px; }
  .sidebar-foot-button { min-height: 44px; }
  .user-button { min-width: 44px; min-height: 44px; justify-content: center; }
  .rt-status { min-height: 28px; }
}

/* -- 21. Auth screen ---------------------------------------------------------------- */

.auth {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  min-height: 100dvh;
}

.auth-brand {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  padding: var(--s-6) var(--s-5) var(--s-8);
  background: var(--dark);
  color: var(--on-dark);
  overflow: hidden;
  isolation: isolate;
}

/* A low amber glow, like a lamp on paper. */
.auth-brand::before {
  content: "";
  position: absolute;
  z-index: -1;
  right: -20%;
  bottom: -35%;
  width: 90%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(200, 133, 63, 0.34), rgba(200, 133, 63, 0) 70%);
  pointer-events: none;
}

.auth-brand .brand { color: var(--on-dark); }
.auth-brand .brand:hover { color: var(--on-dark); }
.auth-brand :focus-visible { outline-color: var(--accent-on-dark); }

.auth-headline {
  font-size: clamp(1.875rem, 4.6vw, 3.25rem);
  line-height: 1.06;
  letter-spacing: -0.02em;
  max-width: 13ch;
}

.auth-headline em {
  font-style: italic;
  color: var(--accent-on-dark);
}

.auth-lede {
  margin-top: var(--s-4);
  max-width: 46ch;
  color: var(--on-dark-muted);
  font-size: var(--text-md);
  line-height: 1.55;
}

.auth-points {
  display: none;
  flex-direction: column;
  gap: var(--s-4);
  max-width: 48ch;
}

.auth-point {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  font-size: 0.9375rem;
  line-height: 1.45;
  color: #E4DCCD;
}

.auth-point-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  background: rgba(224, 165, 96, 0.14);
  color: var(--accent-on-dark);
}

.auth-point strong { display: block; color: var(--on-dark); font-weight: 600; }

/* Faux conversation: shows the product's idea without a screenshot. */
.auth-demo {
  display: none;
  flex-direction: column;
  gap: 10px;
  max-width: 420px;
  padding: var(--s-4);
  border: 1px solid rgba(246, 241, 232, 0.12);
  border-radius: 14px;
  background: rgba(246, 241, 232, 0.05);
}

.auth-bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.45;
}

.auth-bubble-visitor {
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  background: rgba(246, 241, 232, 0.12);
  color: var(--on-dark);
}

.auth-bubble-reply {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--accent);
  color: var(--ink);
}

.auth-demo-meta {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--on-dark-muted);
  font-size: var(--text-xs);
}

.auth-demo-meta .icon { color: var(--accent-on-dark); }

.auth-fineprint {
  margin-top: auto;
  color: var(--on-dark-muted);
  font-size: var(--text-xs);
  display: none;
}

.auth-panel {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--s-8) var(--s-5) var(--s-12);
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-title {
  font-size: var(--text-2xl);
}

.auth-sub {
  margin-top: 6px;
  color: var(--muted);
}

.auth-tabs { margin: var(--s-6) 0 var(--s-5); }

.auth-form {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.auth-submit { margin-top: var(--s-2); }

.auth-invite-email { margin: 0; font-weight: 600; }
.auth-invite-email[readonly] { background-color: var(--sunken); }

.auth-switch {
  margin-top: var(--s-5);
  color: var(--muted);
  font-size: 0.875rem;
  text-align: center;
}

.auth-switch button {
  color: var(--accent-ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.auth-switch button:hover { color: var(--ink); }

/* Live password rules */
.pw-rules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px var(--s-3);
  margin-top: 2px;
}

.pw-rule {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: var(--text-xs);
  transition: color var(--t) var(--ease);
}

.pw-rule .icon { color: var(--faint); transition: color var(--t) var(--ease); }
.pw-rule.is-met { color: var(--success-ink); }
.pw-rule.is-met .icon { color: var(--success); }

@media (min-width: 640px) {
  .auth-brand { padding: var(--s-8) var(--s-10) var(--s-10); }
  .auth-panel { padding: var(--s-12) var(--s-8); }
}

@media (min-width: 1024px) {
  .auth { grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .auth-brand { padding: var(--s-10) clamp(40px, 5vw, 72px) var(--s-10); gap: var(--s-8); }
  .auth-brand-main { margin-top: auto; }
  .auth-points, .auth-demo { display: flex; }
  .auth-fineprint { display: block; }
  .auth-panel { align-items: center; padding: var(--s-10) var(--s-8); }
}

@media (min-width: 1024px) and (max-height: 760px) {
  .auth-demo { display: none; }
}

/* Keyboard shortcut sheet */
.shortcut-list {
  display: grid;
  gap: var(--s-2);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: 6px 0;
  font-size: 0.875rem;
}

.shortcut-keys {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: var(--text-xs);
}

/* -- 22. Motion, print, forced colours ----------------------------------------------- */

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@keyframes pulse {
  0% { transform: scale(1); opacity: 0.55; }
  70%, 100% { transform: scale(2.6); opacity: 0; }
}

@keyframes breathe {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.94); opacity: 0.75; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@keyframes toast-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(8px); }
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes meter-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .skeleton { animation: none; background: var(--sunken); }
  .spinner, .btn.is-loading::after { animation-duration: 1.2s !important; animation-iteration-count: infinite !important; }
  .btn:hover, .card-hover:hover, a.card:hover, button.card:hover { transform: none; }
}

@media (forced-colors: active) {
  .btn, .input, .select, .textarea, .card, .badge, .chip { border: 1px solid CanvasText; }
  .toggle-track { border: 1px solid CanvasText; }
  .meter { border: 1px solid CanvasText; }
  .meter-fill { background: Highlight; }
  .nav-item[aria-current="page"] { outline: 2px solid Highlight; }
}

@media print {
  .sidebar, .topbar, .toast-stack, .drawer-scrim, .skip-link { display: none !important; }
  .shell { display: block; height: auto; overflow: visible; }
  .shell-body { overflow: visible; }
  body { background: #FFFFFF; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* -- 23. Dialogs opened from views (mounted outside .view-*, so unscoped) ---- */

/* Share a conversation: teammate link + read-only transcript links */
.ib-share { display: flex; flex-direction: column; gap: 18px; }
.ib-share-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--surface), #FAFBFF);
}
.ib-share-head { display: flex; align-items: flex-start; gap: 12px; }
.ib-share-head .hint { margin: 2px 0 0; }
.ib-share-title { margin: 0; font-family: var(--font-display); font-size: 1rem; font-weight: 600; }
.ib-share-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: #FFFFFF;
  box-shadow: 0 8px 18px -10px rgba(79, 70, 229, 0.8);
}
.ib-share-icon.is-team { background: linear-gradient(135deg, #6366F1, #8B5CF6); }
.ib-share-icon.is-public { background: linear-gradient(135deg, #0EA5E9, #10B981); box-shadow: 0 8px 18px -10px rgba(14, 165, 233, 0.8); }
.ib-share-copy { display: flex; gap: 8px; }
.ib-share-url { flex: 1 1 auto; min-width: 0; font-family: var(--font-mono); font-size: var(--text-xs); }
.ib-share-create { display: flex; flex-wrap: wrap; gap: 8px; }
.ib-share-create .select { flex: 1 1 180px; }
.ib-share-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.ib-share-link {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  animation: ib-share-in 200ms var(--ease) both;
}
.ib-share-link.is-off { opacity: 0.6; background: var(--bg); }
.ib-share-link-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ib-share-link-meta { color: var(--muted); font-size: var(--text-xs); }
.ib-share-link-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ib-share-link-actions .ib-share-copy { flex: 1 1 260px; }
.ib-share-off { color: var(--danger-ink); }
.ib-share-locked {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-soft), #FCE7F3);
  color: var(--accent-ink);
  font-size: var(--text-sm);
}
.ib-share-locked p { margin: 4px 0 0; color: var(--ink-2); }
.ib-share-locked a { color: var(--accent); font-weight: 600; }

/* Edit a contact */
.ib-contact-form { display: flex; flex-direction: column; gap: 14px; }
.ib-contact-form .hint { margin: 0; }

/* Contact profile pieces shared by the inbox and Contacts (views/inbox/profile.js) */
.ib-blocked-note {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger-ink);
  font-size: var(--text-sm);
  font-weight: 500;
}

.ib-tag {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 2px 4px 2px 9px;
  border-radius: 999px;
  background: linear-gradient(135deg, #EEF2FF, #FCE7F3);
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.22);
  color: var(--accent-ink);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  animation: ib-tag-in 180ms var(--ease) both;
}
.ib-tag > span { overflow: hidden; text-overflow: ellipsis; }
.ib-tag-sm { padding: 0 7px; font-size: 0.6875rem; line-height: 1.55; animation: none; }
.ib-tag-more { color: var(--muted); font-size: 0.6875rem; font-weight: 600; }
.ib-tag-x {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: var(--accent-ink);
  opacity: 0.6;
  transition: opacity var(--t) var(--ease), background-color var(--t) var(--ease);
}
.ib-tag-x:hover { opacity: 1; background: rgba(79, 70, 229, 0.14); }
.ib-tag-editor { display: flex; flex-direction: column; gap: 8px; }
.ib-tag-editor.is-busy { opacity: 0.75; }
.ib-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.ib-tags:empty { display: none; }
.ib-tag-add {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  color: var(--muted);
  transition: border-color var(--t) var(--ease), background-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.ib-tag-add:focus-within { border-style: solid; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--focus); }
.ib-tag-input { flex: 1 1 auto; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font: inherit; font-size: var(--text-sm); }

.ib-kvedit-wrap { display: flex; flex-direction: column; gap: 10px; }
.ib-kvedit-wrap .ib-none { margin: 0; color: var(--muted); font-size: var(--text-sm); }
.ib-kvedit { display: flex; flex-direction: column; gap: 2px; margin: 0; }
.ib-kvedit-row {
  display: grid;
  grid-template-columns: minmax(70px, 38%) 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 4px 4px 4px 10px;
  border-radius: 8px;
  font-size: var(--text-sm);
  transition: background-color var(--t) var(--ease);
}
.ib-kvedit-row:nth-child(odd) { background: var(--bg); }
.ib-kvedit.is-readonly .ib-kvedit-row { grid-template-columns: minmax(70px, 38%) 1fr; }
.ib-kvedit-key { overflow: hidden; color: var(--muted); font-family: var(--font-mono); font-size: var(--text-xs); text-overflow: ellipsis; white-space: nowrap; }
.ib-kvedit-value { margin: 0; color: var(--ink); font-weight: 500; }
.ib-kvedit-x {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  color: var(--faint);
  opacity: 0;
  transition: opacity var(--t) var(--ease), color var(--t) var(--ease), background-color var(--t) var(--ease);
}
.ib-kvedit-row:hover .ib-kvedit-x,
.ib-kvedit-x:focus-visible { opacity: 1; }
.ib-kvedit-x:hover { color: var(--danger); background: var(--danger-soft); }
.ib-kvedit-add { display: grid; grid-template-columns: 1fr 1.3fr auto; gap: 6px; }
.ib-kvedit-add .input { min-width: 0; }
.ib-subtitle {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}

@keyframes ib-tag-in {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: none; }
}

@media (hover: none), (pointer: coarse) {
  .ib-kvedit-x { opacity: 1; }
}

@keyframes ib-share-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 520px) {
  .ib-share-copy { flex-direction: column; }
}

/* -- Two-step sign-in (lib/mfa.js, the sign-in screen) ------------------------------ */
.auth-alt { display: flex; justify-content: center; margin-top: var(--s-2); }
.auth-code,
.mfa-code { font-family: var(--font-mono); font-size: 1.25rem; letter-spacing: 0.3em; text-align: center; }
.mfa-code { max-width: 240px; }

.mfa-steps { margin: 0; padding-left: 1.25em; display: grid; gap: 4px; color: var(--ink-2); font-size: var(--text-sm); }

.mfa-scan {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-4);
  border-radius: var(--radius);
  background: var(--sunken);
}

/* The code stays dark on white in either theme, as scanners expect. */
.mfa-qr { padding: 8px; border-radius: var(--radius-sm); background: #ffffff; line-height: 0; }
.mfa-qr .qr { display: block; width: 180px; height: 180px; }
.mfa-key { display: block; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--card); font-size: var(--text-sm); letter-spacing: 0.08em; overflow-wrap: anywhere; }

.mfa-recovery { display: grid; gap: var(--s-3); }

.mfa-codes {
  margin: 0;
  padding: var(--s-3) var(--s-4) var(--s-3) 2.5em;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px var(--s-6);
  border-radius: var(--radius);
  background: var(--sunken);
  font-size: var(--text-md);
}

@media (max-width: 479px) {
  .mfa-scan { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .mfa-codes { grid-template-columns: 1fr; }
}
