/* ═══════════════════════════════════════════════════════════════════════════
   Bubbly Design System — public/bubbly.css  (served as /assets/bubbly.css)
   Identity: ink-black actions on clean white canvases, soft aurora light,
   glass navigation, pill controls, generous radii, Inter display type with
   tight tracking. Brand = "bubble" gradient (pink #ff3d8b → orange #ff8a3d),
   used sparingly: the mark, highlights and "you are here" indicators.
   Prefix: bb- (classes) and --bb- (custom properties).
   Theming: light-dark() + color-scheme (Chrome 123+, Firefox 120+, Safari 17.5+).
   Page-level styles live in bubbly-home.css, bubbly-management.css,
   bubbly-editor.css, bubbly-media.css and bubbly-report.css.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 1. Font ─────────────────────────────────────────────────────────────── */
/* Inter 4 variable (SIL OFL 1.1, see /assets/fonts/Inter-OFL.txt), latin subset. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/assets/fonts/inter-latin-wght-normal.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;
}

/* ── 2. Tokens ───────────────────────────────────────────────────────────── */
:root {
  color-scheme: light dark;

  /* Brand — decorative only (mark, gradients, glows). Never body text. */
  --bb-brand-pink:      #ff3d8b;
  --bb-brand-orange:    #ff8a3d;
  --bb-brand-gradient:  linear-gradient(135deg, var(--bb-brand-pink) 0%, var(--bb-brand-orange) 100%);
  /* Large-text-safe stops (≥ 3:1 on light canvases) for display highlights. */
  --bb-brand-text-from: light-dark(#e0156f, #ff5fa2);
  --bb-brand-text-to:   light-dark(#ea580c, #ff9a5c);

  /* Surfaces */
  --bb-bg:             light-dark(#f6f6f7, #0a0a0b);
  --bb-canvas:         light-dark(#ffffff, #0a0a0b);
  --bb-surface:        light-dark(#ffffff, #141416);
  --bb-surface-raised: light-dark(#f1f1f3, #1c1c1f);
  --bb-surface-sunken: light-dark(#ececef, #0f0f11);
  --bb-hover:          light-dark(rgba(10,10,10,.045), rgba(255,255,255,.06));
  --bb-press:          light-dark(rgba(10,10,10,.08), rgba(255,255,255,.1));

  /* Text */
  --bb-text:   light-dark(#0a0a0a, #f5f5f7);
  --bb-muted:  light-dark(#5f5f66, #a1a1aa);
  --bb-subtle: light-dark(#71717a, #8e8e96);

  /* Borders */
  --bb-border:        light-dark(#e6e6e9, #26262b);
  --bb-border-strong: light-dark(#d4d4d8, #3a3a40);

  /* Ink — primary actions */
  --bb-ink:       light-dark(#0a0a0a, #f5f5f7);
  --bb-ink-hover: light-dark(#2a2a2f, #ffffff);
  --bb-on-ink:    light-dark(#ffffff, #0a0a0a);

  /* Accent — Bubbly pink, text-safe (≥ 4.5:1 on surfaces) */
  --bb-accent:        light-dark(#c8195f, #ff5fa2);
  --bb-accent-hover:  light-dark(#a8124f, #ff7ab3);
  --bb-accent-subtle: light-dark(rgba(255,61,139,.10), rgba(255,95,162,.14));
  --bb-on-accent:     light-dark(#ffffff, #0a0a0a);

  /* Semantic */
  --bb-danger:          light-dark(#b91c1c, #f87171);
  --bb-danger-subtle:   light-dark(rgba(185,28,28,.07), rgba(248,113,113,.12));
  --bb-success:         light-dark(#166534, #34d399);
  --bb-success-subtle:  light-dark(rgba(22,101,52,.07), rgba(52,211,153,.12));
  --bb-warning:         light-dark(#92400e, #fbbf24);
  --bb-warning-subtle:  light-dark(rgba(146,64,14,.07), rgba(251,191,36,.12));

  /* Data visualisation */
  --bb-chart-1: var(--bb-accent);
  --bb-chart-2: light-dark(#0a0a0a, #e4e4e7);
  --bb-chart-3: light-dark(#ea580c, #ff9a5c);
  --bb-chart-4: light-dark(#6d5dfc, #a59bff);
  --bb-chart-grid: var(--bb-border);

  /* Radius */
  --bb-radius:      12px;   /* inputs, small controls */
  --bb-radius-md:   16px;   /* tiles, menus, notices */
  --bb-radius-lg:   22px;   /* cards */
  --bb-radius-xl:   30px;   /* panels, dialogs, hero media */
  --bb-radius-pill: 999px;

  /* Elevation */
  --bb-shadow:    0 1px 2px light-dark(rgba(10,10,10,.05), rgba(0,0,0,.45));
  --bb-shadow-md: 0 1px 2px light-dark(rgba(10,10,10,.04), rgba(0,0,0,.4)), 0 12px 32px -12px light-dark(rgba(10,10,10,.14), rgba(0,0,0,.65));
  --bb-shadow-lg: 0 2px 6px light-dark(rgba(10,10,10,.05), rgba(0,0,0,.45)), 0 32px 64px -24px light-dark(rgba(10,10,10,.24), rgba(0,0,0,.75));
  --bb-ring:      0 0 0 4px var(--bb-accent-subtle);

  /* Glass */
  --bb-glass:        light-dark(rgba(255,255,255,.74), rgba(20,20,22,.72));
  --bb-glass-border: light-dark(rgba(255,255,255,.85), rgba(255,255,255,.08));
  --bb-glass-blur:   blur(24px) saturate(180%);

  /* Typography */
  --bb-font:      "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --bb-font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, monospace;
  --bb-tracking-display: -.045em;
  --bb-tracking-tight:   -.025em;

  /* Z-index scale */
  --bb-z-base:     0;
  --bb-z-raised:   10;
  --bb-z-dropdown: 20;
  --bb-z-sticky:   40;
  --bb-z-overlay:  100;
  --bb-z-modal:    200;
  --bb-z-toast:    300;

  /* Shell dimensions */
  --bb-sidebar-w: 248px;
  --bb-topbar-h:  60px;
  --bb-bottom-h:  64px;

  /* Motion */
  --bb-dur-fast: 140ms;
  --bb-dur-base: 220ms;
  --bb-dur-slow: 360ms;
  --bb-ease:     cubic-bezier(.2,0,0,1);
  --bb-ease-out: cubic-bezier(.22,1,.36,1);
}

/* Explicit overrides: tokens follow color-scheme through light-dark(). */
[data-theme="dark"]  { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }

/* ── 3. Reset & base ─────────────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 6rem;
}

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

body {
  font-family: var(--bb-font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--bb-text);
  background: var(--bb-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
}
body.bb-public { background: var(--bb-canvas); }

img,svg,video { display: block; max-width: 100%; }
a { color: var(--bb-accent); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input,textarea,select { font-family: inherit; font-size: inherit; color: var(--bb-text); }
ul,ol { list-style: none; }
h1,h2,h3,h4,h5,h6 { font-weight: 700; line-height: 1.2; letter-spacing: var(--bb-tracking-tight); color: var(--bb-text); text-wrap: balance; font-feature-settings: "cv11"; }
p { text-wrap: pretty; }
code,kbd,samp,pre { font-family: var(--bb-font-mono); font-size: .9em; }
strong { font-weight: 650; }
::selection { background: light-dark(rgba(255,61,139,.2), rgba(255,95,162,.32)); }

/* ── 4. Accessibility ────────────────────────────────────────────────────── */
.bb-skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: var(--bb-z-toast);
  padding: .625rem 1.125rem;
  background: var(--bb-ink);
  border-radius: var(--bb-radius-pill);
  color: var(--bb-on-ink);
  font-weight: 600;
  font-size: .875rem;
  text-decoration: none;
  transition: top var(--bb-dur-fast) var(--bb-ease);
}
.bb-skip-link:focus { top: 1rem; }

:focus-visible { outline: 2px solid var(--bb-accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

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

/* ── 5. Typography primitives ────────────────────────────────────────────── */
.bb-eyebrow {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--bb-muted);
  margin-bottom: .75rem;
}
.bb-eyebrow::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--bb-brand-gradient);
  flex-shrink: 0;
}

.bb-display {
  font-size: clamp(2.5rem, 5vw + 1rem, 4.75rem);
  font-weight: 800;
  letter-spacing: var(--bb-tracking-display);
  line-height: .98;
}

.bb-title {
  font-size: clamp(1.5rem, 1.2vw + 1.1rem, 2rem);
  font-weight: 800;
  letter-spacing: -.035em;
  line-height: 1.12;
}

.bb-description {
  font-size: .9375rem;
  color: var(--bb-muted);
  line-height: 1.6;
  margin-top: .375rem;
  max-width: 60ch;
}

.bb-brand-text {
  background: linear-gradient(100deg, var(--bb-brand-text-from) 0%, var(--bb-brand-text-to) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.bb-link {
  color: var(--bb-text);
  font-weight: 550;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--bb-accent) 55%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  transition: text-decoration-color var(--bb-dur-fast) var(--bb-ease);
}
.bb-link:hover { color: var(--bb-text); text-decoration-color: var(--bb-accent); }

/* ── 6. Wordmark ─────────────────────────────────────────────────────────── */
.bb-wordmark {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  min-height: 44px;
  font-size: 1.3125rem;
  font-weight: 800;
  letter-spacing: -.05em;
  color: var(--bb-text);
  text-decoration: none;
  flex-shrink: 0;
  line-height: 1;
}
.bb-wordmark:hover { color: var(--bb-text); text-decoration: none; }
.bb-wordmark-mark { width: 28px; height: 28px; flex-shrink: 0; transition: transform var(--bb-dur-slow) var(--bb-ease-out); }
.bb-wordmark:hover .bb-wordmark-mark { transform: rotate(-12deg) scale(1.06); }
.bb-wordmark-text { padding-bottom: 2px; }

/* ── 7. Surfaces: aurora light & glass ───────────────────────────────────── */
/* Soft, fixed aurora behind public pages (home, sign-in, notices). */
.bb-aurora { position: relative; isolation: isolate; }
.bb-aurora::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(44rem 32rem at 6% -8%,  light-dark(rgba(146,168,255,.30), rgba(99,102,241,.16)), transparent 70%),
    radial-gradient(42rem 30rem at 98% 2%,  light-dark(rgba(255,176,140,.34), rgba(255,122,61,.12)), transparent 70%),
    radial-gradient(38rem 26rem at 70% 108%, light-dark(rgba(255,120,180,.20), rgba(255,61,139,.10)), transparent 70%);
}

.bb-glass {
  background: var(--bb-glass);
  -webkit-backdrop-filter: var(--bb-glass-blur);
  backdrop-filter: var(--bb-glass-blur);
  border: 1px solid var(--bb-glass-border);
}

/* Initial avatar */
.bb-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bb-brand-gradient);
  color: #fff;
  font-size: .875rem;
  font-weight: 700;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}

/* ── 8. App shell ────────────────────────────────────────────────────────── */
.bb-app {
  display: flex;
  min-height: 100dvh;
  background: var(--bb-bg);
}

/* Sidebar: sits on the canvas; the active page floats as a white pill. */
.bb-sidebar {
  width: var(--bb-sidebar-w);
  flex-shrink: 0;
  background: var(--bb-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-block: 0;
  left: 0;
  z-index: var(--bb-z-overlay);
  overflow-y: auto;
  overflow-x: hidden;
  padding: .75rem .75rem 1rem;
  transition: transform var(--bb-dur-slow) var(--bb-ease-out), box-shadow var(--bb-dur-slow) var(--bb-ease-out);
  scrollbar-width: thin;
  scrollbar-color: var(--bb-border) transparent;
}

.bb-sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .375rem .5rem 1.25rem;
  flex-shrink: 0;
}

.bb-sidebar-close { display: none; }

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

.bb-nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 0 .875rem;
  min-height: 44px;
  border-radius: var(--bb-radius);
  color: var(--bb-muted);
  font-size: .9375rem;
  font-weight: 550;
  text-decoration: none;
  transition: background var(--bb-dur-fast) var(--bb-ease), color var(--bb-dur-fast) var(--bb-ease), box-shadow var(--bb-dur-fast) var(--bb-ease);
  touch-action: manipulation;
  cursor: pointer;
}
.bb-nav-item:hover { background: var(--bb-hover); color: var(--bb-text); text-decoration: none; }

.bb-nav-item[aria-current="page"],
.bb-nav-item.bb-nav-item-active {
  background: var(--bb-surface);
  color: var(--bb-text);
  font-weight: 650;
  box-shadow: var(--bb-shadow), 0 0 0 1px var(--bb-border);
}

.bb-nav-item-icon { display: flex; flex-shrink: 0; opacity: .8; transition: color var(--bb-dur-fast) var(--bb-ease); }
.bb-nav-item[aria-current="page"] .bb-nav-item-icon,
.bb-nav-item.bb-nav-item-active .bb-nav-item-icon { opacity: 1; color: var(--bb-accent); }

.bb-sidebar-foot {
  margin-top: 1rem;
  padding: .75rem .75rem .375rem;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: .375rem;
  border-radius: var(--bb-radius-md);
  background: var(--bb-surface);
  box-shadow: 0 0 0 1px var(--bb-border);
}

.bb-nav-user { display: flex; align-items: center; gap: .625rem; min-width: 0; }
.bb-nav-user-text { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; min-width: 0; }
.bb-nav-user-meta { display: flex; align-items: center; gap: .5rem; }

.bb-nav-user-email {
  max-width: 100%;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--bb-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bb-sidebar-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: .25rem;
  border-top: 1px solid var(--bb-border);
}
.bb-sidebar-actions form { margin: 0; }

/* Backdrop */
.bb-sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10,10,10,.4);
  z-index: calc(var(--bb-z-overlay) - 1);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

/* App content wrapper */
.bb-app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100dvh;
}

/* Mobile/tablet topbar */
.bb-topbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .75rem;
  height: var(--bb-topbar-h);
  background: var(--bb-glass);
  -webkit-backdrop-filter: var(--bb-glass-blur);
  backdrop-filter: var(--bb-glass-blur);
  border-bottom: 1px solid var(--bb-border);
  position: sticky;
  top: 0;
  z-index: var(--bb-z-sticky);
  flex-shrink: 0;
}
.bb-topbar .bb-wordmark { flex: 1; }

/* Main content area */
.bb-main { flex: 1; min-width: 0; }
.bb-main.bb-main-full { overflow: hidden; }

/* Bottom nav (mobile) */
.bb-bottom-nav {
  display: flex;
  background: var(--bb-glass);
  -webkit-backdrop-filter: var(--bb-glass-blur);
  backdrop-filter: var(--bb-glass-blur);
  border-top: 1px solid var(--bb-border);
  position: sticky;
  bottom: 0;
  z-index: var(--bb-z-sticky);
  padding: .25rem .25rem env(safe-area-inset-bottom, 0px);
  flex-shrink: 0;
}

.bb-bottom-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1875rem;
  padding: .375rem .25rem;
  min-height: var(--bb-bottom-h);
  border-radius: var(--bb-radius);
  color: var(--bb-muted);
  font-size: .6875rem;
  font-weight: 600;
  text-decoration: none;
  transition: color var(--bb-dur-fast) var(--bb-ease), background var(--bb-dur-fast) var(--bb-ease);
  touch-action: manipulation;
}
.bb-bottom-item svg { transition: transform var(--bb-dur-base) var(--bb-ease-out); }
.bb-bottom-item:hover { color: var(--bb-text); text-decoration: none; }
.bb-bottom-item[aria-current="page"],
.bb-bottom-item.bb-bottom-item-active { color: var(--bb-text); }
.bb-bottom-item[aria-current="page"] svg,
.bb-bottom-item.bb-bottom-item-active svg { color: var(--bb-accent); transform: translateY(-1px); }

/* Desktop: sidebar always visible; content floats as a workspace panel. */
@media (min-width: 1024px) {
  .bb-sidebar { transform: none !important; }
  .bb-sidebar-close { display: none !important; }
  .bb-topbar { display: none; }
  .bb-bottom-nav { display: none; }
  .bb-app-content { margin-left: var(--bb-sidebar-w); padding: .75rem .75rem .75rem 0; }
  .bb-main {
    background: var(--bb-surface);
    border: 1px solid var(--bb-border);
    border-radius: var(--bb-radius-xl);
    box-shadow: var(--bb-shadow);
  }
  .bb-main.bb-main-full { height: calc(100dvh - 1.5rem); }
}

/* Mobile/tablet: sidebar is a drawer */
@media (max-width: 1023px) {
  .bb-sidebar {
    transform: translateX(-100%);
    visibility: hidden;
    width: min(86vw, 300px);
    background: var(--bb-surface);
    border-radius: 0 var(--bb-radius-xl) var(--bb-radius-xl) 0;
  }
  .bb-sidebar.bb-sidebar-open { transform: translateX(0); visibility: visible; box-shadow: var(--bb-shadow-lg); }
  .bb-sidebar-close { display: inline-flex; }
  .bb-sidebar-foot { background: var(--bb-surface-raised); box-shadow: none; }
  .bb-nav-item[aria-current="page"],
  .bb-nav-item.bb-nav-item-active { background: var(--bb-surface-raised); box-shadow: none; }
}

/* ── 9. Page primitives ──────────────────────────────────────────────────── */
.bb-page {
  padding: 2.25rem 2.5rem 4rem;
  max-width: 1200px;
  margin-inline: auto;
}
.bb-page.bb-page-full { max-width: none; }

.bb-page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.bb-page-header-text { flex: 1; min-width: 0; }
.bb-page-header h1,
.bb-page-header .bb-title {
  font-size: clamp(1.75rem, 1.4vw + 1.2rem, 2.375rem);
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1.08;
}

.bb-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* ── 10. Buttons ─────────────────────────────────────────────────────────── */
.bb-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: 0 1.25rem;
  min-height: 44px;
  border-radius: var(--bb-radius-pill);
  font-family: var(--bb-font);
  font-size: .9375rem;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.2;
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  transition:
    background var(--bb-dur-fast) var(--bb-ease),
    color var(--bb-dur-fast) var(--bb-ease),
    border-color var(--bb-dur-fast) var(--bb-ease),
    box-shadow var(--bb-dur-fast) var(--bb-ease),
    transform var(--bb-dur-fast) var(--bb-ease);
}
.bb-button:hover { text-decoration: none; }
.bb-button:active { transform: scale(.97); }
.bb-button:disabled,
.bb-button[aria-disabled="true"] {
  opacity: .42;
  cursor: not-allowed;
  pointer-events: none;
}
.bb-button[aria-busy="true"] { opacity: .78; cursor: progress; }
.bb-button[aria-busy="true"]::before {
  content: "";
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: bb-spin .7s linear infinite;
}
@keyframes bb-spin { to { transform: rotate(360deg); } }

.bb-button-primary {
  background: var(--bb-ink);
  color: var(--bb-on-ink);
  border-color: var(--bb-ink);
  box-shadow: 0 1px 2px rgba(10,10,10,.18), inset 0 1px 0 rgba(255,255,255,.12);
}
.bb-button-primary:hover {
  background: var(--bb-ink-hover);
  border-color: var(--bb-ink-hover);
  color: var(--bb-on-ink);
}

.bb-button-secondary {
  background: var(--bb-surface);
  color: var(--bb-text);
  border-color: var(--bb-border-strong);
}
.bb-button-secondary:hover { background: var(--bb-surface-raised); color: var(--bb-text); }

.bb-button-ghost {
  background: transparent;
  color: var(--bb-muted);
  border-color: transparent;
}
.bb-button-ghost:hover { background: var(--bb-hover); color: var(--bb-text); }

.bb-button-danger {
  background: var(--bb-surface);
  color: var(--bb-danger);
  border-color: color-mix(in srgb, var(--bb-danger) 35%, transparent);
}
.bb-button-danger:hover { background: var(--bb-danger-subtle); border-color: var(--bb-danger); }

.bb-button-full { width: 100%; }

.bb-button-sm { padding: 0 .875rem; min-height: 36px; font-size: .8125rem; gap: .375rem; }
.bb-button-lg { padding: 0 1.75rem; min-height: 54px; font-size: 1rem; }

/* Icon-only button */
.bb-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--bb-radius-pill);
  color: var(--bb-muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
  transition: background var(--bb-dur-fast) var(--bb-ease), color var(--bb-dur-fast) var(--bb-ease), transform var(--bb-dur-fast) var(--bb-ease);
}
.bb-icon-button:hover { background: var(--bb-hover); color: var(--bb-text); }
.bb-icon-button:active { transform: scale(.94); }

/* Touch devices and phone widths: every control reaches 44px. */
@media (pointer: coarse), (max-width: 767px) {
  .bb-button-sm { min-height: 44px; }
  .bb-icon-button { width: 44px; height: 44px; }
}

/* ── 11. Cards, grids & metrics ──────────────────────────────────────────── */
.bb-card {
  background: var(--bb-surface);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius-lg);
  padding: 1.5rem;
  box-shadow: var(--bb-shadow);
}

.bb-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.125rem;
}

.bb-card-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.015em;
  color: var(--bb-text);
}

.bb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.bb-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.bb-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }

.bb-metric {
  background: var(--bb-surface);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius-lg);
  padding: 1.25rem 1.375rem 1.375rem;
  box-shadow: var(--bb-shadow);
  min-width: 0;
}

.bb-metric-label {
  font-size: .8125rem;
  font-weight: 550;
  color: var(--bb-muted);
  margin-bottom: .625rem;
}

.bb-metric-value {
  font-size: clamp(1.75rem, 1.2vw + 1.2rem, 2.25rem);
  font-weight: 750;
  color: var(--bb-text);
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.bb-metric-sub { font-size: .8125rem; color: var(--bb-muted); margin-top: .5rem; }

/* ── 12. Forms ───────────────────────────────────────────────────────────── */
.bb-form { display: flex; flex-direction: column; gap: 1.25rem; }

.bb-field { display: flex; flex-direction: column; gap: .4375rem; min-width: 0; }

.bb-label { font-size: .875rem; font-weight: 600; color: var(--bb-text); }

.bb-required { color: var(--bb-accent); margin-left: .125rem; }

.bb-input,
.bb-select,
.bb-textarea {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  padding: .6875rem .9375rem;
  background: var(--bb-surface);
  border: 1px solid var(--bb-border-strong);
  border-radius: var(--bb-radius);
  color: var(--bb-text);
  font-size: 1rem;
  line-height: 1.4;
  min-height: 46px;
  transition: border-color var(--bb-dur-fast) var(--bb-ease), box-shadow var(--bb-dur-fast) var(--bb-ease), background var(--bb-dur-fast) var(--bb-ease);
}
.bb-input:hover,.bb-select:hover,.bb-textarea:hover { border-color: var(--bb-subtle); }
.bb-input:focus,.bb-select:focus,.bb-textarea:focus {
  outline: none;
  border-color: var(--bb-accent);
  box-shadow: var(--bb-ring);
}
.bb-input::placeholder,.bb-textarea::placeholder { color: var(--bb-subtle); opacity: 1; }
.bb-input[readonly],.bb-input[disabled],.bb-select[disabled],.bb-textarea[readonly],.bb-textarea[disabled] {
  background: var(--bb-surface-raised);
  color: var(--bb-muted);
  border-color: var(--bb-border);
  cursor: default;
}
.bb-input[aria-invalid="true"],.bb-input.bb-input-error,.bb-select[aria-invalid="true"],.bb-textarea[aria-invalid="true"] {
  border-color: var(--bb-danger);
  box-shadow: 0 0 0 4px var(--bb-danger-subtle);
}

.bb-textarea { resize: vertical; min-height: 104px; }

.bb-select {
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%2371717a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.625rem;
  cursor: pointer;
}

.bb-help { font-size: .8125rem; color: var(--bb-muted); line-height: 1.5; }

.bb-error {
  font-size: .8125rem;
  font-weight: 550;
  color: var(--bb-danger);
  display: flex;
  align-items: flex-start;
  gap: .375rem;
}

/* Input with embedded button (password toggle) */
.bb-input-wrap { position: relative; display: flex; }
.bb-input-wrap .bb-input { padding-right: 3rem; }

.bb-password-toggle {
  position: absolute;
  right: 1px; top: 1px; bottom: 1px;
  width: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bb-subtle);
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 0 var(--bb-radius) var(--bb-radius) 0;
  transition: color var(--bb-dur-fast) var(--bb-ease);
}
.bb-password-toggle:hover { color: var(--bb-text); }
.bb-pw-icon-show,.bb-pw-icon-hide { display: flex; }

/* Checkbox / self-declaration */
.bb-check {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  cursor: pointer;
  font-size: .875rem;
  color: var(--bb-text);
  line-height: 1.5;
}
.bb-check input[type="checkbox"],
.bb-check input[type="radio"] {
  width: 18px; height: 18px;
  flex-shrink: 0;
  margin-top: .15em;
  accent-color: var(--bb-accent);
  cursor: pointer;
}

/* Error summary */
.bb-error-summary {
  background: var(--bb-danger-subtle);
  border: 1px solid color-mix(in srgb, var(--bb-danger) 30%, transparent);
  border-radius: var(--bb-radius-md);
  padding: .875rem 1.125rem;
  color: var(--bb-danger);
  font-size: .875rem;
}
.bb-error-summary p + p { margin-top: .25rem; }
.bb-error-summary p:first-child { font-weight: 600; }
.bb-error-summary:focus { outline: none; box-shadow: 0 0 0 4px var(--bb-danger-subtle); }

/* ── 13. Notices & badges ────────────────────────────────────────────────── */
.bb-notice {
  border-radius: var(--bb-radius-md);
  padding: 1rem 1.25rem;
  font-size: .875rem;
  line-height: 1.55;
  border: 1px solid;
}
.bb-notice-title { font-weight: 650; margin-bottom: .25rem; }

.bb-notice-info    { background: var(--bb-surface-raised); border-color: var(--bb-border); color: var(--bb-text); }
.bb-notice-success { background: var(--bb-success-subtle); border-color: color-mix(in srgb, var(--bb-success) 28%, transparent); color: var(--bb-success); }
.bb-notice-error   { background: var(--bb-danger-subtle);  border-color: color-mix(in srgb, var(--bb-danger) 28%, transparent);  color: var(--bb-danger); }
.bb-notice-warning { background: var(--bb-warning-subtle); border-color: color-mix(in srgb, var(--bb-warning) 28%, transparent); color: var(--bb-warning); }
.bb-notice-info .bb-link,.bb-notice-info a { color: var(--bb-text); }

.bb-badge {
  display: inline-flex;
  align-items: center;
  gap: .3125rem;
  padding: .1875rem .625rem;
  border-radius: var(--bb-radius-pill);
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .005em;
  line-height: 1.4;
  white-space: nowrap;
  /* Translucent so neutral badges stay visible on raised and tinted surfaces too. */
  background: color-mix(in srgb, var(--bb-text) 6%, transparent);
  color: var(--bb-muted);
  border: 1px solid var(--bb-border);
}
.bb-badge-accent  { background: var(--bb-accent-subtle);  color: var(--bb-accent);  border-color: transparent; }
.bb-badge-success { background: var(--bb-success-subtle); color: var(--bb-success); border-color: transparent; }
.bb-badge-danger  { background: var(--bb-danger-subtle);  color: var(--bb-danger);  border-color: transparent; }
.bb-badge-warning { background: var(--bb-warning-subtle); color: var(--bb-warning); border-color: transparent; }
.bb-badge-ink     { background: var(--bb-ink);            color: var(--bb-on-ink);   border-color: transparent; }

/* ── 14. Tables ──────────────────────────────────────────────────────────── */
.bb-table-wrap {
  overflow-x: auto;
  background: var(--bb-surface);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius-lg);
}
.bb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
.bb-table th {
  text-align: left;
  padding: .75rem 1rem;
  color: var(--bb-subtle);
  font-size: .6875rem;
  font-weight: 650;
  letter-spacing: .1em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--bb-border);
  white-space: nowrap;
}
.bb-table td {
  padding: .875rem 1rem;
  color: var(--bb-text);
  border-bottom: 1px solid var(--bb-border);
  vertical-align: middle;
}
.bb-table tr:last-child td { border-bottom: none; }
.bb-table tbody tr { transition: background var(--bb-dur-fast) var(--bb-ease); }
.bb-table tbody tr:hover td { background: var(--bb-hover); }

/* ── 15. Empty state ─────────────────────────────────────────────────────── */
.bb-empty { text-align: center; padding: 3.5rem 1.5rem; }
.bb-empty-icon {
  margin: 0 auto 1.25rem;
  width: 56px; height: 56px;
  padding: 14px;
  border-radius: 50%;
  background: var(--bb-accent-subtle);
  color: var(--bb-accent);
}
.bb-empty-title { font-size: 1.125rem; font-weight: 700; letter-spacing: -.02em; color: var(--bb-text); margin-bottom: .375rem; }
.bb-empty-message {
  font-size: .9375rem;
  color: var(--bb-muted);
  margin: 0 auto 1.5rem;
  max-width: 40ch;
}

/* ── 16. Tabs & segmented control ────────────────────────────────────────── */
.bb-tabs {
  display: flex;
  gap: 1.5rem;
  border-bottom: 1px solid var(--bb-border);
  margin-bottom: 1.75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.bb-tabs::-webkit-scrollbar { display: none; }

.bb-tab {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 0 .125rem;
  font-size: .9375rem;
  font-weight: 550;
  color: var(--bb-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  min-height: 46px;
  transition: color var(--bb-dur-fast) var(--bb-ease), border-color var(--bb-dur-fast) var(--bb-ease);
  touch-action: manipulation;
}
.bb-tab:hover { color: var(--bb-text); text-decoration: none; }
.bb-tab[aria-current],.bb-tab[aria-selected="true"],.bb-tab.bb-tab-active {
  color: var(--bb-text);
  font-weight: 650;
  border-bottom-color: var(--bb-accent);
}

.bb-segmented {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: var(--bb-radius-pill);
  background: var(--bb-surface-sunken);
  box-shadow: inset 0 0 0 1px var(--bb-border);
}
.bb-segmented > a,
.bb-segmented > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  min-height: 36px;
  padding: 0 .9375rem;
  border-radius: var(--bb-radius-pill);
  font-size: .8125rem;
  font-weight: 600;
  color: var(--bb-muted);
  text-decoration: none;
  transition: background var(--bb-dur-fast) var(--bb-ease), color var(--bb-dur-fast) var(--bb-ease), box-shadow var(--bb-dur-fast) var(--bb-ease);
}
.bb-segmented > a:hover,
.bb-segmented > button:hover { color: var(--bb-text); text-decoration: none; }
.bb-segmented > [aria-current],
.bb-segmented > [aria-pressed="true"],
.bb-segmented > [aria-selected="true"],
.bb-segmented > .bb-segmented-active {
  background: var(--bb-surface);
  color: var(--bb-text);
  box-shadow: var(--bb-shadow), 0 0 0 1px var(--bb-border);
}

/* ── 17. Modal / dialog ──────────────────────────────────────────────────── */
.bb-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,10,10,.42);
  z-index: var(--bb-z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: opacity var(--bb-dur-base) var(--bb-ease);
}
@starting-style { .bb-modal-overlay { opacity: 0; } }

.bb-modal {
  background: var(--bb-surface);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius-xl);
  box-shadow: var(--bb-shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90dvh;
  overflow-y: auto;
  transition: transform var(--bb-dur-slow) var(--bb-ease-out), opacity var(--bb-dur-base) var(--bb-ease);
}
@starting-style { .bb-modal { opacity: 0; transform: translateY(10px) scale(.98); } }

.bb-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.375rem 1.5rem 1rem;
}
.bb-modal-title { font-size: 1.125rem; font-weight: 750; letter-spacing: -.025em; }
.bb-modal-body  { padding: .5rem 1.5rem 1.5rem; }
.bb-modal-foot  {
  padding: 1rem 1.5rem 1.375rem;
  border-top: 1px solid var(--bb-border);
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: .625rem;
}

/* ── 18. Theme toggle icons ──────────────────────────────────────────────── */
.bb-theme-icon-sun,
.bb-theme-icon-moon {
  display: none;
  align-items: center;
  justify-content: center;
}
/* Sun (→ light) in dark mode; moon (→ dark) in light mode. */
[data-theme="dark"] .bb-theme-icon-sun { display: flex; }
[data-theme="light"] .bb-theme-icon-moon { display: flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .bb-theme-icon-sun  { display: flex; }
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .bb-theme-icon-moon { display: flex; }
}

/* ── 19. Public header (floating glass pill) ─────────────────────────────── */
.bb-pub-header {
  position: sticky;
  top: 0;
  z-index: var(--bb-z-sticky);
  padding: .875rem 1rem 0;
  pointer-events: none;
}

.bb-pub-header-inner {
  pointer-events: auto;
  max-width: 1180px;
  margin: 0 auto;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .5rem .5rem .5rem 1.125rem;
  background: var(--bb-glass);
  -webkit-backdrop-filter: var(--bb-glass-blur);
  backdrop-filter: var(--bb-glass-blur);
  border: 1px solid var(--bb-glass-border);
  border-radius: var(--bb-radius-pill);
  box-shadow: var(--bb-shadow-md), inset 0 1px 0 light-dark(rgba(255,255,255,.9), rgba(255,255,255,.04));
}

.bb-pub-header-nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .25rem;
}

.bb-pub-nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1rem;
  border-radius: var(--bb-radius-pill);
  font-size: .9375rem;
  font-weight: 550;
  color: var(--bb-text);
  text-decoration: none;
  transition: background var(--bb-dur-fast) var(--bb-ease);
  touch-action: manipulation;
}
.bb-pub-nav-link:hover { background: var(--bb-hover); color: var(--bb-text); text-decoration: none; }

/* ── 20. Auth pages ──────────────────────────────────────────────────────── */
.bb-auth-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.25rem 4rem;
  min-height: calc(100dvh - 5rem);
}
.bb-auth-shell { width: 100%; max-width: 440px; }

.bb-auth-card {
  background: var(--bb-surface);
  border: 1px solid var(--bb-border);
  border-radius: var(--bb-radius-xl);
  box-shadow: var(--bb-shadow-lg);
  padding: 2.5rem 2.25rem 2.25rem;
  width: 100%;
}
.bb-auth-card-center { text-align: center; }
.bb-auth-card-center .bb-notice { text-align: left; }

.bb-auth-header { text-align: center; margin-bottom: 2rem; }
.bb-auth-mark { width: 48px; height: 48px; margin: 0 auto 1.25rem; }
.bb-auth-icon {
  width: 56px; height: 56px;
  margin: 0 auto 1.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bb-accent-subtle);
  color: var(--bb-accent);
}
.bb-auth-icon-danger { background: var(--bb-danger-subtle); color: var(--bb-danger); }

.bb-auth-title {
  font-size: clamp(1.625rem, 2vw + 1rem, 2rem);
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1.1;
  color: var(--bb-text);
}
.bb-auth-subtitle { font-size: .9375rem; color: var(--bb-muted); margin-top: .5rem; }
.bb-auth-subtitle strong { color: var(--bb-text); }
.bb-auth-lead { font-size: .9375rem; color: var(--bb-muted); margin-bottom: 1.5rem; }
.bb-auth-lead strong { color: var(--bb-text); }

.bb-auth-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: .875rem;
  color: var(--bb-muted);
}
.bb-auth-footer a {
  color: var(--bb-text);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--bb-accent) 55%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
}
.bb-auth-footer a:hover { text-decoration-color: var(--bb-accent); }

/* ── 21. Notice / error pages ────────────────────────────────────────────── */
.bb-notice-page {
  min-height: calc(100dvh - 6rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem 4rem;
  text-align: center;
}
.bb-main .bb-notice-page { min-height: 70vh; }
.bb-notice-page-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--bb-accent-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  color: var(--bb-accent);
}
.bb-notice-page-title {
  font-size: clamp(1.75rem, 2.5vw + 1rem, 2.5rem);
  font-weight: 800;
  letter-spacing: -.045em;
  line-height: 1.08;
  margin-bottom: .875rem;
}
.bb-notice-page-message {
  font-size: 1rem;
  color: var(--bb-muted);
  max-width: 46ch;
  margin: 0 auto 2rem;
  line-height: 1.6;
}
.bb-notice-page-actions { display: flex; gap: .625rem; justify-content: center; flex-wrap: wrap; }

/* ── 22. Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .bb-page { padding: 1.5rem 1rem calc(var(--bb-bottom-h) + 2.5rem); }
  .bb-grid-2,.bb-grid-3 { grid-template-columns: 1fr; }
  .bb-page-header { flex-direction: column; align-items: stretch; margin-bottom: 1.5rem; }
  .bb-card { padding: 1.25rem; }
  .bb-auth-card { padding: 2rem 1.25rem 1.5rem; border-radius: var(--bb-radius-lg); }
  .bb-modal-overlay { align-items: flex-end; padding: .5rem; }
  .bb-modal { border-radius: var(--bb-radius-lg); }
}

@media (max-width: 559px) {
  .bb-pub-header { padding: .625rem .625rem 0; }
  .bb-pub-header-inner { padding-left: .875rem; gap: .5rem; }
  .bb-pub-header-cta { display: none; }
  .bb-pub-nav-link { padding: 0 .75rem; }
}
