/**
 * BUNEXA
 * Copyright (c) 2026 Devlan Solutions Ltd. All rights reserved.
 * PROPRIETARY AND CONFIDENTIAL. A product of Devlan Solutions Ltd (https://devlan.co.ke).
 * Unauthorised copying, modification or distribution is prohibited without a written licence from Devlan.
 */
/*
 * BUNEXA Design System v2: component library. Uses ONLY the variables from tokens.css.
 * Naming: legacy shared classes (.btn .field .card .badge .alert .table) keep their names so existing
 * views upgrade for free; every new component is .bx-*.
 */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-gutter: stable; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--text-base)/var(--leading-normal) var(--font-body); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: var(--leading-tight); margin: 0 0 .5em; letter-spacing: -.01em; font-weight: 600; }
h1 { font-size: var(--text-xl); } h2 { font-size: var(--text-lg); } h3 { font-size: var(--text-md); }
p { margin: 0 0 1em; }
a { color: var(--brand-text); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }
code, kbd, samp { font-family: var(--font-mono); font-size: .9em; }
code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
kbd, .bx-kbd { display: inline-flex; align-items: center; min-width: 1.5em; justify-content: center; padding: .05em .4em; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); color: var(--text-soft); font-size: .72rem; line-height: 1.5; }
.muted { color: var(--muted); } .small { font-size: var(--text-sm); } .right { text-align: right; } .nowrap { white-space: nowrap; }
.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; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--brand-soft); }
.icon { width: 1.25em; height: 1.25em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.25em; }
.num, .tnum { font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn { --h: 40px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: var(--h); padding: 0 var(--space-4); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: 500 var(--text-base)/1.2 var(--font-body); text-decoration: none; cursor: pointer; white-space: nowrap; position: relative; transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); -webkit-tap-highlight-color: transparent; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--bg-elev); }
.btn-danger:hover { background: var(--danger); filter: brightness(.92); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-tonal { background: var(--brand-soft); border-color: transparent; color: var(--brand-text); }
.btn-tonal:hover { background: color-mix(in srgb, var(--brand) 20%, transparent); }
.btn-sm { --h: 32px; padding: 0 .7rem; font-size: var(--text-sm); }
.btn-lg { --h: 48px; padding: 0 1.4rem; font-size: var(--text-md); }
.btn-block { width: 100%; }
.icon-btn { min-width: var(--h); padding: 0; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 1.1em; height: 1.1em; border-radius: 50%; border: 2px solid var(--text); border-right-color: transparent; animation: bx-spin .7s linear infinite; }
.btn-primary.is-loading::after { border-color: var(--brand-contrast); border-right-color: transparent; }
.btn-danger.is-loading::after { border-color: var(--bg-elev); border-right-color: transparent; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
@keyframes bx-spin { to { transform: rotate(360deg); } }
@media (pointer: coarse) { .btn { --h: 44px; } .btn-sm { --h: 40px; } }

/* ---------- Forms ---------- */
.field { margin-bottom: var(--space-4); min-width: 0; }
.field > label, .label { display: flex; align-items: baseline; gap: .35rem; font-weight: 500; font-size: var(--text-sm); color: var(--text); margin-bottom: .35rem; }
.field > label .req, .label .req { color: var(--danger); }
.field > label .opt { color: var(--muted); font-weight: 400; font-size: var(--text-xs); }
.hint { color: var(--muted); font-size: var(--text-xs); margin-top: .3rem; }
.field-error, .field-err { display: flex; gap: .3rem; align-items: flex-start; color: var(--danger); font-size: var(--text-xs); margin-top: .3rem; font-weight: 500; }
.input, .select, .textarea, .field input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=color]):not([type=file]):not([type=range]), .field select, .field textarea {
  width: 100%; min-height: 40px; padding: .5rem .75rem; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font: inherit; transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.field select, .select { appearance: none; padding-right: 2rem; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a9c8f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .6rem center; background-size: 1.1rem; }
.textarea, .field textarea { min-height: 96px; resize: vertical; }
.input::placeholder, .field input::placeholder, .field textarea::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover, .field input:hover:not(:focus), .field select:hover, .field textarea:hover { border-color: var(--muted); }
.input:focus, .select:focus, .textarea:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus-ring); }
.field input[type=color] { width: 56px; height: 40px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: pointer; }
.field input[type=file] { width: 100%; padding: .4rem; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); }
.field input[disabled], .input[disabled], .field select[disabled] { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.is-invalid, .field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger) !important; }
.is-invalid:focus, .field.has-error input:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 30%, transparent); }
.field.is-valid input { border-color: var(--success); }
.form-grid { display: grid; gap: 0 var(--space-5); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border); }
.bx-sticky-actions { position: sticky; bottom: 0; z-index: 5; margin: var(--space-5) calc(var(--space-4) * -1) 0; padding: var(--space-3) var(--space-4); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--border); display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4) var(--space-4); margin: 0 0 var(--space-4); min-width: 0; }
legend { font-weight: 600; padding: 0 .4rem; }
.input-group { display: flex; gap: .5rem; align-items: center; }
.inline-form { display: inline; }
/* prefix / suffix */
.bx-affix { display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
.bx-affix:focus-within { border-color: var(--brand); box-shadow: var(--focus-ring); }
.field.has-error .bx-affix { border-color: var(--danger); }
.bx-affix > input, .field .bx-affix > input { border: 0 !important; box-shadow: none !important; background: transparent !important; min-width: 0; flex: 1; border-radius: 0; }
.bx-affix > .pre, .bx-affix > .suf { display: flex; align-items: center; padding: 0 .75rem; color: var(--muted); font-size: var(--text-sm); background: var(--surface-2); white-space: nowrap; }
.bx-affix > .pre { border-right: 1px solid var(--border); border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.bx-affix > .suf { border-left: 1px solid var(--border); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.bx-counter { text-align: right; font-size: var(--text-xs); color: var(--muted); margin-top: .25rem; font-variant-numeric: tabular-nums; }
.bx-counter.is-over { color: var(--danger); }
/* check, radio, switch */
.check { display: flex; align-items: flex-start; gap: .6rem; min-height: 32px; padding: .3rem 0; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: .1rem; accent-color: var(--brand); flex: none; }
.check small { display: block; color: var(--muted); }
.bx-switch { display: inline-flex; align-items: center; gap: .65rem; cursor: pointer; min-height: 32px; }
.bx-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.bx-switch .track { width: 38px; height: 22px; border-radius: var(--radius-pill); background: var(--border-strong); position: relative; flex: none; transition: background var(--dur) var(--ease); }
.bx-switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--bg-elev); box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease); }
.bx-switch input:checked + .track { background: var(--brand); }
.bx-switch input:checked + .track::after { transform: translateX(16px); background: var(--brand-contrast); }
.bx-switch input:focus-visible + .track { box-shadow: var(--focus-ring); }
.bx-switch input:disabled + .track { opacity: .5; }
/* segmented control */
.bx-seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.bx-seg label { position: relative; margin: 0; }
.bx-seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.bx-seg span { display: inline-flex; align-items: center; gap: .4rem; min-height: 30px; padding: 0 .85rem; border-radius: calc(var(--radius-sm) - 2px); color: var(--muted); font-weight: 500; font-size: var(--text-sm); transition: background var(--dur-fast), color var(--dur-fast); }
.bx-seg input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.bx-seg input:focus-visible + span { box-shadow: var(--focus-ring); }
/* dropzone */
.bx-drop { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: var(--space-5); text-align: center; color: var(--muted); background: var(--surface); cursor: pointer; transition: border-color var(--dur), background var(--dur); position: relative; }
.bx-drop:hover, .bx-drop.is-over { border-color: var(--brand); background: var(--brand-soft); }
.bx-drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: 0; padding: 0; }
.bx-drop strong { color: var(--text); display: block; }
.bx-drop-list { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .75rem; justify-content: center; }
.bx-drop-item { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: var(--text-xs); color: var(--text); max-width: 100%; }
.bx-drop-item img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }

/* ---------- Combobox / select ---------- */
.bx-combo { position: relative; }
.bx-combo-box { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; min-height: 40px; padding: .25rem .5rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); cursor: text; transition: border-color var(--dur-fast), box-shadow var(--dur-fast); }
.bx-combo.is-open .bx-combo-box, .bx-combo-box:focus-within { border-color: var(--brand); box-shadow: var(--focus-ring); }
.bx-combo-input { flex: 1; min-width: 80px; border: 0 !important; outline: 0; box-shadow: none !important; background: transparent !important; padding: .2rem 0 !important; min-height: 28px !important; font: inherit; color: var(--text); }
.bx-chip { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .2rem .1rem .55rem; border-radius: var(--radius-pill); background: var(--brand-soft); color: var(--brand-text); font-size: var(--text-sm); font-weight: 500; }
.bx-chip button { border: 0; background: none; color: inherit; cursor: pointer; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; padding: 0; }
.bx-chip button:hover { background: var(--brand-soft); }
.bx-combo-val { color: var(--text); padding: 0 .25rem; }
.bx-combo-caret { margin-left: auto; color: var(--muted); }
.bx-list { position: fixed; z-index: 3000; max-height: 280px; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow); padding: .25rem; animation: bx-pop var(--dur-fast) var(--ease); }
.bx-opt { display: flex; align-items: center; gap: .5rem; padding: .5rem .65rem; border-radius: 6px; cursor: pointer; color: var(--text); }
.bx-opt.is-active { background: var(--surface-2); }
.bx-opt[aria-selected="true"] { color: var(--brand-text); font-weight: 600; }
.bx-opt small { color: var(--muted); margin-left: auto; }
.bx-opt-empty { padding: .75rem; color: var(--muted); text-align: center; }

/* ---------- Date picker ---------- */
.bx-cal { position: fixed; z-index: 3000; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: .75rem; width: 296px; animation: bx-pop var(--dur-fast) var(--ease); }
.bx-cal.has-presets { width: 440px; display: grid; grid-template-columns: 124px 1fr; gap: .75rem; }
.bx-cal-presets { display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--border); padding-right: .6rem; }
.bx-cal-presets button { text-align: left; border: 0; background: none; padding: .4rem .5rem; border-radius: 6px; color: var(--text-soft); font: inherit; font-size: var(--text-sm); cursor: pointer; }
.bx-cal-presets button:hover { background: var(--surface-2); color: var(--text); }
.bx-cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .4rem; font-weight: 600; font-family: var(--font-display); }
.bx-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.bx-cal-grid .dow { font-size: var(--text-xs); color: var(--muted); padding: .25rem 0; }
.bx-day { border: 0; background: none; aspect-ratio: 1; border-radius: 8px; font: inherit; font-size: var(--text-sm); color: var(--text); cursor: pointer; font-variant-numeric: tabular-nums; }
.bx-day:hover { background: var(--surface-2); }
.bx-day.out { color: var(--muted); opacity: .55; }
.bx-day.today { box-shadow: inset 0 0 0 1px var(--brand); }
.bx-day.in-range { background: var(--brand-soft); border-radius: 0; }
.bx-day.sel { background: var(--brand); color: var(--brand-contrast); }
.bx-cal-foot { display: flex; justify-content: space-between; margin-top: .5rem; padding-top: .5rem; border-top: 1px solid var(--border); }

/* ---------- Cards, grid, stats ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: var(--space-5); margin-bottom: var(--space-5); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: var(--space-4); flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: var(--space-4); }
.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)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.split { display: grid; gap: var(--space-5); grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: var(--space-4); }
.bx-stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4) var(--space-5); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.bx-stat .lbl { color: var(--muted); font-size: var(--text-sm); display: flex; align-items: center; gap: .4rem; }
.bx-stat .val { font: 600 var(--text-2xl)/1.15 var(--font-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.bx-stat .row { display: flex; align-items: flex-end; justify-content: space-between; gap: .75rem; }
.bx-delta { display: inline-flex; align-items: center; gap: .2rem; font-size: var(--text-xs); font-weight: 600; padding: .1rem .45rem; border-radius: var(--radius-pill); }
.bx-delta.up { color: var(--success); background: var(--success-soft); } .bx-delta.down { color: var(--danger); background: var(--danger-soft); } .bx-delta.flat { color: var(--muted); background: var(--surface-2); }
.bx-stat .foot { font-size: var(--text-xs); color: var(--muted); display: flex; gap: .5rem; align-items: center; }

/* ---------- Badges, status pills, alerts, avatar ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .55rem; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 600; background: var(--surface-2); color: var(--text-soft); white-space: nowrap; line-height: 1.6; }
.badge .icon { width: 1em; height: 1em; }
.badge-brand { background: var(--brand-soft); color: var(--brand-text); }
.badge-success { background: var(--success-soft); color: var(--success); } .badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); } .badge-info { background: var(--info-soft); color: var(--info); }
.bx-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.bx-count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: var(--bg-elev); font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
.alert { display: flex; gap: .7rem; align-items: flex-start; padding: .75rem 1rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); margin-bottom: var(--space-4); }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 40%, transparent); }
.alert-danger, .alert-error { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.alert-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.alert-info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 40%, transparent); }
.alert > .icon { margin-top: .1rem; } .alert-success > .icon { color: var(--success); } .alert-danger > .icon { color: var(--danger); } .alert-warning > .icon { color: var(--warning); } .alert-info > .icon { color: var(--info); }
.alert-body { flex: 1; min-width: 0; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-text); display: inline-grid; place-items: center; font-weight: 600; font-size: var(--text-xs); flex: none; overflow: hidden; }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-base); } .avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.bx-avatars { display: inline-flex; } .bx-avatars .avatar { border: 2px solid var(--surface); margin-left: -8px; } .bx-avatars .avatar:first-child { margin-left: 0; }
.bx-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem; font-size: var(--text-sm); color: var(--muted); margin-bottom: .35rem; padding: 0; list-style: none; }
.bx-crumbs a { color: var(--muted); text-decoration: none; } .bx-crumbs a:hover { color: var(--text); text-decoration: underline; }
.bx-crumbs li + li::before { content: "/"; margin-right: .25rem; opacity: .5; }
.bx-crumbs [aria-current] { color: var(--text-soft); }
.breadcrumb { font-size: var(--text-sm); color: var(--muted); margin-bottom: .35rem; } .breadcrumb a { color: var(--muted); }

/* ---------- Progress, stepper, skeleton, empty ---------- */
.bx-progress { height: 8px; background: var(--surface-2); border-radius: var(--radius-pill); overflow: hidden; }
.bx-progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width var(--dur-slow) var(--ease); }
.bx-steps { display: flex; gap: 0; list-style: none; padding: 0; margin: 0 0 var(--space-5); counter-reset: s; }
.bx-steps li { flex: 1; display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: var(--text-sm); counter-increment: s; position: relative; }
.bx-steps li::before { content: counter(s); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--border-strong); font-weight: 600; font-size: var(--text-xs); flex: none; background: var(--surface); }
.bx-steps li:not(:last-child)::after { content: ""; flex: 1; height: 2px; background: var(--border); margin: 0 .5rem; min-width: 12px; }
.bx-steps li.done { color: var(--text); } .bx-steps li.done::before { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); content: "\2713"; }
.bx-steps li.done:not(:last-child)::after { background: var(--brand); }
.bx-steps li.current { color: var(--text); font-weight: 600; } .bx-steps li.current::before { border-color: var(--brand); color: var(--brand-text); box-shadow: var(--focus-ring); }
@media (max-width: 640px) { .bx-steps li span { display: none; } .bx-steps li.current span { display: inline; } }
.skeleton, .bx-skel { display: block; border-radius: 6px; min-height: 1em; background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 50%, var(--surface)) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: bx-shimmer 1.3s infinite; }
@keyframes bx-shimmer { to { background-position: -200% 0; } }
.empty, .bx-empty { text-align: center; padding: var(--space-8) var(--space-5); border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); }
.empty > .icon, .bx-empty > .icon { width: 2.75rem; height: 2.75rem; color: var(--muted); margin-bottom: .5rem; padding: .6rem; background: var(--surface-2); border-radius: 50%; box-sizing: content-box; }
.empty h2, .bx-empty h2 { font-size: var(--text-md); margin-bottom: .3rem; }
.empty p, .bx-empty p { color: var(--muted); max-width: 42ch; margin: 0 auto 1rem; }

/* ---------- Tabs, menus, tooltip, popover ---------- */
.bx-tabs, .tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: var(--space-5); overflow-x: auto; scrollbar-width: none; }
.bx-tabs [role=tab], .tabs a { padding: .6rem .9rem; min-height: 42px; display: inline-flex; align-items: center; gap: .4rem; background: none; border: 0; text-decoration: none; color: var(--muted); font: 500 var(--text-base) var(--font-body); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; cursor: pointer; }
.bx-tabs [role=tab]:hover, .tabs a:hover { color: var(--text); }
.bx-tabs [aria-selected="true"], .tabs a[aria-current="page"] { color: var(--brand-text); border-bottom-color: var(--brand); }
.bx-menu, .dropdown-menu { position: fixed; z-index: 3000; min-width: 200px; max-width: 320px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .3rem; animation: bx-pop var(--dur-fast) var(--ease); }
.dropdown { position: relative; display: inline-block; }
.bx-menu > a, .bx-menu > button, .bx-menu form button, .dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: .6rem; width: 100%; min-height: 36px; padding: .35rem .6rem; border: 0; background: none; color: var(--text); font: inherit; text-align: left; text-decoration: none; border-radius: 7px; cursor: pointer; }
.bx-menu > a:hover, .bx-menu > button:hover, .bx-menu form button:hover, .bx-menu .is-active, .dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-2); }
.bx-menu .danger, .bx-menu .danger .icon { color: var(--danger); }
.bx-menu hr, .dropdown-menu hr { margin: .3rem 0; }
.bx-menu .menu-head, .dropdown-menu .menu-head { padding: .5rem .6rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; }
.bx-menu .menu-label { padding: .4rem .6rem .2rem; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.bx-menu .check-row { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; border-radius: 7px; cursor: pointer; }
.bx-menu .check-row:hover { background: var(--surface-2); }
.bx-tip { position: fixed; z-index: 4000; background: var(--text); color: var(--bg); padding: .3rem .55rem; border-radius: 6px; font-size: var(--text-xs); max-width: 260px; pointer-events: none; animation: bx-pop var(--dur-fast) var(--ease); }
.bx-popover { position: fixed; z-index: 3000; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: var(--space-4); max-width: 320px; animation: bx-pop var(--dur-fast) var(--ease); }
@keyframes bx-pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Overlays: dialog, modal, drawer ---------- */
.bx-layer { position: fixed; inset: 0; z-index: 2500; display: grid; place-items: center; padding: var(--space-4); background: var(--scrim); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: bx-fade var(--dur) var(--ease); }
.bx-layer.is-closing { opacity: 0; transition: opacity var(--dur-fast); }
.bx-dialog { width: min(420px, 100%); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: var(--space-6) var(--space-5) var(--space-5); text-align: center; animation: bx-zoom var(--dur-slow) var(--ease); outline: 0; }
.bx-dialog .bx-dlg-icon { width: 64px; height: 64px; margin: 0 auto var(--space-4); border-radius: 50%; display: grid; place-items: center; }
.bx-dialog .bx-dlg-icon svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 48; stroke-dashoffset: 48; animation: bx-draw .5s .15s var(--ease) forwards; }
.bx-dlg-success { color: var(--success); background: var(--success-soft); } .bx-dlg-danger, .bx-dlg-error { color: var(--danger); background: var(--danger-soft); }
.bx-dlg-warning { color: var(--warning); background: var(--warning-soft); } .bx-dlg-info, .bx-dlg-question { color: var(--info); background: var(--info-soft); }
.bx-dialog h2 { font-size: var(--text-lg); margin-bottom: .4rem; }
.bx-dialog .bx-dlg-text { color: var(--muted); margin: 0 0 var(--space-4); overflow-wrap: anywhere; }
.bx-dialog .bx-dlg-input { text-align: left; margin-bottom: var(--space-4); }
.bx-dialog .bx-dlg-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: var(--space-4); }
.bx-dialog .bx-dlg-actions .btn { min-width: 110px; }
.bx-dialog .bx-dlg-error-msg { color: var(--danger); font-size: var(--text-sm); margin-top: .35rem; min-height: 1.2em; }
@keyframes bx-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bx-zoom { from { opacity: 0; transform: scale(.92) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes bx-draw { to { stroke-dashoffset: 0; } }
.bx-modal { width: min(560px, 100%); max-height: min(88vh, 900px); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: bx-zoom var(--dur-slow) var(--ease); outline: 0; }
.bx-modal.sm { width: min(400px, 100%); } .bx-modal.lg { width: min(820px, 100%); } .bx-modal.xl { width: min(1100px, 100%); }
.bx-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); flex: none; }
.bx-head h2 { margin: 0; font-size: var(--text-lg); }
.bx-body { padding: var(--space-5); overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.bx-foot { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .5rem; flex-wrap: wrap; flex: none; background: var(--surface); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.bx-layer.is-drawer { place-items: stretch end; padding: 0; }
.bx-layer.is-drawer.left { place-items: stretch start; }
.bx-drawer { width: min(480px, 100%); height: 100%; display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: bx-slide var(--dur-slow) var(--ease); outline: 0; }
.bx-drawer.lg { width: min(720px, 100%); }
.is-drawer.left .bx-drawer { border-left: 0; border-right: 1px solid var(--border); animation-name: bx-slide-l; }
@keyframes bx-slide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bx-slide-l { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bx-sheet { from { transform: translateY(100%); } to { transform: none; } }
@media (max-width: 640px) {
  .bx-layer { align-items: end; padding: 0; }
  .bx-layer:not(.is-dialog) { place-items: end stretch; }
  .bx-modal, .bx-drawer { width: 100% !important; max-height: 92vh; height: auto; border-radius: var(--radius-lg) var(--radius-lg) 0 0; border: 0; border-top: 1px solid var(--border); animation: bx-sheet var(--dur-slow) var(--ease); }
  .bx-layer.is-drawer { place-items: end stretch; }
  .bx-drawer { max-height: 92vh; }
  .bx-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--border-strong); }
  .bx-head { position: relative; padding-top: var(--space-5); }
  .bx-foot { padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom)); }
  .bx-dialog { margin-bottom: var(--space-4); }
  .bx-layer.is-dialog { align-items: center; padding: var(--space-4); }
}

/* ---------- Toasts ---------- */
.bx-toasts { position: fixed; z-index: 5000; right: var(--space-4); bottom: var(--space-4); display: flex; flex-direction: column-reverse; gap: .5rem; width: min(380px, calc(100vw - 2rem)); pointer-events: none; }
.bx-toast { pointer-events: auto; position: relative; overflow: hidden; display: flex; gap: .7rem; align-items: flex-start; padding: .8rem .9rem; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); animation: bx-toast-in var(--dur-slow) var(--ease); }
.bx-toast.is-out { opacity: 0; transform: translateX(16px); transition: opacity var(--dur), transform var(--dur); }
.bx-toast > .icon { margin-top: .1rem; width: 1.2em; height: 1.2em; }
.bx-toast-success > .icon { color: var(--success); } .bx-toast-error > .icon, .bx-toast-danger > .icon { color: var(--danger); } .bx-toast-warning > .icon { color: var(--warning); } .bx-toast-info > .icon { color: var(--info); }
.bx-toast .t-body { flex: 1; min-width: 0; } .bx-toast .t-title { font-weight: 600; }
.bx-toast .t-msg { color: var(--text-soft); overflow-wrap: anywhere; }
.bx-toast .t-act { border: 0; background: none; color: var(--brand-text); font: 600 var(--text-sm) var(--font-body); cursor: pointer; padding: .1rem .3rem; border-radius: 4px; }
.bx-toast .t-x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px; border-radius: 4px; display: grid; }
.bx-toast .t-bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--brand); transform-origin: left; animation: bx-bar linear forwards; }
.bx-toast-error .t-bar, .bx-toast-danger .t-bar { background: var(--danger); } .bx-toast-warning .t-bar { background: var(--warning); } .bx-toast-info .t-bar { background: var(--info); } .bx-toast-success .t-bar { background: var(--success); }
.bx-toast:hover .t-bar { animation-play-state: paused; }
@keyframes bx-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes bx-toast-in { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) { .bx-toasts { left: var(--space-3); right: var(--space-3); width: auto; bottom: calc(72px + env(safe-area-inset-bottom)); } }

/* ---------- Table (bx-table enhancement) ---------- */
.bx-tw { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: var(--space-5); position: relative; }
.bx-tw-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.bx-tw-search { position: relative; flex: 1 1 220px; max-width: 340px; }
.bx-tw-search .icon { position: absolute; left: .65rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.bx-tw-search input { width: 100%; min-height: 34px; padding: 0 .75rem 0 2.1rem; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); font: inherit; }
.bx-tw-search input:focus { outline: 0; border-color: var(--brand); box-shadow: var(--focus-ring); background: var(--surface); }
.bx-tw-spacer { flex: 1; }
.bx-tw-bulk { display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem; background: var(--brand-soft); border-bottom: 1px solid var(--border); color: var(--brand-text); font-weight: 600; flex-wrap: wrap; }
.bx-tw-scroll { overflow: auto; max-height: var(--bx-table-h, none); }
.bx-tw table, table.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.bx-tw th, .bx-tw td, .table th, .table td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.bx-tw[data-density="compact"] th, .bx-tw[data-density="compact"] td { padding: .35rem .75rem; font-size: var(--text-sm); }
.bx-tw[data-density="comfortable"] th, .bx-tw[data-density="comfortable"] td { padding: .85rem 1rem; }
.bx-tw thead th, .table th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; white-space: nowrap; user-select: none; }
.bx-tw th[data-sort] { cursor: pointer; } .bx-tw th[data-sort]:hover { color: var(--text); }
.bx-tw th .sort { display: inline-block; width: .8em; margin-left: .25rem; opacity: .35; }
.bx-tw th[aria-sort="ascending"] .sort::after { content: "\25B2"; opacity: 1; } .bx-tw th[aria-sort="descending"] .sort::after { content: "\25BC"; }
.bx-tw th[aria-sort="ascending"], .bx-tw th[aria-sort="descending"] { color: var(--brand-text); } .bx-tw th[aria-sort] .sort { opacity: 1; }
.bx-tw th:not([aria-sort]) .sort::after { content: "\21C5"; }
.bx-tw tbody tr { transition: background var(--dur-fast); } .bx-tw tbody tr:hover, .table tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.bx-tw tbody tr.is-selected { background: var(--brand-soft); }
.bx-tw tbody tr:last-child td { border-bottom: 0; }
.bx-tw .num, .bx-tw th.num, .table .num { text-align: right; font-variant-numeric: tabular-nums; }
.bx-tw td.actions, .table td.actions { text-align: right; white-space: nowrap; width: 1%; }
.bx-tw .col-check { width: 40px; padding-right: 0; }
.bx-tw input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.bx-tw-foot { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; justify-content: space-between; padding: .55rem .75rem; border-top: 1px solid var(--border); color: var(--muted); font-size: var(--text-sm); }
.bx-pager { display: inline-flex; gap: .25rem; align-items: center; }
.bx-pager button { min-width: 32px; height: 32px; border: 1px solid transparent; background: none; border-radius: 8px; color: var(--text-soft); font: inherit; cursor: pointer; font-variant-numeric: tabular-nums; }
.bx-pager button:hover:not([disabled]) { background: var(--surface-2); } .bx-pager button[aria-current="page"] { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; } .bx-pager button[disabled] { opacity: .4; cursor: default; }
.bx-tw-empty { padding: var(--space-8) var(--space-5); text-align: center; color: var(--muted); }
.bx-tw-loading { position: absolute; inset: 0; background: color-mix(in srgb, var(--surface) 70%, transparent); display: grid; place-items: center; z-index: 4; border-radius: var(--radius); }
.bx-tw .bx-sel { min-height: 32px; padding: 0 1.9rem 0 .6rem; font-size: var(--text-sm); width: auto; }
@media (max-width: 640px) {
  .bx-tw.is-cards table, .bx-tw.is-cards tbody, .bx-tw.is-cards tr, .bx-tw.is-cards td { display: block; width: 100%; }
  .bx-tw.is-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
  .bx-tw.is-cards tbody tr { padding: .6rem .9rem; border-bottom: 1px solid var(--border); position: relative; }
  .bx-tw.is-cards td { border: 0; padding: .2rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right !important; }
  .bx-tw.is-cards td::before { content: attr(data-label); color: var(--muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; text-align: left; flex: none; padding-top: .15rem; }
  .bx-tw.is-cards td.col-check { position: absolute; top: .6rem; right: .6rem; width: auto; }
  .bx-tw.is-cards td.col-check::before, .bx-tw.is-cards td[data-label=""]::before { display: none; }
  .bx-tw.is-cards td.actions { justify-content: flex-end; }
  .bx-tw-search { max-width: none; flex-basis: 100%; }
}

/* ---------- Charts ---------- */
.bx-chart { width: 100%; }
.bx-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.bx-chart .grid line { stroke: var(--border); stroke-width: 1; } .bx-chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font-body); }
.bx-spark { display: inline-block; width: 96px; height: 32px; }
.bx-legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .5rem; font-size: var(--text-sm); color: var(--text-soft); }
.bx-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; }
.bx-chart-tip { position: fixed; z-index: 4000; background: var(--text); color: var(--bg); padding: .3rem .55rem; border-radius: 6px; font-size: var(--text-xs); pointer-events: none; white-space: nowrap; }

/* ---------- Command palette ---------- */
.bx-layer.is-palette { place-items: start center; padding-top: 12vh; }
.bx-pal { width: min(600px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; animation: bx-zoom var(--dur) var(--ease); }
.bx-pal-in { display: flex; align-items: center; gap: .6rem; padding: .85rem 1rem; border-bottom: 1px solid var(--border); color: var(--muted); }
.bx-pal-in input { flex: 1; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: var(--text-md); }
.bx-pal-list { max-height: 50vh; overflow-y: auto; padding: .4rem; }
.bx-pal-group { padding: .5rem .6rem .2rem; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.bx-pal-item { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 8px; color: var(--text); text-decoration: none; cursor: pointer; }
.bx-pal-item.is-active { background: var(--brand-soft); color: var(--brand-text); }
.bx-pal-item small { margin-left: auto; color: var(--muted); }
.bx-pal-foot { display: flex; gap: 1rem; padding: .5rem 1rem; border-top: 1px solid var(--border); color: var(--muted); font-size: var(--text-xs); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; } .bx-dialog .bx-dlg-icon svg { stroke-dashoffset: 0; } }
@media print { .bx-toasts, .bx-layer, .bx-tw-bar, .bx-tw-foot { display: none !important; } }
