/* ============================================================================
   layout.css — app shell, shared component library and dark theme.
   Loaded AFTER control.css and neobrutalism.css (see templates/base.html).
   Look: 2px edge, hard offset shadow, flat fills (mint / yellow / red / blue / purple),
   press-on-hover. Every colour goes through the --lx-* tokens below so the dark theme
   (html[data-theme="dark"], or any element with data-theme="dark") re-skins everything.
   Sections: 1 tokens · 2 base · 3 shell · 4 buttons+dropdowns · 5 header widgets · 6 palette
   7 modal/drawer · 8 page header · 9 cards/stat/detail/settings · 10 chips/avatars · 11 tabs/pagination
   12 toolbar/table/grid/skeleton · 13 charts · 14 forms+layout utilities · 15 dark legacy fixes
   16 responsive · 17 print · 18 ui-kit page
   ============================================================================ */

/* 1 · Tokens ------------------------------------------------------------- */
:root {
  --lx-bg: #fef6e4;
  --lx-surface: #ffffff;
  --lx-surface-2: #fff8e8;
  --lx-surface-3: #f1e8cf;
  --lx-text: #000000;
  --lx-text-soft: #4a4a4a;
  --lx-edge: #000000;
  --lx-line: rgba(0, 0, 0, 0.22);
  --lx-shadow-color: #000000;
  --lx-danger-text: #b3261e;
  --lx-mint: #7ee0a3;
  --lx-mint-strong: #3fce7f;
  --lx-yellow: #ffdc58;
  --lx-red: #ff8a80;
  --lx-blue: #8ec5ff;
  --lx-purple: #c4b5fd;
  --lx-gray: #e5e5e5;
  --lx-grid-line: rgba(0, 0, 0, 0.06);
  --sb-w: 272px;
  --header-h: 64px;
  --shell-gap: 16px;
}

html[data-theme="dark"], [data-theme="dark"] {
  color-scheme: dark;
  --lx-bg: #14151a;
  --lx-surface: #21232b;
  --lx-surface-2: #2a2d37;
  --lx-surface-3: #363a47;
  --lx-text: #f4f0e4;
  --lx-text-soft: #b8b3a4;
  --lx-edge: #e9e3d2;
  --lx-line: rgba(233, 227, 210, 0.28);
  --lx-shadow-color: #9a9484;
  --lx-danger-text: #ff9d94;
  --lx-grid-line: rgba(255, 255, 255, 0.045);
  /* Re-point the neobrutalism.css / control.css tokens so legacy components follow the theme. */
  --nb-border: var(--lx-edge);
  --nb-surface: var(--lx-surface);
  --nb-surface-focus: #2d313c;
  --nb-text: var(--lx-text);
  --nb-bg: var(--lx-bg);
  --nb-shadow: 2px 2px 0 0 var(--lx-shadow-color);
  --nb-shadow-sm: 1px 1px 0 0 var(--lx-shadow-color);
  --nb-shadow-lg: 4px 4px 0 0 var(--lx-shadow-color);
  --shadow-sm: var(--nb-shadow);
  --shadow-md: var(--nb-shadow);
  --shadow-lg: var(--nb-shadow-lg);
  --ink: var(--lx-text);
  --ink-soft: #e5e0d2;
  --muted: var(--lx-text-soft);
  --green: #7ee0a3;
  --green-hover: #a8efc3;
  --line: var(--lx-edge);
  --line-strong: var(--lx-edge);
  --paper: var(--lx-bg);
  --surface-subtle: var(--lx-surface-2);
  --white: var(--lx-surface);
  --danger: #ff9d94;
  --ring: 0 0 0 3px #ffdc58, 0 0 0 5px var(--lx-edge);
  background-color: var(--lx-bg);
  color: var(--lx-text);
}
html[data-theme="dark"] {
  background-image:
    linear-gradient(to right, var(--lx-grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--lx-grid-line) 1px, transparent 1px);
}
/* Fills keep black text in both themes: re-scope the text tokens inside filled surfaces. */
.card--mint, .card--yellow, .card--red {
  --lx-text: #000; --lx-text-soft: #222; --nb-text: #000; --ink: #000; --muted: #222; color: #000;
}

/* 2 · Base --------------------------------------------------------------- */
[hidden] { display: none !important; }
html { scroll-padding-top: 96px; }
button { color: var(--nb-text); }
::placeholder { color: var(--lx-text-soft); opacity: 1; }
kbd {
  font: 700 11px var(--font); padding: 1px 6px; border: 2px solid var(--lx-edge); border-radius: 4px;
  background: var(--lx-surface-2); color: var(--lx-text); line-height: 1.5;
}
/* A modal locks page scroll. The scrollbar then disappears, so pad the page by its measured width (--sbw, set in
   control.js) to keep the layout still, and tint the page background itself with the same dim as ::backdrop so
   that padded strip is dark too instead of showing a light band. */
html:has(dialog[open]) {
  overflow: hidden; padding-right: var(--sbw, 0px);
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.55)),
    linear-gradient(to right, rgba(0, 0, 0, 0.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0, 0, 0, 0.06) 1px, transparent 1px);
  background-size: auto, 48px 48px, 48px 48px;
}
html[data-theme="dark"]:has(dialog[open]) {
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
    linear-gradient(to right, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
}
.ui-icon { flex: 0 0 auto; }

/* 3 · App shell ---------------------------------------------------------- */
.app-shell { min-height: 100vh; }
.app-sidebar {
  position: fixed; z-index: 40; top: var(--shell-gap); left: var(--shell-gap); bottom: var(--shell-gap);
  width: var(--sb-w); display: flex; flex-direction: column; overflow: hidden;
  background: var(--lx-surface); color: var(--lx-text);
  border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: var(--nb-shadow);
  transition: width 0.18s ease-out, transform 0.2s ease-out;
}
.app-content {
  margin-left: calc(var(--sb-w) + var(--shell-gap) * 2); padding: var(--shell-gap) var(--shell-gap) var(--shell-gap) 0;
  min-height: 100vh; display: flex; flex-direction: column; min-width: 0; transition: margin-left 0.18s ease-out;
}
.app-shell .app-main { flex: 1 1 auto; max-width: none; margin: 0; padding: 24px 0 28px; min-height: 0; min-width: 0; }
.app-shell footer.app-footer {
  max-width: none; margin: 0; padding: 14px 2px 18px; border-top: 2px solid var(--lx-edge);
  font-size: 13px; letter-spacing: 1px; color: var(--lx-text-soft); font-weight: 700;
}
.app-footer b { color: var(--lx-text-soft); margin: 0 8px; }
.app-scrim { display: none; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.55); }

.sb-brand { display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px; border-bottom: 2px solid var(--lx-edge); }
.sb-logo { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; color: var(--lx-text); }
.sb-logo .brand-mark { flex: 0 0 auto; width: auto; min-width: 42px; height: 42px; padding: 0 9px; font-size: 15px; background: var(--lx-mint); color: #000; border-color: var(--lx-edge); }
.sb-logo-text { font-size: 13px; font-weight: 800; line-height: 1.25; letter-spacing: 0.2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sb-close { display: none; }
.sb-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; padding: 6px 12px 16px; scrollbar-width: thin; }
.sb-section { margin: 18px 4px 6px; font-size: 13px; font-weight: 800; letter-spacing: 1.6px; color: var(--lx-text-soft); }
.sb-link, .sb-sublink {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; margin: 2px 0;
  border: 2px solid transparent; border-radius: 5px; background: transparent; color: var(--lx-text);
  font-size: 14.5px; font-weight: 700; text-align: left; cursor: pointer; box-shadow: none; justify-content: flex-start;
}
.sb-link .ui-icon { width: 19px; height: 19px; }
.sb-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-link:hover, .sb-sublink:hover, button.sb-link:hover:enabled {
  background: var(--lx-yellow); border-color: var(--lx-edge); color: #000; transform: none; box-shadow: none;
}
.sb-link.is-active, .sb-sublink.is-active, button.sb-link.is-active:hover:enabled {
  background: var(--lx-mint); border-color: var(--lx-edge); color: #000; box-shadow: var(--nb-shadow-sm);
}
.sb-chevron { display: inline-flex; transition: transform 0.15s ease-out; }
.sb-group.is-open .sb-chevron { transform: rotate(180deg); }
.sb-children { display: none; margin: 2px 0 4px 20px; padding-left: 10px; border-left: 2px solid var(--lx-edge); }
.sb-group.is-open .sb-children { display: block; }
.sb-sublink { padding: 7px 10px; font-size: 13.5px; }
.sb-tree { margin-top: 14px; padding-top: 4px; border-top: 2px dashed var(--lx-line); }
.tree-filter { position: relative; display: block; margin: 12px 0 4px; }
.tree-filter .ui-icon { position: absolute; left: 11px; top: 50%; width: 15px; height: 15px; transform: translateY(-50%); color: var(--lx-text-soft); pointer-events: none; }
.tree-filter input { height: 36px; padding: 0 10px 0 34px; font-size: 13.5px; margin-top: 0; }
.app-sidebar .sidebar-tree { display: block; }
.app-sidebar .sidebar-heading { margin: 14px 4px 8px; font-size: 13px; letter-spacing: 1.6px; color: var(--lx-text-soft); }
.app-sidebar .sidebar-company { font-size: 14px; padding: 4px 6px; color: var(--lx-text); }
.app-sidebar .sidebar-plants { padding-left: 6px; }
.app-sidebar .sidebar-plants a { font-size: 13.5px; padding: 5px 8px; color: var(--lx-text); }
.app-sidebar .sidebar-plants a:hover { color: #000; }
.app-sidebar .sidebar-code, .app-sidebar .sidebar-empty { color: var(--lx-text-soft); }
.app-sidebar .sidebar-toggle { color: var(--lx-text); padding: 2px 8px; }

.app-header {
  position: sticky; top: var(--shell-gap); z-index: 30; display: flex; align-items: center; gap: 12px;
  min-height: var(--header-h); padding: 8px 14px; background: var(--lx-surface); color: var(--lx-text);
  border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: var(--nb-shadow-sm);
}
.app-header-spacer { flex: 1 1 auto; }
.app-header-tools { display: flex; align-items: center; gap: 10px; }
.app-burger { display: none; }
.guest-body .topbar { gap: 12px; }
.guest-body .topbar .top-label { margin-left: auto; }

/* Mini (icons-only) sidebar, desktop only. */
@media (min-width: 1001px) {
  html[data-sidebar="mini"] { --sb-w: 76px; }
  html[data-sidebar="mini"] .sb-label, html[data-sidebar="mini"] .sb-chevron, html[data-sidebar="mini"] .sb-logo-text,
  html[data-sidebar="mini"] .sb-tree, html[data-sidebar="mini"] .sb-group .sb-children { display: none; } /* .sb-group: must outrank ".sb-group.is-open .sb-children" so open sub-menus fold away in the icon rail */
  html[data-sidebar="mini"] .sb-brand { flex-direction: column; padding: 12px 8px; }
  html[data-sidebar="mini"] .sb-logo .brand-mark { min-width: 44px; padding: 0 4px; font-size: 12px; }
  html[data-sidebar="mini"] .sb-logo .brand-mark span { display: none; }
  html[data-sidebar="mini"] .sb-link { justify-content: center; padding: 10px 0; }
  html[data-sidebar="mini"] .sb-section { font-size: 0; margin: 10px 8px 6px; border-top: 2px solid var(--lx-line); }
  html[data-sidebar="mini"] .sb-scroll { padding: 4px 8px 12px; }
  /* Floating sub-menu next to a group's icon (position set by shell.js; fixed so the rail never clips it). */
  html[data-sidebar="mini"] .sb-group.is-flyout .sb-children {
    display: block; position: fixed; z-index: 60; min-width: 220px; margin: 0; padding: 6px;
    background: var(--lx-surface); border: 2px solid var(--lx-edge); border-radius: 5px; box-shadow: var(--nb-shadow);
  }
  html[data-sidebar="mini"] .sb-group.is-flyout .sb-sublink { white-space: nowrap; }
  html[data-sidebar="mini"] .sb-collapse .ui-icon { transform: scaleX(-1); }
}

/* 4 · Buttons and dropdowns --------------------------------------------- */
.icon-btn, .btn-menu, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0;
  background: var(--lx-surface); color: var(--lx-text); border: 2px solid var(--lx-edge); border-radius: 5px;
  box-shadow: var(--nb-shadow-sm); font-size: 14px; font-weight: 700; cursor: pointer;
}
.icon-btn { width: 40px; position: relative; }
.btn-menu, .btn-ghost { padding: 0 12px; }
.btn-menu .ui-icon:last-child { width: 15px; height: 15px; }
.icon-btn .ui-icon { width: 18px; height: 18px; }
.icon-btn:hover:enabled, .btn-menu:hover:enabled, .btn-ghost:hover:enabled {
  background: var(--lx-yellow); color: #000; transform: translate(1px, 1px); box-shadow: none;
}
.icon-btn.is-active, .icon-btn.is-active:hover:enabled { background: var(--lx-mint); color: #000; }
.icon-btn:active:enabled, .btn-menu:active:enabled, .btn-ghost:active:enabled { transform: translate(1px, 1px); box-shadow: none; }
.page-header-actions .button, .page-header-actions button.primary {
  height: 40px; padding: 0 16px; font-size: 14px; gap: 8px;
}
.page-header-actions .button .ui-icon, .page-header-actions button .ui-icon { width: 17px; height: 17px; }

.dropdown { position: relative; display: inline-flex; }
.dropdown-menu {
  position: absolute; top: calc(100% + 8px); z-index: 60; min-width: 220px; max-width: min(380px, 92vw);
  display: flex; flex-direction: column; gap: 2px; padding: 6px; background: var(--lx-surface); color: var(--lx-text);
  border: 2px solid var(--lx-edge); border-radius: 6px; box-shadow: var(--nb-shadow);
}
.dropdown-menu--right { right: 0; }
.dropdown-menu--left { left: 0; }
html:not(.js) .dropdown:focus-within > .dropdown-menu[hidden] { display: flex !important; }
.dropdown-heading { margin: 0; padding: 8px 10px 4px; font-size: 13px; font-weight: 800; letter-spacing: 1.4px; color: var(--lx-text-soft); }
.dropdown-sep { height: 0; margin: 6px -6px; border-top: 2px solid var(--lx-edge); }
.dropdown-form { margin: 0; }
.dropdown-custom { padding: 6px 8px; }
.dropdown-item {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; padding: 9px 10px;
  border: 2px solid transparent; border-radius: 5px; background: transparent; color: var(--lx-text);
  font-size: 14px; font-weight: 700; text-align: left; cursor: pointer; box-shadow: none;
}
.dropdown-item span { min-width: 0; }
.dropdown-item small { display: block; font-size: 13px; font-weight: 600; color: var(--lx-text-soft); }
.dropdown-item:hover:enabled, a.dropdown-item:hover, .dropdown-item:focus-visible {
  background: var(--lx-yellow); border-color: var(--lx-edge); color: #000; transform: none; box-shadow: none; outline: none;
}
.dropdown-item:hover small, .dropdown-item:focus-visible small { color: #222; }
.dropdown-item.is-danger { color: var(--lx-danger-text); }
.dropdown-item.is-danger:hover:enabled, a.dropdown-item.is-danger:hover { background: var(--lx-red); color: #000; }
.dropdown-item.is-current { background: var(--lx-mint); border-color: var(--lx-edge); color: #000; }
.dropdown-item.is-current small { color: #222; }
.dropdown-item:disabled, .dropdown-item[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.dropdown-item .ui-icon { width: 17px; height: 17px; }
.columns-menu { display: grid; gap: 2px; padding: 2px 4px 6px; max-height: 280px; overflow: auto; }

/* 5 · Header widgets ----------------------------------------------------- */
.ws-toggle {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0; max-width: 260px; padding: 5px 10px 5px 6px;
  background: var(--lx-surface-2); color: var(--lx-text); border: 2px solid var(--lx-edge); border-radius: 5px;
  box-shadow: var(--nb-shadow-sm); cursor: pointer; text-align: left;
}
.ws-toggle:hover:enabled { background: var(--lx-yellow); color: #000; transform: translate(1px, 1px); box-shadow: none; }
.ws-toggle:hover:enabled small { color: #222; }
.ws-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.ws-text small { font-size: 13px; font-weight: 700; color: var(--lx-text-soft); }
.ws-text b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-toggle > .ui-icon { width: 15px; height: 15px; }
.ws-menu { min-width: 260px; }
.theme-icon { display: inline-flex; }
.theme-icon--dark { display: none; }
[data-theme="dark"] .theme-icon--light { display: none; }
[data-theme="dark"] .theme-icon--dark { display: inline-flex; }
.search-btn { width: auto; padding: 0 10px; gap: 10px; }
.search-btn kbd { font-size: 10.5px; }
.notif-badge {
  position: absolute; top: -9px; right: -9px; min-width: 20px; height: 20px; padding: 0 5px; display: flex;
  align-items: center; justify-content: center; border: 2px solid var(--lx-edge); border-radius: 10px;
  background: #ff6e63; color: #000; font-size: 11px; font-weight: 800; line-height: 1;
}
.notif-menu { width: min(380px, 92vw); }
.notif-list { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow: auto; display: grid; gap: 2px; }
.notif-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border: 2px solid transparent; border-radius: 5px; color: var(--lx-text); }
.notif-item:hover { background: var(--lx-yellow); border-color: var(--lx-edge); color: #000; }
.notif-item:hover small, .notif-item:hover .notif-text span { color: #222; }
.notif-item .status-dot { margin-top: 5px; }
.notif-text { display: flex; flex-direction: column; gap: 2px; font-size: 13px; min-width: 0; }
.notif-text b { font-size: 14px; }
.notif-text small { font-size: 13px; color: var(--lx-text-soft); }
.notif-text span { color: var(--lx-text-soft); font-weight: 600; }
.notif-more { margin: 4px 10px; font-size: 13px; color: var(--lx-text-soft); }
.notif-empty { display: flex; gap: 10px; align-items: center; margin: 0; padding: 14px 10px; font-weight: 700; font-size: 14px; }
.avatar-toggle { padding: 0; background: none; border: 0; border-radius: 50%; box-shadow: none; cursor: pointer; display: inline-flex; }
.avatar-toggle:hover:enabled { transform: none; box-shadow: none; background: none; }
.avatar-toggle:focus-visible .avatar { box-shadow: var(--ring); }
.account-menu { min-width: 250px; }
.account-head { display: flex; align-items: center; gap: 12px; padding: 8px 10px; }
.account-head b { display: block; font-size: 15px; }
.account-head small { color: var(--lx-text-soft); font-weight: 700; font-size: 13px; }

/* 6 · Command palette ---------------------------------------------------- */
dialog.palette {
  padding: 0; border: 0; background: transparent; width: min(640px, calc(100vw - 24px)); max-width: none;
  margin: 12vh auto auto; max-height: 76vh; overflow: visible; color: var(--lx-text);
}
dialog.palette::backdrop, dialog.modal::backdrop { background: rgba(0, 0, 0, 0.55); }
.palette-card {
  display: flex; flex-direction: column; max-height: 76vh; background: var(--lx-surface);
  border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: var(--nb-shadow-lg);
}
.palette-search { display: flex; align-items: center; gap: 10px; margin: 0; padding: 10px 14px; border-bottom: 2px solid var(--lx-edge); }
.palette-search .ui-icon { color: var(--lx-text-soft); }
.palette-search input, .palette-search input:focus {
  border: 0; box-shadow: none; background: transparent; height: 36px; padding: 0; margin: 0; font-size: 16px; color: var(--lx-text);
}
.palette-list { overflow: auto; padding: 8px; }
.palette-group { margin: 10px 8px 4px; font-size: 13px; font-weight: 800; letter-spacing: 1.4px; color: var(--lx-text-soft); }
.palette-item {
  display: flex; align-items: center; justify-content: flex-start; gap: 10px; width: 100%; padding: 9px 10px;
  border: 2px solid transparent; border-radius: 5px; background: transparent; color: var(--lx-text);
  font-size: 14px; font-weight: 700; text-align: left; cursor: pointer; box-shadow: none;
}
.palette-item small { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--lx-text-soft); }
.palette-item.is-active, .palette-item:hover:enabled { background: var(--lx-yellow); border-color: var(--lx-edge); color: #000; transform: none; box-shadow: none; }
.palette-item.is-active small, .palette-item:hover small { color: #222; }
.palette-badge {
  width: 22px; height: 22px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  border: 2px solid var(--lx-edge); border-radius: 5px; background: var(--lx-mint); color: #000; font-size: 9.5px; font-weight: 800;
}
.palette-empty { margin: 0; padding: 18px; text-align: center; color: var(--lx-text-soft); }
.palette-foot { display: flex; gap: 18px; padding: 10px 14px; border-top: 2px solid var(--lx-edge); font-size: 13px; color: var(--lx-text-soft); }
.palette-foot kbd { margin-right: 2px; }

/* 7 · Modal and drawer --------------------------------------------------- */
dialog.modal {
  padding: 0; border: 0; background: transparent; color: var(--lx-text); width: min(560px, calc(100vw - 24px));
  max-width: none; max-height: calc(100vh - 32px); overflow: visible;
}
dialog.modal--sm { width: min(420px, calc(100vw - 24px)); }
dialog.modal--lg { width: min(820px, calc(100vw - 24px)); }
dialog.modal[open] { animation: modal-in 0.14s ease-out; }
.modal-card {
  display: flex; flex-direction: column; max-height: calc(100vh - 32px); background: var(--lx-surface);
  border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: var(--nb-shadow-lg);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px; border-bottom: 2px solid var(--lx-edge); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-head p { margin: 4px 0 0; font-size: 13px; color: var(--lx-text-soft); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 14px 20px; border-top: 2px solid var(--lx-edge); background: var(--lx-surface-2); }
dialog.drawer { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(460px, 100vw); }
dialog.drawer--left { margin: 0 auto 0 0; }
dialog.drawer .modal-card { height: 100%; max-height: none; border-radius: 0; border-width: 0 0 0 2px; box-shadow: none; }
dialog.drawer--left .modal-card { border-width: 0 2px 0 0; }
dialog.drawer[open] { animation: drawer-in 0.18s ease-out; }
dialog.drawer--left[open] { animation-name: drawer-in-left; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes drawer-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes drawer-in-left { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* 8 · Page header -------------------------------------------------------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 14px 20px; margin: 0 0 22px; }
.page-header-main { min-width: 0; }
.page-header-title { margin: 0; font-size: 26px; line-height: 1.2; letter-spacing: -0.5px; }
.page-header-sub { margin: 4px 0 0; font-size: 14px; color: var(--lx-text-soft); }
.page-header-eyebrow { margin: 0 0 4px; font-size: 13px; font-weight: 800; letter-spacing: 1.6px; color: var(--lx-text-soft); }
.page-header-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 0 0 6px; font-size: 13px; font-weight: 700; color: var(--lx-text-soft); }
.crumbs a { color: var(--lx-text-soft); }
.crumbs a:hover { color: var(--lx-text); text-decoration: underline; }
.crumbs b { color: var(--lx-text); }
.crumbs .ui-icon { width: 14px; height: 14px; }
.view-toggle { display: inline-flex; background: var(--lx-surface); border: 2px solid var(--lx-edge); border-radius: 5px; overflow: hidden; box-shadow: var(--nb-shadow-sm); }
.view-toggle .icon-btn { height: 36px; width: 40px; border: 0; border-radius: 0; box-shadow: none; }
.view-toggle .icon-btn + .icon-btn { border-left: 2px solid var(--lx-edge); }
.view-toggle .icon-btn:hover:enabled { transform: none; }

/* 9 · Cards, stat cards, detail lists, settings rows --------------------- */
.card { min-width: 0; background: var(--lx-surface); color: var(--lx-text); border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: var(--nb-shadow); }
.card--mint { background: var(--lx-mint); }
.card--yellow { background: var(--lx-yellow); }
.card--red { background: var(--lx-red); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 2px solid var(--lx-edge); }
.card-heading h2 { margin: 0; font-size: 17px; line-height: 1.3; }
.card-heading p { margin: 2px 0 0; font-size: 13px; color: var(--lx-text-soft); }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 18px; }
.card-body.is-flush { padding: 0; }
.card-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 12px 18px; border-top: 2px solid var(--lx-edge); background: var(--lx-surface-2); border-radius: 0 0 6px 6px; }
.card--mint .card-footer, .card--yellow .card-footer, .card--red .card-footer { background: rgba(255, 255, 255, 0.35); }

.stat-card {
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px 14px; align-items: center;
  padding: 16px; background: var(--lx-surface); color: var(--lx-text); border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: var(--nb-shadow);
}
a.stat-card { transition: transform 0.1s ease-out, box-shadow 0.1s ease-out; }
a.stat-card:hover { transform: translate(2px, 2px); box-shadow: none; color: var(--lx-text); }
.stat-icon { width: 48px; height: 48px; display: inline-flex; align-items: center; justify-content: center; border: 2px solid var(--lx-edge); border-radius: 6px; background: var(--lx-mint); color: #000; }
.stat-icon .ui-icon { width: 22px; height: 22px; }
.stat-card--yellow .stat-icon { background: var(--lx-yellow); }
.stat-card--red .stat-icon { background: var(--lx-red); }
.stat-card--blue .stat-icon { background: var(--lx-blue); }
.stat-card--purple .stat-icon { background: var(--lx-purple); }
.stat-card--gray .stat-icon { background: var(--lx-gray); }
.stat-body { display: flex; flex-direction: column; min-width: 0; }
.stat-label { font-size: 13px; font-weight: 700; color: var(--lx-text-soft); }
.stat-value { font-size: 30px; line-height: 1.1; font-weight: 800; letter-spacing: -0.5px; }
.stat-hint { font-size: 13px; color: var(--lx-text-soft); margin-top: 2px; }
.stat-delta { align-self: start; }
.stat-spark { grid-column: 1 / -1; display: block; }
.stat-spark .chart { width: 100%; height: 36px; }

.detail-list { margin: 0; display: grid; }
.detail-row { display: grid; grid-template-columns: minmax(110px, 38%) minmax(0, 1fr); gap: 12px; padding: 10px 0; border-bottom: 2px dashed var(--lx-line); }
.detail-row:first-child { padding-top: 0; }
.detail-row:last-child { border-bottom: 0; padding-bottom: 0; }
.detail-row dt { font-size: 13px; font-weight: 700; color: var(--lx-text-soft); }
.detail-row dd { margin: 0; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.settings-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px; padding: 16px 0; border-bottom: 2px dashed var(--lx-line); }
.settings-row:first-child { padding-top: 0; }
.settings-row:last-child { border-bottom: 0; padding-bottom: 0; }
.settings-row-text { min-width: 0; flex: 1 1 280px; }
.settings-row-text strong { font-size: 15px; }
.settings-row-text p { margin: 3px 0 0; font-size: 13px; color: var(--lx-text-soft); }
.settings-row-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* 10 · Chips and avatars ------------------------------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border: 2px solid var(--lx-edge); border-radius: 5px;
  background: var(--lx-gray); color: #000; font-size: 13px; font-weight: 800; line-height: 1.4; white-space: nowrap;
}
.chip .ui-icon { width: 13px; height: 13px; }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: #000; }
.chip--success { background: var(--lx-mint); }
.chip--warning { background: var(--lx-yellow); }
.chip--danger { background: var(--lx-red); }
.chip--info { background: var(--lx-blue); }
.chip--purple { background: var(--lx-purple); }
.chip--neutral { background: var(--lx-gray); }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; overflow: hidden;
  /* Paint containment stops Chrome leaking this inline-flex box's scrollable
     overflow through table cells to the root, which made whole pages scrollable. */
  contain: paint;
  border: 2px solid var(--lx-edge); border-radius: 50%; color: #000; font-weight: 800; line-height: 1; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar--xs { width: 24px; height: 24px; font-size: 10px; }
.avatar--sm { width: 32px; height: 32px; font-size: 12px; }
.avatar--md { width: 40px; height: 40px; font-size: 14px; }
.avatar--lg { width: 52px; height: 52px; font-size: 18px; }
.avatar--xl { width: 76px; height: 76px; font-size: 26px; }
.avatar--c0 { background: var(--lx-mint); }
.avatar--c1 { background: var(--lx-yellow); }
.avatar--c2 { background: var(--lx-red); }
.avatar--c3 { background: var(--lx-blue); }
.avatar--c4 { background: var(--lx-purple); }
.avatar--c5 { background: #ffb36b; }
.avatar--c6 { background: #7fe3e0; }
.avatar--c7 { background: #f9a8d4; }

/* 11 · Tabs and pagination ----------------------------------------------- */
.tabs { display: flex; gap: 6px; margin: 0 0 18px; overflow-x: auto; overflow-y: hidden; border-bottom: 2px solid var(--lx-edge); scrollbar-width: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; margin-bottom: -2px; white-space: nowrap;
  border: 2px solid transparent; border-bottom: 0; border-radius: 5px 5px 0 0; background: transparent;
  color: var(--lx-text); font-size: 14px; font-weight: 700; cursor: pointer; box-shadow: none;
}
.tab .ui-icon { width: 16px; height: 16px; }
.tab:hover:enabled, a.tab:hover { background: var(--lx-yellow); border-color: var(--lx-edge); color: #000; transform: none; box-shadow: none; }
.tab.is-active, .tab.is-active:hover:enabled { background: var(--lx-mint); border-color: var(--lx-edge); color: #000; }
.tab-count { padding: 0 6px; border: 2px solid var(--lx-edge); border-radius: 4px; background: var(--lx-surface); color: var(--lx-text); font-size: 13px; }
.tab:hover .tab-count, .tab.is-active .tab-count { background: #fff; color: #000; border-color: #000; }
.tab-pane { padding-top: 2px; }

.pagination-bar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 12px; min-height: 44px; padding: 6px 14px; border-top: 2px solid var(--lx-edge); font-variant-numeric: tabular-nums; }
.pagination-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; }
.pagination-info { margin: 0; font-size: 13px; color: var(--lx-text-soft); }
.pagination-info b { color: var(--lx-text); }
.page-size-group { display: inline-flex; align-items: center; }
.page-size-group .ui-select-field { width: auto; }
.page-size-group .ui-select { min-width: 122px; }
.page-size-group .ui-select-option-label { white-space: nowrap; }
.page-size-group .ui-select-trigger { min-height: 30px; height: 30px; padding: 2px 8px; font-size: 13px; font-weight: 800; }
/* The pager sits at the bottom of a card, so its menu opens upward, over the table. */
.page-size-group .ui-select-popover { top: auto; bottom: calc(100% + 6px); right: auto; min-width: 176px; }
.page-size-group .ui-select-option { gap: 16px; padding: 7px 12px; }
.page-size-group .ui-select-option-label { font-size: 14px; font-weight: 700; }
.pagination { display: flex; flex-wrap: wrap; gap: 4px; }
.page-link {
  min-width: 30px; height: 30px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--lx-edge); border-radius: 5px; background: var(--lx-surface); color: var(--lx-text); font-size: 13px; font-weight: 800;
}
a.page-link:hover { background: var(--lx-yellow); color: #000; }
.page-link.is-current { background: var(--lx-mint); color: #000; box-shadow: var(--nb-shadow-sm); }
.page-link.is-disabled { opacity: 0.4; }
.page-link .ui-icon { width: 14px; height: 14px; }
.page-gap { align-self: center; padding: 0 2px; font-weight: 800; }
[data-paginate-region] { scroll-margin-top: 84px; }
[data-paginate-region].is-loading .pagination-bar { opacity: 0.6; pointer-events: none; }
.data-table td, .stat-value { font-variant-numeric: tabular-nums; }

/* 12 · Data toolbar, tables, grid view, skeleton ------------------------- */
.data-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 2px solid var(--lx-edge);
}
.toolbar-search {
  position: relative;
  display: block;
  flex: 0 1 240px;
  max-width: 250px;
  min-width: 170px;
  margin: 0;
}
.toolbar-search .ui-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  color: var(--lx-text-soft);
  pointer-events: none;
}
.toolbar-search input {
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  box-sizing: border-box;
  padding: 0 10px 0 32px;
  margin: 0;
  font-size: 13.5px;
  border: 2px solid var(--lx-edge);
  border-radius: 5px;
  box-shadow: var(--nb-shadow-sm);
  background: var(--lx-surface);
  color: var(--lx-text);
  line-height: 34px;
}
.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.toolbar-filters .ui-select-field {
  min-width: 120px;
  max-width: 185px;
  width: auto;
  margin: 0;
  flex: 0 1 auto;
}
.toolbar-filters .ui-select-trigger {
  height: 38px;
  min-height: 38px !important;
  max-height: 38px;
  box-sizing: border-box;
  padding: 0 8px 0 10px;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 600;
  border: 2px solid var(--lx-edge);
  border-radius: 5px;
  box-shadow: var(--nb-shadow-sm);
  background: var(--lx-surface);
  color: var(--lx-text);
  line-height: 34px;
}
.toolbar-filters .ui-select-trigger-main {
  flex-wrap: nowrap;
  gap: 6px;
}
.toolbar-filters .ui-select-value {
  font-size: 13.5px;
  line-height: 1.2;
}
.toolbar-filters .ui-select-chevron {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toolbar-filters .ui-select-chevron .ui-icon {
  width: 14px;
  height: 14px;
}
.toolbar-filters .ui-select-popover {
  min-width: max(100%, 240px);
}

/* Unified medium height and styling across data-toolbar buttons */
.data-toolbar .secondary,
.data-toolbar button.primary,
.data-toolbar .button,
.data-toolbar button[type="submit"] {
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  box-sizing: border-box;
  padding: 0 13px;
  font-size: 13.5px;
  font-weight: 700;
  gap: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--lx-edge);
  border-radius: 5px;
  box-shadow: var(--nb-shadow-sm) !important;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.1s ease-out, box-shadow 0.1s ease-out, background-color 0.1s;
}
.data-toolbar .secondary .ui-icon,
.data-toolbar button .ui-icon,
.data-toolbar .button .ui-icon {
  width: 15px;
  height: 15px;
}
.data-toolbar .secondary:hover:enabled,
.data-toolbar button.primary:hover:enabled,
.data-toolbar .button:hover:enabled,
.data-toolbar button[type="submit"]:hover:enabled {
  transform: translate(1px, 1px);
  box-shadow: none !important;
}

.toolbar-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
.toolbar-tools .btn-menu,
.toolbar-tools .btn-ghost {
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  box-sizing: border-box;
  padding: 0 10px;
  font-size: 13.5px;
  font-weight: 700;
  gap: 6px;
  border: 2px solid var(--lx-edge);
  border-radius: 5px;
  box-shadow: var(--nb-shadow-sm);
}
.toolbar-tools .btn-menu .ui-icon {
  width: 15px;
  height: 15px;
}
.toolbar-tools .icon-btn {
  width: 38px;
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  box-sizing: border-box;
  padding: 0;
  border: 2px solid var(--lx-edge);
  border-radius: 5px;
  box-shadow: var(--nb-shadow-sm);
}
.toolbar-tools .icon-btn .ui-icon {
  width: 16px;
  height: 16px;
}
.toolbar-tools .btn-menu:hover:enabled,
.toolbar-tools .icon-btn:hover:enabled {
  transform: translate(1px, 1px);
  box-shadow: none;
}
.data-toolbar .view-toggle {
  height: 38px;
  box-sizing: border-box;
}
.data-toolbar .view-toggle .icon-btn {
  height: 34px;
  width: 36px;
}
/* Tables take the viewport space left after the shell chrome above and below them
   (app header, page heading, toolbar, pagination bar). Rows beyond that scroll
   inside the wrap, so a 50/100-row page no longer stretches the whole page. */
.table-wrap {
  width: 100%; overflow: auto; -webkit-overflow-scrolling: touch;
  max-height: max(280px, calc(100dvh - 400px));
  overscroll-behavior: contain; scrollbar-width: thin;
}
/* Legacy sheets put overflow:hidden on some tables; that kills the sticky header. */
.table-wrap .data-table { overflow: visible; }
.data-table thead th { position: sticky; top: 0; z-index: 2; box-shadow: inset 0 -2px 0 var(--lx-edge); }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; color: var(--lx-text); }
.data-table th {
  padding: 12px 16px; text-align: left; white-space: nowrap; font-size: 13px; font-weight: 800; letter-spacing: 0.6px;
  text-transform: uppercase; color: var(--lx-text); background: var(--lx-surface-2); border-bottom: 2px solid var(--lx-edge);
}
.data-table th[data-sort] { cursor: pointer; user-select: none; }
.data-table th[data-sort]::after { content: "↕"; margin-left: 6px; opacity: 0.4; }
.data-table th[aria-sort="ascending"]::after { content: "↑"; opacity: 1; }
.data-table th[aria-sort="descending"]::after { content: "↓"; opacity: 1; }
.data-table th:focus-visible { outline: none; box-shadow: inset var(--ring); }
.data-table td { padding: 12px 16px; vertical-align: middle; border-bottom: 2px solid var(--lx-line); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: var(--lx-surface-2); }
.data-table .col-actions { width: 1%; text-align: right; white-space: nowrap; }
.data-table td small, .cell-entity small { display: block; color: var(--lx-text-soft); font-size: 13px; }
.cell-entity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-entity b, .cell-entity a { font-weight: 800; }
.table-empty { margin: 0; padding: 32px 18px; text-align: center; color: var(--lx-text-soft); font-weight: 700; }
.entity-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; padding: 18px; }
.entity-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; background: var(--lx-surface); color: var(--lx-text); border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: var(--nb-shadow-sm); }
.entity-card-head { display: flex; align-items: center; gap: 12px; }
.entity-card-head > div:nth-child(2) { flex: 1 1 auto; min-width: 0; }
.entity-card-head b { display: block; font-size: 15px; }
.entity-card-head small { color: var(--lx-text-soft); font-size: 13px; }
.entity-meta { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; color: var(--lx-text-soft); font-weight: 600; }

.skeleton {
  display: block; border: 2px solid var(--lx-line); border-radius: 5px;
  background: linear-gradient(90deg, var(--lx-surface-3) 25%, var(--lx-surface-2) 37%, var(--lx-surface-3) 63%);
  background-size: 400% 100%; animation: skeleton-shimmer 1.4s ease infinite;
}
.skeleton--line { height: 14px; width: 100%; }
.skeleton--w40 { width: 40%; }
.skeleton--w60 { width: 60%; }
.skeleton--w80 { width: 80%; }
.skeleton--avatar { width: 44px; height: 44px; border-radius: 50%; }
.skeleton--block { height: 56px; width: 100%; }
.skeleton-text { display: grid; gap: 10px; }
.skeleton-card { display: grid; gap: 10px; padding: 16px; background: var(--lx-surface); border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: var(--nb-shadow-sm); }
@keyframes skeleton-shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* 13 · Charts ------------------------------------------------------------ */
.chart { display: block; max-width: 100%; height: auto; }
.chart-track { stroke: var(--lx-surface-3); }
.chart-edge, .chart-baseline { stroke: var(--lx-edge); }
.chart-bar { stroke: var(--lx-edge); }
.chart-text { fill: var(--lx-text); font-family: var(--font); }
.chart-area { opacity: 0.35; stroke: none; }
.chart-track-fill { fill: var(--lx-surface-3); }
.chart-stroke--mint { stroke: var(--lx-mint); } .chart-fill--mint { fill: var(--lx-mint); }
.chart-stroke--yellow { stroke: var(--lx-yellow); } .chart-fill--yellow { fill: var(--lx-yellow); }
.chart-stroke--red { stroke: var(--lx-red); } .chart-fill--red { fill: var(--lx-red); }
.chart-stroke--blue { stroke: var(--lx-blue); } .chart-fill--blue { fill: var(--lx-blue); }
.chart-stroke--purple { stroke: var(--lx-purple); } .chart-fill--purple { fill: var(--lx-purple); }
.chart-stroke--gray { stroke: var(--lx-gray); } .chart-fill--gray { fill: var(--lx-gray); }
.chart-line.chart-stroke--mint, .chart-line.chart-stroke--yellow, .chart-line.chart-stroke--red,
.chart-line.chart-stroke--blue, .chart-line.chart-stroke--purple, .chart-line.chart-stroke--gray { stroke: var(--lx-edge); }
.chart-progress { width: 100%; height: 16px; border: 2px solid var(--lx-edge); border-radius: 5px; }
.chart-progress .chart-bar { stroke: none; }
.progress-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 13px; font-weight: 700; }
.donut { display: flex; align-items: center; flex-wrap: wrap; gap: 24px; }
.donut-figure { position: relative; display: inline-flex; flex: 0 0 auto; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.donut-center strong { font-size: 26px; line-height: 1; }
.donut-center small { margin-top: 4px; font-size: 13px; color: var(--lx-text-soft); font-weight: 700; }
.legend { flex: 1 1 140px; list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 14px; font-weight: 700; }
.legend li { display: flex; align-items: center; gap: 10px; }
.legend b { margin-left: auto; }
.legend-swatch { width: 14px; height: 14px; display: inline-block; border: 2px solid var(--lx-edge); border-radius: 3px; flex: 0 0 auto; }
.legend-swatch.chart-fill--mint { background: var(--lx-mint); }
.legend-swatch.chart-fill--yellow { background: var(--lx-yellow); }
.legend-swatch.chart-fill--red { background: var(--lx-red); }
.legend-swatch.chart-fill--blue { background: var(--lx-blue); }
.legend-swatch.chart-fill--purple { background: var(--lx-purple); }
.legend-swatch.chart-fill--gray { background: var(--lx-gray); }
.bars, .spark { display: block; max-width: 100%; }

/* 14 · Form helpers and layout utilities -------------------------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0; min-width: 0; }
.field > span, .field-label { font-size: 13px; font-weight: 800; }
.field input, .field textarea { margin: 0; font-size: 14px; padding: 9px 12px; min-height: 42px; }
.field textarea { min-height: 96px; resize: vertical; width: 100%; font-family: var(--font); }
.field small { font-size: 13px; color: var(--lx-text-soft); }
.field abbr { color: var(--lx-danger-text); text-decoration: none; margin-left: 2px; }
.check-row { display: flex; align-items: center; gap: 10px; margin: 0; padding: 6px 8px; font-size: 14px; border-radius: 5px; cursor: pointer; }
.check-row input { width: auto; margin: 0; flex: 0 0 auto; }
.check-row:hover { background: var(--lx-yellow); color: #000; }
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.form-stack { display: grid; gap: 20px; min-width: 0; }
.ui-grid { display: grid; gap: 20px; }
.ui-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ui-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ui-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ui-grid--split { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stack-lg { display: grid; gap: 20px; }
.inline-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* 15 · Dark theme: legacy component fixes -------------------------------- */
[data-theme="dark"] .history-row b,
[data-theme="dark"] .ui-select-tag,
[data-theme="dark"] .token-panel dd,
[data-theme="dark"] .sql-plan,
[data-theme="dark"] .card-bottom, [data-theme="dark"] .card-bottom span, [data-theme="dark"] .card-bottom a { color: #000; }
[data-theme="dark"] .register-panel, [data-theme="dark"] .register-panel h2, [data-theme="dark"] .register-panel .muted { color: #000; }
[data-theme="dark"] .register-panel .muted { opacity: 0.85; }
[data-theme="dark"] .attention-panel { background: #3b1f1e; color: var(--lx-text); }
[data-theme="dark"] .attention-list a { color: #ffd2cd; }
[data-theme="dark"] .dash-group[open] > summary, [data-theme="dark"] .dash-group[open] > summary * { color: #000; }
[data-theme="dark"] .ui-select.is-open .ui-select-trigger, [data-theme="dark"] .ui-select-trigger:focus-visible,
[data-theme="dark"] .ui-select.is-open .ui-select-chevron, [data-theme="dark"] .ui-select.is-open .ui-select-prefix-icon { color: #000; }
[data-theme="dark"] .ui-select-option:hover:not(.is-disabled), [data-theme="dark"] .ui-select-option.is-focused:not(.is-disabled),
[data-theme="dark"] .ui-select-option.is-selected, [data-theme="dark"] .ui-select-option.is-selected * ,
[data-theme="dark"] .ui-select-option:hover:not(.is-disabled) *, [data-theme="dark"] .ui-select-option.is-focused * { color: #000; }
[data-theme="dark"] .ui-select-trigger-badge, [data-theme="dark"] .ui-select-option-badge { color: var(--lx-text); }
[data-theme="dark"] .ui-select-popover { color: var(--lx-text); }
[data-theme="dark"] .ui-select-option-sublabel, [data-theme="dark"] .ui-select-count { color: var(--lx-text-soft); }
[data-theme="dark"] .ui-select-value.is-placeholder { color: var(--lx-text-soft); }
[data-theme="dark"] .plants-table th { color: #000; }
[data-theme="dark"] .plants-table td { color: var(--lx-text); }
[data-theme="dark"] .history-item:hover, [data-theme="dark"] .data-table tbody tr:hover { background: var(--lx-surface-2); }
[data-theme="dark"] .status-dot { background: var(--lx-surface-3); }
[data-theme="dark"] .status-dot.is-online { background: var(--lx-mint-strong); }
[data-theme="dark"] .status-dot.is-offline { background: #ff6e63; }
[data-theme="dark"] .muted, [data-theme="dark"] .mini-modules span, [data-theme="dark"] .station-meta span, [data-theme="dark"] .host { color: var(--lx-text-soft); }
[data-theme="dark"] .eyebrow { color: #000; }
[data-theme="dark"] .workspace-panel a { color: var(--lx-text); background-image: linear-gradient(transparent 60%, rgba(255, 220, 88, 0.45) 60%); }
[data-theme="dark"] .token-panel dt, [data-theme="dark"] .back-link { color: var(--lx-text); }
[data-theme="dark"] .back-link:hover { color: #000; }
[data-theme="dark"] .empty { background: var(--lx-surface-2); color: var(--lx-text); }
[data-theme="dark"] .confirm-modal::backdrop { background: rgba(0, 0, 0, 0.7); }
[data-theme="dark"] .login-intro .lede, [data-theme="dark"] .login-intro h1 { color: var(--lx-text); }
[data-theme="dark"] .topbar { background: var(--lx-surface); }
[data-theme="dark"] .brand { color: var(--lx-text); }
[data-theme="dark"] .brand-mark { color: #000; }
[data-theme="dark"] .alert, [data-theme="dark"] .observe, [data-theme="dark"] .danger { color: #000; }
[data-theme="dark"] pre { background: #0b0c0f; border-color: var(--lx-edge); }
[data-theme="dark"] .card--mint input, [data-theme="dark"] .card--yellow input, [data-theme="dark"] .card--red input,
[data-theme="dark"] .card--mint textarea, [data-theme="dark"] .card--yellow textarea, [data-theme="dark"] .card--red textarea {
  --lx-text: #f4f0e4; --lx-text-soft: #b8b3a4; color: #f4f0e4;
}
[data-theme="dark"] .command-id { color: var(--lx-text-soft); }
[data-theme="dark"] .module-detail { background: var(--lx-surface-2); }
[data-theme="dark"] a:hover { color: var(--lx-text); }
[data-theme="dark"] .chip, [data-theme="dark"] .avatar, [data-theme="dark"] .palette-badge, [data-theme="dark"] .notif-badge { color: #000; }

/* 16 · Responsive -------------------------------------------------------- */
@media (max-width: 1200px) {
  .ui-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ui-grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-layout, .ui-grid--split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1000px) {
  :root { --shell-gap: 12px; }
  .app-sidebar { width: min(300px, 86vw); transform: translateX(calc(-100% - 24px)); z-index: 50; }
  html[data-nav="open"] .app-sidebar { transform: none; }
  html[data-nav="open"] .app-scrim { display: block; }
  .app-content { margin-left: 0; padding: var(--shell-gap); }
  .app-burger { display: inline-flex; }
  .sb-close { display: inline-flex; }
  .sb-collapse { display: none; }
  .app-header-spacer { display: none; }
  .ws-switch { margin-right: auto; min-width: 0; }
  .app-shell .app-main { padding-top: 18px; }
}
@media (max-width: 700px) {
  .ui-grid--2, .ui-grid--3, .ui-grid--4, .form-grid { grid-template-columns: minmax(0, 1fr); }
  .search-btn kbd, .ws-text small { display: none; }
  .app-header { padding: 6px 10px; gap: 8px; }
  .app-header-tools { gap: 6px; }
  .ws-toggle { max-width: 150px; }
  .page-header { align-items: flex-start; }
  .page-header-actions { width: 100%; }
  .page-header-title { font-size: 22px; }
  .toolbar-search { max-width: none; flex-basis: 100%; }
  .toolbar-tools { margin-left: 0; }
  .table-wrap { max-height: max(240px, 55dvh); }
  .detail-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  dialog.palette { margin-top: 6vh; }
  .modal-body { padding: 16px; }
  .notif-menu, .ws-menu, .account-menu { position: fixed; top: 80px; right: 12px; left: 12px; width: auto; max-width: none; }
  .stat-card { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .app-sidebar, .app-content, dialog.modal[open], dialog.drawer[open], .skeleton { transition: none; animation: none; }
}

/* 17 · Print ------------------------------------------------------------- */
@media print {
  .table-wrap, .fit-card .table-wrap { max-height: none !important; height: auto !important; overflow: visible; }
  .app-sidebar, .app-header, .app-scrim, .app-footer, .page-header-actions, .data-toolbar, .pagination-bar, dialog { display: none !important; }
  .app-content { margin: 0; padding: 0; }
  html, body { background: #fff !important; }
  .card, .stat-card { box-shadow: none; }
}

/* 18 · UI kit page (templates/ui_kit.html) ------------------------------- */
.kit-nav { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
.kit-nav a { padding: 5px 12px; border: 2px solid var(--lx-edge); border-radius: 5px; background: var(--lx-surface); font-size: 13px; font-weight: 800; color: var(--lx-text); }
.kit-nav a:hover { background: var(--lx-yellow); color: #000; }
.kit-section { margin: 0 0 34px; scroll-margin-top: 96px; }
.kit-section > h2 { margin: 0 0 4px; font-size: 20px; }
.kit-section > p { margin: 0 0 14px; font-size: 13.5px; color: var(--lx-text-soft); }
.kit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.kit-scope { padding: 18px; border: 2px dashed var(--lx-edge); border-radius: 8px; background: var(--lx-bg); color: var(--lx-text); }
.kit-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.kit-swatch { height: 64px; display: flex; align-items: flex-end; padding: 6px 8px; border: 2px solid var(--lx-edge); border-radius: 6px; box-shadow: var(--nb-shadow-sm); font-size: 13px; font-weight: 800; color: #000; }
.kit-swatch--mint { background: var(--lx-mint); } .kit-swatch--yellow { background: var(--lx-yellow); } .kit-swatch--red { background: var(--lx-red); }
.kit-swatch--blue { background: var(--lx-blue); } .kit-swatch--purple { background: var(--lx-purple); } .kit-swatch--gray { background: var(--lx-gray); }
.kit-swatch--surface { background: var(--lx-surface); color: var(--lx-text); } .kit-swatch--surface2 { background: var(--lx-surface-2); color: var(--lx-text); }

/* --- Review fixes (phase 1) ------------------------------------------------
   .icon-btn sets display later in this file, so the mobile-only buttons need a
   more specific selector to stay hidden on wide screens. */
.icon-btn.sb-close, .icon-btn.app-burger { display: none; }
.sb-logo-text { display: none; }
@media (max-width: 1000px) {
  .icon-btn.sb-close, .icon-btn.app-burger { display: inline-flex; }
  .icon-btn.sb-collapse { display: none; }
}

/* --- Review fixes (phase 2) ------------------------------------------------
   .ui-select-field is width:100% (control.css); inside a wrapping flex toolbar every
   dropdown then claimed a full row. Filters take a fixed basis and sit side by side. */
.toolbar-filters .ui-select-field,
.pl-log-filters .ui-select-field { width: auto; flex: 0 1 auto; min-width: 120px; max-width: 185px; }
.toolbar-filters .ui-select-label { display: none; }
@media (max-width: 700px) {
  .toolbar-filters, .toolbar-filters .ui-select-field { width: 100%; flex-basis: 100%; }
}
.data-table th:first-child, .data-table td:first-child { min-width: 250px; }
.data-table td:nth-child(2) { min-width: 170px; }
@media (max-width: 700px) {
  /* KPI cards stay two per row on phones instead of one very tall column. */
  .ui-grid:has(> .stat-card) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .ui-grid:has(> .stat-card) .stat-card { padding: 12px; gap: 8px 10px; }
  .ui-grid:has(> .stat-card) .stat-icon { width: 38px; height: 38px; }
  .ui-grid:has(> .stat-card) .stat-value { font-size: clamp(18px, 5vw, 24px); overflow-wrap: anywhere; }
  /* Wrap plant workspace tabs on phones so no tab is hidden off-screen. */
  .tabs { flex-wrap: wrap; overflow: visible; border-bottom: 0; gap: 8px; }
  .tab { min-height: 44px; padding: 8px 12px; margin-bottom: 0; border: 2px solid var(--lx-edge); border-radius: 5px; background: var(--lx-surface); }
}
.tabs::-webkit-scrollbar { display: none; }

/* Tooltip (neobrutalism tooltip: yellow bubble, hard border and shadow). Positioned by shell.js. */
.ui-tooltip { position: fixed; z-index: 200; max-width: min(320px, 90vw); padding: 6px 12px; font-size: 13px; font-weight: 700; line-height: 1.35; color: #000; background: var(--lx-yellow); border: 2px solid var(--lx-edge); border-radius: 8px; box-shadow: 1.5px 1.5px 0 0 var(--lx-edge); pointer-events: none; opacity: 0; transform: translateY(4px); transition: opacity .12s ease, transform .12s ease; }
.ui-tooltip.is-open { opacity: 1; transform: none; }
.ui-tooltip::after { content: ""; position: absolute; width: 10px; height: 10px; background: var(--lx-yellow); border: 2px solid var(--lx-edge); transform: rotate(45deg); }
.ui-tooltip--top::after { left: calc(50% - 5px); bottom: -7px; border-top: 0; border-left: 0; }
.ui-tooltip--bottom::after { left: calc(50% - 5px); top: -7px; border-bottom: 0; border-right: 0; }
.ui-tooltip--right::after { top: calc(50% - 5px); left: -7px; border-top: 0; border-right: 0; }
.tip-wrap { display: inline-flex; }
@media (prefers-reduced-motion: reduce) { .ui-tooltip { transition: none; } }

/* Toasts (neobrutalism.dev "Sonner" look): white card, 2px black border, hard 4px shadow, square icon chip. */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 12px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 12px; padding: 12px 12px 12px 14px; background: #fff; color: #000; border: 2px solid #000; border-radius: 5px; box-shadow: 2px 2px 0 0 #000; animation: toast-in 0.18s ease-out; }
.toast-icon { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border: 2px solid #000; border-radius: 5px; font-weight: 900; font-size: 15px; line-height: 1; background: #ffdc58; }
.toast--success .toast-icon { background: #7ee0a3; }
.toast--danger { background: #ffd9d4; }
.toast--danger .toast-icon { background: #ff8a80; }
.toast--warning .toast-icon { background: #ffdc58; }
.toast--info .toast-icon { background: #a8d1ff; }
.toast-body { flex: 1 1 auto; min-width: 0; }
.toast-title { display: block; font-size: 14.5px; font-weight: 800; line-height: 1.3; }
.toast-desc { margin: 2px 0 0; font-size: 13px; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; }
.toast-close { flex: none; width: 24px; height: 24px; padding: 0; display: grid; place-items: center; font-size: 18px; line-height: 1; background: #fff; color: #000; border: 2px solid #000; border-radius: 5px; box-shadow: none; }
.toast-close:hover:enabled { transform: none; background: #ffdc58; box-shadow: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
