/* ============================================================================
 * DocuMate — the interface design system
 * ----------------------------------------------------------------------------
 * Loaded on top of the Tailwind CDN build on every app page, the builder and
 * the signing pages. Component classes are namespaced `dm-*`.
 *
 *   Type      Geist for the interface, Geist Mono for codes and figures —
 *             the same faces as the landing page. A document's own fonts are
 *             the author's and are never inherited from here (section 15).
 *   Colour    Cool neutrals biased toward the accent; one accent, the
 *             workspace's brand colour, which layouts pass in already made
 *             readable (src/lib/brand.js → --brand, --brand-on, --brand-text,
 *             --brand-text-dark); semantic colours kept separate from it.
 *   Actions   Primary (the one thing the page is for), secondary, tertiary
 *             (ghost), link, and destructive — each with hover, focus-visible,
 *             active, loading (aria-busy) and disabled states.
 *   Depth     Hairlines and soft shadow. No gradients except the skeleton.
 * ========================================================================== */

:root {
  /* --- Brand ------------------------------------------------------------- */
  --brand: #4f46e5;
  --brand-on: #ffffff;                                   /* text on the brand */
  --brand-text: var(--brand);                            /* brand as text on light surfaces */
  --brand-text-dark: color-mix(in srgb, var(--brand) 62%, white);
  --brand-fg: var(--brand-text);                         /* the one to use; swapped in dark */
  --brand-strong: color-mix(in srgb, var(--brand) 84%, black);
  --brand-tint:   color-mix(in srgb, var(--brand) 10%, white);
  --brand-wash:   color-mix(in srgb, var(--brand) 8%, white);
  --brand-line:   color-mix(in srgb, var(--brand) 26%, white);
  --brand-ring:   color-mix(in srgb, var(--brand) 32%, transparent);

  /* --- Neutrals — a cool slate biased slightly toward the accent ----------- */
  --ink:    #0C1220;
  --ink-2:  #37425A;
  --muted:  #646D80;
  --faint:  #98A1B4;
  --line:   #E3E7F0;
  --line-2: #EDF0F6;
  --line-strong: #D5DAE5;                                /* control borders */
  --canvas: #F4F5FA;
  --surface:#FFFFFF;
  --surface-2:#F7F8FC;

  /* --- Semantic (separate from the accent) -------------------------------- */
  --info:#1D4ED8; --info-wash:#EAF0FE; --info-line:#C9D8FB;
  --warn:#B45309; --warn-wash:#FDF3E3; --warn-line:#F2D9AE;
  --ok:#047857;   --ok-wash:#E3F5EC;   --ok-line:#B7E3CD;
  --bad:#C62828;  --bad-wash:#FDECEC;  --bad-line:#F4C7C7;

  /* --- Type --------------------------------------------------------------- */
  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --font-display: var(--font-sans);
  --mono: var(--font-mono);

  /* --- Shape -------------------------------------------------------------- */
  --r:    .875rem;   /* cards, dialogs */
  --r-sm: .625rem;   /* controls */
  --r-xs: .4375rem;  /* badges, menu items */
  --shadow-xs: 0 1px 1px rgb(12 18 32 / .04);
  --shadow-sm: 0 1px 2px rgb(12 18 32 / .06);
  --shadow:    0 6px 18px -8px rgb(12 18 32 / .14), 0 2px 6px -2px rgb(12 18 32 / .06);
  --shadow-md: 0 14px 34px -14px rgb(12 18 32 / .24), 0 3px 8px -3px rgb(12 18 32 / .08);

  --tooltip-bg: #0C1220;
  --tooltip-fg: #FFFFFF;
}

/* ----------------------------------------------------------------------------
 * 1. Accessibility + base typography
 * -------------------------------------------------------------------------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px;
}
:where(a, button, input, select, textarea, summary, [tabindex]):focus:not(:focus-visible) { outline: none; }
input[type="checkbox"], input[type="radio"], input[type="range"], progress { accent-color: var(--brand); }

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

html { -webkit-text-size-adjust: 100%; }
/* The app header is sticky. A field reached with Tab, or an anchor jumped to,
   must not land underneath it — nor under a sticky action bar (section 11). */
html:has(> body.dm-app-bg) { scroll-padding-top: 5rem; }
html:has(.dm-sticky-actions) { scroll-padding-bottom: 6.5rem; }
/* On a phone the bar's buttons and note can wrap to a second or third row. */
@media (max-width: 639px) { html:has(.dm-sticky-actions) { scroll-padding-bottom: 11rem; } }

body {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.006em; color: var(--ink-2);
}
/* One face carries the hierarchy: headings, display numbers, titles. */
h1, h2, h3, h4, .dm-page-title, .dm-section-title, .dm-stat-value, .dm-display {
  font-family: var(--font-display); letter-spacing: -0.02em; color: var(--ink);
}
/* Headings default to --ink, but that direct rule would otherwise override the
   inherited color inside a light-on-dark container (e.g. a brand band).
   Re-inherit so headings on dark sections stay legible instead of going dark. */
.text-white h1, .text-white h2, .text-white h3, .text-white h4 { color: inherit; }
.tnum, .dm-stat-value { font-variant-numeric: tabular-nums; }
.dm-mono, code, kbd, samp { font-family: var(--font-mono); }

* { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 9999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; background-clip: content-box; }

/* The brand, as it can be read. Tailwind's `text-brand` is the raw colour; a
   pale brand on white, or a dark one on the dark theme, disappeared. */
.text-brand { color: var(--brand-fg) !important; }
.bg-brand.text-white, .bg-brand .dm-on-brand { color: var(--brand-on) !important; }

/* ----------------------------------------------------------------------------
 * 2. Buttons
 * ----------------------------------------------------------------------------
 * .dm-btn-primary    the one action a screen is for — one per view or form
 * .dm-btn-secondary  everything else that is a button
 * .dm-btn-ghost      tertiary: toolbars, "Cancel" beside a primary in a row
 * .dm-btn-link       an action that reads as a link
 * .dm-btn-danger     destructive (outlined); -danger-solid inside a confirmation
 * Sizes: -sm 32px · default 38px · -lg 44px · -icon square
 * -------------------------------------------------------------------------- */
.dm-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  font-family: var(--font-sans); font-size: 0.875rem; font-weight: 600; line-height: 1.25rem; letter-spacing: -0.01em;
  padding: 0.5rem 0.9rem; border-radius: var(--r-sm);
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
  white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent;
}
.dm-btn:active:not(:disabled) { transform: translateY(0.5px); }
.dm-btn > i, .dm-btn > svg { flex: none; }
.dm-btn:disabled, .dm-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; box-shadow: none; }
/* A button that is working is not a disabled one: it keeps its colour. */
.dm-btn[aria-busy="true"] { cursor: progress; opacity: .85; }

.dm-btn-primary { background: var(--brand); color: var(--brand-on); box-shadow: 0 1px 2px rgb(12 18 32 / .14), inset 0 1px 0 rgb(255 255 255 / .12); }
.dm-btn-primary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--brand-strong); }

.dm-btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); box-shadow: var(--shadow-xs); }
.dm-btn-secondary:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--surface-2); border-color: #C3CAD8; }

.dm-btn-ghost { background: transparent; color: var(--ink-2); }
.dm-btn-ghost:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--surface-2); color: var(--ink); }

.dm-btn-link { background: none; border: 0; padding: 0; color: var(--brand-fg); font-weight: 600; box-shadow: none; }
.dm-btn-link:hover:not(:disabled) { text-decoration: underline; text-underline-offset: 3px; }

.dm-btn-danger { background: var(--surface); color: var(--bad); border-color: var(--bad-line); box-shadow: var(--shadow-xs); }
.dm-btn-danger:hover:not(:disabled):not([aria-disabled="true"]) { background: var(--bad-wash); border-color: color-mix(in srgb, var(--bad) 45%, var(--bad-line)); }
.dm-btn-danger-solid { background: var(--bad); color: #fff; }
.dm-btn-danger-solid:hover:not(:disabled):not([aria-disabled="true"]) { background: color-mix(in srgb, var(--bad) 86%, black); }

.dm-btn-sm { padding: 0.3125rem 0.65rem; font-size: 0.8125rem; border-radius: 0.5rem; gap: .375rem; }
.dm-btn-lg { padding: 0.6875rem 1.15rem; font-size: 0.9375rem; }
.dm-btn-block { width: 100%; }
.dm-btn-icon { padding: 0.5rem; aspect-ratio: 1; }
.dm-btn-icon.dm-btn-sm { padding: 0.375rem; }
/* The button's gap spaces its icon; a margin a view added on top of that
   doubled the space. */
.dm-btn > i[class*="mr-"], .dm-btn > svg[class*="mr-"] { margin-right: 0 !important; }
/* A row of actions: primary last on the right, the way dialogs read. */
.dm-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.dm-actions--end { justify-content: flex-end; }

/* ----------------------------------------------------------------------------
 * 3. Forms
 * -------------------------------------------------------------------------- */
/* No font-family: a control inherits its container's, so a field inside a
   document (.dm-doc) keeps the document's face and one in the interface gets
   the interface's. */
.dm-input, .dm-select, .dm-textarea {
  width: 100%; font-size: 0.875rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 0.5rem 0.75rem; line-height: 1.25rem; box-shadow: var(--shadow-xs);
  transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease;
}
.dm-input:hover:not(:disabled):not(:focus), .dm-select:hover:not(:disabled):not(:focus), .dm-textarea:hover:not(:disabled):not(:focus) { border-color: #C3CAD8; }
.dm-input::placeholder, .dm-textarea::placeholder { color: var(--faint); }
.dm-input:focus, .dm-select:focus, .dm-textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring);
}
.dm-input:disabled, .dm-select:disabled, .dm-textarea:disabled {
  background: var(--surface-2); color: var(--muted); border-color: var(--line); box-shadow: none; cursor: not-allowed;
}
.dm-input[readonly], .dm-textarea[readonly] { background: var(--surface-2); }
.dm-textarea { min-height: 6rem; resize: vertical; }
/* One chevron on every platform, in the neutral that reads on both themes. */
.dm-select {
  appearance: none; -webkit-appearance: none; padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%238792A5' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .7rem center; background-size: .875rem;
}
.dm-select[multiple] { background-image: none; padding-right: .75rem; }
.dm-label { display: block; font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); margin-bottom: 0.375rem; letter-spacing: -0.005em; }
.dm-hint { font-size: 0.75rem; line-height: 1.45; color: var(--muted); margin-top: 0.375rem; }
.dm-required::after { content: " *"; color: var(--bad); }

/* Layout: a form is a column of fields with one rhythm, and a row of actions. */
.dm-form { display: grid; gap: 1rem; }
.dm-field { display: grid; gap: .375rem; align-content: start; min-width: 0; }
.dm-field > .dm-label, .dm-field > .dm-hint { margin: 0; }
.dm-form-row { display: grid; gap: 1rem; }
@media (min-width: 640px) { .dm-form-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.dm-form-section { display: grid; gap: 1rem; padding-top: 1.25rem; border-top: 1px solid var(--line-2); }
.dm-form-section:first-child { padding-top: 0; border-top: 0; }
.dm-form-section-title { font-size: .9375rem; font-weight: 600; color: var(--ink); letter-spacing: -0.015em; margin: 0; }
.dm-form-section-text { font-size: .8125rem; color: var(--muted); margin: -.625rem 0 0; }
.dm-check { display: flex; align-items: flex-start; gap: .625rem; font-size: .875rem; color: var(--ink-2); cursor: pointer; }
.dm-check > input { margin-top: .1875rem; flex: none; width: 1rem; height: 1rem; }
.dm-check small, .dm-check .dm-hint { display: block; margin-top: .125rem; }

/* ----------------------------------------------------------------------------
 * 4. Cards & surfaces
 * -------------------------------------------------------------------------- */
.dm-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-sm); }
.dm-card-pad { padding: 1.25rem; }
.dm-card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; padding: .875rem 1.25rem; border-bottom: 1px solid var(--line-2); }
.dm-card-body { padding: 1.25rem; }
.dm-card-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem; padding: .75rem 1.25rem; border-top: 1px solid var(--line-2); background: var(--surface-2); border-radius: 0 0 var(--r) var(--r); }
.dm-card-hover { transition: box-shadow .18s ease, border-color .18s ease; }
.dm-card-hover:hover { box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--brand) 28%, var(--line)); }
.dm-surface-brand { background: var(--brand-wash); border: 1px solid var(--brand-line); }

/* App canvas: a clean, solid off-white. */
.dm-app-bg { background: var(--canvas); }

/* ----------------------------------------------------------------------------
 * 5. Responsive sidebar drawer (mobile)
 * -------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
  .dm-sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: 16rem; z-index: 50;
    transform: translateX(-100%); transition: transform .22s ease, visibility 0s linear .22s;
    box-shadow: 0 10px 40px -10px rgb(15 23 42 / .35);
    /* Off screen is not enough: a closed drawer's links were still in the tab
       order, so Tab walked through a dozen invisible items before the page. */
    visibility: hidden;
  }
  .dm-sidebar.is-open { transform: translateX(0); visibility: visible; transition: transform .22s ease; }
}

/* ----------------------------------------------------------------------------
 * 6. Content components
 * -------------------------------------------------------------------------- */
.dm-page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.dm-page-head > :last-child:not(:first-child) { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.dm-page-title { font-size: 1.75rem; line-height: 1.15; font-weight: 650; letter-spacing: -0.03em; text-wrap: balance; }
.dm-page-sub { font-size: 0.9375rem; line-height: 1.5; color: var(--muted); margin-top: 0.375rem; max-width: 46rem; text-wrap: pretty; }
.dm-section-title { font-size: 1rem; line-height: 1.35; font-weight: 600; letter-spacing: -0.015em; color: var(--ink); }
.dm-eyebrow {
  display: inline-flex; align-items: center; gap: 0.375rem;
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--brand-fg); background: var(--brand-wash); padding: 0.25rem 0.55rem; border-radius: 999px;
}
@media (max-width: 639.98px) { .dm-page-title { font-size: 1.5rem; } }

/* Stat / KPI card. */
.dm-stat { position: relative; container-type: inline-size; }
.dm-stat-value { font-size: 1.75rem; font-weight: 650; letter-spacing: -0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* An amount of money is the long figure: in a half-width card on a phone,
   "₱1,245,000.00" at full size ran out of its card and the page scrolled
   sideways. It scales with the card instead. */
.dm-stat-value:has(> [data-dm-money]) { font-size: min(1.75rem, 12cqi); }
.dm-stat-label { font-size: 0.78rem; font-weight: 500; color: var(--muted); }

.dm-chip { display: inline-flex; align-items: center; justify-content: center; border-radius: .7rem; }

/* Status pill with a leading dot — document and recipient status. */
.dm-pill { display: inline-flex; align-items: center; gap: 0.375rem; font-size: 0.75rem; font-weight: 600; line-height: 1.1rem; padding: 0.125rem 0.55rem; border-radius: 999px; white-space: nowrap; }
.dm-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.dm-pill--info  { color: var(--info); background: var(--info-wash); }
.dm-pill--warn  { color: var(--warn); background: var(--warn-wash); }
.dm-pill--ok    { color: var(--ok);   background: var(--ok-wash); }
.dm-pill--bad   { color: var(--bad);  background: var(--bad-wash); }
.dm-pill--brand { color: var(--brand-fg); background: var(--brand-wash); }
.dm-pill--muted { color: var(--muted); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-2); }
.dm-delta { font-size: 0.75rem; font-weight: 650; display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.15rem 0.5rem; border-radius: 999px; }
.dm-delta--up { color: var(--ok); background: var(--ok-wash); }
.dm-delta--down { color: var(--bad); background: var(--bad-wash); }

/* Badge — a label or a count, without the status dot. */
.dm-badge {
  display: inline-flex; align-items: center; gap: .25rem; min-height: 1.25rem; padding: 0 .45rem;
  border-radius: var(--r-xs); font-size: .6875rem; font-weight: 600; line-height: 1; letter-spacing: .01em; white-space: nowrap;
  color: var(--ink-2); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line);
}
.dm-badge--brand { color: var(--brand-fg); background: var(--brand-wash); box-shadow: inset 0 0 0 1px var(--brand-line); }
.dm-badge--ok    { color: var(--ok);   background: var(--ok-wash);   box-shadow: inset 0 0 0 1px var(--ok-line); }
.dm-badge--warn  { color: var(--warn); background: var(--warn-wash); box-shadow: inset 0 0 0 1px var(--warn-line); }
.dm-badge--bad   { color: var(--bad);  background: var(--bad-wash);  box-shadow: inset 0 0 0 1px var(--bad-line); }
.dm-badge--info  { color: var(--info); background: var(--info-wash); box-shadow: inset 0 0 0 1px var(--info-line); }
.dm-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 1.125rem; height: 1.125rem; padding: 0 .3rem;
  border-radius: 999px; background: var(--brand); color: var(--brand-on); font-size: .625rem; font-weight: 700; font-variant-numeric: tabular-nums;
}

/* Table */
.dm-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.875rem; }
.dm-table thead th { text-align: left; font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0.625rem 1.25rem; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.dm-table tbody td { padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.dm-table tbody tr:last-child td { border-bottom: 0; }
.dm-table tbody tr { transition: background-color .12s ease; }
.dm-table tbody tr:hover { background: var(--surface-2); }
.dm-table-compact tbody td { padding: .5rem 1rem; }
.dm-table-compact thead th { padding: .5rem 1rem; }
/* Every table gets a horizontal-scroll safety wrapper. */
.dm-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Below a phone's width a table with data-label cells becomes a stack of rows:
   each cell says what it is, instead of the table scrolling sideways. The same
   happens when the table's own box is that narrow — a tablet with the sidebar
   open left a four-column team table about 460px, and emails broke across
   three lines. The container query needs .dm-table-wrap (dm-format.js adds it
   around every table); the media query covers the moment before it runs. */
.dm-table-wrap { container: dmtable / inline-size; }
@media (max-width: 639.98px) {
  .dm-table-stack thead { display: none; }
  .dm-table-stack, .dm-table-stack tbody, .dm-table-stack tr, .dm-table-stack td { display: block; width: 100%; }
  .dm-table-stack tbody tr { padding: .75rem 1rem; border-bottom: 1px solid var(--line-2); }
  .dm-table-stack tbody tr:last-child { border-bottom: 0; }
  .dm-table-stack tbody td { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .3rem 0; border: 0; text-align: right; }
  .dm-table-stack tbody td[data-label]::before { content: attr(data-label); font-size: .75rem; font-weight: 600; color: var(--muted); text-align: left; flex: none; }
  .dm-table-stack tbody td.dm-cell-main { display: block; text-align: left; padding-bottom: .4rem; }
  .dm-table-stack tbody td.dm-cell-main::before { content: none; }
}
@container dmtable (max-width: 36rem) {
  .dm-table-stack thead { display: none; }
  .dm-table-stack, .dm-table-stack tbody, .dm-table-stack tr, .dm-table-stack td { display: block; width: 100%; }
  .dm-table-stack tbody tr { padding: .75rem 1rem; border-bottom: 1px solid var(--line-2); }
  .dm-table-stack tbody tr:last-child { border-bottom: 0; }
  .dm-table-stack tbody td { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .3rem 0; border: 0; text-align: right; }
  .dm-table-stack tbody td[data-label]::before { content: attr(data-label); font-size: .75rem; font-weight: 600; color: var(--muted); text-align: left; flex: none; }
  .dm-table-stack tbody td.dm-cell-main { display: block; text-align: left; padding-bottom: .4rem; }
  .dm-table-stack tbody td.dm-cell-main::before { content: none; }
}

/* Empty state — says what is missing and offers the way forward. A list that
   has nothing yet, and a search that matched nothing, are different states and
   say different things (partials/empty.ejs). */
.dm-empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .375rem; color: var(--muted); padding: 3rem 1.25rem; }
.dm-empty-icon { width: 2.75rem; height: 2.75rem; border-radius: .875rem; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); display: flex; align-items: center; justify-content: center; color: var(--muted); margin-bottom: 0.5rem; font-size: 1.125rem; }
.dm-empty-title { margin: 0; font-size: .9375rem; line-height: 1.35; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
.dm-empty-text { margin: 0; font-size: .875rem; line-height: 1.5; max-width: 26rem; text-wrap: pretty; }
.dm-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-top: .875rem; }
.dm-empty--compact { padding: 1.75rem 1rem; }
.dm-empty--compact .dm-empty-icon { width: 2.25rem; height: 2.25rem; font-size: .9375rem; }

/* Tabs */
.dm-tabs { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.dm-tabs::-webkit-scrollbar { display: none; }
.dm-tab { position: relative; padding: 0.65rem 0.125rem; font-size: 0.875rem; font-weight: 500; color: var(--muted); white-space: nowrap; transition: color .12s ease; }
.dm-tab:hover { color: var(--ink-2); }
.dm-tab-active, .dm-tab[aria-selected="true"] { color: var(--ink); font-weight: 600; }
.dm-tab-active::after, .dm-tab[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px; background: var(--brand); }

/* Filter chips — a toggle for one value of a filter (a status, a category).
   The chosen one says so in its attributes as well as its colour. */
.dm-filter-chip {
  display: inline-flex; align-items: center; gap: .375rem; padding: .3125rem .75rem; border-radius: 999px;
  font-size: .8125rem; font-weight: 500; line-height: 1.25rem; white-space: nowrap; text-decoration: none; cursor: pointer;
  color: var(--ink-2); background: var(--surface); border: 1px solid var(--line-strong); transition: background-color .12s, border-color .12s, color .12s;
}
.dm-filter-chip:hover { border-color: #C3CAD8; color: var(--ink); }
.dm-filter-chip .dm-filter-count { color: var(--muted); font-variant-numeric: tabular-nums; }
.dm-filter-chip.is-on, .dm-filter-chip[aria-current="true"], .dm-filter-chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-on); }
.dm-filter-chip.is-on .dm-filter-count, .dm-filter-chip[aria-current="true"] .dm-filter-count, .dm-filter-chip[aria-pressed="true"] .dm-filter-count { color: inherit; opacity: .8; }
:root[data-theme="dark"] .dm-filter-chip:hover { border-color: #465266; }
/* A row of filter chips: wraps on a wide screen; on a phone it scrolls
   sideways as one line instead of stacking three rows above the list. */
.dm-chip-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
@media (max-width: 639px) {
  .dm-chip-row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -1.25rem; padding: 2px 1.25rem; scroll-padding-inline: 1.25rem; }
  .dm-chip-row::-webkit-scrollbar { display: none; }
  .dm-chip-row > * { flex: none; }
}

/* Inline code and placeholders ({{client_name}}) — used by views, defined
   nowhere until now. */
.dm-code { font-family: var(--font-mono); font-size: .85em; padding: .1em .35em; border-radius: .3rem; background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

/* Segmented control */
.dm-seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 0.65rem; padding: 3px; }
.dm-seg > button { border: none; background: none; font: inherit; font-size: 0.78rem; font-weight: 600; color: var(--muted); padding: 0.32rem 0.7rem; border-radius: 0.45rem; cursor: pointer; }
.dm-seg > button.is-on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* Menus and popovers — a surface, items with one hover and focus state, and a
   destructive item that looks like one. */
.dm-menu { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); border-radius: .75rem; box-shadow: var(--shadow-md); padding: .375rem; }
.dm-menu-item {
  display: flex; align-items: center; gap: .625rem; width: 100%; padding: .5rem .625rem; border: 0; background: none;
  border-radius: var(--r-xs); font: inherit; font-size: .875rem; color: var(--ink-2); text-align: left; text-decoration: none; cursor: pointer;
}
.dm-menu-item > i, .dm-menu-item > svg { width: 1rem; text-align: center; color: var(--muted); flex: none; }
.dm-menu-item:hover, .dm-menu-item:focus-visible { background: var(--surface-2); color: var(--ink); }
.dm-menu-item.is-danger { color: var(--bad); }
.dm-menu-item.is-danger > i { color: var(--bad); }
.dm-menu-item.is-danger:hover, .dm-menu-item.is-danger:focus-visible { background: var(--bad-wash); color: var(--bad); }
.dm-menu-label { padding: .375rem .625rem .25rem; font-size: .6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.dm-menu-sep { height: 1px; margin: .3rem .25rem; background: var(--line-2); border: 0; }

/* Tooltips — for an icon button's name when a person hovers or tabs to it. The
   accessible name is still aria-label; this is the visible half. */
:where([data-tooltip]) { position: relative; }
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after {
  content: attr(data-tooltip); position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%);
  z-index: 200; pointer-events: none; white-space: nowrap;
  background: var(--tooltip-bg); color: var(--tooltip-fg); box-shadow: var(--shadow);
  font: 500 .75rem/1.3 var(--font-sans); letter-spacing: 0; padding: .3rem .5rem; border-radius: .4rem;
}
[data-tooltip-pos="top"]:hover::after, [data-tooltip-pos="top"]:focus-visible::after { top: auto; bottom: calc(100% + 6px); }

/* Alerts — an outcome or a problem on the page itself, with its way forward. */
.dm-alert { display: flex; align-items: flex-start; gap: .75rem; padding: .75rem 1rem; border-radius: .75rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: .875rem; line-height: 1.5; }
.dm-alert > i:first-child { margin-top: .2rem; flex: none; }
.dm-alert-body { flex: 1; min-width: 0; }
.dm-alert-title { display: block; font-weight: 600; color: inherit; }
.dm-alert-actions { display: flex; flex-wrap: wrap; gap: .375rem .75rem; margin-top: .5rem; }
.dm-alert-actions a, .dm-alert-actions button { font: inherit; font-weight: 600; color: inherit; background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.dm-alert-close { flex: none; margin: -.125rem -.25rem 0 0; padding: .25rem; border: 0; background: none; color: inherit; opacity: .6; cursor: pointer; border-radius: .375rem; }
.dm-alert-close:hover { opacity: 1; }
.dm-alert--bad  { background: var(--bad-wash);  border-color: var(--bad-line);  color: color-mix(in srgb, var(--bad) 82%, var(--ink)); }
.dm-alert--bad > i:first-child { color: var(--bad); }
.dm-alert--ok   { background: var(--ok-wash);   border-color: var(--ok-line);   color: color-mix(in srgb, var(--ok) 82%, var(--ink)); }
.dm-alert--ok > i:first-child { color: var(--ok); }
.dm-alert--warn { background: var(--warn-wash); border-color: var(--warn-line); color: color-mix(in srgb, var(--warn) 82%, var(--ink)); }
.dm-alert--warn > i:first-child { color: var(--warn); }
.dm-alert--info { background: var(--info-wash); border-color: var(--info-line); color: color-mix(in srgb, var(--info) 82%, var(--ink)); }
.dm-alert--info > i:first-child { color: var(--info); }

/* ----------------------------------------------------------------------------
 * 7. Dialogs + animations
 * -------------------------------------------------------------------------- */
/* Every native <dialog> takes the theme's surface — a dialog on the dark theme
   was a white sheet with light text. .dm-modal adds the standard anatomy. */
dialog { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); max-height: calc(100dvh - 2rem); overflow: auto; }
dialog::backdrop { background: rgb(12 18 32 / .45); backdrop-filter: blur(2px); }
dialog[open] { animation: dm-dialog-in .18s ease-out; }
dialog.dm-modal { width: min(100% - 2rem, 28rem); padding: 0; border-radius: 1rem; box-shadow: var(--shadow-md); }
dialog.dm-modal-lg { width: min(100% - 2rem, 40rem); }
.dm-modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.25rem 1.25rem 0; }
.dm-modal-title { margin: 0; font-size: 1.0625rem; line-height: 1.35; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); }
.dm-modal-text { margin: .25rem 0 0; font-size: .875rem; line-height: 1.5; color: var(--muted); }
.dm-modal-body { display: grid; gap: 1rem; padding: 1rem 1.25rem 1.25rem; }
.dm-modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; padding: .875rem 1.25rem; border-top: 1px solid var(--line-2); background: var(--surface-2); }
.dm-modal-close { flex: none; margin: -.375rem -.5rem 0 0; }
@keyframes dm-dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes dm-fade-in { from { opacity: 0; } to { opacity: 1; } }
.dm-fade-in { animation: dm-fade-in .2s ease both; }
@keyframes dm-slide-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.dm-slide-up { animation: dm-slide-up .25s ease both; }

/* ============================================================================
 * 8. Dialogs, toasts, loading and skeletons (driven by public/js/dm-ui.js)
 * ========================================================================== */

.dm-overlay {
  position: fixed; inset: 0; z-index: 120;
  background: rgb(12 18 32 / .5); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
  animation: dm-fade-in .12s ease both;
}
.dm-dialog {
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-md);
  width: 100%; max-width: 28rem; padding: 1.25rem;
  animation: dm-dialog-in .16s ease-out both;
}
.dm-dialog-title { font-family: var(--font-display); font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.02em; color: var(--ink); margin: 0 0 .375rem; }
.dm-dialog-msg { margin: 0; font-size: .9375rem; line-height: 1.55; }
.dm-dialog-detail { margin: .6rem 0 0; font-size: .8125rem; color: var(--muted); }
.dm-dialog .dm-label { margin-top: 1rem; }
.dm-dialog .dm-input { margin-top: .3rem; }
.dm-dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; }
/* A destructive dialog leads with the accent that matches its consequence. */
.dm-dialog.is-danger { border-color: var(--bad-line); }
/* The confirmation's native <dialog> is only a frame for the panel above: it
   brings the top layer and the backdrop, and draws nothing of its own. */
dialog.dm-confirm { width: min(100% - 2rem, 28rem); max-width: none; padding: 0; border: 0; background: transparent; box-shadow: none; overflow: visible; }
dialog.dm-confirm[open] { animation: none; }

/* Toasts. Bottom-centre on a phone (thumb reach), bottom-right on a desktop. */
.dm-flash-stack {
  position: fixed; z-index: 130; display: flex; flex-direction: column; gap: .5rem;
  left: 1rem; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  align-items: center; pointer-events: none;
}
@media (min-width: 640px) { .dm-flash-stack { left: auto; right: 1.25rem; align-items: flex-end; } }
.dm-flash {
  pointer-events: auto; display: flex; align-items: center; gap: .75rem;
  background: var(--ink); color: #fff; border-radius: .75rem;
  padding: .7rem .8rem .7rem 1rem; box-shadow: var(--shadow-md);
  font-size: .875rem; max-width: min(30rem, 100%);
  animation: dm-slide-up .2s ease both;
}
.dm-flash--ok   { background: #065F46; }
.dm-flash--bad  { background: #B91C1C; }
.dm-flash--warn { background: #92400E; }
.dm-flash-text { flex: 1; min-width: 0; }
.dm-flash-action {
  background: rgb(255 255 255 / .16); color: #fff; border: 0; border-radius: .5rem;
  font: inherit; font-weight: 600; padding: .3rem .7rem; cursor: pointer; white-space: nowrap;
}
.dm-flash-action:hover { background: rgb(255 255 255 / .28); }
.dm-flash-close { background: none; border: 0; color: rgb(255 255 255 / .7); font-size: 1.1rem; line-height: 1; cursor: pointer; padding: 0 .2rem; }
.dm-flash-close:hover { color: #fff; }

/* Spinner */
.dm-spinner {
  display: inline-block; width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: dm-spin .6s linear infinite; vertical-align: -0.125em;
}
@keyframes dm-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .dm-spinner { animation-duration: 1.6s; } }
[aria-busy="true"] { cursor: progress; }

/* Skeletons — what a region shows while it is still arriving, in the shape it
   will have, so nothing jumps when it lands. */
.dm-skeleton {
  background: linear-gradient(90deg, var(--line-2) 25%, var(--surface-2) 37%, var(--line-2) 63%);
  background-size: 400% 100%; animation: dm-shimmer 1.4s ease infinite;
  border-radius: .5rem; color: transparent !important; user-select: none;
}
@keyframes dm-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .dm-skeleton { animation: none; background: var(--line-2); } }
.dm-skeleton-line { height: .8rem; margin: .35rem 0; }
.dm-skeleton-line.w-60 { width: 60%; } .dm-skeleton-line.w-40 { width: 40%; } .dm-skeleton-line.w-80 { width: 80%; }
.dm-skeleton-circle { border-radius: 999px; flex: none; }
.dm-skeleton-row { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; }
.dm-skeleton-row > .dm-skeleton-stack { flex: 1; min-width: 0; }

/* ----------------------------------------------------------------------------
 * 9. Touch, safe areas and the mobile table
 * -------------------------------------------------------------------------- */

/* Forty-four is the floor for a thumb, and several row controls were near 30. */
@media (pointer: coarse) {
  .dm-btn, .dm-tap { min-height: 44px; }
  .dm-icon-btn { min-width: 44px; min-height: 44px; }
  /* iOS zooms the page when a focused field is under 16px, which jumps the
     layout mid-form. */
  .dm-input, .dm-select, .dm-textarea, input, select, textarea { font-size: max(16px, 0.875rem); }
}
.dm-icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem; border-radius: .6rem; color: var(--muted);
  background: none; border: 0; cursor: pointer; transition: background-color .12s, color .12s;
}
.dm-icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Anything pinned to the bottom clears the iOS toolbar. */
.dm-safe-bottom { padding-bottom: calc(.75rem + env(safe-area-inset-bottom, 0px)); }

/* A table below this width is the wrong shape; views pair .dm-table-cards with
   a card list that takes over. */
@media (max-width: 767.98px) {
  .dm-table-cards { display: none; }
  .dm-cards-only { display: block; }
}
@media (min-width: 768px) { .dm-cards-only { display: none; } }

/* ----------------------------------------------------------------------------
 * 10. Dark mode, everywhere rather than in the builder only
 * ----------------------------------------------------------------------------
 * Everything above is written against these tokens, so redefining them is most
 * of the port. The rest re-points the Tailwind utilities views use directly.
 * -------------------------------------------------------------------------- */
:root[data-theme="dark"], .dark {
  --ink:      #EAEFF7;
  --ink-2:    #B8C1D0;
  --muted:    #8D98AB;
  --faint:    #6B7688;
  --line:     #2A3444;
  --line-2:   #222B39;
  --line-strong: #364153;
  --canvas:   #0B0F16;
  --surface:  #131A24;
  --surface-2:#1A222E;

  --info-wash:#14213D; --warn-wash:#2B1F0F; --ok-wash:#0D271E; --bad-wash:#301617;
  --info-line:#243A66; --warn-line:#4D3715; --ok-line:#16463A; --bad-line:#5A2527;
  --info:#8AB0FF; --warn:#E9A14B; --ok:#4ADE9A; --bad:#F87171;

  --brand-fg:   var(--brand-text-dark);
  --brand-tint: color-mix(in srgb, var(--brand) 26%, #131A24);
  --brand-wash: color-mix(in srgb, var(--brand) 18%, #131A24);
  --brand-line: color-mix(in srgb, var(--brand) 42%, #131A24);
  --brand-ring: color-mix(in srgb, var(--brand-text-dark) 45%, transparent);
  --shadow-xs: 0 1px 1px rgb(0 0 0 / .3);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .4);
  --shadow:    0 6px 18px -8px rgb(0 0 0 / .6), 0 2px 6px -2px rgb(0 0 0 / .4);
  --shadow-md: 0 14px 34px -14px rgb(0 0 0 / .75);
  --tooltip-bg: #EAEFF7;
  --tooltip-fg: #0C1220;
  color-scheme: dark;
}
:root[data-theme="dark"] body, .dark body { background: var(--canvas); color: var(--ink-2); }
:root[data-theme="dark"] .bg-white, .dark .bg-white { background: var(--surface) !important; }
/* Tailwind's opacity variants are separate classes, so `.bg-white` never
   matched `bg-white/85` — which is exactly what the app header uses, and why it
   stayed light on a dark ground. Same for the translucent borders. */
:root[data-theme="dark"] [class*="bg-white/"], .dark [class*="bg-white/"] { background: color-mix(in srgb, var(--surface) 88%, transparent) !important; }
:root[data-theme="dark"] [class*="bg-slate-50/"], .dark [class*="bg-slate-50/"] { background: var(--surface-2) !important; }
:root[data-theme="dark"] [class*="border-slate-200/"], :root[data-theme="dark"] [class*="border-slate-100/"],
.dark [class*="border-slate-200/"], .dark [class*="border-slate-100/"] { border-color: var(--line) !important; }
/* Except where white-on-brand is deliberate: a translucent white pill sitting
   ON the accent colour must stay translucent white, not become a surface. */
:root[data-theme="dark"] .bg-brand [class*="bg-white/"], .dark .bg-brand [class*="bg-white/"],
:root[data-theme="dark"] .text-white [class*="bg-white/"], .dark .text-white [class*="bg-white/"] {
  background: rgb(255 255 255 / .12) !important;
}
:root[data-theme="dark"] .bg-slate-50, .dark .bg-slate-50 { background: var(--surface-2) !important; }
:root[data-theme="dark"] .bg-slate-100, .dark .bg-slate-100 { background: var(--line-2) !important; }
:root[data-theme="dark"] .bg-slate-200, .dark .bg-slate-200 { background: var(--line) !important; }
:root[data-theme="dark"] .text-slate-800, :root[data-theme="dark"] .text-slate-900,
.dark .text-slate-800, .dark .text-slate-900 { color: var(--ink) !important; }
:root[data-theme="dark"] .text-slate-700, :root[data-theme="dark"] .text-slate-600,
.dark .text-slate-700, .dark .text-slate-600 { color: var(--ink-2) !important; }
:root[data-theme="dark"] .text-slate-500, :root[data-theme="dark"] .text-slate-400,
.dark .text-slate-500, .dark .text-slate-400 { color: var(--muted) !important; }
/* slate-300 is the faintest text in the light theme; on a dark ground it came
   out brighter than the body copy, turning the hierarchy upside down. */
:root[data-theme="dark"] .text-slate-300, .dark .text-slate-300 { color: var(--faint) !important; }
:root[data-theme="dark"] .border-slate-200, :root[data-theme="dark"] .border-slate-100,
.dark .border-slate-200, .dark .border-slate-100 { border-color: var(--line) !important; }
:root[data-theme="dark"] .border-slate-300, .dark .border-slate-300 { border-color: var(--line-strong) !important; }
/* Row separators. `divide-*` colours the borders BETWEEN a list's children —
   a rule the border mapping above never matches — so every list's separators
   stayed as light lines on a dark ground. And the faint row borders with them. */
:root[data-theme="dark"] .border-slate-50, .dark .border-slate-50,
:root[data-theme="dark"] :is(.divide-slate-50, .divide-slate-100, .divide-slate-200) > :not([hidden]) ~ :not([hidden]),
.dark :is(.divide-slate-50, .divide-slate-100, .divide-slate-200) > :not([hidden]) ~ :not([hidden]) { border-color: var(--line) !important; }
/* Hover states. `hover:bg-slate-100` is its own class; unmapped, every menu
   item and row in the dark theme flashed a light block with light text on it. */
:root[data-theme="dark"] :is(.hover\:bg-slate-50, .hover\:bg-slate-100, .hover\:bg-slate-200, .hover\:bg-white):hover,
.dark :is(.hover\:bg-slate-50, .hover\:bg-slate-100, .hover\:bg-slate-200, .hover\:bg-white):hover { background: var(--surface-2) !important; }
:root[data-theme="dark"] :is(.hover\:text-slate-600, .hover\:text-slate-700, .hover\:text-slate-800, .hover\:text-slate-900):hover,
.dark :is(.hover\:text-slate-600, .hover\:text-slate-700, .hover\:text-slate-800, .hover\:text-slate-900):hover { color: var(--ink) !important; }
:root[data-theme="dark"] .hover\:border-slate-300:hover, .dark .hover\:border-slate-300:hover { border-color: #465266 !important; }
:root[data-theme="dark"] :is(.ring-white), .dark :is(.ring-white) { --tw-ring-color: var(--surface) !important; }
:root[data-theme="dark"] :is(.ring-slate-100, .ring-slate-200), .dark :is(.ring-slate-100, .ring-slate-200) { --tw-ring-color: var(--line) !important; }
/* Tinted notices (warning panels, error boxes, success rows). The light tints
   were pale blocks with pale text on the dark theme. */
:root[data-theme="dark"] :is(.bg-red-50, .bg-red-100, .bg-rose-50, .bg-rose-100), .dark :is(.bg-red-50, .bg-red-100, .bg-rose-50, .bg-rose-100) { background: var(--bad-wash) !important; }
:root[data-theme="dark"] :is(.bg-amber-50, .bg-amber-100, .bg-yellow-50, .bg-orange-50), .dark :is(.bg-amber-50, .bg-amber-100, .bg-yellow-50, .bg-orange-50) { background: var(--warn-wash) !important; }
:root[data-theme="dark"] :is(.bg-emerald-50, .bg-emerald-100, .bg-green-50, .bg-green-100), .dark :is(.bg-emerald-50, .bg-emerald-100, .bg-green-50, .bg-green-100) { background: var(--ok-wash) !important; }
:root[data-theme="dark"] :is(.bg-blue-50, .bg-sky-50, .bg-indigo-50, .bg-indigo-100, .bg-violet-50), .dark :is(.bg-blue-50, .bg-sky-50, .bg-indigo-50, .bg-indigo-100, .bg-violet-50) { background: var(--info-wash) !important; }
:root[data-theme="dark"] [class*="bg-amber-50/"], .dark [class*="bg-amber-50/"] { background: var(--warn-wash) !important; }
:root[data-theme="dark"] :is([class*="bg-red-50/"], [class*="bg-rose-50/"]), .dark :is([class*="bg-red-50/"], [class*="bg-rose-50/"]) { background: var(--bad-wash) !important; }
:root[data-theme="dark"] :is([class*="bg-emerald-50/"], [class*="bg-green-50/"]), .dark :is([class*="bg-emerald-50/"], [class*="bg-green-50/"]) { background: var(--ok-wash) !important; }
:root[data-theme="dark"] :is([class*="bg-blue-50/"], [class*="bg-indigo-50/"]), .dark :is([class*="bg-blue-50/"], [class*="bg-indigo-50/"]) { background: var(--info-wash) !important; }
:root[data-theme="dark"] :is(.border-red-200, .border-red-300, .border-rose-200), .dark :is(.border-red-200, .border-red-300, .border-rose-200) { border-color: var(--bad-line) !important; }
:root[data-theme="dark"] :is(.border-amber-200, .border-amber-300, .border-yellow-200), .dark :is(.border-amber-200, .border-amber-300, .border-yellow-200) { border-color: var(--warn-line) !important; }
:root[data-theme="dark"] :is(.border-emerald-200, .border-emerald-300, .border-green-200), .dark :is(.border-emerald-200, .border-emerald-300, .border-green-200) { border-color: var(--ok-line) !important; }
:root[data-theme="dark"] :is(.border-blue-200, .border-indigo-200), .dark :is(.border-blue-200, .border-indigo-200) { border-color: var(--info-line) !important; }
:root[data-theme="dark"] :is(.text-red-600, .text-red-700, .text-red-800, .text-red-900, .text-rose-700, .text-rose-900, .hover\:text-red-600:hover, .hover\:text-red-700:hover),
.dark :is(.text-red-600, .text-red-700, .text-red-800, .text-red-900, .text-rose-700, .text-rose-900, .hover\:text-red-600:hover, .hover\:text-red-700:hover) { color: var(--bad) !important; }
:root[data-theme="dark"] :is(.text-amber-600, .text-amber-700, .text-amber-800, .text-amber-900), .dark :is(.text-amber-600, .text-amber-700, .text-amber-800, .text-amber-900) { color: var(--warn) !important; }
:root[data-theme="dark"] :is(.text-emerald-600, .text-emerald-700, .text-emerald-800, .text-emerald-900, .text-green-600, .text-green-700), .dark :is(.text-emerald-600, .text-emerald-700, .text-emerald-800, .text-emerald-900, .text-green-600, .text-green-700) { color: var(--ok) !important; }
:root[data-theme="dark"] :is(.text-blue-600, .text-blue-700, .text-sky-700, .text-indigo-600, .text-indigo-700, .text-violet-700), .dark :is(.text-blue-600, .text-blue-700, .text-sky-700, .text-indigo-600, .text-indigo-700, .text-violet-700) { color: var(--info) !important; }
:root[data-theme="dark"] .hover\:bg-red-50:hover, .dark .hover\:bg-red-50:hover { background: var(--bad-wash) !important; }
/* Form controls a view styled by hand rather than with .dm-input. Zero
   specificity, so a view's own background class (bg-transparent) still wins. */
/* A field that sits inside its own pill (the header search, the list filters)
   is transparent on purpose; painting it the surface colour drew a dark box
   inside the lighter pill. */
:root[data-theme="dark"] :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not(.bg-transparent), select:not(.bg-transparent), textarea:not(.bg-transparent)),
.dark :where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not(.bg-transparent), select:not(.bg-transparent), textarea:not(.bg-transparent)) { background-color: var(--surface); color: var(--ink); border-color: var(--line-strong); }
:root[data-theme="dark"] :where(input.bg-transparent, textarea.bg-transparent), .dark :where(input.bg-transparent, textarea.bg-transparent) { color: var(--ink); }
:root[data-theme="dark"] :where(input, textarea)::placeholder, .dark :where(input, textarea)::placeholder { color: var(--faint); }
/* The button inside a file input is styled by utilities for the light theme
   (file:bg-white); on the dark theme it was a white box with light text. */
:root[data-theme="dark"] input[type="file"]::file-selector-button, .dark input[type="file"]::file-selector-button { background-color: var(--surface-2); color: var(--ink); border-color: var(--line-strong); }
:root[data-theme="dark"] input[type="file"], .dark input[type="file"] { color: var(--ink-2); }
:root[data-theme="dark"] .dm-btn-secondary:hover:not(:disabled), .dark .dm-btn-secondary:hover:not(:disabled) { border-color: #465266; }
:root[data-theme="dark"] .dm-input:hover:not(:disabled):not(:focus), :root[data-theme="dark"] .dm-select:hover:not(:disabled):not(:focus), :root[data-theme="dark"] .dm-textarea:hover:not(:disabled):not(:focus) { border-color: #465266; }
:root[data-theme="dark"] * { scrollbar-color: #3a4556 transparent; }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #3a4556; background-clip: content-box; }

/* ----------------------------------------------------------------------------
 * 11. Sticky action bars
 * ----------------------------------------------------------------------------
 * On a long form the primary action was off the bottom of the screen. The bar
 * sticks to the bottom of the viewport while its form is on screen and sits in
 * the flow at the end of it; html gets matching scroll padding (section 1), so
 * a field reached with Tab is never hidden behind it.
 * -------------------------------------------------------------------------- */
.dm-sticky-actions {
  position: sticky; bottom: 0; z-index: 15;
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  margin-top: 1.25rem; padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  -webkit-backdrop-filter: saturate(140%) blur(8px); backdrop-filter: saturate(140%) blur(8px);
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 -10px 26px -20px rgb(12 18 32 / .4);
}
.dm-sticky-actions > .dm-sticky-note { flex: 1 1 14rem; min-width: 0; font-size: .8125rem; color: var(--muted); }

/* ----------------------------------------------------------------------------
 * 12. Small corrections
 * -------------------------------------------------------------------------- */
/* !important because the Tailwind Play CDN injects its utilities into the DOM
   AFTER this stylesheet, so an element carrying both `block` and this class
   would otherwise keep display:block and never clamp. */
.dm-wrap-2 {
  display: -webkit-box !important; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere;
}
/* A sorted column should say so. */
.dm-sorted { color: var(--ink); }
.dm-sorted::after { content: "↑"; margin-left: .3rem; font-size: .8em; }
.dm-sorted.is-desc::after { content: "↓"; }

@media (prefers-reduced-transparency: reduce) {
  dialog::backdrop, .dm-overlay { backdrop-filter: none; background: rgb(12 18 32 / .72); }
  .dm-sticky-actions { backdrop-filter: none; background: var(--surface); }
}
@media (forced-colors: active) {
  .dm-btn, .dm-card, .dm-input, .dm-select, .dm-textarea, .dm-menu, .dm-badge { border: 1px solid CanvasText; }
  .dm-pill::before { forced-color-adjust: none; }
  .dm-spinner { border-color: CanvasText; border-right-color: transparent; }
}
@media (prefers-contrast: more) {
  .dm-pill, .dm-badge { outline: 1px solid currentColor; }
  .dm-input, .dm-select, .dm-textarea, .dm-btn-secondary { border-color: var(--ink-2); }
}

/* ----------------------------------------------------------------------------
 * 13. The command palette
 * -------------------------------------------------------------------------- */
.dm-palette-overlay { align-items: flex-start; padding-top: 12vh; }
.dm-palette {
  width: 100%; max-width: 34rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-md); overflow: hidden;
  animation: dm-dialog-in .14s ease-out both;
}
.dm-palette-head { display: flex; align-items: center; gap: .7rem; padding: .85rem 1rem; border-bottom: 1px solid var(--line-2); color: var(--faint); }
.dm-palette-input { flex: 1; border: 0; background: none; font: inherit; font-size: 1rem; color: var(--ink); outline: none; }
.dm-palette-input::placeholder { color: var(--faint); }
.dm-kbd {
  font-family: var(--font-mono); font-size: .65rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: .35rem; padding: .15rem .4rem;
}
.dm-palette-list { max-height: min(24rem, 60vh); overflow-y: auto; padding: .35rem; }
.dm-palette-row {
  display: flex; align-items: center; gap: .75rem; width: 100%; text-align: left;
  border: 0; background: none; font: inherit; font-size: .9375rem; color: var(--ink-2);
  padding: .55rem .7rem; border-radius: .6rem; cursor: pointer;
}
.dm-palette-row > i { color: var(--faint); width: 1rem; text-align: center; flex: none; }
.dm-palette-row.is-on { background: var(--brand-wash); color: var(--ink); }
.dm-palette-row.is-on > i { color: var(--brand-fg); }
.dm-palette-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-palette-hint { font-size: .7rem; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; flex: none; }
.dm-palette-empty { padding: 1.25rem .7rem; margin: 0; color: var(--faint); font-size: .875rem; text-align: center; }

/* Breadcrumbs */
.dm-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .8125rem; color: var(--muted); margin-bottom: .6rem; }
.dm-crumbs a { color: var(--muted); text-decoration: none; }
.dm-crumbs a:hover { color: var(--ink); text-decoration: underline; }
.dm-crumbs li + li::before { content: "/"; margin-right: .4rem; color: var(--faint); }
.dm-crumbs ol { display: contents; list-style: none; margin: 0; padding: 0; }
.dm-crumbs li { display: flex; align-items: center; }

/* Field-level errors: the message belongs under the field that caused it, not
   in a bar at the top of the page. */
.dm-field-error { margin: .3rem 0 0; font-size: .78rem; color: var(--bad); }
[aria-invalid="true"] { border-color: var(--bad) !important; }
[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent) !important; }

.dm-savestate { font-size: .75rem; color: var(--muted); }
.dm-savestate.is-saving { color: var(--muted); }
.dm-savestate.is-saved { color: var(--ok); }
.dm-savestate.is-failed { color: var(--bad); font-weight: 600; }

/* ----------------------------------------------------------------------------
 * 14. Phone behaviours
 * -------------------------------------------------------------------------- */
.dm-pull {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90;
  background: var(--brand); color: var(--brand-on); text-align: center;
  font-size: .8125rem; font-weight: 600; padding: .5rem;
  transform: translateY(-100%); transition: transform .1s linear;
}
.dm-offline {
  position: fixed; left: 0; right: 0; z-index: 140;
  bottom: 0; padding: .8rem 1rem calc(.8rem + env(safe-area-inset-bottom, 0px));
  background: #92400E; color: #fff; font-size: .8125rem; line-height: 1.5;
  animation: dm-slide-up .2s ease both;
}
.dm-smallscreen {
  position: fixed; inset: 0; z-index: 150; background: var(--canvas);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .75rem; padding: 2rem 1.5rem; text-align: center; color: var(--ink-2);
}
.dm-smallscreen strong { font-family: var(--font-display); font-size: 1.125rem; color: var(--ink); }
.dm-smallscreen span { max-width: 24rem; font-size: .9375rem; }

/* A menu near the screen edge is a hit-test problem on a phone; the same markup
   becomes a bottom sheet. */
@media (max-width: 767.98px) {
  .dm-sheet {
    position: fixed !important; left: 0 !important; right: 0 !important;
    top: auto !important; bottom: 0 !important; margin: 0 !important;
    width: auto !important; max-height: 70vh; overflow-y: auto;
    border-radius: 1rem 1rem 0 0 !important;
    padding: .5rem .5rem calc(.5rem + env(safe-area-inset-bottom, 0px)) !important;
    box-shadow: 0 -12px 40px -12px rgb(12 18 32 / .35) !important;
    animation: dm-slide-up .18s ease both;
  }
  .dm-sheet > a, .dm-sheet > button, .dm-sheet form > button { min-height: 44px; display: flex; align-items: center; }
}

/* An expiry inside two days. Colour is not the only signal — the duration is
   spelled out beside the date. */
.dm-soon { color: var(--warn); font-weight: 600; }

/* Long names and addresses assumed short values and broke their containers. */
.dm-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-break { overflow-wrap: anywhere; word-break: break-word; }

/* ----------------------------------------------------------------------------
 * 15. Document content keeps its own type
 * ----------------------------------------------------------------------------
 * The interface face is the app's; what is inside a document is the author's.
 * A document rendered as HTML (a block document's preview, the signing page)
 * is wrapped in .dm-doc, which resets the interface heading rules above so its
 * headings and text keep the document's typography — the face and spacing
 * documents have always rendered in (Open Sans, loaded by partials/app-head
 * with docFont). --doc-font is there for a document that chooses its own.
 * Canvas pages, PDF pages and generated PDFs never read page CSS at all.
 * -------------------------------------------------------------------------- */
.dm-doc { font-family: var(--doc-font, "Open Sans", ui-sans-serif, system-ui, sans-serif); letter-spacing: -0.006em; }
.dm-doc :where(h1, h2, h3, h4) { font-family: inherit; letter-spacing: -0.02em; }

/* ----------------------------------------------------------------------------
 * 16. Shadows, defined once
 * -------------------------------------------------------------------------- */
.shadow-card { box-shadow: var(--shadow-sm) !important; }
.shadow-soft { box-shadow: var(--shadow) !important; }

/* A focus ring that is removed and not replaced is a keyboard user with no idea
   where they are. `focus:outline-none` appears across the views; this puts the
   ring back for anything that took it away without offering a replacement. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--brand) !important;
  outline-offset: 2px;
}
:root[data-theme="dark"] :where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { outline-color: var(--brand-text-dark) !important; }

/* Builder guides — dropped from a ruler, kept with the page. Drawn as DOM under
   the fields rather than as canvas objects: a guide should not be selectable,
   movable or exportable. */
.dm-guide { position: absolute; z-index: 6; pointer-events: auto; }
.dm-guide--v { top: 0; bottom: 0; width: 1px; background: #ec4899; cursor: col-resize; }
.dm-guide--h { left: 0; right: 0; height: 1px; background: #ec4899; cursor: row-resize; }
.dm-guide::after { content: ""; position: absolute; inset: -3px; }

/* The builder's measurement readout: where the thing being dragged actually is,
   in the unit the author chose. Guides say "aligned"; this says how far. */
.dm-measure {
  position: fixed; z-index: 120; display: none; pointer-events: none;
  background: var(--ink); color: var(--surface); font-family: var(--font-mono);
  font-size: 11px; font-variant-numeric: tabular-nums; letter-spacing: .02em;
  padding: .25rem .45rem; border-radius: .3rem; white-space: pre;
  box-shadow: 0 4px 12px -4px rgb(0 0 0 / .4);
}
/* The printable area, drawn on the page rather than left to the printer. */
.dm-margin-box {
  position: absolute; pointer-events: none; z-index: 4;
  border: 1px dashed color-mix(in srgb, var(--brand) 45%, transparent);
}
