/* components.css — reusable UI components. Prefix `vn-`; BEM-style names; semantic tokens only;
   logical properties (inline/block) so a right-to-left language needs no rewrite. */

/* ============================ icon ============================ */
.vn-icon { width: 1.125rem; height: 1.125rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.vn-icon--sm { width: 0.875rem; height: 0.875rem; }
.vn-icon--lg { width: 1.5rem; height: 1.5rem; }

/* ============================ button ============================ */
.vn-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-block-size: var(--control-h); padding-inline: var(--space-4);
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text);
  font-weight: var(--fw-medium); font-size: var(--fs-md); line-height: 1; white-space: nowrap; text-decoration: none; max-inline-size: 100%;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.vn-btn:hover { background: var(--surface-2); }
.vn-btn--primary { background: var(--accent-solid); border-color: var(--accent-solid); color: var(--on-accent); }
.vn-btn--primary:hover { background: var(--accent-solid-hover); border-color: var(--accent-solid-hover); }
.vn-btn--ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.vn-btn--ghost:hover { background: var(--surface-2); color: var(--text); }
.vn-btn--danger { background: transparent; border-color: var(--err); color: var(--err-text); }
.vn-btn--danger:hover { background: var(--err-subtle); }
.vn-btn--sm { min-block-size: 1.875rem; padding-inline: var(--space-3); font-size: var(--fs-sm); }
.vn-btn--icon { inline-size: var(--control-h); padding-inline: 0; }
.vn-btn--icon.vn-btn--sm { inline-size: 1.875rem; }
.vn-btn:disabled, .vn-btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.vn-btn[aria-busy="true"] { cursor: progress; }
.vn-btn[aria-busy="true"]::before {
  content: ""; inline-size: 0.875rem; block-size: 0.875rem; border: 2px solid currentColor; border-inline-end-color: transparent;
  border-radius: 50%; animation: vn-spin 0.7s linear infinite;
}
@keyframes vn-spin { to { transform: rotate(360deg); } }

/* ============================ badge / status ============================ */
.vn-badge {
  display: inline-flex; align-items: center; gap: 0.375rem; padding: 0 var(--space-2); block-size: 1.25rem;
  border: 1px solid transparent; border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); line-height: 1; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.vn-badge::before { content: ""; inline-size: 0.375rem; block-size: 0.375rem; border-radius: 50%; background: currentColor; }
.vn-badge--plain::before { display: none; }
.vn-badge--ok { background: var(--ok-subtle); color: var(--ok-text); }
.vn-badge--warn { background: var(--warn-subtle); color: var(--warn-text); }
.vn-badge--err { background: var(--err-subtle); color: var(--err-text); }
.vn-badge--accent { background: var(--accent-subtle); color: var(--accent-text); }
.vn-badge--outline { background: transparent; border-color: var(--border-strong); color: var(--text-2); }
.vn-badge--outline::before { display: none; }

/* ============================ card / page header ============================ */
.vn-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-5); }
.vn-card--flush { padding: 0; overflow: hidden; }
.vn-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-block-end: var(--space-4); }
.vn-card__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); line-height: var(--lh-tight); }
.vn-card__desc { color: var(--text-2); font-size: var(--fs-sm); margin-block-start: var(--space-1); }
.vn-page-head { display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: var(--space-4); margin-block-end: var(--space-5); }
.vn-page-head__title { font-size: var(--fs-2xl); font-weight: var(--fw-bold); letter-spacing: -0.01em; line-height: var(--lh-tight); }
.vn-page-head__desc { color: var(--text-2); margin-block-start: var(--space-1); max-inline-size: 60ch; }
.vn-page-head__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ============================ banner ============================ */
.vn-banner {
  display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border); border-inline-start-width: 3px; border-radius: var(--radius-md);
  background: var(--surface); font-size: var(--fs-sm);
}
.vn-banner--info { border-inline-start-color: var(--accent-solid); background: var(--accent-subtle); }
.vn-banner--warn { border-inline-start-color: var(--warn); background: var(--warn-subtle); }
.vn-banner--err { border-inline-start-color: var(--err); background: var(--err-subtle); }
.vn-banner--ok { border-inline-start-color: var(--ok); background: var(--ok-subtle); }
.vn-banner__body { flex: 1; min-inline-size: 0; }
.vn-banner__title { font-weight: var(--fw-semibold); }

/* ============================ form controls ============================ */
.vn-field { display: flex; flex-direction: column; gap: 0.375rem; min-inline-size: 0; }
.vn-field__label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.vn-field__hint { color: var(--text-2); font-size: var(--fs-xs); }
.vn-field__error { color: var(--err-text); font-size: var(--fs-xs); font-weight: var(--fw-medium); }
.vn-input {
  inline-size: 100%; min-block-size: var(--control-h); padding: 0.375rem var(--space-3);
  background: var(--bg); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease);
}
textarea.vn-input { resize: vertical; min-block-size: 5rem; line-height: var(--lh-normal); }
select.vn-input { appearance: none; padding-inline-end: 2.25rem; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 1.15rem) 55%, calc(100% - 0.8rem) 55%; background-size: 0.35rem 0.35rem; background-repeat: no-repeat; }
[dir="rtl"] select.vn-input { background-position: 1.15rem 55%, 0.8rem 55%; }
.vn-input--compact { min-block-size: 2rem; padding-block: 0.125rem; } /* a choice inside a table row */
.vn-mono { font-family: var(--font-mono); letter-spacing: 0.04em; } /* a code to copy: easy to read, easy to tell characters apart */
.vn-input:disabled { opacity: 0.5; cursor: not-allowed; }
.vn-input[aria-invalid="true"] { border-color: var(--err); }
.vn-affix { display: flex; align-items: stretch; }
.vn-affix__text { display: grid; place-items: center; padding-inline: var(--space-3); background: var(--surface-2); border: 1px solid var(--border-strong); border-inline-end: 0; border-start-start-radius: var(--radius-md); border-end-start-radius: var(--radius-md); color: var(--text-2); font-family: var(--font-mono); }
.vn-affix .vn-input { border-start-start-radius: 0; border-end-start-radius: 0; }

/* switch: a native checkbox underneath (keyboard, screen readers, forms all just work) */
.vn-switch { position: relative; display: inline-block; inline-size: 2.5rem; block-size: 1.5rem; flex: none; }
.vn-switch input { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; margin: 0; opacity: 0; cursor: pointer; }
.vn-switch__track { position: absolute; inset: 0; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-full); transition: background var(--dur-base) var(--ease); pointer-events: none; }
.vn-switch__track::after { content: ""; position: absolute; inset-block-start: 2px; inset-inline-start: 2px; inline-size: 1.125rem; block-size: 1.125rem; border-radius: 50%; background: var(--text-2); transition: transform var(--dur-base) var(--ease), background var(--dur-base) var(--ease); }
.vn-switch input:checked + .vn-switch__track { background: var(--accent-solid); border-color: var(--accent-solid); }
.vn-switch input:checked + .vn-switch__track::after { transform: translateX(1rem); background: var(--on-accent); }
[dir="rtl"] .vn-switch input:checked + .vn-switch__track::after { transform: translateX(-1rem); }
.vn-switch input:focus-visible + .vn-switch__track { outline: 2px solid var(--focus); outline-offset: 2px; }
.vn-switch input:disabled { cursor: not-allowed; }
.vn-switch input:disabled + .vn-switch__track { opacity: 0.5; }
.vn-switch-row { display: flex; align-items: center; gap: var(--space-3); }
.vn-check { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.vn-check input { inline-size: 1.125rem; block-size: 1.125rem; accent-color: var(--accent-solid); }

.vn-segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); }
.vn-segmented button { display: inline-flex; align-items: center; gap: var(--space-2); border: 0; background: none; padding: 0.25rem var(--space-3); border-radius: var(--radius-sm); color: var(--text-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); min-block-size: 1.75rem; }
.vn-segmented button:hover { color: var(--text); }
.vn-segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--border); }

/* ============================ tabs ============================ */
.vn-tabs { display: flex; gap: var(--space-1); border-block-end: 1px solid var(--border); margin-block-end: var(--space-4); overflow-x: auto; }
.vn-tabs button { background: none; border: 0; border-block-end: 2px solid transparent; margin-block-end: -1px; padding: var(--space-2) var(--space-3); color: var(--text-2); font-weight: var(--fw-medium); white-space: nowrap; border-radius: 0; }
.vn-tabs button:hover { color: var(--text); }
.vn-tabs button[aria-selected="true"] { color: var(--text); border-block-end-color: var(--accent-solid); }

/* ============================ table ============================ */
/* position: relative makes the wrapper the containing block of visually-hidden (absolutely positioned) header text, so it is clipped with the table instead of widening the whole page */
.vn-table-wrap { position: relative; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.vn-table { inline-size: 100%; font-size: var(--fs-md); }
.vn-table th { text-align: start; padding: var(--space-3) var(--space-4); color: var(--text-2); font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; border-block-end: 1px solid var(--border); }
.vn-table td { padding: var(--space-3) var(--space-4); border-block-end: 1px solid var(--border); vertical-align: middle; }
.vn-table tr:last-child td { border-block-end: 0; }
.vn-table__muted { color: var(--text-2); }
.vn-table__actions { display: flex; justify-content: flex-end; gap: 2px; }
.vn-code { font-family: var(--font-mono); font-size: var(--fs-sm); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1px 0.375rem; }

/* ============================ dialog (native <dialog>) ============================ */
.vn-dialog { padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); inline-size: min(32.5rem, calc(100vw - 2rem)); max-block-size: calc(100dvh - 2rem); box-shadow: var(--shadow-dialog); }
.vn-dialog::backdrop { background: var(--overlay); }
.vn-dialog__form { display: flex; flex-direction: column; max-block-size: inherit; }
.vn-dialog__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-block-end: 1px solid var(--border); }
.vn-dialog__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.vn-dialog__body { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); overflow-y: auto; }
.vn-dialog__foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-block-start: 1px solid var(--border); }

/* ============================ toast ============================ */
.vn-toasts { position: fixed; inset-inline-end: var(--space-4); inset-block-end: var(--space-4); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-2); max-inline-size: min(24rem, calc(100vw - 2rem)); }
.vn-toast { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--surface); border: 1px solid var(--border-strong); border-inline-start: 3px solid var(--accent-solid); border-radius: var(--radius-md); box-shadow: var(--shadow-popover); font-size: var(--fs-sm); }
.vn-toast--ok { border-inline-start-color: var(--ok); }
.vn-toast--err { border-inline-start-color: var(--err); }
.vn-toast__msg { flex: 1; }

/* ============================ tooltip ============================ */
.vn-tooltip { position: relative; display: inline-flex; }
.vn-tooltip__tip { position: absolute; inset-block-end: calc(100% + 0.5rem); inset-inline-start: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 0.25rem var(--space-2); border-radius: var(--radius-sm); font-size: var(--fs-xs); font-weight: var(--fw-medium); white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity var(--dur-fast) var(--ease); z-index: var(--z-sticky); }
.vn-tooltip:hover .vn-tooltip__tip, .vn-tooltip:focus-within .vn-tooltip__tip { opacity: 1; }

/* ============================ menu / popover ============================ */
.vn-menu-anchor { position: relative; }
.vn-menu { position: absolute; inset-inline-start: 0; inset-block-start: calc(100% + 0.25rem); min-inline-size: 100%; z-index: var(--z-drawer); padding: var(--space-1); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-popover); }
.vn-menu__label { padding: var(--space-2) var(--space-3) var(--space-1); color: var(--text-2); font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: 0.04em; text-transform: uppercase; }
.vn-menu__item { display: flex; align-items: center; gap: var(--space-3); inline-size: 100%; padding: var(--space-2) var(--space-3); border: 0; background: none; border-radius: var(--radius-sm); text-align: start; color: var(--text); }
.vn-menu__item:hover, .vn-menu__item:focus-visible { background: var(--surface-2); }
.vn-menu__item[aria-checked="true"] { color: var(--accent-text); font-weight: var(--fw-semibold); }
.vn-menu__item[aria-disabled="true"] { color: var(--text-2); cursor: not-allowed; }
.vn-menu__sep { block-size: 1px; background: var(--border); margin-block: var(--space-1); }

/* ============================ states ============================ */
.vn-state { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); padding: var(--space-6) var(--space-4); text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.vn-state__icon { display: grid; place-items: center; inline-size: 2.75rem; block-size: 2.75rem; border-radius: 50%; background: var(--surface-2); color: var(--text-2); }
.vn-state__title { font-weight: var(--fw-semibold); }
.vn-state__text { color: var(--text-2); font-size: var(--fs-sm); max-inline-size: 42ch; }
.vn-state--err { border-style: solid; border-color: var(--err); background: var(--err-subtle); }
.vn-state--err .vn-state__icon { background: transparent; color: var(--err-text); }
.vn-skeleton { display: block; block-size: 0.875rem; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--skeleton-a), var(--skeleton-b), var(--skeleton-a)); background-size: 200% 100%; animation: vn-sheen 1.4s ease-in-out infinite; }
@keyframes vn-sheen { to { background-position: -200% 0; } }

/* ============================ stat / avatar / chart ============================ */
.vn-stat { display: flex; flex-direction: column; gap: 0.125rem; }
.vn-stat__value { font-size: var(--fs-xl); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }
.vn-stat__label { color: var(--text-2); font-size: var(--fs-sm); }
.vn-avatar { display: grid; place-items: center; inline-size: 1.75rem; block-size: 1.75rem; border-radius: var(--radius-sm); background: var(--accent-subtle); color: var(--accent-text); font-size: var(--fs-xs); font-weight: var(--fw-bold); flex: none; }
.vn-chart { inline-size: 100%; block-size: auto; display: block; }
.vn-chart text { fill: var(--text-2); font-size: 12px; font-family: var(--font-sans); }
.vn-chart__grid { stroke: var(--chart-grid); stroke-width: 1; }
.vn-chart__bar--1 { fill: var(--chart-1); }
.vn-chart__bar--2 { fill: var(--chart-2); }
.vn-chart__line--1 { stroke: var(--chart-1); fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.vn-chart__area--1 { fill: var(--chart-1); opacity: 0.12; }

/* ============================ module card / save bar ============================ */
.vn-module { display: flex; flex-direction: column; gap: var(--space-3); }
.vn-module__top { display: flex; align-items: center; gap: var(--space-3); }
.vn-module__icon { display: grid; place-items: center; inline-size: 2.25rem; block-size: 2.25rem; border-radius: var(--radius-md); background: var(--accent-subtle); color: var(--accent-text); flex: none; }
.vn-module--soon .vn-module__icon { background: var(--surface-2); color: var(--text-2); }
.vn-module__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); flex: 1; min-inline-size: 0; }
.vn-module__text { color: var(--text-2); font-size: var(--fs-sm); flex: 1; }
.vn-module__actions { display: flex; gap: var(--space-2); }
.vn-savebar { position: sticky; inset-block-end: var(--space-4); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-popover); }

/* touch screens: bigger targets */
@media (pointer: coarse) {
  .vn-btn, .vn-input, .vn-menu__item { min-block-size: var(--control-h-touch); }
  .vn-btn--icon { inline-size: var(--control-h-touch); }
  .vn-segmented button { min-block-size: 2.25rem; }
}

/* skeleton widths (classes, because inline styles are blocked by the CSP) */
.vn-skeleton--w-40 { inline-size: 40%; }
.vn-skeleton--w-60 { inline-size: 60%; }
.vn-skeleton--w-90 { inline-size: 90%; }

/* a long label wraps instead of pushing the page sideways on a phone */
@media (max-width: 860px) {
  .vn-btn { white-space: normal; text-align: center; line-height: 1.25; padding-block: var(--space-2); }
}

/* table rows as cards on a phone (opt-in with the `stack` option) */
@media (max-width: 860px) {
  .vn-table-wrap:has(.vn-table--stack) { border: 0; background: transparent; overflow: visible; }
  .vn-table--stack, .vn-table--stack tbody, .vn-table--stack tr, .vn-table--stack td { display: block; }
  .vn-table--stack thead { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
  .vn-table--stack tr { margin-block-end: var(--space-3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-2) var(--space-4); }
  .vn-table--stack td { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-2) 0; border-block-end: 1px solid var(--border); text-align: end; }
  .vn-table--stack td:last-child { border-block-end: 0; }
  .vn-table--stack td::before { content: attr(data-label); color: var(--text-2); font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: 0.04em; text-transform: uppercase; text-align: start; flex: none; }
  .vn-table--stack td:not([data-label])::before { content: none; }
  .vn-table--stack td:not([data-label]) { justify-content: flex-end; }
  .vn-table--stack td:first-child { font-weight: var(--fw-semibold); }
}

.vn-chat-preview { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3); font-size: var(--fs-sm); min-block-size: 2.5rem; overflow-wrap: anywhere; }
.vn-chat-preview b { color: var(--accent-text); }
.vn-wrap { overflow-wrap: anywhere; }
.vn-toolbar { display: flex; align-items: flex-end; gap: var(--space-3); flex-wrap: wrap; }
.vn-notes { display: flex; flex-direction: column; gap: var(--space-1); list-style: disc; padding-inline-start: var(--space-5); }

.vn-stat__value--na { font-size: var(--fs-md); font-weight: var(--fw-regular); color: var(--text-2); }

.vn-region { min-inline-size: 0; }

/* a region reserved for a message that is not there takes no space */
[role='alert']:empty { display: none; }

/* a plain list of items with a divider, for messages and signals */
.vn-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.vn-list__item { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding-block: var(--space-3); border-block-end: 1px solid var(--border); }
.vn-list__item:last-child { border-block-end: 0; }

/* label / value rows (a status list) */
.vn-kvs { margin: 0; display: flex; flex-direction: column; }
.vn-kv { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); padding-block: var(--space-2); border-block-end: 1px solid var(--border); }
.vn-kv:last-child { border-block-end: 0; }
.vn-kv dt { flex: 0 0 12rem; color: var(--text-2); }
.vn-kv dd { margin: 0; flex: 1; min-inline-size: 0; }

/* A share bar (the votes of a poll option): a real <progress>, so assistive technology reads the value. */
.vn-progress { inline-size: 100%; block-size: 0.625rem; appearance: none; border: 0; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.vn-progress::-webkit-progress-bar { background: var(--surface-2); }
.vn-progress::-webkit-progress-value { background: var(--accent-solid); border-radius: 999px; }
.vn-progress::-moz-progress-bar { background: var(--accent-solid); border-radius: 999px; }

/* A group of related checkboxes (the days of a schedule) under one legend. */
.vn-fieldset { border: 0; margin: 0; padding: 0; min-inline-size: 0; }
.vn-fieldset > legend { padding: 0; margin-block-end: var(--space-2); }
.vn-checks { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); }

/* A grid of counts by weekday (rows) and hour (columns): the darker a square, the more messages. It is a real table. */
.vn-heat-wrap { position: relative; overflow-x: auto; } /* relative: the hidden text of the cells is clipped here, not by the page */
.vn-heat { border-collapse: separate; border-spacing: 2px; font-size: var(--fs-xs); }
.vn-heat th { font-weight: var(--fw-medium); color: var(--text-2); padding: 0 var(--space-1); white-space: nowrap; text-align: start; }
.vn-heat td { inline-size: 1.1rem; min-inline-size: 1.1rem; block-size: 1.1rem; border-radius: 3px; background: var(--surface-2); padding: 0; }
.vn-heat td[data-level="1"] { background: color-mix(in srgb, var(--accent-solid) 25%, var(--surface-2)); }
.vn-heat td[data-level="2"] { background: color-mix(in srgb, var(--accent-solid) 50%, var(--surface-2)); }
.vn-heat td[data-level="3"] { background: color-mix(in srgb, var(--accent-solid) 75%, var(--surface-2)); }
.vn-heat td[data-level="4"] { background: var(--accent-solid); }
