/**
 * Zeyn default UI kit.
 *
 * A quiet, dense visual system for screens people work in all day: grids, long forms,
 * windows and toolbars. Every visual decision reads from the tokens on :root, so an
 * organization themes the kit by overriding a handful of custom properties in its own
 * stylesheet (see docs/theming.md). No web fonts, no external URLs.
 *
 * Theme selection: the system setting by default, forced with
 * <html data-theme="light"> or <html data-theme="dark">.
 * Density: --z-density (1 regular, 0.75 compact) or <html data-density="compact">.
 */

:root {
  color-scheme: light;

  --z-brand: #0f6674;
  --z-on-brand: #ffffff;

  --z-font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --z-font-mono: ui-monospace, "Cascadia Mono", "SF Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  --z-font-size: 0.875rem;
  --z-font-size-sm: 0.8125rem;
  --z-font-size-xs: 0.75rem;

  --z-radius: 4px;
  --z-density: 1;

  --z-bg: #f4f5f6;
  --z-surface: #ffffff;
  --z-surface-2: #f7f8f9;
  --z-hover: #eceef1;
  --z-border: #dcdfe3;
  --z-border-strong: #7d848d;
  --z-text: #1a1d21;
  --z-text-muted: #5b626b;

  --z-danger: #b3261e;
  --z-warning: #8a5300;
  --z-success: #1e6b3a;
  --z-info: #2b5d8a;

  --z-tint: 9%;
  --z-accent: var(--z-brand);
  --z-primary: var(--z-brand);
  --z-on-primary: var(--z-on-brand);
  --z-primary-hover: color-mix(in oklab, var(--z-brand) 86%, #000000);
  --z-primary-active: color-mix(in oklab, var(--z-brand) 74%, #000000);
  --z-shadow-color: 220 20% 10%;
  --z-shadow-strength: 16%;
  --z-backdrop: rgb(20 24 28 / 40%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --z-bg: #121416;
    --z-surface: #1a1d20;
    --z-surface-2: #202326;
    --z-hover: #2a2e33;
    --z-border: #33383e;
    --z-border-strong: #7a818a;
    --z-text: #e4e6e9;
    --z-text-muted: #a2a9b1;
    --z-danger: #f28b82;
    --z-warning: #e6b45a;
    --z-success: #6fcf8f;
    --z-info: #8ab8e6;
    --z-tint: 20%;
    --z-accent: color-mix(in oklab, var(--z-brand) 45%, #ffffff);
    --z-primary: var(--z-accent);
    --z-on-primary: #121416;
    --z-primary-hover: color-mix(in oklab, var(--z-accent) 84%, #ffffff);
    --z-primary-active: color-mix(in oklab, var(--z-accent) 70%, #ffffff);
    --z-shadow-color: 0 0% 0%;
    --z-shadow-strength: 50%;
    --z-backdrop: rgb(0 0 0 / 60%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --z-bg: #121416;
  --z-surface: #1a1d20;
  --z-surface-2: #202326;
  --z-hover: #2a2e33;
  --z-border: #33383e;
  --z-border-strong: #7a818a;
  --z-text: #e4e6e9;
  --z-text-muted: #a2a9b1;
  --z-danger: #f28b82;
  --z-warning: #e6b45a;
  --z-success: #6fcf8f;
  --z-info: #8ab8e6;
  --z-tint: 20%;
  --z-accent: color-mix(in oklab, var(--z-brand) 45%, #ffffff);
  --z-primary: var(--z-accent);
  --z-on-primary: #121416;
  --z-primary-hover: color-mix(in oklab, var(--z-accent) 84%, #ffffff);
  --z-primary-active: color-mix(in oklab, var(--z-accent) 70%, #ffffff);
  --z-shadow-color: 0 0% 0%;
  --z-shadow-strength: 50%;
  --z-backdrop: rgb(0 0 0 / 60%);
}

@supports (color: oklch(from red l c h)) {
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --z-accent: oklch(from var(--z-brand) 0.8 c h); }
  }
  :root[data-theme="dark"] { --z-accent: oklch(from var(--z-brand) 0.8 c h); }
}

:root[data-density="compact"] { --z-density: 0.75; }

:root {
  --z-brand-subtle: color-mix(in oklab, var(--z-accent) var(--z-tint), var(--z-surface));
  --z-focus: var(--z-accent);

  --z-danger-subtle: color-mix(in oklab, var(--z-danger) var(--z-tint), var(--z-surface));
  --z-warning-subtle: color-mix(in oklab, var(--z-warning) var(--z-tint), var(--z-surface));
  --z-success-subtle: color-mix(in oklab, var(--z-success) var(--z-tint), var(--z-surface));
  --z-info-subtle: color-mix(in oklab, var(--z-info) var(--z-tint), var(--z-surface));

  --z-space: calc(4px * var(--z-density));
  --z-control: max(24px, calc(var(--z-space) * 8));
  --z-row: max(24px, calc(var(--z-space) * 8));
  --z-gap: calc(var(--z-space) * 3);

  --z-radius-sm: calc(var(--z-radius) * 0.75);
  --z-radius-lg: calc(var(--z-radius) * 1.5);

  --z-shadow-2: 0 2px 4px hsl(var(--z-shadow-color) / calc(var(--z-shadow-strength) * 0.5)), 0 12px 32px -8px hsl(var(--z-shadow-color) / var(--z-shadow-strength));
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--z-font);
  font-size: var(--z-font-size);
  line-height: 1.45;
  color: var(--z-text);
  background: var(--z-bg);
  -webkit-font-smoothing: antialiased;
}

body:has(dialog[open]) { overflow: hidden; }

:focus-visible {
  outline: 2px solid var(--z-focus);
  outline-offset: 2px;
}

a {
  color: var(--z-accent);
  text-underline-offset: 2px;
}

a:hover { text-decoration-thickness: 2px; }

code, pre { font-family: var(--z-font-mono); font-size: 0.9em; }

.z-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.z-skip {
  position: absolute;
  left: 8px;
  top: -100px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--z-brand);
  color: var(--z-on-brand);
  border-radius: var(--z-radius);
  font-weight: 600;
  text-decoration: none;
}

.z-skip:focus { top: 8px; }


/**
 * Shell: a fixed side navigation and a scrolling work area.
 * The application name sits on a solid brand band, the one place the brand color is used
 * as a large surface; everywhere else it marks state (current, primary, focus).
 */

.z-app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100dvh;
}

.z-nav {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  padding: 0 calc(var(--z-space) * 2) calc(var(--z-space) * 3);
  background: var(--z-surface);
  border-right: 1px solid var(--z-border);
}

.z-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.z-app-name {
  display: flex;
  align-items: center;
  min-height: 52px;
  margin: 0 calc(var(--z-space) * -2) calc(var(--z-space) * 2);
  padding: 0 calc(var(--z-space) * 4 + 2px);
  background: var(--z-brand);
  color: var(--z-on-brand);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.005em;
}

.z-nav-group { padding-top: calc(var(--z-space) * 2); }

.z-nav h2,
.z-nav h3,
.z-nav summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  margin: 0 0 2px;
  padding: 0 10px;
  font-size: var(--z-font-size-xs);
  font-weight: 600;
  color: var(--z-text-muted);
}

.z-nav h2 .z-icon,
.z-nav h3 .z-icon { width: 14px; height: 14px; }

.z-nav summary { cursor: pointer; }

.z-nav li + li { margin-top: 1px; }

.z-nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--z-control);
  padding: 0 10px 0 32px;
  border-radius: var(--z-radius);
  color: var(--z-text);
  text-decoration: none;
}

.z-nav a:hover { background: var(--z-hover); }

.z-nav a[aria-current="page"] {
  background: var(--z-brand-subtle);
  color: var(--z-accent);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--z-accent);
}

.z-main {
  min-width: 0;
  padding: calc(var(--z-space) * 5) calc(var(--z-space) * 7) calc(var(--z-space) * 8);
}

.z-main:focus { outline: none; }

@media (max-width: 800px) {
  .z-app { grid-template-columns: minmax(0, 1fr); }
  .z-nav {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
    padding: 0 12px 8px;
    border-right: 0;
    border-bottom: 1px solid var(--z-border);
  }
  .z-app-name {
    flex-basis: calc(100% + 24px);
    min-height: 44px;
    margin: 0 -12px 4px;
    padding: 0 16px;
  }
  .z-nav-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding-top: 0;
  }
  .z-nav-group ul { display: flex; gap: 2px; }
  .z-nav h2 { padding: 0 4px; margin: 0; }
  .z-nav a { padding: 0 10px; }
  .z-nav li + li { margin-top: 0; }
  .z-locale { margin: 0; padding: 0; flex-direction: row; align-items: center; }
  .z-main { padding: 16px; }
}


/**
 * Screens and windows.
 */

.z-screen,
.z-window {
  display: flex;
  flex-direction: column;
  gap: var(--z-gap);
}

.z-screen > h1 {
  margin: 0 0 calc(var(--z-space) * 1);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.z-screen.z-error {
  max-width: 640px;
  padding: calc(var(--z-space) * 5) calc(var(--z-space) * 6);
  background: var(--z-surface);
  border: 1px solid var(--z-border);
  border-left: 3px solid var(--z-danger);
  border-radius: var(--z-radius);
}

.z-screen.z-error > h1 { margin: 0; font-size: 1.0625rem; }

dialog.z-dialog {
  padding: 0;
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-lg);
  background: var(--z-surface);
  color: var(--z-text);
  box-shadow: var(--z-shadow-2);
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
}

dialog.z-dialog::backdrop { background: var(--z-backdrop); }

.z-window {
  --z-pad: calc(var(--z-space) * 5);
  width: min(var(--z-width, 560px), calc(100vw - 32px));
  max-width: 100%;
  padding: 0 var(--z-pad) var(--z-pad);
}

.z-window:focus { outline: none; }

.z-window > h2 {
  margin: 0 calc(var(--z-pad) * -1);
  padding: calc(var(--z-space) * 3 + 2px) 56px calc(var(--z-space) * 3 + 2px) var(--z-pad);
  border-bottom: 1px solid var(--z-border);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
}

.z-window .z-form { max-width: none; }

.z-window .z-form-actions {
  position: sticky;
  bottom: calc(var(--z-pad) * -1);
  z-index: 2;
  margin: calc(var(--z-space) * 2) calc(var(--z-pad) * -1) calc(var(--z-pad) * -1);
  padding: calc(var(--z-space) * 3) var(--z-pad);
  background: var(--z-surface-2);
  border-top: 1px solid var(--z-border);
}

.z-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--z-radius);
  background: transparent;
  color: var(--z-text-muted);
  font: 400 1.375rem/1 var(--z-font);
  cursor: pointer;
}

.z-close:hover { background: var(--z-hover); color: var(--z-text); }


/**
 * Toolbar and buttons. The default button is quiet; `.z-primary` carries the brand.
 */

.z-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--z-space) * 2);
}

.z-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--z-control);
  min-width: var(--z-control);
  padding: 0 calc(var(--z-space) * 3);
  border: 1px solid var(--z-border-strong);
  border-radius: var(--z-radius);
  background: var(--z-surface);
  color: var(--z-text);
  font: inherit;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 80ms linear, border-color 80ms linear;
}

.z-button:hover:not(:disabled) { background: var(--z-hover); }

.z-button:active:not(:disabled) { background: color-mix(in oklab, var(--z-hover) 80%, var(--z-text)); }

.z-button:disabled {
  cursor: not-allowed;
  color: var(--z-text-muted);
  border-color: var(--z-border);
  background: var(--z-surface-2);
}

.z-button .z-icon { color: var(--z-text-muted); }

.z-button.z-primary {
  background: var(--z-primary);
  border-color: var(--z-primary);
  color: var(--z-on-primary);
  font-weight: 600;
}

.z-button.z-primary .z-icon { color: inherit; }

.z-button.z-primary:hover:not(:disabled) {
  background: var(--z-primary-hover);
  border-color: var(--z-primary-hover);
}

.z-button.z-primary:active:not(:disabled) {
  background: var(--z-primary-active);
  border-color: var(--z-primary-active);
}

.z-button.z-primary:disabled {
  opacity: 0.5;
  color: var(--z-on-primary);
  background: var(--z-primary);
  border-color: var(--z-primary);
}

.z-button[aria-keyshortcuts]::after {
  content: attr(aria-keyshortcuts) / "";
  margin-left: 2px;
  padding: 1px 4px;
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-sm);
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--z-text-muted);
}

.z-button.z-primary[aria-keyshortcuts]::after {
  color: inherit;
  border-color: color-mix(in oklab, var(--z-on-primary) 40%, transparent);
}


.z-icon {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: var(--z-i) center / contain no-repeat;
  mask: var(--z-i) center / contain no-repeat;
}

.z-icon-plus { --z-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
.z-icon-edit { --z-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20h4L19 9l-4-4L4 16zM14 6l4 4'/%3E%3C/svg%3E"); }
.z-icon-delete { --z-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3'/%3E%3C/svg%3E"); }
.z-icon-save { --z-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M5 4h11l3 3v13H5zM8 4v5h7V4M8 20v-6h8v6'/%3E%3C/svg%3E"); }
.z-icon-search { --z-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-4-4'/%3E%3C/svg%3E"); }
.z-icon-box { --z-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M3 7l9-4 9 4v10l-9 4-9-4zM3 7l9 4 9-4M12 11v10'/%3E%3C/svg%3E"); }
.z-icon-cart { --z-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4h2l2.5 11h10.5l2-7H6.2'/%3E%3Ccircle cx='9' cy='20' r='1.5'/%3E%3Ccircle cx='17' cy='20' r='1.5'/%3E%3C/svg%3E"); }
.z-icon-table { --z-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linejoin='round'%3E%3Cpath d='M3 5h18v14H3zM3 10h18M9 10v9'/%3E%3C/svg%3E"); }


/**
 * Grid. Rows are flat (no shadows, no filters) so the virtual grid repaints cheaply;
 * state is shown with background color and an inset bar on the first cell.
 */

.z-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(100%, max-content);
  align-content: start;
  max-height: max(320px, calc(100dvh - 12rem));
  overflow: auto;
  background: var(--z-surface);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius);
  font-size: var(--z-font-size-sm);
  font-variant-numeric: tabular-nums;
}

.z-window .z-grid { max-height: 60dvh; }

.z-grid table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.z-grid thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.z-grid th,
.z-grid td {
  height: var(--z-row);
  padding: calc(var(--z-space) * 1) calc(var(--z-space) * 3);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--z-border);
}

.z-grid th {
  background: var(--z-surface-2);
  font-size: var(--z-font-size-xs);
  font-weight: 600;
  color: var(--z-text-muted);
  white-space: nowrap;
  border-bottom-color: var(--z-border-strong);
}

.z-grid th + th { box-shadow: inset 1px 0 0 var(--z-border); }

.z-grid th[style*="--z-flex"] { width: calc(var(--z-flex) * 20%); }

.z-grid th:has(.z-sort) { padding: 0 2px; }

.z-sort {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  min-height: max(24px, calc(var(--z-row) - 4px));
  padding: 0 calc(var(--z-space) * 3 - 2px);
  border: 0;
  border-radius: var(--z-radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: inherit;
  cursor: pointer;
}

.z-sort:hover { background: var(--z-hover); color: var(--z-text); }

.z-sort::after {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  margin-left: auto;
  background: currentColor;
  opacity: 0;
  -webkit-mask: var(--z-sort-i) center / contain no-repeat;
  mask: var(--z-sort-i) center / contain no-repeat;
  --z-sort-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M5 1l3 3H2zM5 9L2 6h6z'/%3E%3C/svg%3E");
}

.z-sort:hover::after,
.z-sort:focus-visible::after { opacity: 0.55; }

th[aria-sort="ascending"] .z-sort,
th[aria-sort="descending"] .z-sort { color: var(--z-text); }

th[aria-sort="ascending"] .z-sort::after {
  opacity: 1;
  --z-sort-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M5 2l4 5H1z'/%3E%3C/svg%3E");
}

th[aria-sort="descending"] .z-sort::after {
  opacity: 1;
  --z-sort-i: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M5 8L1 3h8z'/%3E%3C/svg%3E");
}

.z-grid th.z-num,
.z-grid th.z-num .z-sort { text-align: right; justify-content: flex-end; }

.z-grid th.z-num .z-sort::after { margin-left: 0; order: -1; }

.z-filter-row td {
  height: auto;
  padding: 3px 2px;
  background: var(--z-surface-2);
  border-bottom-color: var(--z-border-strong);
}

.z-filter-row td + td { box-shadow: inset 1px 0 0 var(--z-border); }

.z-filter {
  width: 100%;
  min-width: 64px;
  min-height: max(24px, calc(var(--z-row) - 6px));
  padding: 0 8px;
  border: 1px solid var(--z-border-strong);
  border-radius: var(--z-radius-sm);
  background: var(--z-surface);
  color: var(--z-text);
  font: inherit;
  font-size: var(--z-font-size-sm);
  font-weight: 400;
}

.z-filter:focus-visible { outline-offset: 0; border-color: var(--z-focus); }

.z-filter-pair {
  display: flex;
  gap: 2px;
  min-width: 0;
}

.z-filter-pair .z-filter { min-width: 0; flex: 1 1 0; }

.z-filter-pair .z-filter-op {
  flex: 0 0 auto;
  width: 2.25rem;
  padding-inline: 2px;
  color: var(--z-text-muted);
}

.z-filter-range .z-filter { min-width: 4.5rem; padding-inline: 4px; }

.z-filter-select { min-width: 0; }
.z-filter-pair .z-filter-select { flex: 0 0 auto; width: 2.75rem; }
.z-filter-select .z-select-button {
  min-height: max(24px, calc(var(--z-row) - 6px));
  padding-inline: 6px;
  gap: 2px;
}
.z-filter-select .z-select-value { overflow: hidden; white-space: nowrap; }
.z-filter-pair .z-filter-select .z-select-value { color: var(--z-text-muted); }

.z-filter-choice {
  display: block;
  text-align: start;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}

.z-filter-choice.z-active { border-color: var(--z-accent); color: var(--z-accent); }

.z-popover {
  position: fixed;
  inset: auto;
  margin: 0;
  min-width: 12rem;
  max-height: min(20rem, 70dvh);
  overflow: auto;
  padding: calc(var(--z-space) * 1.5);
  background: var(--z-surface);
  color: var(--z-text);
  border: 1px solid var(--z-border-strong);
  border-radius: var(--z-radius);
  box-shadow: var(--z-shadow-2);
  font-size: var(--z-font-size-sm);
}

.z-check {
  display: flex;
  align-items: center;
  gap: calc(var(--z-space) * 2);
  min-height: 28px;
  padding-inline: calc(var(--z-space) * 1.5);
  border-radius: var(--z-radius-sm);
  cursor: pointer;
}

.z-check:hover { background: var(--z-hover); }

/**
 * Column header: sort button, menu button and resize handle. Pinned columns use
 * position: sticky with offsets the runtime measures; the rules have no specificity
 * (:where) so row states (hover, focus, zebra, highlights) still paint pinned cells.
 */

.z-th {
  display: flex;
  align-items: center;
  min-width: 0;
}

.z-th .z-sort { flex: 1 1 auto; min-width: 0; }

:where(.z-grid th) { position: relative; }

.z-col-menu {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: var(--z-radius-sm);
  background: transparent;
  color: inherit;
  cursor: pointer;
  opacity: 0;
}

.z-col-menu::before {
  content: "";
  width: 12px;
  height: 12px;
  background: currentColor;
  -webkit-mask: var(--z-dots) center / contain no-repeat;
  mask: var(--z-dots) center / contain no-repeat;
  --z-dots: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Ccircle cx='6' cy='2' r='1.3'/%3E%3Ccircle cx='6' cy='6' r='1.3'/%3E%3Ccircle cx='6' cy='10' r='1.3'/%3E%3C/svg%3E");
}

.z-grid th:hover .z-col-menu,
.z-col-menu:focus-visible,
.z-col-menu[aria-expanded="true"] { opacity: 1; }

.z-col-menu:hover { background: var(--z-hover); color: var(--z-text); }

@media (hover: none) { .z-col-menu { opacity: 1; } }

.z-resize {
  position: absolute;
  inset-block: 0;
  inset-inline-end: -4px;
  z-index: 2;
  width: 8px;
  cursor: col-resize;
  touch-action: none;
}

.z-resize::after {
  content: "";
  position: absolute;
  inset-block: 25%;
  inset-inline-start: 3px;
  width: 2px;
  border-radius: 1px;
  background: transparent;
}

.z-resize:hover::after,
.z-resize:focus-visible::after,
.z-resize.z-active::after { background: var(--z-accent); }

.z-resize:focus-visible { outline: none; }

.z-grid table.z-fixed { table-layout: fixed; }

.z-grid .z-spacer td { position: static; }

.z-grid thead { z-index: 3; }

.z-grid tfoot td { z-index: 2; }

:where(.z-grid[data-pin-start="1"] > table > * > tr > :nth-child(-n + 1)),
:where(.z-grid[data-pin-start="2"] > table > * > tr > :nth-child(-n + 2)),
:where(.z-grid[data-pin-start="3"] > table > * > tr > :nth-child(-n + 3)),
:where(.z-grid[data-pin-start="4"] > table > * > tr > :nth-child(-n + 4)),
:where(.z-grid[data-pin-start="5"] > table > * > tr > :nth-child(-n + 5)),
:where(.z-grid[data-pin-end="1"] > table > * > tr > :nth-last-child(-n + 1)),
:where(.z-grid[data-pin-end="2"] > table > * > tr > :nth-last-child(-n + 2)),
:where(.z-grid[data-pin-end="3"] > table > * > tr > :nth-last-child(-n + 3)) {
  position: sticky;
  z-index: 1;
  background-color: var(--z-surface);
}

:where(.z-grid > table > * > tr > :nth-child(1)) { inset-inline-start: var(--z-ps1, 0); }
:where(.z-grid > table > * > tr > :nth-child(2)) { inset-inline-start: var(--z-ps2, 0); }
:where(.z-grid > table > * > tr > :nth-child(3)) { inset-inline-start: var(--z-ps3, 0); }
:where(.z-grid > table > * > tr > :nth-child(4)) { inset-inline-start: var(--z-ps4, 0); }
:where(.z-grid > table > * > tr > :nth-child(5)) { inset-inline-start: var(--z-ps5, 0); }
:where(.z-grid > table > * > tr > :nth-last-child(1)) { inset-inline-end: var(--z-pe1, 0); }
:where(.z-grid > table > * > tr > :nth-last-child(2)) { inset-inline-end: var(--z-pe2, 0); }
:where(.z-grid > table > * > tr > :nth-last-child(3)) { inset-inline-end: var(--z-pe3, 0); }

:where(.z-grid[data-pin-start="1"] > table > * > tr > :nth-child(1)),
:where(.z-grid[data-pin-start="2"] > table > * > tr > :nth-child(2)),
:where(.z-grid[data-pin-start="3"] > table > * > tr > :nth-child(3)),
:where(.z-grid[data-pin-start="4"] > table > * > tr > :nth-child(4)),
:where(.z-grid[data-pin-start="5"] > table > * > tr > :nth-child(5)) { box-shadow: inset -1px 0 0 var(--z-border-strong); }

:where(.z-grid[data-pin-end="1"] > table > * > tr > :nth-last-child(1)),
:where(.z-grid[data-pin-end="2"] > table > * > tr > :nth-last-child(2)),
:where(.z-grid[data-pin-end="3"] > table > * > tr > :nth-last-child(3)) { box-shadow: inset 1px 0 0 var(--z-border-strong); }

:where([dir="rtl"]) :where(.z-grid[data-pin-start="1"] > table > * > tr > :nth-child(1)),
:where([dir="rtl"]) :where(.z-grid[data-pin-start="2"] > table > * > tr > :nth-child(2)),
:where([dir="rtl"]) :where(.z-grid[data-pin-start="3"] > table > * > tr > :nth-child(3)),
:where([dir="rtl"]) :where(.z-grid[data-pin-start="4"] > table > * > tr > :nth-child(4)),
:where([dir="rtl"]) :where(.z-grid[data-pin-start="5"] > table > * > tr > :nth-child(5)) { box-shadow: inset 1px 0 0 var(--z-border-strong); }

:where(.z-grid thead th[data-pin]),
:where(.z-grid .z-filter-row td[data-pin]),
:where(.z-grid tfoot td) { background-color: var(--z-surface-2); }

/**
 * Menus: column menus and context menus. Items are buttons with menu roles;
 * the check mark shows aria-checked.
 */

.z-menu {
  min-width: 13rem;
  max-height: min(34rem, 90dvh);
  padding: 4px;
}

.z-menu-item {
  display: flex;
  align-items: center;
  gap: calc(var(--z-space) * 2);
  width: 100%;
  min-height: 30px;
  padding: 0 calc(var(--z-space) * 2) 0 calc(var(--z-space) * 7);
  border: 0;
  border-radius: var(--z-radius-sm);
  background: transparent;
  color: var(--z-text);
  font: inherit;
  text-align: start;
  cursor: pointer;
  position: relative;
}

.z-menu-item:hover,
.z-menu-item:focus { background: var(--z-hover); outline: none; }

.z-menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--z-focus); }

.z-menu-item[aria-disabled="true"] { color: var(--z-text-muted); cursor: default; }

.z-menu-item[aria-checked="true"]::before {
  content: "";
  position: absolute;
  inset-inline-start: calc(var(--z-space) * 2);
  width: 12px;
  height: 12px;
  background: currentColor;
  -webkit-mask: var(--z-check) center / contain no-repeat;
  mask: var(--z-check) center / contain no-repeat;
  --z-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 6.5l2.5 2.5L10 3'/%3E%3C/svg%3E");
}

.z-menu-item[aria-haspopup="menu"]::after {
  content: "";
  margin-inline-start: auto;
  width: 6px;
  height: 6px;
  border-block-start: 1.5px solid currentColor;
  border-inline-end: 1.5px solid currentColor;
  transform: rotate(45deg);
}

[dir="rtl"] .z-menu-item[aria-haspopup="menu"]::after { transform: rotate(-135deg); }

.z-menu-label { flex: 1 1 auto; }

.z-menu-hint {
  color: var(--z-text-muted);
  font-size: var(--z-font-size-xs);
  font-family: var(--z-font-mono);
}

.z-menu-item .z-icon { margin-inline-start: calc(var(--z-space) * -5); }

.z-menu-sep {
  height: 1px;
  margin: 4px 0;
  background: var(--z-border);
}

/**
 * Cell components: badges, progress bars, yes/no icons, links and row action buttons.
 */

.z-badge {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: var(--z-font-size-xs);
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  --z-tone: var(--z-text-muted);
  color: color-mix(in oklab, var(--z-tone) 85%, var(--z-text));
  background: color-mix(in oklab, var(--z-tone) var(--z-tint), var(--z-surface));
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--z-tone) 30%, transparent);
}

.z-tone-info { --z-tone: var(--z-info); }
.z-tone-success { --z-tone: var(--z-success); }
.z-tone-warning { --z-tone: var(--z-warning); }
.z-tone-danger { --z-tone: var(--z-danger); }
.z-tone-brand { --z-tone: var(--z-accent); }

.z-progress {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--z-space) * 2);
  width: 100%;
}

.z-progress-track {
  flex: 1 1 auto;
  height: 6px;
  min-width: 32px;
  border-radius: 3px;
  background: var(--z-hover);
  overflow: hidden;
}

.z-progress-bar {
  display: block;
  width: var(--z-pct, 0%);
  height: 100%;
  border-radius: 3px;
  background: var(--z-accent);
}

.z-progress-text { flex: none; min-width: 3ch; text-align: end; }

.z-bool {
  display: inline-block;
  width: 14px;
  height: 14px;
  background: currentColor;
  vertical-align: middle;
  -webkit-mask: var(--z-b) center / contain no-repeat;
  mask: var(--z-b) center / contain no-repeat;
}

.z-bool-yes {
  color: var(--z-success);
  --z-b: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 7.5l3 3 6-7'/%3E%3C/svg%3E");
}

.z-bool-no {
  color: var(--z-text-muted);
  --z-b: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M3.5 7h7'/%3E%3C/svg%3E");
}

.z-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--z-accent);
  font: inherit;
  text-align: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.z-link:hover { text-decoration-thickness: 2px; }

.z-grid td.z-row-actions,
.z-grid th.z-actions-col { width: 1%; white-space: nowrap; }

.z-row-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--z-radius-sm);
  background: transparent;
  color: var(--z-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.z-row-action + .z-row-action { margin-inline-start: 2px; }

.z-row-action:hover { background: var(--z-brand-subtle); border-color: color-mix(in oklab, var(--z-accent) 30%, transparent); }

.z-row-action:disabled { opacity: 0.5; cursor: progress; }

/**
 * Row selection: checkbox column and the selection bar above the grid.
 */

.z-grid th.z-select-col,
.z-grid td.z-row-select { width: 36px; padding-inline: 0; text-align: center; }

.z-row-select input,
.z-select-col input { width: 16px; height: 16px; margin: 0; accent-color: var(--z-accent); cursor: pointer; }

.z-grid tbody tr[aria-selected="true"] > td { background: var(--z-brand-subtle); }

.z-bulk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--z-space) * 2);
  margin-block-end: calc(var(--z-space) * 2);
  padding: calc(var(--z-space) * 1.5) calc(var(--z-space) * 3);
  border: 1px solid color-mix(in oklab, var(--z-accent) 35%, var(--z-border));
  border-radius: var(--z-radius);
  background: var(--z-brand-subtle);
}

.z-bulk[hidden] { display: none; }

.z-bulk-count { font-weight: 600; margin-inline-end: auto; }

/**
 * Inline editing: inputs fill their cell; errors show under the input.
 */

.z-grid tbody tr.z-editing > td { background: var(--z-surface); padding-block: 2px; }

.z-grid tbody tr.z-editing { box-shadow: inset 0 0 0 2px var(--z-accent); }

.z-grid td[data-v] { cursor: text; }


.z-cell-input {
  width: 100%;
  min-width: 4rem;
  min-height: max(24px, calc(var(--z-row) - 6px));
  padding: 0 6px;
  border: 1px solid var(--z-border-strong);
  border-radius: var(--z-radius-sm);
  background: var(--z-surface);
  color: var(--z-text);
  font: inherit;
  text-align: inherit;
}

.z-cell-input[type="checkbox"] { width: 16px; min-width: 0; min-height: 0; accent-color: var(--z-accent); }

.z-cell-input[aria-invalid="true"] { border-color: var(--z-danger); }

.z-cell-error {
  display: block;
  margin-top: 2px;
  color: var(--z-danger);
  font-size: var(--z-font-size-xs);
  white-space: normal;
}

.z-toast-action {
  margin-inline-start: calc(var(--z-space) * 3);
  padding: 2px 8px;
  border: 1px solid currentColor;
  border-radius: var(--z-radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.z-grid-state {
  position: sticky;
  inset-inline-start: 0;
  width: var(--z-view-w, 100%);
  box-sizing: border-box;
  padding: calc(var(--z-space) * 8) calc(var(--z-space) * 4);
  color: var(--z-text-muted);
  text-align: center;
}

.z-grid-state[data-kind="error"] { color: var(--z-danger); }

.z-grid-state[hidden] { display: none; }

.z-sort-order {
  display: inline-grid;
  place-items: center;
  min-width: 1.25em;
  height: 1.25em;
  padding-inline: 2px;
  border-radius: 999px;
  background: var(--z-brand-subtle);
  color: var(--z-accent);
  font-size: 0.6875rem;
  line-height: 1;
}

.z-grid tbody td { color: var(--z-text); }

.z-grid tbody tr:last-child > td { border-bottom-color: transparent; }

.z-grid tbody tr:nth-child(even):not([data-zeyn-index]) > td,
.z-grid tbody tr.z-alt > td { background: var(--z-surface-2); }

.z-grid[data-zeyn-paging="virtual"] {
  overflow-anchor: none;
  contain: content;
}

.z-grid[data-zeyn-paging="virtual"] table { table-layout: fixed; }

.z-grid[data-zeyn-paging="virtual"] [data-zeyn-rows] {
  will-change: transform;
}

.z-grid[data-zeyn-paging="virtual"] [data-zeyn-rows] td {
  box-sizing: border-box;
  height: var(--z-row-height, 32px);
  max-height: var(--z-row-height, 32px);
  padding-block: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.z-grid[data-zeyn-paging="virtual"] [data-zeyn-rows] tr:last-child td { border-bottom-color: var(--z-border); }

.z-spacer td {
  height: auto;
  padding: 0;
  border: 0;
}

.z-placeholder td::before {
  content: "";
  display: block;
  width: 56%;
  height: 0.5em;
  border-radius: 2px;
  background: var(--z-hover);
}

.z-grid tbody tr:hover > td { background: var(--z-hover); }

.z-grid tbody tr[data-zeyn-effect] { cursor: default; }

.z-grid tbody tr:focus { outline: none; }

.z-grid tbody tr:focus > td { background: var(--z-brand-subtle); }

.z-grid tbody tr:focus > td:first-child { box-shadow: inset 2px 0 0 var(--z-accent); }

.z-grid tbody tr:focus-visible > td {
  box-shadow: inset 0 2px 0 var(--z-focus), inset 0 -2px 0 var(--z-focus);
}

.z-grid tbody tr:focus-visible > td:first-child {
  box-shadow: inset 2px 2px 0 var(--z-focus), inset 0 -2px 0 var(--z-focus);
}

.z-grid tbody tr:focus-visible > td:last-child {
  box-shadow: inset -2px 2px 0 var(--z-focus), inset 0 -2px 0 var(--z-focus);
}

.z-num,
.z-grid .z-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.z-grid tbody tr.z-row-warning > td { background: var(--z-warning-subtle); }
.z-grid tbody tr.z-row-danger > td { background: var(--z-danger-subtle); }
.z-grid tbody tr.z-row-success > td { background: var(--z-success-subtle); }
.z-grid tbody tr.z-row-warning > td:first-child { box-shadow: inset 3px 0 0 var(--z-warning); }
.z-grid tbody tr.z-row-danger > td:first-child { box-shadow: inset 3px 0 0 var(--z-danger); }
.z-grid tbody tr.z-row-success > td:first-child { box-shadow: inset 3px 0 0 var(--z-success); }
.z-grid tbody tr.z-row-muted > td { color: var(--z-text-muted); }

.z-grid tbody tr.z-row-warning:hover > td,
.z-grid tbody tr.z-row-danger:hover > td,
.z-grid tbody tr.z-row-success:hover > td { background: color-mix(in oklab, var(--z-hover) 50%, transparent); }

/* Cell cursor, cell ranges, paste errors and column virtualization gaps. */

.z-grid tbody td:focus { outline: 2px solid var(--z-accent); outline-offset: -2px; }

.z-grid tbody tr:has(> td:focus) > td { background: var(--z-brand-subtle); }

.z-grid tbody tr > td[aria-selected="true"] { background: color-mix(in oklab, var(--z-accent) 18%, var(--z-surface)); }

.z-grid tbody tr > td[aria-invalid="true"] { box-shadow: inset 0 -2px 0 var(--z-danger); }

.z-grid .z-col-gap { padding: 0; }

/* Grouping and trees: group header rows, indented tree cells and "Load more" rows. */

.z-grid tbody tr.z-group:nth-child(n) > td { background: var(--z-surface-2); }

.z-grid tbody tr.z-group:hover > td { background: var(--z-hover); }

.z-grid tbody tr.z-group > td:not(:first-child) { position: static; }

.z-group-head,
.z-tree {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-inline-start: calc(var(--z-level, 0) * 20px);
  white-space: nowrap;
}

.z-group-count { color: var(--z-text-muted); }

.z-tree-spacer { flex: none; width: 24px; }

.z-grid tbody tr.z-branch-more > td { padding-inline-start: calc(var(--z-space) * 12); }

/* Master detail: the expander column and the row that holds an opened detail screen. */

.z-grid th.z-expand-col,
.z-grid td.z-expand { width: 36px; padding-inline: 0; text-align: center; }

.z-expander {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--z-radius-sm);
  background: transparent;
  color: var(--z-text-muted);
  cursor: pointer;
}

.z-expander::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.12s ease;
}

:where([dir="rtl"]) .z-expander::before { transform: rotate(135deg); }

.z-expander[aria-expanded="true"]::before { transform: rotate(45deg); }

.z-expander:hover { background: var(--z-hover); color: var(--z-text); }

.z-expander:focus-visible { outline: 2px solid var(--z-accent); outline-offset: -2px; }

.z-grid tbody tr.z-detail:nth-child(n) > td {
  position: static;
  height: auto;
  padding: calc(var(--z-space) * 3) calc(var(--z-space) * 3) calc(var(--z-space) * 4);
  background: var(--z-surface-2);
  box-shadow: inset 3px 0 0 var(--z-accent);
  white-space: normal;
}

.z-detail-body {
  position: sticky;
  inset-inline-start: calc(var(--z-space) * 3);
  max-width: calc(var(--z-view-w, 100%) - var(--z-space) * 8);
  color: var(--z-text);
}

.z-detail-body > .z-screen,
.z-detail-body > .z-window { width: auto; padding: 0; }

.z-detail-body h3 { margin: 0; font-size: var(--z-font-size-sm); font-weight: 600; }

.z-detail-body .z-form-actions { position: static; margin: 0; padding: 0; border: 0; background: none; }

.z-grid tfoot td {
  position: sticky;
  bottom: 0;
  background: var(--z-surface-2);
  font-weight: 600;
  border-top: 1px solid var(--z-border-strong);
  border-bottom: 0;
}

.z-grid tfoot td[data-agg] { white-space: nowrap; }

.z-grid:has(> .z-pager) tfoot td {
  bottom: calc(max(24px, calc(var(--z-control) - 4px)) + var(--z-space) * 3 + 1px);
}

.z-agg { display: inline-flex; align-items: baseline; gap: 0.35em; }

.z-agg + .z-agg { margin-inline-start: 1em; }

.z-agg-label {
  color: var(--z-text-muted);
  font-size: var(--z-font-size-xs);
  font-weight: 500;
}

.z-grid[aria-busy="true"] tbody { opacity: 0.6; }

.z-pager {
  position: sticky;
  bottom: 0;
  inset-inline-start: 0;
  z-index: 3;
  box-sizing: border-box;
  width: var(--z-view-w, 100%);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: calc(var(--z-space) * 2);
  padding: calc(var(--z-space) * 1.5) calc(var(--z-space) * 3);
  background: var(--z-surface);
  border-top: 1px solid var(--z-border);
}

.z-pager .z-button {
  min-width: 28px;
  min-height: max(24px, calc(var(--z-control) - 4px));
  padding: 0 6px;
  font-size: 1.125rem;
  line-height: 1;
}

.z-page-info {
  min-width: 10ch;
  text-align: center;
  color: var(--z-text-muted);
  font-size: var(--z-font-size-xs);
  font-variant-numeric: tabular-nums;
}

.z-more {
  display: flex;
  justify-content: center;
  padding: calc(var(--z-space) * 2);
}

@media (max-width: 800px) {
  .z-grid table { min-width: 36rem; }
}


/**
 * Forms. Labels are quiet, values are full strength; numbers align right.
 */

.z-form {
  display: flex;
  flex-direction: column;
  gap: calc(var(--z-space) * 4);
  max-width: 760px;
}

.z-form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  gap: calc(var(--z-space) * 4);
}

.z-field {
  display: flex;
  flex-direction: column;
  gap: calc(var(--z-space) * 1 + 1px);
  min-width: 0;
}

.z-field label {
  font-size: var(--z-font-size-sm);
  font-weight: 500;
  color: var(--z-text-muted);
}

.z-required {
  margin-left: 2px;
  color: var(--z-danger);
}

.z-field input:not([type="checkbox"]):not([type="radio"]),
.z-field select,
.z-field textarea,
select[data-zeyn-locale],
select[data-zeyn-timezone],
select[data-zeyn-theme-picker] {
  width: 100%;
  min-height: var(--z-control);
  padding: 0 calc(var(--z-space) * 2 + 2px);
  border: 1px solid var(--z-border-strong);
  border-radius: var(--z-radius);
  background: var(--z-surface);
  color: var(--z-text);
  font: inherit;
}

.z-field textarea { padding-block: calc(var(--z-space) * 1.5); min-height: calc(var(--z-control) * 2.5); }

.z-field input:not([type="checkbox"]):not([type="radio"]):hover,
.z-field select:hover,
.z-field textarea:hover { border-color: var(--z-text-muted); }

.z-field input:focus-visible,
.z-field select:focus-visible,
.z-field textarea:focus-visible {
  outline: 2px solid var(--z-focus);
  outline-offset: -1px;
  border-color: var(--z-focus);
}

.z-field input[readonly] {
  background: var(--z-surface-2);
  border-color: var(--z-border);
  color: var(--z-text-muted);
}

.z-field input:disabled,
.z-field select:disabled,
.z-field textarea:disabled {
  background: var(--z-surface-2);
  border-color: var(--z-border);
  color: var(--z-text-muted);
  cursor: not-allowed;
}

.z-field input.z-num { text-align: right; }

.z-field:has(> input[type="checkbox"]) {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-height: var(--z-control);
}

.z-form-row > .z-field:has(> input[type="checkbox"]) { align-self: end; }

.z-field:has(> input[type="checkbox"]) label {
  order: 1;
  font-size: var(--z-font-size);
  font-weight: 400;
  color: var(--z-text);
}

.z-field:has(> input[type="checkbox"]) .z-field-error { order: 2; flex-basis: 100%; }

.z-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 3px;
  accent-color: var(--z-accent);
}

.z-field [aria-invalid="true"] {
  border-color: var(--z-danger) !important;
  box-shadow: inset 0 0 0 1px var(--z-danger);
}

.z-field input[type="checkbox"][aria-invalid="true"] { outline: 2px solid var(--z-danger); box-shadow: none; }

.z-field-error {
  margin: 0;
  font-size: var(--z-font-size-sm);
  color: var(--z-danger);
}

.z-field-error:empty { display: none; }

.z-form-errors {
  padding: calc(var(--z-space) * 2.5) calc(var(--z-space) * 3);
  border: 1px solid color-mix(in oklab, var(--z-danger) 40%, var(--z-surface));
  border-left: 3px solid var(--z-danger);
  border-radius: var(--z-radius);
  background: var(--z-danger-subtle);
  color: var(--z-text);
}

.z-form-errors p { margin: 0; }
.z-form-errors p + p { margin-top: 4px; }

.z-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: calc(var(--z-space) * 2);
  padding-top: calc(var(--z-space) * 1);
}

.z-form[aria-busy="true"] { cursor: progress; }

.z-locale {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: auto 0 0;
  padding: calc(var(--z-space) * 3) 10px 0;
  font-size: var(--z-font-size-xs);
  font-weight: 600;
  color: var(--z-text-muted);
}

.z-locale + .z-locale { margin-top: 0; }

select[data-zeyn-locale],
select[data-zeyn-timezone],
select[data-zeyn-theme-picker] {
  min-height: max(24px, calc(var(--z-control) - 4px));
  font-size: var(--z-font-size-sm);
  font-weight: 400;
}


/**
 * API reference page.
 */

.z-api-docs { max-width: 960px; }

.z-api-docs > p {
  margin: 0;
  max-width: 72ch;
  color: var(--z-text-muted);
}

.z-api-op {
  padding: calc(var(--z-space) * 4) calc(var(--z-space) * 5) calc(var(--z-space) * 5);
  background: var(--z-surface);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius);
}

.z-api-op h2 {
  margin: 0 0 calc(var(--z-space) * 2);
  font-size: 0.9375rem;
  font-weight: 600;
}

.z-api-op h2 code { font-size: 1em; }

.z-api-op h3 {
  margin: calc(var(--z-space) * 4) 0 calc(var(--z-space) * 1.5);
  font-size: var(--z-font-size-sm);
  font-weight: 600;
  color: var(--z-text-muted);
}

.z-api-op p { margin: 0; max-width: 80ch; }

.z-api-op pre {
  margin: 0;
  padding: calc(var(--z-space) * 3);
  overflow: auto;
  max-height: 24rem;
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-sm);
  font-size: var(--z-font-size-xs);
  line-height: 1.55;
  tab-size: 2;
}

.z-api-op pre + p { margin-top: calc(var(--z-space) * 3); color: var(--z-text-muted); }

.z-api-docs :not(pre) > code {
  padding: 1px 4px;
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-sm);
}

.z-api-op h2 code { padding: 0; background: none; border: 0; }


/**
 * Toasts.
 */

.z-toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}

.z-toast {
  padding: calc(var(--z-space) * 2.5) calc(var(--z-space) * 4) calc(var(--z-space) * 2.5) calc(var(--z-space) * 3.5);
  border: 1px solid var(--z-border);
  border-left: 3px solid var(--z-info);
  border-radius: var(--z-radius);
  background: var(--z-surface);
  color: var(--z-text);
  box-shadow: var(--z-shadow-2);
  pointer-events: auto;
  animation: z-toast-in 140ms ease-out;
}

.z-toast-error {
  border-left-color: var(--z-danger);
  background: var(--z-danger-subtle);
}

@keyframes z-toast-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (forced-colors: active) {
  .z-icon,
  .z-sort::after { background: CanvasText; }
  .z-button.z-primary .z-icon { background: HighlightText; }
  .z-app-name { border-bottom: 1px solid CanvasText; }
  .z-nav a[aria-current="page"] { outline: 2px solid Highlight; outline-offset: -2px; }
  .z-button.z-primary { forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight; }
  .z-grid tbody tr:focus > td { background: Highlight; color: HighlightText; forced-color-adjust: none; }
  .z-grid tbody tr:focus-visible { outline: 2px solid CanvasText; }
  .z-grid tbody tr.z-row-warning > td:first-child,
  .z-grid tbody tr.z-row-danger > td:first-child,
  .z-grid tbody tr.z-row-success > td:first-child { border-left: 3px solid CanvasText; }
  .z-placeholder td::before { background: GrayText; }
  .z-toast, .z-form-errors, .z-screen.z-error { border-left-color: CanvasText; }
}

.z-col-moving, .z-col-moving * { cursor: grabbing !important; user-select: none; }
.z-grid th.z-col-dragging { opacity: 0.55; }
.z-grid th.z-col-drop-start { box-shadow: inset 3px 0 0 var(--z-accent); }
.z-grid th.z-col-drop-end { box-shadow: inset -3px 0 0 var(--z-accent); }
[dir="rtl"] .z-grid th.z-col-drop-start { box-shadow: inset -3px 0 0 var(--z-accent); }
[dir="rtl"] .z-grid th.z-col-drop-end { box-shadow: inset 3px 0 0 var(--z-accent); }

/*
 * Prose and code: long text rendered on the server, such as documentation pages. Syntax colors
 * use the status and accent tokens, which reach 4.5:1 on --z-surface-2 in both themes.
 * .z-doc lays out an article with an "On this page" aside; .z-doc-live holds a live component.
 */
.z-doc {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px);
  gap: calc(var(--z-space) * 8);
  align-items: start;
}

.z-prose {
  max-width: 78ch;
  min-width: 0;
  line-height: 1.6;
}

.z-prose h2,
.z-prose h3,
.z-prose h4 {
  margin: calc(var(--z-space) * 7) 0 calc(var(--z-space) * 2);
  line-height: 1.3;
  scroll-margin-top: calc(var(--z-space) * 4);
}

.z-prose h2 { font-size: 1.125rem; font-weight: 600; padding-bottom: calc(var(--z-space) * 1); border-bottom: 1px solid var(--z-border); }
.z-prose h3 { font-size: 1rem; font-weight: 600; }
.z-prose h4 { font-size: var(--z-font-size); font-weight: 600; }
.z-prose > :first-child { margin-top: 0; }
.z-prose p, .z-prose ul, .z-prose ol, .z-prose table, .z-prose pre { margin: 0 0 calc(var(--z-space) * 3); }
.z-prose ul, .z-prose ol { padding-inline-start: 1.5em; }
.z-prose li + li { margin-top: calc(var(--z-space) * 1); }
.z-prose a { color: var(--z-accent); text-underline-offset: 2px; }
.z-prose :not(pre) > code {
  padding: 1px 4px;
  font-family: var(--z-font-mono);
  font-size: 0.9em;
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius-sm);
}

.z-prose table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: var(--z-font-size-sm);
}

.z-prose th,
.z-prose td {
  padding: calc(var(--z-space) * 1.5) calc(var(--z-space) * 3);
  text-align: start;
  vertical-align: top;
  border: 1px solid var(--z-border);
}

.z-prose th { background: var(--z-surface-2); font-weight: 600; }

.z-code {
  overflow-x: auto;
  padding: calc(var(--z-space) * 3) calc(var(--z-space) * 4);
  font-family: var(--z-font-mono);
  font-size: var(--z-font-size-sm);
  line-height: 1.5;
  tab-size: 4;
  color: var(--z-text);
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius);
}

.z-code:focus-visible { outline: 2px solid var(--z-focus); outline-offset: 2px; }
.z-hl-kw { color: var(--z-accent); font-weight: 600; }
.z-hl-str { color: var(--z-success); }
.z-hl-num { color: var(--z-warning); }
.z-hl-com { color: var(--z-text-muted); font-style: italic; }
.z-hl-ty, .z-hl-key { color: var(--z-info); }
.z-hl-mac { color: var(--z-danger); }

.z-doc-live {
  margin: 0 0 calc(var(--z-space) * 4);
  padding: calc(var(--z-space) * 4);
  background: var(--z-bg);
  border: 1px dashed var(--z-border-strong);
  border-radius: var(--z-radius);
}

.z-doc-live > .z-doc-live-label {
  margin: 0 0 calc(var(--z-space) * 2);
  font-size: var(--z-font-size-xs);
  font-weight: 600;
  color: var(--z-text-muted);
}

.z-doc-toc {
  position: sticky;
  top: calc(var(--z-space) * 4);
  font-size: var(--z-font-size-sm);
}

.z-doc-toc h2 { margin: 0 0 calc(var(--z-space) * 2); font-size: var(--z-font-size-xs); font-weight: 600; color: var(--z-text-muted); }
.z-doc-toc ul { margin: 0; padding: 0; list-style: none; }
.z-doc-toc li { margin: 0 0 calc(var(--z-space) * 1.5); }
.z-doc-toc li.z-doc-toc-sub { padding-inline-start: calc(var(--z-space) * 3); }
.z-doc-toc a { color: var(--z-text-muted); text-decoration: none; }
.z-doc-toc a:hover { color: var(--z-accent); text-decoration: underline; }

.z-doc-pager {
  display: flex;
  justify-content: space-between;
  gap: calc(var(--z-space) * 3);
  margin-top: calc(var(--z-space) * 8);
  padding-top: calc(var(--z-space) * 4);
  border-top: 1px solid var(--z-border);
}

.z-doc-pager a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 24px;
  padding: calc(var(--z-space) * 2) calc(var(--z-space) * 3);
  color: var(--z-accent);
  text-decoration: none;
  border: 1px solid var(--z-border);
  border-radius: var(--z-radius);
}

.z-doc-pager a:hover { background: var(--z-hover); }
.z-doc-pager a span { font-size: var(--z-font-size-xs); color: var(--z-text-muted); }
.z-doc-pager .z-doc-next { margin-inline-start: auto; text-align: end; }

@media (max-width: 1100px) {
  .z-doc { grid-template-columns: minmax(0, 1fr); }
  .z-doc-toc { position: static; order: -1; }
}

@media (forced-colors: active) {
  .z-hl-kw, .z-hl-str, .z-hl-num, .z-hl-com, .z-hl-ty, .z-hl-key, .z-hl-mac { color: CanvasText; }
  .z-code { border-color: CanvasText; }
}
