/* ============================================================================
   VEGA design system — the single source of truth for all VEGA styling.

   Enterprise UI: flat, dense, functional. Palette is light-pink surfaces with
   a violet accent (deep-violet sidebar). No gradients, glows, blur, or
   decorative animation. Transitions are limited to <=120ms on hover/focus.
   HTMX only — no bespoke JavaScript, no AJAX framework.

   RULE: no page-level <style> blocks and no inline styles. Every visual is a
   class defined here. Add new components to this file, never to a page.

   Sections:
     1.  Design tokens (:root, dark theme)
     2.  Reset / base / typography
     3.  Layout: container, grid, stack, cluster
     4.  App shell (sidebar + topbar + content)
     5.  Buttons
     6.  Forms
     7.  Tables
     8.  Cards / panels
     9.  Badges / tags / status
     10. Alerts
     11. Tabs
     12. Breadcrumbs
     13. Pagination
     14. Toolbar / button group
     15. Dropdown menu (CSS-only)
     16. Dialog / modal (native <dialog>)
     17. Tooltip
     18. Key-value / definition list
     19. Empty state
     20. HTMX helpers / spinner
     21. Utilities
     22. Responsive
   ============================================================================ */

/* ===== 1. Design tokens =================================================== */
:root {
    /* Surfaces — light pink base */
    --bg-app: #fbf2f7;         /* page background (light pink) */
    --bg-surface: #ffffff;     /* panels, cards, table rows */
    --bg-subtle: #f6e8f0;      /* zebra rows, disabled fields, hover fills */
    --bg-inset: #faf1f6;       /* code, wells */
    --bg-sidebar: #3a2a4d;     /* deep violet rail */
    --bg-topbar: #ffffff;

    /* Text */
    --text: #241a29;           /* primary body text */
    --text-muted: #6b5c72;     /* secondary / labels */
    --text-faint: #9a8ca0;     /* placeholders, disabled */
    --text-invert: #f7eefb;    /* text on dark surfaces */

    /* Borders */
    --border: #ecd9e5;
    --border-strong: #d6bccb;
    --border-focus: var(--accent);

    /* Brand + semantic — violet accent on pink */
    --accent: #7c3aed;         /* violet */
    --accent-hover: #6d28d9;
    --accent-soft: #f2e9fc;    /* tinted background for accent surfaces */
    --info: #1d6fb8;    --info-soft: #e6f0f8;
    --success: #1f7a3d; --success-soft: #e6f2ea;
    --warning: #b7791f; --warning-soft: #fbf1e0;
    --danger: #c0392b;  --danger-soft: #fbeae8;

    /* Radius */
    --radius-sm: 3px;
    --radius: 5px;
    --radius-lg: 8px;

    /* Shadows (restrained) */
    --shadow-sm: 0 1px 2px rgba(16, 24, 32, 0.08);
    --shadow: 0 2px 6px rgba(16, 24, 32, 0.10);
    --shadow-pop: 0 6px 20px rgba(16, 24, 32, 0.16);

    /* Typography */
    --font-sans: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Oxygen, Ubuntu, sans-serif;
    --font-mono: 'Cascadia Code', 'Consolas', 'Monaco', monospace;
    --fs-xs: 0.75rem;
    --fs-sm: 0.825rem;
    --fs-base: 0.9rem;
    --fs-md: 1rem;
    --fs-lg: 1.15rem;
    --fs-xl: 1.4rem;
    --fs-2xl: 1.75rem;

    /* Spacing scale — 50% larger than the base scale (bigger paddings/margins,
       fonts unchanged). Base values were 0.25/0.5/0.75/1/1.5/2/3rem. */
    --sp-1: 0.375rem;
    --sp-2: 0.75rem;
    --sp-3: 1.125rem;
    --sp-4: 1.5rem;
    --sp-5: 2.25rem;
    --sp-6: 3rem;
    --sp-8: 4.5rem;

    /* Layout dims */
    --sidebar-w: 145px;
    --topbar-h: 42px;

    --z-dropdown: 100;
    --z-sticky: 200;
    --z-dialog: 300;
    --z-tooltip: 400;
}

/* Opt-in dark theme: <html data-theme="dark"> */
:root[data-theme="dark"] {
    --bg-app: #1a121f;
    --bg-surface: #241a2b;
    --bg-subtle: #2e2136;
    --bg-inset: #1e1524;
    --bg-sidebar: #140d1a;
    --bg-topbar: #241a2b;
    --text: #efe6f2;
    --text-muted: #b6a5bf;
    --text-faint: #7d6b86;
    --text-invert: #efe6f2;
    --border: #362a3f;
    --border-strong: #48394f;
    --accent: #a970f5;
    --accent-hover: #b98af7;
    --accent-soft: #2c1c3d;
    --info-soft: #10283d;
    --success-soft: #16301f;
    --warning-soft: #33280f;
    --danger-soft: #331815;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    --shadow-pop: 0 6px 20px rgba(0, 0, 0, 0.6);
}

/* ===== 2. Reset / base / typography ======================================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 20px; }

body {
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.5;
    color: var(--text);
    background: var(--bg-app);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 600; line-height: 1.25; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
h5, h6 { font-size: var(--fs-base); }
p { margin: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

small, .text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }

hr { border: none; border-top: 1px solid var(--border); margin: var(--sp-4) 0; }

code, kbd, samp { font-family: var(--font-mono); font-size: 0.85em; }
code {
    background: var(--bg-inset); border: 1px solid var(--border);
    padding: 0.1rem 0.35rem; border-radius: var(--radius-sm);
}
.code-block {
    background: var(--bg-inset); border: 1px solid var(--border);
    border-radius: var(--radius); padding: var(--sp-4);
    overflow-x: auto; margin: var(--sp-3) 0;
}
.code-block code { background: none; border: none; padding: 0; }
kbd {
    background: var(--bg-subtle); border: 1px solid var(--border-strong);
    border-bottom-width: 2px; border-radius: var(--radius-sm);
    padding: 0.05rem 0.35rem; font-size: 0.8em;
}

/* ===== 3. Layout ========================================================== */
.container { max-width: 1360px; margin: 0 auto; padding: var(--sp-5) var(--sp-5); }
.container-narrow { max-width: 720px; margin: 0 auto; padding: var(--sp-5); }

/* Auto-fit card grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-4); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); }

/* Vertical stack with consistent gap */
.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-6); }

/* Horizontal cluster that wraps */
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.cluster-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); }

/* Page header: title + actions */
.vg-page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-3); margin-bottom: var(--sp-5); flex-wrap: wrap;
}
.vg-page-head .vg-page-title { display: flex; flex-direction: column; gap: 0.15rem; }
.vg-page-head .vg-page-title small { color: var(--text-muted); }
.vg-page-head .vg-page-actions { display: flex; align-items: center; gap: var(--sp-2); }

.vg-toolbar { margin-bottom: var(--sp-4); }
.vg-toolbar .vg-search { max-width: 22rem; }

/* ===== 4. App shell ======================================================= */
.vg-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: var(--topbar-h) 1fr; grid-template-areas: "brand topbar" "sidebar main"; min-height: 100vh; }

.vg-brand {
    grid-area: brand; background: var(--bg-sidebar); color: var(--text-invert);
    display: flex; align-items: center; gap: var(--sp-2);
    padding: 0 var(--sp-4); font-weight: 700; letter-spacing: 0.14em; font-size: var(--fs-md);
}

.vg-topbar {
    grid-area: topbar; background: var(--bg-topbar); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 var(--sp-5); gap: var(--sp-4);
}
.vg-topbar .vg-user { display: flex; align-items: center; gap: var(--sp-3); color: var(--text-muted); font-size: var(--fs-sm); }

.vg-sidebar {
    grid-area: sidebar; background: var(--bg-sidebar); color: var(--text-invert);
    padding: var(--sp-3) 0; overflow-y: auto;
}
.vg-nav-section { padding: var(--sp-3) var(--sp-4) var(--sp-1); font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.08em; color: #7d8894; }
.vg-nav-item {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-4); color: #c3ccd5; font-size: var(--fs-base);
    border-left: 3px solid transparent;
}
.vg-nav-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.vg-nav-item.active { background: rgba(255, 255, 255, 0.09); color: #fff; border-left-color: var(--accent); font-weight: 600; }

.vg-main { grid-area: main; overflow-y: auto; }
.vg-main > .container { padding-top: var(--sp-5); }

/* Site-wide top menu (used on every page, both auth states) */
.vg-appbar {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
    height: var(--topbar-h); padding: 0 var(--sp-5);
    background: var(--bg-topbar); border-bottom: 1px solid var(--border);
}
.vg-appbar .vg-logo { font-weight: 700; letter-spacing: 0.14em; color: var(--accent); font-size: var(--fs-md); text-decoration: none; }
.vg-appbar .vg-logo:hover { text-decoration: none; }
.vg-appbar-actions { display: flex; align-items: center; gap: var(--sp-3); }
.vg-appbar-actions form { display: flex; margin: 0; }

/* Logged-in indicator: dot + name */
.vg-userchip { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-muted); }
.vg-userchip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.vg-userchip .name { color: var(--text); font-weight: 600; }

/* Authenticated body: left nav panel + content, sits under the top menu */
.vg-layout { display: flex; align-items: stretch; min-height: calc(100vh - var(--topbar-h)); }
.vg-layout .vg-sidebar { flex: 0 0 var(--sidebar-w); }
.vg-layout .vg-main { flex: 1; min-width: 0; }

/* ===== 5. Buttons ========================================================= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    padding: 0.4rem 0.85rem; font-size: var(--fs-base); font-family: inherit; font-weight: 500;
    line-height: 1.4; color: var(--text); background: var(--bg-surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    cursor: pointer; white-space: nowrap; transition: background 0.12s, border-color 0.12s;
    text-decoration: none;
}
.btn:hover { background: var(--bg-subtle); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled, .btn.disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.94); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--text); }
.btn-link { background: transparent; border-color: transparent; color: var(--accent); padding: 0.4rem 0.25rem; }
.btn-link:hover { background: transparent; text-decoration: underline; }

.btn-sm { padding: 0.2rem 0.55rem; font-size: var(--fs-sm); }
.btn-lg { padding: 0.55rem 1.2rem; font-size: var(--fs-md); }
.btn-block { display: flex; width: 100%; }

/* ===== 6. Forms =========================================================== */
.form-control,
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]),
textarea, select {
    width: 100%; padding: 0.4rem 0.55rem; font-family: inherit; font-size: var(--fs-base);
    color: var(--text); background: var(--bg-surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius); line-height: 1.4;
}
textarea { min-height: 5rem; resize: vertical; }
select { appearance: none; padding-right: 1.75rem;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%235c6773'/></svg>");
    background-repeat: no-repeat; background-position: right 0.6rem center; }
.form-control:focus, input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 2px var(--accent-soft);
}
.form-control:disabled, input:disabled, textarea:disabled, select:disabled { background: var(--bg-subtle); color: var(--text-faint); cursor: not-allowed; }
::placeholder { color: var(--text-faint); }
.form-control.input-sm { padding: 0.2rem 0.4rem; font-size: var(--fs-sm); }

/* Field wrapper: label + control + help/error */
.vg-field { margin-bottom: var(--sp-3); }
.vg-field > label, label.vg-label { display: block; margin-bottom: 0.2rem; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
.vg-field .field-help { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 0.2rem; }
.vg-field .field-error { font-size: var(--fs-xs); color: var(--danger); margin-top: 0.2rem; }
.vg-field.has-error .form-control, .vg-field.has-error input, .vg-field.has-error select, .vg-field.has-error textarea { border-color: var(--danger); }

/* Required marker */
.vg-label .req, label .req { color: var(--danger); margin-left: 0.15rem; }

/* Structured SkuPart editor: one labeled input per segment (e.g. Розмір / Вік / Зріст), inline in a size row */
.vg-skupart { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.vg-skupart-seg { display: flex; flex-direction: column; gap: 0.15rem; }
.vg-skupart-seg .vg-skupart-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); }
.vg-skupart-seg .form-control { width: 7rem; }

/* Inline horizontal form row (label beside control) */
.vg-form-row { display: grid; grid-template-columns: 180px 1fr; gap: var(--sp-3); align-items: start; margin-bottom: var(--sp-3); }
.vg-form-row > label { padding-top: 0.4rem; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }

/* Checkbox / radio rows */
.vg-check { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-base); cursor: pointer; }
.vg-check input { width: auto; margin: 0; }

/* Input group: text + button glued together */
.input-group { display: flex; }
.input-group > .form-control { border-radius: var(--radius) 0 0 var(--radius); }
.input-group > .btn { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }

/* Toggle switch */
.vg-switch { position: relative; display: inline-block; width: 38px; height: 20px; }
.vg-switch input { opacity: 0; width: 0; height: 0; }
.vg-switch .slider { position: absolute; inset: 0; background: var(--border-strong); border-radius: 20px; transition: background 0.12s; }
.vg-switch .slider::before { content: ""; position: absolute; height: 14px; width: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.12s; }
.vg-switch input:checked + .slider { background: var(--accent); }
.vg-switch input:checked + .slider::before { transform: translateX(18px); }

/* ===== 7. Tables ========================================================== */
.vg-table { width: 100%; border-collapse: collapse; background: var(--bg-surface); font-size: var(--fs-base); }
.vg-table th, .vg-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.vg-table thead th {
    color: var(--text-muted); font-weight: 600; font-size: var(--fs-xs);
    text-transform: uppercase; letter-spacing: 0.04em; background: var(--bg-subtle);
    border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.vg-table tbody tr:hover { background: var(--bg-subtle); }
.vg-table.striped tbody tr:nth-child(even) { background: var(--bg-inset); }
.vg-table.striped tbody tr:nth-child(even):hover { background: var(--bg-subtle); }
.vg-table.compact th, .vg-table.compact td { padding: 0.3rem 0.5rem; font-size: var(--fs-sm); }
.vg-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.vg-table .row-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; }

/* Sortable header (HTMX-driven; arrow is decorative) */
.vg-table th.sortable { cursor: pointer; user-select: none; }
.vg-table th.sortable::after { content: "\2195"; opacity: 0.35; margin-left: 0.3rem; }
.vg-table th.sort-asc::after { content: "\2191"; opacity: 1; }
.vg-table th.sort-desc::after { content: "\2193"; opacity: 1; }

/* Sticky header inside a scroll region */
.vg-table-scroll { max-height: 70vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.vg-table-scroll .vg-table thead th { position: sticky; top: 0; z-index: var(--z-sticky); }

/* ===== 8. Cards / panels ================================================== */
.card, .panel {
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
}
.card { padding: var(--sp-5); margin-bottom: var(--sp-4); }
.card > h2, .card > h3 { margin-bottom: var(--sp-3); }

/* Panel with distinct header/body/footer */
.panel { margin-bottom: var(--sp-4); overflow: hidden; }
.panel-head { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); background: var(--bg-inset); font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.panel-body { padding: var(--sp-4); }
.panel-body.flush { padding: 0; }   /* for full-bleed tables */
.panel-foot { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); background: var(--bg-inset); }

/* Stat tile */
.stat { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--sp-4); }
.stat .stat-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.stat .stat-value { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.1; margin-top: 0.2rem; font-variant-numeric: tabular-nums; }
.stat .stat-sub { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 0.2rem; }

/* ===== 9. Badges / tags / status ========================================= */
.badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    padding: 0.1rem 0.5rem; font-size: var(--fs-xs); font-weight: 600; line-height: 1.5;
    border-radius: 10px; background: var(--bg-subtle); color: var(--text-muted);
}
.badge-accent  { background: var(--accent-soft);  color: var(--accent); }
.badge-info    { background: var(--info-soft);     color: var(--info); }
.badge-success { background: var(--success-soft);  color: var(--success); }
.badge-warning { background: var(--warning-soft);  color: var(--warning); }
.badge-danger  { background: var(--danger-soft);   color: var(--danger); }

/* Square tag (filter chips, labels) */
.tag { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.1rem 0.45rem; font-size: var(--fs-xs); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); color: var(--text-muted); }

/* Status dot + label (static, no animation) */
.status { display: inline-flex; align-items: center; gap: 0.4rem; font-size: var(--fs-sm); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.status.ok::before      { background: var(--success); }
.status.warn::before    { background: var(--warning); }
.status.err::before     { background: var(--danger); }
.status.info::before    { background: var(--info); }
.status.idle::before    { background: var(--text-faint); }

/* ===== 10. Alerts ========================================================= */
.alert { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius); background: var(--bg-surface); font-size: var(--fs-base); margin-bottom: var(--sp-4); }
.alert-info    { border-left-color: var(--info);    background: var(--info-soft); }
.alert-success { border-left-color: var(--success); background: var(--success-soft); }
.alert-warning { border-left-color: var(--warning); background: var(--warning-soft); }
.alert-danger  { border-left-color: var(--danger);  background: var(--danger-soft); }
.alert .alert-title { font-weight: 600; }

/* Utility: force-hide (beats display rules like .alert{display:flex}, which override the [hidden] attribute) */
.is-hidden { display: none !important; }

/* Emerald monitor: recent-events log */
.vg-em-log { list-style: none; margin: 0; padding: 0; max-height: 16rem; overflow: auto; font-family: var(--font-mono, monospace); font-size: var(--fs-sm); }
.vg-em-log li { padding: 0.15rem 0; border-bottom: 1px solid var(--border); white-space: nowrap; }

/* ===== 11. Tabs =========================================================== */
.vg-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); margin-bottom: var(--sp-4); }
.vg-tab { padding: var(--sp-2) var(--sp-4); font-size: var(--fs-base); color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; }
.vg-tab:hover { color: var(--text); text-decoration: none; }
.vg-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ===== 12. Breadcrumbs ==================================================== */
.vg-breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--sp-4); }
.vg-breadcrumb a { color: var(--text-muted); }
.vg-breadcrumb a:hover { color: var(--accent); }
.vg-breadcrumb li { list-style: none; display: inline-flex; align-items: center; gap: 0.4rem; }
.vg-breadcrumb li + li::before { content: "/"; color: var(--text-faint); }
.vg-breadcrumb .current { color: var(--text); font-weight: 600; }

/* ===== 13. Pagination ===================================================== */
.vg-pager { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.vg-pager a, .vg-pager span { padding: 0.3rem 0.7rem; font-size: var(--fs-sm); color: var(--text); border-right: 1px solid var(--border); }
.vg-pager a:last-child, .vg-pager span:last-child { border-right: none; }
.vg-pager a:hover { background: var(--bg-subtle); text-decoration: none; }
.vg-pager .active { background: var(--accent); color: #fff; }
.vg-pager .disabled { color: var(--text-faint); pointer-events: none; }

/* ===== 14. Toolbar / button group ========================================= */
.vg-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); padding: var(--sp-2) 0; margin-bottom: var(--sp-3); }
.vg-toolbar .spacer { flex: 1; }

.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; border-right-width: 0; }
.btn-group > .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.btn-group > .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-right-width: 1px; }

/* ===== 15. Dropdown menu (CSS-only, uses <details>) ======================= */
.vg-dropdown { position: relative; display: inline-block; }
.vg-dropdown > summary { list-style: none; cursor: pointer; }
.vg-dropdown > summary::-webkit-details-marker { display: none; }
.vg-menu {
    position: absolute; top: calc(100% + 4px); left: 0; min-width: 180px; z-index: var(--z-dropdown);
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-pop); padding: var(--sp-1) 0;
}
.vg-menu.right { left: auto; right: 0; }
.vg-menu a, .vg-menu button {
    display: flex; align-items: center; gap: var(--sp-2); width: 100%; text-align: left;
    padding: 0.4rem var(--sp-4); font-size: var(--fs-base); color: var(--text);
    background: none; border: none; cursor: pointer;
}
.vg-menu a:hover, .vg-menu button:hover { background: var(--bg-subtle); text-decoration: none; }
.vg-menu .divider { height: 1px; background: var(--border); margin: var(--sp-1) 0; }

/* ===== 16. Dialog / modal (native <dialog>) =============================== */
dialog.vg-dialog {
    border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 0;
    box-shadow: var(--shadow-pop); background: var(--bg-surface); color: var(--text);
    max-width: 520px; width: calc(100% - 2rem);
}
dialog.vg-dialog::backdrop { background: rgba(16, 24, 32, 0.45); }
.vg-dialog .dialog-head { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.vg-dialog .dialog-body { padding: var(--sp-4); }
.vg-dialog .dialog-foot { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--sp-2); }

/* ===== 17. Tooltip (CSS-only, data-tip) =================================== */
[data-tip] { position: relative; }
[data-tip]:hover::after {
    content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: #1a2027; color: #fff; padding: 0.25rem 0.5rem; border-radius: var(--radius-sm);
    font-size: var(--fs-xs); white-space: nowrap; z-index: var(--z-tooltip); box-shadow: var(--shadow);
}

/* ===== 18. Key-value / definition list =================================== */
.vg-kv { display: grid; grid-template-columns: max-content 1fr; align-items: center; gap: 0.35rem var(--sp-4); font-size: var(--fs-base); }
.vg-kv dt { color: var(--text-muted); font-weight: 600; }
.vg-kv dd { margin: 0; }

/* ===== 19. Empty state ==================================================== */
.vg-empty { text-align: center; padding: var(--sp-8) var(--sp-4); color: var(--text-muted); }
.vg-empty h3 { color: var(--text); margin-bottom: var(--sp-2); }

/* ===== 20. HTMX helpers / spinner ======================================== */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }
.spinner {
    display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-strong);
    border-top-color: var(--accent); border-radius: 50%; animation: vg-spin 0.6s linear infinite;
}
@keyframes vg-spin { to { transform: rotate(360deg); } }
/* Fade a swap target while its request is in flight */
.htmx-request.vg-busy { opacity: 0.5; pointer-events: none; }

/* ===== Catalog (per-space product cards) ================================= */
/* Collapsible category group (native <details>, collapsed by default, CSS-only +/- toggle). */
.vg-cat { border-bottom: 1px solid var(--border); }
.vg-cat-heading {
    display: flex; align-items: center; gap: var(--sp-2);
    font-size: var(--fs-lg); font-weight: 600;
    padding: var(--sp-3) var(--sp-1); cursor: pointer; user-select: none;
    list-style: none;
}
.vg-cat-heading::-webkit-details-marker { display: none; }   /* hide default disclosure triangle */
.vg-cat-heading::marker { content: ""; }
.vg-cat-heading:hover, .vg-cat[open] > .vg-cat-heading { color: var(--accent); }
.vg-cat-name { margin-right: auto; }
.vg-cat-toggle { display: inline-flex; justify-content: center; width: 1em; font-weight: 700; color: var(--accent); }
.vg-cat-toggle::before { content: "+"; }
.vg-cat[open] > .vg-cat-heading .vg-cat-toggle::before { content: "\2212"; }  /* minus sign */
.vg-cat-body { padding: 0 var(--sp-1) var(--sp-5); }
.vg-cat-loading { padding: var(--sp-3) 0; color: var(--text-muted); display: inline-flex; align-items: center; gap: var(--sp-2); }

/* Fixed max column width so sparse categories don't stretch cards (and their images) huge. */
.vg-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 200px)); gap: var(--sp-4); justify-content: start; }

.vg-prod-card {
    display: flex; flex-direction: column; background: var(--bg-surface);
    border: 1px solid var(--border); border-radius: var(--radius-lg);
    overflow: hidden; box-shadow: var(--shadow-sm); transition: box-shadow 0.12s;
    color: inherit; text-decoration: none;
}
.vg-prod-card:hover { box-shadow: var(--shadow); text-decoration: none; }
.vg-prod-deleted { opacity: 0.55; }
.vg-prod-deleted:hover { opacity: 0.8; }

.vg-prod-thumb { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; background: var(--bg-subtle); }
.vg-prod-noimg { display: flex; align-items: center; justify-content: center; color: var(--text-faint); font-size: var(--fs-sm); }

.vg-prod-body { padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-1); }
.vg-prod-ref { font-weight: 600; font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--text); }
.vg-prod-price { font-size: var(--fs-lg); font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.vg-prod-dates { display: grid; grid-template-columns: max-content 1fr; gap: 0.1rem var(--sp-2); margin-top: var(--sp-1); font-size: var(--fs-xs); color: var(--text-muted); }
.vg-prod-dates dt { color: var(--text-faint); }
.vg-prod-dates dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ===== Product detail page ============================================== */
.vg-product-top { display: grid; grid-template-columns: 360px 1fr; gap: var(--sp-5); align-items: start; margin-bottom: var(--sp-5); }
.vg-product-side > .panel:last-child { margin-bottom: 0; }
.vg-gallery { display: flex; flex-direction: column; gap: var(--sp-3); }
.vg-gallery-main {
    width: 100%; aspect-ratio: 1 / 1; object-fit: contain;
    background: var(--bg-inset); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.vg-gallery-main.vg-prod-noimg { display: flex; align-items: center; justify-content: center; color: var(--text-faint); }
.vg-gallery-strip { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.vg-gallery-thumb {
    width: 64px; height: 64px; object-fit: cover;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-subtle);
}
.vg-gallery-thumb:hover { border-color: var(--accent); }
.vg-desc { white-space: pre-line; }
.vg-desc + .vg-desc { margin-top: var(--sp-3); }

@media (max-width: 760px) {
    .vg-product-top { grid-template-columns: 1fr; }
}

/* Denser layout on the product detail / create pages (scoped via body class). */
.vg-page-product .vg-main > .container { padding: var(--sp-3) var(--sp-4); }
.vg-page-product .vg-page-head { margin-bottom: var(--sp-3); }
.vg-page-product .vg-product-top { gap: var(--sp-4); margin-bottom: var(--sp-4); }
.vg-page-product .panel { margin-bottom: var(--sp-3); }
.vg-page-product .panel-head { padding: var(--sp-2) var(--sp-3); }
.vg-page-product .panel-body { padding: var(--sp-1); }
.vg-page-product .mt-6 { margin-top: var(--sp-4); }

/* ===== Home landing ==================================================== */
/* Belt-and-suspenders against a pointless scrollbar over empty space. */
body.vg-landing { overflow: hidden; }
/* In-flow centring so the hero sits inside the content area (never over the
   sidebar/appbar). Height accounts for the .container padding so it fits the
   viewport exactly — centred image, no scroll. */
.vg-home {
    display: flex; align-items: center; justify-content: center;
    min-height: calc(100vh - var(--topbar-h) - 2 * var(--sp-5));
}
.vg-home-image { width: min(320px, 60vw); max-height: 70vh; height: auto; object-fit: contain; }

/* ===== Auth / sign-in screen =========================================== */
.vg-auth {
    display: flex; align-items: center; justify-content: center;
    /* Subtract the .container padding so the sign-in screen fits the viewport
       exactly — centred, with no pointless scrollbar over empty space. */
    min-height: calc(100vh - var(--topbar-h) - 2 * var(--sp-5)); padding: var(--sp-6) var(--sp-4);
}
.vg-auth-card {
    width: 100%; max-width: 440px;
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow); padding: var(--sp-8) var(--sp-6);
}
.vg-auth-brand {
    font-weight: 700; letter-spacing: 0.18em; color: var(--accent);
    font-size: var(--fs-md); margin-bottom: var(--sp-5);
}
.vg-auth-title { font-size: var(--fs-xl); margin-bottom: var(--sp-2); }
.vg-auth-sub { color: var(--text-muted); font-size: var(--fs-sm); margin-bottom: var(--sp-6); }
.vg-auth-alt { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--sp-5); text-align: center; }

/* ===== 21. Utilities ===================================================== */
.flex { display: flex; } .inline-flex { display: inline-flex; }
.items-center { align-items: center; } .items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; } .justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--sp-1); } .gap-2 { gap: var(--sp-2); } .gap-3 { gap: var(--sp-3); } .gap-4 { gap: var(--sp-4); }
.flex-1 { flex: 1; } .flex-wrap { flex-wrap: wrap; }
.block { display: block; } .hidden { display: none; }
.w-full { width: 100%; }
.text-left { text-align: left; } .text-center { text-align: center; } .text-right { text-align: right; }
.text-accent { color: var(--accent); } .text-danger { color: var(--danger); } .text-success { color: var(--success); }
.nowrap { white-space: nowrap; } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: var(--font-mono); }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: var(--sp-2); } .mt-3 { margin-top: var(--sp-3); } .mt-4 { margin-top: var(--sp-4); } .mt-6 { margin-top: var(--sp-6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--sp-2); } .mb-3 { margin-bottom: var(--sp-3); } .mb-4 { margin-bottom: var(--sp-4); } .mb-6 { margin-bottom: var(--sp-6); }
.p-0 { padding: 0; } .p-3 { padding: var(--sp-3); } .p-4 { padding: var(--sp-4); }

/* ===== 22. Responsive ==================================================== */
@media (max-width: 900px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .vg-form-row { grid-template-columns: 1fr; gap: var(--sp-1); }
    .vg-form-row > label { padding-top: 0; }
}
@media (max-width: 760px) {
    .vg-shell { grid-template-columns: 1fr; grid-template-rows: var(--topbar-h) auto 1fr; grid-template-areas: "topbar" "sidebar" "main"; }
    .vg-brand { display: none; }
    .vg-sidebar { padding: var(--sp-2) 0; }
    .container { padding: var(--sp-4); }
}

/* ===== 23. Inline edit (click-to-edit) + floating action bar ============= */
/* Controls that read as plain text until hovered/focused, so the product page looks unchanged until a field
   is clicked. Only .vg-inline-title / .vg-inline-block / .num deviate from the full-width default. */
.vg-inline {
    width: 100%;
    max-width: 100%;
    font: inherit;
    color: inherit;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 2px 4px;
}
.vg-inline:hover { background: var(--bg-inset); }
.vg-inline:focus { background: var(--bg-surface); border-color: var(--border-focus); outline: none; }
.vg-inline::placeholder { color: var(--text-faint); }

.vg-inline-title { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.2; }
/* field-sizing grows the box to fit its content (rows= acts as the minimum height). */
.vg-inline-block { display: block; resize: vertical; field-sizing: content; }
.vg-inline.num { width: 7rem; text-align: right; }

.vg-ref-edit { display: flex; align-items: center; gap: var(--sp-2); }
.vg-ref-edit .vg-inline { flex: 1; }

.vg-floating-actions {
    position: fixed;
    right: var(--sp-5);
    bottom: var(--sp-5);
    display: none;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-pop);
    z-index: var(--z-sticky);
}
.vg-floating-actions.is-visible { display: flex; }
