/* ============================================================
   Microcessor Design System — Bootstrap Overrides
   ============================================================
   Brand: #925D87 (plum) / --bs-primary #875D92 (violet)
   Text:  #414244 (dark gray)
   BG:    #F7F6F3 (warm off-white)
   ============================================================ */

/* Carton — the default theme. Warm paper tones: deeper warm background,
   soft off-white surfaces, warm-tinted borders and text. */
:root, [data-theme="carton"] {
  /* Brand overrides for Bootstrap */
  --bs-primary: #875D92;
  --bs-primary-rgb: 135, 93, 146;
  --bs-body-bg: #ECEAE5;
  --bs-body-color: #38372F;
  --bs-font-sans-serif: 'Inter', system-ui, -apple-system, sans-serif;
  --bs-border-color: #D8D4C8;

  /* Custom tokens */
  --brand: #925D87;
  --brand-dark: #7A4C70;
  --brand-darker: #623C5A;
  --brand-light: #B07FA6;
  --brand-subtle: #EDE2E9;
  --coral: #FF6B5B;
  --coral-dark: #F5564A;
  --focus: #5D9288;
  --focus-dark: #4A7A70;
  --focus-subtle: #DFE9E4;
  --danger: #C0392B;
  --danger-dark: #A93226;
  --danger-subtle: #F2DDD8;
  --warning: #A8761B;
  --warning-subtle: #F0E4CB;
  --text-primary: #38372F;
  --text-secondary: #625F53;
  --text-muted: #918D7F;
  --bg: #ECEAE5;
  --bg-sunken: #E2DFD4;
  --surface: #F8F7F3;
  --bg-hover: #E6E3D9;
  --surface-hover: rgba(85, 60, 8, 0.05);
  --veil: rgba(185, 182, 175, 0.45);
  --logo-url: url('/public/micro.svg?v=2');
  color-scheme: light;
}

[data-theme="light"] {
  /* Brand overrides for Bootstrap */
  --bs-primary: #875D92;
  --bs-primary-rgb: 135, 93, 146;
  --bs-body-bg: #F7F6F3;
  --bs-body-color: #414244;
  --bs-font-sans-serif: 'Inter', system-ui, -apple-system, sans-serif;
  --bs-border-color: #E2E0DB;

  /* Custom tokens */
  --brand: #925D87;
  --brand-dark: #7A4C70;
  --brand-darker: #623C5A;
  --brand-light: #B07FA6;
  --brand-subtle: #F2E6EF;
  --coral: #FF6B5B;
  --coral-dark: #F5564A;
  --focus: #5D9288;
  --focus-dark: #4A7A70;
  --focus-subtle: #E8F2EF;
  --danger: #C0392B;
  --danger-dark: #A93226;
  --danger-subtle: #FADBD8;
  --warning: #B7791F;
  --warning-subtle: #FCEFD4;
  --text-primary: #414244;
  --text-secondary: #6B6D6F;
  --text-muted: #9B9DA0;
  --bg: #F7F6F3;
  --bg-sunken: #EFEEE9;
  --surface: #fff;
  --bg-hover: #f1f3f5;
  --surface-hover: rgba(0, 0, 0, 0.03);
  --veil: rgba(176, 174, 168, 0.4);
  --logo-url: url('/public/micro.svg?v=2');
  color-scheme: light;
}

[data-theme="dark"] {
  --bs-primary: #A67FB0;
  --bs-primary-rgb: 166, 127, 176;
  --bs-body-bg: #1A1B1E;
  --bs-body-color: #E0DED9;
  --bs-border-color: #2E3035;

  --brand: #B07FA6;
  --brand-dark: #925D87;
  --brand-darker: #7A4C70;
  --brand-light: #C49BBC;
  --brand-subtle: #2C2229;
  --focus: #7DB0A5;
  --focus-dark: #5D9288;
  --focus-subtle: #1E2C29;
  --danger: #E74C3C;
  --danger-dark: #C0392B;
  --danger-subtle: #3B1C1A;
  --warning: #E0A33E;
  --warning-subtle: #372C15;
  --text-primary: #E0DED9;
  --text-secondary: #A3A1A0;
  --text-muted: #8A8C8F;
  --bg: #1A1B1E;
  --bg-sunken: #141517;
  --surface: #232529;
  --bg-hover: #2a2c30;
  --surface-hover: rgba(255, 255, 255, 0.04);
  --veil: rgba(8, 9, 11, 0.55);
  --logo-url: url('/public/microw.svg?v=2');
  color-scheme: dark;
}

/* Geometry, not palette: the same in every theme, so it is declared once. */
:root {
  --radius-sm: 6px;
}

body {
  font-family: var(--bs-font-sans-serif);
  background-color: var(--bg);
  color: var(--text-primary);
}

/* --- Alpine.js: hide elements until initialized --- */
[x-cloak] { display: none !important; }

/* --- Bootstrap button override --- */
.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark);
  --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-darker);
  --bs-btn-active-border-color: var(--brand-darker);
  --bs-btn-disabled-bg: var(--brand);
  --bs-btn-disabled-border-color: var(--brand);
}

.btn-outline-danger {
  --bs-btn-color: var(--danger);
  --bs-btn-border-color: var(--danger);
  --bs-btn-hover-bg: var(--danger);
  --bs-btn-hover-border-color: var(--danger);
  --bs-btn-hover-color: #fff;
  --bs-btn-active-bg: var(--danger-dark);
  --bs-btn-active-border-color: var(--danger-dark);
}

.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-border-color: var(--brand);
  --bs-btn-active-bg: var(--brand-dark);
  --bs-btn-active-border-color: var(--brand-dark);
}

/* --- Links --- */
a {
  color: var(--brand);
}
a:hover {
  color: var(--brand-dark);
}

/* --- Navbar --- */
.navbar {
  background: color-mix(in srgb, var(--bg) 92%, transparent) !important;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bs-border-color);
}

/* --- Dark mode: surface colors --- */
[data-theme="dark"] .card,
[data-theme="dark"] .form-control,
[data-theme="dark"] .form-select,
[data-theme="dark"] .input-group-text { background-color: var(--surface); color: var(--text-primary); border-color: var(--bs-border-color); }
[data-theme="dark"] .form-control::placeholder { color: var(--text-muted); }
[data-theme="dark"] .btn-outline-primary { --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand); }
[data-theme="dark"] .text-muted { color: var(--text-muted) !important; }
[data-theme="dark"] .text-secondary { color: var(--text-secondary) !important; }
[data-theme="dark"] .table {
  --bs-table-color: var(--text-primary);
  --bs-table-striped-color: var(--text-primary);
  --bs-table-active-color: var(--text-primary);
  --bs-table-hover-color: var(--text-primary);
}
[data-theme="dark"] .border-bottom, [data-theme="dark"] .border-top { border-color: var(--bs-border-color) !important; }
[data-theme="dark"] .form-nested-overlay { background: rgba(0, 0, 0, 0.88); }

/* --- Form inputs — upgraded polish ---
   Shared visual DNA for .form-control, .form-select, .msel-trigger, .mdate-trigger.
   Any native <input>, <select>, or custom trigger inherits the same look. */
.form-control,
.form-select {
  border: 2px solid var(--bs-border-color);
  border-radius: 10px;
  color: var(--text-primary);
  background-color: var(--surface);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.form-control,
.form-select,
.form-control-sm,
.form-select-sm {
  min-height: 38px;
  padding: 8px 12px;
  font-size: 0.875rem;
  line-height: 1.35;
}
.form-control::placeholder {
  color: var(--text-muted);
  opacity: 1;
}
.form-control:hover:not(:focus):not(:disabled):not([readonly]),
.form-select:hover:not(:focus):not(:disabled) {
  border-color: var(--brand-light);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
}
.form-control:focus,
.form-select:focus {
  border-color: var(--brand);
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent),
    0 1px 2px rgba(16, 24, 40, 0.05);
}
.form-control:disabled,
.form-control[readonly],
.form-select:disabled {
  background-color: var(--bg-sunken);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}
textarea.form-control,
textarea.form-control-sm {
  min-height: 72px;
  line-height: 1.5;
}

/* Native <select> visual parity — keep Bootstrap's chevron but push it in
   so it sits at the same inset as the msel/mdate triggers. */
.form-select {
  padding-left: 36px;
  background-position: left 12px center;
  background-size: 14px 10px;
}

/* --- Labels — assertive, spaced --- */
.form-label,
.form-group .form-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.005em;
  margin-bottom: 0;
  line-height: 1.3;
}
.form-group .form-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  margin-bottom: 0.5rem;
}

/* Form switch / checkbox brand color */
.form-check-input {
  border-color: var(--bs-border-color);
}
.form-check-input:checked {
  background-color: var(--brand);
  border-color: var(--brand);
}
.form-check-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}

/* --- Cards --- */
.card {
  border-color: var(--bs-border-color);
  border-radius: 0.75rem;
  background: var(--surface);
  transition: box-shadow 0.2s ease;
}
.card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* --- Brand helpers --- */
.text-brand { color: var(--brand) !important; }
.bg-brand { background-color: var(--brand) !important; }
.bg-brand-subtle { background-color: var(--brand-subtle) !important; }
.border-brand { border-color: var(--brand) !important; }

/* --- Badge overrides --- */
.badge.bg-brand-subtle {
  color: var(--brand-dark);
}

/* --- Custom: app icon box --- */
.app-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-subtle);
  color: var(--brand);
  border-radius: 0.5rem;
}

/* --- Custom: app cloud (radial icon arrangement on landing) --- */
.app-cloud {
  position: relative;
  width: 100%;
  max-width: 820px;
  aspect-ratio: 1.7 / 1;
  margin: 0 auto;
}
.app-bubble {
  position: absolute;
  transform: translate(50%, -50%);
  display: block;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              filter 0.25s ease;
  cursor: pointer;
  text-decoration: none;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.12));
  z-index: 1;
}
.app-bubble img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 22%;
}
.app-bubble:hover {
  transform: translate(50%, -50%) scale(1.55);
  z-index: 10;
  filter: drop-shadow(0 16px 28px rgba(0, 0, 0, 0.25));
}
.app-bubble--xl { width: 80px; height: 80px; }
.app-bubble--lg { width: 64px; height: 64px; }
.app-bubble--md { width: 52px; height: 52px; }
.app-bubble--sm { width: 40px; height: 40px; }
.app-bubble .bubble-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 50%;
  transform: translateX(50%);
  background: var(--text-primary);
  color: var(--bg);
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.app-bubble:hover .bubble-tooltip { opacity: 1; }
@media (max-width: 576px) {
  .app-bubble--xl { width: 54px; height: 54px; }
  .app-bubble--lg { width: 44px; height: 44px; }
  .app-bubble--md { width: 34px; height: 34px; }
  .app-bubble--sm { width: 26px; height: 26px; }
  .app-bubble .bubble-tooltip { font-size: 10px; }
}

/* --- Custom: numbered steps --- */
.step-number {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 1.125rem;
  border-radius: 50%;
  flex-shrink: 0;
}

/* --- Custom: code block --- */
.code-block {
  background: #1E1E2E;
  color: #CDD6F4;
  border-radius: 0.75rem;
  padding: 1.5rem;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
}
.code-block .comment { color: #6C7086; }
.code-block .keyword { color: #CBA6F7; }
.code-block .string { color: #A6E3A1; }
.code-block .function { color: #89B4FA; }
.code-block .punctuation { color: #9399B2; }

/* --- Custom: CTA banner --- */
.cta-banner {
  background: var(--brand);
  border-radius: 1rem;
  color: #fff;
}
.cta-banner h2 { color: #fff; }
.cta-banner p { color: rgba(255, 255, 255, 0.8); }

.btn-white {
  background: var(--surface);
  color: var(--brand);
  border: none;
  font-weight: 600;
}
.btn-white:hover {
  background: var(--bg);
  color: var(--brand-dark);
}

/* --- Pricing card --- */
.pricing-card .price {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--brand);
}
.pricing-card .price-unit {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 400;
}
.pricing-card .free-tier {
  font-size: 0.8rem;
  color: var(--focus);
  font-weight: 500;
}

/* --- Ecosystem pills --- */
.eco-node {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 50rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  transition: all 0.2s ease;
}
.eco-node:hover {
  border-color: var(--brand);
  background: var(--brand-subtle);
  color: var(--brand-dark);
}
.eco-hub {
  padding: 0.6rem 1.5rem;
  background: var(--brand);
  color: #fff;
  border-radius: 50rem;
  font-weight: 700;
  font-size: 1rem;
  border: 2px solid var(--brand);
}
.eco-connector {
  width: 32px;
  height: 2px;
  background: var(--bs-border-color);
}

@media (max-width: 768px) {
  .eco-connector {
    display: none;
  }
}

/* ============================================================
   Form Drawer System
   ============================================================ */

/* --- Backdrop: translucent glass blur --- */
.form-backdrop {
  position: fixed;
  inset: 0;
  background: var(--veil);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 1040;
  cursor: pointer;
}

/* --- Right-side drawer --- */
.form-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 65vw;
  min-width: 480px;
  max-width: 90vw;
  background: var(--bg);
  border-right: 1px solid var(--bs-border-color);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.08);
  animation: drawer-slide-in 0.2s ease-out;
}

@media (max-width: 768px) {
  .form-drawer {
    width: 100vw;
    min-width: 0;
  }
}

@keyframes drawer-slide-in {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

.form-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--bs-border-color);
  flex-shrink: 0;
}

.form-drawer-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}

/* Breadcrumb crumbs inside a (possibly nested) drawer title */
.form-crumb {
  font: inherit;
  white-space: nowrap;
}

/* Only the current (last) crumb truncates when space is tight — the parent
   pill always shows its full name. */
.form-crumb-current {
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Parent crumb — a pill button that closes this layer back to the parent */
.form-crumb-parent {
  flex-shrink: 0;
  border: 1px solid var(--bs-border-color);
  background: var(--surface-hover);
  color: var(--text-secondary);
  font-weight: 500;
  border-radius: 999px;
  padding: 0.125rem 0.625rem;
  cursor: pointer;
}

.form-crumb-parent:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.form-crumb-sep {
  font-size: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* A form layer = backdrop + drawer. Top-level layers paint at the backdrop/
   drawer's own z-index; a nested layer establishes its own stacking context
   above the parent so its backdrop dims the parent drawer underneath. */
.form-panel-layer-nested {
  position: relative;
  z-index: 1070;
}

.form-drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.form-drawer-body::-webkit-scrollbar { display: none; }

.form-drawer-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}
.form-drawer-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.form-drawer-close .material-symbols-outlined { font-size: 20px; }

.form-drawer-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--bs-border-color);
  display: flex;
  justify-content: space-between;
  margin-top: auto;
}

/* ============================================================
   Form Modal — centered sibling of the form drawer (forms/modal.html)
   Same fields + submit as the drawer, rendered as a wide centered card.
   Reuses .form-backdrop for the overlay.

   Centered via a flex positioner, NOT a transform on the card: a
   transformed ancestor becomes the containing block for the select
   dropdown's position:fixed, which mispositions it and causes a
   focus/scroll reposition loop (violent flicker). The positioner is
   click-through (pointer-events:none) so clicks outside the card reach
   the backdrop and close it; the card re-enables pointer events.
   ============================================================ */
.form-modal-positioner {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.form-modal {
  pointer-events: auto;
  width: 65vw;
  min-width: 520px;
  height: 86vh;
  background: var(--bg);
  border: 2px solid var(--brand);
  border-radius: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  animation: form-modal-in 0.16s ease-out;
}

@keyframes form-modal-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@media (max-width: 768px) {
  .form-modal {
    width: 100vw;
    min-width: 0;
    height: 100%;
    border-radius: 0;
    border-width: 0;
  }
}

.form-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--bs-border-color);
  flex-shrink: 0;
}

.form-modal-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}
.form-modal-close:hover { background: var(--surface-hover); color: var(--text-primary); }
.form-modal-close .material-symbols-outlined { font-size: 20px; }

.form-modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.form-modal-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--bs-border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Inline chips field (Chips descriptor) — toggle pills syncing an array */
.form-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.form-chip {
  border: 1px solid var(--bs-border-color);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.form-chip:hover { border-color: var(--brand-light); }
.form-chip.is-on {
  background: var(--brand-subtle);
  border-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 500;
}

/* ============================================================
   Drawer System — platform-level slide-out panel
   Usage: overlay → drawer container → header / body
   Width: default (65vw, min 480px), .drawer-lg (70vw)

   The silhouette matches the form drawer: the panel floats off
   every viewport edge with a real radius and shadow. Interiors
   keep their existing --surface plane; only the shell changed.
   ============================================================ */

.drawer-overlay {
  position: fixed; inset: 0; z-index: 1040;
  background: var(--veil);
  -webkit-backdrop-filter: blur(6px) saturate(1.4);
  backdrop-filter: blur(6px) saturate(1.4);
  animation: drawer-fade-in 0.28s ease both;
  cursor: pointer;
}
@keyframes drawer-fade-in { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed; top: 14px; left: 14px; bottom: 14px;
  width: 65vw; min-width: 480px; max-width: calc(100vw - 28px);
  z-index: 1050;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--brand) 14%, var(--bs-border-color));
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    0 48px 90px -24px rgba(20, 18, 16, 0.42),
    0 8px 24px -12px rgba(20, 18, 16, 0.22);
  display: flex; flex-direction: column;
  animation: drawer-slide-in 0.42s cubic-bezier(0.32, 0.72, 0, 1) backwards;
}
[data-theme="dark"] .drawer {
  box-shadow:
    0 48px 90px -24px rgba(0, 0, 0, 0.7),
    0 8px 24px -12px rgba(0, 0, 0, 0.5);
}
.drawer-lg { width: 70vw; }

.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--bs-border-color);
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
}
.drawer-title {
  margin: 0; font-size: 0.9375rem; font-weight: 600;
  color: var(--text-primary);
}
.drawer-close {
  background: none; border: none; font-size: 1.25rem;
  color: var(--text-muted); cursor: pointer;
  padding: 0.25rem; line-height: 1; border-radius: 4px;
}
.drawer-close:hover { background: var(--bg-sunken); color: var(--text-primary); }

.drawer-body {
  flex: 1; overflow-y: auto; padding: 1.25rem;
  scrollbar-width: none; -ms-overflow-style: none;
}
.drawer-body::-webkit-scrollbar { display: none; }

@media (max-width: 768px) {
  .drawer { top: 0; left: 0; bottom: 0; width: 100vw; min-width: 0; border: none; border-radius: 0; }
}

/* ============================================================
   Nested Form (Level 2) — form inside an existing drawer
   Usage: overlay covers the drawer body, toolbar + card on top
   ============================================================ */

.form-nested-overlay {
  position: fixed;
  top: 14px;
  left: 14px;
  bottom: 14px;
  width: 65vw;
  min-width: 480px;
  max-width: calc(100vw - 28px);
  border-radius: 20px;
  overflow: hidden;
  z-index: 1060;
  /* No backdrop-filter/filter/transform here: any of those makes this overlay
     the containing block for position:fixed descendants, which throws the
     microSelect dropdown (currency, pay frequency) off-screen. Opacity is
     raised to keep the drawer behind obscured without the blur. */
  background: rgba(255, 255, 255, 0.74);
  display: flex;
  flex-direction: column;
  animation: drawer-fade-in 0.15s ease;
}

/* Inside the wider detail card the level-2 overlay matches its geometry,
   so the card behind is fully covered rather than peeking out. */
.dv-card .form-nested-overlay { width: min(1080px, 86vw); }

@media (max-width: 768px) {
  .form-nested-overlay {
    top: 0;
    left: 0;
    bottom: 0;
    width: 100vw;
    min-width: 0;
    border-radius: 0;
  }
}

.form-nested-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0rem 9rem;
  margin-top: 9rem;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.form-nested-close {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.form-nested-close:hover {
  background: color-mix(in srgb, var(--danger) 18%, transparent);
}
.form-nested-close .material-symbols-outlined { font-size: 16px; }

.form-nested-save {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  background: color-mix(in srgb, var(--focus) 10%, transparent);
  color: var(--focus);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.form-nested-save:hover {
  background: color-mix(in srgb, var(--focus) 18%, transparent);
}
.form-nested-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.form-nested-save .material-symbols-outlined { font-size: 16px; }

.form-nested-card {
  margin: 0 9rem 9rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.form-nested-card .alert { margin: 0; }

/* ============================================================
   Centered Modal — shared across all apps
   Usage: .pf-modal-backdrop > .pf-modal > header / body / footer
   ============================================================ */

.pf-modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--veil);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1040;
}

.pf-modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: pf-modal-in 0.15s ease;
}

.pf-modal-sm { max-width: 400px; }

@keyframes pf-modal-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.pf-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--bs-border-color);
}

.pf-modal-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.pf-modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.pf-modal-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.pf-modal-close .material-symbols-outlined { font-size: 20px; }

.pf-modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.pf-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--bs-border-color);
}

/* --- Form groups ---
   (label / text styles live with the form inputs block above for cohesion.) */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

/* --- Sections --- */
.form-section {
  border: none;
  padding: 0;
  margin: 0.25rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.form-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0;
  padding-bottom: 0.375rem;
  border-bottom: 1px solid var(--bg-sunken);
}

.form-section-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-section-chevron {
  font-size: 0.625rem;
  transition: transform 0.2s;
}

.form-section-chevron.expanded {
  transform: rotate(-180deg);
}

/* --- Radio cards --- */
.radio-cards {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.radio-card {
  flex: 1;
  min-width: 100px;
  border: 2px solid var(--bs-border-color);
  border-radius: 0.5rem;
  padding: 0.625rem 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  background: var(--surface);
}

.radio-card:hover {
  border-color: var(--brand-light);
}

.radio-card.active {
  border-color: var(--brand);
  background: var(--brand-subtle);
}

.radio-card-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.radio-card-icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  margin-bottom: 0.125rem;
}

.radio-card.active .radio-card-icon {
  color: var(--brand);
}

.radio-card-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.radio-card-desc {
  font-size: 0.6875rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* --- Lookup field --- */
.lookup-wrapper {
  position: relative;
}

.lookup-clear {
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
}

.lookup-clear:hover {
  color: var(--text-primary);
}

.lookup-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 0.375rem;
  margin-top: 0.25rem;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.lookup-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4375rem 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--text-primary);
}

.lookup-option:hover,
.lookup-option.active {
  background: var(--brand-subtle);
  color: var(--brand-dark);
}

.lookup-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.lookup-initials {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.625rem;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  line-height: 1;
}

.lookup-option-icon {
  font-size: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.lookup-status {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
}

/* Inline "create new" affordance inside a lookup dropdown */
.lookup-create-trigger {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--brand);
  cursor: pointer;
  border-top: 1px solid var(--bs-border-color);
}

.lookup-create-trigger:hover {
  background: var(--brand-subtle);
}

.lookup-create-trigger .material-symbols-outlined {
  font-size: 18px;
}

.lookup-multi-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 0.375rem;
}

.lookup-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  background: var(--brand-subtle);
  color: var(--brand-dark);
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.5;
}

.lookup-chip-remove {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1;
  color: var(--brand-dark);
  cursor: pointer;
  opacity: 0.6;
}

.lookup-chip-remove:hover {
  opacity: 1;
}

/* --- File upload zone --- */
.file-upload-zone {
  border: 2px dashed var(--bs-border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.file-upload-zone:hover,
.file-upload-zone.drag-over {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 5%, transparent);
}
.file-upload-icon {
  font-size: 24px;
  color: var(--text-muted);
}
.file-upload-text {
  font-size: 0.8125rem;
  color: var(--text-muted);
}
.file-upload-list {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.file-upload-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.5rem;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  position: relative;
}
.file-upload-item-icon {
  font-size: 18px;
  color: var(--text-muted);
}
.file-upload-item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-upload-item-size {
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}
.file-upload-item-progress {
  position: absolute;
  bottom: 0;
  right: 0;
  left: 0;
  height: 2px;
  background: var(--bs-border-color);
  border-radius: 0 0 6px 6px;
  overflow: hidden;
}
.file-upload-item-bar {
  height: 100%;
  background: var(--brand);
  transition: width 0.2s;
}
.file-upload-item-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.125rem;
}
.file-upload-item-remove:hover {
  color: var(--danger);
}

/* --- Line grid (repeating rows field) --- */
.line-grid .line-grid-table-wrap {
  border: 1px solid var(--bs-border-color);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.line-grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}
.line-grid-table th {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  text-align: right;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--bs-border-color);
}
.line-grid-table td {
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--bs-border-color);
  vertical-align: middle;
}
.line-grid-table tbody tr:last-child td {
  border-bottom: none;
}
.line-grid-table th.num,
.line-grid-table td.num {
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.line-grid-table input,
.line-grid-table select {
  width: 100%;
  font-size: 0.8125rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  border-radius: 4px;
}
.line-grid-table input.num {
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.line-grid-table input:focus,
.line-grid-table select:focus {
  border-color: var(--brand);
  background: var(--surface);
  outline: none;
}
.line-grid-table tfoot td {
  font-weight: 600;
  padding: 0.4rem 0.5rem;
  border-top: 2px solid var(--bs-border-color);
  border-bottom: none;
}
.line-grid-table .row-actions {
  width: 32px;
  text-align: center;
}
.line-grid-table .row-actions button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0.125rem;
  display: inline-flex;
}
.line-grid-table .row-actions button:hover {
  color: var(--danger);
}
.line-grid-table .row-actions .material-symbols-outlined {
  font-size: 18px;
}
.line-grid-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.line-grid-balance {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}
.line-grid-balance.is-balanced {
  color: var(--focus);
  background: color-mix(in srgb, var(--focus) 12%, transparent);
}
.line-grid-balance.is-unbalanced {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

/* --- Hero specifics --- */
.hero-title {
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.05;
}

/* ============================================================
   MicroFilter — search-and-select input with closable badges
   ============================================================ */

.mf-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 34px;
  padding: 3px 8px;
  border: 1px solid var(--bs-border-color);
  border-radius: 6px;
  background: var(--surface);
  cursor: text;
  transition: border-color 0.15s;
}

.mf-wrap:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--brand) 25%, transparent);
}

.mf-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.mf-icon .material-symbols-outlined {
  font-size: 18px;
  display: block;
}

.mf-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 8px 1px 6px;
  border-radius: 4px;
  background: var(--brand-subtle);
  color: var(--brand-dark);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  line-height: 1.6;
}

.mf-badge-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border: none;
  background: transparent;
  color: var(--brand);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  border-radius: 2px;
}

.mf-badge-close:hover {
  background: var(--brand);
  color: #fff;
}

.mf-input {
  flex: 1;
  min-width: 80px;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.8125rem;
  color: var(--text-primary);
  padding: 2px 0;
}

.mf-input::placeholder {
  color: var(--text-muted);
}

.mf-clear {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  border-radius: 2px;
}

.mf-clear:hover {
  color: var(--text-primary);
}

.mf-clear .material-symbols-outlined {
  font-size: 16px;
}

.mf-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 20;
}

.mf-option {
  padding: 6px 10px;
  font-size: 0.8125rem;
  color: var(--text-primary);
  cursor: pointer;
}

.mf-option:hover {
  background: var(--brand-subtle);
  color: var(--brand-dark);
}

.mf-status {
  padding: 8px 10px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: center;
}

/* ============================================================
   is-loading — universal button spinner
   Works on circle, square, pill, or any shaped button.
   Dims the button and replaces content with a CSS spinner.
   ============================================================ */

.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  opacity: 0.65;
}

.is-loading > * {
  visibility: hidden;
}

.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 50%;
  width: 1em;
  height: 1em;
  margin: -0.5em -0.5em 0 0;
  border: 2px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
  animation: spin-loading 0.6s linear infinite;
  opacity: 1;
  color: var(--text-muted);
}

/* White spinner on brand-colored buttons */
.is-loading[class*="btn-primary"]::after,
.is-loading.chat-send-btn::after,
.is-loading.chat-create-btn::after {
  color: #fff;
}

@keyframes spin-loading {
  to { transform: rotate(-360deg); }
}

/* ------------------------------------------------------------
   In-flight HTMX buttons borrow the same spinner.

   HTMX puts .htmx-request on the element that fired the request and takes it
   off once the response has swapped in, so a button that opens a form panel
   shows feedback for exactly as long as the fetch takes, with no per-trigger
   wiring and nothing to clear by hand. pointer-events are dropped for the
   duration, which also kills the double-click that opens two panels.
   ------------------------------------------------------------ */
button.htmx-request,
.btn.htmx-request {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  opacity: 0.65;
}

button.htmx-request > *,
.btn.htmx-request > * {
  visibility: hidden;
}

button.htmx-request::after,
.btn.htmx-request::after {
  content: '';
  position: absolute;
  top: 50%;
  right: 50%;
  width: 1em;
  height: 1em;
  margin: -0.5em -0.5em 0 0;
  border: 2px solid currentColor;
  border-left-color: transparent;
  border-radius: 50%;
  animation: spin-loading 0.6s linear infinite;
  opacity: 1;
  color: var(--text-muted);
}

button.htmx-request[class*="btn-primary"]::after,
.btn.htmx-request[class*="btn-primary"]::after {
  color: #fff;
}

/* Triggers that are not buttons (a clickable card or table row) cannot blank
   their content for a spinner without looking broken, so they just go quiet
   and busy instead. Opt in with .hx-busy; plain .htmx-request is left alone so
   containers that load their own content are unaffected. */
.hx-busy.htmx-request {
  opacity: 0.6;
  cursor: progress;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

/* --- Section backgrounds --- */
.bg-white-section {
  background: var(--surface);
}

/* --- Footer --- */
footer h6 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
footer a {
  color: var(--text-secondary);
}
footer a:hover {
  color: var(--text-primary);
}

/* ============================================================
   Form System, "Showroom"

   The visual layer for core/forms (panel.html, modal.html,
   partials/fields.html). Appended last so it refines the base
   rules above; every colour comes from a platform token, so
   carton / light / dark follow automatically.

   Two ideas carry the whole skin:

     1. The panel floats. It sits off every viewport edge with a
        real radius and shadow instead of welding to the side.
     2. Controls are sunken, then lift. An input is filled with
        --bg-sunken and rises to --surface with a brand ring on
        focus, which is what lets a section card (also --surface)
        sit on the body without the two planes blurring together.

   Input rules stay scoped to .form-drawer-body / .form-modal-body
   on purpose: microselect and microdate are used app-wide (filter
   bars, toolbars, tables) and must keep their own look out there.
   ============================================================ */

/* --- Backdrop --- */
.form-backdrop {
  background: var(--veil);
  -webkit-backdrop-filter: blur(6px) saturate(1.4);
  backdrop-filter: blur(6px) saturate(1.4);
  animation: form-veil-in 0.28s ease both;
}
@keyframes form-veil-in { from { opacity: 0; } to { opacity: 1; } }

/* --- Drawer: floats off every edge --- */
.form-drawer {
  top: 14px;
  left: 14px;
  bottom: 14px;
  width: min(760px, 72vw);
  min-width: 0;
  max-width: none;
  background: var(--bg);
  border: 1px solid color-mix(in srgb, var(--brand) 14%, var(--bs-border-color));
  border-right: 1px solid color-mix(in srgb, var(--brand) 14%, var(--bs-border-color));
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    0 48px 90px -24px rgba(20, 18, 16, 0.42),
    0 8px 24px -12px rgba(20, 18, 16, 0.22);
  animation: drawer-slide-in 0.42s cubic-bezier(0.32, 0.72, 0, 1) backwards;
}
[data-theme="dark"] .form-drawer {
  box-shadow:
    0 48px 90px -24px rgba(0, 0, 0, 0.7),
    0 8px 24px -12px rgba(0, 0, 0, 0.5);
}
@keyframes drawer-slide-in {
  from { transform: translateX(calc(-1*(100% + 24px))); }
  to   { transform: none; }
}

/* A nested form sits slightly inside its parent, so the layer underneath
   stays visible at the edges and the stack reads as depth, not a redraw. */
.form-panel-layer-nested .form-drawer {
  top: 30px;
  bottom: 30px;
  left: 30px;
}

@media (max-width: 820px) {
  .form-drawer,
  .form-panel-layer-nested .form-drawer {
    top: 0; left: 0; bottom: 0; right: 0;
    width: auto;
    border: none;
    border-radius: 0;
  }
}

/* --- Header: brand wash with a light source in the top left --- */
.form-modal-header,
.form-drawer-header {
  position: relative;
  flex: none;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 20px 18px;
  border-bottom: none;
  background:
    radial-gradient(130% 150% at 6% -30%, color-mix(in srgb, var(--brand) 26%, transparent), transparent 62%),
    linear-gradient(-135deg,
      color-mix(in srgb, var(--brand) 13%, var(--surface)),
      color-mix(in srgb, var(--brand-light) 5%, var(--surface)));
}

.form-head-icon {
  width: 46px; height: 46px; flex: none;
  border-radius: 15px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(-150deg, var(--brand-light), var(--brand) 55%, var(--brand-dark));
  box-shadow:
    0 12px 24px -8px color-mix(in srgb, var(--brand) 70%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    inset 0 -1px 0 rgba(0, 0, 0, 0.14);
}
.form-head-icon .material-symbols-outlined { font-size: 24px; }

.form-head-titles {
  display: flex; flex-direction: column; gap: 3px;
  min-width: 0; flex: 1; padding-top: 2px;
}
.form-modal-title,
.form-drawer-title,
.form-crumb-current {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.022em;
  line-height: 1.2;
  color: var(--text-primary);
}
.form-head-sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.45;
}

/* Live completion readout next to the title */
.form-head-meta {
  display: inline-flex; align-items: center; gap: 6px;
  align-self: flex-start; margin-top: 4px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
  color: var(--brand-dark);
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  padding: 3px 9px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
[data-theme="dark"] .form-head-meta { color: var(--brand-light); }

/* Breadcrumbs on a nested form */
.form-crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; }
.form-crumb { font: inherit; white-space: nowrap; }
.form-crumb-current { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.form-crumb-parent {
  flex-shrink: 0;
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--bs-border-color));
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--text-secondary);
  font-size: 12px; font-weight: 600;
  border-radius: 999px;
  padding: 2px 10px;
  cursor: pointer;
}
.form-crumb-parent:hover { color: var(--text-primary); border-color: var(--brand); }
.form-crumb-sep { font-size: 17px; color: var(--text-muted); flex-shrink: 0; }

.form-modal-close,
.form-drawer-close {
  flex: none;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: none; border-radius: 10px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.form-modal-close:hover,
.form-drawer-close:hover {
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--text-primary);
}
.form-modal-close .material-symbols-outlined,
.form-drawer-close .material-symbols-outlined { font-size: 20px; }

/* --- Completion rail: doubles as the header rule --- */
.form-progress {
  flex: none;
  height: 3px;
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--brand) 16%, var(--bs-border-color));
}
.form-progress-bar {
  height: 3px; width: 0;
  border-radius: 3px 0 0 3px;
  background: linear-gradient(-90deg, var(--brand-light), var(--brand));
  box-shadow: 0 0 14px color-mix(in srgb, var(--brand) 65%, transparent);
  transition: width 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}

/* --- Error summary: pinned, so it never scrolls out of sight --- */
.form-error-summary {
  flex: none;
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 18px;
  background: color-mix(in srgb, var(--danger-subtle) 75%, var(--bg));
  border-bottom: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
  color: var(--danger-dark);
  font-size: 12.5px; line-height: 1.45;
  animation: form-drop-in 0.28s cubic-bezier(0.32, 0.72, 0, 1) both;
}
[data-theme="dark"] .form-error-summary { color: #F5A79E; }
.form-error-summary .material-symbols-outlined { font-size: 19px; flex: none; margin-top: -1px; }
.form-error-summary b { display: block; font-weight: 700; margin-bottom: 1px; }
@keyframes form-drop-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}

/* --- Bodies --- */
.form-modal-body,
.form-drawer-body {
  padding: 18px;
  gap: 14px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  scrollbar-width: none;
}

/* The body is the ONE scroll container in a form. Its children keep their full
   natural height: in a column flex box a child would otherwise shrink to fit,
   squashing a tall section and cutting off its last row of fields. */
.form-modal-body > *,
.form-drawer-body > * { flex-shrink: 0; }
.form-modal-body::-webkit-scrollbar,
.form-drawer-body::-webkit-scrollbar { display: none; }

/* Two-column bodies: only loose top-level fields sit side by side, every
   section card spans the full width and runs its own internal grid. */
.form-body-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px 18px;
  align-content: start;
}
.form-body-grid > .form-section,
.form-body-grid > .line-grid,
.form-body-grid > .form-group:has(textarea),
.form-body-grid > .form-group:has(.file-upload-zone),
.form-body-grid > .form-group:has(.avatar-upload),
.form-body-grid > .form-group:has(.tag-input),
.form-body-grid > .form-group:has(.toggle-list),
.form-body-grid > .form-group:has(.color-swatches),
.form-body-grid > .form-group:has(.form-chips),
.form-body-grid > .form-group:has(.lookup-multi-chips),
.form-body-grid > .form-group:has(.line-grid-table),
.form-body-grid > .form-group:has(.form-richtext),
.form-body-grid > .form-group:has(.radio-cards:not(.radio-segmented)),
.form-body-grid > .form-span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-body-grid { grid-template-columns: 1fr; } }

/* --- Section: an elevated card with its own header --- */
.form-modal-body .form-section,
.form-drawer-body .form-section,
.form-body-grid .form-section {
  margin: 0; padding: 0; min-width: 0;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 16px;
  /* Never clip and never scroll: a section grows to hold every field it has,
     and the form body is the only thing that scrolls. Nothing inside a section
     paints to its edge, so the rounded corners need no clipping, and leaving
     overflow visible also lets a lookup dropdown escape the card. */
  overflow: visible;
  box-shadow:
    0 1px 2px rgba(20, 18, 16, 0.04),
    0 14px 30px -22px rgba(20, 18, 16, 0.55);
  transition: border-color 0.2s, box-shadow 0.2s;
  animation: form-section-rise 0.55s cubic-bezier(0.32, 0.72, 0, 1) backwards;
  animation-delay: calc(var(--sec-i, 0) * 70ms + 120ms);
}
@keyframes form-section-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.form-section.has-error {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--bs-border-color));
  box-shadow:
    0 1px 2px rgba(20, 18, 16, 0.04),
    0 14px 30px -22px color-mix(in srgb, var(--danger) 60%, transparent);
}

.form-section-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
}
/* Hand-rolled forms outside the DSL have no collapse state to toggle. */
.form-section-head.is-static { cursor: default; }
.form-section-head:hover .form-section-label { color: var(--brand-dark); }
.form-section-head.is-static:hover .form-section-label { color: var(--text-primary); }
[data-theme="dark"] .form-section-head:hover .form-section-label { color: var(--brand-light); }

.form-section-chip {
  width: 34px; height: 34px; flex: none;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800;
  color: var(--brand-dark);
  background: linear-gradient(-150deg,
    color-mix(in srgb, var(--brand) 24%, var(--surface)),
    color-mix(in srgb, var(--brand) 9%, var(--surface)));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 20%, transparent);
}
[data-theme="dark"] .form-section-chip { color: var(--brand-light); }
.form-section-chip .material-symbols-outlined { font-size: 19px; }

.form-section-titles { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.form-section-label {
  margin: 0; padding: 0;
  font-size: 13.5px; font-weight: 700; letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text-primary);
  transition: color 0.15s;
}
.form-section-sub { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }

.form-section-count {
  flex: none;
  font-size: 11px; font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  background: var(--bg-sunken);
  padding: 3px 9px;
  border-radius: 999px;
}
.form-section-count.done { background: var(--focus-subtle); color: var(--focus-dark); }
[data-theme="dark"] .form-section-count.done { color: var(--focus); }

.form-section-chevron {
  flex: none;
  color: var(--text-muted);
  transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
.form-section-chevron .material-symbols-outlined { font-size: 20px; display: block; }
.form-section.is-collapsed .form-section-chevron { transform: rotate(90deg); }

.form-section-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px 16px;
  padding: 2px 16px 16px;
  overflow: visible;
  min-height: 0;
}
.form-section-body > .form-group:has(textarea),
.form-section-body > .form-group:has(.file-upload-zone),
.form-section-body > .form-group:has(.avatar-upload),
.form-section-body > .form-group:has(.tag-input),
.form-section-body > .form-group:has(.toggle-list),
.form-section-body > .form-group:has(.color-swatches),
.form-section-body > .form-group:has(.form-chips),
.form-section-body > .form-group:has(.lookup-multi-chips),
.form-section-body > .form-group:has(.line-grid-table),
.form-section-body > .form-group:has(.form-slider),
.form-section-body > .form-group:has(.form-richtext),
.form-section-body > .form-group:has(.radio-cards:not(.radio-segmented)),
.form-section-body > .form-section,
.form-section-body > .line-grid,
.form-section-body > .form-span-2 { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-section-body { grid-template-columns: 1fr; } }

/* --- Field group --- */
.form-modal-body .form-group,
.form-drawer-body .form-group,
.form-nested-card .form-group {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 0; min-width: 0;
}
.form-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.form-modal-body .form-label,
.form-drawer-body .form-label,
.form-nested-card .form-label {
  font-size: 12px; font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.004em; line-height: 1.3;
  margin-bottom: 0;
}
.form-modal-body .form-text,
.form-drawer-body .form-text {
  font-size: 11.5px; color: var(--text-muted); line-height: 1.45;
  margin: 0;
}

/* --- Server-driven advice notes (core.forms Form.advice) ---
   Injected into .form-group by formShell, so they sit under whatever control
   the group holds. Help reads like help text; the warning is advisory only and
   deliberately stops short of .field-error's red so it never reads as a block. */
.form-advice-help {
  font-size: 11.5px; color: var(--text-muted); line-height: 1.45;
  margin-top: 4px;
}
.form-advice-warn {
  display: flex; align-items: flex-start; gap: 5px;
  font-size: 11.5px; line-height: 1.45; color: var(--warning);
  background: var(--warning-subtle);
  border-radius: 6px;
  padding: 5px 8px;
  margin-top: 5px;
}
.form-advice-warn .material-symbols-outlined {
  font-size: 14px; flex: none; margin-top: 1px;
}
.form-charcount {
  font-family: var(--gr-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 10.5px; color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* --- Controls: sunken, then lift on focus --- */
.form-modal-body .form-control, .form-drawer-body .form-control, .form-nested-card .form-control,
.form-modal-body .form-select, .form-drawer-body .form-select,
.form-modal-body .msel-trigger, .form-drawer-body .msel-trigger, .form-nested-card .msel-trigger,
.form-modal-body .mdate-trigger, .form-drawer-body .mdate-trigger, .form-nested-card .mdate-trigger {
  width: 100%;
  min-height: 42px;
  padding: 10px 13px;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--bg-sunken);
  border: 1.5px solid transparent;
  border-radius: 11px;
  box-shadow: inset 0 1px 2px rgba(20, 18, 16, 0.05);
  transition: background 0.16s, border-color 0.16s, box-shadow 0.16s;
}
.form-modal-body .form-control:hover:not(:focus):not(:disabled):not([readonly]),
.form-drawer-body .form-control:hover:not(:focus):not(:disabled):not([readonly]),
.form-modal-body .form-select:hover:not(:focus), .form-drawer-body .form-select:hover:not(:focus),
.form-modal-body .msel-trigger:hover, .form-drawer-body .msel-trigger:hover,
.form-modal-body .mdate-trigger:hover, .form-drawer-body .mdate-trigger:hover {
  border-color: color-mix(in srgb, var(--brand) 28%, transparent);
  box-shadow: inset 0 1px 2px rgba(20, 18, 16, 0.05);
}
.form-modal-body .form-control:focus, .form-drawer-body .form-control:focus, .form-nested-card .form-control:focus,
.form-modal-body .form-select:focus, .form-drawer-body .form-select:focus,
.form-modal-body .msel-trigger:focus-within, .form-drawer-body .msel-trigger:focus-within,
.form-modal-body .msel-trigger.is-open, .form-drawer-body .msel-trigger.is-open, .form-nested-card .msel-trigger.is-open,
.form-modal-body .mdate-trigger:focus-within, .form-drawer-body .mdate-trigger:focus-within {
  outline: none;
  background: var(--surface);
  border-color: var(--brand);
  box-shadow:
    0 0 0 3.5px color-mix(in srgb, var(--brand) 15%, transparent),
    0 3px 10px -4px color-mix(in srgb, var(--brand) 45%, transparent);
}
.form-modal-body textarea.form-control,
.form-drawer-body textarea.form-control {
  min-height: 88px; line-height: 1.55; padding-block: 11px; resize: vertical;
}
.form-modal-body .form-control:disabled, .form-drawer-body .form-control:disabled,
.form-modal-body .form-control[readonly], .form-drawer-body .form-control[readonly] {
  background: color-mix(in srgb, var(--bg-sunken) 60%, transparent);
  color: var(--text-muted);
  box-shadow: none;
}

/* Leading icon inside a control, plus the trailing state glyph */
.form-input-wrap { position: relative; display: flex; align-items: center; }
.form-input-wrap.has-icon .form-control { padding-right: 39px; }
.form-input-icon {
  position: absolute; right: 12px; pointer-events: none;
  font-size: 19px; color: var(--text-muted);
  transition: color 0.16s;
}
.form-control:focus ~ .form-input-icon { color: var(--brand); }
.form-input-trail {
  position: absolute; left: 12px; pointer-events: none;
  font-size: 19px;
  opacity: 0; transform: scale(0.6);
  transition: opacity 0.2s, transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}

/* Valid / invalid */
.form-group.is-valid .form-control { border-color: color-mix(in srgb, var(--focus) 50%, transparent); }
.form-group.is-valid .form-control:not(:focus) { padding-left: 38px; }
.form-group.is-valid .form-input-trail { opacity: 1; transform: none; color: var(--focus-dark); }
[data-theme="dark"] .form-group.is-valid .form-input-trail { color: var(--focus); }
.form-group.is-invalid .form-control,
.form-group.is-invalid .msel-trigger,
.form-group.is-invalid .mdate-trigger {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger-subtle) 55%, var(--bg-sunken));
}
.form-group.is-invalid .form-control:focus {
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--danger) 16%, transparent);
}
.form-group.is-invalid .form-input-trail { opacity: 1; transform: none; color: var(--danger); }
.form-group.is-invalid .form-input-icon { color: var(--danger); }
.field-error {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500; line-height: 1.4;
  color: var(--danger-dark);
  animation: form-drop-in 0.22s ease both;
}
[data-theme="dark"] .field-error { color: #F5A79E; }
.field-error .material-symbols-outlined { font-size: 15px; flex: none; }

/* --- Radio cards --- */
.form-modal-body .radio-cards,
.form-drawer-body .radio-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 9px;
}
.form-modal-body .radio-card,
.form-drawer-body .radio-card {
  position: relative;
  display: flex; flex-direction: column; gap: 2px;
  min-height: 0;
  padding: 11px 12px;
  cursor: pointer;
  background: var(--bg-sunken);
  border: 1.5px solid transparent;
  border-radius: 12px;
  transition: border-color 0.16s, background 0.16s, box-shadow 0.16s;
}
.form-modal-body .radio-card:hover,
.form-drawer-body .radio-card:hover { border-color: color-mix(in srgb, var(--brand) 32%, transparent); }
.radio-card-icon { width: 19px; height: 19px; color: var(--text-muted); margin-bottom: 1px; transition: color 0.16s; }
.radio-card-label { font-size: 12.5px; font-weight: 650; color: var(--text-primary); }
.radio-card-desc { font-size: 11px; color: var(--text-muted); line-height: 1.35; }
.form-modal-body .radio-card.active,
.form-drawer-body .radio-card.active {
  border-color: var(--brand);
  background: linear-gradient(-150deg,
    color-mix(in srgb, var(--brand) 15%, var(--surface)),
    color-mix(in srgb, var(--brand) 6%, var(--surface)));
  box-shadow: 0 6px 16px -10px color-mix(in srgb, var(--brand) 90%, transparent);
}
.radio-card.active .radio-card-icon { color: var(--brand); }
.radio-card-disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* Segmented variant */
.form-modal-body .radio-cards.radio-segmented,
.form-drawer-body .radio-cards.radio-segmented {
  display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 3px;
  background: var(--bg-sunken);
  border-radius: 12px;
  box-shadow: inset 0 1px 2px rgba(20, 18, 16, 0.05);
  min-height: 42px;
}
.radio-segmented .radio-card {
  flex: 1; min-width: 88px;
  padding: 7px 15px;
  border: none; background: transparent; box-shadow: none;
  border-radius: 9px;
  align-items: center; justify-content: center; gap: 0;
}
.radio-segmented .radio-card .radio-card-icon,
.radio-segmented .radio-card .radio-card-desc { display: none; }
.form-modal-body .radio-segmented .radio-card.active,
.form-drawer-body .radio-segmented .radio-card.active {
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(20, 18, 16, 0.10), 0 4px 10px -6px rgba(20, 18, 16, 0.4);
}
.radio-segmented .radio-card.active .radio-card-label { color: var(--brand-dark); }
[data-theme="dark"] .radio-segmented .radio-card.active .radio-card-label { color: var(--brand-light); }

/* --- Checkbox / switch field --- */
/* Bootstrap floats the switch and pulls it back with a negative margin, which
   a flex row would render as a stray overhang. Reset both, then lay it out. */
.form-modal-body .form-check.form-switch,
.form-drawer-body .form-check.form-switch {
  display: flex; align-items: center; gap: 10px;
  min-height: 42px; padding: 9px 13px;
  background: var(--bg-sunken);
  border: 1.5px solid transparent;
  border-radius: 11px;
  margin: 0;
}
.form-modal-body .form-check.form-switch .form-check-input,
.form-drawer-body .form-check.form-switch .form-check-input {
  float: none;
  margin: 0;
  flex: none;
}
.form-modal-body .form-check.form-switch:hover,
.form-drawer-body .form-check.form-switch:hover { border-color: color-mix(in srgb, var(--brand) 28%, transparent); }
.form-modal-body .form-check-label,
.form-drawer-body .form-check-label { font-size: 13px; font-weight: 600; cursor: pointer; }

/* --- Lookup --- */
.lookup-wrapper { position: relative; }
.form-modal-body .lookup-dropdown,
.form-drawer-body .lookup-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; left: 0; z-index: 20;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 13px;
  box-shadow: 0 20px 44px -16px rgba(20, 18, 16, 0.45);
  padding: 5px;
  max-height: 250px; overflow-y: auto;
  animation: form-drop-in 0.18s ease both;
}
.form-modal-body .lookup-option,
.form-drawer-body .lookup-option {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
}
.form-modal-body .lookup-option:hover, .form-drawer-body .lookup-option:hover,
.form-modal-body .lookup-option.active, .form-drawer-body .lookup-option.active {
  background: var(--brand-subtle);
}
.lookup-avatar, .lookup-initials {
  width: 26px; height: 26px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  object-fit: cover;
  color: #fff; font-size: 10px; font-weight: 700;
}
.lookup-option-icon { font-size: 19px; color: var(--text-muted); }
.lookup-status { padding: 10px; font-size: 12.5px; color: var(--text-muted); }
.lookup-create-trigger {
  display: flex; align-items: center; gap: 7px;
  margin-top: 4px; padding: 9px;
  border-top: 1px solid var(--bs-border-color);
  color: var(--brand-dark);
  font-size: 12.5px; font-weight: 650;
  cursor: pointer;
}
[data-theme="dark"] .lookup-create-trigger { color: var(--brand-light); }
.lookup-create-trigger .material-symbols-outlined { font-size: 17px; }
.lookup-clear {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  z-index: 2;
  border: none; background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 7px;
  font-size: 17px; line-height: 1;
}
.lookup-clear:hover { background: var(--surface-hover); color: var(--text-primary); }
.lookup-multi-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 7px; }
.lookup-chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 11px 0 5px;
  background: color-mix(in srgb, var(--brand) 16%, var(--surface));
  color: var(--brand-darker);
  border-radius: 999px;
  font-size: 12px; font-weight: 650;
}
[data-theme="dark"] .lookup-chip { color: var(--brand-light); }
.lookup-chip-remove {
  border: none; background: none; color: inherit; cursor: pointer;
  padding: 0; width: 16px; height: 16px;
  display: grid; place-items: center;
  border-radius: 50%; opacity: 0.65; font-size: 15px; line-height: 1;
}
.lookup-chip-remove:hover { opacity: 1; background: rgba(20, 18, 16, 0.12); }

/* --- Chips --- */
.form-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.form-modal-body .form-chip,
.form-drawer-body .form-chip {
  border: 1.5px solid var(--bs-border-color);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12.5px; font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.form-modal-body .form-chip:hover,
.form-drawer-body .form-chip:hover { border-color: var(--brand-light); color: var(--text-primary); }
.form-modal-body .form-chip.is-on,
.form-drawer-body .form-chip.is-on {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(-150deg, var(--brand-light), var(--brand));
  box-shadow: 0 6px 14px -8px color-mix(in srgb, var(--brand) 90%, transparent);
}

/* --- Tag input --- */
.tag-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  min-height: 42px; padding: 6px 9px;
  background: var(--bg-sunken);
  border: 1.5px solid transparent;
  border-radius: 11px;
  box-shadow: inset 0 1px 2px rgba(20, 18, 16, 0.05);
  transition: background 0.16s, border-color 0.16s, box-shadow 0.16s;
}
.tag-input:focus-within {
  background: var(--surface);
  border-color: var(--brand);
  box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--brand) 15%, transparent);
}
.tag-chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 11px 0 5px;
  background: color-mix(in srgb, var(--brand) 16%, var(--surface));
  color: var(--brand-darker);
  border-radius: 999px;
  font-size: 12px; font-weight: 650;
}
[data-theme="dark"] .tag-chip { color: var(--brand-light); }
.tag-chip-x {
  border: none; background: none; color: inherit; cursor: pointer;
  padding: 0; width: 16px; height: 16px;
  display: grid; place-items: center;
  border-radius: 50%; font-size: 15px; line-height: 1; opacity: 0.65;
}
.tag-chip-x:hover { opacity: 1; background: rgba(20, 18, 16, 0.12); }
.tag-input-field {
  flex: 1; min-width: 110px;
  border: none; outline: none; background: transparent;
  font: inherit; font-size: 13px; color: var(--text-primary);
}

/* --- Toggles --- */
.toggle-list { display: flex; flex-direction: column; gap: 2px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 2px; }
.toggle-row + .toggle-row { border-top: 1px solid var(--bs-border-color); }
.toggle-row-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.toggle-row-label { font-size: 13px; font-weight: 650; color: var(--text-primary); }
.toggle-row-desc { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.toggle-switch {
  flex: none; width: 44px; height: 25px;
  border-radius: 999px; border: none; cursor: pointer; padding: 0;
  background: var(--bs-border-color);
  position: relative;
  transition: background 0.2s;
}
.toggle-switch.is-on {
  background: linear-gradient(-150deg, var(--brand-light), var(--brand));
  box-shadow: 0 5px 12px -6px color-mix(in srgb, var(--brand) 95%, transparent);
}
.toggle-knob {
  position: absolute; top: 3px; right: 3px;
  width: 19px; height: 19px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 18, 16, 0.35);
  transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}
.toggle-switch.is-on .toggle-knob { transform: translateX(-19px); }

/* --- Colour swatches --- */
.color-swatches { display: flex; flex-wrap: wrap; gap: 9px; }
.color-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  cursor: pointer; padding: 0; border: none;
  display: grid; place-items: center;
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(20, 18, 16, 0.1);
  transition: transform 0.16s, box-shadow 0.16s;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch-check {
  font-size: 17px;
  opacity: 0; transform: scale(0.5);
  transition: opacity 0.18s, transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
}
.color-swatch.is-on { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--brand); }
.color-swatch.is-on .color-swatch-check { opacity: 1; transform: none; }

/* --- Slider --- */
.form-slider-bubble {
  font-size: 12px; font-weight: 700;
  color: var(--brand-dark);
  background: color-mix(in srgb, var(--brand) 15%, transparent);
  padding: 2px 10px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
[data-theme="dark"] .form-slider-bubble { color: var(--brand-light); }
.form-slider {
  width: 100%; height: 6px; border-radius: 99px;
  appearance: none; -webkit-appearance: none;
  background: var(--bg-sunken);
  outline: none; cursor: pointer;
  margin: 8px 0 2px;
  box-shadow: inset 0 1px 2px rgba(20, 18, 16, 0.08);
}
.form-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(-150deg, var(--brand-light), var(--brand));
  border: 3px solid var(--surface);
  box-shadow: 0 2px 8px -2px color-mix(in srgb, var(--brand) 90%, transparent);
  cursor: pointer;
}
.form-slider::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--brand);
  border: 3px solid var(--surface);
  box-shadow: 0 2px 8px -2px rgba(20, 18, 16, 0.4);
  cursor: pointer;
}

/* --- Rating (numbers / stars / smileys) --- */
.form-rating {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
  min-height: 38px;
}
.form-rating-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer; padding: 0;
}

/* Numbers: bordered pills, single active value */
.form-rating-numbers .form-rating-btn {
  width: 38px; height: 34px;
  border: 2px solid var(--bs-border-color); border-radius: 10px;
  background: var(--surface);
  font-size: 13px; font-weight: 700;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.form-rating-numbers .form-rating-btn.is-hover {
  border-color: var(--brand-light); color: var(--text-primary);
}
.form-rating-numbers .form-rating-btn.is-on {
  background: var(--brand); border-color: var(--brand); color: #fff;
}

/* Stars: cumulative fill up to the value, hover previews the fill */
.form-rating-stars { gap: 2px; }
.form-rating-stars .form-rating-btn .material-symbols-outlined {
  font-size: 26px;
  color: color-mix(in srgb, var(--text-muted) 55%, transparent);
  transition: color 0.12s, transform 0.12s;
}
.form-rating-stars .form-rating-btn.is-fill .material-symbols-outlined {
  color: var(--brand);
  font-variation-settings: 'FILL' 1;
}
.form-rating-stars .form-rating-btn:active .material-symbols-outlined {
  transform: scale(0.88);
}

/* Smileys: five faces, single active value */
.form-rating-smileys { gap: 4px; }
.form-rating-smileys .form-rating-btn .material-symbols-outlined {
  font-size: 26px;
  color: color-mix(in srgb, var(--text-muted) 65%, transparent);
  transition: color 0.12s, transform 0.12s;
}
.form-rating-smileys .form-rating-btn.is-hover .material-symbols-outlined {
  color: var(--text-primary);
}
.form-rating-smileys .form-rating-btn.is-on .material-symbols-outlined {
  color: var(--brand);
  font-variation-settings: 'FILL' 1;
  transform: scale(1.12);
}

/* --- Avatar upload --- */
.avatar-upload { display: flex; align-items: center; gap: 15px; }
.avatar-upload-btn {
  width: 74px; height: 74px; flex: none;
  border-radius: 50%; cursor: pointer; padding: 0; overflow: hidden;
  display: grid; place-items: center;
  background: var(--bg-sunken);
  border: 1.5px dashed color-mix(in srgb, var(--brand) 35%, var(--bs-border-color));
  transition: border-color 0.16s, box-shadow 0.16s;
}
.avatar-upload-btn:hover {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 12%, transparent);
}
.avatar-upload-btn.is-uploading { opacity: 0.6; }
.avatar-upload-img { width: 100%; height: 100%; object-fit: cover; }
.avatar-upload-ph { font-size: 25px; color: var(--text-muted); }
.avatar-upload-side { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.avatar-upload-remove {
  border: none; background: none; color: var(--text-muted);
  font-size: 12px; cursor: pointer; padding: 0;
}
.avatar-upload-remove:hover { color: var(--danger); }

/* --- File upload --- */
.form-modal-body .file-upload-zone,
.form-drawer-body .file-upload-zone {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  padding: 22px; cursor: pointer; text-align: center;
  background: var(--bg-sunken);
  border: 1.5px dashed color-mix(in srgb, var(--brand) 28%, var(--bs-border-color));
  border-radius: 13px;
  transition: all 0.16s;
}
.form-modal-body .file-upload-zone:hover, .form-drawer-body .file-upload-zone:hover,
.form-modal-body .file-upload-zone.drag-over, .form-drawer-body .file-upload-zone.drag-over {
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 6%, var(--bg-sunken));
}
.file-upload-icon { font-size: 24px; color: var(--brand); }
.file-upload-text { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.file-upload-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.form-modal-body .file-upload-item,
.form-drawer-body .file-upload-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 11px;
  font-size: 12.5px;
}
.file-upload-item-icon { color: var(--brand); font-size: 19px; }
.file-upload-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-upload-item-size { margin-right: auto; font-size: 11px; color: var(--text-muted); }
.file-upload-item-progress {
  width: 70px; height: 4px; border-radius: 99px;
  background: var(--bg-sunken); overflow: hidden;
}
.file-upload-item-bar {
  height: 100%;
  background: linear-gradient(-90deg, var(--brand-light), var(--brand));
  transition: width 0.2s ease;
}
.file-upload-item-remove {
  border: none; background: none; color: var(--text-muted);
  cursor: pointer; padding: 0;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 7px; font-size: 16px; line-height: 1;
}
.file-upload-item-remove:hover { background: var(--danger-subtle); color: var(--danger); }

/* --- Line grid --- */
.form-modal-body .line-grid-table-wrap,
.form-drawer-body .line-grid-table-wrap {
  border: 1px solid var(--bs-border-color);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}
.form-modal-body .line-grid-table th,
.form-drawer-body .line-grid-table th {
  padding: 9px 11px;
  background: var(--bg-sunken);
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
}
.form-modal-body .line-grid-table td,
.form-drawer-body .line-grid-table td { padding: 5px 7px; }
.form-modal-body .line-grid-table input,
.form-drawer-body .line-grid-table input,
.form-modal-body .line-grid-table select,
.form-drawer-body .line-grid-table select {
  width: 100%;
  border: 1.5px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 7px 8px;
  font: inherit; font-size: 12.5px;
  color: var(--text-primary);
}
.form-modal-body .line-grid-table input:focus, .form-drawer-body .line-grid-table input:focus,
.form-modal-body .line-grid-table select:focus, .form-drawer-body .line-grid-table select:focus {
  outline: none;
  background: var(--bg-sunken);
  border-color: var(--brand);
}
.line-grid-table tfoot td {
  padding: 9px 11px; font-weight: 700;
  background: var(--bg-sunken);
  font-variant-numeric: tabular-nums;
}
.line-grid-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 9px; gap: 10px; }
.line-grid-balance { font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.line-grid-balance.is-balanced { background: var(--focus-subtle); color: var(--focus-dark); }
.line-grid-balance.is-unbalanced { background: var(--danger-subtle); color: var(--danger-dark); }
[data-theme="dark"] .line-grid-balance.is-balanced { color: var(--focus); }
[data-theme="dark"] .line-grid-balance.is-unbalanced { color: #F5A79E; }

/* --- Footer: sticky glass --- */
.form-modal-footer,
.form-drawer-footer {
  flex: none;
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  margin-top: 0;
  justify-content: flex-start;
  border-top: 1px solid var(--bs-border-color);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.form-footer-actions { margin-right: auto; display: flex; align-items: center; gap: 10px; }
.form-kbd-hint { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-muted); }
.form-kbd-hint kbd {
  font-family: inherit; font-size: 10.5px; font-weight: 700;
  background: var(--bg-sunken);
  border: 1px solid var(--bs-border-color);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  color: var(--text-secondary);
}
@media (max-width: 640px) { .form-kbd-hint { display: none; } }

/* Buttons inside a form panel */
.form-modal-footer .btn,
.form-drawer-footer .btn {
  border-radius: 11px;
  padding: 10px 17px;
  font-size: 13.5px; font-weight: 650;
  border-width: 1.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: transform 0.14s, box-shadow 0.2s, background 0.16s, color 0.16s, border-color 0.16s;
}
.form-submit-inner { display: inline-flex; align-items: center; gap: 6px; }
.form-submit-inner .material-symbols-outlined { font-size: 18px; }
.btn.form-submit-btn {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(-150deg, var(--brand-light), var(--brand) 58%, var(--brand-dark));
  box-shadow:
    0 10px 22px -10px color-mix(in srgb, var(--brand) 95%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}
.btn.form-submit-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow:
    0 16px 28px -12px color-mix(in srgb, var(--brand) 95%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.34);
}
.btn.form-submit-btn:active:not(:disabled) { transform: translateY(0) scale(0.988); }
.btn.form-submit-btn:disabled { opacity: 0.75; }
.form-modal-footer .form-cancel-btn,
.form-drawer-footer .form-cancel-btn {
  background: transparent;
  border-color: var(--bs-border-color);
  color: var(--text-secondary);
}
.form-modal-footer .form-cancel-btn:hover,
.form-drawer-footer .form-cancel-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

/* Unsaved-changes guard, replacing the footer contents in place */
.form-drawer-footer.is-guarding,
.form-modal-footer.is-guarding {
  background: color-mix(in srgb, var(--danger-subtle) 55%, var(--surface));
  border-top-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.form-guard { display: flex; align-items: center; gap: 12px; width: 100%; animation: form-drop-in 0.2s ease both; }
.form-guard-text { font-size: 12.5px; font-weight: 600; color: var(--danger-dark); line-height: 1.35; }
[data-theme="dark"] .form-guard-text { color: #F5A79E; }
.form-guard-text span { display: block; font-weight: 400; color: var(--text-secondary); font-size: 11.5px; }
.form-guard .btn { margin-right: auto; }
.form-guard .btn + .btn { margin-right: 0; }

/* --- Modal: the centered sibling of the drawer --- */
.form-modal {
  width: min(760px, 72vw);
  min-width: 0;
  height: min(720px, 92vh);
  max-height: none;
  background: var(--bg);
  border: 1px solid color-mix(in srgb, var(--brand) 14%, var(--bs-border-color));
  border-radius: 20px;
  box-shadow:
    0 48px 90px -24px rgba(20, 18, 16, 0.42),
    0 8px 24px -12px rgba(20, 18, 16, 0.22);
  animation: form-modal-in 0.28s cubic-bezier(0.32, 0.72, 0, 1) backwards;
}
[data-theme="dark"] .form-modal {
  box-shadow:
    0 48px 90px -24px rgba(0, 0, 0, 0.7),
    0 8px 24px -12px rgba(0, 0, 0, 0.5);
}
.form-modal-lg { width: min(980px, 82vw); }
@keyframes form-modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}
@media (max-width: 820px) {
  .form-modal, .form-modal-lg {
    width: 100vw; height: 100%; max-height: none;
    border-radius: 0; border: none;
  }
}

/* Motion is decoration here: keep every state, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  .form-drawer, .form-modal, .form-backdrop, .form-section,
  .form-error-summary, .field-error, .lookup-dropdown, .form-guard {
    animation: none !important;
  }
  .form-progress-bar, .toggle-knob, .btn.form-submit-btn { transition: none !important; }
}

/* ============================================================
   Sheet - spreadsheet skin for plain server-rendered tables.

   The static counterpart of the MicroTable grid (public/js/microtable.css):
   same gridlines, same header fill, same row height, no JS. Add `sheet` to
   any <table> that lists or reports data but cannot be a MicroTable:
   hierarchical reports, ledgers with running balances, subtotal and totals
   rows, editable line-item grids. Keep the two skins in step.

   Child combinators keep nested tables out of it. Selectors carry a
   :last-child where an app rule (finance's .finance-table) already claims
   that slot, so the grid wins without the app stylesheet having to change.
   ============================================================ */
table.sheet {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

table.sheet > thead > tr > th,
table.sheet > tbody > tr > th,
table.sheet > tbody > tr > td,
table.sheet > tfoot > tr > th,
table.sheet > tfoot > tr > td {
  border-left: 1px solid var(--bs-border-color);
  border-bottom: 1px solid var(--bs-border-color);
}

/* The last column already ends at the table edge; a rule there doubles up. */
table.sheet > thead > tr > th:last-child,
table.sheet > tbody > tr > th:last-child,
table.sheet > tbody > tr > td:last-child,
table.sheet > tfoot > tr > th:last-child,
table.sheet > tfoot > tr > td:last-child {
  border-left: none;
}

/* Close the grid on the final row (app styles tend to strip this border). */
table.sheet > tbody > tr:last-child > td,
table.sheet > tbody > tr:last-child > th {
  border-bottom: 1px solid var(--bs-border-color);
}

/* Type and spacing here mirror .mtbl-table th exactly, so a static sheet and a
   MicroTable sitting on the same page read as the same component. */
table.sheet > thead > tr > th {
  padding: 0.5rem 0.75rem;
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: right;
  white-space: nowrap;
  border-bottom: 2px solid var(--bs-border-color);
}

/* A floor, not a cap: cells with taller content still grow. */
table.sheet > tbody > tr > td,
table.sheet > tbody > tr > th {
  height: 2.25rem;
  padding: 0.5rem 0.75rem;
  vertical-align: middle;
}

table.sheet > tbody > tr:hover {
  background: var(--surface-hover);
}

/* Totals sit under a heavier rule, the way a sheet closes a column. The rule
   belongs above the totals stack as a whole, not above each row inside it. */
table.sheet > tfoot > tr > td,
table.sheet > tfoot > tr > th {
  padding: 0.5rem 0.75rem;
  font-weight: 600;
}
table.sheet > tfoot > tr:first-child > td,
table.sheet > tfoot > tr:first-child > th {
  border-top: 2px solid var(--bs-border-color);
}

/* Group, subtotal, and total rows inside reports: fill, no hover lift. */
table.sheet > tbody > tr.sheet-group > td,
table.sheet > tbody > tr.sheet-total > td {
  background: var(--bg-sunken);
  font-weight: 600;
}
table.sheet > tbody > tr.sheet-group:hover,
table.sheet > tbody > tr.sheet-total:hover {
  background: var(--bg-sunken);
}

/* ---------------------------------------------------------------------------
   Break glass — admin mode (core/elevation.py)

   The ring is deliberately loud. An admin needs to know, at a glance and
   without looking for it, that they are currently able to change anything in
   the workspace. Colour alone would fail colourblind users and anyone
   heads-down in a tab, so the state also carries a shield glyph and a text
   countdown in the avatar menu.
--------------------------------------------------------------------------- */
.pf-elevated .pf-avatar {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--danger);
  animation: pf-elev-pulse 2.2s ease-in-out infinite;
}

@keyframes pf-elev-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--danger); }
  50%      { box-shadow: 0 0 0 2px var(--surface), 0 0 0 5px color-mix(in srgb, var(--danger) 55%, transparent); }
}

/* Respect a stated preference for less motion: keep the ring, drop the pulse. */
@media (prefers-reduced-motion: reduce) {
  .pf-elevated .pf-avatar { animation: none; }
}

.pf-elev-item { display: flex; align-items: center; gap: 8px; }
.pf-elev-item-on { color: var(--danger); font-weight: 600; }
.pf-elev-exit { margin-right: auto; font-size: 0.75rem; opacity: 0.7; }

/* Teleported to body (see navbar.html): the navbar is a containing block, so a
   fixed child of it covers the header strip instead of the viewport. Matches
   .pf-modal-backdrop's veil, blur and z-index family so it sits in the same
   stacking order as every other modal. */
.pf-elev-backdrop {
  position: fixed;
  inset: 0;
  background: var(--veil);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1050;
}

.pf-elev-modal {
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  width: 100%; max-width: 420px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
}

.pf-elev-modal-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.pf-elev-modal-head .material-symbols-outlined { color: var(--danger); font-size: 28px; }
.pf-elev-modal-title { font-weight: 650; font-size: 1rem; }
.pf-elev-modal-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.pf-elev-label { display: block; font-size: 0.78rem; font-weight: 600; margin: 12px 0 4px; }
.pf-elev-hint { font-size: 0.72rem; color: var(--text-muted); margin-top: 4px; }
.pf-elev-error { color: var(--danger); font-size: 0.8rem; margin-top: 10px; }
.pf-elev-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* The exact permission behind a denial. A 403 that does not say what is
   missing reads as the product being broken rather than as something the
   person can go and ask an admin for. */
.access-wall-missing {
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.access-wall-missing code {
  background: var(--bg-sunken);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.78rem;
}

/* ============================================================
   Detail View System, "Showroom" counterpart

   The viewing sibling of the form skin (core/details renders
   through it; hand-rolled detail drawers use the same classes).
   Same two ideas as the form:

     1. The panel floats, wider than the form. Creating is a
        corridor (760px); viewing is a room: min(1080px, 86vw).
     2. Twin panes. Prose lives on elevated section cards in a
        scrolling main column; the facts live on a full-height
        rail card that stays fixed while the story scrolls (each
        pane scrolls internally; the body itself never does).
        Rail rows are sunken-then-lift, the form's input grammar:
        a row that lifts on hover says "click me to edit".
   ============================================================ */

/* --- Backdrop: identical to the form veil --- */
.dv-backdrop {
  position: fixed; inset: 0; z-index: 1040;
  background: var(--veil);
  -webkit-backdrop-filter: blur(6px) saturate(1.4);
  backdrop-filter: blur(6px) saturate(1.4);
  animation: dv-veil-in 0.28s ease both;
  cursor: pointer;
}
@keyframes dv-veil-in { from { opacity: 0; } to { opacity: 1; } }

/* --- The card: floats off every edge, wider than the form --- */
.dv-card {
  position: fixed; top: 14px; left: 14px; bottom: 14px; z-index: 1050;
  width: min(1080px, 86vw);
  display: flex; flex-direction: column;
  background: var(--bg);
  border: 1px solid color-mix(in srgb, var(--brand) 14%, var(--bs-border-color));
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    0 48px 90px -24px rgba(20, 18, 16, 0.42),
    0 8px 24px -12px rgba(20, 18, 16, 0.22);
  animation: dv-slide-in 0.42s cubic-bezier(0.32, 0.72, 0, 1) backwards;
}
[data-theme="dark"] .dv-card {
  box-shadow:
    0 48px 90px -24px rgba(0, 0, 0, 0.7),
    0 8px 24px -12px rgba(0, 0, 0, 0.5);
}
@keyframes dv-slide-in {
  from { transform: translateX(calc(-1*(100% + 24px))); }
  to   { transform: none; }
}
@media (max-width: 820px) {
  .dv-card { top: 0; left: 0; bottom: 0; right: 0; width: auto; border: none; border-radius: 0; }
}

/* --- Header: same brand wash, light source top-left --- */
.dv-header {
  position: relative; flex: none;
  display: flex; align-items: flex-start; gap: 14px;
  padding: 20px 20px 16px;
  background:
    radial-gradient(130% 150% at 6% -30%, color-mix(in srgb, var(--brand) 26%, transparent), transparent 62%),
    linear-gradient(-135deg,
      color-mix(in srgb, var(--brand) 13%, var(--surface)),
      color-mix(in srgb, var(--brand-light) 5%, var(--surface)));
}
.dv-head-icon {
  width: 46px; height: 46px; flex: none;
  border-radius: 15px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(-150deg, var(--brand-light), var(--brand) 55%, var(--brand-dark));
  box-shadow:
    0 12px 24px -8px color-mix(in srgb, var(--brand) 70%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    inset 0 -1px 0 rgba(0, 0, 0, 0.14);
}
.dv-head-icon .material-symbols-outlined { font-size: 24px; }

.dv-head-titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; padding-top: 1px; }
.dv-head-topline { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.dv-key {
  flex: none;
  font-family: var(--gr-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 11px; font-weight: 700; letter-spacing: 0.03em;
  color: var(--brand-dark);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 24%, var(--bs-border-color));
  padding: 2px 8px; border-radius: 7px;
}
[data-theme="dark"] .dv-key { color: var(--brand-light); }

/* Status: the one loud fact, an interactive pill in the wash */
.dv-status {
  flex: none; display: inline-flex; align-items: center; gap: 5px;
  border: none; cursor: pointer;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
  color: var(--brand-dark);
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  padding: 3px 10px 3px 6px; border-radius: 999px;
  transition: background 0.15s;
}
.dv-status:hover { background: color-mix(in srgb, var(--brand) 26%, transparent); }
.dv-status .material-symbols-outlined { font-size: 16px; }
[data-theme="dark"] .dv-status { color: var(--brand-light); }
.dv-status-static { cursor: default; padding-left: 10px; }
.dv-status-static:hover { background: color-mix(in srgb, var(--brand) 16%, transparent); }

/* The title is the record's name: bigger than the form's, editable when wired */
.dv-title {
  font-size: 19px; font-weight: 800; letter-spacing: -0.022em; line-height: 1.25;
  color: var(--text-primary);
  border: none; background: transparent; padding: 0; margin: 0; width: 100%;
  border-radius: 6px;
  transition: box-shadow 0.15s;
}
input.dv-title:hover { background: transparent; }
input.dv-title:focus { outline: none; background: transparent; box-shadow: none; }
.dv-head-sub { font-size: 12.5px; color: var(--text-secondary); line-height: 1.45; }

.dv-head-actions { display: flex; align-items: center; gap: 6px; flex: none; padding-top: 2px; }
.dv-head-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid color-mix(in srgb, var(--brand) 22%, var(--bs-border-color));
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--text-secondary);
  font-size: 12px; font-weight: 600;
  border-radius: 999px; padding: 4px 12px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.dv-head-btn:hover { color: var(--text-primary); border-color: var(--brand); }
.dv-head-btn:disabled { opacity: 0.55; cursor: default; }
.dv-head-btn .material-symbols-outlined { font-size: 16px; }
.dv-head-btn.primary {
  color: #fff; border-color: transparent;
  background: linear-gradient(-150deg, var(--brand-light), var(--brand) 60%, var(--brand-dark));
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--brand) 70%, transparent);
}
.dv-close {
  flex: none; width: 32px; height: 32px;
  display: grid; place-items: center;
  border: none; border-radius: 10px;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dv-close:hover { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--text-primary); }
.dv-close .material-symbols-outlined { font-size: 20px; }

/* --- The rail under the header carries real data in view mode --- */
.dv-progress {
  flex: none; height: 3px;
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--brand) 16%, var(--bs-border-color));
}
.dv-progress-bar {
  height: 3px; width: 0;
  border-radius: 3px 0 0 3px;
  background: linear-gradient(-90deg, var(--brand-light), var(--brand));
  box-shadow: 0 0 14px color-mix(in srgb, var(--brand) 65%, transparent);
  transition: width 0.6s cubic-bezier(0.32, 0.72, 0, 1);
}

/* --- View switch (Details / Wiki style tabs), sits under the progress rail --- */
.dv-tabs {
  flex: none; display: flex; gap: 2px;
  padding: 8px 18px 0;
  border-bottom: 1px solid var(--bs-border-color);
  background: var(--bg);
}
.dv-tab {
  border: none; background: transparent; cursor: pointer;
  font-size: 12.5px; font-weight: 600;
  color: var(--text-muted);
  padding: 7px 12px 9px;
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}
.dv-tab:hover { color: var(--text-primary); }
.dv-tab.is-active { color: var(--brand-dark); border-bottom-color: var(--brand); }
[data-theme="dark"] .dv-tab.is-active { color: var(--brand-light); }

/* --- Body: twin panes. The body itself never scrolls; each column
       does, so the rail card's height is the padded body area by
       construction, no measurement, no resize handling. --- */
.dv-body {
  padding: .5em;
  gap: .5em;
  flex: 1; min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-rows: minmax(0, 1fr);
}
/* Rail-less detail views collapse to a single column */
.dv-body.no-rail { grid-template-columns: minmax(0, 1fr); }
.dv-main {
  display: flex; flex-direction: column; gap: 14px;
  min-width: 0; min-height: 0;
  overflow-y: auto;
  scrollbar-width: none;
}
.dv-main::-webkit-scrollbar { display: none; }
.dv-main > * { flex-shrink: 0; }

/* --- Single-column mode: facts as a compact meta strip --- */
.dv-facts-strip {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px 20px;
  padding: 4px 6px 0;
}
.dv-strip-fact {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-primary); min-width: 0;
}
.dv-strip-fact .material-symbols-outlined { font-size: 15px; color: var(--brand); }
.dv-strip-fact .dv-avatar { width: 20px; height: 20px; font-size: 8.5px; }
.dv-strip-fact .muted { color: var(--text-muted); }
.dv-strip-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
}

/* --- Section card: the form's anatomy, verbatim --- */
.dv-section {
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 16px;
  overflow: visible;
  box-shadow:
    0 1px 2px rgba(20, 18, 16, 0.04),
    0 14px 30px -22px rgba(20, 18, 16, 0.55);
  animation: dv-rise 0.55s cubic-bezier(0.32, 0.72, 0, 1) backwards;
  animation-delay: calc(var(--sec-i, 0) * 70ms + 120ms);
}
@keyframes dv-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.dv-section-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.dv-section-chip {
  width: 34px; height: 34px; flex: none;
  border-radius: 11px;
  display: grid; place-items: center;
  color: var(--brand-dark);
  background: linear-gradient(-150deg,
    color-mix(in srgb, var(--brand) 24%, var(--surface)),
    color-mix(in srgb, var(--brand) 9%, var(--surface)));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 20%, transparent);
}
[data-theme="dark"] .dv-section-chip { color: var(--brand-light); }
.dv-section-chip .material-symbols-outlined { font-size: 19px; }
.dv-section-titles { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.dv-section-label { font-size: 13.5px; font-weight: 700; letter-spacing: -0.01em; color: var(--text-primary); }
.dv-section-sub { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.dv-section-count {
  flex: none; font-size: 11px; font-weight: 700;
  color: var(--text-muted); font-variant-numeric: tabular-nums;
  background: var(--bg-sunken); padding: 3px 9px; border-radius: 999px;
}
.dv-section-count.done { background: var(--focus-subtle); color: var(--focus-dark); }
[data-theme="dark"] .dv-section-count.done { color: var(--focus); }
.dv-section-body { padding: 2px 16px 16px; }
.dv-section-action {
  flex: none; display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--bs-border-color);
  background: transparent; cursor: pointer;
  font-size: 11.5px; font-weight: 600;
  color: var(--text-secondary);
  border-radius: 999px; padding: 3px 10px;
  transition: color 0.15s, border-color 0.15s;
}
.dv-section-action:hover { color: var(--text-primary); border-color: var(--brand); }
.dv-section-action:disabled { opacity: 0.55; cursor: default; }
.dv-section-action .material-symbols-outlined { font-size: 14px; }

/* Prose inside a section card */
.dv-prose { font-size: 13.5px; line-height: 1.65; color: var(--text-primary); }
.dv-prose p { margin: 0 0 10px; }
.dv-prose ul, .dv-prose ol { margin: 0 0 10px; padding-right: 20px; }
.dv-prose li { margin-bottom: 4px; }
.dv-prose :last-child { margin-bottom: 0; }

/* Checklist rows */
.dv-check { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; transition: background 0.15s; margin-bottom: 0; }
.dv-check:hover { background: var(--surface-hover); }
.dv-check input[type="checkbox"] {
  appearance: none; width: 17px; height: 17px; flex: none; cursor: pointer;
  border: 1.5px solid var(--bs-border-color); border-radius: 6px;
  background: var(--bg-sunken);
  display: grid; place-items: center;
  transition: background 0.15s, border-color 0.15s;
  margin: 0;
}
.dv-check input[type="checkbox"]:checked { background: var(--brand); border-color: var(--brand); }
.dv-check input[type="checkbox"]:checked::after {
  content: 'check'; font-family: 'Material Symbols Outlined';
  font-size: 13px; color: #fff; line-height: 1;
}
.dv-check-label { font-size: 13px; color: var(--text-primary); flex: 1; min-width: 0; }
.dv-check input[type="checkbox"]:checked ~ .dv-check-label { color: var(--text-muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--text-muted) 55%, transparent); }
.dv-check-who { font-size: 11px; color: var(--text-muted); flex: none; }

/* File rows */
.dv-file { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; transition: background 0.15s; }
.dv-file:hover { background: var(--surface-hover); }
.dv-file-icon {
  width: 32px; height: 32px; flex: none; border-radius: 9px;
  display: grid; place-items: center;
  color: var(--brand-dark);
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 16%, transparent);
}
[data-theme="dark"] .dv-file-icon { color: var(--brand-light); }
.dv-file-icon .material-symbols-outlined { font-size: 17px; }
.dv-file-name { font-size: 12.5px; font-weight: 600; color: var(--text-primary); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
a.dv-file-name:hover { color: var(--brand-dark); }
.dv-file-size { font-size: 11px; color: var(--text-muted); flex: none; font-variant-numeric: tabular-nums; }
.dv-file-remove {
  flex: none; border: none; background: transparent; cursor: pointer;
  color: var(--text-muted); font-size: 16px; line-height: 1;
  padding: 2px 6px; border-radius: 6px;
}
.dv-file-remove:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* Comments with avatars, composer sunken-then-lift */
.dv-comment { display: flex; gap: 10px; padding: 6px 0; }
.dv-avatar {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 700; color: #fff;
  object-fit: cover;
}
.dv-avatar.sm { width: 22px; height: 22px; font-size: 9px; }
.dv-comment-body { min-width: 0; flex: 1; }
.dv-comment-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.dv-comment-author { font-size: 12.5px; font-weight: 700; color: var(--text-primary); }
.dv-comment-when { font-size: 11px; color: var(--text-muted); }
.dv-comment-text { font-size: 13px; line-height: 1.55; color: var(--text-primary); }
.dv-comment-text p { margin: 0 0 6px; }
.dv-comment-text :last-child { margin-bottom: 0; }
.dv-composer,
textarea.dv-composer {
  width: 100%; min-height: 42px; margin-top: 8px;
  padding: 10px 13px; font-size: 13.5px; color: var(--text-primary);
  background: var(--bg-sunken);
  border: 1.5px solid transparent; border-radius: 11px;
  box-shadow: inset 0 1px 2px rgba(20, 18, 16, 0.05);
  transition: background 0.16s, border-color 0.16s, box-shadow 0.16s;
  resize: none;
}
.dv-composer:hover { border-color: color-mix(in srgb, var(--brand) 28%, transparent); }
.dv-composer:focus, .dv-composer:focus-within {
  outline: none; background: var(--surface); border-color: var(--brand);
  box-shadow:
    0 0 0 3.5px color-mix(in srgb, var(--brand) 15%, transparent),
    0 3px 10px -4px color-mix(in srgb, var(--brand) 45%, transparent);
}

/* --- The meta rail: a full-height section card, facts that stay put --- */
.dv-railcol { min-height: 0; }
.dv-rail {
  height: 100%;
  overflow-y: auto;
  scrollbar-width: none;
  padding: 16px 14px; display: flex; flex-direction: column; gap: 3px;
}
.dv-rail::-webkit-scrollbar { display: none; }
.dv-rail > * { flex-shrink: 0; }
.dv-rail-caption {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--text-muted);
  padding: 10px 10px 5px;
}
.dv-rail-caption:first-child { padding-top: 2px; }

/* A fact row: sunken by default, lifts on hover = "editable here" */
.dv-fact {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: right;
  border: 1.5px solid transparent; border-radius: 11px;
  background: transparent; cursor: pointer;
  padding: 7px 10px;
  transition: background 0.16s, border-color 0.16s, box-shadow 0.16s;
}
.dv-fact:hover, .dv-fact:focus-within {
  background: var(--surface);
  border-color: color-mix(in srgb, var(--brand) 28%, transparent);
  box-shadow: 0 3px 10px -4px color-mix(in srgb, var(--brand) 30%, transparent);
}
.dv-fact:hover .dv-fact-caret { opacity: 1; }
.dv-fact.readonly { cursor: default; }
.dv-fact.readonly:hover { background: transparent; border-color: transparent; box-shadow: none; }
.dv-fact-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); width: 74px; flex: none; }
.dv-fact-value { font-size: 12.5px; font-weight: 600; color: var(--text-primary); display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1; }
.dv-fact-value .muted { color: var(--text-muted); font-weight: 500; }
.dv-fact-value input {
  border: none; background: transparent; padding: 0; width: 100%;
  font: inherit; color: inherit;
}
.dv-fact-value input:focus { outline: none; }
.dv-fact-caret { margin-right: auto; flex: none; color: var(--text-muted); opacity: 0; transition: opacity 0.15s; }
.dv-fact-caret .material-symbols-outlined { font-size: 16px; display: block; }
.dv-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dv-chipset { display: flex; flex-wrap: wrap; gap: 4px; }
.dv-chip {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; font-weight: 700;
  color: var(--brand-dark);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  padding: 2px 8px; border-radius: 999px;
}
[data-theme="dark"] .dv-chip { color: var(--brand-light); }
.dv-chip-remove {
  border: none; background: transparent; cursor: pointer;
  color: inherit; font-size: 12px; line-height: 1; padding: 0;
  opacity: 0.7;
}
.dv-chip-remove:hover { opacity: 1; }

/* Fact rows hosting a picker dropdown need an anchor */
.dv-fact-anchor { position: relative; }

/* The rail's picker dropdown: same plane as the member picker, reusable */
.dv-picker-dropdown {
  position: absolute; top: calc(100% + 4px); right: 0; left: 0; z-index: 30;
  background: var(--surface);
  border: 1px solid var(--bs-border-color);
  border-radius: 12px;
  box-shadow: 0 18px 40px -18px rgba(20, 18, 16, 0.5);
  overflow: hidden;
}
.dv-picker-dropdown.dropup { top: auto; bottom: calc(100% + 4px); }
.dv-picker-search {
  width: 100%; border: none; border-bottom: 1px solid var(--bs-border-color);
  background: transparent; padding: 9px 12px;
  font-size: 12.5px; color: var(--text-primary);
}
.dv-picker-search:focus { outline: none; }
.dv-picker-results { max-height: 240px; overflow-y: auto; scrollbar-width: none; padding: 4px; }
.dv-picker-results::-webkit-scrollbar { display: none; }
.dv-picker-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: right; border: none; background: transparent; cursor: pointer;
  font-size: 12.5px; color: var(--text-primary);
  padding: 7px 9px; border-radius: 8px;
}
.dv-picker-item:hover { background: var(--surface-hover); }
.dv-picker-item .muted { color: var(--text-muted); font-size: 11px; }

/* Time block on the rail: numbers plus a mini bar */
.dv-time { padding: 7px 10px; }
.dv-time-nums { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.dv-time-big { font-size: 15px; font-weight: 800; letter-spacing: -0.02em; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.dv-time-big span { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.dv-time-pct { font-size: 11px; font-weight: 700; color: var(--brand-dark); font-variant-numeric: tabular-nums; }
[data-theme="dark"] .dv-time-pct { color: var(--brand-light); }
.dv-time-track { height: 5px; border-radius: 3px; background: color-mix(in srgb, var(--brand) 14%, transparent); overflow: hidden; }
.dv-time-fill { height: 100%; border-radius: 3px; background: linear-gradient(-90deg, var(--brand-light), var(--brand)); }

.dv-rail-sep { height: 1px; background: var(--bs-border-color); margin: 10px 6px; }

/* Rail-scoped skins for the shared widgets so microdate/microselect
   triggers read as fact rows (sunken, then lift) */
.dv-rail .mdate-trigger,
.dv-rail .msel-trigger {
  border: 1.5px solid transparent;
  background: transparent;
  border-radius: 11px;
  font-size: 12.5px; font-weight: 600;
  min-height: 0; padding: 7px 10px;
  box-shadow: none;
}
.dv-rail .mdate-trigger:hover, .dv-rail .mdate-trigger:focus-within,
.dv-rail .msel-trigger:hover, .dv-rail .msel-trigger.is-open {
  background: var(--surface);
  border-color: color-mix(in srgb, var(--brand) 28%, transparent);
  box-shadow: 0 3px 10px -4px color-mix(in srgb, var(--brand) 30%, transparent);
}

/* --- Footer: quiet provenance, danger stays out of the content --- */
.dv-footer {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--bs-border-color);
  background: var(--surface);
}
.dv-footer-meta { font-size: 11.5px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.dv-footer-meta .material-symbols-outlined { font-size: 15px; }
.dv-footer-spacer { flex: 1; }
.dv-danger-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid transparent; background: transparent;
  color: var(--text-muted); cursor: pointer;
  font-size: 12px; font-weight: 600;
  border-radius: 9px; padding: 5px 11px;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.dv-danger-btn:hover, .dv-danger-btn.armed {
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.dv-danger-btn .material-symbols-outlined { font-size: 16px; }
.dv-footer-confirm { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--danger); }

@media (max-width: 820px) {
  /* One column: back to a single scroll surface, rail card in flow */
  .dv-body { grid-template-columns: 1fr; grid-template-rows: none; overflow-y: auto; scrollbar-width: none; }
  .dv-body::-webkit-scrollbar { display: none; }
  .dv-main { overflow: visible; }
  .dv-rail { height: auto; overflow: visible; }
}

/* --- Flush editors: Microtext hugging its container edge to edge --- */

/* A section card whose body IS the editor (task description): the toolbar
   runs the full card width and the editable area ends at the card's edge. */
.dv-section-body.dv-flush { padding: 0; }
.dv-section-body.dv-flush .mt-wrap {
  border: none;
  border-radius: 0 0 15px 15px;
}
.dv-section-body.dv-flush .mt-toolbar {
  border-top: 1px solid var(--bs-border-color);
  border-radius: 0;
}

/* A full-bleed editor pane (task wiki): no body padding, the toolbar spans
   the card and the editable area fills every pixel down to the footer. */
.dv-body.dv-body-flush { padding: 0; gap: 0; }
.dv-body-flush .dv-main { gap: 0; }
.dv-editor-fill {
  flex: 1 0 auto;
  display: flex; flex-direction: column;
}
.dv-editor-fill .mt-wrap {
  flex: 1;
  display: flex; flex-direction: column;
  border: none; border-radius: 0;
}
.dv-editor-fill .mt-toolbar { flex: none; }
.dv-editor-fill .mt-wrap > [data-content] {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
.dv-editor-fill .mt-editor { flex: 1; }

/* --- In-page detail (.dv-page): the dv vocabulary on a scrolling page.
       No overlay and no bounded panes (nested fixed-height scroll under a
       sticky header causes scroll-chaining jank in the shell): the hero is
       a card, section cards stack, and the facts rail sticks while the
       page scrolls. --- */
/* The hero pins below the (also sticky) board header; the page scrolls
   under it. --te-sticky-top is measured as board-header height PLUS the
   page's own top padding, i.e. the hero's natural resting offset, so the
   hero never travels before pinning (zero wiggle). No shadow: a pinned
   wash card needs no lift. */
/* No overflow clip here, deliberately. .dv-card needs one for its 20px radius;
   this hero is border-radius: 0 and has no corners to clip, and a clip would
   cut off the status picker that opens out of .dv-header past the hero's
   bottom edge. Do not re-add it. */
/* Stays UNDER the app's own sticky header (the board header composites at 10,
   and it owns the tab strip plus the "More" overflow button and dropdown; that
   dropdown's z-index is clamped inside the header's stacking context, so it
   never escapes 10). The hero only has to outrank the page content scrolling
   beneath it, which is z-index auto. Raising this above the app header hides
   the tab controls. */
.dv-page-hero {
  flex: none;
  position: sticky;
  top: var(--te-sticky-top, 0px);
  z-index: 8;
  border: 1px solid color-mix(in srgb, var(--brand) 14%, var(--bs-border-color));
  border-radius: 0;
}
.dv-page .dv-body {
  overflow: visible;
  grid-template-rows: none;
  padding: 0;
}
.dv-page .dv-main { overflow: visible; }
/* In-page cards sit flat: the border does the framing, no shadow */
.dv-page .dv-section { box-shadow: none; }
.dv-page .dv-railcol { min-height: 0; }
/* The rail sticks below the pinned hero (--te-hero-h is measured live) */
.dv-page .dv-rail {
  position: sticky;
  top: calc(var(--te-sticky-top, 0px) + var(--te-hero-h, 0px) + 22px);
  height: auto;
  max-height: calc(100vh - var(--te-sticky-top, 0px) - var(--te-hero-h, 0px) - 32px);
}
.dv-page .dv-tabs {
  background: transparent;
  padding: 4px 4px 0;
  flex: none;
}

/* ============================================================
   Language switcher (anonymous surfaces: marketing + auth)
   Signed-in members use the pills in the account dropdown instead.
   Logical properties throughout so the menu mirrors under dir="rtl".
   ============================================================ */
.lang-switch { position: relative; }
.lang-switch-btn {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.25rem 0.5rem; border: 1px solid transparent;
  border-radius: 6px; background: transparent;
  font-size: 0.8125rem; font-weight: 500;
  color: var(--text-muted); cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.lang-switch-btn:hover,
.lang-switch-btn[aria-expanded="true"] { background: var(--surface-hover); color: var(--text-primary); }
.lang-switch-globe { flex: none; }
.lang-switch-code { letter-spacing: 0.03em; }
.lang-switch-menu {
  position: absolute; inset-block-start: calc(100% + 4px); inset-inline-end: 0;
  min-width: 160px; padding: 0.25rem; z-index: 1050;
  background: var(--surface); border: 1px solid var(--bs-border-color);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.10);
}
/* Footer placement opens upward: set lang_switch_up before including the partial. */
.lang-switch-up .lang-switch-menu {
  inset-block-start: auto; inset-block-end: calc(100% + 4px);
}
.lang-switch-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; padding: 0.4rem 0.6rem; border-radius: 6px;
  font-size: 0.8125rem; color: var(--text-primary); text-decoration: none;
}
.lang-switch-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.lang-switch-item-on { font-weight: 600; }
.lang-switch-tag {
  font-size: 0.65rem; font-weight: 600; letter-spacing: 0.05em;
  color: var(--text-muted);
}
.lang-switch-item-on .lang-switch-tag { color: var(--brand); }

/* ============================================================
   Arabic UI type. Noto Sans Arabic is vendored (SIL OFL, see
   public/vendor/fonts/noto-sans-arabic/OFL.txt); the unicode-range
   keeps the files from ever downloading on Latin-only pages, and
   Latin glyphs inside an RTL page keep falling through to the
   regular stack.
   ============================================================ */
@font-face {
  font-family: 'Noto Sans Arabic';
  src: url('/public/vendor/fonts/noto-sans-arabic/NotoSansArabic-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'Noto Sans Arabic';
  src: url('/public/vendor/fonts/noto-sans-arabic/NotoSansArabic-Bold.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF;
}
[dir="rtl"] body {
  font-family: 'Noto Sans Arabic', var(--bs-font-sans-serif);
}

/* Typed content decides its own direction under an RTL page: an email
   address, URL or English name entered in an Arabic form stays legible
   LTR, while Arabic text stays RTL. Applies only under [dir="rtl"], so
   LTR pages are untouched. */
[dir="rtl"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
[dir="rtl"] textarea,
[dir="rtl"] [contenteditable="true"] {
  unicode-bidi: plaintext;
}
