/* mzool design system.
   Tokens are CSS custom properties; a later stylesheet may override --brand.
   Light theme by default, dark theme from the OS or <html data-theme="dark">. */

/* ---------- Tokens ---------- */

:root {
  color-scheme: light;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Noto Sans Arabic", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --brand: #5b5bd6;
  --on-brand: #ffffff;
  --brand-hover: color-mix(in oklab, var(--brand) 86%, #000);
  --brand-fg: color-mix(in oklab, var(--brand) 88%, var(--text));
  --brand-soft: color-mix(in oklab, var(--brand) 12%, var(--surface));
  --brand-softer: color-mix(in oklab, var(--brand) 7%, var(--surface));
  --brand-line: color-mix(in oklab, var(--brand) 35%, transparent);

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f0f2f5;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --input-border: #d5dae2;
  --text: #161a22;
  --text-2: #344054;
  --muted: #5f6878;
  --subtle: #687082; /* 4.6:1 on white: placeholders and labels stay readable */

  --success: #16803c;
  --warning: #b45309;
  --danger: #d1293d;
  --info: #1d64d8;
  --success-soft: color-mix(in oklab, var(--success) 11%, var(--surface));
  --warning-soft: color-mix(in oklab, var(--warning) 12%, var(--surface));
  --danger-soft: color-mix(in oklab, var(--danger) 9%, var(--surface));
  --info-soft: color-mix(in oklab, var(--info) 10%, var(--surface));

  --toast-bg: #1d2129;
  --toast-text: #f4f5f8;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;

  --shadow-xs: 0 1px 2px rgb(16 24 40 / 0.05);
  --shadow-sm: 0 1px 3px rgb(16 24 40 / 0.08), 0 1px 2px rgb(16 24 40 / 0.04);
  --shadow-md: 0 6px 16px -4px rgb(16 24 40 / 0.1), 0 2px 4px -2px rgb(16 24 40 / 0.05);
  --shadow-lg: 0 18px 40px -12px rgb(16 24 40 / 0.22), 0 6px 12px -6px rgb(16 24 40 / 0.08);
  --ring: 0 0 0 3px color-mix(in oklab, var(--brand) 28%, transparent);
  --ring-danger: 0 0 0 3px color-mix(in oklab, var(--danger) 22%, transparent);

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs: 14px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 21px;
  --fs-2xl: 26px;

  --topbar-h: 52px;
  --sidebar-w: 236px;
  --sheet-w: 1120px;
  --control-h: 34px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* Tag and app colors. */
  --c0: #64748b;
  --c1: #e5484d;
  --c2: #f76b15;
  --c3: #c99400;
  --c4: #0894b3;
  --c5: #8e4ec6;
  --c6: #a07553;
  --c7: #12a594;
  --c8: #0d74ce;
  --c9: #d6409f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #6363dd; /* white text on it is 4.8:1 */
    --on-brand: #ffffff;
    --brand-hover: color-mix(in oklab, var(--brand) 88%, #fff);
    --brand-fg: color-mix(in oklab, var(--brand) 70%, #fff);
    --brand-soft: color-mix(in oklab, var(--brand) 20%, var(--surface));
    --brand-softer: color-mix(in oklab, var(--brand) 11%, var(--surface));
    --bg: #0d0f14;
    --surface: #15181f;
    --surface-2: #191d25;
    --surface-3: #20252f;
    --border: #272c36;
    --border-strong: #363d4a;
    --input-border: #343b48;
    --text: #e8ebf1;
    --text-2: #c5cad4;
    --muted: #9aa2b1;
    --subtle: #8a92a3;
    --success: #3fbf6e;
    --warning: #e6a23c;
    --danger: #f2596b;
    --info: #5d9bf7;
    --toast-bg: #eceef3;
    --toast-text: #14171d;
    --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.35);
    --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.45);
    --shadow-md: 0 8px 20px -6px rgb(0 0 0 / 0.55);
    --shadow-lg: 0 22px 48px -12px rgb(0 0 0 / 0.7), 0 0 0 1px rgb(255 255 255 / 0.04);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #6363dd;
  --on-brand: #ffffff;
  --brand-hover: color-mix(in oklab, var(--brand) 88%, #fff);
  --brand-fg: color-mix(in oklab, var(--brand) 70%, #fff);
  --brand-soft: color-mix(in oklab, var(--brand) 20%, var(--surface));
  --brand-softer: color-mix(in oklab, var(--brand) 11%, var(--surface));
  --bg: #0d0f14;
  --surface: #15181f;
  --surface-2: #191d25;
  --surface-3: #20252f;
  --border: #272c36;
  --border-strong: #363d4a;
  --input-border: #343b48;
  --text: #e8ebf1;
  --text-2: #c5cad4;
  --muted: #9aa2b1;
  --subtle: #8a92a3;
  --success: #3fbf6e;
  --warning: #e6a23c;
  --danger: #f2596b;
  --info: #5d9bf7;
  --toast-bg: #eceef3;
  --toast-text: #14171d;
  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.35);
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.45);
  --shadow-md: 0 8px 20px -6px rgb(0 0 0 / 0.55);
  --shadow-lg: 0 22px 48px -12px rgb(0 0 0 / 0.7), 0 0 0 1px rgb(255 255 255 / 0.04);
}

/* ---------- Base ---------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs)/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--text); }
p { margin: 0; }
a { color: var(--brand-fg); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: inline-block; }
::selection { background: color-mix(in oklab, var(--brand) 26%, transparent); }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--radius-xs); }

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

/* "Skip to content": the first stop of the keyboard, shown when focused. */
.skip-link {
  position: fixed;
  inset-block-start: 8px; inset-inline-start: 8px;
  z-index: 200;
  padding: 8px 14px;
  border-radius: var(--radius);
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
  transform: translateY(-200%);
}
.skip-link:focus, .skip-link:focus-visible { transform: none; outline: none; box-shadow: var(--ring); text-decoration: none; }
main[tabindex="-1"]:focus { outline: none; }

.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.mono { font-family: var(--font-mono); font-size: 13px; }
.num, .is-num { font-variant-numeric: tabular-nums; }
.empty { color: var(--subtle); }
.link { color: var(--brand-fg); }

/* Icons: one sprite, stroked with the current color. */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 18px; height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: middle;
}
.icon-sm { width: 15px; height: 15px; }

/* ---------- App shell ---------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "top top" "side main";
  min-height: 100vh;
  min-height: 100dvh;
}
.shell.no-sidebar {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "top" "main";
}

.topbar {
  grid-area: top;
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  height: var(--topbar-h);
  padding-block: 0; padding-inline: var(--sp-2) var(--sp-3);
  background: color-mix(in oklab, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
/* A thin progress bar while a page loads. */
.topbar::after {
  content: "";
  position: absolute;
  inset-inline-start: 0; bottom: -1px;
  height: 2px; width: 100%;
  background: linear-gradient(90deg, transparent, var(--brand), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
html.is-loading .topbar::after {
  opacity: 1;
  animation: progress 1s var(--ease) infinite;
  transition-delay: 0.15s;
}
[dir="rtl"].is-loading .topbar::after { animation-direction: reverse; } /* it runs the way text reads */
@keyframes progress {
  from { background-position: -40% 0; }
  to { background-position: 140% 0; }
}

.topbar-start, .topbar-end { display: flex; align-items: center; gap: var(--sp-1); min-width: 0; }
.topbar-start { flex: 1; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding-block: 4px; padding-inline: 4px 8px;
  margin-inline-start: 2px;
  border-radius: var(--radius);
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; background: var(--surface-3); }
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(140deg, color-mix(in oklab, var(--brand) 70%, #fff), var(--brand) 55%, color-mix(in oklab, var(--brand) 75%, #000));
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25), 0 2px 6px -1px color-mix(in oklab, var(--brand) 50%, transparent);
}
.brand-mark .icon { width: 15px; height: 15px; stroke-width: 2.2; }
.brand-mark-lg { width: 44px; height: 44px; border-radius: 13px; }
.brand-logo { display: block; height: 26px; width: auto; max-width: 140px; object-fit: contain; border-radius: 6px; }
.brand-logo-lg { height: 44px; max-width: 200px; border-radius: 10px; }
.brand-mark-lg .icon { width: 24px; height: 24px; }

.crumbs { min-width: 0; padding-inline-start: var(--sp-3); margin-inline-start: var(--sp-1); border-inline-start: 1px solid var(--border); }
.crumbs ol { display: flex; align-items: center; list-style: none; margin: 0; padding: 0; min-width: 0; font-size: var(--fs-sm); }
.crumbs li { display: flex; align-items: center; min-width: 0; color: var(--muted); white-space: nowrap; }
.crumbs li + li::before { content: "/"; margin: 0 8px; color: var(--border-strong); }
.crumbs a { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.crumbs a:hover { color: var(--text); text-decoration: none; }
.crumbs [aria-current="page"] { color: var(--text); font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.crumbs .crumb-app { color: var(--text); font-weight: 600; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--control-h); height: var(--control-h);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.icon-btn[aria-expanded="true"] { background: var(--surface-3); color: var(--text); }
.icon-btn-sm { width: 28px; height: 28px; border-radius: var(--radius-sm); }
.icon-btn-sm .icon { width: 16px; height: 16px; }
.icon-btn.is-disabled { opacity: 0.35; pointer-events: none; }
.drawer-toggle { display: none; }

/* The theme toggle shows a moon in light mode and a sun in dark mode. */
.theme-icon-dark { display: none; }
:root[data-theme="dark"] .theme-icon-dark { display: block; }
:root[data-theme="dark"] .theme-icon-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-dark { display: block; }
  :root:not([data-theme="light"]) .theme-icon-light { display: none; }
}

.user-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--control-h);
  padding-block: 0; padding-inline: 4px 8px;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-2);
  font-weight: 550;
  cursor: pointer;
}
.user-btn:hover, .user-btn[aria-expanded="true"] { background: var(--surface-3); }
.user-btn .icon { color: var(--subtle); }

.avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-fg);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.avatar-lg { width: 38px; height: 38px; font-size: 14px; }
.avatar-xl { width: 64px; height: 64px; font-size: 22px; }

.sidebar {
  grid-area: side;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--sp-3) var(--sp-2) var(--sp-6);
  background: var(--surface);
  border-inline-end: 1px solid var(--border);
}
.sidenav { display: flex; flex-direction: column; gap: 1px; }
.sidenav-section { display: flex; flex-direction: column; gap: 1px; margin-top: var(--sp-3); }
.sidenav-section:first-child { margin-top: 0; }
.sidenav-heading {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 4px;
  color: var(--subtle);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.sidenav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}
.sidenav-link .icon { color: var(--subtle); width: 17px; height: 17px; }
.sidenav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.sidenav-link.is-active { background: var(--brand-soft); color: var(--brand-fg); font-weight: 600; }
.sidenav-link.is-active .icon { color: var(--brand-fg); }
.sidenav-link.is-active::before {
  content: "";
  position: absolute;
  inset-inline-start: -8px; top: 8px; bottom: 8px;
  width: 3px;
  border-start-end-radius: 3px; border-end-end-radius: 3px;
  background: var(--brand);
}

.drawer-backdrop { display: none; }

.main {
  grid-area: main;
  min-width: 0;
  padding: var(--sp-5) var(--sp-8) var(--sp-10);
}

.bare {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--sp-6) var(--sp-4);
  background:
    radial-gradient(1100px 520px at 0% -10%, color-mix(in oklab, var(--brand) 16%, transparent), transparent 62%),
    radial-gradient(900px 460px at 105% 110%, color-mix(in oklab, var(--c7) 10%, transparent), transparent 60%),
    var(--bg);
}

/* ---------- Dropdowns ---------- */

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-start: 0;
  z-index: 40;
  min-width: 230px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.14s var(--ease);
  transform-origin: top left;
}
.dropdown-end { inset-inline-start: auto; inset-inline-end: 0; transform-origin: top right; }
[dir="rtl"] .dropdown-menu { transform-origin: top right; }
[dir="rtl"] .dropdown-end { transform-origin: top left; }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.dropdown-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 10px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.dropdown-header > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.dropdown-header strong { font-weight: 600; }
.dropdown-form { margin: 0; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
  text-align: start;
  cursor: pointer;
}
.dropdown-item .icon { color: var(--subtle); width: 17px; height: 17px; }
.dropdown-item:hover, .dropdown-item:focus-visible { background: var(--surface-3); color: var(--text); text-decoration: none; outline: none; }
.dropdown-item.is-danger, .dropdown-item.is-danger .icon { color: var(--danger); }
.dropdown-item.is-danger:hover { background: var(--danger-soft); }

.apps-menu { width: 336px; padding: 10px; }
.apps-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.app-tile-sm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 12px 6px 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 550;
  text-align: center;
}
.app-tile-sm:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.app-tile-sm.is-active { background: var(--brand-softer); color: var(--brand-fg); }
.app-tile-label { line-height: 1.25; overflow-wrap: anywhere; }

.app-icon {
  --app: var(--brand);
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(150deg, color-mix(in oklab, var(--app) 72%, #fff), var(--app) 60%, color-mix(in oklab, var(--app) 82%, #000));
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.28), 0 3px 8px -2px color-mix(in oklab, var(--app) 45%, transparent);
}
.app-icon .icon { width: 21px; height: 21px; stroke-width: 1.9; }
.app-icon-lg { width: 64px; height: 64px; border-radius: 18px; }
.app-icon-lg .icon { width: 30px; height: 30px; stroke-width: 1.8; }
:is(.apps-grid, .app-grid) > :nth-child(8n+1) .app-icon { --app: #5b5bd6; }
:is(.apps-grid, .app-grid) > :nth-child(8n+2) .app-icon { --app: var(--c7); }
:is(.apps-grid, .app-grid) > :nth-child(8n+3) .app-icon { --app: var(--c2); }
:is(.apps-grid, .app-grid) > :nth-child(8n+4) .app-icon { --app: var(--c9); }
:is(.apps-grid, .app-grid) > :nth-child(8n+5) .app-icon { --app: var(--c8); }
:is(.apps-grid, .app-grid) > :nth-child(8n+6) .app-icon { --app: #2f9e44; }
:is(.apps-grid, .app-grid) > :nth-child(8n+7) .app-icon { --app: var(--c5); }
:is(.apps-grid, .app-grid) > :nth-child(8n+8) .app-icon { --app: var(--c3); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--control-h);
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 560;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s, transform 0.05s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn .icon { width: 16px; height: 16px; }
.btn:disabled, .btn.is-disabled { opacity: 0.45; pointer-events: none; }

.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
  box-shadow: 0 1px 2px rgb(16 24 40 / 0.14), inset 0 1px 0 rgb(255 255 255 / 0.14);
}
.btn-primary:hover { background: var(--brand-hover); color: var(--on-brand); }
.btn-primary:focus-visible { box-shadow: var(--ring), 0 1px 2px rgb(16 24 40 / 0.14); }

.btn-secondary, .btn-save {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover, .btn-save:hover { background: var(--surface-2); border-color: color-mix(in oklab, var(--border-strong) 70%, var(--text) 30%); color: var(--text); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; box-shadow: 0 1px 2px rgb(16 24 40 / 0.14); }
.btn-danger:hover { background: color-mix(in oklab, var(--danger) 88%, #000); color: #fff; }
.btn-danger:focus-visible { box-shadow: var(--ring-danger); }

.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; border-radius: 7px; gap: 6px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-lg { height: 42px; padding: 0 18px; font-size: var(--fs-md); border-radius: 10px; }
.btn-block { width: 100%; }

/* ---------- Pages ---------- */

.page { min-width: 0; }

.toolbar { margin-bottom: var(--sp-2); }
.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--sp-3) var(--sp-4);
}
.toolbar-title {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 36px;
  margin-inline-end: auto;
}
.toolbar-title h1 { font-size: var(--fs-xl); font-weight: 680; letter-spacing: -0.015em; }

.search { flex: 1 1 360px; min-width: 0; max-width: 640px; margin: 0; }

/* The search bar of lists: facets (active filters, grouping, link
   filters), the text, and a toggle opening the Filters / Group by panel. */
.searchbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding-inline: 10px 3px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.searchbar:hover { border-color: var(--border-strong); }
.searchbar:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
.searchbar-icon { flex: none; width: 16px; height: 16px; color: var(--subtle); margin-inline-end: 2px; }
.searchbar-field { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; flex: 1 1 auto; min-width: 0; padding-block: 4px; cursor: text; }
.searchbar-field input {
  flex: 1 1 120px;
  min-width: 90px;
  height: 26px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  outline: none;
}
.searchbar-field input::placeholder { color: var(--subtle); }
.searchbar-field input::-webkit-search-cancel-button { cursor: pointer; }
.searchbar .search-kbd { position: static; translate: none; flex: none; margin-inline: 2px 4px; }
.searchbar:focus-within .search-kbd, .searchbar:has(input:not(:placeholder-shown)) .search-kbd, .searchbar.htmx-request .search-kbd { display: none; }
.searchbar > .spinner { display: none; flex: none; margin-inline: 2px 6px; }
.searchbar.htmx-request > .spinner { display: block; }
.searchbar-toggle {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  flex: none;
  align-self: stretch;
  margin-block: 3px;
  padding: 0 7px;
  border: 0;
  border-inline-start: 1px solid var(--border);
  border-radius: 0 6px 6px 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
[dir="rtl"] .searchbar-toggle { border-radius: 6px 0 0 6px; }
.searchbar-toggle:hover, .searchbar-toggle[aria-expanded="true"] { background: var(--surface-3); color: var(--text); }
.searchbar-toggle:focus-visible { outline: none; box-shadow: var(--ring); }
.searchbar-toggle .icon { width: 16px; height: 16px; }
.searchbar-toggle .icon-sm { width: 13px; height: 13px; transition: transform 0.15s; }
.searchbar-toggle[aria-expanded="true"] .icon-sm { transform: rotate(180deg); }
/* The bar's dropdown is its panel: it opens under the whole bar. */
.searchbar.dropdown { position: relative; }

.facet {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  height: 24px;
  padding-inline: 7px 2px;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand-fg);
  font-size: 12.5px;
  font-weight: 560;
  line-height: 1;
  animation: pop-in 0.12s var(--ease);
}
/* A facet with nothing in it (no filter on, no grouping) isn't shown. */
.facet:not(:has(.facet-value:not(:empty))) { display: none; }
.facet-icon { flex: none; width: 13px; height: 13px; }
.facet-label { color: color-mix(in oklab, var(--brand-fg) 75%, var(--muted)); font-weight: 500; }
.facet-label::after { content: ":"; }
.facet-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-or { margin-inline: 4px; color: color-mix(in oklab, var(--brand-fg) 60%, transparent); font-weight: 450; }
.facet-value:first-of-type .facet-or { display: none; }
.facet-remove {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 18px; height: 18px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.facet-remove:hover { background: color-mix(in oklab, var(--brand) 20%, transparent); text-decoration: none; }
.facet-remove:focus-visible { outline: none; box-shadow: var(--ring); }
.facet-remove .icon { width: 12px; height: 12px; }

.search-panel {
  top: calc(100% + 6px);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px 12px;
  width: min(260px, calc(100vw - 32px));
  max-height: min(70vh, 520px);
  overflow-y: auto;
  padding: 8px;
}
.search-panel[hidden] { display: none; }
.search-panel:has(.search-panel-col + .search-panel-col) { grid-template-columns: repeat(2, minmax(0, 1fr)); width: min(500px, calc(100vw - 32px)); }
.search-panel-col { min-width: 0; margin: 0; padding: 0; border: 0; }
.search-panel-col + .search-panel-col { border-inline-start: 1px solid var(--border); padding-inline-start: 12px; }
@media (max-width: 520px) {
  .search-panel:has(.search-panel-col + .search-panel-col) { grid-template-columns: minmax(0, 1fr); }
  .search-panel-col + .search-panel-col { border-inline-start: 0; padding-inline-start: 0; border-top: 1px solid var(--border); padding-top: 4px; }
}
.search-panel-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.menu-check {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: var(--fs-sm);
  line-height: 1.3;
  cursor: pointer;
}
.menu-check:hover, .menu-check:has(input:focus-visible) { background: var(--surface-3); color: var(--text); }
.menu-check input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.menu-check-mark {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 16px; height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.menu-check-mark .icon { width: 11px; height: 11px; color: var(--on-brand); stroke-width: 3.2; opacity: 0; }
.menu-check input:checked ~ .menu-check-mark { background: var(--brand); border-color: var(--brand); }
.menu-check input:checked ~ .menu-check-mark .icon { opacity: 1; }
.menu-check.is-radio .menu-check-mark { border-radius: 50%; }
.menu-check.is-radio input:checked ~ .menu-check-mark { background: var(--surface); box-shadow: inset 0 0 0 3.5px var(--brand); }
.menu-check input:checked ~ .menu-check-label { color: var(--text); font-weight: 560; }
.menu-check-label { min-width: 0; overflow-wrap: anywhere; }

.search-box { position: relative; flex: 1 1 100%; }
.search-box > .icon {
  position: absolute;
  inset-inline-start: 11px; top: 50%;
  translate: 0 -50%;
  width: 16px; height: 16px;
  color: var(--subtle);
  pointer-events: none;
}
.search-box input {
  width: 100%;
  height: 36px;
  padding-block: 0; padding-inline: 35px 38px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box input::placeholder { color: var(--subtle); }
.search-box input:hover { border-color: var(--border-strong); }
.search-box input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.search-box input::-webkit-search-cancel-button { cursor: pointer; }
.search-kbd, .search-box .spinner {
  position: absolute;
  inset-inline-end: 10px; top: 50%;
  translate: 0 -50%;
}
.search-kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--subtle);
  font: 600 11px/1 var(--font-sans);
  pointer-events: none;
  transition: opacity 0.15s;
}
.search-box input:focus ~ .search-kbd, .search-box input:not(:placeholder-shown) ~ .search-kbd { opacity: 0; }
.search-box.htmx-request .search-kbd { opacity: 0; }

.chip-toggle { position: relative; display: inline-flex; cursor: pointer; }
.chip-toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip-toggle span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 550;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.chip-toggle:hover span { border-color: color-mix(in oklab, var(--border-strong) 60%, var(--text) 25%); }
.chip-toggle input:checked + span {
  background: var(--brand-soft);
  border-color: var(--brand-line);
  color: var(--brand-fg);
}
.chip-toggle input:checked + span::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--brand);
}
.chip-toggle input:focus-visible + span { box-shadow: var(--ring); }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-3);
}
.segmented-item {
  display: inline-grid;
  place-items: center;
  width: 32px; height: 28px;
  border-radius: 7px;
  color: var(--muted);
}
.segmented-item:hover { color: var(--text); text-decoration: none; }
.segmented-item.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
/* Words instead of icons (the calendar's Month / Week). */
.segmented-item.segmented-text { width: auto; padding-inline: 10px; font-size: var(--fs-sm); font-weight: 560; white-space: nowrap; }

/* Results dim a little while htmx loads a new page of them. */
.results { transition: opacity 0.2s; }
.results.htmx-request { opacity: 0.55; transition-delay: 0.12s; }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-indicator { opacity: 0; transition: opacity 0.15s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---------- Tables ---------- */

.table-card {
  display: block;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  position: relative; /* holds .sr-only texts of its table: no page-wide scroll on phones */
}
.results-form { margin: 0; }
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 38px; /* as tall as the bulk bar: the table doesn't jump when rows are ticked */
  margin-bottom: var(--sp-2);
}
.results-bar-end { margin-inline-start: auto; }
.results-bar:not(:has(.pager)):not(:has(.bulk-bar:not([hidden]))) { min-height: 0; margin: 0; }
.bulk-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-block: 3px; padding-inline: 12px 4px;
  border: 1px solid var(--brand-line);
  border-radius: 10px;
  background: var(--brand-softer);
  animation: pop-in 0.14s var(--ease);
}
.bulk-count { color: var(--text-2); font-size: var(--fs-sm); margin-inline-end: 4px; }
.bulk-count strong { color: var(--brand-fg); }

.table-scroll {
  position: relative;
  overflow: auto;
  max-height: calc(100dvh - var(--topbar-h) - 200px);
  min-height: 0;
  overscroll-behavior-x: contain;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
.table th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0 14px;
  height: 38px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  text-align: start;
  white-space: nowrap;
}
.table th.is-sorted { color: var(--text); }
.table th .sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 -6px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  color: inherit;
}
.table th .sort:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.table th .sort .icon { color: var(--brand-fg); }
.table th .sort .sort-hint { color: var(--subtle); opacity: 0; transition: opacity 0.12s; }
.table th .sort:hover .sort-hint, .table th .sort:focus-visible .sort-hint { opacity: 1; }
.table th.is-num, .table td.is-num { text-align: end; }
.table th.is-num .sort { flex-direction: row-reverse; }

.table td {
  max-width: 380px;
  height: 42px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}
.table td:first-of-type, .table td.col-check + td { color: var(--text); font-weight: 520; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { position: relative; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:has(.checkbox:checked) td { background: var(--brand-softer); }
.table tbody tr.is-muted td { color: var(--subtle); }
.table .col-check { position: relative; z-index: 1; width: 44px; padding-block: 0; padding-inline: 14px 4px; }
/* The select-all box stays with the header (the rule above is for the
   rows' boxes, above the row link). */
.table th.col-check { position: sticky; top: 0; z-index: 3; }
/* The whole cell ticks the box: a tap beside it doesn't open the record. */
.check-hit {
  display: grid;
  place-items: center start;
  min-height: 38px;
  margin-inline: -14px -4px;
  padding-inline: 14px 4px;
  cursor: pointer;
}
.row-link { color: inherit; outline: none; }
.row-link:hover { text-decoration: none; }
.row-link::after { content: ""; position: absolute; inset: 0; }
.row-link:focus-visible::after { box-shadow: inset 0 0 0 2px var(--brand); border-radius: 2px; }
.table .tags { flex-wrap: nowrap; }
.bool-yes { display: inline-flex; align-items: center; gap: 4px; color: var(--success); }

.checkbox {
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  place-content: center;
  width: 16px; height: 16px;
  margin: 0;
  vertical-align: middle;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.checkbox:hover { border-color: var(--brand); }
.checkbox:checked, .checkbox:indeterminate { background: var(--brand); border-color: var(--brand); }
.checkbox:checked::before {
  content: "";
  width: 8px; height: 4.5px;
  margin-top: -2px;
  border: 2px solid #fff;
  border-top: 0; border-right: 0;
  transform: rotate(-45deg);
}
.checkbox:indeterminate::before { content: ""; width: 8px; height: 2px; background: #fff; border-radius: 1px; }
.checkbox:focus-visible { outline: none; box-shadow: var(--ring); }

.pager { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-2); }
.pager-text { white-space: nowrap; }
.pager-range { font-weight: 600; font-variant-numeric: tabular-nums; }
.pager-buttons { display: inline-flex; gap: 2px; }

/* ---------- Tags and badges ---------- */

.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
.tag {
  --tag: var(--c0);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  height: 22px;
  padding: 0 8px;
  border: 1px solid color-mix(in oklab, var(--tag) 24%, transparent);
  border-radius: var(--radius-full);
  background: color-mix(in oklab, var(--tag) 13%, var(--surface));
  color: color-mix(in oklab, var(--tag) 62%, var(--text));
  font-size: 12px;
  font-weight: 560;
  line-height: 1;
  white-space: nowrap;
}
.tag > span { overflow: hidden; text-overflow: ellipsis; }
.tag-1 { --tag: var(--c1); }
.tag-2 { --tag: var(--c2); }
.tag-3 { --tag: var(--c3); }
.tag-4 { --tag: var(--c4); }
.tag-5 { --tag: var(--c5); }
.tag-6 { --tag: var(--c6); }
.tag-7 { --tag: var(--c7); }
.tag-8 { --tag: var(--c8); }
.tag-9 { --tag: var(--c9); }
.tag-removable { padding-inline-end: 3px; }
.tag-remove {
  display: inline-grid;
  place-items: center;
  width: 16px; height: 16px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  opacity: 0.65;
  cursor: pointer;
}
.tag-remove:hover { opacity: 1; background: color-mix(in oklab, var(--tag) 22%, transparent); }
.tag-remove .icon { width: 11px; height: 11px; stroke-width: 2.6; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 560;
  white-space: nowrap;
}
.badge .icon { width: 13px; height: 13px; }
.badge-warning {
  background: var(--warning-soft);
  border-color: color-mix(in oklab, var(--warning) 28%, transparent);
  color: color-mix(in oklab, var(--warning) 85%, var(--text));
}
.badge-danger {
  background: var(--danger-soft);
  border-color: color-mix(in oklab, var(--danger) 28%, transparent);
  color: color-mix(in oklab, var(--danger) 85%, var(--text));
}
.badge-success {
  background: var(--success-soft);
  border-color: color-mix(in oklab, var(--success) 28%, transparent);
  color: color-mix(in oklab, var(--success) 85%, var(--text));
}
.jobs-intro { margin: 0 0 var(--sp-4); }
.job-error { margin-top: 4px; color: var(--danger); overflow-wrap: anywhere; max-width: 48ch; white-space: normal; }
.jobs-tasks { margin-top: var(--sp-6); }
.jobs-tasks h2 { font-size: var(--fs-lg); font-weight: 650; margin-bottom: var(--sp-2); }
.jobs-tasks .alert { margin-bottom: var(--sp-3); }
.page-mail .table td { white-space: normal; overflow-wrap: anywhere; }
.page-mail .table td.mail-when, .page-mail .table td.mail-actions { white-space: nowrap; overflow-wrap: normal; }
.mail-intro { margin: 0 0 var(--sp-4); }
.page-mail .alert { margin-bottom: var(--sp-4); }
.mail-test { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--sp-4); max-width: 520px; }
.mail-test .input { flex: 1 1 220px; }
.mail-tabs { display: flex; gap: 4px; margin-bottom: var(--sp-3); flex-wrap: wrap; }
.mail-tab { padding: 6px 12px; border-radius: 999px; color: var(--text-2); font-size: var(--fs-sm); text-decoration: none; }
.mail-tab:hover { background: var(--brand-softer); }
.mail-tab.is-active { background: var(--brand-soft); color: var(--brand-fg); font-weight: 600; }
.mail-actions { text-align: end; }
.mail-actions .dropdown-form { display: inline-block; }
.mail-more { padding: var(--sp-3) var(--sp-4); margin: 0; }

/* ---------- Kanban ---------- */

.board {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  overflow-x: auto;
  padding-bottom: var(--sp-3);
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
}
.board-col {
  flex: 0 0 292px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in oklab, var(--surface-3) 70%, var(--bg));
  scroll-snap-align: start;
}
.board-col-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 4px; }
.board-col-head h2 { font-size: var(--fs-sm); font-weight: 650; color: var(--text); }
.count {
  display: inline-grid;
  place-items: center;
  min-width: 22px; height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.board-cards { display: flex; flex-direction: column; gap: var(--sp-2); }
.card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  color: var(--text-2);
  font-size: var(--fs-sm);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.card:hover {
  text-decoration: none;
  border-color: var(--brand-line);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.card.is-muted { opacity: 0.6; }
.card-title { color: var(--text); font-size: var(--fs); font-weight: 620; line-height: 1.35; overflow-wrap: anywhere; }
.card-line { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--muted); }
.card-line .icon { color: var(--subtle); }
.card-label { color: var(--subtle); flex: none; }
.card-label::after { content: ":"; }
.card-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-tags { margin-top: 3px; }
.board-empty { padding: 18px 8px; color: var(--subtle); font-size: var(--fs-sm); text-align: center; border: 1px dashed var(--border-strong); border-radius: 10px; }

/* ---------- Empty state ---------- */

.empty-art {
  display: inline-grid;
  place-items: center;
  width: 56px; height: 56px;
  margin-bottom: 4px;
  border-radius: 16px;
  background: var(--brand-soft);
  color: var(--brand-fg);
}
.empty-art .icon { width: 26px; height: 26px; stroke-width: 1.8; }
div.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 56px 24px 60px;
  color: var(--muted);
  text-align: center;
}
div.empty h2 { font-size: var(--fs-lg); font-weight: 650; }
div.empty p { max-width: 400px; }
div.empty .btn { margin-top: 8px; }

/* ---------- Forms ---------- */

.page-form { max-width: var(--sheet-w); margin: 0 auto; }

.control-panel {
  position: sticky;
  top: var(--topbar-h);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-3);
  margin: calc(-1 * var(--sp-5)) calc(-1 * var(--sp-2)) var(--sp-3);
  padding: var(--sp-3) var(--sp-2);
  background: color-mix(in oklab, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.cp-title { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.cp-model { color: var(--muted); font-size: var(--fs-sm); font-weight: 560; }
.cp-actions { display: flex; align-items: center; gap: var(--sp-2); margin-inline-start: auto; }

.dirty-note { display: none; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-sm); margin-inline-end: 4px; }
.dirty-note .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 0 3px color-mix(in oklab, var(--warning) 20%, transparent); }
.page-form[data-dirty] .dirty-note { display: inline-flex; }
.page-form[data-dirty] .btn-save {
  background: var(--brand);
  border-color: transparent;
  color: var(--on-brand);
  box-shadow: 0 1px 2px rgb(16 24 40 / 0.14), 0 0 0 3px color-mix(in oklab, var(--brand) 18%, transparent);
}
.page-form[data-dirty] .btn-save:hover { background: var(--brand-hover); }
.page-form:not([data-dirty]) .btn-discard { color: var(--muted); }

.record-form { margin: 0; }
.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.form-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.form-header + .sheet { border-top-left-radius: 0; border-top-right-radius: 0; }

.statusbar { display: flex; list-style: none; margin: 0; margin-inline-start: auto; padding: 0; overflow-x: auto; max-width: 100%; }
.step {
  position: relative;
  display: flex;
  align-items: center;
  height: 30px;
  padding-block: 0; padding-inline: 22px 16px;
  margin-inline-start: -6px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 580;
  white-space: nowrap;
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%, 10px 50%);
}
.step:first-child { margin-inline-start: 0; padding-inline-start: 14px; clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%); border-start-start-radius: 7px; border-end-start-radius: 7px; }
/* Right to left, the steps point the other way. */
[dir="rtl"] .step { clip-path: polygon(100% 0, 10px 0, 0 50%, 10px 100%, 100% 100%, calc(100% - 10px) 50%); }
[dir="rtl"] .step:first-child { clip-path: polygon(100% 0, 10px 0, 0 50%, 10px 100%, 100% 100%); }
.step.is-current { background: var(--brand); color: var(--on-brand); }

.sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6) var(--sp-8) var(--sp-5);
}
.sheet-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--sp-3) var(--sp-5); margin-bottom: var(--sp-5); }
.sheet-heading { min-width: 0; flex: 1 1 260px; }
/* Links to related records ("Moves 12"), at the top end of the sheet. */
.sheet-links { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.sheet-link {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 92px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-2);
  line-height: 1.25;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}
.sheet-link:hover { background: var(--brand-softer); border-color: var(--brand-line); }
.sheet-link:focus-visible { outline: none; box-shadow: var(--ring); }
.sheet-link-value { color: var(--brand-fg); font-size: var(--fs-md); font-weight: 680; font-variant-numeric: tabular-nums; }
.sheet-link-label { color: var(--muted); font-size: var(--fs-xs); font-weight: 550; }
.sheet-kicker { display: block; margin-bottom: 4px; color: var(--brand-fg); font-size: var(--fs-xs); font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; }
.sheet-title { font-size: var(--fs-2xl); font-weight: 680; letter-spacing: -0.02em; overflow-wrap: anywhere; }
.sheet .alert { margin-bottom: var(--sp-5); }

.group { margin: 0 0 var(--sp-4); }
.group:last-child { margin-bottom: 0; }
.group-label {
  margin: var(--sp-2) 0 var(--sp-2);
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.group-cols { display: grid; gap: 0 var(--sp-10); }
.cols-1 { grid-template-columns: minmax(0, 720px); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.group-col { min-width: 0; }

.field {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: start;
  gap: 4px var(--sp-4);
  padding: 5px 0;
}
.field-label {
  display: flex;
  align-items: baseline;
  gap: 3px;
  padding-top: 7px;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.is-readonly .field-label { color: var(--muted); }
.req { color: var(--danger); font-weight: 700; }
/* the language a translatable text is edited in */
.field-lang {
  margin-inline-start: 6px; padding: 0 5px; border: 1px solid var(--border); border-radius: 4px;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase; color: var(--muted); vertical-align: 1px;
}
.field-control { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.field-help { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
/* widget: barcode draws the value under the field; widget: image shows a
   large preview. */
.barcode-img { display: block; height: 64px; max-width: 100%; margin-top: 8px; padding: 4px; border-radius: var(--radius-sm); background: #fff; }
.image-preview { display: block; width: 160px; height: 160px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.image-zoom { display: inline-block; flex: none; border-radius: var(--radius); cursor: zoom-in; }
.image-zoom:hover .image-preview, .image-zoom:hover .file-thumb { border-color: var(--brand); }
.image-zoom:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.readonly-image { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-2); }
.file-field.is-image .file-current { flex-direction: column; align-items: flex-start; }
.image-empty { display: grid; place-items: center; width: 160px; height: 120px; margin-bottom: 8px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--subtle); }
.image-empty .icon { width: 32px; height: 32px; }

/* Thumbnails of pictures in lists and kanban cards. */
.table td.cell-image { width: 1%; padding-block: 4px; }
.list-thumb { display: block; width: 36px; height: 36px; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-3); }
.card-image { display: block; width: 100%; height: 120px; margin-bottom: 8px; object-fit: contain; border-radius: var(--radius-sm); background: var(--surface-2); }

/* The scan box of a form: a scanner types the code and Enter. */
.scan {
  margin-bottom: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  border: 1px dashed var(--brand-line);
  border-radius: var(--radius-lg);
  background: var(--brand-softer);
}
.scan.has-error { border-color: color-mix(in oklab, var(--danger) 45%, transparent); background: var(--danger-soft); }
.scan-label { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 6px; color: var(--brand-fg); font-size: var(--fs-sm); font-weight: 650; }
.scan-row { display: flex; align-items: center; gap: var(--sp-2); }
.scan-input { flex: 1 1 auto; min-width: 0; font-family: var(--font-mono); font-size: var(--fs-md); }
.scan-input::placeholder { font-family: var(--font-sans); } /* Arabic doesn't read well in monospace */
.scan-error { margin-top: 6px; }
/* The camera reading barcodes (browsers with BarcodeDetector). */
.scan-video { display: block; width: 100%; max-height: 50vh; margin-top: var(--sp-2); border-radius: var(--radius); background: #000; object-fit: cover; }

.field-error { display: flex; align-items: flex-start; gap: 5px; color: var(--danger); font-size: 12.5px; font-weight: 520; }
.field-error .icon { margin-top: 1px; width: 14px; height: 14px; }
.sheet-body > .field:not(.is-wide), .tabpanel > .field:not(.is-wide) { max-width: 720px; }
.field.is-wide { grid-template-columns: minmax(0, 1fr); gap: 6px; }
.field.is-wide .field-label { padding-top: 0; }
.field.w-bool .field-control { padding-top: 6px; }

.readonly { min-height: var(--control-h); padding: 7px 0; color: var(--text); overflow-wrap: anywhere; }
.readonly-text { white-space: pre-wrap; }
.readonly.is-num { font-variant-numeric: tabular-nums; }

.input {
  width: 100%;
  height: var(--control-h);
  padding: 0 10px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input::placeholder { color: var(--subtle); }
.input:hover { border-color: var(--border-strong); }
.input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.input.is-num { font-variant-numeric: tabular-nums; }
.input-lg { height: 42px; padding: 0 12px; font-size: var(--fs-md); border-radius: 10px; }
.textarea { height: auto; min-height: 92px; padding: 8px 10px; line-height: 1.5; resize: vertical; }
.input-date { max-width: 260px; }
.input-date::-webkit-calendar-picker-indicator { opacity: 0.6; cursor: pointer; }
.has-error .input, .input[aria-invalid="true"], .has-error .tags-input { border-color: var(--danger); }
.has-error .input:focus, .input[aria-invalid="true"]:focus, .has-error .tags-input:focus-within { box-shadow: var(--ring-danger); }

.select-wrap { position: relative; }
.select { appearance: none; -webkit-appearance: none; padding-inline-end: 32px; cursor: pointer; }
.select-caret { position: absolute; inset-inline-end: 10px; top: 50%; translate: 0 -50%; color: var(--muted); pointer-events: none; }

.switch { position: relative; display: inline-flex; align-items: center; width: max-content; cursor: pointer; }
.switch-input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track {
  position: relative;
  display: inline-block;
  width: 36px; height: 21px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  transition: background 0.18s var(--ease);
}
.switch-thumb {
  position: absolute;
  top: 2.5px; inset-inline-start: 2.5px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: transform 0.18s var(--ease);
}
.switch-input:checked + .switch-track { background: var(--brand); }
.switch-input:checked + .switch-track .switch-thumb { transform: translateX(15px); }
[dir="rtl"] .switch-input:checked + .switch-track .switch-thumb { transform: translateX(-15px); }
.switch-input:focus-visible + .switch-track { box-shadow: var(--ring); }
.switch:hover .switch-track { filter: brightness(0.97); }

.combo { position: relative; display: flex; align-items: center; gap: 4px; }
.combo-tags .tags-input { flex: 1 1 auto; min-width: 0; }
.combo-field { position: relative; flex: 1; min-width: 0; }
.combo-input { padding-inline-end: 30px; text-overflow: ellipsis; }
.combo-caret { position: absolute; inset-inline-end: 10px; top: 50%; translate: 0 -50%; color: var(--subtle); pointer-events: none; }
.combo-input.htmx-request ~ .combo-caret { animation: spin 0.8s linear infinite; }
.combo-open { color: var(--subtle); }
/* Fixed, placed by mzool.js under (or over) the field: a scrolling table
   or dialog around the field can't cut it off. */
.combo-list {
  position: fixed;
  top: 0; left: 0;
  z-index: 35;
  width: 16rem;
  max-height: 264px;
  white-space: normal; /* not a table cell's nowrap or end alignment */
  text-align: start;
  font-weight: normal;
  overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.12s var(--ease);
}
.combo-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  line-height: 1.35;
  cursor: pointer;
}
.combo-option > span { min-width: 0; overflow-wrap: break-word; } /* wrap between words, not inside them */
/* Right to left, a name takes its direction from its first letter, so
   "Acme (HQ)" keeps its brackets in place. */
[dir="rtl"] :is(.combo-option, .tag) > span { unicode-bidi: plaintext; text-align: right; }
.combo-list.is-up { animation-name: pop-up; }
@keyframes pop-up { from { opacity: 0; transform: translateY(4px) scale(0.98); } }
.combo-option:hover, .combo-option.is-active { background: var(--brand-softer); color: var(--text); }
.combo-option.is-active { box-shadow: inset 2px 0 0 var(--brand); }
[dir="rtl"] .combo-option.is-active { box-shadow: inset -2px 0 0 var(--brand); }
.combo-option.is-picked { color: var(--brand-fg); font-weight: 600; }
.combo-option.is-picked::after { content: "✓"; margin-inline-start: auto; font-weight: 700; }
.combo-empty { padding: 10px; color: var(--subtle); font-size: var(--fs-sm); text-align: center; }
/* A record: its name, the typed text marked, and where else it matched. */
.combo-text { display: flex; flex-direction: column; min-width: 0; }
.combo-name { overflow-wrap: break-word; }
.combo-option mark {
  padding: 0 1px;
  border-radius: 3px;
  background: color-mix(in oklab, var(--brand) 16%, transparent);
  color: inherit;
  font-weight: 650;
}
.combo-hint { color: var(--subtle); font-size: var(--fs-xs); line-height: 1.3; overflow-wrap: anywhere; }
/* Under the records: Create “x”, Search More…, Create and edit… */
.combo-actions {
  position: sticky; bottom: -4px; /* always in sight under a long list */
  margin: 4px -4px -4px;
  padding: 4px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-end-start-radius: 10px; border-end-end-radius: 10px;
}
.combo-hint mark { font-weight: 650; }
.combo-action { color: var(--brand-fg); font-weight: 560; font-size: var(--fs-sm); }
.combo-action .icon { flex: none; }
.combo-action.is-busy { opacity: 0.6; pointer-events: none; }
.combo-action.is-busy .icon { animation: spin 0.8s linear infinite; }
.combo-list:has(.combo-actions) { padding-bottom: 4px; }

/* widget: checkboxes — every choice of a many2many, ticked when linked */
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); gap: var(--sp-2) var(--sp-4); padding-block: 7px; }
.check { display: flex; align-items: flex-start; gap: var(--sp-2); min-width: 0; cursor: pointer; line-height: 1.35; }
.check .checkbox { flex: none; margin-block-start: 1px; }
.check span { min-width: 0; overflow-wrap: anywhere; }

.tags-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-height: var(--control-h);
  padding: 4px 6px;
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  cursor: text;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tags-input:hover { border-color: var(--border-strong); }
.tags-input:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
.tags-q {
  flex: 1 0 90px;
  min-width: 90px;
  height: 24px;
  padding: 0 4px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.tags-q::placeholder { color: var(--subtle); }

.o2m { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.o2m-list {
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.o2m-list li + li { border-top: 1px solid var(--border); }
.o2m-list li > a, .o2m-list li > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  color: var(--text);
}
.o2m-list li > a:hover { background: var(--surface-2); text-decoration: none; }
.o2m-list .icon { color: var(--subtle); }
.o2m-empty { color: var(--subtle); font-size: var(--fs-sm); padding: 6px 0; }
.o2m-add { margin-inline-start: -6px; }
.o2m-table { align-self: stretch; border: 1px solid var(--border); border-radius: var(--radius); }
.o2m-table .table { margin: 0; }

.notebook { margin-top: var(--sp-5); }
.tablist {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tab {
  position: relative;
  padding: 9px 14px;
  margin-bottom: -1px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 570;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }
.tab:focus-visible { outline: none; box-shadow: inset var(--ring); border-radius: 6px 6px 0 0; }
.tab.has-error::after {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin-inline-start: 6px;
  vertical-align: 2px;
  border-radius: 50%;
  background: var(--danger);
}
.tabpanel { padding: var(--sp-4) 0 var(--sp-1); }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px var(--sp-6);
  margin: var(--sp-6) 0 0;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
}
.meta div { display: flex; gap: 6px; }
.meta dt { font-weight: 500; }
.meta dd { margin: 0; color: var(--text-2); }

/* ---------- API keys ---------- */

.keys-grid { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.keys-grid > .keys-list:only-child { grid-column: 1 / -1; }
.key-new { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; flex: 1; }
.key-secret { width: 100%; }
.key-access, .stack-field fieldset { border: 0; padding: 0; margin: 0; }
.radio-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.key-models { display: flex; flex-direction: column; max-height: 220px; overflow: auto; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); }
@media (max-width: 900px) {
  .keys-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- File fields ---------- */

.file-field { display: flex; flex-direction: column; gap: var(--sp-2); }
.file-current { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.file-thumb { width: 56px; height: 56px; object-fit: cover; border: 1px solid var(--border); border-radius: var(--radius); }
.file-input { padding: 5px; }
.file-input::file-selector-button { margin-inline-end: var(--sp-2); padding: 3px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font: inherit; cursor: pointer; }
.file-input::file-selector-button:hover { border-color: var(--brand); }
/* A file input is a button in the app's language plus the chosen name
   (the browser's own "Choose File" can't be translated). */
.file-choose { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); min-width: 0; }
.file-chosen { min-width: 0; overflow-wrap: anywhere; }
.file-choose .file-pick:focus-within { outline: none; box-shadow: var(--ring); }
.has-error .file-choose .file-pick { border-color: var(--danger); }
.file-chip-thumb { width: 24px; height: 24px; flex: none; object-fit: cover; border-radius: 4px; background: var(--surface-3); }
.file-clear { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); }

/* ---------- Company switcher ---------- */

.company-btn { max-width: 220px; }
.company-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) {
  .company-name { display: none; }
}

/* ---------- Chatter (activity under a form) ---------- */

.chatter { margin-top: var(--sp-5); }
.chatter-loading { display: flex; align-items: center; gap: 8px; }
.chatter-inner {
  display: flex; flex-direction: column; gap: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5) var(--sp-8);
}
.chatter-title { font-size: var(--fs-lg); font-weight: 650; }
.chatter-compose { display: flex; flex-direction: column; gap: var(--sp-2); }
.chatter-compose .textarea { min-height: 64px; }
.chatter-actions { display: flex; justify-content: flex-end; }
.chatter-files { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); }
.file-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: 0; padding: 0; list-style: none; }
.file { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding-block: 4px; padding-inline: 10px 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.file-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28ch; }
.file form { display: contents; }
.file-pick { cursor: pointer; }
.file-pick:focus-within { outline: 2px solid var(--brand); outline-offset: 2px; }
.timeline { display: flex; flex-direction: column; gap: var(--sp-4); margin: 0; padding: 0; list-style: none; }
.msg { display: flex; gap: var(--sp-3); align-items: flex-start; }
.msg-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-changes { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); }
.msg-changes li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.msg-changes .old { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
.msg-event .msg-text, .msg-change .msg-text { color: var(--text-2); }
@media (max-width: 640px) {
  .chatter-inner { padding: var(--sp-4); }
}

/* ---------- Alerts ---------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.45;
}
.alert .icon { margin-top: 1px; }
.alert ul { margin: 4px 0 0; padding-inline-start: 18px; }
.alert-danger { background: var(--danger-soft); border-color: color-mix(in oklab, var(--danger) 28%, transparent); color: color-mix(in oklab, var(--danger) 78%, var(--text)); }
.alert-success { background: var(--success-soft); border-color: color-mix(in oklab, var(--success) 28%, transparent); color: color-mix(in oklab, var(--success) 78%, var(--text)); }
.alert-warning { background: var(--warning-soft); border-color: color-mix(in oklab, var(--warning) 32%, transparent); color: color-mix(in oklab, var(--warning) 60%, var(--text)); }
.alert-info { background: var(--info-soft); border-color: color-mix(in oklab, var(--info) 28%, transparent); color: color-mix(in oklab, var(--info) 78%, var(--text)); }

/* ---------- Screen help ---------- */
/* A model's "About this screen" (its description:): a toggle next to the
   title, the panel under the toolbar of lists and boards, or under a
   form's control panel. */
.help-toggle[aria-expanded="true"] { background: var(--brand-soft); color: var(--brand-fg); }
.help-panel {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  padding-block: var(--sp-3);
  padding-inline: var(--sp-4) var(--sp-2);
  border: 1px solid color-mix(in oklab, var(--brand) 22%, var(--border));
  border-radius: var(--radius-lg);
  background: var(--brand-softer);
  color: var(--text-2);
  font-size: 13.5px;
  line-height: 1.55;
  animation: fade-in 0.15s var(--ease);
}
.page-form .help-panel { margin: 0 0 var(--sp-3); }
.help-panel-icon { flex: none; width: 18px; height: 18px; margin-top: 2px; color: var(--brand-fg); }
.help-panel-body { flex: 1 1 auto; min-width: 0; max-width: 48rem; }
.help-panel-title { margin-bottom: 4px; font-size: var(--fs); font-weight: 620; line-height: 1.5; }
.help-panel-body p, .help-panel-body ul { margin: 0 0 6px; }
.help-panel-body ul { padding-inline-start: 18px; }
.help-panel-body li + li { margin-top: 2px; }
.help-panel-body > :last-child { margin-bottom: 0; }
.help-panel-close { margin-block: -4px; margin-inline-start: auto; }
@media (max-width: 640px) {
  .help-panel { gap: var(--sp-2); padding-inline: var(--sp-3) var(--sp-1); }
  .help-panel-icon { display: none; }
}
/* A list header whose field has help shows it as a tooltip. */
.table th.has-help { cursor: help; }
.table th.has-help, .table th.has-help .sort > span { text-decoration: underline dotted var(--subtle); text-underline-offset: 3px; }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  inset-inline-end: 18px; bottom: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: min(400px, calc(100vw - 36px));
  padding-block: 10px; padding-inline: 14px 10px;
  border-radius: 11px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-lg);
  font-weight: 520;
  pointer-events: auto;
  animation: toast-in 0.28s var(--ease);
}
.toast.is-leaving { animation: toast-out 0.2s ease-in forwards; }
.toast-icon { flex: none; }
.toast-success .toast-icon { color: #3fbf6e; }
.toast-error .toast-icon { color: #f2596b; }
.toast-info .toast-icon { color: #7b9cff; }
.toast-text { flex: 1; }
.toast-close { color: inherit; opacity: 0.6; width: 26px; height: 26px; }
.toast-close:hover { opacity: 1; background: rgb(128 128 128 / 0.2); color: inherit; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ---------- Dialog ---------- */

.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
.dialog[open] { animation: pop-in 0.16s var(--ease); }
.dialog::backdrop { background: rgb(10 12 18 / 0.45); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.dialog-body { display: flex; gap: 14px; padding: 22px 22px 6px; }
.dialog-icon {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-fg);
}
.dialog.is-danger .dialog-icon { background: var(--danger-soft); color: var(--danger); }
.dialog-title { font-size: var(--fs-lg); font-weight: 650; margin-bottom: 4px; }
.dialog-text { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 22px 20px; }

/* Search More: the records a link field may take, in a window. */
.pick-dialog {
  display: none;
  width: min(980px, calc(100vw - 32px));
  max-height: min(86vh, 860px);
  max-height: min(86dvh, 860px);
  overflow: hidden;
}
.pick-dialog[open] { display: flex; flex-direction: column; }
.dialog-loading { display: grid; place-items: center; min-height: 200px; }
.dialog-loading .spinner { width: 22px; height: 22px; }
.pick { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.pick-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 18px 18px 10px 22px; }
.pick-head .dialog-title { margin: 0; }
.pick-search { padding: 0 22px 12px; margin: 0; }
.pick-search .search-box input { padding-inline-end: 12px; }
.pick-rows { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; border-top: 1px solid var(--border); }
.pick-rows.htmx-request { opacity: 0.6; transition: opacity 0.12s 0.1s; }
.pick-bar { display: flex; justify-content: flex-end; padding: 6px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
.pick-scroll { flex: 1 1 auto; max-height: none; }
.pick-table td { cursor: pointer; }
.pick-row:focus-visible { outline: none; }
.pick-row:focus-visible td { background: var(--brand-softer); box-shadow: inset 0 1px 0 var(--brand-line), inset 0 -1px 0 var(--brand-line); }
.pick-row:focus-visible td:first-child { box-shadow: inset 2px 0 0 var(--brand), inset 0 1px 0 var(--brand-line), inset 0 -1px 0 var(--brand-line); }
.pick-row.is-selected td { background: var(--brand-softer); }
.pick-row.is-linked td { color: var(--subtle); cursor: default; }
.pick-empty { display: grid; place-items: center; gap: var(--sp-2); padding: 48px 16px; color: var(--muted); text-align: center; }
.pick-empty .icon { width: 28px; height: 28px; color: var(--subtle); }
.pick-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); }
.pick-foot-end { display: flex; align-items: center; gap: 8px; margin-inline-start: auto; }

/* Create and edit: a form page (?_dialog=1) in a window, as an iframe. */
.frame-dialog { width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: hidden; background: var(--bg); }
.frame-dialog-frame { display: block; width: 100%; height: min(78vh, 720px); border: 0; background: var(--bg); color-scheme: normal; }
.frame-dialog.is-waiting .frame-dialog-frame { position: absolute; opacity: 0; pointer-events: none; }
.frame-dialog:not(.is-waiting) .dialog-loading { display: none; }
.dialog-page { padding: 0 var(--sp-5) var(--sp-5); }
.dialog-page .page-form { max-width: none; }
.dialog-page .control-panel { top: 0; margin: 0 calc(-1 * var(--sp-5)) var(--sp-3); padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--border); background: color-mix(in oklab, var(--surface) 94%, transparent); }
.dialog-page .sheet { box-shadow: none; }
.frame-close { margin-inline-start: 2px; }

/* a button that asks for inputs first: a dialog over the form, or a page */
.ask-dialog { width: min(560px, calc(100vw - 32px)); }
.ask-dialog .dialog-title { padding: 22px 22px 0; }
.ask-body { display: grid; gap: var(--sp-3); padding: 14px 22px 0; }
.ask-body .field { grid-template-columns: 1fr; }
.ask-panel { max-width: 640px; }
.ask-panel .ask-body { padding: 0; }
.ask-panel .dialog-actions { padding-inline: 0; }

/* ---------- Login ---------- */

.auth { display: flex; flex-direction: column; align-items: center; gap: var(--sp-5); width: 100%; }
.auth-card {
  width: min(400px, 100%);
  padding: 32px 30px 30px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-app { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -0.01em; }
.auth-title { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; }
.auth-sub { margin: 6px 0 22px; color: var(--muted); }
.auth-card .alert { margin-bottom: 18px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form .btn { margin-top: 6px; }
.auth-links { margin-top: 18px; text-align: center; font-size: var(--fs-sm); }
.auth-foot { color: var(--subtle); font-size: var(--fs-xs); }

.stack-form { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.stack-field { display: flex; flex-direction: column; gap: 6px; }
.stack-field label { color: var(--text-2); font-size: var(--fs-sm); font-weight: 500; }

/* ---------- Home, preferences, errors ---------- */

.page-home { max-width: 980px; margin: var(--sp-6) auto; }
.home-head h1 { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; }
.home-head p { margin-top: 4px; }
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-6);
}
.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 22px 12px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-xl);
  color: var(--text);
  font-weight: 600;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.app-tile:hover {
  text-decoration: none;
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.page-prefs { max-width: 900px; }
.prefs-grid { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: var(--sp-4); align-items: start; }
.prefs-main { display: grid; gap: var(--sp-4); min-width: 0; }
.panel {
  padding: var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.panel-title { display: flex; align-items: center; gap: 8px; margin-bottom: var(--sp-4); font-size: var(--fs-lg); font-weight: 650; }
.panel-title .icon { color: var(--muted); }
.panel .alert { margin-bottom: var(--sp-4); }
.profile { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.profile h2 { font-size: var(--fs-lg); font-weight: 650; }

.page-error { display: grid; place-items: center; min-height: 60vh; }
.error-card { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 460px; text-align: center; }
.error-status {
  font-size: 64px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  background: linear-gradient(140deg, var(--brand), color-mix(in oklab, var(--brand) 40%, var(--c9)));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.error-card h1 { font-size: var(--fs-xl); font-weight: 680; }
.error-card p { color: var(--muted); }
.error-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .shell, .shell.no-sidebar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "main";
  }
  .drawer-toggle { display: inline-grid; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; inset-inline-start: 0;
    z-index: 60;
    width: min(84vw, 300px);
    height: 100vh;
    height: 100dvh;
    padding-top: var(--sp-4);
    transform: translateX(-102%);
    /* Closed, it is hidden from the keyboard and screen readers too (after
       the slide out), and casts no shadow at the screen's edge. */
    visibility: hidden;
    transition: transform 0.24s var(--ease), visibility 0s linear 0.24s;
  }
  [dir="rtl"] .sidebar { transform: translateX(102%); }
  .shell.is-drawer-open .sidebar { transform: none; visibility: visible; transition-delay: 0s; box-shadow: var(--shadow-lg); }
  .shell.is-drawer-open .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgb(10 12 18 / 0.4);
    animation: fade-in 0.2s;
  }
  .main { padding: var(--sp-4) var(--sp-4) var(--sp-8); }
  .control-panel { margin-top: calc(-1 * var(--sp-4)); }
  .group-cols, .cols-2, .cols-3, .cols-4 { grid-template-columns: minmax(0, 1fr); }
  .sheet { padding: var(--sp-5) var(--sp-5) var(--sp-4); }
  .prefs-grid { grid-template-columns: minmax(0, 1fr); }
  .table-scroll { max-height: none; }
  .table th, .table th.col-check { position: static; }
}
@keyframes fade-in { from { opacity: 0; } }

@media (max-width: 640px) {
  .brand-name, .user-name, .crumbs li:not(:last-child) { display: none; }
  .crumbs { padding-inline-start: var(--sp-2); }
  .crumbs li + li::before { display: none; }
  .field { grid-template-columns: minmax(0, 1fr); gap: 4px; padding: 6px 0; }
  .field-label { padding-top: 0; }
  .field.w-bool { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .field.w-bool .field-control { padding-top: 0; }
  /* The switch sits beside the label; its help and error take the line
     under both (in the switch's column they squeezed the label to one
     letter a line). */
  .field.w-bool .field-control { display: contents; }
  .field.w-bool .field-control > :is(.field-help, .field-error) { grid-column: 1 / -1; }
  .sheet { padding: var(--sp-4); border-radius: var(--radius); }
  .sheet-title { font-size: var(--fs-xl); }
  .toolbar-title h1 { font-size: var(--fs-lg); }
  /* One line for the title, New, the views and the menu; the title is cut
     first, New shows its + only (its word stays for screen readers). */
  .toolbar-row { column-gap: var(--sp-2); }
  .toolbar-title { flex: 1 1 0; min-width: 0; gap: var(--sp-2); }
  .toolbar-title h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .toolbar-title > .btn-primary { flex: none; padding-inline: 10px; }
  .segmented-item:not(.segmented-text) { width: 30px; }
  .search { flex-basis: 100%; min-width: 0; max-width: none; order: 3; }
  .search-kbd { display: none; }
  .search-panel { width: calc(100vw - 32px); }
  /* The bulk bar gets a line of its own above the pager. */
  .results-bar { flex-wrap: wrap; }
  .bulk-bar { flex: 1 1 100%; }
  /* Icon-only buttons keep their word for screen readers. */
  :is(.toolbar-title > .btn-primary, .btn-discard, .btn-save) > span {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
  }
  .btn-discard, .btn-save { padding: 0 10px; }
  .form-header { border-radius: var(--radius) var(--radius) 0 0; }
  .statusbar { margin-inline-start: 0; }
  .toasts { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
  .toast { max-width: none; }
  .apps-menu { width: min(336px, calc(100vw - 24px)); }
  .app-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: var(--sp-2); }
  .app-tile { padding: 16px 8px 14px; }
  .app-icon-lg { width: 54px; height: 54px; border-radius: 15px; }
  .board-col { flex-basis: 84vw; }
  .table td { max-width: 240px; }
}

@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 print {
  .topbar, .sidebar, .control-panel, .toasts, .form-header .form-buttons, .help-toggle, .help-panel { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .sheet { border: 0; box-shadow: none; padding: 0; }
}

/* ---------- Lists: grouping, export / import, kanban moves ---------- */
.toolbar-actions { flex: none; }
.group-note { white-space: nowrap; }
.table.is-grouped tbody.row-group:not(.is-open) > tr:not(.group-head) { display: none; }
.table .group-head > th, .table .group-head > td { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.table .group-head > th {
  position: static; height: 44px; padding: 0;
  color: var(--text); font-size: 13.5px; font-weight: 600; letter-spacing: normal; text-transform: none;
  text-align: start; white-space: nowrap;
}
.table.is-grouped tbody.row-group > tr:last-child td { border-bottom: 1px solid var(--border); }
.table.is-grouped tbody.row-group:last-of-type:not(.is-open) > .group-head > * { border-bottom: 0; }
.table.is-grouped tbody.row-group > tr.group-head:hover > * { background: var(--surface-3); }
.group-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 12px; border: 0; background: none; color: var(--text);
  font: inherit; text-align: start; cursor: pointer;
}
.group-toggle:hover { color: var(--brand); }
.group-toggle:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.group-chevron { color: var(--subtle); transition: transform 0.15s ease; }
.row-group.is-open .group-chevron { transform: rotate(90deg); }
[dir="rtl"] .group-chevron { transform: scaleX(-1); }
[dir="rtl"] .row-group.is-open .group-chevron { transform: rotate(90deg); }
/* Right to left, icons that point along the line point the other way. */
[dir="rtl"] .icon:has(> use[href="#i-chevron-left"]), [dir="rtl"] .icon:has(> use[href="#i-chevron-right"]),
[dir="rtl"] .icon:has(> use[href="#i-arrow-left"]), [dir="rtl"] .icon:has(> use[href="#i-log-out"]),
[dir="rtl"] .icon:has(> use[href="#i-undo"]) { transform: scaleX(-1); }
/* Right to left, typed text takes its direction from its first letter, so
   "+962 6 555 0100" and Latin names keep their order; numbers stay left to
   right (a minus sign stays in front). Values shown as text sit in <bdi>. */
[dir="rtl"] :is(input:is([type="text"], [type="email"], [type="tel"], [type="url"], [type="search"]), textarea) { unicode-bidi: plaintext; text-align: right; }
[dir="rtl"] bdi { unicode-bidi: plaintext; }
[dir="rtl"] :is(.num, .is-num > bdi) { direction: ltr; unicode-bidi: isolate; }
/* A cut value ends in "…" on its own end: a Latin name keeps its start. */
[dir="rtl"] :is(.table td, .card-value) bdi { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
/* Messages and notes take their direction from their first letter, so an
   English line keeps its full stop at its end; they still line up right. */
[dir="rtl"] :is(.msg-text, .act-summary, .act-note, .notif-title, .notif-body) { unicode-bidi: plaintext; text-align: right; }
.row-group-label { white-space: nowrap; }
.group-toggle .count { margin-inline-start: 2px; }
.group-toggle .spinner { margin-inline-start: auto; }
.group-sum { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.group-more td { padding: 6px 12px; text-align: center; }

.board-col.is-drop { outline: 2px dashed var(--brand); outline-offset: -2px; background: color-mix(in oklab, var(--brand) 6%, var(--surface-2)); }
.card[draggable="true"] { cursor: grab; }
.card.is-dragging { opacity: 0.45; cursor: grabbing; }
.board-more { align-self: center; }

.import-grid { display: grid; grid-template-columns: minmax(0, 22rem) minmax(0, 1fr); gap: var(--sp-4); align-items: start; }
.import-help { margin: 0; padding-inline-start: 1.1em; display: flex; flex-direction: column; gap: 4px; }
.import-fields summary { cursor: pointer; color: var(--muted); font-size: var(--fs-sm); }
.import-fields ul { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; font-size: var(--fs-sm); }
.import-result { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; }
.import-subtitle { font-size: var(--fs-sm); font-weight: 650; color: var(--muted); }
.import-errors { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-sm); }
.import-errors li { display: flex; gap: 10px; }
.import-line { flex: none; min-width: 4.5em; color: var(--danger); font-weight: 600; font-variant-numeric: tabular-nums; }
.import-preview td { white-space: nowrap; max-width: 18rem; overflow: hidden; text-overflow: ellipsis; }
.import-upload { display: flex; flex-direction: column; gap: var(--sp-3); }
.input-file { padding: 5px; color: var(--muted); }
.input-file::file-selector-button {
  margin-inline-end: 10px; padding: 5px 12px;
  border: 1px solid var(--border-strong, var(--border)); border-radius: var(--radius-sm, 6px);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 550; cursor: pointer;
}
.input-file::file-selector-button:hover { background: var(--surface-3); }
@media (max-width: 760px) {
  .import-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Editable lines (one2many inside a form) ---------- */

.o2m > .lines { align-self: stretch; }
.lines { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-2); min-width: 0; }
.lines-scroll { align-self: stretch; max-height: none; border: 1px solid var(--border); border-radius: var(--radius); }
.lines-table { margin: 0; }
.lines-table th { white-space: nowrap; }
.lines-table td.line-td { padding: 5px 6px; vertical-align: top; }
.lines-table td.line-td:first-child { padding-inline-start: 10px; }
.lines-table .input { min-width: 8rem; }
.lines-table .is-num .input { min-width: 6rem; text-align: end; }
.lines-table .select-wrap, .lines-table .combo { min-width: 10rem; }
.lines-table .readonly { padding: 7px 4px; }
.lines-table .is-num .readonly { text-align: end; }
.line-actions { width: 1%; white-space: nowrap; text-align: end; vertical-align: middle; }
.line-cell.has-error .input { border-color: var(--danger); }
.cell-error { margin: 4px 0 0; color: var(--danger); font-size: var(--fs-xs); line-height: 1.35; white-space: normal; }
.line-error { margin: 0 0 4px; }
.lines-error { margin: 0; }
.lines-empty[hidden] { display: none; }
.lines-add { margin-inline-start: -6px; }

/* Phones: each line is a small card: the first column and the remove button
   on top, the other columns wrapping below, their names shown above them. */
@media (max-width: 640px) {
  .lines-scroll { overflow: visible; border: 0; border-radius: 0; }
  .lines-table, .lines-table tbody { display: block; }
  .lines-table thead { display: none; }
  .lines-table tbody { display: flex; flex-direction: column; gap: var(--sp-2); }
  .lines-table tr.line {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 10px;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  }
  .lines-table tbody tr.line:hover td { background: none; }
  .lines-table tr.line > td, .lines-table tr.line > td:first-child {
    display: block; height: auto; max-width: none; padding: 0; border: 0; order: 2; flex: 1 1 5.5rem; min-width: 0;
  }
  .lines-table tr.line > td:first-child { order: 0; flex: 1 1 calc(100% - 52px); }
  .lines-table tr.line > td.line-actions { order: 1; flex: 0 0 auto; width: auto; }
  .lines-table .input, .lines-table .is-num .input, .lines-table .select-wrap, .lines-table .combo { min-width: 0; width: 100%; }
  .lines-table .readonly { padding: 7px 0; }
  .lines-table .line-cell > .line-label {
    position: static !important; display: block; width: auto; height: auto; margin: 0 0 4px; overflow: hidden;
    clip: auto; clip-path: none; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font-size: var(--fs-xs);
  }
}

/* Set password (administrators) */
.password-panel { max-width: 520px; }
.password-panel .alert { margin-bottom: var(--sp-4); }
.password-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Charts (graph views), drawn by ui.BuildChart. */
/* Series colors: the first is the brand indigo; the order keeps
   neighbouring series apart for color-blind readers. Dark mode has the
   same hues, stepped for the dark surface. */
:root {
  --chart-0: #5b5bd6;
  --chart-1: #eb6834;
  --chart-2: #1baf7a;
  --chart-3: #eda100;
  --chart-4: #e87ba4;
  --chart-5: #008300;
  --chart-6: #0894b3;
  --chart-7: #e34948;
  --chart-grid: var(--border);
  --chart-axis: var(--border-strong);
  --chart-on-fill: #ffffff;
  --chart-on-light-fill: #161a22;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --chart-0: #7b7bf0;
    --chart-1: #d95926;
    --chart-2: #199e70;
    --chart-3: #c98500;
    --chart-4: #d55181;
    --chart-5: #008300;
    --chart-6: #0ea5c6;
    --chart-7: #e66767;
  }
}

:root[data-theme="dark"] {
  --chart-0: #7b7bf0;
  --chart-1: #d95926;
  --chart-2: #199e70;
  --chart-3: #c98500;
  --chart-4: #d55181;
  --chart-5: #008300;
  --chart-6: #0ea5c6;
  --chart-7: #e66767;
}

/* The drawing scales with its container; below 540px it scrolls rather
   than shrinking its text out of reach. */
.chart-box { display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; overflow-x: auto; }
.chart {
  display: block; width: 100%; height: auto; max-width: 60rem; min-width: 540px;
  font-family: var(--font-sans); font-size: 12px;
  direction: ltr; /* the layout mirrors itself for right to left (is-rtl) */
}
.chart.is-rtl { direction: rtl; }
.chart text { fill: var(--muted); }
.chart .chart-num { direction: ltr; font-variant-numeric: tabular-nums; }
.chart-grid line { stroke: var(--chart-grid); stroke-width: 1; vector-effect: non-scaling-stroke; shape-rendering: crispEdges; }
.chart-axis { stroke: var(--chart-axis); stroke-width: 1; vector-effect: non-scaling-stroke; shape-rendering: crispEdges; }

.chart-c0 { --chart: var(--chart-0); }
.chart-c1 { --chart: var(--chart-1); }
.chart-c2 { --chart: var(--chart-2); }
.chart-c3 { --chart: var(--chart-3); }
.chart-c4 { --chart: var(--chart-4); }
.chart-c5 { --chart: var(--chart-5); }
.chart-c6 { --chart: var(--chart-6); }
.chart-c7 { --chart: var(--chart-7); }

/* Marks are styled through their group: the svg's own class names the
   kind (chart-bar, chart-line), so it can't name a mark too. */
.chart-bars path, .chart-slices path, .chart-dots circle { fill: var(--chart, var(--chart-0)); }
.chart-bars path, .chart-slices path { transition: opacity 0.12s var(--ease); }
.chart-bars path:hover, .chart-slices path:hover { opacity: 0.8; }
.chart-lines polyline {
  fill: none; stroke: var(--chart, var(--chart-0)); stroke-width: 2;
  stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke;
}
/* A ring of the surface keeps dots apart from lines; a gap between slices. */
.chart-dots circle { stroke: var(--surface); stroke-width: 2; }
.chart-slices path { stroke: var(--surface); stroke-width: 2; stroke-linejoin: round; }
.chart .chart-pct { fill: var(--chart-on-fill); font-size: 13px; font-weight: 650; pointer-events: none; }
.chart .chart-pct.chart-c3 { fill: var(--chart-on-light-fill); }

.chart-legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; padding: 0; list-style: none;
  font-size: var(--fs-sm); color: var(--text-2);
}
.chart-legend li { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chart-swatch { flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--chart, var(--chart-0)); }
.chart-box-line .chart-swatch { width: 14px; height: 3px; border-radius: var(--radius-full); }
.chart-legend-label { min-width: 0; overflow-wrap: anywhere; }
.chart-legend-value, .chart-legend-pct { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* A pie sits beside its legend when there is room, below it when not. */
.chart-box-pie { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--sp-4) var(--sp-8); }
.chart.chart-pie { flex: 0 1 18rem; max-width: 18rem; min-width: 0; }
.chart-box-pie .chart-legend { flex-direction: column; flex-wrap: nowrap; gap: 6px; min-width: min(16rem, 100%); }
/* The label pushes the numbers to the far end: numbers are left to right
   even in Arabic (.num), so their own inline-start is the wrong side. */
.chart-box-pie .chart-legend-label { margin-inline-end: auto; padding-inline-end: var(--sp-4); }
.chart-box-pie .chart-legend-pct { min-width: 3.5em; text-align: right; }
[dir="rtl"] .chart-box-pie .chart-legend-pct { text-align: left; }

.chart-empty { padding: var(--sp-8) var(--sp-4); text-align: center; }

/* ---------- Analysis views: controls, pivot, graph, calendar ---------- */

[dir="rtl"] .flip-rtl { transform: scaleX(-1); }

.analysis-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
}
/* The selects share the line with Swap and Export (Export went to a line
   of its own when the selects took their natural width). */
.analysis-select { display: flex; flex-direction: column; gap: 3px; flex: 1 1 9rem; min-width: 9rem; max-width: 13rem; }
.analysis-controls > .btn { flex: none; }
.analysis-select .select { height: var(--control-h); }

.pivot-scroll { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.pivot { width: auto; min-width: 100%; }
.pivot th, .pivot td { white-space: nowrap; }
.pivot thead th { background: var(--surface-2); border-inline-end: 1px solid var(--border); }
.pivot td { border-inline-end: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.pivot .pivot-label { color: var(--text); font-weight: 520; text-align: start; }
.pivot .pivot-l1 .pivot-label { padding-inline-start: calc(var(--sp-3) + 18px); }
.pivot .pivot-l2 .pivot-label { padding-inline-start: calc(var(--sp-3) + 36px); }
.pivot .pivot-sub th, .pivot .pivot-sub td { background: var(--surface-2); font-weight: 600; }
.pivot .pivot-total { background: color-mix(in oklab, var(--surface-3) 60%, var(--surface)); font-weight: 600; }
.pivot .pivot-grand th, .pivot .pivot-grand td { border-top: 2px solid var(--border-strong); background: var(--surface-3); color: var(--text); font-weight: 650; }
.pivot-cut, .graph-note { margin-top: var(--sp-2); }

.graph { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.graph-numbers summary { cursor: pointer; color: var(--muted); font-size: var(--fs-sm); font-weight: 560; }
.graph-numbers .table-scroll { margin-top: var(--sp-2); }

.cal-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.cal-nav { display: flex; align-items: center; gap: var(--sp-1); }
.cal-title { margin-inline-start: var(--sp-2); font-size: var(--fs-lg); font-weight: 650; }
.cal { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--border); gap: 1px; overflow: hidden; }
.cal-head, .cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; }
.cal-dayname { padding: 6px 8px; background: var(--surface-2); color: var(--muted); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.cal .cal-day {
  flex: initial;
  gap: 4px;
  min-height: 7.5rem;
  min-width: 0;
  padding: 6px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
}
.cal-week .cal-day { min-height: 22rem; }
.cal-day.is-outside { background: var(--surface-2); }
.cal-day.is-outside .cal-num { color: var(--subtle); }
.cal-day-head { display: flex; align-items: center; justify-content: space-between; min-height: 24px; }
.cal-num { display: inline-grid; place-items: center; min-width: 24px; height: 24px; border-radius: var(--radius-full); color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-day.is-today .cal-num { background: var(--brand); color: var(--on-brand); }
.cal-new { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: var(--radius-sm); color: var(--subtle); opacity: 0; transition: opacity 0.12s; }
.cal-day:hover .cal-new, .cal-new:focus-visible { opacity: 1; }
@media (hover: none) { .cal-new { opacity: 1; } } /* no hover on touch screens */
.cal-new:hover { background: var(--surface-3); color: var(--text); }
.cal-events { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
/* The color comes from the tag-N class the event always has. */
.cal-event {
  display: block;
  overflow: hidden;
  padding: 2px 6px;
  border-inline-start: 3px solid var(--tag);
  border-radius: var(--radius-xs);
  background: color-mix(in oklab, var(--tag) 12%, var(--surface));
  color: var(--text);
  font-size: var(--fs-xs);
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-event:hover { text-decoration: none; background: color-mix(in oklab, var(--tag) 20%, var(--surface)); }
.cal-event[draggable="true"] { cursor: grab; }
.cal-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.cal-more { padding-inline-start: 6px; }
@media (max-width: 640px) {
  .cal .cal-day { min-height: 4.5rem; padding: 3px; }
  .cal-dayname { padding: 4px 2px; text-align: center; letter-spacing: 0; }
  .cal-event { padding: 1px 3px; }
  .cal-time { display: none; }
}

/* ---------- Editable lists ---------- */

/* The pencil (and a row's save / discard) stays in view when a wide list
   scrolls sideways, as on phones. */
.table .col-edit { width: 1%; padding-block: 0; padding-inline: 4px 10px; white-space: nowrap; text-align: end; position: sticky; inset-inline-end: 0; z-index: 1; background: var(--surface); }
.table th.col-edit { background: var(--surface-2); z-index: 3; }
.table tbody tr .col-edit .icon-btn { opacity: 0; transition: opacity 0.12s; }
.table tbody tr:hover .col-edit .icon-btn, .table tbody tr .col-edit .icon-btn:focus-visible, .table tr.is-editing .col-edit .icon-btn { opacity: 1; }
.table tr.is-editing td { background: var(--brand-softer); vertical-align: top; }
.table tr.is-editing td.line-td { padding: 5px 6px; }
.table tr.is-editing .input { min-width: 7rem; }
.table tr.is-editing .is-num .input { min-width: 5rem; text-align: end; }
.table tr.is-editing .readonly { padding: 7px 4px; }
/* A picture in a row being edited stays a thumbnail (it changes on the form). */
.table tr.is-editing .readonly-image { padding: 0; }
.table tr.is-editing .readonly-image .image-preview { width: 36px; height: 36px; object-fit: cover; }
.table tr.is-editing .readonly-image > .link { display: none; }
.row-edit-actions { display: flex; gap: 2px; justify-content: flex-end; padding-top: 4px; }
@media (hover: none) { .table tbody tr .col-edit .icon-btn { opacity: 1; } }

/* ---------- Collaboration: bell, followers, activities, notifications ---------- */

.notify-btn { position: relative; }
.notify-badge {
  position: absolute;
  inset-block-start: 2px;
  inset-inline-end: 1px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--surface);
}

.chatter-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.chatter-follow { display: flex; align-items: center; gap: var(--sp-2); }
.chatter-follow form { margin: 0; }
.btn.is-following { color: var(--brand-fg); border-color: var(--brand-line); background: var(--brand-softer); }
.chatter-subtitle { margin-bottom: var(--sp-2); color: var(--muted); font-size: var(--fs-sm); font-weight: 650; }
.schedule > summary { list-style: none; width: max-content; }
.schedule > summary::-webkit-details-marker { display: none; }
.schedule[open] > summary { margin-bottom: var(--sp-3); }
.schedule-form { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); }
.schedule-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); }
.schedule-fields > :last-child { grid-column: 1 / -1; }

.act-list { display: flex; flex-direction: column; gap: var(--sp-2); margin: 0; padding: 0; list-style: none; }
.act { display: flex; gap: var(--sp-3); align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.act-icon { display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: var(--radius-full); background: var(--info-soft); color: var(--info); }
.act-late .act-icon { background: var(--danger-soft); color: var(--danger); }
.act-today .act-icon { background: var(--warning-soft); color: var(--warning); }
.act-planned .act-icon { background: var(--success-soft); color: var(--success); }
.act-main { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--sp-2); flex: 1; min-width: 0; }
.act-head, .act-summary, .act-note { flex-basis: 100%; min-width: 0; overflow-wrap: anywhere; }
.act-due { font-size: var(--fs-sm); font-weight: 650; }
.act-late .act-due { color: var(--danger); }
.act-today .act-due { color: var(--warning); }
.act-note { white-space: pre-wrap; }
.act-actions > summary { list-style: none; }
.act-actions > summary::-webkit-details-marker { display: none; }
.act-actions[open] { flex-basis: 100%; }
.act-done { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }
.act-done .input { flex: 1 1 14rem; }
.act-cancel { margin: 0; }

.page-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-inline-start: auto; }
.page-actions form { margin: 0; }
.notif-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.notif + .notif { border-top: 1px solid var(--border); }
.notif-link { display: flex; gap: var(--sp-3); padding: 12px 16px; color: var(--text-2); }
.notif-link:hover { text-decoration: none; background: var(--surface-2); }
.notif.is-unread .notif-link { background: var(--brand-softer); }
.notif-icon { display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: var(--radius-full); background: var(--surface-3); color: var(--muted); }
.notif-mention .notif-icon { background: var(--brand-soft); color: var(--brand-fg); }
.notif-activity .notif-icon { background: var(--warning-soft); color: var(--warning); }
.notif-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif-head { display: flex; align-items: center; gap: var(--sp-2); }
.notif-title { color: var(--text); overflow-wrap: anywhere; }
.notif-dot { width: 8px; height: 8px; flex: none; border-radius: var(--radius-full); background: var(--brand); }
.notif-body { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: pre-wrap; overflow-wrap: anywhere; }

.act-group + .act-group { margin-top: var(--sp-5); }
.act-group-title { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-2); font-size: var(--fs-md); font-weight: 650; }
.act-late .act-group-title { color: var(--danger); }
@media (max-width: 640px) {
  .schedule-fields { grid-template-columns: minmax(0, 1fr); }
  .notif-link { padding: 10px 12px; }
}

/* A picture shown large over the page (links with data-zoom). */
.lightbox { position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: var(--sp-4); border: 0; background: transparent; color: #fff; }
.lightbox[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2); }
.lightbox::backdrop { background: rgb(10 12 16 / 0.82); }
/* The frame is as wide as the picture; the bar takes no width of its own
   (width 0, at least the frame's), so a long title can't widen it. */
.lightbox-frame { display: flex; flex-direction: column; gap: var(--sp-2); width: fit-content; min-width: min(280px, 100%); max-width: 100%; }
.lightbox-bar { display: flex; align-items: center; gap: var(--sp-1); width: 0; min-width: 100%; }
.lightbox-frame > .lightbox-img { align-self: center; }
.lightbox-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lightbox .icon-btn { color: #fff; }
.lightbox .icon-btn:hover { background: rgb(255 255 255 / 0.14); }
.lightbox-img { display: block; max-width: min(100%, 1200px); max-height: calc(100dvh - 96px); object-fit: contain; border-radius: var(--radius); background: #fff; box-shadow: 0 12px 40px rgb(0 0 0 / 0.45); }

/* A tab holding only a field of the same name doesn't repeat the name
   (the label stays for screen readers). */
.tabpanel-solo > .field { gap: 0; }
.tabpanel-solo > .field > .field-label {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* A button whose form is being sent (data-once): further clicks do nothing. */
.btn[data-busy] { cursor: progress; opacity: 0.7; }

/* ---------- Touch screens ---------- */
/* Fingers (often gloved, on a scanner) need bigger targets than a mouse:
   44px controls, 40px small buttons and icon buttons, 22px boxes. */
@media (pointer: coarse) {
  :root { --control-h: 44px; }
  .btn-sm { height: 40px; padding-inline: 14px; }
  .icon-btn-sm { width: 40px; height: 40px; }
  .checkbox { width: 22px; height: 22px; border-radius: 5px; }
  .checkbox:checked::before { width: 11px; height: 6px; }
  .check-hit { min-height: 44px; }
  .table td { height: 48px; }
  .chip-toggle span { height: 36px; padding-inline: 14px; font-size: var(--fs-sm); }
  .facet { height: 30px; }
  .facet-remove { width: 26px; height: 26px; }
  .menu-check { min-height: 44px; }
  .searchbar { min-height: 44px; }
  .tag-remove { width: 26px; height: 26px; }
  .tags-q { height: 34px; }
  .sidenav-link { min-height: 44px; }
  .dropdown-item { min-height: 44px; }
  .segmented-item { height: 36px; }
  .segmented-item:not(.segmented-text) { width: 34px; } /* five views still fit a phone's toolbar line */
  .tab { padding-block: 12px; }
  .combo-option { min-height: 44px; }
  .cal-new { width: 32px; height: 32px; }
  .search-box input { height: 44px; }
  .switch-track { width: 44px; height: 26px; }
  .switch-thumb { width: 21px; height: 21px; }
  .switch-input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
  [dir="rtl"] .switch-input:checked + .switch-track .switch-thumb { transform: translateX(-18px); }
}
