/* =====================================================================
   عَــدزّة (Adzzah) — Design System
   RTL-first, touch-first (iPad 10–13"), light + dark, zero dependencies.
   Layers: reset → tokens → base → layout → components → utilities
   Every color is a custom property on :root; dark overrides tokens only.
   ===================================================================== */

@layer reset, tokens, base, layout, components, utilities;

/* ---------------------------------------------------------------------
   0. Fonts — self-hosted if present in /public/assets/fonts, otherwise the
      browser silently falls through to system Arabic faces.
   --------------------------------------------------------------------- */
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/Cairo-arabic.woff2') format('woff2');
  font-weight: 200 1000; font-style: normal; font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC, U+102E0-102FB, U+10E60-10E7E, U+10EC2-10EC4, U+10EFC-10EFF, U+1EE00-1EE03, U+1EE05-1EE1F, U+1EE21-1EE22, U+1EE24, U+1EE27, U+1EE29-1EE32, U+1EE34-1EE37, U+1EE39, U+1EE3B, U+1EE42, U+1EE47, U+1EE49, U+1EE4B, U+1EE4D-1EE4F, U+1EE51-1EE52, U+1EE54, U+1EE57, U+1EE59, U+1EE5B, U+1EE5D, U+1EE5F, U+1EE61-1EE62, U+1EE64, U+1EE67-1EE6A, U+1EE6C-1EE72, U+1EE74-1EE77, U+1EE79-1EE7C, U+1EE7E, U+1EE80-1EE89, U+1EE8B-1EE9B, U+1EEA1-1EEA3, U+1EEA5-1EEA9, U+1EEAB-1EEBB, U+1EEF0-1EEF1;
}
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/Cairo-latin-ext.woff2') format('woff2');
  font-weight: 200 1000; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Cairo';
  src: url('../fonts/Cairo-latin.woff2') format('woff2');
  font-weight: 200 1000; font-style: normal; font-display: swap;
  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;
}
/* ---------------------------------------------------------------------
   1. Tokens
   --------------------------------------------------------------------- */
@layer tokens {
  :root {
    color-scheme: light;

    /* Brand — espresso. Appears ONLY as an accent: primary buttons,
       active nav item, key figures. Never as a page surface. */
    --brand:        #6F4E37;
    --brand-600:    #5A4030;
    --brand-700:    #463127;
    --brand-800:    #32241D;
    --brand-200:    #D5C6B8;
    --brand-100:    #E9E1D9;
    --brand-50:     #F4F1ED;
    --on-brand:     #FBF9F7;

    --accent:       #C8A27A;
    --accent-600:   #B0875A;
    --accent-700:   #7D5A37;
    --accent-200:   #E6DACA;
    --accent-100:   #F3EDE5;
    --on-accent:    #231E1B;

    /* Surfaces & text — neutral gray / white, chroma C* = 0 (R=G=B).
       Ramp: surface 100 > bg 96.5 > surface-2 93.8 > bg-deep 90.9 > surface-3 88.1 */
    --bg:           #F5F5F5;
    --bg-deep:      #E5E5E5;
    --surface:      #FFFFFF;
    --surface-2:    #EDEDED;
    --surface-3:    #DDDDDD;
    --surface-glass: rgb(255 255 255 / .82);
    --text:         #1F1F1F;
    --text-2:       #575757;
    --text-3:       #616161;
    --text-inverse: #F5F5F5;
    --border:       #D4D4D4;
    --border-strong:#7B7B7B;
    --divider:      #E4E4E4;

    /* Semantic — one muted L* band (40–43), never a traffic light */
    --success:      #2C6A4F;
    --success-bg:   #EAF2ED;
    --success-border:#C6DCD0;
    --warning:      #875D22;
    --warning-bg:   #F6EFE0;
    --warning-border:#E4D2AE;
    --danger:       #A33E34;
    --danger-600:   #88291F;
    --danger-bg:    #F8EBE9;
    --danger-border:#EBC8C3;
    --info:         #2E6291;
    --info-bg:      #E9EFF5;
    --info-border:  #C7D8E7;
    --on-status:    #FFFFFF;

    /* Focus ring — 5.35:1 on white, visible on every neutral surface */
    --focus:        #876440;
    --focus-ring:   0 0 0 2px var(--surface), 0 0 0 5px var(--focus);

    /* Shadows — neutral, light and tight so a gray UI never reads dirty */
    --shadow-color: 20 20 20;
    --shadow-1: 0 1px 2px rgb(var(--shadow-color) / .05), 0 1px 3px rgb(var(--shadow-color) / .07);
    --shadow-2: 0 2px 4px rgb(var(--shadow-color) / .05), 0 6px 16px rgb(var(--shadow-color) / .08);
    --shadow-3: 0 4px 8px rgb(var(--shadow-color) / .06), 0 16px 40px rgb(var(--shadow-color) / .14);
    --shadow-inset: inset 0 1px 2px rgb(var(--shadow-color) / .07);

    /* Spacing — 8px scale */
    --sp-0-5: 4px;
    --sp-1:  8px;
    --sp-1-5:12px;
    --sp-2:  16px;
    --sp-3:  24px;
    --sp-4:  32px;
    --sp-5:  40px;
    --sp-6:  48px;
    --sp-8:  64px;
    --sp-10: 80px;
    --sp-12: 96px;

    /* Radius */
    --r-xs:  6px;
    --r-sm:  8px;
    --r-md:  12px;
    --r-lg:  16px;
    --r-xl:  22px;
    --r-pill: 999px;

    /* Type */
    --font-display: 'Cairo', 'Tajawal', 'Segoe UI', system-ui, 'Noto Sans Arabic', sans-serif;
    --font-body:    'Tajawal', 'Cairo', 'Segoe UI', system-ui, 'Noto Sans Arabic', sans-serif;
    --font-mono:    ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    --fs-xs:  .75rem;
    --fs-sm:  .875rem;
    --fs-md:  1rem;
    --fs-lg:  1.125rem;
    --fs-xl:  1.375rem;
    --fs-2xl: 1.75rem;
    --fs-3xl: 2.25rem;
    --lh-tight: 1.25;
    --lh-body:  1.6;

    /* Motion */
    --ease-out:  cubic-bezier(.2, .8, .2, 1);
    --ease-in:   cubic-bezier(.4, 0, 1, 1);
    --ease-spring: cubic-bezier(.34, 1.4, .64, 1);
    --dur-fast: 150ms;
    --dur:      200ms;
    --dur-slow: 320ms;

    /* Layout */
    --tap:        44px;
    --sidebar-w:  268px;
    --sidebar-w-collapsed: 80px;
    --topbar-h:   64px;
    --content-max: 1440px;
    --gutter: clamp(16px, 2.4vw, 32px);
    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left:   env(safe-area-inset-left, 0px);
    --safe-right:  env(safe-area-inset-right, 0px);

    /* Z-index scale */
    --z-sidebar: 40;
    --z-topbar:  30;
    --z-dropdown: 50;
    --z-drawer:  60;
    --z-modal:   70;
    --z-toast:   80;
    --z-tooltip: 90;
  }

  /* Dark palette — roasted bean. Identical token names, no new colors. */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      /* Brand — espresso, lifted for dark surfaces */
      --brand:        #8F684C;
      --brand-600:    #7A583F;
      --brand-700:    #6F4E37;
      --brand-800:    #573F2D;
      --brand-200:    #5B4735;
      --brand-100:    #3D3027;
      --brand-50:     #2B241E;
      --on-brand:     #FBF8F5;
      --accent:       #D9B893;
      --accent-600:   #C09B71;
      --accent-700:   #BA8F60;
      --accent-200:   #6A5540;
      --accent-100:   #342A20;
      --on-accent:    #191614;
      /* Surfaces & text — neutral gray, chroma C* = 0 (R=G=B) */
      --bg:           #1B1B1B;
      --bg-deep:      #141414;
      --surface:      #222222;
      --surface-2:    #292929;
      --surface-3:    #303030;
      --surface-glass: rgb(34 34 34 / .82);
      --text:         #E9E9E9;
      --text-2:       #ABABAB;
      --text-3:       #989898;
      --text-inverse: #141414;
      --border:       #3B3B3B;
      --border-strong:#7A7A7A;
      --divider:      #333333;
      /* Semantic */
      --success:      #67BC91;
      --success-bg:   #16261F;
      --success-border:#2E5240;
      --warning:      #DFAE63;
      --warning-bg:   #2A2114;
      --warning-border:#57431F;
      --danger:       #E58277;
      --danger-600:   #CC6659;
      --danger-bg:    #2D1C1A;
      --danger-border:#5B342E;
      --info:         #7EB2DB;
      --info-bg:      #16222D;
      --info-border:  #2D4A64;
      --on-status:    #141414;
      /* Focus ring */
      --focus:        #D9B893;
      --focus-ring:   0 0 0 2px var(--surface), 0 0 0 5px var(--focus);
      /* Shadows — neutral black, deeper than light */
      --shadow-color: 0 0 0;
      --shadow-1: 0 1px 2px rgb(var(--shadow-color) / .35), 0 1px 3px rgb(var(--shadow-color) / .30);
      --shadow-2: 0 2px 4px rgb(var(--shadow-color) / .30), 0 8px 20px rgb(var(--shadow-color) / .45);
      --shadow-3: 0 4px 8px rgb(var(--shadow-color) / .35), 0 20px 48px rgb(var(--shadow-color) / .60);
      --shadow-inset: inset 0 1px 2px rgb(var(--shadow-color) / .40);
    }
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    /* Brand — espresso, lifted for dark surfaces */
    --brand:        #8F684C;
    --brand-600:    #7A583F;
    --brand-700:    #6F4E37;
    --brand-800:    #573F2D;
    --brand-200:    #5B4735;
    --brand-100:    #3D3027;
    --brand-50:     #2B241E;
    --on-brand:     #FBF8F5;
    --accent:       #D9B893;
    --accent-600:   #C09B71;
    --accent-700:   #BA8F60;
    --accent-200:   #6A5540;
    --accent-100:   #342A20;
    --on-accent:    #191614;
    /* Surfaces & text — neutral gray, chroma C* = 0 (R=G=B) */
    --bg:           #1B1B1B;
    --bg-deep:      #141414;
    --surface:      #222222;
    --surface-2:    #292929;
    --surface-3:    #303030;
    --surface-glass: rgb(34 34 34 / .82);
    --text:         #E9E9E9;
    --text-2:       #ABABAB;
    --text-3:       #989898;
    --text-inverse: #141414;
    --border:       #3B3B3B;
    --border-strong:#7A7A7A;
    --divider:      #333333;
    /* Semantic */
    --success:      #67BC91;
    --success-bg:   #16261F;
    --success-border:#2E5240;
    --warning:      #DFAE63;
    --warning-bg:   #2A2114;
    --warning-border:#57431F;
    --danger:       #E58277;
    --danger-600:   #CC6659;
    --danger-bg:    #2D1C1A;
    --danger-border:#5B342E;
    --info:         #7EB2DB;
    --info-bg:      #16222D;
    --info-border:  #2D4A64;
    --on-status:    #141414;
    /* Focus ring */
    --focus:        #D9B893;
    --focus-ring:   0 0 0 2px var(--surface), 0 0 0 5px var(--focus);
    /* Shadows — neutral black, deeper than light */
    --shadow-color: 0 0 0;
    --shadow-1: 0 1px 2px rgb(var(--shadow-color) / .35), 0 1px 3px rgb(var(--shadow-color) / .30);
    --shadow-2: 0 2px 4px rgb(var(--shadow-color) / .30), 0 8px 20px rgb(var(--shadow-color) / .45);
    --shadow-3: 0 4px 8px rgb(var(--shadow-color) / .35), 0 20px 48px rgb(var(--shadow-color) / .60);
    --shadow-inset: inset 0 1px 2px rgb(var(--shadow-color) / .40);
  }

  @media (prefers-reduced-motion: reduce) {
    :root { --dur-fast: 0ms; --dur: 0ms; --dur-slow: 0ms; }
  }
}

/* ---------------------------------------------------------------------
   2. Reset
   --------------------------------------------------------------------- */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; hanging-punctuation: first last; }
  body { min-height: 100dvh; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
  img, picture, video, canvas, svg { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
  button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
  a { color: inherit; text-decoration: none; touch-action: manipulation; }
  p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
  h1, h2, h3, h4 { text-wrap: balance; }
  ul, ol { list-style: none; padding: 0; }
  table { border-collapse: collapse; border-spacing: 0; }
  fieldset { border: 0; padding: 0; min-inline-size: 0; }
  legend { padding: 0; }
  dialog { border: 0; padding: 0; background: transparent; color: inherit; max-width: none; max-height: none; }
  [hidden] { display: none !important; }
  :focus { outline: none; }
  :focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-xs); }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  }
}

/* ---------------------------------------------------------------------
   3. Base typography & document
   --------------------------------------------------------------------- */
@layer base {
  html { font-size: 16px; scroll-behavior: smooth; background: var(--bg); }
  body {
    font-family: var(--font-body);
    font-size: var(--fs-md);
    line-height: var(--lh-body);
    color: var(--text);
    background: var(--bg);
    direction: rtl;
    text-align: start;
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
    overflow-x: clip;
  }
  h1, h2, h3, h4, h5, h6, .display {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: var(--lh-tight);
    color: var(--text);
    letter-spacing: -0.005em;
  }
  h1, .h1 { font-size: var(--fs-2xl); }
  h2, .h2 { font-size: var(--fs-xl); }
  h3, .h3 { font-size: var(--fs-lg); }
  h4, .h4 { font-size: var(--fs-md); }
  small, .small { font-size: var(--fs-sm); }
  strong, b { font-weight: 700; }
  a.link { color: var(--brand); text-decoration: underline; text-decoration-color: var(--accent-200); text-underline-offset: .18em; transition: color var(--dur-fast) var(--ease-out); }
  a.link:hover { color: var(--brand-600); text-decoration-color: var(--accent); }
  code, kbd, pre, .mono { font-family: var(--font-mono); font-size: .92em; direction: ltr; unicode-bidi: isolate; }
  kbd { display: inline-block; padding: 1px 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 6px; background: var(--surface-2); font-size: var(--fs-xs); line-height: 1.4; color: var(--text-2); }
  hr { border: 0; border-top: 1px solid var(--divider); margin-block: var(--sp-3); }
  ::selection { background: var(--accent-200); color: var(--text); }
  ::placeholder { color: var(--text-3); opacity: 1; }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
  ::-webkit-scrollbar-track { background: transparent; }
  .num, .money, [data-num], td.num, th.num, .tabular {
    font-variant-numeric: tabular-nums lining-nums;
    font-feature-settings: 'tnum' 1, 'lnum' 1;
  }
  .ltr { direction: ltr; unicode-bidi: isolate; }
  .rtl { direction: rtl; unicode-bidi: isolate; }
  .muted { color: var(--text-2); }
  .faint { color: var(--text-3); }
  .text-brand { color: var(--accent-700); }
  .text-accent { color: var(--accent-700); }
  .text-success { color: var(--success); }
  .text-warning { color: var(--warning); }
  .text-danger { color: var(--danger); }
  .text-info { color: var(--info); }
  .eyebrow { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .06em; color: var(--text-3); text-transform: uppercase; }
  .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; }
  .skip-link { position: absolute; inset-inline-start: var(--sp-2); top: -100px; z-index: 100; padding: var(--sp-1) var(--sp-2); background: var(--brand); color: var(--on-brand); border-radius: var(--r-sm); font-weight: 700; }
  .skip-link:focus-visible { top: var(--sp-2); }
}

/* ---------------------------------------------------------------------
   4. Layout — app shell: fixed RIGHT sidebar (RTL), sticky topbar, content
   --------------------------------------------------------------------- */
@layer layout {
  .app { min-height: 100dvh; display: flex; flex-direction: column; }
  html[data-sidebar="collapsed"] { --sidebar-w: var(--sidebar-w-collapsed); }

  /* Main column sits beside the fixed sidebar */
  .app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding-inline-start: calc(var(--sidebar-w) + var(--safe-right));
    transition: padding var(--dur) var(--ease-out);
  }
  .app-content {
    flex: 1;
    width: 100%;
    max-width: var(--content-max);
    margin-inline: auto;
    padding: var(--sp-3) var(--gutter) calc(var(--sp-6) + var(--safe-bottom));
  }
  .app-footer {
    padding: var(--sp-2) var(--gutter) calc(var(--sp-2) + var(--safe-bottom));
    border-top: 1px solid var(--divider);
    color: var(--text-3);
    font-size: var(--fs-xs);
    display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); align-items: center; justify-content: space-between;
  }

  /* ---- Sidebar ---- */
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--sidebar-w);
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-inline-end: 1px solid var(--border);
    padding-top: var(--safe-top);
    padding-inline-start: var(--safe-right);
    transition: width var(--dur) var(--ease-out), translate var(--dur-slow) var(--ease-out);
    will-change: width;
  }
  /* ---- Brand lockup — this is where the shop logo lives ---- */
  .sidebar-brand {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: var(--sp-1-5);
    padding: 0 var(--sp-2);
    border-bottom: 1px solid var(--divider);
    flex: none;
  }
  /* A real wordmark is wide (~1.6:1); give it vertical room and centre it.
     The icon + text lockup keeps the compact 64px row. */
  .sidebar-brand.has-logo {
    height: auto;
    min-height: var(--topbar-h);
    padding: var(--sp-1-5) var(--sp-2);
    justify-content: center;
  }
  .brand-link {
    display: flex; align-items: center; gap: var(--sp-1-5);
    min-width: 0; max-width: 100%;
    padding: var(--sp-0-5);
    border-radius: var(--r-md);
    color: var(--text);
    transition: background var(--dur-fast) var(--ease-out);
  }
  .brand-link:hover { background: var(--surface-2); }

  /* The wordmark itself: always contained, never cropped, never on a coloured
     chip — the neutral sidebar surface is its background. --logo-plate stays
     transparent in light mode and becomes a light plate in dark mode. */
  .brand-logo {
    display: block;
    width: auto; height: auto;
    max-width: 100%; max-height: 72px;
    object-fit: contain;
    background: var(--logo-plate, transparent);
    padding: var(--logo-plate-pad, 0);
    border-radius: var(--r-sm);
  }
  /* Square mark used when the rail is collapsed and a wordmark cannot fit */
  .brand-logo-mini {
    display: none;
    width: 40px; height: 40px; flex: none;
    object-fit: contain;
    background: var(--logo-plate, transparent);
    padding: var(--logo-plate-pad, 0);
    border-radius: var(--r-sm);
  }

  /* Fallback chip — the brand gradient sits behind the inline SVG mark ONLY */
  .brand-mark {
    width: 40px; height: 40px; flex: none;
    display: grid; place-items: center;
    border-radius: var(--r-md);
    background: linear-gradient(145deg, var(--brand) 0%, var(--brand-700) 100%);
    color: var(--on-brand);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / .18), var(--shadow-1);
  }
  .brand-mark svg { width: 24px; height: 24px; }
  .brand-mark.is-mini { display: none; }
  /* If a logo file is placed inside .brand-mark anywhere, strip the chip and
     contain the artwork instead of centre-cropping it into a square. */
  .brand-mark:has(img) {
    width: auto; min-width: 40px; height: 40px;
    background: none; box-shadow: none; border-radius: var(--r-sm);
  }
  .brand-mark img { display: block; width: auto; height: 100%; max-width: 100%; object-fit: contain; }

  .brand-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
  .brand-name { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-sub { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* Dark mode: a deep-red mark on a dark neutral surface loses contrast.
     Give the artwork a light plate with a soft radius instead of tinting it. */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .brand-logo,
    :root:not([data-theme="light"]) .brand-logo-mini {
      --logo-plate: var(--on-brand);
      --logo-plate-pad: var(--sp-0-5);
      box-shadow: var(--shadow-1);
    }
  }
  :root[data-theme="dark"] .brand-logo,
  :root[data-theme="dark"] .brand-logo-mini {
    --logo-plate: var(--on-brand);
    --logo-plate-pad: var(--sp-0-5);
    box-shadow: var(--shadow-1);
  }

  .sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: var(--sp-1-5) var(--sp-1-5) var(--sp-2); scrollbar-width: thin; }
  .nav-group { margin-bottom: var(--sp-2); }
  .nav-group-title {
    display: block;
    padding: var(--sp-1) var(--sp-1-5) var(--sp-0-5);
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: .04em;
    color: var(--text-3);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .nav-item {
    position: relative;
    display: flex; align-items: center; gap: var(--sp-1-5);
    min-height: var(--tap);
    padding: 0 var(--sp-1-5);
    border-radius: var(--r-md);
    color: var(--text-2);
    font-weight: 500;
    font-size: var(--fs-sm);
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
    -webkit-user-select: none; user-select: none;
  }
  .nav-item:hover { background: var(--surface-2); color: var(--text); }
  .nav-item:active { background: var(--surface-3); }
  /* Deliberate brand moment #1 — the only filled espresso in the sidebar */
  .nav-item[aria-current="page"], .nav-item.is-active {
    background: var(--brand);
    color: var(--on-brand);
    font-weight: 700;
    box-shadow: var(--shadow-1);
  }
  .nav-item[aria-current="page"]:hover, .nav-item.is-active:hover {
    background: var(--brand-600);
    color: var(--on-brand);
  }
  /* Crema line — the active marker hugs the RIGHT edge in RTL */
  .nav-item[aria-current="page"]::before, .nav-item.is-active::before {
    content: '';
    position: absolute;
    inset-inline-start: -12px;
    top: 10px; bottom: 10px; width: 4px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
  }
  .nav-icon { width: 22px; height: 22px; flex: none; color: var(--text-3); transition: color var(--dur-fast); }
  .nav-item:hover .nav-icon, .nav-item[aria-current="page"] .nav-icon, .nav-item.is-active .nav-icon { color: currentColor; }
  .nav-icon svg { width: 100%; height: 100%; }
  .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .nav-badge { font-size: var(--fs-xs); font-weight: 700; padding: 1px 8px; border-radius: var(--r-pill); background: var(--accent-100); color: var(--accent-700); }

  .sidebar-foot { flex: none; padding: var(--sp-1-5); border-top: 1px solid var(--divider); display: flex; flex-direction: column; gap: var(--sp-1); }
  .sidebar-collapse {
    display: flex; align-items: center; justify-content: center; gap: var(--sp-1);
    min-height: var(--tap); width: 100%;
    border-radius: var(--r-md);
    color: var(--text-3); font-size: var(--fs-sm); font-weight: 500;
    transition: background var(--dur-fast), color var(--dur-fast);
  }
  .sidebar-collapse:hover { background: var(--surface-2); color: var(--text); }
  .sidebar-collapse svg { width: 20px; height: 20px; transition: rotate var(--dur) var(--ease-out); }

  /* Collapsed state — icons only, labels become tooltips */
  html[data-sidebar="collapsed"] .brand-text,
  html[data-sidebar="collapsed"] .nav-label,
  html[data-sidebar="collapsed"] .nav-badge,
  html[data-sidebar="collapsed"] .nav-group-title,
  html[data-sidebar="collapsed"] .sidebar-collapse span { display: none; }
  html[data-sidebar="collapsed"] .sidebar-brand { justify-content: center; padding: 0; }
  /* 80px rail: a wide wordmark cannot fit — swap in the square mark / SVG */
  html[data-sidebar="collapsed"] .sidebar-brand.has-logo { height: var(--topbar-h); min-height: 0; padding: 0; }
  html[data-sidebar="collapsed"] .brand-logo { display: none; }
  html[data-sidebar="collapsed"] .brand-logo-mini { display: block; }
  html[data-sidebar="collapsed"] .brand-mark.is-mini { display: grid; }
  html[data-sidebar="collapsed"] .nav-item { justify-content: center; padding: 0; }
  html[data-sidebar="collapsed"] .nav-group { margin-bottom: var(--sp-1); padding-top: var(--sp-1); border-top: 1px solid var(--divider); }
  html[data-sidebar="collapsed"] .nav-group:first-child { border-top: 0; padding-top: 0; }
  html[data-sidebar="collapsed"] .sidebar-collapse svg { rotate: 180deg; }
  html[data-sidebar="collapsed"] .nav-item[aria-current="page"]::before { inset-inline-start: -12px; }

  /* ---- Topbar ---- */
  .topbar {
    position: sticky; top: 0; z-index: var(--z-topbar);
    height: calc(var(--topbar-h) + var(--safe-top));
    padding-top: var(--safe-top);
    display: flex; align-items: center; gap: var(--sp-1-5);
    padding-inline: var(--gutter);
    background: var(--surface-glass);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid var(--border);
  }
  /* Crema line — signature hairline */
  .topbar::after {
    content: '';
    position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--accent) 35%, var(--accent) 65%, transparent 100%);
    opacity: .7;
    pointer-events: none;
  }
  .topbar-start, .topbar-end { display: flex; align-items: center; gap: var(--sp-1); min-width: 0; }
  .topbar-start { flex: 1; }
  .topbar-title { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-branch { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: var(--fs-sm); padding: 6px 10px; border-radius: var(--r-pill); background: var(--surface-2); white-space: nowrap; }
  .topbar-branch svg { width: 16px; height: 16px; color: var(--text-3); }
  .topbar-sep { width: 1px; height: 24px; background: var(--border); margin-inline: var(--sp-0-5); }
  .hamburger { display: none; }

  /* ---- Page header / breadcrumbs ---- */
  .page-head {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--sp-2);
    margin-bottom: var(--sp-3);
  }
  .page-head-text { min-width: 0; }
  .page-title { font-size: var(--fs-2xl); margin: 0; }
  .page-sub { color: var(--text-2); margin-top: 4px; font-size: var(--fs-sm); }
  .page-actions { display: flex; flex-wrap: wrap; gap: var(--sp-1); align-items: center; }
  .breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-3); margin-bottom: var(--sp-1); }
  .breadcrumb a { color: var(--text-2); transition: color var(--dur-fast); }
  .breadcrumb a:hover { color: var(--accent-700); }
  .breadcrumb li { display: inline-flex; align-items: center; gap: 6px; }
  .breadcrumb li + li::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: var(--border-strong); display: inline-block; }
  .breadcrumb [aria-current="page"] { color: var(--text); font-weight: 600; }

  /* ---- Grid helpers ---- */
  .grid { display: grid; gap: var(--sp-2); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-auto { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
  .grid-stats { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
  .split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--sp-3); align-items: start; }
  .stack { display: flex; flex-direction: column; gap: var(--sp-2); }
  .stack-sm { display: flex; flex-direction: column; gap: var(--sp-1); }
  .row { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; }
  .row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-1); flex-wrap: wrap; }
  .grow { flex: 1; min-width: 0; }
  .container { width: 100%; max-width: var(--content-max); margin-inline: auto; padding-inline: var(--gutter); }
  .container-narrow { max-width: 760px; margin-inline: auto; }
  .container-form { max-width: 920px; margin-inline: auto; }

  /* Auth / centered blank-layout shell */
  .center-shell {
    min-height: 100dvh;
    display: grid; place-items: center;
    padding: calc(var(--sp-3) + var(--safe-top)) var(--gutter) calc(var(--sp-3) + var(--safe-bottom));
    background:
      radial-gradient(1200px 600px at 100% -10%, var(--accent-100), transparent 60%),
      radial-gradient(900px 500px at 0% 110%, var(--brand-50), transparent 60%),
      var(--bg);
  }
  .center-card { width: min(100%, 440px); }

  /* Responsive shell: sidebar becomes off-canvas drawer below 1024px */
  @media (max-width: 1023.98px) {
    .app-main { padding-inline-start: 0; }
    .sidebar {
      width: min(320px, 86vw) !important;
      translate: 100% 0;
      box-shadow: none;
      visibility: hidden;
      transition: translate var(--dur-slow) var(--ease-out), visibility 0s linear var(--dur-slow);
    }
    html[data-sidebar-open="true"] .sidebar { translate: 0 0; visibility: visible; box-shadow: var(--shadow-3); transition: translate var(--dur-slow) var(--ease-out); }
    html[data-sidebar="collapsed"] .brand-text,
    html[data-sidebar="collapsed"] .nav-label,
    html[data-sidebar="collapsed"] .nav-badge,
    html[data-sidebar="collapsed"] .nav-group-title { display: revert; }
    html[data-sidebar="collapsed"] .nav-item { justify-content: flex-start; padding: 0 var(--sp-1-5); }
    html[data-sidebar="collapsed"] .sidebar-brand { justify-content: flex-start; padding: 0 var(--sp-2); }
    /* Drawer mode: the rail is never collapsed, so the full wordmark comes back */
    html[data-sidebar="collapsed"] .brand-text { display: flex; }
    html[data-sidebar="collapsed"] .sidebar-brand.has-logo { height: auto; min-height: var(--topbar-h); padding: var(--sp-1-5) var(--sp-2); justify-content: center; }
    html[data-sidebar="collapsed"] .brand-logo { display: block; }
    html[data-sidebar="collapsed"] .brand-logo-mini { display: none; }
    html[data-sidebar="collapsed"] .brand-mark.is-mini { display: none; }
    html[data-sidebar="collapsed"] .nav-group { border-top: 0; padding-top: 0; margin-bottom: var(--sp-2); }
    .sidebar-collapse { display: none; }
    .hamburger { display: inline-flex; }
    .sidebar-backdrop {
      position: fixed; inset: 0; z-index: calc(var(--z-sidebar) - 1);
      background: rgb(15 18 22 / .45);
      -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
      opacity: 0; visibility: hidden;
      transition: opacity var(--dur-slow) var(--ease-out), visibility 0s linear var(--dur-slow);
    }
    html[data-sidebar-open="true"] .sidebar-backdrop { opacity: 1; visibility: visible; transition: opacity var(--dur-slow) var(--ease-out); }
    html[data-sidebar-open="true"] body { overflow: hidden; }
    .topbar-branch { display: none; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .split { grid-template-columns: 1fr; }
  }
  @media (min-width: 1024px) { .sidebar-backdrop { display: none; } }
  @media (max-width: 767.98px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .page-title { font-size: var(--fs-xl); }
    .topbar-title { display: none; }
    .app-content { padding-top: var(--sp-2); }
  }
}

/* ---------------------------------------------------------------------
   5. Components A — buttons, forms, controls, chips, badges, cards
   --------------------------------------------------------------------- */
@layer components {
  /* ---- Buttons ---- */
  .btn {
    --btn-bg: var(--surface);
    --btn-fg: var(--text);
    --btn-bd: var(--border-strong);
    --btn-bg-hover: var(--surface-2);
    position: relative;
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-1);
    min-height: var(--tap); min-width: var(--tap);
    padding: 0 var(--sp-2);
    border-radius: var(--r-md);
    border: 1px solid var(--btn-bd);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font-family: var(--font-body);
    font-weight: 700; font-size: var(--fs-sm);
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    -webkit-user-select: none; user-select: none;
    text-decoration: none;
    transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast), translate var(--dur-fast) var(--ease-out);
  }
  .btn:hover { background: var(--btn-bg-hover); }
  .btn:active { translate: 0 1px; }
  .btn:focus-visible { box-shadow: var(--focus-ring); }
  .btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; pointer-events: none; }
  .btn svg { width: 18px; height: 18px; flex: none; }
  .btn-primary {
    --btn-bg: var(--brand); --btn-fg: var(--on-brand); --btn-bd: var(--brand); --btn-bg-hover: var(--brand-600);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / .14), var(--shadow-1);
  }
  .btn-primary:hover { border-color: var(--brand-600); }
  .btn-accent { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bd: var(--accent); --btn-bg-hover: var(--accent-600); }
  .btn-secondary { --btn-bg: var(--brand-50); --btn-fg: var(--brand); --btn-bd: var(--brand-100); --btn-bg-hover: var(--brand-100); }
  .btn-outline { --btn-bg: transparent; --btn-fg: var(--brand); --btn-bd: var(--brand-200); --btn-bg-hover: var(--brand-50); }
  .btn-ghost { --btn-bg: transparent; --btn-fg: var(--text-2); --btn-bd: transparent; --btn-bg-hover: var(--surface-2); }
  .btn-ghost:hover { color: var(--text); }
  .btn-danger { --btn-bg: var(--danger); --btn-fg: var(--on-status); --btn-bd: var(--danger); --btn-bg-hover: var(--danger-600); }
  .btn-danger-soft { --btn-bg: var(--danger-bg); --btn-fg: var(--danger); --btn-bd: var(--danger-border); --btn-bg-hover: var(--danger-border); }
  .btn-success { --btn-bg: var(--success); --btn-fg: var(--on-status); --btn-bd: var(--success); --btn-bg-hover: color-mix(in oklab, var(--success), black 10%); }
  .btn-success-soft { --btn-bg: var(--success-bg); --btn-fg: var(--success); --btn-bd: var(--success-border); --btn-bg-hover: var(--success-border); }
  .btn-warning-soft { --btn-bg: var(--warning-bg); --btn-fg: var(--warning); --btn-bd: var(--warning-border); --btn-bg-hover: var(--warning-border); }
  .btn-icon { padding: 0; width: var(--tap); height: var(--tap); border-radius: var(--r-md); }
  .btn-icon svg { width: 20px; height: 20px; }
  .btn-icon.btn-round { border-radius: 50%; }
  .btn-sm { min-height: 36px; min-width: 36px; padding: 0 var(--sp-1-5); font-size: var(--fs-xs); border-radius: var(--r-sm); }
  .btn-sm.btn-icon { width: 36px; height: 36px; }
  .btn-sm svg { width: 16px; height: 16px; }
  .btn-lg { min-height: 56px; padding: 0 var(--sp-3); font-size: var(--fs-md); border-radius: var(--r-lg); }
  .btn-block { width: 100%; }
  .btn-pill { border-radius: var(--r-pill); }
  .btn.is-loading { color: transparent !important; pointer-events: none; }
  .btn.is-loading::after {
    content: ''; position: absolute; width: 18px; height: 18px;
    border: 2px solid currentColor; border-color: var(--btn-fg) transparent var(--btn-fg) var(--btn-fg);
    border-radius: 50%; animation: spin .7s linear infinite;
  }
  .btn-group { display: inline-flex; }
  .btn-group .btn { border-radius: 0; margin-inline-start: -1px; }
  .btn-group .btn:first-child { border-start-start-radius: var(--r-md); border-end-start-radius: var(--r-md); margin-inline-start: 0; }
  .btn-group .btn:last-child { border-start-end-radius: var(--r-md); border-end-end-radius: var(--r-md); }
  @keyframes spin { to { rotate: 360deg; } }

  /* ---- Fields ---- */
  .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .field-label { font-size: var(--fs-sm); font-weight: 700; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
  .field-label .req { color: var(--danger); font-weight: 700; }
  .field-hint { font-size: var(--fs-xs); color: var(--text-3); }
  .field-error { font-size: var(--fs-xs); color: var(--danger); font-weight: 600; display: none; }
  .field.has-error .field-error, .field-error:not(:empty) { display: block; }
  .field.has-error .input, .field.has-error .select, .field.has-error .textarea,
  .input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px color-mix(in oklab, var(--danger) 22%, transparent); }
  .input, .select, .textarea {
    width: 100%;
    min-height: var(--tap);
    padding: 0 var(--sp-1-5);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-md);
    line-height: 1.4;
    box-shadow: var(--shadow-inset);
    transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
    -webkit-appearance: none; appearance: none;
  }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--accent-600); }
  .input:focus-visible, .select:focus-visible, .textarea:focus-visible { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in oklab, var(--focus) 30%, transparent); border-radius: var(--r-md); }
  .input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
  .input:read-only { background: var(--surface-2); }
  .textarea { padding: var(--sp-1) var(--sp-1-5); min-height: 96px; resize: vertical; field-sizing: content; max-height: 60vh; }
  .input-sm, .select-sm { min-height: 36px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
  .input-lg { min-height: 56px; font-size: var(--fs-lg); border-radius: var(--r-lg); }
  .input[type="number"], .input[inputmode="decimal"], .input[inputmode="numeric"], .input.money { font-variant-numeric: tabular-nums; direction: ltr; text-align: end; }
  .input::-webkit-outer-spin-button, .input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
  .input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
  .input[type="date"], .input[type="time"], .input[type="datetime-local"] { direction: ltr; text-align: end; }
  .input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
  .input[type="file"] { padding-block: 9px; }
  .input[type="file"]::file-selector-button { border: 0; border-radius: var(--r-sm); padding: 6px 12px; margin-inline-end: var(--sp-1); background: var(--brand-50); color: var(--brand); font-weight: 700; font-family: inherit; cursor: pointer; }
  .select {
    padding-inline-end: 44px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23616161' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
    background-repeat: no-repeat;
    background-position: left 14px center;
    background-size: 18px;
    cursor: pointer;
  }
  .select[multiple] { padding: var(--sp-1); background-image: none; min-height: 120px; }
  /* Chevron has to be re-stated per theme: it lives inside a data-URI, not a token */
  :root[data-theme="dark"] .select:not([multiple]) {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23989898' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .select:not([multiple]) {
      background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23989898' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
    }
  }
  .input-group { position: relative; display: flex; align-items: stretch; }
  .input-group .input { flex: 1; min-width: 0; }
  .input-group > .input:not(:first-child) { border-start-start-radius: 0; border-end-start-radius: 0; }
  .input-group > .input:not(:last-child) { border-start-end-radius: 0; border-end-end-radius: 0; }
  .input-addon {
    display: inline-flex; align-items: center; justify-content: center; padding: 0 var(--sp-1-5);
    border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-2);
    font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
  }
  .input-addon:first-child { border-start-start-radius: var(--r-md); border-end-start-radius: var(--r-md); border-inline-end: 0; }
  .input-addon:last-child { border-start-end-radius: var(--r-md); border-end-end-radius: var(--r-md); border-inline-start: 0; }
  .input-icon { position: relative; }
  .input-icon > svg { position: absolute; inset-inline-start: 14px; top: 50%; translate: 0 -50%; width: 18px; height: 18px; color: var(--text-3); pointer-events: none; }
  .input-icon > .input { padding-inline-start: 42px; }
  .input-icon.icon-end > svg { inset-inline-start: auto; inset-inline-end: 14px; }
  .input-icon.icon-end > .input { padding-inline-start: var(--sp-1-5); padding-inline-end: 42px; }
  .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: var(--sp-2); }
  .form-actions { display: flex; flex-wrap: wrap; gap: var(--sp-1); justify-content: flex-start; padding-top: var(--sp-2); border-top: 1px solid var(--divider); margin-top: var(--sp-1); }
  .form-section { display: flex; flex-direction: column; gap: var(--sp-2); }
  .form-section-title { font-size: var(--fs-md); font-weight: 700; color: var(--text); padding-bottom: var(--sp-1); border-bottom: 1px solid var(--divider); }

  /* Number stepper */
  .stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
  .stepper .input { border: 0; border-radius: 0; box-shadow: none; width: 72px; text-align: center; min-height: calc(var(--tap) - 2px); }
  .stepper .input:focus-visible { box-shadow: none; }
  .stepper button { width: var(--tap); display: grid; place-items: center; color: var(--text-2); font-size: var(--fs-lg); font-weight: 700; transition: background var(--dur-fast); }
  .stepper button:hover { background: var(--surface-2); color: var(--brand); }
  .stepper button:active { background: var(--surface-3); }
  .stepper button svg { width: 18px; height: 18px; }

  /* Checkbox / Radio */
  .check { display: inline-flex; align-items: center; gap: var(--sp-1); min-height: var(--tap); cursor: pointer; font-size: var(--fs-sm); color: var(--text); -webkit-user-select: none; user-select: none; }
  .check input { appearance: none; -webkit-appearance: none; width: 22px; height: 22px; flex: none; border: 2px solid var(--border-strong); border-radius: 6px; background: var(--surface); display: grid; place-items: center; transition: background var(--dur-fast), border-color var(--dur-fast); cursor: pointer; }
  .check input[type="radio"] { border-radius: 50%; }
  .check input::after { content: ''; width: 12px; height: 12px; scale: 0; transition: scale var(--dur-fast) var(--ease-spring); }
  .check input[type="checkbox"]::after { width: 6px; height: 11px; border: solid var(--on-brand); border-width: 0 2.5px 2.5px 0; rotate: 45deg; translate: 0 -1px; }
  .check input[type="radio"]::after { width: 10px; height: 10px; border-radius: 50%; background: var(--on-brand); }
  .check input:checked { background: var(--brand); border-color: var(--brand); }
  .check input:checked::after { scale: 1; }
  .check input:focus-visible { box-shadow: var(--focus-ring); }
  .check input:disabled { opacity: .5; cursor: not-allowed; }

  /* Switch */
  .switch { display: inline-flex; align-items: center; gap: var(--sp-1); min-height: var(--tap); cursor: pointer; font-size: var(--fs-sm); -webkit-user-select: none; user-select: none; }
  .switch input { appearance: none; -webkit-appearance: none; position: relative; width: 48px; height: 28px; flex: none; border-radius: var(--r-pill); background: var(--border-strong); transition: background var(--dur) var(--ease-out); cursor: pointer; box-shadow: var(--shadow-inset); }
  .switch input::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: translate var(--dur) var(--ease-spring); }
  .switch input:checked { background: var(--success); }
  .switch input:checked::after { translate: -20px 0; }
  .switch input:focus-visible { box-shadow: var(--focus-ring); }
  .switch input:disabled { opacity: .5; cursor: not-allowed; }
  .switch.switch-brand input:checked { background: var(--brand); }

  /* Segmented control */
  .segmented { display: inline-flex; padding: 4px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); }
  .segmented > label, .segmented > button, .segmented > a { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 var(--sp-1-5); border-radius: var(--r-sm); font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap; transition: background var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast); }
  .segmented > label input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
  .segmented > label:has(input:checked), .segmented > .is-active, .segmented > [aria-pressed="true"] { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-1); }
  .segmented > label:has(input:focus-visible) { box-shadow: var(--focus-ring); }
  .segmented > label:hover, .segmented > button:hover { color: var(--text); }
  .segmented.segmented-block { display: flex; }
  .segmented.segmented-block > * { flex: 1; }
  .segmented.segmented-lg > * { min-height: var(--tap); font-size: var(--fs-md); }

  /* Chips */
  .chips { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
  .chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 var(--sp-1-5); border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; cursor: pointer; white-space: nowrap; transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast); }
  .chip:hover { border-color: var(--accent); color: var(--text); }
  .chip.is-active, .chip[aria-pressed="true"], .chip:has(input:checked) { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
  .chip input { position: absolute; opacity: 0; width: 0; height: 0; }
  .chip .chip-x { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; margin-inline-end: -6px; opacity: .7; }
  .chip .chip-x:hover { background: color-mix(in oklab, currentColor 16%, transparent); opacity: 1; }
  .chip svg { width: 16px; height: 16px; }

  /* Badges / pills */
  .badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 700; line-height: 1.4; white-space: nowrap; background: var(--surface-3); color: var(--text-2); border: 1px solid transparent; }
  .badge-brand { background: var(--brand-50); color: var(--brand); }
  .badge-accent { background: var(--accent-100); color: var(--accent-700); }
  .badge-success { background: var(--success-bg); color: var(--success); }
  .badge-warning { background: var(--warning-bg); color: var(--warning); }
  .badge-danger { background: var(--danger-bg); color: var(--danger); }
  .badge-info { background: var(--info-bg); color: var(--info); }
  .badge-outline { background: transparent; border-color: var(--border-strong); }
  .badge-solid { background: var(--brand); color: var(--on-brand); }
  .badge-lg { padding: 6px 14px; font-size: var(--fs-sm); }
  .badge svg { width: 12px; height: 12px; }
  .badge-dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

  /* Status pill — printer / online indicators */
  .status-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px 0 14px; border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; max-width: 100%; transition: border-color var(--dur), background var(--dur); cursor: pointer; }
  .status-pill:hover { border-color: var(--border-strong); background: var(--surface-2); }
  .status-pill .dot { position: relative; width: 10px; height: 10px; border-radius: 50%; background: var(--text-3); flex: none; }
  .status-pill .dot::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid currentColor; opacity: 0; }
  .status-pill.is-online { color: var(--success); border-color: var(--success-border); background: var(--success-bg); }
  .status-pill.is-online .dot { background: var(--success); }
  .status-pill.is-offline { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
  .status-pill.is-offline .dot { background: var(--danger); }
  .status-pill.is-busy { color: var(--warning); border-color: var(--warning-border); background: var(--warning-bg); }
  .status-pill.is-busy .dot { background: var(--warning); }
  .status-pill.is-busy .dot::after { animation: ping 1.4s var(--ease-out) infinite; color: var(--warning); }
  .status-pill.is-online .dot::after { animation: ping 2.4s var(--ease-out) infinite; color: var(--success); }
  .status-pill .pill-text { overflow: hidden; text-overflow: ellipsis; }
  .status-pill .pill-meta { color: inherit; opacity: .7; font-weight: 500; }
  .status-pill svg { width: 16px; height: 16px; flex: none; }
  @keyframes ping { 0% { scale: .6; opacity: .8; } 100% { scale: 1.6; opacity: 0; } }
  @media (prefers-reduced-motion: reduce) { .status-pill .dot::after { animation: none !important; } }

  /* Avatar */
  .avatar { --size: 40px; width: var(--size); height: var(--size); flex: none; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(145deg, var(--accent-100), var(--brand-100)); color: var(--brand); font-family: var(--font-display); font-weight: 700; font-size: calc(var(--size) * .4); overflow: hidden; border: 2px solid var(--surface); box-shadow: var(--shadow-1); }
  .avatar img { width: 100%; height: 100%; object-fit: cover; }
  .avatar-sm { --size: 32px; }
  .avatar-lg { --size: 56px; }
  .avatar-xl { --size: 80px; }
  .avatar-square { border-radius: var(--r-md); }
  .avatar-group { display: inline-flex; }
  .avatar-group .avatar + .avatar { margin-inline-start: -10px; }

  /* Cards */
  .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); overflow: clip; display: flex; flex-direction: column; min-width: 0; }
  .card-hover { transition: box-shadow var(--dur) var(--ease-out), translate var(--dur) var(--ease-out), border-color var(--dur); }
  .card-hover:hover { box-shadow: var(--shadow-2); translate: 0 -2px; border-color: var(--accent); }
  .card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-1); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--divider); flex-wrap: wrap; }
  .card-title { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-md); display: flex; align-items: center; gap: var(--sp-1); }
  .card-title svg { width: 20px; height: 20px; color: var(--accent-700); }
  .card-sub { color: var(--text-3); font-size: var(--fs-sm); }
  .card-body { padding: var(--sp-3); }
  .card-body.is-flush { padding: 0; }
  .card-foot { padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--divider); background: var(--surface-2); display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; }
  .card-compact .card-head, .card-compact .card-foot { padding: var(--sp-1-5) var(--sp-2); }
  .card-compact .card-body { padding: var(--sp-2); }
  .card-flat { box-shadow: none; }
  .card-soft { background: var(--surface-2); border-color: transparent; box-shadow: none; }
  .card-brand { background: linear-gradient(150deg, var(--brand) 0%, var(--brand-700) 100%); color: var(--on-brand); border-color: transparent; }
  .card-brand .card-title, .card-brand h1, .card-brand h2, .card-brand h3 { color: inherit; }
  .card-brand .muted, .card-brand .faint { color: color-mix(in oklab, var(--on-brand) 80%, transparent); }

  /* Stat card */
  .stat { position: relative; display: flex; flex-direction: column; gap: var(--sp-1); padding: var(--sp-2) var(--sp-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); min-width: 0; overflow: clip; transition: box-shadow var(--dur), border-color var(--dur); }
  a.stat:hover { box-shadow: var(--shadow-2); border-color: var(--accent); }
  .stat-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-1); }
  .stat-label { font-size: var(--fs-sm); color: var(--text-2); font-weight: 600; }
  .stat-icon { width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--brand-50); color: var(--brand); flex: none; }
  .stat-icon svg { width: 20px; height: 20px; }
  .stat-value { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 700; line-height: 1.1; color: var(--text); font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; text-align: start; display: flex; align-items: baseline; gap: 6px; }
  .stat-value .unit { font-family: var(--font-body); font-size: var(--fs-sm); color: var(--text-3); font-weight: 600; }
  .stat-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-1); font-size: var(--fs-xs); color: var(--text-3); }
  .stat-delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); font-variant-numeric: tabular-nums; }
  .stat-delta.up { color: var(--success); background: var(--success-bg); }
  .stat-delta.down { color: var(--danger); background: var(--danger-bg); }
  .stat-delta.flat { color: var(--text-2); background: var(--surface-3); }
  .stat-delta svg { width: 12px; height: 12px; }
  .stat.tone-success .stat-icon { background: var(--success-bg); color: var(--success); }
  .stat.tone-warning .stat-icon { background: var(--warning-bg); color: var(--warning); }
  .stat.tone-danger .stat-icon { background: var(--danger-bg); color: var(--danger); }
  .stat.tone-info .stat-icon { background: var(--info-bg); color: var(--info); }
  .stat.tone-accent .stat-icon { background: var(--accent-100); color: var(--accent-700); }
  .stat.stat-brand { background: linear-gradient(150deg, var(--brand) 0%, var(--brand-700) 100%); color: var(--on-brand); border-color: transparent; }
  .stat.stat-brand .stat-label, .stat.stat-brand .stat-foot, .stat.stat-brand .stat-value .unit { color: color-mix(in oklab, var(--on-brand) 80%, transparent); }
  .stat.stat-brand .stat-value { color: var(--on-brand); }
  .stat.stat-brand .stat-icon { background: color-mix(in oklab, var(--on-brand) 16%, transparent); color: var(--on-brand); }
}

/* ---------------------------------------------------------------------
   6. Components B — tabs, tables, pagination, overlays, feedback
   --------------------------------------------------------------------- */
@layer components {
  /* ---- Tabs ---- */
  .tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 var(--sp-2); color: var(--text-2); font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; border-radius: var(--r-sm) var(--r-sm) 0 0; transition: color var(--dur-fast), background var(--dur-fast); cursor: pointer; }
  .tab:hover { color: var(--text); background: var(--surface-2); }
  .tab[aria-selected="true"], .tab.is-active { color: var(--accent-700); }
  .tab[aria-selected="true"]::after, .tab.is-active::after { content: ''; position: absolute; left: var(--sp-1); right: var(--sp-1); bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: linear-gradient(90deg, var(--accent), var(--brand)); }
  .tab svg { width: 18px; height: 18px; }
  .tab .badge { margin-inline-start: 2px; }
  .tab-panel { padding-top: var(--sp-3); }
  .tab-panel[hidden] { display: none; }
  .tabs-pills { border: 0; gap: var(--sp-1); }
  .tabs-pills .tab { border-radius: var(--r-pill); border: 1px solid transparent; }
  .tabs-pills .tab[aria-selected="true"] { background: var(--brand-50); border-color: var(--brand-100); }
  .tabs-pills .tab[aria-selected="true"]::after { display: none; }

  /* ---- Table ---- */
  .table-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1); padding: var(--sp-1-5) var(--sp-2); border-bottom: 1px solid var(--divider); }
  .table-toolbar .input-icon { flex: 1 1 220px; max-width: 420px; }
  .table-toolbar .table-count { color: var(--text-3); font-size: var(--fs-sm); white-space: nowrap; margin-inline-start: auto; }
  .table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { width: 100%; font-size: var(--fs-sm); }
  .table th, .table td { padding: 12px var(--sp-2); text-align: start; vertical-align: middle; border-bottom: 1px solid var(--divider); }
  .table thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); color: var(--text-2); font-weight: 700; font-size: var(--fs-xs); letter-spacing: .02em; white-space: nowrap; border-bottom: 1px solid var(--border); }
  .table thead th[data-sort] { cursor: pointer; -webkit-user-select: none; user-select: none; padding-inline-end: 26px; position: sticky; }
  .table thead th[data-sort]::after { content: ''; position: absolute; inset-inline-end: 10px; top: 50%; translate: 0 -50%; width: 8px; height: 8px; border-inline-end: 2px solid currentColor; border-bottom: 2px solid currentColor; rotate: 45deg; opacity: .25; transition: opacity var(--dur-fast), rotate var(--dur-fast), translate var(--dur-fast); margin-top: -2px; }
  .table thead th[data-sort]:hover::after { opacity: .6; }
  .table thead th[aria-sort="ascending"]::after { opacity: 1; rotate: -135deg; translate: 0 -30%; color: var(--accent-700); }
  .table thead th[aria-sort="descending"]::after { opacity: 1; color: var(--accent-700); }
  .table tbody tr { transition: background var(--dur-fast); }
  .table tbody tr:hover { background: var(--surface-2); }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr.is-selected { background: var(--brand-50); }
  .table tbody tr[data-href] { cursor: pointer; }
  .table td.num, .table th.num { text-align: end; direction: ltr; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .table td.actions, .table th.actions { text-align: end; white-space: nowrap; width: 1%; }
  .table td.actions .btn { margin-inline-start: 4px; }
  .table td.shrink, .table th.shrink { width: 1%; white-space: nowrap; }
  .table .cell-primary { font-weight: 700; color: var(--text); }
  .table .cell-sub { display: block; font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
  .table tfoot td { background: var(--surface-2); font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
  .table-striped tbody tr:nth-child(even) { background: color-mix(in oklab, var(--surface-2) 55%, transparent); }
  .table-compact th, .table-compact td { padding: 8px var(--sp-1-5); }
  .table-lines td, .table-lines th { border-inline-end: 1px solid var(--divider); }
  .table-lines td:last-child, .table-lines th:last-child { border-inline-end: 0; }
  .card > .table-wrap .table thead th:first-child { border-start-start-radius: 0; }
  .table-empty td { padding: var(--sp-6) var(--sp-2); text-align: center; color: var(--text-3); }
  .table-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-1); padding: var(--sp-1-5) var(--sp-2); border-top: 1px solid var(--divider); font-size: var(--fs-sm); color: var(--text-3); }

  /* ---- Pagination ---- */
  .pagination { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
  .page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 40px; padding: 0 10px; border-radius: var(--r-sm); border: 1px solid transparent; color: var(--text-2); font-weight: 600; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast); }
  .page-link:hover { background: var(--surface-2); color: var(--text); }
  .page-link[aria-current="page"] { background: var(--brand); color: var(--on-brand); border-color: var(--brand); }
  .page-link.is-disabled { opacity: .4; pointer-events: none; }
  .page-link svg { width: 18px; height: 18px; }
  .page-ellipsis { min-width: 28px; text-align: center; color: var(--text-3); }
  .per-page { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-sm); color: var(--text-3); }
  .per-page .select { min-height: 40px; width: auto; padding-inline-start: 12px; }

  /* ---- Dropdown ---- */
  .dropdown { position: relative; display: inline-block; }
  .dropdown-menu {
    position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: var(--z-dropdown);
    min-width: 220px; max-width: min(92vw, 360px); padding: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-3);
    opacity: 0; visibility: hidden; translate: 0 -6px; scale: .98;
    transition: opacity var(--dur-fast) var(--ease-out), translate var(--dur-fast) var(--ease-out), scale var(--dur-fast) var(--ease-out), visibility 0s linear var(--dur-fast);
  }
  .dropdown.is-open > .dropdown-menu, .dropdown-menu.is-open { opacity: 1; visibility: visible; translate: 0 0; scale: 1; transition: opacity var(--dur-fast) var(--ease-out), translate var(--dur-fast) var(--ease-out), scale var(--dur-fast) var(--ease-out); }
  .dropdown-menu.align-start { inset-inline-end: auto; inset-inline-start: 0; }
  .dropdown-menu.drop-up { top: auto; bottom: calc(100% + 6px); }
  .dropdown-item { display: flex; align-items: center; gap: var(--sp-1); width: 100%; min-height: var(--tap); padding: 0 12px; border-radius: var(--r-sm); color: var(--text); font-size: var(--fs-sm); font-weight: 500; text-align: start; transition: background var(--dur-fast); cursor: pointer; }
  .dropdown-item:hover, .dropdown-item:focus-visible { background: var(--surface-2); }
  .dropdown-item svg { width: 18px; height: 18px; color: var(--text-3); flex: none; }
  .dropdown-item.is-danger { color: var(--danger); }
  .dropdown-item.is-danger svg { color: currentColor; }
  .dropdown-item.is-danger:hover { background: var(--danger-bg); }
  .dropdown-item kbd { margin-inline-start: auto; }
  .dropdown-sep { height: 1px; background: var(--divider); margin: 6px 4px; }
  .dropdown-head { padding: 8px 12px 6px; font-size: var(--fs-xs); font-weight: 700; color: var(--text-3); }
  .dropdown-user { display: flex; align-items: center; gap: var(--sp-1); padding: 10px 12px; }
  .dropdown-user .name { font-weight: 700; font-size: var(--fs-sm); line-height: 1.2; }
  .dropdown-user .role { font-size: var(--fs-xs); color: var(--text-3); }

  /* ---- Modal (native <dialog>) ---- */
  .modal { position: fixed; inset: 0; z-index: var(--z-modal); width: 100%; height: 100%; max-width: 100vw; max-height: 100dvh; display: grid; place-items: center; padding: var(--sp-2); overflow: auto; background: transparent; }
  .modal::backdrop { background: rgb(15 18 22 / .5); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
  .modal:not([open]) { display: none; }
  .modal-box { width: min(100%, 560px); max-height: calc(100dvh - var(--sp-4) - var(--safe-top) - var(--safe-bottom)); display: flex; flex-direction: column; background: var(--surface); color: var(--text); border-radius: var(--r-xl); box-shadow: var(--shadow-3); border: 1px solid var(--border); overflow: clip; }
  .modal-sm .modal-box { width: min(100%, 420px); }
  .modal-lg .modal-box { width: min(100%, 820px); }
  .modal-xl .modal-box { width: min(100%, 1100px); }
  .modal-head { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--divider); }
  .modal-title { flex: 1; font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; margin: 0; }
  .modal-body { flex: 1; padding: var(--sp-3); overflow: auto; -webkit-overflow-scrolling: touch; }
  .modal-foot { display: flex; align-items: center; justify-content: flex-start; gap: var(--sp-1); flex-wrap: wrap; padding: var(--sp-2) var(--sp-3) calc(var(--sp-2) + var(--safe-bottom)); border-top: 1px solid var(--divider); background: var(--surface-2); }
  .modal-foot .spacer { flex: 1; }
  .modal-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto var(--sp-2); background: var(--brand-50); color: var(--brand); }
  .modal-icon svg { width: 28px; height: 28px; }
  .modal-icon.is-danger { background: var(--danger-bg); color: var(--danger); }
  .modal-icon.is-warning { background: var(--warning-bg); color: var(--warning); }
  .modal-icon.is-success { background: var(--success-bg); color: var(--success); }
  .modal-confirm .modal-body { text-align: center; padding-top: var(--sp-4); }
  .modal-confirm .modal-body h3 { margin-bottom: var(--sp-1); }
  .modal-confirm .modal-body p { color: var(--text-2); }
  .modal-confirm .modal-foot { justify-content: center; background: transparent; border-top: 0; padding-top: 0; }
  .modal-confirm .modal-foot .btn { min-width: 120px; }
  .modal[open] .modal-box { animation: modal-in var(--dur-slow) var(--ease-out) both; }
  .modal[open]::backdrop { animation: fade-in var(--dur) var(--ease-out) both; }
  .modal.is-closing .modal-box { animation: modal-out var(--dur-fast) var(--ease-in) both; }
  .modal.is-closing::backdrop { animation: fade-out var(--dur-fast) var(--ease-in) both; }
  @keyframes modal-in { from { opacity: 0; translate: 0 12px; scale: .97; } to { opacity: 1; translate: 0 0; scale: 1; } }
  @keyframes modal-out { from { opacity: 1; scale: 1; } to { opacity: 0; scale: .97; } }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
  @keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
  @media (max-width: 767.98px) {
    .modal { padding: 0; align-items: end; }
    .modal-box, .modal-sm .modal-box, .modal-lg .modal-box, .modal-xl .modal-box { width: 100%; max-height: calc(100dvh - var(--sp-3) - var(--safe-top)); border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: 0; }
    .modal[open] .modal-box { animation-name: sheet-in; }
  }

  /* ---- Drawer (side panel) ---- */
  .drawer { position: fixed; inset: 0; z-index: var(--z-drawer); width: 100%; height: 100%; max-width: 100vw; max-height: 100dvh; display: block; padding: 0; overflow: visible; }
  .drawer:not([open]) { display: none; }
  .drawer::backdrop { background: rgb(15 18 22 / .45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
  .drawer-box { position: absolute; top: 0; bottom: 0; inset-inline-end: 0; width: min(100%, 460px); display: flex; flex-direction: column; background: var(--surface); color: var(--text); box-shadow: var(--shadow-3); border-inline-start: 1px solid var(--border); padding-top: var(--safe-top); }
  .drawer-start .drawer-box { inset-inline-end: auto; inset-inline-start: 0; border-inline-start: 0; border-inline-end: 1px solid var(--border); }
  .drawer-lg .drawer-box { width: min(100%, 640px); }
  .drawer-head { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--divider); }
  .drawer-title { flex: 1; font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; margin: 0; }
  .drawer-body { flex: 1; overflow: auto; padding: var(--sp-3); -webkit-overflow-scrolling: touch; }
  .drawer-foot { display: flex; gap: var(--sp-1); flex-wrap: wrap; padding: var(--sp-2) var(--sp-3) calc(var(--sp-2) + var(--safe-bottom)); border-top: 1px solid var(--divider); background: var(--surface-2); }
  .drawer[open] .drawer-box { animation: drawer-in var(--dur-slow) var(--ease-out) both; }
  .drawer[open]::backdrop { animation: fade-in var(--dur) var(--ease-out) both; }
  .drawer.is-closing .drawer-box { animation: drawer-out var(--dur-fast) var(--ease-in) both; }
  .drawer.is-closing::backdrop { animation: fade-out var(--dur-fast) var(--ease-in) both; }
  .drawer-start[open] .drawer-box { animation-name: drawer-in-start; }
  @keyframes drawer-in { from { translate: -100% 0; } to { translate: 0 0; } }
  @keyframes drawer-in-start { from { translate: 100% 0; } to { translate: 0 0; } }
  @keyframes drawer-out { from { opacity: 1; } to { opacity: 0; } }

  /* ---- Bottom sheet ---- */
  .sheet { position: fixed; inset: 0; z-index: var(--z-drawer); width: 100%; height: 100%; max-width: 100vw; max-height: 100dvh; display: grid; align-items: end; padding: 0; }
  .sheet:not([open]) { display: none; }
  .sheet::backdrop { background: rgb(15 18 22 / .45); }
  .sheet-box { width: 100%; max-height: calc(92dvh - var(--safe-top)); display: flex; flex-direction: column; background: var(--surface); color: var(--text); border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-3); border-top: 1px solid var(--border); overflow: clip; }
  .sheet-grip { width: 44px; height: 5px; border-radius: 5px; background: var(--border-strong); margin: 10px auto 0; flex: none; }
  .sheet-head { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-1-5) var(--sp-3); }
  .sheet-title { flex: 1; font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; margin: 0; }
  .sheet-body { flex: 1; overflow: auto; padding: 0 var(--sp-3) var(--sp-3); -webkit-overflow-scrolling: touch; }
  .sheet-foot { display: flex; gap: var(--sp-1); padding: var(--sp-2) var(--sp-3) calc(var(--sp-2) + var(--safe-bottom)); border-top: 1px solid var(--divider); background: var(--surface-2); }
  .sheet[open] .sheet-box { animation: sheet-in var(--dur-slow) var(--ease-out) both; }
  .sheet[open]::backdrop { animation: fade-in var(--dur) var(--ease-out) both; }
  .sheet.is-closing .sheet-box { animation: sheet-out var(--dur-fast) var(--ease-in) both; }
  .sheet.is-closing::backdrop { animation: fade-out var(--dur-fast) var(--ease-in) both; }
  @keyframes sheet-in { from { translate: 0 100%; } to { translate: 0 0; } }
  @keyframes sheet-out { from { translate: 0 0; } to { translate: 0 100%; } }

  /* ---- Toasts ---- */
  .toasts { position: fixed; z-index: var(--z-toast); inset-inline-start: 50%; translate: -50% 0; bottom: calc(var(--sp-3) + var(--safe-bottom)); display: flex; flex-direction: column; gap: var(--sp-1); width: min(calc(100vw - var(--sp-4)), 460px); pointer-events: none; }
  [dir="rtl"] .toasts { translate: 50% 0; }
  .toast { pointer-events: auto; display: flex; align-items: center; gap: var(--sp-1-5); padding: 12px 14px; background: var(--text); color: var(--text-inverse); border-radius: var(--r-lg); box-shadow: var(--shadow-3); font-size: var(--fs-sm); font-weight: 600; animation: toast-in var(--dur-slow) var(--ease-spring) both; border: 1px solid color-mix(in oklab, var(--text-inverse) 12%, transparent); }
  .toast.is-leaving { animation: toast-out var(--dur) var(--ease-in) both; }
  .toast-icon { width: 28px; height: 28px; flex: none; border-radius: 50%; display: grid; place-items: center; background: color-mix(in oklab, var(--text-inverse) 14%, transparent); }
  .toast-icon svg { width: 16px; height: 16px; }
  .toast-success .toast-icon { background: var(--success); color: var(--on-status); }
  .toast-danger .toast-icon { background: var(--danger); color: var(--on-status); }
  .toast-warning .toast-icon { background: var(--warning); color: var(--on-status); }
  .toast-info .toast-icon { background: var(--info); color: var(--on-status); }
  .toast-text { flex: 1; min-width: 0; line-height: 1.45; }
  .toast-action { flex: none; padding: 6px 12px; border-radius: var(--r-sm); background: color-mix(in oklab, var(--text-inverse) 16%, transparent); color: inherit; font-weight: 700; font-size: var(--fs-xs); min-height: 36px; }
  .toast-action:hover { background: color-mix(in oklab, var(--text-inverse) 26%, transparent); }
  .toast-close { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; opacity: .6; }
  .toast-close:hover { opacity: 1; background: color-mix(in oklab, var(--text-inverse) 14%, transparent); }
  .toast-close svg { width: 16px; height: 16px; }
  @keyframes toast-in { from { opacity: 0; translate: 0 16px; scale: .96; } to { opacity: 1; translate: 0 0; scale: 1; } }
  @keyframes toast-out { from { opacity: 1; } to { opacity: 0; translate: 0 8px; } }

  /* ---- Alerts ---- */
  .alert { display: flex; align-items: flex-start; gap: var(--sp-1-5); padding: var(--sp-1-5) var(--sp-2); border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: var(--fs-sm); }
  .alert-icon { width: 22px; height: 22px; flex: none; margin-top: 1px; }
  .alert-icon svg { width: 100%; height: 100%; }
  .alert-body { flex: 1; min-width: 0; }
  .alert-title { font-weight: 700; margin-bottom: 2px; }
  .alert ul { list-style: disc; padding-inline-start: 18px; margin-top: 4px; }
  .alert-close { flex: none; width: 32px; height: 32px; margin: -6px -6px -6px 0; border-radius: 50%; display: grid; place-items: center; opacity: .6; }
  .alert-close:hover { opacity: 1; background: color-mix(in oklab, currentColor 10%, transparent); }
  .alert-close svg { width: 16px; height: 16px; }
  .alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
  .alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
  .alert-danger, .alert-error { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
  .alert-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }
  .alert-brand { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand); }

  /* ---- Empty state ---- */
  .empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: var(--sp-1); padding: var(--sp-8) var(--sp-3); color: var(--text-2); }
  .empty-icon { width: 88px; height: 88px; border-radius: 28px; display: grid; place-items: center; background: linear-gradient(145deg, var(--surface-2), var(--brand-50)); color: var(--brand); border: 1px solid var(--border); margin-bottom: var(--sp-1); }
  .empty-icon svg { width: 40px; height: 40px; opacity: .85; }
  .empty-title { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-lg); color: var(--text); }
  .empty-text { max-width: 44ch; font-size: var(--fs-sm); color: var(--text-3); }
  .empty-actions { display: flex; gap: var(--sp-1); flex-wrap: wrap; justify-content: center; margin-top: var(--sp-1); }
  .empty-sm { padding: var(--sp-4) var(--sp-2); }
  .empty-sm .empty-icon { width: 56px; height: 56px; border-radius: 18px; }
  .empty-sm .empty-icon svg { width: 26px; height: 26px; }

  /* ---- Skeleton ---- */
  .skeleton { position: relative; overflow: hidden; background: var(--surface-3); border-radius: var(--r-sm); color: transparent !important; min-height: 1em; }
  .skeleton::after { content: ''; position: absolute; inset: 0; translate: -100% 0; background: linear-gradient(90deg, transparent, rgb(255 255 255 / .55), transparent); animation: shimmer 1.4s var(--ease-out) infinite; }
  :root[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgb(255 255 255 / .08), transparent); }
  .skeleton-text { height: 14px; margin-block: 6px; }
  .skeleton-title { height: 22px; width: 50%; }
  .skeleton-circle { border-radius: 50%; }
  .skeleton-block { height: 120px; border-radius: var(--r-lg); }
  @keyframes shimmer { to { translate: 100% 0; } }
  @media (prefers-reduced-motion: reduce) { .skeleton::after { animation: none; } }

  /* ---- Progress ---- */
  .progress { position: relative; width: 100%; height: 8px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
  .progress-bar { height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--brand), var(--accent)); transition: width var(--dur-slow) var(--ease-out); }
  .progress-lg { height: 14px; }
  .progress-sm { height: 4px; }
  .progress.is-success .progress-bar { background: var(--success); }
  .progress.is-warning .progress-bar { background: var(--warning); }
  .progress.is-danger .progress-bar { background: var(--danger); }
  .progress.is-indeterminate .progress-bar { width: 40%; animation: indeterminate 1.4s var(--ease-out) infinite; }
  @keyframes indeterminate { 0% { translate: 160% 0; } 100% { translate: -260% 0; } }
  .progress-label { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--text-3); margin-bottom: 6px; font-variant-numeric: tabular-nums; }

  /* ---- Tooltip (pure CSS, data-tip) ---- */
  [data-tip] { position: relative; }
  [data-tip]::after { content: attr(data-tip); position: absolute; z-index: var(--z-tooltip); bottom: calc(100% + 8px); inset-inline-start: 50%; translate: 50% 4px; padding: 6px 10px; border-radius: var(--r-sm); background: var(--text); color: var(--text-inverse); font-size: var(--fs-xs); font-weight: 600; line-height: 1.4; white-space: nowrap; opacity: 0; visibility: hidden; pointer-events: none; box-shadow: var(--shadow-2); transition: opacity var(--dur-fast) var(--ease-out), translate var(--dur-fast) var(--ease-out), visibility 0s linear var(--dur-fast); }
  [data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; visibility: visible; translate: 50% 0; transition-delay: 300ms, 300ms, 300ms; }
  [data-tip][data-tip-pos="bottom"]::after { bottom: auto; top: calc(100% + 8px); translate: 50% -4px; }
  [data-tip][data-tip-pos="bottom"]:hover::after { translate: 50% 0; }
  [data-tip][data-tip-pos="start"]::after { bottom: auto; top: 50%; inset-inline-start: auto; inset-inline-end: calc(100% + 8px); translate: 0 -50%; }
  [data-tip][data-tip-pos="end"]::after { bottom: auto; top: 50%; inset-inline-start: calc(100% + 8px); translate: 0 -50%; }
  @media (hover: none) { [data-tip]:hover::after { opacity: 0; visibility: hidden; } }

  /* ---- Misc: kpi list, divider label, list rows ---- */
  .list { display: flex; flex-direction: column; }
  .list-item { display: flex; align-items: center; gap: var(--sp-1-5); min-height: 56px; padding: var(--sp-1) 0; border-bottom: 1px solid var(--divider); }
  .list-item:last-child { border-bottom: 0; }
  .list-item .list-main { flex: 1; min-width: 0; }
  .list-item .list-title { font-weight: 700; font-size: var(--fs-sm); }
  .list-item .list-sub { font-size: var(--fs-xs); color: var(--text-3); }
  .list-item .list-end { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; }
  .divider-label { display: flex; align-items: center; gap: var(--sp-1-5); color: var(--text-3); font-size: var(--fs-xs); font-weight: 700; }
  .divider-label::before, .divider-label::after { content: ''; flex: 1; height: 1px; background: var(--divider); }
  .kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px var(--sp-2); font-size: var(--fs-sm); }
  .kv dt { color: var(--text-3); font-weight: 600; }
  .kv dd { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
  .total-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-1); padding: 8px 0; font-size: var(--fs-sm); color: var(--text-2); border-bottom: 1px dashed var(--divider); }
  .total-row .money { color: var(--text); font-weight: 700; }
  .total-row.is-grand { border-bottom: 0; padding-top: var(--sp-1-5); font-size: var(--fs-lg); color: var(--text); font-weight: 700; }
  .total-row.is-grand .money { font-family: var(--font-display); font-size: var(--fs-2xl); color: var(--accent-700); }
  .money-neg { color: var(--danger); }
  .money-pos { color: var(--success); }

  /* ---- Error pages ---- */
  .error-page { min-height: 60vh; display: grid; place-items: center; text-align: center; padding: var(--sp-6) var(--sp-2); }
  .error-code { font-family: var(--font-display); font-size: clamp(64px, 14vw, 128px); font-weight: 700; line-height: 1; color: var(--brand-100); letter-spacing: -.04em; direction: ltr; -webkit-text-stroke: 1px var(--brand-200); }
  :root[data-theme="dark"] .error-code { color: var(--brand-100); -webkit-text-stroke: 1px var(--brand-200); }
  .error-title { font-size: var(--fs-2xl); margin-top: calc(var(--sp-2) * -1); }
  .error-text { color: var(--text-2); max-width: 46ch; margin: var(--sp-1) auto var(--sp-3); }
  .error-cup { width: 96px; height: 96px; margin: 0 auto var(--sp-2); color: var(--accent-600); }

  /* ---- Login / PIN ---- */
  .pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-1); }
  .pin-pad .btn { min-height: 64px; font-size: var(--fs-xl); font-family: var(--font-display); border-radius: var(--r-lg); }
  .pin-dots { display: flex; justify-content: center; gap: 12px; padding: var(--sp-2) 0; }
  .pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); transition: background var(--dur-fast), border-color var(--dur-fast), scale var(--dur-fast) var(--ease-spring); }
  .pin-dots span.is-filled { background: var(--brand); border-color: var(--brand); scale: 1.1; }
}

/* ---------------------------------------------------------------------
   7. Utilities
   --------------------------------------------------------------------- */
@layer utilities {
  .flex { display: flex; } .inline-flex { display: inline-flex; } .block { display: block; } .inline-block { display: inline-block; } .hidden { display: none; }
  .items-center { align-items: center; } .items-start { align-items: flex-start; } .items-end { align-items: flex-end; } .items-baseline { align-items: baseline; }
  .justify-between { justify-content: space-between; } .justify-center { justify-content: center; } .justify-end { justify-content: flex-end; } .justify-start { justify-content: flex-start; }
  .wrap { flex-wrap: wrap; } .nowrap { white-space: nowrap; } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .flex-col { flex-direction: column; } .flex-1 { flex: 1 1 0%; } .flex-none { flex: none; }
  .gap-0 { gap: 0; } .gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); } .gap-half { gap: var(--sp-0-5); }
  .m-0 { margin: 0; } .mt-1 { margin-top: var(--sp-1); } .mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); }
  .mb-1 { margin-bottom: var(--sp-1); } .mb-2 { margin-bottom: var(--sp-2); } .mb-3 { margin-bottom: var(--sp-3); } .mb-4 { margin-bottom: var(--sp-4); }
  .ms-auto { margin-inline-start: auto; } .me-auto { margin-inline-end: auto; } .mx-auto { margin-inline: auto; }
  .p-0 { padding: 0; } .p-1 { padding: var(--sp-1); } .p-2 { padding: var(--sp-2); } .p-3 { padding: var(--sp-3); } .p-4 { padding: var(--sp-4); }
  .px-2 { padding-inline: var(--sp-2); } .py-2 { padding-block: var(--sp-2); } .py-1 { padding-block: var(--sp-1); }
  .w-full { width: 100%; } .w-auto { width: auto; } .h-full { height: 100%; } .min-w-0 { min-width: 0; }
  .text-start { text-align: start; } .text-end { text-align: end; } .text-center { text-align: center; }
  .text-xs { font-size: var(--fs-xs); } .text-sm { font-size: var(--fs-sm); } .text-md { font-size: var(--fs-md); } .text-lg { font-size: var(--fs-lg); } .text-xl { font-size: var(--fs-xl); } .text-2xl { font-size: var(--fs-2xl); } .text-3xl { font-size: var(--fs-3xl); }
  .fw-400 { font-weight: 400; } .fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
  .font-display { font-family: var(--font-display); }
  .bg-surface { background: var(--surface); } .bg-surface-2 { background: var(--surface-2); } .bg-brand { background: var(--brand); color: var(--on-brand); }
  .rounded { border-radius: var(--r-md); } .rounded-lg { border-radius: var(--r-lg); } .rounded-pill { border-radius: var(--r-pill); }
  .border { border: 1px solid var(--border); } .border-t { border-top: 1px solid var(--divider); } .border-b { border-bottom: 1px solid var(--divider); }
  .shadow-1 { box-shadow: var(--shadow-1); } .shadow-2 { box-shadow: var(--shadow-2); } .shadow-3 { box-shadow: var(--shadow-3); }
  .relative { position: relative; } .sticky-top { position: sticky; top: calc(var(--topbar-h) + var(--sp-2)); }
  .overflow-auto { overflow: auto; } .overflow-hidden { overflow: hidden; }
  .cursor-pointer { cursor: pointer; } .select-none { -webkit-user-select: none; user-select: none; }
  .touch { min-height: var(--tap); min-width: var(--tap); }
  .icon { width: 20px; height: 20px; flex: none; } .icon-sm { width: 16px; height: 16px; } .icon-lg { width: 28px; height: 28px; }
  .fade-in { animation: fade-in var(--dur-slow) var(--ease-out) both; }
  .rise-in { animation: rise-in var(--dur-slow) var(--ease-out) both; }
  @keyframes rise-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }
  .print-only { display: none !important; }
  @media (min-width: 768px) { .md\:hidden { display: none; } .md\:flex { display: flex; } }
  @media (max-width: 767.98px) { .sm\:hidden { display: none; } .sm\:block { display: block; } .sm\:w-full { width: 100%; } .sm\:flex-col { flex-direction: column; } }
  @media print {
    .no-print, .sidebar, .topbar, .app-footer, .toasts, .sidebar-backdrop { display: none !important; }
    .print-only { display: revert !important; }
    .app-main { padding: 0 !important; }
    body { background: #fff; color: #000; }
    .card, .stat { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  }
}

/* ---------------------------------------------------------------------
   8. POS primitives — shared by pos/index.php (layout 'blank'). Tablet first.
   --------------------------------------------------------------------- */
@layer components {
  .pos { height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); grid-template-rows: auto 1fr; background: var(--bg); overflow: hidden; padding-top: var(--safe-top); }
  .pos-bar { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--sp-1); min-height: 60px; padding: 0 var(--gutter); background: var(--surface); border-bottom: 1px solid var(--border); position: relative; }
  .pos-bar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--accent) 40%, var(--accent) 60%, transparent); opacity: .7; }
  .pos-catalog { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
  .pos-cats { display: flex; gap: var(--sp-1); padding: var(--sp-1-5) var(--gutter); overflow-x: auto; scrollbar-width: none; flex: none; }
  .pos-cats::-webkit-scrollbar { display: none; }
  .pos-cat { flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 var(--sp-2); border-radius: var(--r-pill); background: var(--surface); border: 1px solid var(--border); color: var(--text-2); font-weight: 700; font-size: var(--fs-sm); white-space: nowrap; transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast); }
  .pos-cat.is-active, .pos-cat[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
  .pos-cat .swatch { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
  .pos-grid { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 var(--gutter) calc(var(--sp-3) + var(--safe-bottom)); display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: var(--sp-1-5); align-content: start; }
  .tile { position: relative; display: flex; flex-direction: column; min-height: 132px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); overflow: clip; text-align: start; transition: box-shadow var(--dur-fast), translate var(--dur-fast) var(--ease-out), border-color var(--dur-fast); -webkit-user-select: none; user-select: none; }
  .tile:hover { box-shadow: var(--shadow-2); border-color: var(--accent); }
  .tile:active { translate: 0 1px; box-shadow: var(--shadow-inset); }
  .tile:focus-visible { box-shadow: var(--focus-ring); }
  .tile-img { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; color: var(--accent-600); overflow: hidden; }
  .tile-img img { width: 100%; height: 100%; object-fit: cover; }
  .tile-img svg { width: 32px; height: 32px; opacity: .6; }
  .tile-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .tile-name { font-weight: 700; font-size: var(--fs-sm); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .tile-price { margin-top: auto; font-family: var(--font-display); font-weight: 700; color: var(--accent-700); font-variant-numeric: tabular-nums; direction: ltr; text-align: start; }
  .tile-badge { position: absolute; top: 8px; inset-inline-start: 8px; }
  .tile-qty { position: absolute; top: 8px; inset-inline-end: 8px; min-width: 28px; height: 28px; padding: 0 8px; border-radius: var(--r-pill); background: var(--brand); color: var(--on-brand); font-weight: 700; font-size: var(--fs-sm); display: grid; place-items: center; box-shadow: var(--shadow-1); animation: pop var(--dur) var(--ease-spring); }
  .tile.is-out { opacity: .55; }
  .tile.is-out .tile-img::after { content: 'غير متوفر'; position: absolute; inset: 0; display: grid; place-items: center; background: rgb(15 18 22 / .48); color: #FFFFFF; font-weight: 700; font-size: var(--fs-sm); }
  .tile.is-out .tile-img { position: relative; }
  .tile-compact { min-height: 88px; }
  .tile-compact .tile-img { display: none; }
  @keyframes pop { from { scale: .6; } to { scale: 1; } }

  .pos-cart { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-inline-start: 1px solid var(--border); box-shadow: var(--shadow-2); }
  .cart-head { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-1-5) var(--sp-2); border-bottom: 1px solid var(--divider); flex: none; }
  .cart-title { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-md); flex: 1; display: flex; align-items: center; gap: 8px; }
  .cart-lines { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 var(--sp-1-5); }
  .cart-line { display: grid; grid-template-columns: 1fr auto; gap: 4px var(--sp-1); padding: 10px 6px; border-bottom: 1px solid var(--divider); align-items: center; transition: background var(--dur-fast); }
  .cart-line:hover { background: var(--surface-2); }
  .cart-line.is-active { background: var(--brand-50); box-shadow: inset 3px 0 0 var(--accent); }
  .cart-line .line-name { font-weight: 700; font-size: var(--fs-sm); }
  .cart-line .line-mods { font-size: var(--fs-xs); color: var(--text-3); grid-column: 1; }
  .cart-line .line-total { font-weight: 700; font-variant-numeric: tabular-nums; direction: ltr; text-align: end; grid-row: 1; grid-column: 2; }
  .cart-line .line-ctl { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-1); margin-top: 4px; }
  .cart-line .line-ctl .stepper .input { width: 56px; }
  .cart-line .line-ctl .stepper button { width: 40px; }
  .cart-line .line-unit { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
  .cart-totals { flex: none; padding: var(--sp-1-5) var(--sp-2); border-top: 1px solid var(--divider); background: var(--surface-2); }
  .cart-actions { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: var(--sp-1-5) var(--sp-2) calc(var(--sp-1-5) + var(--safe-bottom)); border-top: 1px solid var(--divider); background: var(--surface); }
  .cart-actions .btn-pay { grid-column: 1 / -1; min-height: 60px; font-size: var(--fs-lg); border-radius: var(--r-lg); display: flex; justify-content: space-between; padding-inline: var(--sp-3); }
  .cart-actions .btn-pay .pay-amt { font-family: var(--font-display); font-size: var(--fs-xl); font-variant-numeric: tabular-nums; direction: ltr; }
  .cart-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: var(--sp-1); color: var(--text-3); text-align: center; padding: var(--sp-4); }
  .cart-empty svg { width: 56px; height: 56px; opacity: .35; }

  .keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .keypad .btn { min-height: 56px; font-size: var(--fs-xl); font-family: var(--font-display); border-radius: var(--r-md); font-variant-numeric: tabular-nums; }
  .keypad .btn.span-2 { grid-column: span 2; }
  .pay-methods { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
  .pay-method { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 76px; border-radius: var(--r-lg); border: 2px solid var(--border); background: var(--surface); color: var(--text-2); font-weight: 700; font-size: var(--fs-sm); transition: border-color var(--dur-fast), background var(--dur-fast), color var(--dur-fast); }
  .pay-method svg { width: 26px; height: 26px; }
  .pay-method:hover { border-color: var(--accent); }
  .pay-method.is-active, .pay-method[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-50); color: var(--brand); }
  .quick-amounts { display: flex; flex-wrap: wrap; gap: 8px; }
  .quick-amounts .btn { flex: 1 1 calc(25% - 8px); font-variant-numeric: tabular-nums; }
  .change-due { display: flex; justify-content: space-between; align-items: baseline; padding: var(--sp-1-5) var(--sp-2); border-radius: var(--r-md); background: var(--success-bg); color: var(--success); font-weight: 700; }
  .change-due .amt { font-family: var(--font-display); font-size: var(--fs-2xl); font-variant-numeric: tabular-nums; direction: ltr; }
  .change-due.is-short { background: var(--danger-bg); color: var(--danger); }
  .shortcut-bar { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); padding: 6px var(--gutter); font-size: var(--fs-xs); color: var(--text-3); border-top: 1px solid var(--divider); background: var(--surface); }
  .shortcut-bar span { display: inline-flex; align-items: center; gap: 6px; }

  /* Tablet: cart becomes a bottom sheet */
  @media (max-width: 1023.98px) {
    .pos { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
    .pos-cart { position: fixed; inset-inline: 0; bottom: 0; z-index: var(--z-drawer); height: calc(86dvh - var(--safe-top)); border-radius: var(--r-xl) var(--r-xl) 0 0; border: 1px solid var(--border); border-bottom: 0; translate: 0 calc(100% - 76px - var(--safe-bottom)); transition: translate var(--dur-slow) var(--ease-out); box-shadow: var(--shadow-3); }
    .pos-cart.is-open { translate: 0 0; }
    .cart-head { min-height: 76px; cursor: pointer; padding-top: 18px; }
    .cart-head::before { content: ''; position: absolute; top: 8px; left: 50%; translate: -50% 0; width: 44px; height: 5px; border-radius: 5px; background: var(--border-strong); }
    .pos-cart { position: fixed; }
    .cart-head { position: relative; }
    .pos-grid { padding-bottom: calc(96px + var(--safe-bottom)); }
    .shortcut-bar { display: none; }
  }
  @media (max-width: 767.98px) {
    .pos-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 124px), 1fr)); gap: var(--sp-1); }
    .tile { min-height: 116px; }
    .cart-actions { grid-template-columns: repeat(2, 1fr); }
  }

  /* ---- Timeline (audit / shift history) ---- */
  .timeline { position: relative; padding-inline-start: 26px; }
  .timeline::before { content: ''; position: absolute; top: 6px; bottom: 6px; inset-inline-start: 8px; width: 2px; background: var(--divider); }
  .timeline-item { position: relative; padding-bottom: var(--sp-2); }
  .timeline-item::before { content: ''; position: absolute; inset-inline-start: -23px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); }
  .timeline-item.is-danger::before { border-color: var(--danger); }
  .timeline-item.is-success::before { border-color: var(--success); }
  .timeline-time { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }
  .timeline-title { font-weight: 700; font-size: var(--fs-sm); }
  .timeline-text { font-size: var(--fs-sm); color: var(--text-2); }

  /* ---- Receipt preview (on-screen mock of the thermal receipt) ---- */
  .receipt-preview { width: 100%; max-width: 340px; margin-inline: auto; background: #fff; color: #111; padding: 18px 16px 28px; font-size: 12.5px; line-height: 1.55; border-radius: 4px; box-shadow: var(--shadow-2); position: relative; font-family: var(--font-body); }
  .receipt-preview::after { content: ''; position: absolute; left: 0; right: 0; bottom: -8px; height: 8px; background: linear-gradient(-45deg, transparent 6px, #fff 0) 0 0 / 12px 12px, linear-gradient(45deg, transparent 6px, #fff 0) 6px 0 / 12px 12px; background-repeat: repeat-x; }
  .receipt-preview .rp-center { text-align: center; }
  .receipt-preview .rp-dash { border-top: 1px dashed #999; margin: 8px 0; }
  .receipt-preview table { width: 100%; }
  .receipt-preview td { padding: 2px 0; vertical-align: top; }
  .receipt-preview .rp-total { font-weight: 700; font-size: 14px; }
}

/* ---------------------------------------------------------------------
   9. Filters, date ranges, validation summary, offline state, misc
   --------------------------------------------------------------------- */
@layer components {
  .filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-1-5); padding: var(--sp-2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); margin-bottom: var(--sp-2); }
  .filters .field { flex: 1 1 180px; min-width: 0; }
  .filters .field-label { font-size: var(--fs-xs); }
  .filters .filters-actions { display: flex; gap: var(--sp-1); flex: none; }
  .date-range { display: flex; flex-direction: column; gap: 8px; }
  .date-range .inputs { display: flex; align-items: center; gap: 8px; }
  .date-range .inputs .input { flex: 1; min-width: 0; }
  .date-range .inputs .sep { color: var(--text-3); font-size: var(--fs-sm); flex: none; }
  .range-presets { display: flex; flex-wrap: wrap; gap: 6px; }
  .range-presets .chip { min-height: 32px; font-size: var(--fs-xs); padding: 0 12px; }
  .range-presets .chip.is-active { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
  .date-nav { display: inline-flex; align-items: center; gap: 4px; }
  .date-nav .input { width: 160px; }

  .form-errors { margin-bottom: var(--sp-2); }
  .form-errors ul { margin: 0; }
  form[aria-busy="true"] { position: relative; }
  form[aria-busy="true"] .form-actions .btn:not(.is-loading) { opacity: .6; pointer-events: none; }

  /* Offline: the topbar shows an amber stripe; the pill turns amber */
  html[data-offline] .topbar::after { background: var(--warning); opacity: 1; height: 2px; }
  html[data-offline] .topbar::before { content: 'غير متصل بالإنترنت'; position: absolute; top: calc(var(--safe-top) + 100%); inset-inline-start: 50%; translate: 50% 0; padding: 2px 12px; border-radius: 0 0 var(--r-sm) var(--r-sm); background: var(--warning); color: var(--on-status); font-size: var(--fs-xs); font-weight: 700; z-index: 1; }

  /* Notification bell with unread dot */
  .bell { position: relative; }
  .bell .dot { position: absolute; top: 9px; inset-inline-end: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); border: 2px solid var(--surface); }

  /* Shift indicator in the topbar */
  .shift-pill { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 0 12px; border-radius: var(--r-pill); font-size: var(--fs-sm); font-weight: 700; white-space: nowrap; border: 1px solid var(--border); color: var(--text-2); background: var(--surface); transition: background var(--dur-fast), border-color var(--dur-fast); }
  .shift-pill:hover { background: var(--surface-2); }
  .shift-pill.is-open { color: var(--success); border-color: var(--success-border); background: var(--success-bg); }
  .shift-pill.is-closed { color: var(--text-3); }
  .shift-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
  .shift-pill .since { font-weight: 500; opacity: .75; font-variant-numeric: tabular-nums; }
  .shift-pill svg { width: 16px; height: 16px; }

  /* Search field in the topbar (global search / command) */
  .topbar-search { flex: 0 1 320px; }
  .topbar-search .input { min-height: 40px; background: var(--surface-2); border-color: transparent; border-radius: var(--r-pill); }
  .topbar-search .input:focus-visible { background: var(--surface); border-color: var(--focus); }
  .topbar-search kbd { position: absolute; inset-inline-end: 10px; top: 50%; translate: 0 -50%; pointer-events: none; }

  /* Definition / detail panels */
  .detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: var(--sp-2); }
  .detail { display: flex; flex-direction: column; gap: 2px; padding: var(--sp-1-5); background: var(--surface-2); border-radius: var(--r-md); }
  .detail .k { font-size: var(--fs-xs); color: var(--text-3); font-weight: 700; }
  .detail .v { font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

  /* Sticky action bar at the bottom of long forms (tablet-friendly) */
  .action-bar { position: sticky; bottom: 0; z-index: 5; display: flex; gap: var(--sp-1); flex-wrap: wrap; align-items: center; padding: var(--sp-1-5) var(--sp-2) calc(var(--sp-1-5) + var(--safe-bottom)); margin-top: var(--sp-3); background: var(--surface-glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-top: 1px solid var(--border); border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .action-bar .spacer { flex: 1; }

  /* Callout for the printer / bridge explainer boxes */
  .callout { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-1-5); padding: var(--sp-2); border-radius: var(--r-lg); background: var(--accent-100); border: 1px solid var(--accent-200); color: var(--text); }
  .callout svg { width: 24px; height: 24px; color: var(--accent-700); }
  .callout-title { font-weight: 700; margin-bottom: 2px; }
  .callout p { font-size: var(--fs-sm); color: var(--text-2); }
  .callout ol { list-style: decimal; padding-inline-start: 20px; font-size: var(--fs-sm); color: var(--text-2); display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }

  /* Step indicator (installer / wizards) */
  .steps { display: flex; align-items: center; gap: 4px; counter-reset: step; }
  .step { flex: 1; display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-3); font-weight: 600; min-width: 0; }
  .step::before { counter-increment: step; content: counter(step); width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); font-weight: 700; font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
  .step.is-done::before { background: var(--success); color: var(--on-status); content: '✓'; }
  .step.is-active { color: var(--accent-700); }
  .step.is-active::before { background: var(--brand); color: var(--on-brand); }
  .step span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .step:not(:last-child)::after { content: ''; flex: 1; height: 2px; background: var(--divider); min-width: 12px; }
  .step.is-done:not(:last-child)::after { background: var(--success-border); }
  @media (max-width: 767.98px) { .step span { display: none; } .step { flex: 0 0 auto; } .step.is-active span { display: inline; } }

  /* Ready-state reveal: avoid layout flash before prefs apply */
  html:not(.is-ready) .sidebar, html:not(.is-ready) .dropdown-menu { transition: none !important; }
}

/* Topbar user button + sidebar user row (kept out of inline styles for CSP) */
@layer components {
  .user-btn { padding-inline: 6px 10px; gap: 10px; }
  .user-btn-text { display: flex; flex-direction: column; align-items: flex-start; text-align: start; line-height: 1.15; min-width: 0; }
  .user-btn-name { display: block; max-width: 140px; font-size: var(--fs-sm); }
  .user-btn-role { display: block; max-width: 140px; font-size: var(--fs-xs); font-weight: 500; color: var(--text-3); }
  .sidebar-user { padding: 4px 6px; }
  .sidebar-user .name { font-weight: 700; font-size: var(--fs-sm); line-height: 1.2; }
  .sidebar-user .role { font-size: var(--fs-xs); color: var(--text-3); }
  html[data-sidebar="collapsed"] .sidebar-user { justify-content: center; padding: 4px 0; }
  @media (max-width: 1023.98px) { html[data-sidebar="collapsed"] .sidebar-user { justify-content: flex-start; padding: 4px 6px; } }
}

/* ── حقوق التطوير: FirstOfDev ─────────────────────────────────────────────── */
.fod{display:inline-flex;align-items:center;gap:8px;text-decoration:none;color:inherit;opacity:.85;transition:opacity .2s,transform .2s;direction:rtl;white-space:nowrap}
.fod:hover{opacity:1;transform:translateY(-1px)}.fod:focus-visible{outline:2px solid var(--focus);outline-offset:3px;border-radius:8px}
.fod-t{font-size:12px;color:var(--text-3)}
.fod-mk{width:22px;height:22px;flex:0 0 auto;filter:drop-shadow(0 2px 4px rgba(120,0,230,.25))}
.fod-w{direction:ltr;font-family:"Avenir Next","Segoe UI",Inter,system-ui,-apple-system,sans-serif;font-weight:600;font-size:14px;letter-spacing:-.3px;color:var(--text);display:inline-flex}
.fod-w b{font-weight:600}.fod-w i{font-style:normal;font-weight:800;background:linear-gradient(90deg,#E100FF,#8A00E6);-webkit-background-clip:text;background-clip:text;color:transparent}
.fod-img{height:26px;width:auto;display:block}
.fod-light .fod-t{color:rgb(255 255 255 / .7)}.fod-light .fod-w{color:#FFFFFF}
.app-footer .fod{margin-inline-start:12px}
