/* ==========================================================================
   BFA UI — design system stylesheet  ·  v1.0  ·  Butterfly Agency (BFA)
   One file, no build step. Tokens → base → layout → components → utilities.
   Written with logical properties (inline-start/end) so dir="rtl" just works.
   ========================================================================== */

/* ---------- 0. Fonts (self-hosted, paths relative to this file) ---------- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/inter-latin-var.woff2") format("woff2-variations"), url("fonts/inter-latin-var.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/inter-latin-ext-var.woff2") format("woff2-variations"), url("fonts/inter-latin-ext-var.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/inter-latin-var-italic.woff2") format("woff2-variations"), url("fonts/inter-latin-var-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD;
}
/* Vazirmatn — Arabic-script face; covers every Sorani Kurdish letter (ڕ ڵ ۆ ێ ە ڤ پ چ ژ گ). */
@font-face { font-family: "Vazirmatn"; font-weight: 400; font-display: swap; size-adjust: 106%; src: url("fonts/vazirmatn-arabic-400.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Vazirmatn"; font-weight: 500; font-display: swap; size-adjust: 106%; src: url("fonts/vazirmatn-arabic-500.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Vazirmatn"; font-weight: 600; font-display: swap; size-adjust: 106%; src: url("fonts/vazirmatn-arabic-600.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Vazirmatn"; font-weight: 700; font-display: swap; size-adjust: 106%; src: url("fonts/vazirmatn-arabic-700.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }

/* ---------- 1. Tokens ---------- */
:root {
  color-scheme: light;

  /* 1a. Primitives — neutral (cool zinc) */
  --gray-0: #ffffff;
  --gray-25: #fbfbfc;
  --gray-50: #f7f7f8;
  --gray-100: #f1f1f3;
  --gray-150: #ebebee;
  --gray-200: #e3e3e7;
  --gray-300: #d1d1d6;
  --gray-400: #a0a0a9;
  --gray-500: #696973;
  --gray-600: #52525b;
  --gray-700: #3d3d44;
  --gray-800: #27272b;
  --gray-900: #18181b;
  --gray-950: #0e0e10;

  /* 1b. Primitives — hues (500 = graphics/dots, 600 = text/icons on white, 50/200 = tints & soft lines) */
  --blue-50: #eff4ff;  --blue-200: #c7d6fd; --blue-500: #3b6cf6; --blue-600: #2556e0; --blue-700: #1d44b8;
  --green-50: #edfcf2; --green-200: #b5ecc8; --green-500: #22a55b; --green-600: #157f45; --green-700: #116537;
  --amber-50: #fff8eb; --amber-200: #fde3a7; --amber-500: #f59e0b; --amber-600: #b45309; --amber-700: #92400e;
  --red-50: #fef2f2;   --red-200: #fecaca;   --red-500: #ef4444;   --red-600: #d42020;   --red-700: #b01b1b;
  --violet-500: #8b5cf6; --violet-600: #7041e0;
  --pink-500: #ec4899;   --teal-500: #14b8a6;   --orange-500: #f97316; --sky-500: #0ea5e9;

  /* 1c. Semantic surfaces — white is the only static surface. Fills below are for STATE only. */
  --bg: var(--gray-0);
  --bg-hover: var(--gray-50);        /* pointer over a row / ghost control */
  --bg-selected: var(--gray-100);    /* current nav item, selected row, active segment track */
  --bg-pressed: var(--gray-150);     /* :active */
  --bg-muted: var(--gray-50);        /* kbd, skeleton base, disabled input */
  --bg-inverse: var(--gray-900);     /* primary button, tooltip, solid badge */
  --bg-inverse-hover: var(--gray-800);
  --backdrop: rgba(14, 14, 16, 0.32);

  /* 1d. Semantic text */
  --text: var(--gray-900);           /* titles, names, primary labels      17.7:1 */
  --text-2: var(--gray-600);         /* body copy, secondary labels         7.7:1 */
  --text-3: var(--gray-500);         /* meta, timestamps, helper text       5.4:1 (4.8 on --bg-selected) */
  --text-4: var(--gray-400);         /* placeholder, disabled (never for meaning) */
  --text-inverse: var(--gray-0);
  --text-link: var(--blue-600);

  /* 1e. Lines */
  --line: var(--gray-150);           /* hairline separators */
  --line-control: var(--gray-200);   /* input / outline-button border */
  --line-strong: var(--gray-300);    /* hover border, checkbox border */
  --line-selected: var(--gray-900);  /* framed list item when selected */
  --line-check: #8a8a93;             /* checkbox / radio border, switch off-track — 3.4:1 non-text contrast */

  /* 1f. Intent */
  --accent: var(--blue-600);
  --accent-dot: var(--blue-500);     /* unread dot, live indicator */
  --focus: var(--blue-600);
  --focus-ring: 0 0 0 3px rgba(37, 86, 224, 0.2);
  --success: var(--green-600); --success-dot: var(--green-500); --success-line: var(--green-200); --success-tint: var(--green-50);
  --warning: var(--amber-600); --warning-dot: var(--amber-500); --warning-line: var(--amber-200); --warning-tint: var(--amber-50);
  --danger: var(--red-600);    --danger-dot: var(--red-500);    --danger-line: var(--red-200);    --danger-tint: var(--red-50);
  --info: var(--blue-600);     --info-dot: var(--blue-500);     --info-line: var(--blue-200);     --info-tint: var(--blue-50);
  --danger-ring: 0 0 0 3px rgba(212, 32, 32, 0.16);
  --on-accent: #ffffff;              /* text on an --accent fill */
  --on-danger: #ffffff;              /* text on a --danger fill (danger button) */
  --danger-hover: var(--red-700);

  /* 1g. Label / tag colours (dots and icon glyphs only, never fills) */
  --label-red: var(--red-500); --label-orange: var(--orange-500); --label-amber: var(--amber-500);
  --label-green: var(--green-500); --label-teal: var(--teal-500); --label-blue: var(--blue-500);
  --label-violet: var(--violet-500); --label-pink: var(--pink-500); --label-gray: var(--gray-400);

  /* 1h. Brand slot — swap per project. Default: ink. */
  --brand: var(--gray-900);
  --brand-contrast: var(--gray-0);

  /* 1i. Typography */
  --font-latin: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-arabic: "Vazirmatn", "Inter", "Segoe UI", Tahoma, "Noto Sans Arabic", sans-serif;
  --font-sans: "Inter", "Vazirmatn", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --text-2xs: 0.6875rem;  /* 11 — tags, micro labels */
  --text-xs: 0.75rem;     /* 12 — meta, counts, timestamps */
  --text-sm: 0.8125rem;   /* 13 — default control & list text */
  --text-base: 0.875rem;  /* 14 — body, labels, names */
  --text-md: 0.9375rem;   /* 15 — long-form reading */
  --text-lg: 1rem;        /* 16 — dialog & section titles */
  --text-xl: 1.125rem;    /* 18 — pane titles */
  --text-2xl: 1.25rem;    /* 20 — page titles, message subject */
  --text-3xl: 1.5rem;     /* 24 — settings H1 */
  --text-4xl: 1.875rem;   /* 30 — KPI numbers, auth heading */

  --lh-2xs: 14px; --lh-xs: 16px; --lh-sm: 18px; --lh-base: 20px; --lh-md: 24px;
  --lh-lg: 24px;  --lh-xl: 26px; --lh-2xl: 28px; --lh-3xl: 32px; --lh-4xl: 38px;
  --lh-prose: 1.7;

  --weight-regular: 400; --weight-medium: 500; --weight-semibold: 600; --weight-bold: 700;

  --tracking-tight: -0.02em;   /* ≥ 24px */
  --tracking-snug: -0.011em;   /* 16–20px */
  --tracking-normal: -0.003em; /* body */
  --tracking-caps: 0.04em;     /* uppercase micro labels */

  /* 1j. Space (4px grid) */
  --space-0: 0; --space-px: 1px; --space-0-5: 2px; --space-1: 4px; --space-1-5: 6px; --space-2: 8px;
  --space-2-5: 10px; --space-3: 12px; --space-4: 16px; --space-5: 20px; --space-6: 24px; --space-8: 32px;
  --space-10: 40px; --space-12: 48px; --space-16: 64px; --space-20: 80px;

  /* 1k. Radius */
  --radius-xs: 4px;   /* tags, kbd, checkbox, count in dark tab */
  --radius-sm: 6px;   /* nav items, tabs, segments, small buttons, menu items */
  --radius-md: 8px;   /* buttons, inputs, list items, file tiles, icon buttons */
  --radius-lg: 10px;  /* menus, popovers, callouts, toasts */
  --radius-xl: 12px;  /* dialogs, floating composer */
  --radius-full: 999px;

  /* 1l. Control heights */
  --h-xs: 24px; --h-sm: 28px; --h-md: 32px; --h-lg: 36px; --h-xl: 40px;

  /* 1m. Elevation — floating layers only, never static content */
  --shadow-xs: 0 1px 2px rgba(16, 16, 20, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 16, 20, 0.07), 0 1px 2px rgba(16, 16, 20, 0.04);
  --shadow-md: 0 8px 20px -6px rgba(16, 16, 20, 0.12), 0 2px 6px -2px rgba(16, 16, 20, 0.06);
  --shadow-lg: 0 20px 48px -12px rgba(16, 16, 20, 0.2), 0 6px 14px -6px rgba(16, 16, 20, 0.08);
  --inset-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.1);

  /* 1n. Motion */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-1: 100ms;  /* colour / background on hover */
  --dur-2: 160ms;  /* menus, popovers, toggles */
  --dur-3: 220ms;  /* dialogs, drawers, toasts */
  --dur-4: 320ms;  /* page-level panels */

  /* 1o. Layout */
  --rail-w: 56px;
  --sidebar-w: 248px;
  --topbar-h: 52px;
  --toolbar-h: 44px;
  --list-w: 360px;
  --reading-max: 720px;
  --content-max: 1200px;
  --page-pad: 24px;

  /* 1p. Z-index */
  --z-sticky: 10; --z-header: 20; --z-dropdown: 50; --z-drawer: 70; --z-modal: 80; --z-toast: 90; --z-tooltip: 100;

  /* 1q. Icon */
  --icon-stroke: 1.75;
}

/* Arabic-script languages: Sorani (ckb), Arabic (ar), Persian (fa), Badini written in Arabic script (kmr-Arab) */
:lang(ckb), :lang(ar), :lang(fa), :lang(kmr-Arab) {
  --font-sans: "Vazirmatn", "Inter", "Segoe UI", Tahoma, sans-serif;
  --tracking-tight: 0; --tracking-snug: 0; --tracking-normal: 0; --tracking-caps: 0;
  --lh-2xs: 18px; --lh-xs: 20px; --lh-sm: 22px; --lh-base: 24px; --lh-md: 28px;
  --lh-lg: 28px; --lh-xl: 30px; --lh-2xl: 32px; --lh-3xl: 38px; --lh-4xl: 44px;
  --lh-prose: 1.9;
}

/* Optional dark theme — opt-in only: <html data-theme="dark">. Default product theme is light/white. */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f11;
  --bg-hover: #17171a;
  --bg-selected: #1e1e22;
  --bg-pressed: #26262b;
  --bg-muted: #17171a;
  --bg-inverse: #f4f4f5;
  --bg-inverse-hover: #e4e4e7;
  --backdrop: rgba(0, 0, 0, 0.56);
  --text: #f4f4f5;
  --text-2: #b8b8c0;
  --text-3: #8e8e97;
  --text-4: #62626b;
  --text-inverse: #0f0f11;
  --text-link: #7d9bff;
  --line: #222226;
  --line-control: #2c2c31;
  --line-strong: #3a3a41;
  --line-selected: #f4f4f5;
  --line-check: #6a6a74;
  --accent: #7d9bff; --accent-dot: #5b80ff; --focus: #7d9bff; --focus-ring: 0 0 0 3px rgba(125, 155, 255, 0.28);
  --success: #4ccd85; --success-line: #1d4a31; --success-tint: #0f2219;
  --warning: #f3b440; --warning-line: #4d3812; --warning-tint: #241a08;
  --danger: #ff6b6b;  --danger-line: #4f1f1f; --danger-tint: #261010;
  --info: #7d9bff;    --info-line: #24305a;   --info-tint: #11162a;
  --on-accent: #0f0f11; --on-danger: #170707; --danger-hover: #ff8585;
  --brand: #f4f4f5; --brand-contrast: #0f0f11;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 10px 24px -6px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow-lg: 0 24px 56px -12px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.05);
  --inset-highlight: none;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; tab-size: 4; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--lh-base);
  letter-spacing: var(--tracking-normal);
  color: var(--text);
  background: var(--bg);
  -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, h4, h5, h6 { font-weight: var(--weight-semibold); color: var(--text); }
ul[role="list"], ol[role="list"], .list-reset { list-style: none; margin: 0; padding: 0; }
img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled, [aria-disabled="true"] { cursor: not-allowed; }
a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
hr { border: 0; border-block-start: 1px solid var(--line); margin: 0; }
::selection { background: var(--blue-200); color: var(--gray-900); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-xs); }
[hidden] { display: none !important; }
code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.92em; }
table { border-collapse: collapse; }

/* Directional content inside RTL pages: wrap emails, URLs, phone numbers, code in <bdi> or dir="ltr". */
.ltr { direction: ltr; unicode-bidi: isolate; }
[dir="rtl"] .ltr { text-align: right; } /* a block of LTR text still starts on the RTL side */
bdi { unicode-bidi: isolate; }
.num, .tabular { font-variant-numeric: tabular-nums; }

/* ---------- 3. Icons ---------- */
.icon {
  inline-size: 16px; block-size: 16px;
  flex: none;
  fill: none; stroke: currentColor; stroke-width: var(--icon-stroke);
  stroke-linecap: round; stroke-linejoin: round;
  vertical-align: middle;
}
.icon--xs { inline-size: 12px; block-size: 12px; stroke-width: 2; }
.icon--sm { inline-size: 14px; block-size: 14px; stroke-width: 1.9; }
.icon--md { inline-size: 18px; block-size: 18px; }
.icon--lg { inline-size: 20px; block-size: 20px; }
.icon--xl { inline-size: 24px; block-size: 24px; stroke-width: 1.5; }
.icon--2xl { inline-size: 32px; block-size: 32px; stroke-width: 1.4; }
/* Directional glyphs (chevron-left/right, arrow-left/right, reply, forward, undo, redo, send, log-in/out) */
[dir="rtl"] .icon--flip { transform: scaleX(-1); }

/* ---------- 4. Typography styles ---------- */
.t-display { font-size: var(--text-4xl); line-height: var(--lh-4xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); }
.t-h1 { font-size: var(--text-3xl); line-height: var(--lh-3xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); }
.t-h2 { font-size: var(--text-2xl); line-height: var(--lh-2xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); }
.t-h3 { font-size: var(--text-xl); line-height: var(--lh-xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); }
.t-h4 { font-size: var(--text-lg); line-height: var(--lh-lg); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); }
.t-h5 { font-size: var(--text-base); line-height: var(--lh-base); font-weight: var(--weight-semibold); }
.t-body { font-size: var(--text-base); line-height: var(--lh-base); }
.t-small { font-size: var(--text-sm); line-height: var(--lh-sm); }
.t-caption { font-size: var(--text-xs); line-height: var(--lh-xs); }
.t-micro { font-size: var(--text-2xs); line-height: var(--lh-2xs); font-weight: var(--weight-medium); letter-spacing: var(--tracking-caps); text-transform: uppercase; }
.t-mono { font-family: var(--font-mono); font-size: var(--text-sm); }
.t-medium { font-weight: var(--weight-medium); }
.t-semibold { font-weight: var(--weight-semibold); }
.t-1 { color: var(--text); } .t-2 { color: var(--text-2); } .t-3 { color: var(--text-3); } .t-4 { color: var(--text-4); }
.t-success { color: var(--success); } .t-warning { color: var(--warning); } .t-danger { color: var(--danger); } .t-accent { color: var(--accent); }

.prose { font-size: var(--text-base); line-height: var(--lh-prose); color: var(--text-2); max-inline-size: 68ch; }
.prose > * + * { margin-block-start: 12px; }
.prose h2, .prose h3 { color: var(--text); margin-block-start: 24px; }
.prose h2 { font-size: var(--text-lg); line-height: var(--lh-lg); }
.prose h3 { font-size: var(--text-base); line-height: var(--lh-base); }
.prose strong { color: var(--text); font-weight: var(--weight-semibold); }
.prose ul, .prose ol { padding-inline-start: 20px; margin-block: 0; }
.prose li + li { margin-block-start: 4px; }
.prose blockquote { border-inline-start: 2px solid var(--line-strong); padding-inline-start: 12px; color: var(--text-3); }
.prose code { background: var(--bg-muted); border: 1px solid var(--line); border-radius: var(--radius-xs); padding: 1px 4px; color: var(--text); }
.prose a { text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--blue-200); }
.prose a.file, .prose a.btn, .prose .file a { text-decoration: none; }

/* ---------- 5. App shell ---------- */
.app {
  display: grid;
  grid-template-columns: auto 1fr;
  block-size: 100dvh;
  overflow: hidden;
  background: var(--bg);
}
.app__main { display: flex; flex-direction: column; min-inline-size: 0; min-block-size: 0; }
.app__body { flex: 1; display: flex; min-block-size: 0; }

/* 5a. Rail — icon-only primary nav (reference 1) */
.rail {
  inline-size: var(--rail-w);
  display: flex; flex-direction: column; align-items: center;
  gap: 4px;
  padding-block: 12px;
  border-inline-end: 1px solid var(--line);
  background: var(--bg);
}
.rail__logo { display: grid; place-items: center; inline-size: 32px; block-size: 32px; margin-block-end: 12px; color: var(--brand); }
.rail__group { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rail__spacer { flex: 1; }
.rail__item {
  position: relative;
  display: grid; place-items: center;
  inline-size: 36px; block-size: 36px;
  border-radius: var(--radius-md);
  color: var(--text-3);
  transition: background var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.rail__item .icon { inline-size: 18px; block-size: 18px; }
.rail__item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.rail__item[aria-current="page"], .rail__item.is-active { background: var(--bg-selected); color: var(--text); }
.rail__item .dot { position: absolute; inset-block-start: 7px; inset-inline-end: 7px; box-shadow: 0 0 0 2px var(--bg); }

/* 5b. Sidebar — labelled nav (reference 2) */
.sidebar {
  inline-size: var(--sidebar-w);
  display: flex; flex-direction: column;
  border-inline-end: 1px solid var(--line);
  background: var(--bg);
  min-block-size: 0;
}
.sidebar__header { display: flex; align-items: center; gap: 8px; padding: 14px 12px 10px; }
.sidebar__search { padding: 0 12px 8px; }
.sidebar__scroll { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.sidebar__footer { padding: 8px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar__footer > hr { margin-block: 8px; }
.workspace {
  flex: 1; min-inline-size: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; margin-inline-start: -6px;
  border-radius: var(--radius-sm);
  text-align: start;
}
.workspace:hover { background: var(--bg-hover); }
.workspace__mark { inline-size: 24px; block-size: 24px; border-radius: var(--radius-sm); display: grid; place-items: center; background: var(--brand); color: var(--brand-contrast); flex: none; }
.workspace__mark .icon { inline-size: 14px; block-size: 14px; stroke-width: 2.25; }
.workspace__name { font-size: var(--text-base); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav + .nav-section, .nav-section + .nav-section { margin-block-start: 16px; }
.nav-section__label {
  display: flex; align-items: center; gap: 4px;
  block-size: 28px; padding-inline: 8px;
  font-size: var(--text-2xs); font-weight: var(--weight-medium); letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--text-4);
  inline-size: 100%;
}
button.nav-section__label:hover { color: var(--text-3); }
.nav-section__label .icon { inline-size: 12px; block-size: 12px; transition: transform var(--dur-2) var(--ease-out); }
.nav-section__label[aria-expanded="false"] .icon { transform: rotate(-90deg); }
[dir="rtl"] .nav-section__label[aria-expanded="false"] .icon { transform: rotate(90deg); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  block-size: 32px; padding-inline: 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-base); color: var(--text-2);
  text-decoration: none;
  transition: background var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
  inline-size: 100%;
  text-align: start;
}
.nav-item .icon { color: var(--text-3); }
.nav-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-item:hover .icon { color: var(--text-2); }
.nav-item[aria-current="page"], .nav-item.is-active { background: var(--bg-selected); color: var(--text); font-weight: var(--weight-medium); }
.nav-item[aria-current="page"] .icon, .nav-item.is-active .icon { color: var(--text); }
.nav-item__label { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item__meta { font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav-item__swatch { inline-size: 8px; block-size: 8px; border-radius: 2px; margin-inline: 4px; flex: none; }

.user-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: var(--radius-sm); inline-size: 100%; text-align: start; }
.user-row:hover { background: var(--bg-hover); }
.user-row__name { flex: 1; min-inline-size: 0; font-size: var(--text-sm); font-weight: var(--weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .icon { color: var(--text-3); }

/* 5c. Topbar */
.topbar {
  display: flex; align-items: center; gap: 12px;
  block-size: var(--topbar-h); flex: none;
  padding-inline: 16px;
  border-block-end: 1px solid var(--line);
  background: var(--bg);
}
.topbar__title { display: flex; align-items: center; gap: 8px; font-size: var(--text-base); font-weight: var(--weight-semibold); min-inline-size: 0; }
.topbar__title .icon { color: var(--text-2); }
.topbar__spacer { flex: 1; }
.topbar__actions { display: flex; align-items: center; gap: 8px; }

/* 5d. Page header (inside a pane or page) */
.page-header { display: flex; align-items: center; gap: 16px; padding: 16px var(--page-pad); min-block-size: 64px; }
.page-header__text { flex: 1; min-inline-size: 0; }
.page-header__title { font-size: var(--text-2xl); line-height: var(--lh-2xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); }
.page-header__desc { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text-3); margin-block-start: 2px; }
.page-header__actions { display: flex; align-items: center; gap: 8px; }
.subbar { display: flex; align-items: center; gap: 12px; padding: 0 var(--page-pad); min-block-size: 48px; border-block-end: 1px solid var(--line); }

/* 5e. Panes */
.pane { display: flex; flex-direction: column; min-inline-size: 0; min-block-size: 0; background: var(--bg); }
.pane--list { inline-size: var(--list-w); flex: none; border-inline-end: 1px solid var(--line); }
.pane--detail { flex: 1; }
.pane__scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.pane__header { padding: 12px 16px; }
.pane__footer { padding: 12px 16px; border-block-start: 1px solid var(--line); }
.page { flex: 1; overflow-y: auto; }
.page__inner { max-inline-size: var(--content-max); margin-inline: auto; padding: 0 var(--page-pad) 48px; }
.page__inner--narrow { max-inline-size: 760px; }

/* ---------- 6. Buttons ---------- */
.btn {
  --btn-h: var(--h-md);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  block-size: var(--btn-h); padding-inline: 12px;
  border: 1px solid transparent; border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1;
  white-space: nowrap; user-select: none;
  text-decoration: none;
  transition: background var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
  position: relative;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--focus); }
.btn .icon { inline-size: 16px; block-size: 16px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }

.btn--primary { background: var(--bg-inverse); color: var(--text-inverse); border-color: var(--bg-inverse); box-shadow: var(--shadow-xs), var(--inset-highlight); }
.btn--primary:hover { background: var(--bg-inverse-hover); border-color: var(--bg-inverse-hover); }
.btn--primary:active { background: var(--gray-950); }
.btn--secondary { background: var(--bg); color: var(--text); border-color: var(--line-control); box-shadow: var(--shadow-xs); }
.btn--secondary:hover { background: var(--bg-hover); border-color: var(--line-strong); }
.btn--secondary:active { background: var(--bg-selected); }
.btn--secondary .icon, .btn--ghost .icon { color: var(--text-2); }
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--bg-selected); color: var(--text); }
.btn--ghost:hover .icon { color: var(--text); }
.btn--ghost:active { background: var(--bg-pressed); }
.btn--danger { background: var(--danger); color: var(--on-danger); border-color: var(--danger); box-shadow: var(--shadow-xs), var(--inset-highlight); }
.btn--danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn--danger:focus-visible { box-shadow: var(--danger-ring); }
.btn--danger-ghost { background: transparent; color: var(--danger); }
.btn--danger-ghost:hover { background: var(--danger-tint); }
.btn--link { block-size: auto; padding: 0; border: 0; color: var(--text-link); font-weight: var(--weight-medium); }
.btn--link:hover { text-decoration: underline; text-underline-offset: 2px; }

.btn--xs { --btn-h: var(--h-xs); padding-inline: 8px; font-size: var(--text-xs); border-radius: var(--radius-sm); gap: 4px; }
.btn--xs .icon { inline-size: 14px; block-size: 14px; }
.btn--sm { --btn-h: var(--h-sm); padding-inline: 10px; font-size: var(--text-xs); border-radius: var(--radius-sm); gap: 5px; }
.btn--sm .icon { inline-size: 14px; block-size: 14px; }
.btn--lg { --btn-h: var(--h-lg); padding-inline: 14px; font-size: var(--text-base); }
.btn--xl { --btn-h: var(--h-xl); padding-inline: 16px; font-size: var(--text-base); }
.btn--block { inline-size: 100%; }

/* Icon-only. Default is bordered square (reference 1 header actions). Add .btn--ghost for toolbars. */
.btn--icon { inline-size: var(--btn-h); padding: 0; }
.btn--icon.btn--sm .icon { inline-size: 15px; block-size: 15px; }

.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading .icon { visibility: hidden; }
.btn.is-loading::after {
  content: ""; position: absolute; inset: 0; margin: auto;
  inline-size: 14px; block-size: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-inline-end-color: transparent;
  color: var(--text-2); animation: bfa-spin 700ms linear infinite;
}
.btn--primary.is-loading::after, .btn--danger.is-loading::after { color: var(--text-inverse); }

/* Split button (reference 2: “Send Now | ⏱”) */
.btn-split { display: inline-flex; align-items: stretch; border-radius: var(--radius-md); box-shadow: var(--shadow-xs); }
.btn-split > .btn { box-shadow: none; }
.btn-split > .btn:first-child { border-start-end-radius: 0; border-end-end-radius: 0; }
.btn-split > .btn:last-child { border-start-start-radius: 0; border-end-start-radius: 0; inline-size: var(--btn-h); padding: 0; }
.btn-split > .btn--primary:last-child { border-inline-start-color: rgba(255, 255, 255, 0.16); }
.btn-split > .btn--secondary:last-child { margin-inline-start: -1px; }

/* Button group (joined, e.g. prev/next) */
.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; box-shadow: none; }
.btn-group > .btn + .btn { margin-inline-start: -1px; }
.btn-group > .btn:first-child { border-start-start-radius: var(--radius-md); border-end-start-radius: var(--radius-md); }
.btn-group > .btn:last-child { border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md); }
.btn-group > .btn:hover, .btn-group > .btn:focus-visible { position: relative; z-index: 1; }
.btn-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- 7. Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-inline-size: 0; }
.field__label { display: flex; align-items: baseline; gap: 6px; font-size: var(--text-sm); line-height: var(--lh-sm); font-weight: var(--weight-medium); color: var(--text); }
.field__optional { font-weight: var(--weight-regular); color: var(--text-3); }
.field__help { font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-3); }
.field__error { display: flex; align-items: flex-start; gap: 6px; font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--danger); }
.field__error .icon { inline-size: 14px; block-size: 14px; margin-block-start: 1px; }
.field-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.input, .textarea, .select__trigger {
  --input-h: var(--h-md);
  inline-size: 100%;
  block-size: var(--input-h);
  padding-inline: 10px;
  border: 1px solid var(--line-control);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--text);
  font-size: var(--text-sm);
  transition: border-color var(--dur-1) var(--ease-out), box-shadow var(--dur-1) var(--ease-out);
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); opacity: 1; }
.input:hover, .textarea:hover, .select__trigger:hover { border-color: var(--line-strong); }
.input:focus, .textarea:focus, .select__trigger:focus-visible, .select__trigger[aria-expanded="true"] { outline: none; border-color: var(--focus); box-shadow: var(--focus-ring); }
.input:disabled, .textarea:disabled, .select__trigger:disabled { background: var(--bg-muted); color: var(--text-4); border-color: var(--line); cursor: not-allowed; }
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select__trigger[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus, .textarea[aria-invalid="true"]:focus { box-shadow: var(--danger-ring); }
.input[readonly] { background: var(--bg-muted); }
.input--sm { --input-h: var(--h-sm); font-size: var(--text-xs); border-radius: var(--radius-sm); padding-inline: 8px; }
.input--lg { --input-h: var(--h-lg); font-size: var(--text-base); }
.textarea { block-size: auto; min-block-size: 88px; padding-block: 8px; line-height: var(--lh-base); resize: vertical; }
.input[type="number"] { font-variant-numeric: tabular-nums; }
.input[type="email"], .input[type="url"], .input[type="tel"], .input--ltr { direction: ltr; }
[dir="rtl"] .input[type="email"], [dir="rtl"] .input[type="url"], [dir="rtl"] .input[type="tel"], [dir="rtl"] .input--ltr { text-align: end; }
.input[type="email"]::placeholder, .input[type="url"]::placeholder, .input[type="tel"]::placeholder { direction: inherit; }

/* Input with leading icon / trailing adornment (search, ⌘K, unit) */
.input-wrap { position: relative; display: flex; align-items: center; inline-size: 100%; }
.input-wrap > .input { flex: 1; }
.input-wrap > .icon { position: absolute; inset-inline-start: 10px; color: var(--text-3); pointer-events: none; }
.input-wrap > .icon ~ .input { padding-inline-start: 32px; }
.input-wrap__end { position: absolute; inset-inline-end: 6px; display: flex; align-items: center; gap: 4px; color: var(--text-3); font-size: var(--text-xs); }
.input-wrap:has(.input-wrap__end) > .input { padding-inline-end: 44px; }
.input-wrap--sm > .icon { inset-inline-start: 8px; inline-size: 14px; block-size: 14px; }
.input-wrap--sm > .icon ~ .input { padding-inline-start: 28px; }

/* Input group (prefix/suffix as attached text) */
.input-group { display: flex; align-items: stretch; inline-size: 100%; }
.input-group__addon {
  display: flex; align-items: center; padding-inline: 10px;
  border: 1px solid var(--line-control); color: var(--text-3); font-size: var(--text-sm); background: var(--bg);
  white-space: nowrap;
}
.input-group__addon:first-child { border-start-start-radius: var(--radius-md); border-end-start-radius: var(--radius-md); border-inline-end: 0; }
.input-group__addon:last-child { border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md); border-inline-start: 0; }
.input-group > .input:not(:first-child) { border-start-start-radius: 0; border-end-start-radius: 0; }
.input-group > .input:not(:last-child) { border-start-end-radius: 0; border-end-end-radius: 0; }

/* Custom select (no native <select> — rule). Trigger looks like an input; list is a .menu with role=listbox. */
.select { position: relative; inline-size: 100%; }
.select__trigger { display: flex; align-items: center; gap: 8px; text-align: start; cursor: pointer; }
.select__value { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select__value:empty::before, .select__value.is-placeholder { color: var(--text-4); }
.select__trigger > .icon:last-child { color: var(--text-3); transition: transform var(--dur-2) var(--ease-out); }
.select__trigger[aria-expanded="true"] > .icon:last-child { transform: rotate(180deg); }
.select > .menu { inline-size: 100%; min-inline-size: 180px; }

/* Checkbox & radio — native inputs, restyled */
.check, .radio { display: inline-flex; align-items: flex-start; gap: 8px; font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text); cursor: pointer; }
.check input, .radio input, input.checkbox, input.radio-input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none;
  inline-size: 16px; block-size: 16px; margin-block-start: 1px;
  border: 1px solid var(--line-check); background: var(--bg);
  display: grid; place-content: center;
  transition: background var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out);
  cursor: pointer;
}
.check input, input.checkbox { border-radius: var(--radius-xs); }
.radio input, input.radio-input { border-radius: 50%; }
.check input:hover, .radio input:hover, input.checkbox:hover, input.radio-input:hover { border-color: var(--text-2); }
.check input:checked, .check input:indeterminate, input.checkbox:checked, input.checkbox:indeterminate { background: var(--bg-inverse); border-color: var(--bg-inverse); }
.check input::after, input.checkbox::after {
  content: ""; inline-size: 10px; block-size: 10px; background: var(--text-inverse);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  transform: scale(0); transition: transform var(--dur-1) var(--ease-out);
}
.check input:checked::after, input.checkbox:checked::after { transform: scale(1); }
.check input:indeterminate::after, input.checkbox:indeterminate::after { -webkit-mask: none; mask: none; block-size: 2px; inline-size: 8px; border-radius: 1px; transform: scale(1); }
.radio input:checked, input.radio-input:checked { border: 5px solid var(--bg-inverse); background: var(--gray-0); }
[data-theme="dark"] .radio input:checked, [data-theme="dark"] input.radio-input:checked { background: var(--bg); }
.check input:focus-visible, .radio input:focus-visible, input.checkbox:focus-visible, input.radio-input:focus-visible { outline: none; box-shadow: var(--focus-ring); border-color: var(--focus); }
.check input:disabled, .radio input:disabled { opacity: 0.45; cursor: not-allowed; }
.check__text, .radio__text { display: flex; flex-direction: column; gap: 2px; }
.check__desc, .radio__desc { font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-3); }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: var(--text-sm); cursor: pointer; }
.switch input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none; cursor: pointer;
  inline-size: 32px; block-size: 18px; border-radius: var(--radius-full);
  background: var(--line-check); position: relative;
  transition: background var(--dur-2) var(--ease-out);
}
.switch input::after {
  content: ""; position: absolute; inset-block-start: 2px; inset-inline-start: 2px;
  inline-size: 14px; block-size: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(16, 16, 20, 0.2);
  transition: transform var(--dur-2) var(--ease-out);
}
.switch input:checked { background: var(--bg-inverse); }
.switch input:checked::after { transform: translateX(14px); }
[dir="rtl"] .switch input:checked::after { transform: translateX(-14px); }
[data-theme="dark"] .switch input:checked::after { background: var(--bg); }
.switch input:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.switch input:disabled { opacity: 0.45; cursor: not-allowed; }

/* Segmented control (reference 2: All Mails / Unread / Archive) */
.segmented {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 2px; border-radius: var(--radius-md);
  background: var(--bg-selected);
}
.segmented__item {
  display: inline-flex; align-items: center; gap: 6px;
  block-size: 28px; padding-inline: 12px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-3);
  transition: color var(--dur-1) var(--ease-out), background var(--dur-1) var(--ease-out);
  white-space: nowrap;
}
.segmented__item:hover { color: var(--text); }
.segmented__item[aria-pressed="true"], .segmented__item[aria-selected="true"], .segmented__item.is-active {
  background: var(--bg); color: var(--text); box-shadow: var(--shadow-xs), 0 0 0 1px var(--line);
}
[data-theme="dark"] .segmented__item[aria-pressed="true"], [data-theme="dark"] .segmented__item[aria-selected="true"] { background: var(--bg-pressed); }
.segmented__item:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.segmented--sm .segmented__item { block-size: 24px; padding-inline: 8px; font-size: var(--text-xs); }
.segmented--block { display: flex; }
.segmented--block .segmented__item { flex: 1; justify-content: center; }

/* Range slider */
.range { appearance: none; -webkit-appearance: none; inline-size: 100%; block-size: 18px; background: transparent; margin: 0; }
.range::-webkit-slider-runnable-track { block-size: 4px; border-radius: 4px; background: var(--gray-200); }
.range::-moz-range-track { block-size: 4px; border-radius: 4px; background: var(--gray-200); }
.range::-moz-range-progress { block-size: 4px; border-radius: 4px; background: var(--bg-inverse); }
.range::-webkit-slider-thumb { -webkit-appearance: none; inline-size: 16px; block-size: 16px; margin-block-start: -6px; border-radius: 50%; background: #fff; border: 1px solid var(--line-strong); box-shadow: var(--shadow-sm); }
.range::-moz-range-thumb { inline-size: 16px; block-size: 16px; border-radius: 50%; background: #fff; border: 1px solid var(--line-strong); box-shadow: var(--shadow-sm); }
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: var(--focus-ring); border-color: var(--focus); }

/* Dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  padding: 24px 16px; border: 1px dashed var(--line-strong); border-radius: var(--radius-lg);
  color: var(--text-3); font-size: var(--text-sm);
  transition: border-color var(--dur-1) var(--ease-out), background var(--dur-1) var(--ease-out);
  cursor: pointer;
}
.dropzone .icon { color: var(--text-3); }
.dropzone strong { color: var(--text); font-weight: var(--weight-medium); }
.dropzone:hover, .dropzone.is-dragover { border-color: var(--text-3); background: var(--bg-hover); }

/* ---------- 8. Tabs ---------- */
/* 8a. Pill tabs with counts (reference 1: Primary 67 · Company 23 · Promotions 120) */
.tabs { display: flex; align-items: center; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  block-size: 28px; padding-inline: 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-3);
  transition: background var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
  white-space: nowrap;
}
.tab .icon { inline-size: 14px; block-size: 14px; }
.tab:hover { color: var(--text); background: var(--bg-hover); }
.tab[aria-selected="true"], .tab.is-active { background: var(--bg-inverse); color: var(--text-inverse); }
.tab[aria-selected="true"] .count, .tab.is-active .count { background: var(--bg); color: var(--text); border-color: transparent; }
.tab:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* 8b. Underline tabs (page sections, settings) */
.tabs--underline { gap: 20px; border-block-end: 1px solid var(--line); }
.tabs--underline .tab { block-size: 40px; padding-inline: 0; border-radius: 0; background: none; position: relative; color: var(--text-3); }
.tabs--underline .tab:hover { background: none; color: var(--text); }
.tabs--underline .tab[aria-selected="true"], .tabs--underline .tab.is-active { background: none; color: var(--text); }
.tabs--underline .tab[aria-selected="true"]::after, .tabs--underline .tab.is-active::after {
  content: ""; position: absolute; inset-inline: 0; inset-block-end: -1px; block-size: 2px; background: var(--text); border-radius: 2px 2px 0 0;
}
.tabs--underline .tab[aria-selected="true"] .count { background: var(--bg-selected); color: var(--text-2); }

/* ---------- 9. Badges, counts, tags, chips, kbd, dots ---------- */
.count {
  display: inline-flex; align-items: center; justify-content: center;
  min-inline-size: 18px; block-size: 18px; padding-inline: 5px;
  border-radius: var(--radius-xs);
  background: var(--bg-selected); color: var(--text-3);
  font-size: var(--text-2xs); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; line-height: 1;
}
.count--pill { border-radius: var(--radius-full); }
.count--solid { background: var(--bg-inverse); color: var(--text-inverse); }
.count--accent { background: var(--accent); color: var(--on-accent); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  block-size: 22px; padding-inline: 8px;
  border: 1px solid var(--line-control); border-radius: var(--radius-full);
  background: var(--bg);
  font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-2);
  white-space: nowrap; line-height: 1;
}
.badge .icon { inline-size: 12px; block-size: 12px; stroke-width: 2; }
.badge--success { color: var(--success); border-color: var(--success-line); }
.badge--warning { color: var(--warning); border-color: var(--warning-line); }
.badge--danger { color: var(--danger); border-color: var(--danger-line); }
.badge--info { color: var(--info); border-color: var(--info-line); }
.badge--solid { /* “NEW” in reference 1 */
  block-size: 18px; padding-inline: 6px; border-radius: var(--radius-xs); border-color: var(--bg-inverse);
  background: var(--bg-inverse); color: var(--text-inverse);
  font-size: 10px; font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase;
}

.tag { /* “TAG #1” in reference 1 */
  display: inline-flex; align-items: center; gap: 4px;
  block-size: 20px; padding-inline: 6px;
  border: 1px solid var(--line-control); border-radius: var(--radius-xs);
  font-size: 10px; font-weight: var(--weight-medium); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-2);
  white-space: nowrap; line-height: 1;
}
.tag .dot { inline-size: 6px; block-size: 6px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }

.chip { /* attachment mini, recipient, filter value */
  display: inline-flex; align-items: center; gap: 6px; max-inline-size: 100%;
  block-size: 24px; padding-inline: 8px;
  border: 1px solid var(--line-control); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text-2);
  font-size: var(--text-xs); line-height: 1; white-space: nowrap;
}
.chip .icon { inline-size: 13px; block-size: 13px; color: var(--text-3); }
.chip--pill { border-radius: var(--radius-full); padding-inline: 3px 10px; }
.chip--pill .avatar { --avatar: 18px; }
.chip__label { overflow: hidden; text-overflow: ellipsis; }
.chip__remove { display: grid; place-items: center; inline-size: 16px; block-size: 16px; margin-inline-end: -4px; border-radius: var(--radius-xs); color: var(--text-3); }
.chip__remove:hover { background: var(--bg-selected); color: var(--text); }
button.chip:hover { border-color: var(--line-strong); color: var(--text); }

.kbd {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-inline-size: 20px; block-size: 20px; padding-inline: 5px;
  border: 1px solid var(--line-control); border-block-end-width: 2px; border-radius: var(--radius-xs);
  background: var(--bg);
  font-family: var(--font-sans); font-size: var(--text-2xs); font-weight: var(--weight-medium); color: var(--text-3);
  direction: ltr; line-height: 1;
}

.dot { display: inline-block; inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--accent-dot); flex: none; }
.dot--sm { inline-size: 6px; block-size: 6px; }
.dot--success { background: var(--success-dot); } .dot--warning { background: var(--warning-dot); } .dot--danger { background: var(--danger-dot); }
.dot--neutral { background: var(--gray-300); } .dot--live { animation: bfa-pulse 2s var(--ease-in-out) infinite; }

/* ---------- 10. Avatars ---------- */
.avatar {
  --avatar: 28px;
  position: relative; display: inline-grid; place-items: center; flex: none;
  inline-size: var(--avatar); block-size: var(--avatar); border-radius: 50%;
  background: var(--bg-selected); color: var(--text-2);
  font-size: calc(var(--avatar) * 0.38); font-weight: var(--weight-semibold); letter-spacing: 0; line-height: 1;
  overflow: visible; user-select: none;
}
.avatar > img { inline-size: 100%; block-size: 100%; border-radius: 50%; object-fit: cover; }
.avatar--xs { --avatar: 18px; } .avatar--sm { --avatar: 24px; } .avatar--md { --avatar: 32px; }
.avatar--lg { --avatar: 40px; } .avatar--xl { --avatar: 56px; } .avatar--2xl { --avatar: 72px; }
.avatar--square { border-radius: var(--radius-sm); } .avatar--square > img { border-radius: var(--radius-sm); }
.avatar::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 1px rgba(16, 16, 20, 0.06); pointer-events: none; }
/* Gradient orbs (reference 1) — placeholder identity when no photo; pick by hash of the id: --orb-1 … --orb-8 */
.avatar--orb { color: transparent; }
.avatar--orb-1 { background: radial-gradient(circle at 30% 25%, #ffd1a8, transparent 55%), linear-gradient(135deg, #ff4d6d, #ff9e45); }
.avatar--orb-2 { background: radial-gradient(circle at 30% 25%, #ffe0f4, transparent 55%), linear-gradient(135deg, #f472b6, #a855f7); }
.avatar--orb-3 { background: radial-gradient(circle at 30% 25%, #c8f7ff, transparent 55%), linear-gradient(135deg, #38bdf8, #6366f1); }
.avatar--orb-4 { background: radial-gradient(circle at 30% 25%, #d9ffd6, transparent 55%), linear-gradient(135deg, #34d399, #0ea5e9); }
.avatar--orb-5 { background: radial-gradient(circle at 30% 25%, #fff3b0, transparent 55%), linear-gradient(135deg, #f59e0b, #ef4444); }
.avatar--orb-6 { background: radial-gradient(circle at 30% 25%, #e6dcff, transparent 55%), linear-gradient(135deg, #8b5cf6, #1e3a8a); }
.avatar--orb-7 { background: radial-gradient(circle at 30% 25%, #ffd6e0, transparent 55%), linear-gradient(135deg, #fb7185, #3b82f6); }
.avatar--orb-8 { background: radial-gradient(circle at 30% 25%, #e0fff4, transparent 55%), linear-gradient(135deg, #14b8a6, #84cc16); }
.avatar__status { position: absolute; inset-block-end: -1px; inset-inline-end: -1px; inline-size: 30%; block-size: 30%; min-inline-size: 7px; min-block-size: 7px; border-radius: 50%; background: var(--success-dot); box-shadow: 0 0 0 2px var(--bg); }
.avatar__status--away { background: var(--warning-dot); } .avatar__status--busy { background: var(--danger-dot); } .avatar__status--offline { background: var(--gray-300); }
.avatar-stack { display: inline-flex; }
.avatar-stack > .avatar { box-shadow: 0 0 0 2px var(--bg); }
.avatar-stack > .avatar + .avatar { margin-inline-start: -6px; }

/* ---------- 11. Lists — message / item rows ---------- */
.list { display: flex; flex-direction: column; }
.list-group__header {
  position: sticky; inset-block-start: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px 8px; background: var(--bg);
  font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text);
}
.list-group__header .spacer { flex: 1; }
.list-group__meta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.list-group__toggle { display: grid; place-items: center; inline-size: 20px; block-size: 20px; border-radius: var(--radius-xs); color: var(--text-3); }
.list-group__toggle:hover { background: var(--bg-selected); color: var(--text); }
.list-group__toggle .icon { transition: transform var(--dur-2) var(--ease-out); }
.list-group__toggle[aria-expanded="false"] .icon { transform: rotate(180deg); }

/* Default: hairline-divided rows (reference 2) */
.item {
  position: relative;
  display: grid; grid-template-columns: auto 1fr; column-gap: 12px;
  padding: 12px 16px;
  border-block-end: 1px solid var(--line);
  color: inherit; text-decoration: none; text-align: start;
  cursor: pointer;
  transition: background var(--dur-1) var(--ease-out);
  inline-size: 100%;
}
.item:hover { background: var(--bg-hover); text-decoration: none; }
.item[aria-selected="true"], .item[aria-current="true"], .item.is-selected { background: var(--bg-selected); }
.item:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 0; }
.item__avatar { padding-block-start: 1px; }
.item__body { min-inline-size: 0; display: flex; flex-direction: column; gap: 2px; }
.item__top { display: flex; align-items: center; gap: 8px; min-block-size: 18px; }
.item__sender { flex: 1; min-inline-size: 0; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item__time { font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.item__subject { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); }
.item__subject > span { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item__preview { font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item__meta { display: flex; flex-wrap: wrap; gap: 4px; margin-block-start: 6px; }
.item__meta .chip { block-size: 20px; padding-inline: 6px; gap: 4px; font-size: var(--text-2xs); border-radius: var(--radius-xs); }
.item__meta .chip .icon { inline-size: 12px; block-size: 12px; }
.item.is-unread .item__sender, .item.is-unread .item__subject { font-weight: var(--weight-semibold); }
.item:not(.is-unread) .item__subject { color: var(--text-2); font-weight: var(--weight-regular); }
.item__actions {
  position: absolute; inset-block-start: 8px; inset-inline-end: 12px;
  display: none; align-items: center; gap: 2px;
  padding-inline-start: 8px;
  background: inherit;
}
.item:hover .item__actions, .item:focus-within .item__actions { display: flex; }
.item:hover .item__time, .item:focus-within .item__time { visibility: hidden; }
.item__actions .btn { --btn-h: 24px; }
.item__actions .btn .icon { inline-size: 14px; block-size: 14px; }
.item.is-dimmed { opacity: 0.5; }

/* Framed variant (reference 1): each item a hairline-bordered row, selected = ink border */
.list--framed { gap: 8px; padding: 0 12px 12px; }
.list--framed .item { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 10px 12px; }
.list--framed .item:hover { border-color: var(--line-strong); background: var(--bg); }
.list--framed .item[aria-selected="true"], .list--framed .item.is-selected { background: var(--bg); border-color: var(--line-selected); box-shadow: 0 0 0 0.5px var(--line-selected); }
.list--framed .list-group__header { padding-inline: 4px; }

/* Simple row (settings lists, members, integrations) */
.row-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-block-end: 1px solid var(--line); }
.row-item:last-child { border-block-end: 0; }
.row-item__body { flex: 1; min-inline-size: 0; }
.row-item__title { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); }
.row-item__desc { font-size: var(--text-xs); line-height: var(--lh-xs); color: var(--text-3); margin-block-start: 2px; }

/* ---------- 12. Reading view ---------- */
.toolbar { display: flex; align-items: center; gap: 2px; block-size: var(--toolbar-h); padding-inline: 12px; border-block-end: 1px solid var(--line); flex: none; }
.toolbar .btn--ghost { --btn-h: 30px; color: var(--text-3); }
.toolbar .btn--ghost .icon { color: currentColor; }
.toolbar .btn--ghost:hover { color: var(--text); }
.toolbar__sep { inline-size: 1px; block-size: 16px; background: var(--line); margin-inline: 6px; flex: none; }
.toolbar__spacer { flex: 1; }
.toolbar--bare { border: 0; padding-inline: 0; block-size: auto; }

.message { padding: 20px 24px 32px; max-inline-size: 880px; }
.message__head { display: flex; align-items: flex-start; gap: 12px; }
.message__from { flex: 1; min-inline-size: 0; }
.message__name { font-size: var(--text-base); font-weight: var(--weight-semibold); color: var(--text); }
.message__email { font-size: var(--text-xs); color: var(--text-3); }
.message__date { font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; padding-block-start: 2px; }
.message__subject { font-size: var(--text-2xl); line-height: var(--lh-2xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); color: var(--text); margin-block: 20px 12px; }
.recipients { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: var(--text-xs); color: var(--text-3); }
.recipients__label { margin-inline-end: 2px; }
.recipients__label:not(:first-child) { margin-inline-start: 8px; }
.message__body { margin-block-start: 20px; padding-block-start: 20px; border-block-start: 1px solid var(--line); }

/* Inline callout — the one small framed block allowed (offers, notices inside content) */
.callout {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--bg);
}
.callout__body { flex: 1; min-inline-size: 0; }
.callout__title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: var(--text-base); font-weight: var(--weight-semibold); color: var(--text); }
.callout__text { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text-3); margin-block-start: 4px; }
.callout__aside { display: flex; align-items: center; gap: 12px; font-size: var(--text-sm); color: var(--text-3); white-space: nowrap; }
.callout__aside strong { color: var(--text); font-weight: var(--weight-semibold); }

/* File tiles */
.files { display: flex; flex-wrap: wrap; gap: 8px; }
.file {
  display: inline-flex; align-items: center; gap: 10px; max-inline-size: 260px;
  padding-block: 8px; padding-inline: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--bg); color: inherit; text-decoration: none;
  transition: border-color var(--dur-1) var(--ease-out);
}
a.file:hover, button.file:hover { border-color: var(--line-strong); text-decoration: none; }
.file__icon { color: var(--text-3); flex: none; }
.file__icon--pdf { color: var(--red-600); } .file__icon--doc { color: var(--blue-600); } .file__icon--xls { color: var(--green-600); }
.file__icon--img { color: var(--violet-600); } .file__icon--zip { color: var(--amber-600); } .file__icon--vid { color: var(--pink-500); }
.file__body { min-inline-size: 0; display: flex; flex-direction: column; gap: 1px; }
.file__name { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file__meta { font-size: var(--text-2xs); color: var(--text-3); font-variant-numeric: tabular-nums; display: flex; gap: 6px; align-items: center; }
.file__meta a { font-weight: var(--weight-medium); }

/* ---------- 13. Composer ---------- */
.composer { border-block-start: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; }
.composer__head { display: flex; align-items: center; gap: 10px; padding: 12px 24px 4px; }
.composer__who { flex: 1; min-inline-size: 0; }
.composer__input {
  display: block; inline-size: 100%; min-block-size: 64px; max-block-size: 40vh;
  padding: 8px 24px 12px; border: 0; resize: none; background: transparent;
  font-size: var(--text-base); line-height: var(--lh-prose); color: var(--text);
}
.composer__input::placeholder { color: var(--text-4); }
.composer__input:focus { outline: none; }
.composer__bar { display: flex; align-items: center; gap: 2px; padding-block: 8px; padding-inline: 20px 16px; border-block-start: 1px solid var(--line); }
.composer__bar .btn--ghost { --btn-h: 28px; color: var(--text-3); }
.composer__bar .btn--ghost .icon { inline-size: 15px; block-size: 15px; color: currentColor; }
.composer__bar .btn--ghost:hover, .composer__bar .btn--ghost[aria-pressed="true"] { color: var(--text); }
.composer__bar .btn--ghost[aria-pressed="true"] { background: var(--bg-selected); }

/* Floating composer (reference 2) */
.composer--floating {
  border: 1px solid var(--line); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  margin: 0 20px 20px; overflow: hidden;
}
.composer--floating .composer__head { padding-block: 12px 4px; padding-inline: 16px 12px; }
.composer--floating .composer__input { padding-inline: 16px; }
.composer--floating .composer__bar { border-block-start: 0; padding-block: 8px 12px; padding-inline: 16px 12px; }
.composer__to { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); color: var(--text-3); padding: 4px 6px; margin-inline-start: -6px; border-radius: var(--radius-sm); }
.composer__to:hover { background: var(--bg-hover); }
.composer__to strong { color: var(--text); font-weight: var(--weight-medium); }

/* ---------- 14. Pagination & meters ---------- */
.pager { display: inline-flex; align-items: center; gap: 12px; font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.progress { block-size: 4px; border-radius: var(--radius-full); background: var(--gray-150); overflow: hidden; }
.progress__bar { block-size: 100%; border-radius: inherit; background: var(--bg-inverse); transition: inline-size var(--dur-4) var(--ease-out); }
.progress--success .progress__bar { background: var(--success-dot); }
.progress--warning .progress__bar { background: var(--warning-dot); }
.progress--danger .progress__bar { background: var(--danger-dot); }
[data-theme="dark"] .progress { background: var(--bg-pressed); }
.meter { display: flex; flex-direction: column; gap: 8px; }
.meter__label { display: flex; justify-content: space-between; gap: 8px; font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
.meter__label strong { color: var(--text); font-weight: var(--weight-medium); }
.spinner { inline-size: 16px; block-size: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-block-start-color: var(--text); animation: bfa-spin 700ms linear infinite; flex: none; }
.spinner--sm { inline-size: 12px; block-size: 12px; border-width: 1.5px; }
.spinner--lg { inline-size: 24px; block-size: 24px; }
.skeleton { border-radius: var(--radius-xs); background: linear-gradient(90deg, var(--gray-100) 0%, var(--gray-50) 50%, var(--gray-100) 100%); background-size: 200% 100%; animation: bfa-shimmer 1.4s linear infinite; color: transparent !important; }
[data-theme="dark"] .skeleton { background: linear-gradient(90deg, var(--bg-selected) 0%, var(--bg-pressed) 50%, var(--bg-selected) 100%); background-size: 200% 100%; }
.skeleton--text { block-size: 10px; margin-block: 4px; }
.skeleton--circle { border-radius: 50%; }

/* ---------- 15. Breadcrumbs ---------- */
.breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: var(--text-sm); color: var(--text-3); }
.breadcrumbs a { color: var(--text-3); }
.breadcrumbs a:hover { color: var(--text); text-decoration: none; }
.breadcrumbs .icon { inline-size: 14px; block-size: 14px; color: var(--text-4); }
.breadcrumbs [aria-current="page"] { color: var(--text); font-weight: var(--weight-medium); }

/* ---------- 16. Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { inline-size: 100%; font-size: var(--text-sm); color: var(--text); }
.table th {
  position: sticky; inset-block-start: 0; z-index: 1;
  block-size: 36px; padding: 0 12px;
  border-block-end: 1px solid var(--line);
  background: var(--bg);
  font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-3); text-align: start; white-space: nowrap;
}
.table td { block-size: 48px; padding: 8px 12px; border-block-end: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background var(--dur-1) var(--ease-out); }
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr[aria-selected="true"] { background: var(--bg-selected); }
.table th:first-child, .table td:first-child { padding-inline-start: var(--table-edge, 16px); }
.table th:last-child, .table td:last-child { padding-inline-end: var(--table-edge, 16px); }
.table .is-num { text-align: end; font-variant-numeric: tabular-nums; }
.table .is-check { inline-size: 40px; padding-inline-end: 0; }
.table .is-actions { inline-size: 1%; white-space: nowrap; text-align: end; }
.table .is-muted { color: var(--text-3); }
.table--compact td { block-size: 36px; padding-block: 4px; }
.th-sort { display: inline-flex; align-items: center; gap: 4px; color: inherit; font-weight: inherit; }
.th-sort:hover { color: var(--text); }
.th-sort .icon { inline-size: 12px; block-size: 12px; opacity: 0.6; }
.th-sort[aria-sort="ascending"], .th-sort[aria-sort="descending"] { color: var(--text); }
.th-sort[aria-sort="ascending"] .icon, .th-sort[aria-sort="descending"] .icon { opacity: 1; }
.cell-user { display: flex; align-items: center; gap: 10px; min-inline-size: 0; }
.cell-user__name { font-weight: var(--weight-medium); }
.cell-user__sub { font-size: var(--text-xs); color: var(--text-3); }

/* ---------- 17. Data display: description list, stats, timeline ---------- */
.dl { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; }
.dl dt, .dl dd { padding: 12px 0; border-block-end: 1px solid var(--line); font-size: var(--text-sm); }
.dl dt { color: var(--text-3); padding-inline-end: 16px; }
.dl dd { color: var(--text); }
.dl > :nth-last-child(-n + 2) { border-block-end: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); border-block: 1px solid var(--line); }
.stat { padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat + .stat { border-inline-start: 1px solid var(--line); }
.stat__label { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--text-3); }
.stat__value { font-size: var(--text-4xl); line-height: var(--lh-4xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); color: var(--text); font-variant-numeric: tabular-nums; }
.stat__delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-xs); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; }
.stat__delta--up { color: var(--success); } .stat__delta--down { color: var(--danger); }
.stat__delta .icon { inline-size: 12px; block-size: 12px; stroke-width: 2.25; }
.stat__hint { font-size: var(--text-xs); color: var(--text-3); }

.timeline { display: flex; flex-direction: column; }
.timeline__item { position: relative; display: grid; grid-template-columns: 20px 1fr; column-gap: 12px; padding-block-end: 20px; }
.timeline__item::before { content: ""; position: absolute; inset-inline-start: 9.5px; inset-block: 18px 0; inline-size: 1px; background: var(--line); }
.timeline__item:last-child::before { display: none; }
.timeline__marker { display: grid; place-items: center; inline-size: 20px; block-size: 20px; border-radius: 50%; border: 1px solid var(--line-control); background: var(--bg); color: var(--text-3); }
.timeline__marker .icon { inline-size: 11px; block-size: 11px; stroke-width: 2.25; }
.timeline__text { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text-2); padding-block-start: 1px; }
.timeline__text strong { color: var(--text); font-weight: var(--weight-medium); }
.timeline__time { font-size: var(--text-xs); color: var(--text-3); margin-block-start: 2px; }

/* ---------- 18. Overlays: menu, popover, tooltip, dialog, drawer, toast, palette ---------- */
.menu {
  position: absolute; z-index: var(--z-dropdown);
  min-inline-size: 200px; max-block-size: min(360px, 70vh); overflow-y: auto;
  padding: 4px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  transform-origin: top;
  animation: bfa-pop var(--dur-2) var(--ease-out);
}
.menu[hidden] { display: none; }
.menu--static { position: static; animation: none; z-index: auto; } /* grid/flex items honour z-index even when static */
.menu__item {
  display: flex; align-items: center; gap: 8px; inline-size: 100%;
  min-block-size: 32px; padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--text); text-align: start; text-decoration: none; cursor: pointer;
}
.menu__item .icon { color: var(--text-3); }
.menu__item:hover, .menu__item:focus-visible, .menu__item.is-highlighted { background: var(--bg-selected); outline: none; text-decoration: none; }
.menu__item:hover .icon { color: var(--text); }
.menu__item[aria-disabled="true"] { color: var(--text-4); pointer-events: none; }
.menu__item--danger, .menu__item--danger .icon { color: var(--danger); }
.menu__item--danger:hover { background: var(--danger-tint); }
.menu__label { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu__desc { display: block; font-size: var(--text-xs); color: var(--text-3); white-space: normal; }
.menu__shortcut { margin-inline-start: 16px; font-size: var(--text-xs); color: var(--text-4); direction: ltr; }
.menu__sep { block-size: 1px; background: var(--line); margin: 4px -4px; }
.menu__heading { padding: 8px 8px 4px; font-size: var(--text-2xs); font-weight: var(--weight-medium); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-4); }
/* Selection inside a menu is shown with a LEADING check column (never a trailing ✓). */
.menu--selectable .menu__item { padding-inline-start: 28px; position: relative; }
.menu--selectable .menu__item[aria-selected="true"], .menu--selectable .menu__item[aria-checked="true"] { font-weight: var(--weight-medium); }
.menu--selectable .menu__item[aria-selected="true"]::before, .menu--selectable .menu__item[aria-checked="true"]::before {
  content: ""; position: absolute; inset-inline-start: 8px; inline-size: 14px; block-size: 14px; background: var(--text);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
}
.menu__search { padding: 4px 4px 6px; border-block-end: 1px solid var(--line); margin: -4px -4px 4px; }
.menu__search .input { border: 0; box-shadow: none !important; }
.menu__empty { padding: 12px 8px; color: var(--text-3); font-size: var(--text-sm); text-align: center; }
.dropdown { position: relative; display: inline-flex; }
.dropdown > .menu { inset-block-start: calc(100% + 6px); inset-inline-start: 0; }
.dropdown--end > .menu { inset-inline-start: auto; inset-inline-end: 0; }
.dropdown--up > .menu { inset-block-start: auto; inset-block-end: calc(100% + 6px); transform-origin: bottom; }

.popover {
  position: absolute; z-index: var(--z-dropdown);
  inline-size: 320px; padding: 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  animation: bfa-pop var(--dur-2) var(--ease-out);
}

.tooltip {
  position: fixed; z-index: var(--z-tooltip); pointer-events: none;
  max-inline-size: 240px; padding: 5px 8px;
  border-radius: var(--radius-sm); background: var(--bg-inverse); color: var(--text-inverse);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: var(--lh-xs);
  box-shadow: var(--shadow-sm);
  animation: bfa-fade var(--dur-1) var(--ease-out);
}
.tooltip .kbd { background: transparent; color: var(--gray-400); border-color: rgba(255, 255, 255, 0.2); margin-inline-start: 6px; block-size: 18px; }

.dialog {
  display: flex; flex-direction: column;
  inline-size: min(480px, calc(100vw - 32px)); max-block-size: calc(100dvh - 64px);
  padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius-xl);
  background: var(--bg); color: var(--text); box-shadow: var(--shadow-lg);
  overflow: hidden;
}
dialog.dialog { margin: auto; }
dialog.dialog:not([open]) { display: none; }
dialog.dialog[open] { animation: bfa-dialog-in var(--dur-3) var(--ease-out); }
.dialog--inline { position: static; margin: 0; } /* documentation / previews only */
dialog.dialog::backdrop { background: var(--backdrop); animation: bfa-fade var(--dur-3) var(--ease-out); }
.dialog--sm { inline-size: min(400px, calc(100vw - 32px)) !important; }
.dialog--lg { inline-size: min(640px, calc(100vw - 32px)) !important; }
.dialog--xl { inline-size: min(880px, calc(100vw - 32px)) !important; }
.dialog__head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 20px 0; }
.dialog__titles { flex: 1; min-inline-size: 0; }
.dialog__title { font-size: var(--text-lg); line-height: var(--lh-lg); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-snug); }
.dialog__desc { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text-3); margin-block-start: 4px; }
.dialog__head .btn--icon { margin-block-start: -4px; margin-inline-end: -6px; }
.dialog__body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.dialog__foot { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 4px 20px 20px; }
.dialog__foot--split { justify-content: space-between; }
.dialog__icon { display: grid; place-items: center; inline-size: 36px; block-size: 36px; border-radius: 50%; border: 1px solid var(--line); color: var(--text-2); flex: none; }
.dialog__icon--danger { color: var(--danger); border-color: var(--danger-line); }

dialog.drawer {
  position: fixed; inset-block: 0; inset-inline-end: 0; inset-inline-start: auto; margin: 0;
  inline-size: min(440px, 100vw); max-inline-size: 100vw; block-size: 100dvh; max-block-size: 100dvh;
  padding: 0; border: 0; border-inline-start: 1px solid var(--line);
  background: var(--bg); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.drawer[open] { display: flex; flex-direction: column; animation: bfa-drawer-in var(--dur-3) var(--ease-out); }
[dir="rtl"] dialog.drawer[open] { animation-name: bfa-drawer-in-rtl; }
dialog.drawer::backdrop { background: var(--backdrop); }
dialog.drawer--start { inset-inline-start: 0; inset-inline-end: auto; border-inline-start: 0; border-inline-end: 1px solid var(--line); }
.drawer__head { display: flex; align-items: center; gap: 12px; padding-inline: 20px 12px; block-size: var(--topbar-h); border-block-end: 1px solid var(--line); flex: none; }
.drawer__title { flex: 1; font-size: var(--text-base); font-weight: var(--weight-semibold); }
.drawer__body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.drawer__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-block-start: 1px solid var(--line); }

.toasts { position: fixed; z-index: var(--z-toast); inset-block-end: 20px; inset-inline-end: 20px; display: flex; flex-direction: column; gap: 8px; inline-size: min(380px, calc(100vw - 40px)); pointer-events: none; }
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  padding-block: 12px; padding-inline: 14px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
  animation: bfa-toast-in var(--dur-3) var(--ease-out);
}
.toast.is-leaving { animation: bfa-toast-out var(--dur-2) var(--ease-in-out) forwards; }
.toast > .icon { margin-block-start: 1px; }
.toast--success > .icon { color: var(--success); } .toast--danger > .icon { color: var(--danger); }
.toast--warning > .icon { color: var(--warning); } .toast--info > .icon { color: var(--info); }
.toast__body { flex: 1; min-inline-size: 0; }
.toast__title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text); }
.toast__text { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text-3); margin-block-start: 2px; }
.toast__actions { display: flex; gap: 12px; margin-block-start: 8px; }
.toast .btn--icon { --btn-h: 24px; margin-block-start: -4px; margin-inline-end: -4px; }

dialog.palette { inline-size: min(600px, calc(100vw - 32px)); margin-block-start: 14vh; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--bg); color: var(--text); box-shadow: var(--shadow-lg); overflow: hidden; }
dialog.palette[open] { display: flex; flex-direction: column; animation: bfa-dialog-in var(--dur-2) var(--ease-out); }
dialog.palette::backdrop { background: var(--backdrop); }
.palette__search { display: flex; align-items: center; gap: 10px; padding: 0 16px; block-size: 52px; border-block-end: 1px solid var(--line); }
.palette__search .icon { color: var(--text-3); }
.palette__search input { flex: 1; border: 0; background: transparent; font-size: var(--text-base); color: var(--text); }
.palette__search input:focus { outline: none; }
.palette__search input::placeholder { color: var(--text-4); }
.palette__results { max-block-size: 360px; overflow-y: auto; padding: 4px 8px 8px; }
.palette__results .menu__item { min-block-size: 36px; }
.palette__foot { display: flex; align-items: center; gap: 16px; padding: 8px 16px; border-block-start: 1px solid var(--line); font-size: var(--text-xs); color: var(--text-3); }
.palette__foot span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- 19. Feedback: alert, banner, empty, error ---------- */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-md);
  background: var(--bg); font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text-2);
}
.alert > .icon { margin-block-start: 1px; color: var(--text-3); }
.alert__body { flex: 1; min-inline-size: 0; }
.alert__title { font-weight: var(--weight-semibold); color: var(--text); }
.alert__title + .alert__text { margin-block-start: 2px; }
.alert__actions { display: flex; gap: 12px; margin-block-start: 8px; }
.alert--info { border-color: var(--info-line); } .alert--info > .icon { color: var(--info); }
.alert--success { border-color: var(--success-line); } .alert--success > .icon { color: var(--success); }
.alert--warning { border-color: var(--warning-line); } .alert--warning > .icon { color: var(--warning); }
.alert--danger { border-color: var(--danger-line); } .alert--danger > .icon { color: var(--danger); }

.banner { display: flex; align-items: center; gap: 10px; padding: 10px var(--page-pad); border-block-end: 1px solid var(--line); font-size: var(--text-sm); color: var(--text-2); background: var(--bg); }
.banner > .icon { color: var(--text-3); }
.banner__text { flex: 1; min-inline-size: 0; }
.banner--warning > .icon { color: var(--warning); } .banner--danger > .icon { color: var(--danger); } .banner--info > .icon { color: var(--info); }

.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 4px; padding: 48px 24px; margin: auto; max-inline-size: 360px; }
.empty__icon { display: grid; place-items: center; inline-size: 44px; block-size: 44px; border-radius: 50%; border: 1px solid var(--line); color: var(--text-3); margin-block-end: 12px; }
.empty__icon .icon { inline-size: 20px; block-size: 20px; }
.empty__title { font-size: var(--text-base); font-weight: var(--weight-semibold); color: var(--text); }
.empty__text { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text-3); }
.empty__actions { display: flex; gap: 8px; margin-block-start: 16px; }

/* ---------- 20. Settings layout ---------- */
.settings-section { display: grid; grid-template-columns: minmax(200px, 280px) 1fr; gap: 24px 48px; padding-block: 28px; border-block-end: 1px solid var(--line); }
.settings-section:last-child { border-block-end: 0; }
.settings-section__title { font-size: var(--text-base); font-weight: var(--weight-semibold); color: var(--text); }
.settings-section__desc { font-size: var(--text-sm); line-height: var(--lh-sm); color: var(--text-3); margin-block-start: 4px; }
.settings-section__body { display: flex; flex-direction: column; gap: 20px; min-inline-size: 0; max-inline-size: 560px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-block: 16px; border-block-start: 1px solid var(--line); }

/* ---------- 21. Utilities (small, deliberate set) ---------- */
.row { display: flex; align-items: center; gap: var(--gap, 8px); }
.stack { display: flex; flex-direction: column; gap: var(--gap, 8px); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-inline-size: 0; }
.spacer { flex: 1; }
.between { justify-content: space-between; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-inline-size: 0; }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.divider { block-size: 1px; background: var(--line); border: 0; }
.divider-v { inline-size: 1px; align-self: stretch; background: var(--line); }
.hairline-top { border-block-start: 1px solid var(--line); }
.hairline-bottom { border-block-end: 1px solid var(--line); }
.sr-only { position: absolute !important; inline-size: 1px; block-size: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.no-scrollbar { scrollbar-width: none; } .no-scrollbar::-webkit-scrollbar { display: none; }
.scroll-thin { scrollbar-width: thin; scrollbar-color: var(--gray-300) transparent; }

/* ---------- 22. Motion ---------- */
@keyframes bfa-spin { to { transform: rotate(360deg); } }
@keyframes bfa-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes bfa-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes bfa-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bfa-pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes bfa-dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes bfa-drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bfa-drawer-in-rtl { from { transform: translateX(-24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bfa-toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes bfa-toast-out { to { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* ---------- 23. Responsive & input modality ---------- */
/* Touch: every interactive control grows to a 40px target */
@media (pointer: coarse) {
  :root { --h-sm: 36px; --h-md: 40px; --h-lg: 44px; }
  .nav-item { block-size: 40px; }
  .rail__item { inline-size: 40px; block-size: 40px; }
  .menu__item { min-block-size: 40px; }
  .item__actions { display: none !important; }
  .item:hover .item__time { visibility: visible; }
}
/* Desktop collapse: [data-sidebar-toggle] adds .is-sidebar-collapsed */
@media (min-width: 1024px) { .app.is-sidebar-collapsed > .sidebar { display: none; } }
/* < 1024: sidebar becomes a drawer (toggle with [data-sidebar-toggle]) */
@media (max-width: 1023.98px) {
  :root { --list-w: 320px; --page-pad: 20px; }
  .app > .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: var(--z-drawer);
    box-shadow: var(--shadow-lg); transform: translateX(-100%); transition: transform var(--dur-3) var(--ease-out);
  }
  [dir="rtl"] .app > .sidebar { transform: translateX(100%); }
  .app.is-sidebar-open > .sidebar { transform: none; }
  .app.is-sidebar-open:has(> .sidebar)::after { content: ""; position: fixed; inset: 0; z-index: calc(var(--z-drawer) - 1); background: var(--backdrop); }
  .settings-section { grid-template-columns: 1fr; gap: 16px; }
}
/* < 768: single pane. List shows; selecting an item adds .is-detail-open on .app__body to swap to detail. */
@media (max-width: 767.98px) {
  :root { --page-pad: 16px; --topbar-h: 52px; }
  .app { grid-template-columns: 1fr; }
  .app > .rail { display: none; }
  .pane--list { inline-size: 100%; border-inline-end: 0; }
  .app__body > .pane--detail { display: none; }
  .app__body.is-detail-open > .pane--list { display: none; }
  .app__body.is-detail-open > .pane--detail { display: flex; }
  .hide-mobile { display: none !important; }
  .page-header { flex-wrap: wrap; row-gap: 12px; }
  .page-header__actions { flex-wrap: wrap; inline-size: 100%; }
  .message { padding: 16px; }
  .composer__head, .composer__input { padding-inline: 16px; }
  .stat + .stat { border-inline-start: 0; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:nth-child(even) { border-inline-start: 1px solid var(--line); }
  .stats .stat:nth-child(n + 3) { border-block-start: 1px solid var(--line); }
  .dl { grid-template-columns: 1fr; }
  .dl dt { border-block-end: 0; padding-block-end: 0; }
  .callout { flex-direction: column; align-items: stretch; gap: 12px; }
  .callout__aside { justify-content: space-between; }
  .app__main:has(.app__body.is-detail-open) > .subbar { display: none; }
  .app.is-sidebar-open > .rail { display: flex; position: fixed; inset-block: 0; inset-inline-start: 0; z-index: var(--z-drawer); box-shadow: var(--shadow-lg); animation: bfa-drawer-in var(--dur-3) var(--ease-out); }
  .app.is-sidebar-open:has(> .rail)::after { content: ""; position: fixed; inset: 0; z-index: calc(var(--z-drawer) - 1); background: var(--backdrop); }
  .toasts { inset-inline: 12px; inset-block-end: 12px; inline-size: auto; }
}
@media (min-width: 768px) { .show-mobile { display: none !important; } }

/* Print: ink on white, no chrome */
@media print {
  .rail, .sidebar, .topbar, .toolbar, .composer, .toasts { display: none !important; }
  .app { display: block; block-size: auto; }
  body { color: #000; }
}
