/* ── 00-base.css — design tokens + reset + sidebar + header + app-layout ── */

/* ══ DESIGN TOKENS ═══════════════════════════════════════════════════════
   Every colour in the app resolves through one of these. A raw hex or rgba()
   anywhere else is a bug: it cannot follow the theme, and the theme is now a
   user setting (Edit profile → Theme, stored in `tigertag.theme` +
   users/{uid}/prefs/app.theme). `npm run theme:check` enforces it.

   The theme is carried by `data-theme` on <html>. It is written STATICALLY in
   inventory.html as the shipped default (dark), so the correct palette applies
   at first paint — before any JS runs — and the renderer only rewrites it when
   the user has picked the other one.

   ── The four groups, and which way each moves ──
     1. SURFACES / TEXT / BORDERS — invert between themes. The bulk of the work.
     2. BRAND + SEMANTIC accents  — the HUE is constant (orange stays orange,
        danger stays red) but the `-soft` tints must be recomputed: a pale peach
        that reads as "subtle" on white becomes a glaring block on near-black.
        They are derived with color-mix() against --surface so a tint always
        sits correctly on whatever it is painted over, in both themes.
     3. FIXED-POLARITY  — colours that must NOT invert. `--on-accent` is the
        text/icon sitting ON a filled orange/red button: white in both themes,
        because the fill underneath never changes. Getting this wrong is the
        single most common dark-mode bug, and this codebase writes `#fff` for
        BOTH "card background" and "label on an orange button" — only the token
        tells them apart.
     4. ALWAYS-DARK — tooltips, and anything sitting on video. A camera feed
        letterboxed in white would be absurd, so media surfaces keep a fixed
        dark scale in both themes. The sidebar and the TD1S panel deliberately
        do NOT belong here: they are panels inside the app, so they follow the
        theme like everything else rather than staying black in a light UI.

   ── Game UI tokens (--game-*) ──
   The Tiger Quests and TigerSquad views, their windows (invite, notices, chest,
   envelopes, send-coins) and the Trophies all paint with ONE shared set:
   --game-bg / -bg-2 / -card / -card-2 / -line / -line-2 / -text / -text-2 /
   -muted for the grounds and ink, --game-win-* for the floating windows, and the
   accents gold, orange, ok, ice, danger (a fill/icon hue plus a `-text` twin that
   deepens on a light ground so small text keeps 4.5:1). New Quest/Squad views
   MUST use them (a local palette such as --tsq-* / --qw-* only ever aliases
   them): no local hex, no "always dark" world. */

  :root {
    /* Space between the filter rows and whatever view is showing. Each view
       container used to declare its own, with a comment pointing at another one
       to justify the number — six copies chasing each other, and two of them
       (Storage and Printers) had already drifted to 4 px, so the same screen
       breathed differently depending on the view you were in. */
    --view-gap: 8px;

    /* ── 1. Surfaces — an elevation ladder, lowest first ── */
    --bg: #f6f7fb;              /* the page itself */
    --surface: #ffffff;         /* cards, panels, rows */
    --surface-2: #f1f3f9;       /* recessed: table heads, chips, inset wells */
    --surface-3: #e7eaf3;       /* deeper inset / pressed state */
    --surface-hover: #eef1f8;   /* hover on an interactive surface */
    --surface-raised: #ffffff;  /* floats ABOVE surface: dropdowns, popovers */

    /* ── Text ── */
    --text: #1c2030;            /* primary */
    --muted: #4f566b;           /* secondary — ≥ 6.5:1 on every light surface (was too pale, founder 2026-11-02) */
    --faint: #697087;           /* tertiary, disabled, timestamps — ≥ 4.5:1 on white */

    /* ── Borders ── */
    --border: #e3e6ef;          /* default hairline */
    --border-soft: #eef0f6;     /* barely-there separator */
    --border-strong: #d0d4dc;   /* emphasised / focus base */

    /* ── 2. Brand + semantic — hue constant across themes ── */
    /* A phone drawn as a phone (AI assistant demo): the same in both themes. */
    --device-frame: #3a3a3f;    /* the metal band */
    --device-frame-hi: #6b6b72; /* its lit edge */
    --device-glass: #050507;    /* the black border around the screen, the island */
    --primary: #ff7a18;
    --primary-hover: #e96900;
    --primary-soft: #ffe9d6;
    --primary-20: rgba(255,120,0,.25);
    --success: #1aaf6c;
    --success-soft: #e1f6ec;
    --danger: #d83b3b;
    --danger-soft: #fbe3e3;
    --warning: #b97a00;
    --warning-soft: #fff5dc;
    --info: #386ecf;
    --info-soft: rgba(56,110,207,.10);
    --neutral: #737a8f;
    --violet: #7c4dff;          /* cloud / premium accent, distinct from brand */
    --violet-hover: #6a3de0;
    --primary-hi: #ffb056;      /* light stop of the brand gradient */
    --success-hover: #16a34a;
    --success-hi: #4fc98d;      /* light stop of the success gradient */
    --danger-hover: #b91c1c;
    --warning-hover: #b45309;
    /* Commerce green — the "buy / add to cart / shop" action throughout, and
       the Shopify brand colour it came from. Semantic, not decorative: it must
       stay recognisably the buy colour, so it only lifts for dark contrast. */
    --buy: #5e8e3e;
    --buy-hover: #4d7532;
    /* Text twins: the accent DEEPENED so small text / icons in that hue keep
       4.5:1 on white and on the -soft tints. Fills keep the plain accent; every
       `color: var(--accent)` uses the twin. Dark: the twin IS the accent. */
    --primary-text: #a84300;
    --success-text: #14783c;
    --warning-text: #8a5a00;
    --danger-text: #b52626;
    --info-text: #2f62bd;
    --neutral-text: #5a6176;
    --buy-text: #4d7532;
    --favorite-text: #8a5a00;
    --success-hover-text: #0f6b34;   /* hover/active twin of --success-text */
    /* The starred/favourite gold. A state, not decoration — the same colour has
       to mean "favourite" on the card badge, the filter chip and the bulk bar. */
    --favorite: #f5a623;
    --favorite-deep: #c98a1e;
    /* Rarity tiers of the Trophies (quests/trophies.css), the hues of the
       TigerCoins draws: one colour per tier, the same in both themes. */
    --tier-common: #a8afc2;
    --tier-uncommon: #3ddc84;
    --tier-rare: #3d8bff;
    --tier-epic: #a855f7;
    --tier-legendary: #ffb21a;
    --tier-event: #ff5fa2;

    /* ── Game UI tokens — Tiger Quests, TigerSquad, Trophies, their windows ──
       One palette for every game view (see the header note). The `-text` twins
       are the same hue deepened for small text on a light ground; fills and
       icons use the plain accent. Dark values reproduce the former
       always-dark world exactly. */
    --game-bg: var(--bg);           /* the view's ground */
    --game-bg-2: #eceff7;           /* inset well, tab rail, bar track */
    --game-card: #ffffff;           /* a card / row */
    --game-card-2: #f6f7fb;         /* raised card, top stop of a panel gradient */
    --game-line: #d3d8e6;
    --game-line-2: #bcc3d6;         /* stronger line, hover edge */
    --game-text: #1c2030;
    --game-text-2: #3d4459;         /* secondary body copy */
    --game-muted: #4f566b;
    /* Floating windows (invite, notices): their own, slightly lighter ground in dark. */
    --game-win-bg: #ffffff;
    --game-win-bg-2: #f3f5fa;
    --game-win-card: #f7f8fc;
    --game-win-line: #d3d8e6;
    --game-gold: #ffcf3d;           --game-gold-text: #8a5a00;
    --game-gold-hi: #fff3c4;        /* pale highlight stop on a gold fill */
    --game-gold-deep: #ffb21a;      /* deep stop of a gold gradient */
    --game-gold-deep-text: #8a5a00;
    --game-orange: #ff8a2e;         --game-orange-text: #b84a00;
    --game-orange-hi: #ffb347;
    --game-ok: #3ddc84;             --game-ok-text: #12803f;
    --game-ice: #2f93e0;            --game-ice-text: #1b69a8;
    --game-ice-deep: #1f7fcf;       /* the saturated cyan of the leagues / TigerSquad stats */
    --game-danger: #ff6b6b;         --game-danger-text: #c42b2b;
    --game-on-gold: #1a1205;        /* ink ON a gold / orange fill — fixed polarity */
    --game-gold-soft:   color-mix(in srgb, var(--game-gold)   16%, var(--game-card));
    --game-orange-soft: color-mix(in srgb, var(--game-orange) 14%, var(--game-card));
    --game-ok-soft:     color-mix(in srgb, var(--game-ok)     14%, var(--game-card));
    --game-ice-soft:    color-mix(in srgb, var(--game-ice)    14%, var(--game-card));
    --game-danger-soft: color-mix(in srgb, var(--game-danger) 12%, var(--game-card));

    /* ── 3. Fixed polarity — these do NOT invert ── */
    --on-accent: #ffffff;       /* label/icon ON a filled accent button */
    --on-dark: #ffffff;         /* label/icon on an always-dark surface */
    --sticker-edge: #ffffff;    /* the die-cut outline of a sticker (Trophies) */
    --qr-frame: #111318;        /* the black rounded frame around a QR code */

    /* ── Effects ── */
    --scrim: rgba(20,24,40,.42);            /* modal backdrop */
    --shadow: 0 1px 2px rgba(20,24,40,.04), 0 8px 24px rgba(20,24,40,.06);
    --shadow-lg: 0 4px 12px rgba(20,24,40,.08), 0 24px 60px rgba(20,24,40,.12);
    --glass-hi: rgba(255,255,255,.75);      /* light sheen on glassy fills */
    --glass-lo: rgba(0,0,0,.06);            /* depth notch */

    /* ── The ink ladder ──────────────────────────────────────────────────
       "Ink" is whatever contrasts with the CURRENT ground: near-black in
       light, white in dark. Reach for it wherever a translucent overlay has
       to read as a border, a fill or a label at a given strength, rather than
       as a specific colour — which is most of what the hand-written
       `rgba(255,255,255,.08)` and `rgba(0,0,0,.12)` were doing all over this
       codebase.

       One ladder replaces ~450 hand-written alphas, and it flips on its own.
       Light steps are slightly lower than their dark twins because black on
       white reads heavier than white on black at the same alpha.

       NOT for shadows or media scrims — those stay dark in both themes and
       belong to --shadow / --scrim / --media-scrim below. */
    --ink-04: rgba(20,24,40,.03);
    --ink-06: rgba(20,24,40,.05);
    --ink-08: rgba(20,24,40,.06);
    --ink-10: rgba(20,24,40,.08);
    --ink-12: rgba(20,24,40,.10);
    --ink-15: rgba(20,24,40,.12);
    --ink-20: rgba(20,24,40,.16);
    --ink-25: rgba(20,24,40,.20);
    --ink-30: rgba(20,24,40,.26);
    /* The upper steps carry TEXT and icons: dark enough to read on white (≥ 4.5:1 from ink-50 up). */
    --ink-40: rgba(20,24,40,.50);
    --ink-50: rgba(20,24,40,.64);
    --ink-60: rgba(20,24,40,.72);
    --ink-70: rgba(20,24,40,.80);
    --ink-85: rgba(20,24,40,.90);

    /* Scrim laid over photo/video so overlaid controls stay readable. Dark in
       BOTH themes — letterboxing a camera feed in white would be absurd. */
    --media-bg: #000000;
    --media-scrim: rgba(0,0,0,.45);

    /* ── 4. Always-dark instrument surfaces (identical in both themes) ── */
    /* The sidebar has its own ground because it is a distinct plane, not a
       card: a faint violet-warm gradient rather than a flat surface. It MUST
       follow the theme — its labels use the ink ladder, so a dark sidebar left
       standing in a light UI would print dark ink on a dark ground. */
    --sidebar-bg: linear-gradient(175deg, #eef0f7 0%, #edeaf4 100%);

    --dark-bg: #0f1117;
    --dark-surface: #1c2030;
    --dark-surface-2: #262b3a;
    /* Literal white on purpose: this group must NOT follow the theme, so it
       cannot borrow the ink ladder — in light mode ink turns dark, and a dark
       tooltip would end up with a dark border on a dark ground. */
    --dark-border: rgba(255,255,255,.10);
    --dark-text: #ffffff;
    --dark-muted: rgba(255,255,255,.62);
    --code-bg: #15151b;

    /* ── Geometry + type (theme-independent) ── */
    --radius: 14px;
    --radius-sm: 10px;
    /* Layout grid — only ever drawn while arranging the storage plan. Minor
       lines mark the snap step, major ones every fifth so distances stay
       readable instead of turning into graph paper. */
    --grid-line:  rgba(58,78,140,.14);
    --grid-major: rgba(58,78,140,.30);

    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  }

  /* ══ DARK ═══════════════════════════════════════════════════════════════
     The scale is anchored on #0f1117 — the exact top stop of the sidebar
     gradient, which has always been dark. So in this theme the content area
     and the sidebar finally belong to the same surface, instead of a light
     document sitting inside a dark frame. */
  :root[data-theme="dark"],
  /* Always dark in BOTH themes, so they take this whole token set: the
     full-screen game stages (.tc-reveal, on a dark scrim), the hero banners
     (navy wall art) and the header banner when it sits on the account's
     colour glow (always mixed into a dark navy — _applyThemeColor). */
  .tc-reveal,
  .qd-hero, .qm-hero, .sqr-hero, .sqr-hero-host,
  :root.has-theme-tint #friendViewBanner {
    --sidebar-bg: linear-gradient(180deg, #101018 0%, #15111D 55%, #1A1020 100%);   /* subtle depth, founder's palette */

    /* On a dark ground the grid has to be lighter than the surface, not darker. */
    --grid-line:  rgba(255,255,255,.075);
    --grid-major: rgba(255,255,255,.16);

    --bg: #0f1117;
    --surface: #171a22;
    --surface-2: #1e222c;
    --surface-3: #262b37;
    --surface-hover: #232734;
    --surface-raised: #232838;

    --text: #e7e9f0;
    --muted: #9aa2b6;
    --faint: #6f778c;

    /* Borders are translucent white rather than a fixed grey: they then read
       correctly over ANY of the surfaces above without a per-elevation value. */
    --border: var(--ink-08);
    --border-soft: var(--ink-04);
    --border-strong: var(--ink-20);

    /* Same hues, lifted for contrast against a dark ground. --warning at
       #b97a00 is a brown on black — it has to brighten to stay legible. */
    --primary: #ff8a33;
    --primary-hover: #ffa057;
    --success: #35c98a;
    --danger: #f2585a;
    --warning: #e9a020;
    --info: #5b8ee0;
    --neutral: #7d8496;
    --violet: #9d7bff;
    --violet-hover: #b294ff;
    --primary-hi: #ffc07a;
    --success-hover: #4ad89b;
    --success-hi: #6fe0b0;
    --danger-hover: #ff7376;
    --warning-hover: #f5b544;
    --buy: #7cae57;
    --buy-hover: #92c06d;
    --favorite: #f7b444;
    --favorite-deep: #e0a33a;
    --primary-text: var(--primary);
    --success-text: var(--success);
    --warning-text: var(--warning);
    --danger-text: var(--danger);
    --info-text: var(--info);
    --neutral-text: var(--neutral);
    --buy-text: var(--buy);
    --favorite-text: var(--favorite);
    --success-hover-text: var(--success-hover);

    /* Tints recomputed against the dark surface instead of pale washes. */
    --primary-soft: color-mix(in srgb, var(--primary) 16%, var(--surface));
    --success-soft: color-mix(in srgb, var(--success) 15%, var(--surface));
    --danger-soft:  color-mix(in srgb, var(--danger)  15%, var(--surface));
    --warning-soft: color-mix(in srgb, var(--warning) 15%, var(--surface));
    --info-soft:    color-mix(in srgb, var(--info)    16%, var(--surface));
    --primary-20: rgba(255,138,51,.30);

    /* Shadows stop being soft grey haze — on a dark ground only near-black
       reads as depth, and the sheen flips from white to a faint lift. */
    --scrim: rgba(0,0,0,.62);
    --shadow: 0 1px 2px rgba(0,0,0,.30), 0 8px 24px rgba(0,0,0,.36);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.40), 0 24px 60px rgba(0,0,0,.50);
    --glass-hi: rgba(255,255,255,.08);
    --glass-lo: rgba(0,0,0,.28);

    /* Ink flips to white — same ladder, opposite polarity. */
    --ink-04: rgba(255,255,255,.04);
    --ink-06: rgba(255,255,255,.06);
    --ink-08: rgba(255,255,255,.08);
    --ink-10: rgba(255,255,255,.10);
    --ink-12: rgba(255,255,255,.12);
    --ink-15: rgba(255,255,255,.15);
    --ink-20: rgba(255,255,255,.20);
    --ink-25: rgba(255,255,255,.25);
    --ink-30: rgba(255,255,255,.30);
    --ink-40: rgba(255,255,255,.40);
    --ink-50: rgba(255,255,255,.50);
    --ink-60: rgba(255,255,255,.60);
    --ink-70: rgba(255,255,255,.70);
    --ink-85: rgba(255,255,255,.85);

    /* Game UI tokens — the former always-dark world, unchanged. */
    --game-bg: #0b0d14;
    --game-bg-2: #121624;
    --game-card: #161b2c;
    --game-card-2: #1c2238;
    --game-line: #2a3150;
    --game-line-2: #3a4260;
    --game-text: #eef1fb;
    --game-text-2: #c9d0e6;
    --game-muted: #8f97b3;
    --game-win-bg: #151922;
    --game-win-bg-2: #1c212d;
    --game-win-card: #1b202b;
    --game-win-line: #303543;
    --game-gold-text: var(--game-gold);
    --game-gold-deep-text: var(--game-gold-deep);
    --game-orange-text: var(--game-orange);
    --game-ok-text: var(--game-ok);
    --game-ice: #8fd3ff;            --game-ice-text: #8fd3ff;
    --game-ice-deep: #3da4f0;
    --game-danger-text: #ff8a8a;
    /* Re-declared so the tints recompute against the dark card (also inside .tc-reveal). */
    --game-gold-soft:   color-mix(in srgb, var(--game-gold)   16%, var(--game-card));
    --game-orange-soft: color-mix(in srgb, var(--game-orange) 14%, var(--game-card));
    --game-ok-soft:     color-mix(in srgb, var(--game-ok)     14%, var(--game-card));
    --game-ice-soft:    color-mix(in srgb, var(--game-ice)    14%, var(--game-card));
    --game-danger-soft: color-mix(in srgb, var(--game-danger) 12%, var(--game-card));
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    line-height: 1.45;
    /* Native-app feel: the UI is clickable but not text/element-selectable, so
       clicking or dragging never leaves a blue selection highlight. Content the
       user genuinely reads/copies stays selectable via the exceptions below
       (form fields, code/JSON blocks, and anything opted in with `.selectable`). */
    -webkit-user-select: none; user-select: none;
  }
  input, textarea, select, [contenteditable], [contenteditable] *,
  pre, code, .selectable, .selectable * {
    -webkit-user-select: text; user-select: text;
  }
  /* Images are never a native drag source. Otherwise a spool/product thumbnail
     in the inventory grid/list or Favorites can be "picked up" and dragged as a
     ghost image — there's no drop, so it just looks broken. Every INTENDED drag
     (rack slots, list/cart reorder, friends) uses a draggable <div>/<span>
     handle, never an <img>, so disabling image-drag here breaks nothing. */
  img { -webkit-user-drag: none; user-drag: none; }
  /* A button held to confirm (setupHoldToConfirm, holdToFire): on a phone a long
     press is also the browser's gesture (link / image menu, scroll), which took
     the press and cancelled the hold. The button keeps it. */
  .hold-press { -webkit-touch-callout: none; touch-action: none; }

  /* ── .circle-center — content optically centred inside a round badge ──────
     Reach for this on ANY circle holding a character, a number or a glyph
     (step badges, counters, avatar initials, icon discs).

     Why the usual `flex + align-items:center` drifts:
       • it centres the LINE BOX, whose height includes the font's ascender and
         descender — a digit has no descender, so the glyph lands slightly high;
       • an inherited line-height (1.4, 1.5…) makes that box taller still;
       • monospace faces are the worst offenders, their vertical metrics are
         built for column alignment, not for optical centring.

     So: `place-items:center` centres the item box itself, `line-height:1` strips
     the leading so the box hugs the glyph, and `tabular-nums` keeps 1 and 11 the
     same width — a counter never has to grow. Set width (or font-size) and a
     background where you use it; `aspect-ratio` keeps it perfectly round. */
  .circle-center {
    display: inline-grid;
    place-items: center;
    aspect-ratio: 1;
    border-radius: 50%;
    line-height: 1;
    text-align: center;
    font-variant-numeric: tabular-nums;
    box-sizing: border-box;
    /* Nudges the glyph down by the half-descender the box reserves but digits
       never use. Sub-pixel, invisible on letters, decisive on numerals. */
    padding-top: .06em;
  }

  /* ── layout ── */
  .app-layout {
    height: 100%; display: flex; flex-direction: row; overflow: hidden;
  }
  /* sidebar */
  .sidebar {
    width: 240px; flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: none;
    display: flex; flex-direction: column; overflow: hidden;
    transition: width .25s cubic-bezier(.4,0,.2,1);
    box-shadow: 2px 0 24px rgba(0,0,0,.25);
    position: relative;
  }
  .sidebar::after {
    content: ""; position: absolute; top: 0; right: 0; bottom: 0; width: 1px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--primary) 30%, transparent) 0%, color-mix(in srgb, var(--primary) 0%, transparent) 60%);
    pointer-events: none;
  }
  .sidebar.collapsed { width: 65px; }

  /* header / brand */
  .sb-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 12px 12px; flex-shrink: 0;
  }
  .sidebar.collapsed .sb-header { justify-content: center; }
  .sb-brand { display: flex; align-items: center; gap: 9px; overflow: hidden; min-width: 0; }
  .sb-brand-dot {
    width: 28px; height: 28px; flex-shrink: 0; border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hi));
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 800; color: var(--on-accent);
    box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 40%, transparent);
  }
  .sb-brand-name { font-size: 13px; font-weight: 700; color: var(--ink-85); white-space: nowrap; letter-spacing: -.01em; }
  .sidebar.collapsed .sb-brand { display: none; }
  .sb-toggle {
    width: 28px; height: 28px; padding: 0; border-radius: 50%; flex-shrink: 0;
    background: var(--ink-08); border: 1px solid var(--ink-12);
    color: var(--ink-40);
    display: flex; align-items: center; justify-content: center;
    transition: background .2s, border-color .2s, box-shadow .2s, color .2s;
  }
  .sb-toggle:hover {
    background: color-mix(in srgb, var(--primary) 18%, transparent) !important; border-color: color-mix(in srgb, var(--primary) 55%, transparent) !important;
    box-shadow: 0 0 12px color-mix(in srgb, var(--primary) 25%, transparent); color: var(--primary-text) !important;
  }
  .sb-chevron {
    display: block; flex-shrink: 0; pointer-events: none;
    transition: transform .25s cubic-bezier(.4,0,.2,1);
  }
  .sidebar.collapsed .sb-chevron { transform: rotate(180deg); }

  /* user section */
  .sb-user {
    padding: 4px 14px 6px;   /* tight under the header */
    /* Was flex-shrink:0. Now allowed to shrink (grow 0 → no empty stretch
       when few friends) so the friend list inside can scroll when the
       sidebar runs out of vertical room — see .sb-friends-list. */
    flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: stretch;
  }
  /* Avatar + (welcome + name) laid out horizontally when expanded. */
  .sb-user-row {
    display: flex; align-items: center; gap: 12px;
    width: 100%;
    flex-shrink: 0;   /* avatar row never shrinks — only the friend list scrolls */
  }
  .sb-user-info {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; align-items: flex-start;
    gap: 2px;
  }
  .sb-avatar {
    /* 40px in BOTH expanded and collapsed sidebar (collapsed is the reference,
       and it matches the friend chips) so the avatar never changes size when the
       sidebar is minimised/expanded. */
    width: 40px; height: 40px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-hi));
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; color: var(--on-accent); letter-spacing: -1px;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent), 0 4px 20px color-mix(in srgb, var(--primary) 20%, transparent);
    transition: box-shadow .3s; flex-shrink: 0; cursor: pointer;
    position: relative;          /* anchor for the swap-back badge overlay */
  }
  .sb-avatar:hover { box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 45%, transparent), 0 4px 28px color-mix(in srgb, var(--primary) 30%, transparent); }
  /* Custom-avatar photo overlay — sits on top of the colour-circle
     gradient + initials. When `state.photoURL` is set, JS injects this
     <img> via `_renderAvatarPhotoOverlay`. When the photo errors out or
     gets removed, the <img> is detached and the circle + initials show
     through again — natural fallback, no extra render path needed. */
  .sb-avatar-photo {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    pointer-events: none;  /* clicks pass through to the avatar button */
  }

  /* ── Avatar tri-state invariant ─────────────────────────────────────
     Every coloured-circle avatar in Studio (sidebar, header chip,
     dropdown, profiles modal, edit-account modal, friend chips/panel,
     friend banner, add-friend preview) is painted by the ONE pipeline in
     inventory.js (`paintAvatar` / `avatarMarkup`). That pipeline stamps
     `data-av-mode="empty|initials|photo"` on the host and guarantees the
     three child nodes exist. These rules — keyed off the attribute, so
     they apply regardless of the container's size class — make EXACTLY
     ONE child visible per mode. The invariant no longer depends on the
     photo merely *covering* the initials, so sub-pixel rounding, z-index
     ambiguity or transparent-PNG edges can never leak the text again. */
  [data-av-mode] > .av-initials { position: relative; z-index: 0; line-height: 1; }
  [data-av-mode] > .av-plus {
    width: 42%; height: 42%; display: block; pointer-events: none;
    color: inherit;
  }
  [data-av-mode="initials"] > .av-plus,
  [data-av-mode="initials"] > .sb-avatar-photo,
  [data-av-mode="empty"]    > .av-initials,
  [data-av-mode="empty"]    > .sb-avatar-photo,
  [data-av-mode="photo"]    > .av-initials,
  [data-av-mode="photo"]    > .av-plus { display: none !important; }
  /* Empty (no-account) styling — neutral gradient + no shadow. Driven by
     CSS (not an inline style) so :hover still works on the sidebar host. */
  .sb-avatar[data-av-mode="empty"] {
    background: rgba(255,255,255,.08); box-shadow: none;
    color: var(--ink-60); cursor: pointer;
  }
  .sb-avatar[data-av-mode="empty"]:hover { background: var(--ink-15); }

  /* Swap-back badge — a small ⇄ chip pinned to the bottom-right of the
     avatar. Hidden by default, revealed only while we're previewing a
     friend's inventory (.sb-user--viewing-friend on the parent). The
     avatar itself remains the click target; this badge is purely a
     visual hint to the user that clicking will swap the view back. */
  .sb-avatar-swap {
    position: absolute;
    right: -3px; bottom: -3px;
    width: 22px; height: 22px;
    border-radius: 50%;
    display: none;               /* shown only in friend-view mode */
    align-items: center; justify-content: center;
    background: var(--dark-surface);
    color: var(--on-accent);
    box-shadow: 0 0 0 2px var(--dark-bg), 0 2px 8px rgba(0,0,0,.4);
    pointer-events: none;        /* clicks fall through to the avatar */
    transform: scale(.6); opacity: 0;
    transition: transform .25s cubic-bezier(.34,1.56,.64,1), opacity .2s;
  }
  .sb-user--viewing-friend .sb-avatar-swap {
    display: flex;
    transform: scale(1); opacity: 1;
  }
  .sb-avatar-swap .icon {
    width: 13px; height: 13px;
    background: var(--surface);            /* mask-image colour */
  }
  /* Collapsed sidebar (avatar shrinks to 40px) → shrink the badge too. */
  .sidebar.collapsed .sb-avatar-swap {
    width: 18px; height: 18px;
    right: -2px; bottom: -2px;
  }
  .sidebar.collapsed .sb-avatar-swap .icon {
    width: 11px; height: 11px;
  }
  .sb-name {
    font-size: 14px; font-weight: 600; color: var(--text); text-align: left;
    margin-top: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    max-width: 100%;
    cursor: pointer; transition: opacity .15s;   /* click → open my user (profile) view */
  }
  .sb-name:hover { opacity: .75; }
  .sb-sub {
    font-size: 10px; color: var(--ink-30); text-align: left;
    font-family: var(--mono); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  }
  .sb-actions { display: flex; flex-direction: column; gap: 7px; margin-top: 14px; width: 100%; flex: 0 1 auto; min-height: 0; }
  /* Refresh / Friends buttons keep their height; only the friend list scrolls. */
  .sb-actions > button { flex-shrink: 0; }
  .sb-actions button {
    display: flex; align-items: center;   /* center the icon on BOTH axes (esp. the collapsed bell) */
    height: 40px; font-size: 12px; width: 100%; justify-content: center; border-radius: 8px;   /* 40px = same height expanded & collapsed (matches the friend avatars) */
  }
  .sb-actions .primary { background: var(--primary); border-color: var(--primary); box-shadow: 0 2px 10px color-mix(in srgb, var(--primary) 35%, transparent); }
  .sb-actions .primary:hover { background: var(--primary-hover) !important; box-shadow: 0 3px 14px color-mix(in srgb, var(--primary) 45%, transparent); }
  .sb-actions button:not(.primary) {
    background: var(--ink-08); border-color: var(--ink-10);
    color: var(--ink-60);
  }
  .sb-actions button:not(.primary):hover { background: var(--ink-12) !important; color: var(--text) !important; }
  /* Action/community button labels (Notifications, GitHub, 3D Files, Discord):
     animatable open/close so the sidebar collapse/expand glides instead of
     popping. See the collapsed rules. */
  .sb-actions .label,
  .sb-community .label {
    display: inline-block; white-space: nowrap; overflow: hidden;
    max-width: 140px; min-width: 0; opacity: 1;   /* min-width:0 so max-width:0 actually collapses it as a flex item */
    transition: max-width .25s cubic-bezier(.4,0,.2,1), opacity .18s ease;
  }
  /* Animate the button width too, so it shrinks in step with its label (the
     label never spills past the narrowing button) — smooth collapse/expand. */
  .sb-friends-btn, .sb-notifs-btn { position: relative; transition: width .25s cubic-bezier(.4,0,.2,1); }
  /* Bell is the same 20px whether the sidebar is expanded or collapsed (overrides
     the .icon-13 in the markup). */
  .sb-notifs-btn .icon { width: 20px; height: 20px; }
  .sb-friends-btn .friends-badge,
  .sb-notifs-btn .friends-badge { position: absolute; top: -5px; right: -5px; margin: 0; }
  .sb-sub-welcome { font-size: 11px; color: var(--ink-40); text-align: left; margin-top: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

  /* ── avatar : état vide (aucun compte) ──
     The avatar's own empty styling (gradient, "+" glyph, hover) now lives
     in the tri-state block above, keyed off data-av-mode="empty". Here we
     only keep the surrounding ROW layout that reacts to .sb-user--empty
     (hiding the name / actions column, recentring the avatar). */

  /* connecté → cacher état vide; déconnecté → cacher état connecté */
  .sb-user--empty .sb-sub-welcome,
  .sb-user--empty .sb-name,
  .sb-user--empty .sb-user-info,
  .sb-user--empty .sb-actions { display: none !important; }
  /* When empty, recenter the avatar in its row since the info column
     is gone — otherwise the avatar would sit awkwardly on the left. */
  .sb-user--empty .sb-user-row { justify-content: center; }
  .sb-noacct { display: none; flex-direction: column; align-items: center; gap: 10px; margin-top: 10px; }
  .sb-user--empty .sb-noacct { display: flex; }
  .sb-noacct-label { font-size: 11px; color: var(--ink-30); text-align: center; }
  .sb-noacct-btn {
    display: flex; align-items: center; gap: 7px;
    height: 32px; padding: 0 14px; border-radius: 8px; font-size: 12px; font-weight: 600;
    background: color-mix(in srgb, var(--primary) 18%, transparent); border: 1px solid color-mix(in srgb, var(--primary) 35%, transparent);
    color: var(--primary-text); cursor: pointer; font-family: inherit;
    transition: background .15s, border-color .15s;
  }
  .sb-noacct-btn:hover { background: color-mix(in srgb, var(--primary) 28%, transparent) !important; border-color: color-mix(in srgb, var(--primary) 55%, transparent) !important; }
  /* collapsed : masquer le contenu no-account (juste l'avatar "+" reste visible) */
  .sidebar.collapsed .sb-noacct { display: none !important; }

  .sidebar.collapsed .sb-name,
  .sidebar.collapsed .sb-sub,
  .sidebar.collapsed .sb-user-info,
  .sidebar.collapsed .sb-sub-welcome { display: none; }
  /* Keep the SAME vertical padding as expanded (only the horizontal shrinks) so
     the user block height never changes between states — no vertical jump. */
  /* Horizontal padding = (65px rail − 40px avatar) / 2 = 12.5px, so the avatar
     (and the 40px bell/chips below) sit centred via flex-start WITHOUT a
     justify-content:center that would snap the avatar to the centre of the
     still-wide sidebar at the start of the collapse (the "jump to the right").
     Now the avatar stays put and the sidebar just shrinks around it. */
  .sidebar.collapsed .sb-user { padding: 4px 12.5px 6px; }
  /* .sb-avatar is 40px in both states (set in the base rule) — no collapsed override needed. */
  .sidebar.collapsed .sb-actions {
    align-items: center;   /* keep base margin-top (14px) so the block doesn't shift */
  }
  /* width-only change in collapsed; height stays 36px (set in the base rule) so
     the Notifications row never changes height between states. */
  .sidebar.collapsed .sb-actions button { width: 40px; height: 40px; padding: 0; }   /* match the 40px friend avatars so the column lines up */
  /* Bigger bell when collapsed: a 13px glyph looked lost (and thus "off-centre")
     in the 40px chip; 18px gives it presence and reads as clearly centred. */
  /* Center the collapsed bell ABSOLUTELY so neither the (0-width) label nor the
     absolutely-positioned badge — children the community buttons don't have —
     can ever shove it off-centre. Robust regardless of siblings/whitespace. */
  .sidebar.collapsed .sb-notifs-btn .icon {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: 20px; height: 20px;
  }

  /* config section */
  .sb-field-wrap { display: flex; flex-direction: column; gap: 4px; }
  .sb-field-label { font-size: 10px; color: var(--ink-30); text-transform: uppercase; letter-spacing: .06em; }
  .sb-field-row { display: flex; gap: 4px; }
  .sb-field-input {
    flex: 1; height: 30px; padding: 0 9px; font-size: 11px; font-family: var(--mono);
    background: var(--ink-08); border: 1px solid var(--ink-10);
    border-radius: 7px; color: var(--ink-85); outline: none; min-width: 0;
    transition: border-color .15s, background .15s;
  }
  .sb-field-input:focus { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
  .sb-eye {
    width: 30px; height: 30px; padding: 0; border-radius: 7px; flex-shrink: 0;
    background: var(--ink-08); border-color: var(--ink-10); color: var(--ink-30);
    display: flex; align-items: center; justify-content: center;
    transition: background .15s, color .15s;
  }
  .sb-eye svg { display: block; }
  .sb-eye:hover { background: var(--ink-12) !important; color: var(--ink-85) !important; }
  .sb-config-save {
    height: 30px; font-size: 12px; background: var(--primary); border-color: var(--primary);
    color: var(--on-accent); border-radius: 7px; width: 100%; justify-content: center; margin-top: 2px;
  }
  .sb-config-save:hover { background: var(--primary-hover) !important; }

  /* stats */
  .sb-stats-wrap {
    flex: 1; overflow-y: auto; padding: 14px 12px 12px;
    display: flex; flex-direction: column; gap: 7px;
  }
  .sidebar:not(.collapsed) .sb-stats-wrap {
    display: grid; grid-template-columns: 1fr 1fr; gap: 7px;
    align-items: start; align-content: start;
  }
  .sb-stats-wrap::-webkit-scrollbar { width: 3px; }
  .sb-stats-wrap::-webkit-scrollbar-track { background: transparent; }
  .sb-stats-wrap::-webkit-scrollbar-thumb { background: var(--ink-15); border-radius: 2px; }
  .sb-stats-section-label {
    font-size: 9px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
    color: var(--ink-25); padding: 4px 2px 6px;
  }
  .sb-stat {
    background: var(--ink-04); border: 1px solid var(--ink-08);
    border-radius: 10px; padding: 10px 12px;
    transition: background .15s, border-color .15s; cursor: default;
    text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px;
  }
  /* No :hover feedback — the stat cards are informational, not clickable
     (filtering lives in the controls next to the search field). */
  .sb-stat .label {
    font-size: 10px; color: var(--ink-40); text-transform: uppercase;
    letter-spacing: .06em;
  }
  .sb-stat .label::before { display: none; }
  /* ⓘ info bubble on the "Stock value" stat */
  .sb-stat-info { display: inline-flex; align-items: center; margin-left: 4px; vertical-align: -1px; cursor: help; }
  .sb-stat-info .icon { background-color: var(--ink-40); }
  .sb-stat-info:hover .icon { background-color: var(--ink-85); }
  .sb-stat .value {
    font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
    color: var(--text); margin-top: 4px; letter-spacing: -.02em;
    transition: color .3s ease;   /* tint back to white after the ticker animation */
  }
  /* Ticker count animation — brief green (up) / red (down) tint while rolling. */
  .sb-stat .value.stat-up   { color: #4ade80; }
  .sb-stat .value.stat-down { color: #f87171; }
  :root:not([data-theme="dark"]) .sb-stat .value.stat-up   { color: var(--success-text); }
  :root:not([data-theme="dark"]) .sb-stat .value.stat-down { color: var(--danger-text); }
  .sidebar.collapsed .sb-stats-wrap {
    display: flex; padding: 8px 5px; gap: 4px; overflow-y: auto;
  }
  .sidebar.collapsed .sb-stat { padding: 5px 4px; border-radius: 8px; }
  .sidebar.collapsed .sb-stat .label { display: none; }
  .sidebar.collapsed .sb-stat .value { display: none; }
  .sidebar.collapsed .sb-stat::before {
    content: attr(data-mini-val); display: block; text-align: center;
    font-size: 13px; font-weight: 700; color: var(--text); letter-spacing: -.02em;
  }
  .sidebar.collapsed .sb-stat::after {
    content: attr(data-mini); display: block; text-align: center;
    font-size: 8px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: var(--ink-30); margin-top: 2px;
  }

  /* ── Top header stats (v1.4.4): the same .sb-stat boxes used in the
     sidebar, relocated to the main header in place of the title block.
     Horizontal layout, light theme (header bg is white-ish vs sidebar
     dark). All `.sb-*` rules above target the dark sidebar; we override
     here to fit the header context. */
  .top-stats {
    flex: 1;
    display: flex !important;        /* override grid from .sidebar:not(.collapsed) */
    flex-direction: row !important;
    gap: 10px;
    padding: 0;
    overflow-x: auto;
    overflow-y: visible;
    min-width: 0;
  }
  .top-stats::-webkit-scrollbar { height: 0; }
  /* Every card keeps the SAME two-line shape whatever the bar's width. `flex: 1 1 0`
     alone let a card be squeezed below its own content, so a long label ("Valeur du
     stock ⓘ") wrapped onto a second line and that one card grew taller than its
     neighbours. `min-width: fit-content` is the floor — a card grows to share the
     space but never shrinks under its text — and `nowrap` keeps the figure, its
     HT/TTC suffix and the label each on one line. Past that floor the whole bar
     scrolls horizontally (.top-stats is already `overflow-x: auto`), which is the
     right trade: a bar that scrolls beats a row of cards with ragged heights. */
  .top-stats .sb-stat {
    flex: 1 1 0;
    min-width: fit-content;
    /* Height shared with the header's TigerCoins card (#topCoins, quests.css). */
    box-sizing: border-box;
    height: var(--top-card-h, 68px);
    justify-content: center;
    padding: 8px 14px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: 1px;
  }
  /* No :hover — header stat cards are informational, not clickable. */
  .top-stats .sb-stat .value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-top: 0;
    line-height: 1.1;
    white-space: nowrap;
  }
  .top-stats .sb-stat .label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    line-height: 1.2;
    margin-top: 2px;
    white-space: nowrap;
  }
  /* HT / TTC qualifier, sitting to the RIGHT of the stock-value figure — a quiet
     suffix on the price line, not on the label below. Smaller and muted so it
     qualifies the number without competing with it; own colour so the up/down
     tween tint on `.value` never turns it green/red. */
  .top-stats .sb-stat .value .sb-stat-tax {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .01em;
    text-transform: none;
    color: var(--muted);
    margin-left: 5px;
    vertical-align: baseline;
  }

  /* Badge spans inside stat labels only need the inherited text-transform reset:
     the badges carry their own capsule geometry (70-detail-misc.css) and must
     stay identical here and on the spool cards. This block used to shrink them
     (9px / 1px 6px), which now fights the fixed-height capsule. */
  .top-stats .sb-stat .label .tag-plus,
  .top-stats .sb-stat .label .tag-diy,
  .top-stats .sb-stat .label .tag-cloud {
    text-transform: none;
    vertical-align: middle;
  }
  /* TigerCloud stat — purple gradient accent */
  .sb-stat--cloud {
    border-color: color-mix(in srgb, var(--violet) 35%, transparent) !important;
    background: linear-gradient(135deg, color-mix(in srgb, var(--violet) 12%, transparent), color-mix(in srgb, var(--violet) 7%, transparent)) !important;
  }
  .sb-stat--cloud .value { color: #7b879b; }
  .sb-stat--cloud .label { color: rgba(123,135,155,.75); }
  :root:not([data-theme="dark"]) .sb-stat--cloud .value { color: var(--neutral-text); }
  :root:not([data-theme="dark"]) .sb-stat--cloud .label { color: var(--neutral-text); }
  /* collapsed sidebar: keep the purple tint on the mini tile */
  .sidebar.collapsed .sb-stat--cloud::before { color: #7b879b; }
  .sidebar.collapsed .sb-stat--cloud::after  { color: rgba(123,135,155,.65); }
  :root:not([data-theme="dark"]) .sidebar.collapsed .sb-stat--cloud::before,
  :root:not([data-theme="dark"]) .sidebar.collapsed .sb-stat--cloud::after  { color: var(--neutral-text); }
  /* top-stats (header) cloud variant — identical to other chips; badge handles the colour */
  .top-stats .sb-stat--cloud          { background: var(--surface-2) !important; border-color: var(--border) !important; }
  .top-stats .sb-stat--cloud .value   { color: var(--text); }
  .top-stats .sb-stat--cloud .label   { color: var(--muted); }
  /* Informational, except the four type tiles: they set the search field's Type
     chip (renderer/filter-bar.js) and light up with it. */
  .top-stats .sb-stat { cursor: default; }
  .top-stats .sb-stat[data-filter^="tiger"] { cursor: pointer; }
  .top-stats .sb-stat.is-active {
    background: color-mix(in srgb, var(--primary) 12%, transparent) !important;
    border-color: var(--primary) !important;
  }
  .top-stats .sb-stat.is-active .value { color: var(--primary-text); }
  .top-stats .sb-stat.is-active .label { color: var(--primary-text); opacity: .75; }
  /* The TigerData tiles light up like the others (their grey slate read as
     switched off, not on). */
  .top-stats .sb-stat--cloud.is-active { background: color-mix(in srgb, var(--primary) 12%, transparent) !important; border-color: var(--primary) !important; }
  .top-stats .sb-stat--cloud.is-active .value { color: var(--primary-text); }


  /* Sidebar friends quick-access list — plain menu items, no card.
     Just an avatar circle + name on a single row. The hover only changes
     the text + avatar opacity slightly; no background, no border. */
  .sb-friends-list {
    display: flex; flex-direction: column;
    gap: 3px;
    width: 100%;             /* fill .sb-actions so chips align by flex-start (no centring jump on collapse) */
    margin: 4px 0 0;
    padding: 4px 0;          /* same in expanded + collapsed so chips don't shift */
    /* Scroll like Discord when the friend list outgrows the sidebar. The
       flex cascade (.sb-user → .sb-actions → here, all shrinkable with
       min-height:0) lets ONLY this list scroll — the avatar row, the
       Refresh/Friends buttons and the community footer stay put. The
       collapsed-mode hover tooltip is body-appended (#sbFriendTip), so the
       overflow clip here doesn't hide it. */
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    /* Scrollable but with NO visible scrollbar (Discord-style). */
    scrollbar-width: none;        /* Firefox */
  }
  .sb-friends-list::-webkit-scrollbar { width: 0; height: 0; display: none; }  /* Chromium */
  .sb-friends-list.hidden { display: none; }
  /* `.sb-actions button:not(.primary)` (specificity 0,2,1) would otherwise
     paint a gray pill behind every chip. Use `button.sb-friend-chip`
     (0,2,1) AND scope it to `.sb-actions` (0,3,1) to definitely win, and
     also neutralise the border + height + border-radius inherited from
     `.sb-actions button` so the chip becomes a flat row. */
  .sb-actions button.sb-friend-chip,
  button.sb-friend-chip {
    position: relative;        /* anchor for the active-view pill */
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    /* Height = avatar height (40px) in BOTH expanded and collapsed sidebar, with
       no extra vertical padding, so toggling the sidebar width never moves the
       chips vertically. The collapsed state (40px row) is the reference. */
    height: 40px;
    padding: 0 4px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ink-60);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    justify-content: flex-start;
    transition: color .15s;
  }
  .sb-actions button.sb-friend-chip:hover,
  button.sb-friend-chip:hover {
    background: transparent !important;
    color: var(--text) !important;
  }
  .sb-friend-chip:hover .sb-friend-avatar {
    box-shadow: 0 0 0 2px rgba(255,255,255,.12);
  }
  /* Active friend = brighter name only. The orange ring is gone: the sliding
     active-view pill (left edge) is the single source of "which view is active". */
  .sb-friend-chip.is-active { color: var(--text); }
  /* Active-view pill — ONE bar pinned to the sidebar's (window's) left edge that
     SLIDES vertically (Pong-style) to line up with the avatar of the view you're
     currently browsing. Its `top` is set in JS (_positionActiveViewPill); the
     transition does the glide. */
  .active-view-pill {
    position: absolute; left: 0; top: 0; z-index: 6;
    width: 4px; height: 30px; border-radius: 0 4px 4px 0;
    background: var(--primary); box-shadow: 0 0 10px color-mix(in srgb, var(--primary) 60%, transparent);
    opacity: 0; pointer-events: none;
    transition: top .34s cubic-bezier(.34,1.25,.5,1), opacity .2s, height .2s;
  }
  .active-view-pill.show { opacity: 1; }
  /* Friend avatars: same size in both expanded and collapsed sidebar —
     40px matches the user avatar in collapsed mode and the user wanted
     the open state to mirror that. Font scales proportionally. */
  .sb-friend-avatar {
    position: relative;       /* anchor for the .sb-avatar-photo overlay */
    width: 40px; height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700;
    color: var(--on-accent);
    letter-spacing: -.5px;
    overflow: hidden;          /* clips the <img> to the circle */
  }
  .sb-friend-name {
    flex: 1; min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Drag-to-reorder — chips slide (translateY) to open the drop gap; the dragged
     chip is hidden (the OS drag image follows the cursor instead). The slide
     transition is applied inline in JS so no sidebar-state rule can override it. */
  .sb-reordering .sb-friend-chip { will-change: transform; }
  .sb-friend-chip--dragging { opacity: 0; }

  /* Hide chip names when sidebar is collapsed (avatars only).
     The `.sb-actions button { width: 36px; height: 36px; padding: 0 }`
     rule above hits any <button> inside .sb-actions — including our
     friend chips. Override with higher specificity so the chips stay
     properly sized as round avatar pills. */
  .sidebar.collapsed .sb-friend-name { display: none; }
  .sidebar.collapsed .sb-actions button.sb-friend-chip {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
    background: transparent;
    border: 0;
    position: relative;          /* anchor for the hover tooltip */
  }
  /* (Friend avatars are 40×40 in both expanded and collapsed mode now —
     no per-state override needed.) */
  .sidebar.collapsed .sb-friends-list {
    align-items: flex-start;   /* chips stay left (centred by the 12.5px rail padding) — no jump-to-centre on collapse, like the main avatar */
    padding: 4px 0;
  }
  /* Hover bubble for collapsed-sidebar friend chips. Appended to <body> by
     JS so it escapes every ancestor's `overflow: hidden` (.sidebar itself
     has overflow:hidden to clip its gradient, which would otherwise eat
     the tooltip). Same dark style as the rack-slot hover tooltip. */
  #sbFriendTip {
    position: fixed;
    z-index: 1000;
    background: var(--dark-surface);
    color: var(--on-dark);
    border: 1px solid var(--ink-10);
    padding: 5px 10px;
    border-radius: 7px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,.3);
    opacity: 0;
    pointer-events: none;
    transform: translateX(-4px);
    transition: opacity .14s, transform .18s cubic-bezier(.4, 0, .2, 1);
  }
  #sbFriendTip.is-open {
    opacity: 1;
    transform: translateX(0);
  }
  #sbFriendTip::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 0; height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-right: 6px solid var(--dark-surface);
  }

  /* mid flex wrapper (login + stats) */
  .sb-mid { flex: 0 0 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .sidebar.collapsed .sb-mid { display: flex; }

  /* community footer — pinned to the bottom of the sidebar (the flexible space
     sits ABOVE it, between the friends list and the footer). */
  .sb-community {
    flex-shrink: 0; margin-top: auto; padding: 4px 13px 13px;
    display: flex; flex-direction: column; gap: 7px;
  }
  .sidebar.collapsed .sb-community {
    padding: 4px 6px 12px; align-items: center;
  }
  .sidebar.collapsed .sb-wiki-btn,
  .sidebar.collapsed .sb-github-btn,
  .sidebar.collapsed .sb-makerworld-btn,
  .sidebar.collapsed .sb-discord-btn,
  .sidebar.collapsed .sb-coffee-btn,
  .sidebar.collapsed .sb-report-btn {
    width: 40px; padding: 0; border-radius: 10px;   /* 40×40 square (height from the shared 40px rule) */
    gap: 0;   /* drop the icon↔label gap so the icon stays centred when the label collapses */
  }
  /* Labels collapse the same animated way as the Notifications row (no display:none). */
  .sidebar.collapsed .sb-actions .label,
  .sidebar.collapsed .sb-community .label { max-width: 0; opacity: 0; margin-left: 0; }
  /* Footer v2, collapsed: no group titles, square rows centred, version over the gear. */
  .sidebar.collapsed .sb-group-label { display: none; }
  .sidebar.collapsed .sb-group { align-items: center; }
  .sidebar.collapsed .sb-community .sb-group > button { width: 40px; height: 40px; padding: 0; justify-content: center; gap: 0; }
  .sidebar.collapsed .sb-foot { flex-direction: column-reverse; gap: 2px; }
  .sidebar.collapsed .sb-foot .sb-version { text-align: center; font-size: 10px; }
  .sidebar.collapsed .sb-settings-btn { width: 40px; justify-content: center; padding: 0; gap: 0; }

  /* App version — discrete line at the very bottom of the sidebar */
  .sb-version {
    font-size: 10px; font-weight: 500;
    color: var(--ink-30);
    text-align: center;
    margin-top: 0;
    padding: 2px 4px;
    user-select: text;
    font-family: var(--mono);
    letter-spacing: .03em;
  }
  /* Version text keeps the same size whether the sidebar is collapsed or not. */

/* Image skeleton / shimmer removed — images now hydrate from the local
   disk cache and paint instantly, so the gliding "loading shine" was both
   unnecessary and visually noisy. Images just appear, like everywhere else. */

/* Global floating snackbar (brief messages, e.g. "already in your cart"). */
.global-flash {
  position: fixed; left: 50%; bottom: 28px;
  transform: translateX(-50%) translateY(8px);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  z-index: 9999; opacity: 0; pointer-events: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  transition: opacity .2s ease, transform .2s ease;
}
.global-flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Length-limit feedback ─────────────────────────────────────────────
   A quick horizontal shake on a field whose maxlength just rejected a
   keystroke — the desktop equivalent of a phone's haptic "no". Applied
   from JS (bumpField) to any [maxlength] input/textarea; the class is
   removed on animationend so it can retrigger on the next rejected key. */
@keyframes fieldBump {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-5px); }
  40%      { transform: translateX(4px); }
  60%      { transform: translateX(-3px); }
  80%      { transform: translateX(2px); }
}
.field-bump { animation: fieldBump 180ms ease; }

/* Respect reduced-motion: no shake, a single danger-tinted border flash
   instead — the rejection is still signalled, just not through movement. */
@media (prefers-reduced-motion: reduce) {
  @keyframes fieldBump {
    0%, 100% { box-shadow: none; }
    50%      { box-shadow: 0 0 0 3px var(--danger-soft); }
  }
  .field-bump { animation: fieldBump 240ms ease; }
}

/* ── Scroll fade (a.k.a. "scroll shadow" / fade scrim) ─────────────────────
   Tells the user there is more content below in a scroller whose scrollbar we
   hide. Wired by `_wireScrollFade()`, which toggles `.can-down` (and
   `.can-up`, opt-in) from the scroll position.

   Done as a MASK on the scroller itself, not as a coloured overlay on a
   wrapper (the way the .ttag import list does it):
     • a mask is relative to the element's own box, so it does not scroll away
       with the content — no wrapper element needed anywhere;
     • it fades to TRANSPARENT, so it works on any background instead of
       having to match a hard-coded surface colour.
   The top fade is opt-in because a sticky <thead> already covers that edge —
   fading it would dim the header itself. */
.scroll-fade { --sf-size: 28px; }
.scroll-fade.can-down {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - var(--sf-size)), transparent);
          mask-image: linear-gradient(to bottom, #000 calc(100% - var(--sf-size)), transparent);
}
/* The top fade starts BELOW any sticky header: `--sf-top-offset` is set from JS
   to that header's height, so the header itself stays crisp while the content
   sliding under it fades. The hard stop at the offset lands exactly on the
   header's bottom border, so it reads as the border, not as a seam.
   Offset 0 (no sticky header, e.g. the grid) degrades to a plain top fade. */
.scroll-fade.can-up.sf-top {
  -webkit-mask-image: linear-gradient(to bottom,
    #000 var(--sf-top-offset, 0px), transparent var(--sf-top-offset, 0px),
    #000 calc(var(--sf-top-offset, 0px) + var(--sf-size)));
          mask-image: linear-gradient(to bottom,
    #000 var(--sf-top-offset, 0px), transparent var(--sf-top-offset, 0px),
    #000 calc(var(--sf-top-offset, 0px) + var(--sf-size)));
}
.scroll-fade.can-up.can-down.sf-top {
  -webkit-mask-image: linear-gradient(to bottom,
    #000 var(--sf-top-offset, 0px), transparent var(--sf-top-offset, 0px),
    #000 calc(var(--sf-top-offset, 0px) + var(--sf-size)),
    #000 calc(100% - var(--sf-size)), transparent);
          mask-image: linear-gradient(to bottom,
    #000 var(--sf-top-offset, 0px), transparent var(--sf-top-offset, 0px),
    #000 calc(var(--sf-top-offset, 0px) + var(--sf-size)),
    #000 calc(100% - var(--sf-size)), transparent);
}

/* Nothing animates while it can't be seen. Closed windows and the account menu
   stay in the page at opacity 0, so their looping animations (pulses, spinners,
   rings, the menu's light sweep) kept the renderer repainting at 60 fps: on an
   idle inventory that was ~50 % CPU on a Mac and worse on Linux without GPU
   compositing (issue #66). Paused, not removed: an animation resumes as the
   window opens. */
.modal-overlay:not(.open) *,
.modal-overlay:not(.open) *::before,
.modal-overlay:not(.open) *::after,
.acct-dropdown:not(.open) *,
.acct-dropdown:not(.open) *::before,
.acct-dropdown:not(.open) *::after { animation-play-state: paused !important; }

/* ── Tiger Studio Web ───────────────────────────────────────────────────────
   In a browser (renderer/web-bridge.js sets `html.is-web`) every element
   tagged `data-desktop-only` is removed: RFID readers, USB devices, LAN
   printers, the app updater. The desktop app never gets the class. */
html.is-web [data-desktop-only] { display: none !important; }
html:not(.is-web) [data-web-only] { display: none !important; }
/* The chip banners of a spool (encode / update / missing twin) all need an NFC
   reader — built in JS, so they are hidden here rather than tagged. */
html.is-web .chip-update-banner { display: none !important; }

/* Narrow screens: the KPI row scrolls sideways (finger or trackpad) — fade its
   right edge so it reads as "there is more", instead of a hard cut. */
@media (max-width: 1100px) {
  .top-stats {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
            mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
  }
}
