:root {
  /* ================================================================
     BRAND PALETTE — the only four values you should need to replace.
     Everything else below derives from these automatically.
     ================================================================ */
  --palette-dominant: #6fffdc;   /* dominant color  — buttons, links, active nav/tabs */
  --palette-support-1: #0f1b2d;  /* support color 1 — body text, strong headings      */
  --palette-support-2: #46566b;  /* support color 2 — muted text, borders             */
  --palette-accent: #dce9f5;     /* accent color    — page background tint, highlights */

  /* ---- Derived neutrals (computed — no need to edit) ---- */
  --color-bg: color-mix(in srgb, var(--palette-accent) 35%, #fbfcfe);
  --color-surface: #ffffff;
  --color-border: color-mix(in srgb, var(--palette-support-2) 22%, white);
  --color-border-soft: color-mix(in srgb, var(--palette-support-2) 12%, white);
  --color-text: var(--palette-support-1);
  --color-text-muted: color-mix(in srgb, var(--palette-support-1) 58%, white);
  --color-text-faint: color-mix(in srgb, var(--palette-support-1) 38%, white);

  /* ---- Derived interactive tones (computed — no need to edit) ---- */
  --color-accent: var(--palette-dominant);
  --color-accent-strong: color-mix(in srgb, var(--palette-dominant) 80%, black);
  --color-accent-bg: color-mix(in srgb, var(--palette-dominant) 10%, white);
  --color-accent-border: color-mix(in srgb, var(--palette-dominant) 32%, white);

  /* Very light, sober tint for a cell actively being edited — deliberately
     close to EngTool's own #fffdf0, not tied to the brand palette. */
  --color-cell-editing-bg: #fffdf0;
  /* Focus border for a cell being edited — a plain, neutral blue instead of
     the brand's mint-green accent, which read as garish on a text input. */
  --color-cell-editing-border: #1a56db;

  /* ---- Grid header tones (EngTool-style: neutral gray, not accent-tinted) ---- */
  --color-th-bg: color-mix(in srgb, var(--palette-support-2) 7%, white);
  --color-th-filter-bg: color-mix(in srgb, var(--palette-support-2) 3%, white);

  --color-danger: #c0392b;
  --color-danger-bg: rgba(192, 57, 43, 0.08);
  --color-danger-border: rgba(192, 57, 43, 0.3);

  /* Non-blocking warning on a value (module field annotators): a light red
     wash, deliberately softer than the --color-danger error outline. */
  --color-warning-soft: #fdecea;

  --color-success: #1f8a5f;
  --color-success-bg: rgba(31, 138, 95, 0.08);
  --color-success-border: rgba(31, 138, 95, 0.3);

  /* ---- Dark top bar (derived from support-1) + fixed on-dark text ---- */
  --color-topbar-bg: color-mix(in srgb, var(--palette-support-1) 92%, black);
  --color-on-dark: #ffffff;
  --color-on-dark-muted: rgba(255, 255, 255, 0.68);
  --color-on-dark-border: rgba(255, 255, 255, 0.22);
  --color-on-dark-hover: rgba(255, 255, 255, 0.1);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  
  --topbar-height: 52px;
  --radius-pill: 999px;
  --radius-lg: 16px;
  --attachment-preview-width: min(560px, 92vw);
  --attachment-preview-height: min(420px, 50vh);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background-color: var(--color-bg);
  background-image:
    radial-gradient(circle at 8% 0%, color-mix(in srgb, var(--palette-accent) 55%, transparent), transparent 32rem),
    radial-gradient(circle at 100% 12%, color-mix(in srgb, var(--palette-accent) 30%, transparent), transparent 30rem);
  background-attachment: fixed;
  color: var(--color-text);
  font-family: var(--font-ui);
  font-size: 15.5px;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
/* Icon-only links (a single <i>/<svg> child) are never underlined */
a:has(> i:only-child):hover,
a:has(> svg:only-child):hover,
.grid-row__view:hover { text-decoration: none; }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

/* Decorative dot pattern — generic accent texture, not tied to any brand asset */
.dot-pattern {
  position: absolute;
  width: 160px;
  height: 130px;
  pointer-events: none;
  opacity: 0.5;
  background-image: radial-gradient(circle, var(--palette-dominant) 1.6px, transparent 1.8px);
  background-size: 16px 16px;
  -webkit-mask-image: linear-gradient(135deg, #000, transparent 78%);
  mask-image: linear-gradient(135deg, #000, transparent 78%);
}

/* Top bar */

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  background-color: var(--color-topbar-bg);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 6px 20px rgba(0, 0, 0, 0.08);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 17.5px;
  text-decoration: none;
  color: var(--color-on-dark);
  flex-shrink: 0;
}

.topbar__brand:hover .topbar__brand-name { text-decoration: underline; }

.topbar__logo {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--color-accent);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 14.5px; font-weight: 700;
  overflow: hidden;
}
.topbar__logo img { width: 100%; height: 100%; object-fit: contain; display: block; }

.topbar__version { font-family: var(--font-mono); font-size: 12px; color: var(--color-on-dark-muted); }

.topbar__nav { display: flex; align-items: center; gap: 2px; height: 100%; }

.topbar__link {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 14px;
  color: var(--color-on-dark-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 15px;
  border-bottom: 2px solid transparent;
}

.topbar__link:hover { color: var(--color-on-dark); background-color: var(--color-on-dark-hover); }
.topbar__link.is-active { color: var(--color-on-dark); border-color: var(--palette-dominant); }

.topbar__right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.topbar__link--help { gap: 6px; }
.topbar__help-icon { width: 15px; height: 15px; flex-shrink: 0; color: currentColor; }

/* Project switcher + module nav wrapper (topbar.html): transparent to the
   topbar's own flex layout on desktop — its children lay out exactly as if
   it weren't there. It only becomes a real box (the burger menu's drawer)
   in the Responsive section at the end of this file, which is also where
   the burger button and the drawer-only Help link are shown. */
.topbar__drawer { display: contents; }
.topbar__menu-toggle, .topbar__link--drawer-only { display: none; }

.dropdown { position: relative; }
.dropdown__toggle {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px 6px 6px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-on-dark-border);
  background-color: transparent;
  color: var(--color-on-dark);
  font-family: var(--font-ui);
  font-weight: 400;
  font-size: 14.5px;
  cursor: pointer;
}
.dropdown__toggle:hover { background-color: var(--color-on-dark-hover); }
.dropdown__caret { flex-shrink: 0; font-size: 11px; line-height: 1; }

.dropdown--project .dropdown__toggle { width: 140px; }
.dropdown--project .dropdown__toggle-label {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown__user-name { padding: 8px 10px 0; font-size: 14.5px; font-weight: 600; color: var(--color-text); }
.dropdown__role { padding: 2px 10px 8px; font-size: 14.5px; }
.dropdown__menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 200px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(20, 30, 50, 0.12);
  padding: 6px;
  z-index: 30;
}
.dropdown.is-open .dropdown__menu { display: block; }
.dropdown__item, .dropdown__link {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: none;
  background: none;
  text-align: left;
  color: var(--color-text);
  text-decoration: none;
  font-size: 14.5px;
  font-family: var(--font-ui);
  cursor: pointer;
}
.dropdown__item:hover, .dropdown__link:hover { background-color: var(--color-bg); }
.dropdown__label { padding: 6px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-faint); }
.dropdown__divider { height: 1px; background: var(--color-border-soft); margin: 6px 2px; }

.avatar-circle {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--color-accent);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}

.btn--onDark {
  border-color: var(--color-on-dark-border);
  background-color: transparent;
  color: var(--color-on-dark);
}
.btn--onDark:hover { background-color: var(--color-on-dark-hover); }

#content { flex: 1; padding: 28px 20px; max-width: 1800px; width: 100%; margin: 0 auto; position: relative; z-index: 1; }
#content.content--wide {
  max-width: none;
  display: flex;
  flex: 0 0 auto; /* override the base rule's `flex:1` (flex-basis:0), which
    would otherwise ignore the explicit height below and let content grow
    app-shell past one viewport instead of scrolling internally */
  flex-direction: column;
  min-height: 0;
  height: calc(100vh - var(--topbar-height));
}

/* Flash message on the standalone login page (not part of the app shell,
   so it isn't routed through the global notification stack below). */

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 15px;
  border: 1px solid var(--color-border);
}
.flash--success { background-color: var(--color-success-bg); border-color: var(--color-success-border); color: var(--color-success); }
.flash--error { background-color: var(--color-danger-bg); border-color: var(--color-danger-border); color: var(--color-danger); }

/* Global notification stack — every flash/status message in the app (create,
   delete, update, errors...) renders here as an overlay, centered under the
   topbar, so it never shifts surrounding layout. Auto-dismisses after 30s or
   on click; see notifications.js. */

.notification-stack {
  position: fixed;
  top: calc(var(--topbar-height) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: min(560px, calc(100vw - 32px));
  pointer-events: none;
}
.notification {
  pointer-events: auto;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14.5px;
  border: 1px solid var(--color-border);
  background-color: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15);
  max-width: 100%;
  opacity: 1;
  transform: translateY(0);
  transition: opacity .2s ease, transform .2s ease;
}
.notification--leaving { opacity: 0; transform: translateY(-6px); }
.notification--success { background-color: color-mix(in srgb, var(--color-success) 12%, var(--color-surface)); border-color: var(--color-success-border); color: var(--color-success); }
.notification--error { background-color: color-mix(in srgb, var(--color-danger) 12%, var(--color-surface)); border-color: var(--color-danger-border); color: var(--color-danger); }
.notification--warning { background-color: var(--color-warning-soft); border-color: var(--color-danger-border); color: var(--color-text); }

/* Page header */

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 24px;
}
.page-header__title { margin: 0; font-size: 22px; font-weight: 700; }
.page-header__title-icon { margin-right: 10px; color: var(--color-text-faint); font-size: 0.85em; }
.page-header__subtitle { margin: 4px 0 0; font-family: var(--font-ui); font-size: 14.5px; color: var(--color-text-muted); }
.page-header__actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-header__actions form { margin: 0; }

/* Tabs (in-page secondary navigation, e.g. Export) */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--color-border); margin-bottom: 20px; }
.tabs__link {
  display: inline-flex; align-items: center;
  padding: 10px 14px; margin-bottom: -1px;
  font-family: var(--font-ui); font-size: 14.5px; font-weight: 600;
  color: var(--color-text-muted);
  background: none; border: none; border-bottom: 2px solid transparent;
  text-decoration: none; cursor: pointer;
}
.tabs__link:hover { color: var(--color-text); }
.tabs__link.is-active { color: var(--color-accent-strong); border-color: var(--palette-dominant); }
.tabs__count {
  margin-left: 6px; padding: 1px 7px; border-radius: 10px;
  font-size: 12px; font-weight: 600; color: var(--color-text-muted); background: var(--color-bg);
}
/* Panels of an item's detail page shown as tabs (js/detail_tabs.js). The fields get a readable width. */
.detail-tabpanel[hidden] { display: none; }
.detail-tabpanel--info { max-width: 960px; }

/* Buttons */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background-color: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}
.btn:hover { background-color: var(--color-bg); transform: translateY(-1px); }
.btn--accent { background-color: var(--color-accent); border-color: var(--color-accent); color: var(--color-text); box-shadow: 0 6px 16px color-mix(in srgb, var(--color-accent) 35%, transparent); }
.btn--accent:hover { background-color: var(--color-accent-strong); color: white; }
.btn--danger { background-color: var(--color-danger-bg); border-color: var(--color-danger-border); color: var(--color-danger); }
.btn--danger:hover { background-color: var(--color-danger-border); }
.btn--sm { padding: 5px 10px; font-size: 13px; }
.btn--icon { padding: 6px; width: 30px; height: 30px; gap: 0; justify-content: center; }
.btn--icon:hover { transform: none; }
.btn--icon.btn--sm { width: 26px; height: 26px; padding: 4px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
/* Mobile-only .btn toggles for the sidebars and the grids' filter row (see
   the Responsive section at the end of this file). Must come after .btn's
   own display: inline-flex above, which has the same specificity. */
.sidebar-toggle, .grid-filter-toggle { display: none; }

/* Cards / sections */

.card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.detail-section { margin-bottom: 24px; }
.detail-section__title { margin: 0 0 12px; font-size: 16.5px; font-weight: 700; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.detail-grid__item { display: flex; flex-direction: column; gap: 4px; }
.detail-grid__label { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--color-text-faint); }
.detail-grid__value { font-size: 15px; word-break: break-word; }

/* Folder/item detail pages: a property list (+ its related-rows table, for
   folders) on the left, attachments on the right. */
.detail-columns { display: flex; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
/* flex-grow: 0 (rather than 2) keeps the left column from ballooning with
   whatever horizontal space the page happens to have (extra space goes to
   the side column/attachments instead) — but min-width pins it at a fixed
   680px (roughly double its old 340px basis) rather than letting it also
   shrink away to nothing, so its own tables (property list, related rows)
   have enough room for a label and a value without wrapping/scrolling. */
.detail-columns__main { flex: 0 1 340px; min-width: 680px; }
/* 712px = the attachments table's minimum width (see .att-col--* below):
   the side column wraps under the main one as soon as the table no longer
   fits beside it, rather than showing a horizontal scrollbar first. */
.detail-columns__side { flex: 1 1 712px; min-width: 0; }
/* The left column's tables (key->value properties, related rows) hug their
   own content by default (.table-wrap's width: fit-content) — stretch them
   to the full column width instead, so the two columns read as evenly
   sized, adjacent panels rather than a narrow table floating in a wide gap
   before the attachments column starts. */
.detail-columns__main .table-wrap { width: 100%; }
.detail-columns__main .table-wrap .table { width: 100%; }
/* Shorter rows than the /database grid's own (which needs room for its
   filter inputs) — these are plain key->value/related-row tables. */
.detail-columns .table th, .detail-columns .table td { padding: 6px 14px; }

/* Forms */

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.form-field { display: flex; flex-direction: column; gap: 6px; font-size: 14.5px; color: var(--color-text-muted); margin-bottom: 14px; }
.form-field input, .form-field select, .form-field textarea {
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--color-border);
  background-color: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-ui);
  font-size: 14.5px;
}
.form-field textarea { resize: vertical; }
/* Two side-by-side form columns (views/form.html) — stacked on mobile. */
.form-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.checkbox-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; border: 1px solid var(--color-border); border-radius: 8px; padding: 10px; }
.checkbox-list label { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }

/* Tables / grid */

.table-wrap { border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface); width: fit-content; }
.table { border-collapse: collapse; font-size: 14.5px; }
/* Fixed layout so a column's width (drag-resized or saved) is authoritative
   instead of a mere hint the browser overrides to fit the widest cell — this
   is what lets a column shrink past its content's natural width, with the
   overflowing text ellipsized below rather than forcing the column back
   open. The tiny explicit `width` alongside it matters just as much: inside
   a `width: fit-content` .table-wrap (kept, so an unresized grid still hugs
   its own content instead of stretching edge-to-edge), a fixed-layout table
   left at `width: auto` has Chrome fall back to measuring every column by
   its content again, silently undoing per-column widths. Any definite
   length breaks that — the table still renders at the sum of its column
   widths (a fixed table is never *narrower* than that), so the actual value
   here is arbitrary. grid.js locks every not-yet-resized column to its
   rendered width on load, so this doesn't otherwise change how a grid looks. */
.table.js-grid { table-layout: fixed; width: 1px; }
/* Key->value property tables (grid.property_table): fixed layout so the
   label column's width is authoritative rather than each table auto-sizing
   to its own longest label — the same fixed-layout/ellipsis trick as
   .js-grid above, just for these detail-page tables so e.g. items/detail's
   "custom attributes" table lines up with its fields table right above it. */
/* Attachments list (items/folders detail pages): same fixed-layout/width:1px
   trick as .js-grid above, so double-clicking a cell into edit mode (e.g.
   the Type column's fk <select>) never changes any column's width — with
   table-layout left at the default `auto`, that edit-mode swap was enough
   of a content change for the browser to re-measure and reflow every
   column, not just the one being edited. */
.table--fixed-cols { table-layout: fixed; width: 1px; }
/* Related-rows table (folders/detail.html's Equipments list): percentage
   column widths (set on the <th>s in the template) only take effect under
   table-layout: fixed — left at the default auto, a long cell (e.g. "Actuated
   ON/OFF valve") makes the browser ignore them and grow the table past its
   100%-width .table-wrap instead, forcing a horizontal scrollbar whose
   sticky, corner-radiused last <th> then visibly detaches from the card
   around it once scrolled. Fixed layout keeps the table at the wrap's own
   width and lets the already-global .table td ellipsis (below) truncate
   an oversized value instead. */
.table--related { table-layout: fixed; }
.table--kv { table-layout: fixed; }
.table--kv th[scope="row"] {
  width: 195px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.table th, .table td { padding: 10px 14px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--color-border-soft); }
/* Truncate with "…" instead of overflowing into the next cell once a column
   is narrower than its content. Deliberately not on the <th> itself — its
   .grid-resizer child sits partly outside the header's own box so it stays
   grabbable even on a column resized down to nothing, and clipping the
   header would clip that handle along with it; .grid-th (below) clips the
   header's own label/filter instead, at the same effective boundary. */
.table td { overflow: hidden; text-overflow: ellipsis; }
/* Icon-only cells (e.g. attachments' leading download link) never hold text
   to truncate — a fixed-width column just barely narrower than the icon's
   own box would otherwise render a stray ellipsis mark next to it. */
.table td.table__icon-cell { overflow: visible; text-overflow: clip; }
/* z-index needed on top of `position: sticky` — without it, table cell
   background/content painting keeps thead behind tbody as the grid scrolls,
   so scrolled-under rows show through the header instead of staying hidden
   beneath it. */
.table thead th { color: var(--color-text-muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; background: var(--color-bg); position: sticky; top: 0; z-index: 1; }
/* .table-wrap can't just clip its corners with `overflow: hidden` — that
   would also make it the sticky header's scrolling ancestor instead of
   .table-scroll, breaking "stays pinned while the body scrolls". So round
   the header cells themselves to match .table-wrap's own 8px radius. */
.table thead tr:first-child th:first-child { border-top-left-radius: 8px; }
.table thead tr:first-child th:last-child { border-top-right-radius: 8px; }
.table tbody tr:hover { background-color: var(--color-bg); }
.table__actions { display: flex; gap: 6px; }

.grid-th { display: flex; flex-direction: column; gap: 0; cursor: grab; overflow: hidden; }
/* Two visually separated zones per column, EngTool-style: a label+sort row
   with its own bottom border, and a filter row with a slightly different
   background — instead of the two being one loosely-gapped flex stack. */
.grid-th__sort {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  cursor: pointer; user-select: none; text-decoration: none; color: inherit;
  padding: 8px 10px;
  border-bottom: 1px solid var(--color-border-soft);
}
.grid-th__label { overflow: hidden; text-overflow: ellipsis; }
.grid-th__required { color: var(--color-danger); font-weight: 600; }
.grid-th__sort-icon { flex: 0 0 auto; color: var(--color-text-faint); font-size: .85em; }
.grid-th__actions { display: flex; align-items: center; gap: 4px; padding: 4px 6px; background: var(--color-th-filter-bg); }
/* Icon/delete column headers carry no sort link or filter — an empty
   .grid-th shell just to pick up the same two-tone sort/filter row
   background split as the real columns, so the header row reads as one
   continuous band edge-to-edge instead of a flat block at each end. */
.grid-th--blank { cursor: default; }
.grid-th--blank .grid-th__sort { cursor: default; }
.grid-th__filter { flex: 1 1 auto; min-width: 0; padding: 4px 6px; font-size: 12.5px; border-radius: 3px; border: 1px solid var(--color-border-soft); background: var(--color-surface); font-weight: 400; text-transform: none; letter-spacing: 0; }
.grid-th__filter:disabled { background-color: var(--color-bg); color: var(--color-text-faint); font-style: italic; }
.grid-th__icon-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 11.5px;
  cursor: pointer;
}
.grid-th__icon-btn:hover { background: var(--color-bg); color: var(--color-text); }
.grid-th__icon-btn.is-active { background: var(--color-accent-strong); border-color: var(--color-accent-strong); color: white; }
th[data-col].is-dragging-col { opacity: .4; }
/* Editable-cell look — EngTool-style: perfectly flat at rest (no border), a
   very sober hover cue, and a pale-yellow tint with a plain blue border while
   a cell is actually being edited. The cell (td) itself carries no padding —
   the display span and the edit input each carry the *same* padding instead,
   so at-rest and editing produce a pixel-identical box with no dependency on
   percentage-height table quirks. The editing border is an inset box-shadow
   rather than a real border so it doesn't consume any extra box space. */
/* One explicit font declaration for every grid cell's content, regardless of
   column kind (text, number, date, fk, list, boolean) — instead of relying
   on inheritance through .table/.db-editor, which is easy to accidentally
   diverge from at some other level. This is the single source of truth for
   grid cell typography, in both tables and views. */
.grid-cell, .grid-cell__display, .grid-cell.is-editing > input, .grid-cell.is-editing > select {
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 400;
}
.grid-cell { position: relative; cursor: pointer; padding: 0; }
.grid-cell__display { display: block; padding: 4px 10px; }
.grid-cell[data-editable="true"]:hover { box-shadow: inset 0 0 0 1px var(--color-border-soft, var(--color-border)); }
/* Non-editable cells keep the same background as any other cell — only the
   text is dimmed a notch (same tone as muted labels elsewhere) so a glance
   at the column tells you it can't be changed, without reading like a
   disabled/greyed-out control. */
.grid-cell[data-editable="false"] .grid-cell__display { color: var(--color-text-muted); }
/* A cell's optional "view details" icon-link (property_value_cell's
   cell.link_url — e.g. items/detail's Unit field linking to the folder)
   floats over the right edge, vertically centered, instead of taking up
   flow width — .grid-cell is already `position: relative` for this. Kept
   outside .grid-cell__display so grid.js's edit-mode swap never touches it;
   the reserved right padding on the display span stops long values from
   running under it. */
.grid-cell--linked .grid-cell__display { padding-right: 28px; }
.grid-cell__link {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  z-index: 1;
}
.grid-cell.is-editing { background: var(--color-cell-editing-bg); }
/* Scoped to a *direct* child of an editing cell — not just any ".grid-cell
   input" — so this never leaks onto the boolean checkbox, which lives one
   level deeper inside .grid-cell__display and is never part of this
   edit-mode swap (see the boolean rules below: no border, no editing tint,
   ever — it isn't "being edited", every click just toggles it). */
.grid-cell.is-editing > input, .grid-cell.is-editing > select {
  display: block;
  box-sizing: border-box;
  width: 100%;
  margin: 0;
  padding: 4px 10px;
  border: 0;
  box-shadow: inset 0 0 0 1.5px var(--color-cell-editing-border);
  border-radius: 2px;
  background: var(--color-cell-editing-bg);
  font: inherit;
  color: inherit;
  outline: none;
}
/* A native <select>'s box is ~1-2px taller than a same-padding <input> even
   with identical font/line-height/appearance — Chromium and Firefox both
   bake extra height into the control for its arrow chrome, and neither
   line-height nor appearance:none changes it. Left alone, that nudges the
   whole row 1px taller for the moment an fk/role/value_type cell is being
   edited, then back down on blur. Pin the height explicitly so it matches
   the input's (and the at-rest display span's) natural height instead. */
.grid-cell.is-editing > select { height: 25px; }
/* Boolean cells: the checkbox IS the cell, always — no double-click, no
   edit mode, no border/outline/tint of any kind; every click toggles and
   saves immediately (grid.js). A genuine third, indeterminate state covers
   "no value yet" on an EAV attribute column (grayed dash, not blue, so it
   never reads as a third kind of "checked"). */
.grid-cell[data-kind="boolean"] { text-align: center; }
.grid-cell[data-kind="count"] { text-align: center; cursor: default; }
.grid-cell__count-link { color: var(--color-text); text-decoration: none; cursor: pointer; }
/* "url" attribute values: the label is a link opening in a new tab. Body
   text color with a mint underline (the dominant mint alone is unreadable
   on white) and a trailing external-link icon. */
.grid-cell__url {
  color: var(--color-text);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--palette-dominant) 75%, black);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  cursor: pointer;
}
.grid-cell__url:hover { text-decoration-color: var(--color-text); }
.grid-cell__url-icon { margin-left: 4px; font-size: 0.85em; color: var(--color-text-muted); }
.grid-cell__count-link:hover { text-decoration: underline; }
.grid-cell__display input[type="checkbox"] {
  display: inline-block;
  width: 16px;
  height: 16px;
  vertical-align: middle;
  margin: 0;
  cursor: pointer;
  outline: none;
}
.grid-cell__display input[type="checkbox"]:indeterminate { accent-color: var(--color-text-faint); }
.grid-cell--error { outline: 2px solid var(--color-danger); }
/* Stays visible while editing too (beats .grid-cell.is-editing's own tint),
   so a module's live check shows up as the user types. */
.grid-cell--warning,
.grid-cell.is-editing.grid-cell--warning,
.grid-cell.is-editing.grid-cell--warning > input { background: var(--color-warning-soft); }
/* Same tint for a form input a module flags live (data-hint fields). */
input.input--warning { background: var(--color-warning-soft); }
.grid-cell--nowrite { cursor: not-allowed; }

/* Banner of an instance's alert rules (grids and detail pages). */
.alert-banner {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 0 0 12px; padding: 10px 14px;
  border: 1px solid var(--color-danger-border); border-radius: 8px;
  background: var(--color-warning-soft); color: var(--color-text);
}
.alert-banner__icon { margin-top: 3px; color: var(--color-danger); }
.alert-banner__list { margin: 2px 0 0; padding-left: 18px; }

/* Inline autocomplete for "text" cells — the other values already used in
   that column, filtered as you type; picking one is a shortcut, not a
   requirement (see grid.js attachSuggestions). Positioned with `fixed` +
   getBoundingClientRect (left/top/width set inline by JS) rather than
   `absolute` off the cell, so it isn't clipped by the grid's own scroll
   containers (.table-wrap/.table-scroll both use overflow: auto). */
.cell-suggestions {
  position: fixed;
  z-index: 40;
  margin: 1px 0 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
  list-style: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border-soft);
  border-radius: 4px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .15);
  font-size: 13px;
  font-family: var(--font-ui);
}
.cell-suggestions li { padding: 7px 12px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-suggestions li:hover, .cell-suggestions li.is-active { background: var(--color-bg); }
.grid-resizer { position: absolute; right: -4px; top: 0; bottom: 0; width: 11px; cursor: col-resize; z-index: 1; }
/* Hover relies on the cursor change alone (no bar) — only an active drag
   gets a thin centered line, so the feedback stays sober instead of a wide
   dark-gray band across the whole hit-area. */
.grid-resizer.is-dragging {
  background: linear-gradient(to right, transparent calc(50% - 1px), var(--palette-support-2) calc(50% - 1px), var(--palette-support-2) calc(50% + 1px), transparent calc(50% + 1px));
}
/* The last data column has no next column to share the handle's usual
   straddle of the border, so its normal 7px right-side bleed would poke past
   the table's own edge — just enough overflow to force a horizontal
   scrollbar even when every column otherwise fits the available width. Keep
   that one handle flush with (not past) the table's right edge instead. */
th[data-col]:not(:has(~ th[data-col])) .grid-resizer { right: 0; width: 7px; }
/* Row action icons (view details, delete) — sized by their own icon glyph
   plus a small hit-area padding, not a fixed box, so they never force the
   row taller than the text/edit cells next to them. Plain at rest, no
   pill/circle background (that's what .btn--icon is for elsewhere, not a
   dense grid row) — just a sober rounded-square tint on hover. */
.grid-row__delete, .grid-row__view, .grid-row__merge, .grid-row__edit {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px;
  border: 0; border-radius: 4px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}
.grid-row__delete:hover { background: var(--color-danger-bg); color: var(--color-danger); }
.grid-row__view:hover { background: var(--color-bg); color: var(--color-text); }
.grid-row__merge:hover { background: var(--color-accent-bg); color: var(--color-accent-strong); }
.grid-row__edit:hover { background: var(--color-bg); color: var(--color-accent-strong); }
/* Groups the trailing per-row icon buttons (Merge, Delete) into one cell
   instead of a dedicated column each — same idea as .toolbar__group, just
   tighter, since it sits inside a dense grid row. */
.row-actions { display: inline-flex; align-items: center; gap: 2px; }
.grid-th__sort-idle { opacity: .35; font-size: .85em; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar__group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pagination { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 14.5px; color: var(--color-text-muted); }
.pagination select { padding: 4px 6px; border-radius: 6px; border: 1px solid var(--color-border); }

/* Badges */

.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; border: 1px solid transparent; }
.badge--accent { background-color: var(--color-accent-bg); border-color: var(--color-accent-border); color: var(--color-accent-strong); }
.badge--muted { background-color: var(--color-bg); border-color: var(--color-border); color: var(--color-text-muted); }
.badge--admin { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.badge--editor { background: #dbeafe; color: #1e3a8a; border-color: #bfdbfe; }
.badge--viewer { background: var(--color-bg); color: var(--color-text-muted); border-color: var(--color-border); }

/* Stat tiles */

.stat-tiles { display: flex; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
/* Forces every tile onto one row (Core/Attachments/Autom together on the
   dashboard) instead of wrapping — tiles shrink to fit instead. */
.stat-tiles--compact { flex-wrap: nowrap; gap: 10px; overflow-x: auto; }
.stat-tiles--compact .stat-tile { min-width: 96px; padding: 12px 12px 10px; }
.stat-tile {
  flex: 1; min-width: 150px; padding: 18px 18px 16px;
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  border-bottom: 3px solid var(--palette-dominant);
  transition: transform 140ms ease, box-shadow 140ms ease;
}
.stat-tile:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08); }
a.stat-tile { display: block; color: inherit; text-decoration: none; }
.stat-tile:nth-child(2) { border-bottom-color: var(--palette-support-2); }
.stat-tile:nth-child(3) { border-bottom-color: color-mix(in srgb, var(--palette-accent) 70%, var(--palette-dominant)); }
.stat-tile:nth-child(4) { border-bottom-color: var(--palette-support-1); }
.stat-tile__label { margin: 0 0 6px; font-size: 11.5px; color: var(--color-text-muted); }
.stat-tile__value { margin: 0; font-size: 24px; font-weight: 700; }

/* Dashboard history chart — hand-rolled inline SVG (no charting library in
   this codebase), driven by static/js/dashboard-chart.js. */
.dashboard-chart {
  position: relative;
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 8px;
}
.dashboard-chart__svg { width: 100%; height: auto; display: block; }
.dashboard-chart__empty { padding: 32px 20px; text-align: center; color: var(--color-text-muted); }
.dashboard-chart__crosshair { stroke: var(--color-text-faint); stroke-width: 1; stroke-dasharray: 4 3; opacity: 0; }
.dashboard-chart__point { opacity: 0; }
.dashboard-chart__tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  padding: 8px 12px;
  font-size: 12.5px;
  line-height: 1.6;
  white-space: nowrap;
}
.dashboard-chart__tooltip-date { color: var(--color-text-faint); font-size: 11px; margin-bottom: 2px; }
.dashboard-chart__tooltip-row { display: flex; align-items: center; gap: 6px; }
.dashboard-chart__tooltip-swatch { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dashboard-chart__legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; margin-bottom: 24px; }
.dashboard-chart__legend-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--color-text-muted); }
.dashboard-chart__legend-swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* Side-nav layout (_side_layout.html) — left sidebar + panel, at the app's
   normal spacious density for plain forms and prose. Shared by every
   /settings/* and /help/* page. Under /settings this includes the
   Users/Groups/Projects admin grids — those
   embed the exact same generic grid partial database/_grid_panel.html
   renders under /database (see admin_table.html), and the "Grid density"
   rule below (scoped to .db-panel, that partial's own wrapper, rather than
   .db-editor) makes sure the grid itself looks identical in both places;
   only the surrounding shell (sidebar width, page padding) differs. */

.side-layout { display: flex; width: 100%; gap: 20px; align-items: flex-start; }

.side-nav {
  flex: 0 0 var(--sidebar-width, 264px);
  min-width: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 10px;
  /* Stays put while the page scrolls (same rule as .db-sidebar). */
  position: sticky;
  top: calc(var(--topbar-height) + 12px);
  max-height: calc(100vh - var(--topbar-height) - 24px);
  overflow-y: auto;
  align-self: flex-start;
}
.side-nav__group-label { padding: 14px 10px 4px 2px; font-size: 12px; text-transform: uppercase; color: var(--color-text-faint); letter-spacing: .03em; }
.side-nav__link { display: block; padding: 8px 10px; border-radius: 7px; text-decoration: none; color: var(--color-text-muted); font-size: 14.5px; font-weight: 400; }
.side-nav__link:hover { background-color: var(--color-bg); }
.side-nav__link.is-active { background-color: var(--color-accent-bg); color: var(--color-accent-strong); font-weight: 600; }
.side-nav__link--sub { padding-left: 20px; }

.side-layout__panel { flex: 1 1 auto; min-width: 0; }

/* Sidebar layout (Database screen) — fixed-width sidebar + panel, each
   scrolling independently, instead of the whole page scrolling together. */

.db-editor { display: flex; width: 100%; gap: 20px; align-items: stretch; flex: 1 1 auto; min-height: 0; }

.db-sidebar {
  flex: 0 0 var(--sidebar-width, 264px);
  min-width: 0;
  /* Flush to the topbar, the window's left edge, and the window's bottom —
     EngTool-style: cancel #content's own padding on all three sides with a
     negative margin, then restore the left inset as padding so the links
     still line up with the page title above. */
  margin: -28px 0 -28px -20px;
  background: var(--color-surface);
  border: none;
  border-right: 1px solid var(--color-border);
  padding: 10px 10px 10px 20px;
  overflow-y: auto;
  /* Stays put while the page on the right scrolls: pinned under the topbar
     and exactly one viewport tall (inside .content--wide the shell already
     has that height, so this changes nothing there). */
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  align-self: flex-start;
}
/* Split variant (database/_sidebar.html): the tree scrolls; the
   Configuration block stays anchored at the bottom. */
.db-sidebar--split { display: flex; flex-direction: column; overflow: hidden; }
.db-sidebar__main { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.db-sidebar__bottom { flex: 0 0 auto; border-top: 1px solid var(--color-border-soft); padding-top: 2px; }
.db-sidebar__bottom .db-sidebar__group-label { margin-top: 6px; }
.db-sidebar__group-label { margin-top: 14px; padding: 8px 10px 4px 2px; font-size: 11px; text-transform: uppercase; color: var(--color-text-faint); letter-spacing: .03em; display: flex; align-items: center; justify-content: space-between; }
.db-sidebar__group-label-link { color: inherit; text-decoration: none; }
.db-sidebar__group-label-link:hover { text-decoration: underline; }
.db-sidebar__group-label--module { border-top: 1px solid var(--color-border-soft); margin-top: 18px; padding-top: 14px; }
.db-sidebar__link { display: block; padding: 7px 10px; border-radius: 7px; text-decoration: none; color: var(--color-text-muted); font-size: 14.5px; font-weight: 400; }
.db-sidebar__link:hover { background-color: var(--color-bg); }
.db-sidebar__link.is-active { background-color: var(--color-accent-bg); color: var(--color-accent-strong); font-weight: 600; }
.db-sidebar__link.db-sidebar__link--nested, .db-sidebar__link.db-sidebar__link--nested-2 { position: relative; }
.db-sidebar__link.db-sidebar__link--nested { padding-left: 20px; }
.db-sidebar__link.db-sidebar__link--nested-2 { padding-left: 30px; }
.db-sidebar__link-icon { display: inline-block; width: 14px; margin-right: 7px; text-align: center; font-size: 12px; color: var(--color-text-faint); }
.db-sidebar__link--nested .db-sidebar__link-icon, .db-sidebar__link--nested-2 .db-sidebar__link-icon { margin-left: 5px; }
.db-sidebar__link--view { display: flex; align-items: center; justify-content: space-between; padding-left: 14px; gap: 4px; }
.db-sidebar__link--view .db-sidebar__link-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-sidebar__add-icon, .db-sidebar__edit-icon {
  width: 20px; height: 20px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; border-radius: 4px; color: var(--color-text-faint);
  text-decoration: none;
}
.db-sidebar__add-icon:hover, .db-sidebar__edit-icon:hover { background: var(--color-bg); color: var(--color-accent-strong); }

/* View switcher above the folder tree (database/_sidebar.html): dropdown +
   "new" and "edit" icons, separated from the tree by a line. */
.view-switcher { display: flex; align-items: center; gap: 4px; padding-bottom: 10px; margin-bottom: 8px; border-bottom: 1px solid var(--color-border-soft); }
.view-switcher__dropdown { position: relative; flex: 1 1 auto; min-width: 0; }
.view-switcher__button {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 6px 8px; border: 1px solid var(--color-border); border-radius: 7px;
  background: var(--color-surface); color: var(--color-text-muted);
  font: inherit; font-size: 14.5px; font-weight: 400; text-align: left; cursor: pointer;
}
.view-switcher__button:hover { background-color: var(--color-bg); }
.view-switcher__current { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-switcher__placeholder { color: var(--color-text-faint); }
.view-switcher__chevron { flex: 0 0 auto; font-size: 10px; color: var(--color-text-faint); }
.view-switcher__menu {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 60vh; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 7px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .12);
}
.view-switcher__menu[hidden] { display: none; }
.view-switcher__option {
  display: block; padding: 7px 10px; border-radius: 7px; text-decoration: none;
  color: var(--color-text-muted); font-size: 14.5px; font-weight: 400;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.view-switcher__option:hover { background-color: var(--color-bg); }
.view-switcher__option.is-selected { background-color: var(--color-accent-bg); color: var(--color-accent-strong); font-weight: 600; }
.view-switcher__separator { margin: 4px 2px; border-top: 1px solid var(--color-border-soft); }

/* Sidebar folder tree (database/_folder_tree.html, js/folder_tree.js) —
   file-explorer style: chevron + folder icon + name, one row per folder,
   indented by depth, children shown only while their parent is open. */
/* Pulled into the sidebar's left padding so deep folders keep room for their name. */
.folder-tree { margin: 0 0 4px -14px; padding-bottom: 8px; }
/* Separator under the tree; inset by the tree's negative left margin so it
   spans the sidebar's content width like the other group separators. */
.folder-tree::after { content: ""; display: block; margin: 8px 0 0 14px; border-bottom: 1px solid var(--color-border-soft); }
.folder-tree__list, .folder-tree__children { list-style: none; margin: 0; padding: 0; }
.folder-tree__children { display: none; }
.folder-tree__item.is-open > .folder-tree__children { display: block; }
.folder-tree__row {
  display: flex; align-items: center; gap: 2px;
  padding: 1px 6px 1px calc(var(--depth, 0) * 12px);
  border-radius: 7px; color: var(--color-text-muted);
  user-select: none;
}
.folder-tree__row:hover { background-color: var(--color-bg); }
.folder-tree__row.is-active { background-color: var(--color-accent-bg); color: var(--color-accent-strong); font-weight: 600; }
.folder-tree__row.is-context { box-shadow: inset 0 0 0 1px var(--color-border); }
.folder-tree__row.is-dragging { opacity: .45; }
.folder-tree__row.is-drop-target { background-color: var(--color-accent-bg); box-shadow: inset 0 0 0 1px var(--color-accent-border); }
.folder-tree__toggle {
  flex: 0 0 18px; width: 18px; height: 18px; padding: 0; border: none; background: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--color-text-faint); font-size: 10px; cursor: pointer; border-radius: 4px;
}
.folder-tree__toggle--leaf { cursor: default; }
button.folder-tree__toggle:hover { color: var(--color-text); }
.folder-tree__toggle i { transition: transform .12s ease; }
.folder-tree__item.is-open > .folder-tree__row .folder-tree__toggle i { transform: rotate(90deg); }
.folder-tree__link {
  flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 7px;
  padding: 2px 2px; color: inherit; text-decoration: none; font-size: 13px;
}
/* The global a:hover underline would also run under the icon — keep it on the label only. */
.folder-tree__link:hover { text-decoration: none; }
.folder-tree__link:hover .folder-tree__label { text-decoration: underline; }
.folder-tree__icon { flex: 0 0 auto; width: 16px; text-align: center; font-size: 13px; color: var(--color-text-faint); }
.folder-tree__row.is-active .folder-tree__icon { color: var(--color-accent-strong); }
.folder-tree__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }


/* Item rows selected for a drag onto a tree folder (js/item_rows.js). */
.table tbody tr.js-item-row.is-selected,
.table tbody tr.js-item-row.is-selected:hover { background-color: var(--color-accent-bg); box-shadow: inset 3px 0 0 var(--color-accent-strong); }
.table tbody tr.js-item-row[draggable="true"] { cursor: grab; }
body.is-dragging-items .table tbody tr.js-item-row.is-selected { opacity: .5; }

/* The small card following the pointer while dragging items. */
.item-drag-card {
  position: fixed; top: -1000px; left: -1000px; z-index: -1;
  min-width: 150px; max-width: 240px; padding: 6px 8px;
  background: var(--color-surface); border: 1px solid var(--color-accent-border); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(15, 27, 45, .16);
  font: 13px var(--font-ui); color: var(--color-text);
}
.item-drag-card__head { font-weight: 600; color: var(--color-accent-strong); margin-bottom: 4px; }
.item-drag-card__head i { margin-right: 4px; }
.item-drag-card__row { padding: 2px 0; border-top: 1px solid var(--color-border-soft); font-family: var(--font-mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-drag-card__more { padding-top: 3px; color: var(--color-text-faint); font-size: 12px; }

/* Right-click context menu (folder tree). */
.context-menu {
  position: fixed; z-index: 1000; min-width: 180px; padding: 4px;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 27, 45, .14);
}
.context-menu[hidden] { display: none; }
.context-menu__item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 10px; border: none; background: none; border-radius: 5px;
  font: inherit; font-size: 13.5px; color: var(--color-text); text-align: left; cursor: pointer;
}
.context-menu__item i { width: 14px; text-align: center; color: var(--color-text-faint); }
.context-menu__item:hover:not(:disabled), .context-menu__item:focus-visible { background: var(--color-bg); outline: none; }
.context-menu__item:disabled { opacity: .45; cursor: not-allowed; }
.context-menu__item--danger, .context-menu__item--danger i { color: var(--color-danger); }
.context-menu__separator { height: 1px; margin: 4px 2px; background: var(--color-border-soft); }

/* Panel: fixed-height header, table body scrolls on its own, pagination
   stays anchored at the bottom — mirrors EngTool's layout. */

.db-panel { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
/* Ajax navigation (js/ajax_nav.js) in flight: the old page dims until the new one is swapped in. */
.db-editor.is-loading .db-panel { opacity: 0.55; transition: opacity 0.15s 0.1s; pointer-events: none; }
.db-panel__header { position: relative; flex: 0 0 auto; }

/* The filter <form> wraps both the scrolling table and the footer bar, so it
   has to be a flex column itself — otherwise .table-scroll's flex:1 sizing
   (and the footer's anchored position below it) has no effect, and a long
   table just pushes the footer down past the viewport instead of leaving it
   pinned at the bottom of the panel. Shared by the Database grid and the
   Views grid (grid-form class, not an id) so both keep the same anchored
   pagination footer instead of drifting apart. */
.grid-form { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.table-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; }

.db-panel__footer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0;
  padding: 1px 8px;
  border-top: 1px solid var(--color-border-soft);
  background: var(--color-surface);
  font-size: 12px;
  line-height: 1.2;
  color: var(--color-text-muted);
}
.db-panel__footer-count { white-space: nowrap; }
.db-panel__footer-pagination { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.db-panel__page-size,
.db-panel__page-jump { display: flex; align-items: center; gap: 4px; }
.db-panel__page-size select,
.db-panel__page-jump select { padding: 0 2px; height: 20px; font-size: 12px; border-radius: 4px; border: 1px solid var(--color-border); font-family: var(--font-ui); }
.db-panel__footer .btn--sm { padding: 0 8px; height: 20px; font-size: 12px; line-height: 1; display: inline-flex; align-items: center; }

/* Desktop grid pages: the panel itself is the one scroller, so the page
   header (title, subtitle, buttons) scrolls away with the rows to free
   vertical space; the column titles + filters (sticky thead, top:0) then pin
   under the global topbar, and the pagination status bar stays at the bottom
   of the panel. (Phones use #content as the scroller instead — see the
   Responsive section.) */
@media (min-width: 1001px) {
  /* Margin/padding swap: the scroller reaches the topbar, the right edge and
     the bottom edge of #content (cancelling its padding, as .db-sidebar
     does), so pinned headers sit flush and the status bar hugs the bottom. */
  .db-panel:has(.grid-form) { overflow: auto; margin: -28px -20px -28px 0; padding: 28px 20px 0 0; }
  /* Detail/form pages: same idea — the panel is the scroller, so the page
     never scrolls as a whole and the sidebar beside it stays put, full
     height, down to the bottom of the window. */
  .db-panel:not(:has(.grid-form)) { overflow-y: auto; margin: -28px -20px -28px 0; padding: 28px 20px 28px 0; }
  .db-panel:not(:has(.grid-form)) > * { flex-shrink: 0; }
  .db-panel:has(.grid-form) > .db-panel__header,
  .db-panel:has(.grid-form) > .db-panel__header { flex: none; }
  /* The form (and Views' .view-body) drop out of the box tree so the footer's
     containing block is the scroller itself — otherwise its sticky left/bottom
     would be confined to the form's own, narrower box. */
  .db-panel:has(.grid-form) > .view-body,
  .db-panel:has(.grid-form) .grid-form { display: contents; }
  .db-panel:has(.grid-form) .table-scroll,
  .db-panel:has(.grid-form) .db-panel__footer { flex: none; }
  .db-panel:has(.grid-form) .table-scroll { overflow: visible; }
  /* Sticky offsets resolve inside the scroller's padding, so cancel it. */
  .db-panel:has(.grid-form) .table thead th { top: -28px; }
  .db-panel:has(.grid-form) > .db-panel__header { position: sticky; left: 0; }
  /* margin-top:auto pushes the bar to the bottom of the panel when the rows
     don't fill it (the panel is a flex column); sticky bottom:0 keeps it
     pinned there when they overflow and the panel scrolls. */
  .db-panel:has(.grid-form) .db-panel__footer { position: sticky; left: 0; bottom: 0; z-index: 3; margin-top: auto; }
}

/* Grid density — resembles EngTool's compact data-grid spacing. Scoped to
   .db-panel, the generic grid partial's own wrapper (database/_grid_panel.
   html), not .db-editor — that partial renders identically under /database
   (inside .db-editor) and under /settings (inside .side-layout__panel, for the
   Users/Groups/Projects admin grids), so scoping to its own wrapper is what
   makes the grid itself look the same in both places; other Settings pages
   (Account, Application, Project), which never render .db-panel, keep the
   app's normal, more spacious sizing untouched. */
.db-panel { font-size: 14px; }
.db-panel .table { font-size: 13px; }
.db-panel .table th, .db-panel .table td { padding: 3px 10px; }
.db-panel .table td.grid-cell { padding: 0; }
.db-panel .table thead th {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  text-transform: none;
  letter-spacing: normal;
  background: var(--color-th-bg);
  padding: 0;
  vertical-align: top;
}
.db-panel .grid-th__filter { font-size: 12px; }
.db-editor .db-sidebar__link { padding: 5px 8px; font-size: 13px; }
.db-editor .db-sidebar__link--nested { padding-left: 18px; }
.db-editor .db-sidebar__link--nested-2 { padding-left: 28px; }
.db-panel .page-header__title { font-size: 18px; }
.db-panel .btn--sm { padding: 3px 8px; font-size: 12.5px; }
.db-panel .btn--icon.btn--sm { width: 24px; height: 24px; padding: 3px; }

/* Empty state */

.empty-state { padding: 44px 20px; text-align: center; border: 1px dashed var(--color-border); border-radius: var(--radius-lg); background: var(--color-surface); color: var(--color-text-muted); }

/* Modal / dialog */

dialog.modal { padding: 0; border: 1px solid var(--color-border); border-radius: var(--radius-lg); max-width: 480px; width: 92%; background: var(--color-surface); color: var(--color-text); box-shadow: 0 24px 48px rgba(15, 23, 42, 0.16); }
dialog.modal::backdrop { background-color: rgba(15, 23, 42, 0.45); }
.modal__body { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.modal__title { margin: 0; font-size: 17.5px; font-weight: 700; }
.modal__text { margin: 0; color: var(--color-text-muted); font-size: 15px; line-height: 1.5; }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; }

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

.view-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* Document preview panel (attachments list on item/folder detail pages, and
   documents-mode views). Fixed to the viewport; js/attachment-preview.js sets
   body[data-preview-dock] to where it sits:
   - right / bottom: docked — the page is made room for (the .db-editor loses
     the panel's width, #content loses its height) instead of being covered;
   - float: a plain overlay on the right edge, no room reserved.
   --attachment-preview-width / --attachment-preview-height are the user's
   (draggable, remembered) sizes. */
.attachment-preview-panel {
  position: fixed;
  top: var(--topbar-height);
  right: 0;
  bottom: 0;
  width: var(--attachment-preview-width);
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: -2px 0 12px rgba(15, 23, 42, 0.12);
  animation: panel-slide-in 180ms ease;
}
.attachment-preview-panel[hidden] { display: none; }
body[data-preview-dock="bottom"] .attachment-preview-panel {
  top: auto;
  left: 0;
  width: auto;
  height: var(--attachment-preview-height);
  border-left: 0;
  border-top: 1px solid var(--color-border);
  box-shadow: 0 -2px 12px rgba(15, 23, 42, 0.12);
  animation: none;
}
@media (min-width: 1001px) {
  /* +4px: cancels #content's 20px right padding, minus a 16px gap so the
     page's right-aligned controls (e.g. "New asset") don't touch the panel. */
  body[data-preview-dock="right"][data-preview-open] .db-editor { width: calc(100% - var(--attachment-preview-width) + 4px); }
  body[data-preview-dock="bottom"][data-preview-open] #content.content--wide { height: calc(100vh - var(--topbar-height) - var(--attachment-preview-height)); }
}
.attachment-preview-panel__resize { position: absolute; z-index: 1; background: transparent; }
.attachment-preview-panel__resize:hover, .attachment-preview-panel__resize.is-dragging { background: var(--color-accent-bg); }
body:not([data-preview-dock="bottom"]) .attachment-preview-panel__resize { top: 0; bottom: 0; left: -3px; width: 6px; cursor: col-resize; }
body[data-preview-dock="bottom"] .attachment-preview-panel__resize { left: 0; right: 0; top: -3px; height: 6px; cursor: row-resize; }
body.is-resizing-preview { user-select: none; }
body.is-resizing-preview iframe, body.is-resizing-preview canvas { pointer-events: none; }
.attachment-preview-panel__header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.attachment-preview-panel__title { margin: 0; font-size: 14px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-preview-panel__tools { display: flex; align-items: center; gap: 2px; flex: none; }
.attachment-preview-panel__tools .is-active { color: var(--color-accent-strong); background: var(--color-accent-bg); }
/* Pages are painted one <canvas> per page (see attachment-preview.js) and
   simply stacked in this scrolling column — that stack, plus the browser's
   native scrollbar, is what lets a multi-page PDF be read by scrolling. */
.attachment-preview-panel__body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  overflow: auto;
  padding: 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border-soft);
  border-radius: 10px;
}
.attachment-preview-panel__page { box-shadow: 0 1px 4px rgba(15, 23, 42, 0.2); border-radius: 2px; }
/* Images fit the panel; a click toggles the file's own size (scrollable). */
.attachment-preview-panel__image { max-width: 100%; height: auto; margin: auto; cursor: zoom-in; background: var(--color-surface); box-shadow: 0 1px 4px rgba(15, 23, 42, 0.2); }
.attachment-preview-panel__image.is-actual-size { max-width: none; margin: 0; cursor: zoom-out; }
.attachment-preview-panel__placeholder { margin: auto; max-width: 240px; text-align: center; color: var(--color-text-muted); font-size: 13px; line-height: 1.5; }

/* Rows that open the preview: attachments list, documents-mode views (those
   also carry .js-item-row, styled further up). */
.table tbody tr.js-preview-row { cursor: pointer; }
.table tbody tr.js-preview-row.is-selected,
.table tbody tr.js-preview-row.is-selected:hover { background-color: var(--color-accent-bg); box-shadow: inset 3px 0 0 var(--color-accent-strong); }
/* Document rows selectable for a zip download (js/document_rows.js), previewable or not. */
.table tbody tr.js-document-row { cursor: pointer; }
.table tbody tr.js-document-row.is-selected,
.table tbody tr.js-document-row.is-selected:hover { background-color: var(--color-accent-bg); box-shadow: inset 3px 0 0 var(--color-accent-strong); }

/* View form: the documents-only options follow the "Rows" radio. */
.view-documents-only { display: none; }
.card form:has(input[name="mode"][value="documents"]:checked) .view-documents-only { display: block; }

/* Attachments list: one filter per column (js/local_filter.js). */
.table tbody tr[hidden] { display: none; }
.attachments-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 6px; }
.attachments-toolbar .attachments-count { margin: 0; }
.attachments-count { margin: 0 0 6px; font-size: 13px; }
/* The header cells are the grid's two-tone cells (label row + filter row) without sorting. The filter
   row stays visible on small screens too (the grid hides it behind a "Filters" button). */
.attachments-stack .table th { padding: 0; }
.attachments-stack .grid-th__sort { cursor: default; }
.attachments-stack .grid-th__actions { display: flex; }

/* Drop zone (Attachments) */

/* Attachments table column widths (attachments/_section.html's <th> classes;
   classes rather than inline styles so the Responsive section can hide some
   of them on phones). Their sum is the 868px .js-dropzone-form width below. */
.att-col--actions { width: 64px; }
.att-col--name { width: auto; }
.att-col--ext { width: 60px; }
.att-col--type { width: 140px; }
.att-col--uploader { width: 130px; }
.att-col--date { width: 150px; }
.att-col--delete { width: 48px; }

/* The Name column takes whatever the others leave, so the table (and the
   drop zone under it) fill the side column instead of forcing a fixed width
   and a horizontal scrollbar. Only below 712px (592px of fixed columns +
   120px for Name) does .table-scroll scroll — keep that number in sync with
   the .att-col--* widths above. */
.attachments-stack .table-wrap { width: 100%; }
.attachments-stack .table--fixed-cols { width: 100%; min-width: 712px; }
.attachments-stack .js-dropzone-form { width: 100%; }

.dropzone {
  border: 1.5px dashed var(--color-border);
  border-radius: 8px;
  padding: 10px 14px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
  margin-top: 12px;
  margin-bottom: 0;
}
.dropzone.is-dragover { border-color: var(--color-accent); background-color: var(--color-accent-bg); color: var(--color-accent-strong); }
.dropzone__browse { color: var(--color-accent); cursor: pointer; }

/* Files column (Database grid: Units/Equipments) — count + drag-and-drop +
   manual-upload icon, all inside one grid cell. Padding matches
   .grid-cell__display's own 4px vertical exactly, with no min-height, so a
   files-cell row is the same height as a plain text-cell row instead of
   taller — the extra height that used to come from a 28px min-height and a
   circle-shaped upload button (see .files-cell__upload-btn below) is gone. */
.grid-cell--files { cursor: default; padding: 0; }
.grid-cell--files:hover { box-shadow: none; }
.files-cell {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 100%; padding: 4px 8px;
  border-radius: 4px;
  transition: background-color .15s, box-shadow .15s;
}
.files-cell.is-dragover { background-color: var(--color-accent-bg); box-shadow: inset 0 0 0 1.5px var(--color-accent); }
.files-cell__count { color: var(--color-text); font-weight: 400; font-size: 13px; font-family: var(--font-ui); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.files-cell__count:hover { text-decoration: underline; }
/* Manual-upload icon — same plain, circle-free treatment as .grid-row__view/
   .grid-row__delete: sized by the glyph plus a small hit-area padding, no
   border/background at rest, just a sober square tint on hover. Replaces the
   former .btn--icon.btn--sm, whose pill border-radius on an equal-width/
   height box rendered as a circle. Padding is 2px (not .grid-row__view's
   3px) so this icon's own content-box height (~17px) stays at or under
   .grid-cell__display's text line height — otherwise, as the tallest thing
   in a files-cell, it alone would still set the row taller than a plain
   text-cell row. */
.files-cell__upload-btn {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px;
  border: 0; border-radius: 4px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.files-cell__upload-btn:hover { background: var(--color-bg); color: var(--color-text); }

/* "blob" field kind (Traces module's `content`, and any future long-text
   column) — a clamped rendering of lite_markdown.render_lite_markdown()'s
   output, replied to full height via the "Show more"/"Show less" button
   grid.js wires up. max-height is a measured 8 lines rather than
   -webkit-line-clamp, which doesn't reliably handle a mix of paragraphs and
   <ul><li> (see lite_markdown.py's own docstring). */
.blob-clamp {
  max-height: calc(8 * 1.5em);
  line-height: 1.5em;
  overflow: hidden;
}
.blob-clamp.is-expanded { max-height: none; }
.blob-clamp ul { margin: 4px 0; padding-left: 20px; }
.blob-clamp__toggle {
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-accent-strong);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.blob-clamp__toggle:hover { text-decoration: underline; }

/* Login page */

.login-page {
  position: relative;
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 8%, color-mix(in srgb, var(--palette-accent) 55%, transparent), transparent 30rem),
    radial-gradient(circle at 90% 90%, color-mix(in srgb, var(--palette-dominant) 10%, transparent), transparent 28rem),
    var(--color-bg);
}
.login-page .dot-pattern { left: 2.5rem; bottom: 2rem; }
.login-card {
  position: relative;
  width: 360px; padding: 32px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.08);
}
.login-card__logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--color-accent); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; margin: 0 auto 16px;
  overflow: hidden;
}
.login-card__logo img { width: 100%; height: 100%; object-fit: contain; }
.login-card h1 { text-align: center; font-size: 20px; margin: 0 0 22px; }

/* Errors page */

.error-page { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 60vh; padding: 40px 20px; }
.error-page__code { font-size: 70.5px; font-weight: 800; margin: 0; color: var(--color-accent); }
.error-page__title { margin: 12px 0 6px; font-size: 22px; font-weight: 700; }
.error-page__subtitle { color: var(--color-text-muted); max-width: 440px; margin: 0 0 20px; }

/* Docs */

.docs { max-width: 760px; display: flex; flex-direction: column; gap: 32px; }
.docs h2 { font-size: 18.5px; margin: 0 0 12px; }
.docs h3 { font-size: 15.5px; margin: 18px 0 8px; }
.docs p, .docs li, .docs dd { color: var(--color-text-muted); font-size: 15px; line-height: 1.65; }

/* Help pages (help/_page.html) — one .docs article per page, inside the
   shared side-nav layout. Wider than a plain .docs block: the KKS reference
   tables and the database schema need the room. */
.docs--page { max-width: 980px; gap: 0; }
.docs--page p, .docs--page li, .docs--page dd { line-height: 1.8; }
.docs--page > h2 { font-size: 24px; font-weight: 700; color: var(--color-text); margin: 0 0 6px; letter-spacing: -.01em; }
.docs__lead { margin: 0 0 28px !important; padding-bottom: 18px; border-bottom: 1px solid var(--color-border); font-size: 16px !important; }
.docs--page h3 {
  font-size: 18px; font-weight: 700; color: var(--color-text);
  margin: 40px 0 14px; padding-left: 12px;
  border-left: 4px solid var(--color-accent);
  line-height: 1.3;
}
.docs--page .docs__tables h3 { font-size: 16px; margin-top: 28px; }
.docs ul, .docs ol { margin: 0 0 20px; padding-left: 24px; }
.docs li { margin-bottom: 8px; }
.docs p { margin: 0 0 16px; }
.docs a { color: color-mix(in srgb, var(--color-accent) 40%, var(--color-text)); font-weight: 500; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.docs a:hover { color: var(--color-text); }
.docs code { font-family: var(--font-mono); font-size: 13px; background: var(--color-th-bg); padding: 1px 5px; border-radius: 4px; }
.docs .table-scroll { margin: 4px 0 20px; }
.docs__small { font-size: 13.5px !important; }
.docs__dl { display: grid; grid-template-columns: 180px 1fr; gap: 14px 20px; margin: 0 0 24px; }
.docs__dl dt { font-weight: 600; font-size: 15px; color: var(--color-text); line-height: 1.8; }
.docs__dl dd { margin: 0; }
.docs__hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; margin: 8px 0 36px; }
.docs__hero img { width: 160px; height: 160px; object-fit: contain; margin-bottom: 10px; border-radius: 28px; }
.docs__hero-title { margin: 0 !important; font-size: 26px !important; font-weight: 700; color: var(--color-text) !important; }
.docs__hero-subtitle { margin: 0 !important; font-size: 15px !important; }
.docs__image { display: block; width: 100%; max-width: 640px; height: auto; margin: 12px 0 20px; border: 1px solid var(--color-border); border-radius: 8px; background: #fff; }
.docs__example { display: flex; justify-content: center; max-width: 640px; margin: 12px 0 18px; padding: 18px 24px; border: 1px solid var(--color-accent-border); border-radius: 8px; background: var(--color-accent-bg); }
.docs__example code { background: none; padding: 0; font-size: 18px; font-weight: 600; color: var(--color-accent-strong); word-break: break-word; }
.docs__tables { display: flex; flex-direction: column; gap: 8px; }
.docs__tables .table-scroll { max-height: 520px; overflow-y: auto; margin-bottom: 4px; }
.docs__tables--full .table-scroll { max-height: none; overflow-y: visible; }
.docs__tables--full thead th { position: static; }
.docs__tables--full td:first-child { font-weight: 600; color: var(--color-text); }
.docs__tables .table { width: 100%; table-layout: fixed; }
.docs__tables td { white-space: normal; vertical-align: top; }
.docs__tables td.docs__mono, .docs .docs__mono { font-family: var(--font-mono); font-weight: 600; }
.docs__tables thead th { position: sticky; top: 0; z-index: 1; }

/* Whole-database schema (help/core/database.html), imported as-is from
   EngTool: boxes per table, grouped in one dashed panel per module. */
.docs__diagram { display: block; width: 100%; max-width: 960px; height: auto; margin: 12px 0 20px; }
.docs__diagram text { font-family: var(--font-ui); }
.docs__diagram-box { fill: var(--color-accent-bg); stroke: var(--color-accent-strong); }
.docs__diagram-label { fill: var(--color-text); }
.docs__diagram-box--minor { fill: var(--color-bg); stroke: var(--color-text-faint); stroke-dasharray: 2 2; }
.docs__diagram-label--minor { fill: var(--color-text-muted); }
.docs__diagram-box--secondary { fill: var(--color-surface); stroke: var(--color-accent-strong); stroke-dasharray: 3 2; }
.docs__diagram-label--secondary { fill: var(--color-accent-strong); }
.docs__diagram-panel { fill: var(--color-bg); stroke: var(--color-border); }
.docs__diagram-panel-label { fill: var(--color-text-muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.docs__diagram-line { stroke: var(--color-text-faint); fill: none; }
.docs__diagram-arrow { fill: var(--color-text-faint); }

@media (max-width: 700px) {
  .docs__dl { grid-template-columns: 1fr; gap: 2px; }
  .docs__dl dd { margin-bottom: 8px; }
}

/* Utility */

.text-muted { color: var(--color-text-muted); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.mb-16 { margin-bottom: 16px; }

/* ================================================================
   Responsive — smartphones (down to 360px wide) and small tablets.
   Every rule below sits under a max-width media query or a touch-only
   device query ((hover: none) and (pointer: coarse)), so the desktop
   rendering above is untouched. Scope is consultation on a phone:
   layout, navigation and readability. Grid editing (double-click) is
   deliberately left exactly as it is — nothing here changes it.
   ================================================================ */

/* No hover on touch screens: a tapped button/tile would otherwise stay in
   its lifted :hover state until the next tap elsewhere. */
@media (hover: none) {
  .btn:hover { transform: none; }
  .stat-tile:hover { transform: none; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); }
}

@media (max-width: 1000px) {
  body { background-attachment: scroll; -webkit-text-size-adjust: 100%; }

  /* z-index: auto so the fixed sidebar drawers inside #content can stack
     above the drawer backdrop (body::after, below) instead of being
     trapped in #content's own stacking context. */
  #content { padding: 16px 12px; z-index: auto; }
  /* dvh tracks the mobile browser's collapsing address bar; vh fallback.
     overflow-y: once stacked into one column, a detail page (properties +
     attachments) is taller than this fixed-height shell — it scrolls inside
     it instead of overflowing the shell, which would eventually carry the
     sticky topbar off-screen along with its parent. Grid pages fit the
     shell exactly and keep scrolling inside their own .table-scroll. */
  #content.content--wide {
    height: calc(100vh - var(--topbar-height));
    height: calc(100dvh - var(--topbar-height));
    overflow-y: auto;
  }

  /* ---- Topbar: brand · user menu · burger; nav moves into a drawer ---- */
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar__version, .topbar__link--help { display: none; }
  .topbar__menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; padding: 0;
    border-radius: 8px;
    border: 1px solid var(--color-on-dark-border);
    background: transparent;
    color: var(--color-on-dark);
    font-size: 17px;
    cursor: pointer;
  }
  .topbar__menu-toggle[aria-expanded="true"] { background-color: var(--color-on-dark-hover); }
  .topbar__drawer {
    display: none;
    position: fixed;
    top: var(--topbar-height); left: 0; right: 0;
    max-height: calc(100dvh - var(--topbar-height));
    overflow-y: auto;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    background-color: var(--color-topbar-bg);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
  }
  .topbar__drawer.is-open { display: flex; }
  .topbar__drawer .topbar__nav { flex-direction: column; align-items: stretch; gap: 2px; height: auto; }
  .topbar__drawer .topbar__link {
    height: 44px; padding: 0 12px;
    border-bottom: 0; border-left: 3px solid transparent; border-radius: 6px;
  }
  .topbar__drawer .topbar__link.is-active { border-color: var(--palette-dominant); background-color: var(--color-on-dark-hover); }
  .topbar__link--drawer-only { display: flex; }
  /* Project switcher: full-width toggle, its list expands in place inside
     the drawer instead of floating off the left edge of the screen. */
  .topbar__drawer .dropdown--project .dropdown__toggle { width: 100%; padding: 10px 14px; }
  .topbar__drawer .dropdown--project .dropdown__menu { position: static; min-width: 0; margin-top: 6px; }
  .topbar__drawer .dropdown--project .dropdown__item { padding: 12px 10px; }
  .dropdown__menu { max-width: calc(100vw - 24px); }

  /* Backdrop behind an open drawer (drawer.js sets the body class). Sits
     under the topbar (z 20, which holds the nav drawer) and the sidebar
     drawers (z 18); tapping it closes the drawer (outside click). */
  body.has-drawer-open::after {
    content: "";
    position: fixed;
    top: var(--topbar-height); right: 0; bottom: 0; left: 0;
    background-color: rgba(15, 23, 42, 0.45);
    z-index: 15;
  }

  /* ---- Sidebars (Database, Traces, Settings) become slide-in drawers ---- */
  .db-editor, .side-layout { flex-direction: column; align-items: stretch; gap: 12px; }
  .sidebar-toggle { display: inline-flex; align-self: flex-start; }
  .db-sidebar, .side-nav {
    position: fixed;
    top: var(--topbar-height); bottom: 0; left: 0;
    width: min(280px, 85vw);
    height: auto; max-height: none;
    margin: 0;
    padding: 10px 12px;
    border: 0; border-right: 1px solid var(--color-border); border-radius: 0;
    background: var(--color-surface);
    overflow-y: auto;
    z-index: 18;
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 180ms ease, visibility 0s linear 180ms;
  }
  .db-sidebar.is-open, .side-nav.is-open {
    transform: none;
    visibility: visible;
    transition: transform 180ms ease;
  }

  /* ---- Page chrome ---- */
  .page-header { gap: 12px; margin-bottom: 16px; }
  .page-header__title { font-size: 19px; }
  .page-header__actions { gap: 8px; }
  .tabs { overflow-x: auto; scrollbar-width: none; }
  .tabs__link { white-space: nowrap; }
  .form-columns { grid-template-columns: 1fr; gap: 0; }
  .form-actions, .modal__actions { flex-wrap: wrap; }
  .stat-tiles { gap: 10px; }
  .stat-tile { min-width: 0; padding: 12px; }

  /* ---- Grids: scroll horizontally inside .table-scroll only ---- */
  .table-scroll { overscroll-behavior-x: contain; }
  /* A plain table not wrapped in .table-scroll (e.g. settings/application's
     modules list) scrolls sideways within its own frame instead of widening
     the page. Grids inside .table-scroll are left alone — making their
     .table-wrap a scroll container would un-stick their headers. */
  :not(.table-scroll) > .table-wrap { max-width: 100%; overflow-x: auto; }
  /* Sidebar-layout pages (/database, /views, detail pages, /traces): one
     single scroller on a phone — #content.content--wide itself, both axes —
     instead of desktop's fixed-height panel whose table scrolls inside its
     own .table-scroll. Vertically, the page header scrolls away and the
     grid gets the whole screen (its thead stays pinned: #content is now its
     sticky header's scroll container), with the pagination footer only
     showing up after the last row. Horizontally, only the table moves: the
     page header, the sidebar toggle and the footer are pinned left
     (sticky), as is the leading icon column (below). Every flex level in
     between takes its natural height (flex: none) so nothing gets
     squeezed — e.g. a trace's own contents table on traces/detail.html. */
  .content--wide .db-editor,
  .content--wide .db-panel,
  .content--wide .view-body,
  .content--wide .grid-form { flex: none; min-height: auto; }
  /* Only a grid's own .table-scroll hands its scrolling over to #content;
     any other table (a trace's linked-traces list, a detail page's
     property table...) keeps scrolling sideways within its own frame. */
  .content--wide .grid-form > .table-scroll { overflow: visible; }
  /* A sticky element can't leave its containing block, so on grid pages the
     panel (and the editor around it) is widened to the table's own width —
     the header/footer, pinned at one screen width, then have room to stay
     put while the table scrolls sideways under them. Scoped with :has() to
     pages that actually hold a grid form: a detail page's max-content width
     would be its two columns side by side, unwrapped. */
  .content--wide .db-editor:has(.grid-form),
  .content--wide .db-panel:has(.grid-form) { width: max-content; min-width: 100%; }
  .content--wide .db-panel__header,
  .content--wide .sidebar-toggle,
  .content--wide .db-panel__footer { position: sticky; left: 0; }
  .content--wide .db-panel:has(.grid-form) .db-panel__header,
  .content--wide .db-panel:has(.grid-form) .db-panel__footer { width: calc(100vw - 24px); }
  /* Sticky offsets resolve against #content's padding-inset box: these
     negative ones cancel its 16px/12px padding, so the pinned thead sits
     flush under the topbar and the pinned icon column flush with the
     screen's left edge, with no strip of scrolled rows showing past them. */
  .content--wide .table thead th { top: -16px; }
  .content--wide .js-grid .grid-col--icon { left: -12px; }
  /* Filter row collapsed by default, revealed by the header's "Filters"
     button (grid.filter_toggle macro / drawer.js). */
  .grid-filter-toggle { display: inline-flex; }
  .grid-th__actions { display: none; }
  .is-filters-open .grid-th__actions { display: flex; }
  /* Leading "view details" icon column stays pinned while the rest of the
     grid scrolls sideways, so a row can always be opened. */
  .js-grid .grid-col--icon {
    position: sticky; left: 0; z-index: 1;
    background: var(--color-surface);
    box-shadow: 1px 0 0 var(--color-border-soft);
  }
  .js-grid thead th.grid-col--icon { z-index: 2; background: var(--color-th-bg); }
  .db-panel__footer { gap: 8px; }

  /* ---- Folder/item detail pages: stack properties above attachments ---- */
  .detail-columns__main, .detail-columns__side { flex: 1 1 100%; min-width: 0; }
  .attachments-stack .js-dropzone-form { width: 100%; }
  :root { --attachment-preview-width: 100vw; --attachment-preview-height: 100vh; }
  .attachment-preview-panel { top: var(--topbar-height); left: 0; width: auto; height: auto; }
  .attachment-preview-panel__resize, .attachment-preview-panel__tools [data-dock] { display: none; }
  .attachment-preview-panel__header .btn--icon { width: 40px; height: 40px; }
}

@media (max-width: 480px) {
  .topbar__user-name { display: none; }
  .dropdown__toggle { padding-right: 10px; }

  .stat-tiles, .stat-tiles--compact {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }
  .stat-tiles--compact .stat-tile { min-width: 0; }
  .stat-tile__value { font-size: 20px; }

  .detail-grid, .form-grid { grid-template-columns: 1fr; }

  /* Key->value property tables: label/value split 40/60 and let both wrap
     instead of ellipsizing (a single row's own fields, not a dense grid). */
  .table--kv th[scope="row"] { width: 40%; white-space: normal; }
  .table--kv td { white-space: normal; }
  .table--kv .grid-cell__display { overflow-wrap: anywhere; }

  /* Secondary columns hidden on phones: folders/detail's related-items Tag/
     Type, and the attachments table's Ext./Uploaded by/Date — which then
     spans the column width, with Name taking whatever is left. */
  .col-hide-sm, .att-col--ext, .att-col--uploader, .att-col--date { display: none; }
  .attachments-stack .table--fixed-cols { width: 100%; min-width: 0; }
  .att-col--actions { width: 80px; }
  .att-col--name { width: auto; }
  .att-col--type { width: 110px; }
  .att-col--delete { width: 56px; }

  /* Pagination footer: count on its own line, "Page size"/"Previous"/
     "Next" words dropped (arrows and selects remain). */
  .db-panel__footer-count { flex-basis: 100%; }
  .db-panel__footer-label { display: none; }

  .form-actions .btn, .modal__actions .btn { flex: 1 1 auto; justify-content: center; }
  .error-page__code { font-size: 54px; }
}

/* Touch-only devices (phones/tablets; not touchscreen laptops). */
@media (hover: none) and (pointer: coarse) {
  /* Column resize/reorder is disabled on touch (grid.js isTouchOnly). */
  .grid-resizer { display: none; }
  .grid-th { cursor: default; }

  /* iOS zooms the page on focusing any field under 16px. Deliberately not
     applied to a grid cell's own inline editor (.grid-cell.is-editing >
     input/select), whose sizing stays exactly as on desktop. */
  .form-field input, .form-field select, .form-field textarea,
  .grid-th__filter, .db-panel__footer select { font-size: 16px; }

  /* Finger-sized hit areas for the per-row icons. The icon columns lose
     their side padding so the bigger buttons still fit their fixed width. */
  .grid-row__view, .grid-row__delete, .grid-row__merge, .grid-row__edit,
  .files-cell__upload-btn, .grid-th__icon-btn { min-width: 32px; min-height: 32px; }
  .db-panel .table td.grid-col--icon, .db-panel .table td.grid-col--actions { padding: 0 4px; }
  .db-sidebar__link, .db-editor .db-sidebar__link, .side-nav__link { padding-top: 10px; padding-bottom: 10px; }

  /* No drag & drop on a phone: the drop zone's "browse" becomes a button. */
  .dropzone__drag-hint { display: none; }
  .dropzone__browse {
    display: inline-flex; align-items: center;
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-weight: 600;
    text-transform: capitalize;
  }
}

/* Folder detail: icon / colour picker popup (static/js/style_picker.js). */
.style-picker__trigger { display: inline-flex; align-items: center; gap: 8px; margin-left: 10px; vertical-align: middle; }
.style-picker__preview { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; color: var(--color-text-muted); }
.style-picker__preview--color { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--color-border); }
.style-picker__preview--color.is-empty { background: repeating-linear-gradient(45deg, var(--color-border) 0 3px, transparent 3px 6px); }
dialog.modal.style-picker { max-width: 640px; }
.style-picker__bar { display: flex; align-items: center; gap: 10px; }
.style-picker__bar input[type="search"] { flex: 1 1 auto; min-width: 0; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-surface); color: var(--color-text); }
.style-picker__count { font-size: 12.5px; color: var(--color-text-muted); white-space: nowrap; }
.style-picker__body { max-height: 52vh; overflow-y: auto; padding: 2px; }
.style-picker__icons { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.style-picker__icon { display: flex; align-items: center; justify-content: center; height: 44px; font-size: 18px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--color-text); cursor: pointer; }
.style-picker__icon[hidden] { display: none; }
.style-picker__icon:hover { background: var(--color-bg); border-color: var(--color-border); }
.style-picker__colors { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; padding: 4px; }
.style-picker__swatch { aspect-ratio: 1; border: 1px solid color-mix(in srgb, #000 12%, transparent); border-radius: 50%; cursor: pointer; }
.style-picker__swatch:hover { transform: scale(1.1); }
.style-picker .is-selected { outline: 2px solid var(--color-accent-strong); outline-offset: 2px; }
/* Value and picker button share one line (the display span is block by default). */
.grid-cell--picker { white-space: nowrap; }
.grid-cell--picker > .grid-cell__display { display: inline-block; vertical-align: middle; }
/* Item page: the item type's files, listed read-only under the item's own. */
.item-type-files { border: 1px solid var(--color-border); border-left: 4px solid var(--color-accent); background: var(--color-th-filter-bg); border-radius: 6px; padding: 12px; }
.item-type-files__bar { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.item-type-files__title { margin: 0; font-size: 14px; font-weight: 700; }
