/* ═══════════════════════════════════════════════════════
   Logirynx ERP — stylesheet
   Foundation: exact mockup CSS, adapted with CSS custom
   properties for light/dark theming.
   ═══════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ─────────────────────────── */
:root,
[data-theme="dark"] {
  --page-bg:        #0d0f17;
  --sidebar-bg:     #11131d;
  --card-bg:        #161926;
  --border:         rgba(255,255,255,0.10);
  --border-soft:    rgba(255,255,255,0.06);
  --border-field:   rgba(255,255,255,0.18);

  --text-primary:   #e2e4ec;
  --text-white:     #fff;
  --text-secondary: rgba(255,255,255,0.80);
  --text-muted:     rgba(255,255,255,0.58);
  --text-dim:       rgba(255,255,255,0.50);
  --text-faint:     rgba(255,255,255,0.44);
  --text-nav:       rgba(255,255,255,0.62);
  --text-nav-hover: rgba(255,255,255,0.92);

  --topbar-bg:      #11131d;
  --nav-active-bg:  rgba(124,92,219,0.22);
  --nav-active-clr: #b09aea;
  --nav-hover-bg:   rgba(255,255,255,0.07);

  --input-bg:       rgba(255,255,255,0.07);
  --input-border:   rgba(255,255,255,0.18);
  --input-color:    #fff;
  --input-ph:       rgba(255,255,255,0.40);

  --scrollbar-thumb: rgba(255,255,255,0.14);

  --notif-dot-border: #11131d;

  --inv-preview-bg:  #fff;
  --inv-preview-clr: #1a1a2e;

  /* ── Surface hover / subtle tint ── */
  --sidebar-hover:   rgba(255,255,255,0.06);
  --surface-tint:    rgba(255,255,255,0.03);
  --surface-pill:    rgba(255,255,255,0.12);
  --row-hover:       rgba(255,255,255,0.025);

  /* ── backward-compat aliases for older templates ── */
  --page-text-muted:     var(--text-muted);
  --page-text-secondary: var(--text-secondary);
  --page-text:           var(--text-primary);
  --card-border:         var(--border);
  --brand:               #7c5cdb;
  --brand-light:         #b09aea;
  --table-header-bg:     transparent;
}

[data-theme="light"] {
  --page-bg:        #f4f5f9;
  --sidebar-bg:     #fff;
  --card-bg:        #fff;
  --border:         rgba(0,0,0,0.12);
  --border-soft:    rgba(0,0,0,0.08);
  --border-field:   rgba(0,0,0,0.22);

  --text-primary:   #1a1c2e;
  --text-white:     #1a1c2e;
  --text-secondary: rgba(0,0,0,0.78);
  --text-muted:     rgba(0,0,0,0.62);
  --text-dim:       rgba(0,0,0,0.55);
  --text-faint:     rgba(0,0,0,0.48);
  --text-nav:       rgba(0,0,0,0.62);
  --text-nav-hover: rgba(0,0,0,0.90);

  --topbar-bg:      #fff;
  --nav-active-bg:  rgba(124,92,219,0.14);
  --nav-active-clr: #6b4ec8;
  --nav-hover-bg:   rgba(0,0,0,0.06);

  --input-bg:       rgba(0,0,0,0.04);
  --input-border:   rgba(0,0,0,0.22);
  --input-color:    #1a1c2e;
  --input-ph:       rgba(0,0,0,0.40);

  --scrollbar-thumb: rgba(0,0,0,0.18);

  --notif-dot-border: #fff;

  --inv-preview-bg:  #fff;
  --inv-preview-clr: #1a1a2e;

  /* ── Surface hover / subtle tint ── */
  --sidebar-hover:   rgba(0,0,0,0.06);
  --surface-tint:    rgba(0,0,0,0.03);
  --surface-pill:    rgba(0,0,0,0.09);
  --row-hover:       rgba(0,0,0,0.025);

  /* ── backward-compat aliases for older templates ── */
  --page-text-muted:     var(--text-muted);
  --page-text-secondary: var(--text-secondary);
  --page-text:           var(--text-primary);
  --card-border:         var(--border);
  --brand:               #7c5cdb;
  --brand-light:         #6b4ec8;
  --table-header-bg:     transparent;
}

/* ── Semantic accent colours — same in dark + light ───────────────── */
:root {
  --success: #5DCAA5;
  --warn:    #EF9F27;
  --danger:  #E24B4A;

  /* Semantic tints — use these for status pill/row backgrounds instead
     of inline rgba() literals, so the palette stays changeable in one
     place. -tint = subtle background wash; -tint-strong = border/emphasis. */
  --success-tint:        rgba(93,202,165,0.10);
  --success-tint-strong: rgba(93,202,165,0.25);
  --warn-tint:           rgba(239,159,39,0.10);
  --warn-tint-strong:    rgba(239,159,39,0.30);
  --danger-tint:         rgba(226,75,74,0.10);
  --danger-tint-strong:  rgba(226,75,74,0.25);
  --brand-tint:          rgba(124,92,219,0.12);
  --brand-tint-strong:   rgba(124,92,219,0.25);
}

/* Bootstrap primary color override */
:root {
  --bs-primary: #7c5cdb;
  --bs-primary-rgb: 124, 92, 219;
}

/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh; /* mobile: track the dynamic URL-bar viewport (fallback above) */
  display: flex;
  overflow: hidden;
  font-size: 14px;
}

a { text-decoration: none; color: inherit; }

/* ── Sidebar ────────────────────────────────────────── */
.sidebar {
  width: 224px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.logo-icon {
  width: 30px;
  height: 30px;
  background: #7c5cdb;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.logo-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-white);
  letter-spacing: -0.02em;
}

.logo-tenant {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 8px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 14px 8px 5px;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-nav);
  transition: background 0.12s, color 0.12s;
  margin-bottom: 1px;
  user-select: none;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--nav-hover-bg);
  color: var(--text-nav-hover);
}

.nav-item.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-clr);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 99px;
}

.badge-warn-nav  { background: rgba(239,159,39,0.18); color: #EF9F27; }
.badge-danger-nav{ background: rgba(226,75,74,0.18);  color: #E24B4A; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

/* ── Sidebar footer user row + dropdown ─────────────── */
.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
}

.user-row:hover { background: var(--nav-hover-bg); }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #7c5cdb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.user-name {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

.user-role {
  font-size: 11px;
  color: var(--text-muted);
}

/* Bootstrap dropup menu inside sidebar footer */
.sidebar-footer .dropdown-menu {
  min-width: 180px;
  background: var(--card-bg);
  border: 1px solid var(--border);
}
.sidebar-footer .dropdown-item {
  color: var(--text-secondary);
  font-size: 13px;
}
.sidebar-footer .dropdown-item:hover {
  background: var(--nav-hover-bg);
  color: var(--text-white);
}
.sidebar-footer .dropdown-divider {
  border-color: var(--border);
}

/* Mobile sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
}
.sidebar-overlay.visible { display: block; }

@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    left: -224px;
    top: 0;
    bottom: 0;
    z-index: 200;
    transition: left 0.2s;
  }
  .sidebar.open { left: 0; }
}

/* ── Main ───────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── Topbar ─────────────────────────────────────────── */
.topbar {
  height: 54px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}

.breadcrumb {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  background: transparent;
  list-style: none;
}

.breadcrumb .crumb-active {
  color: var(--text-secondary);
  font-weight: 500;
}

.topbar-spacer { flex: 1; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border-field);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--input-ph);
  width: 240px;
  cursor: text;
  position: relative;  /* anchor for the dropdown */
}

/* ── Search dropdown ─────────────────────────────────────────────── */
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 340px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  z-index: 1050;
  overflow: hidden;
  /* Origin-aware entrance: scales in from the input above it. Runs once
     each time display flips none→block; content swaps don't re-trigger. */
  transform-origin: top;
  animation: searchDropdownIn 150ms cubic-bezier(0.23, 1, 0.32, 1);
}

@keyframes searchDropdownIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
}

.search-dropdown-inner {
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  text-decoration: none;
  color: var(--page-text);
  transition: background 0.12s;
}

.search-result-item:hover {
  background: var(--sidebar-hover);
  color: var(--page-text);
}

.search-result-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 22px;
  text-align: center;
}

.search-result-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.search-result-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--page-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-sub {
  font-size: 11px;
  color: var(--page-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.search-result-type {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
}

.search-type-order   { background: rgba(76,175,80,0.15);  color: #66bb6a; }
.search-type-partner { background: rgba(33,150,243,0.15); color: #42a5f5; }
.search-type-ticket  { background: rgba(255,152,0,0.15);  color: #ffa726; }
.search-type-material{ background: rgba(156,39,176,0.15); color: #ab47bc; }

.search-no-results {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  font-size: 13px;
  color: var(--page-text-muted);
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
  width: 100%;
}

.search-box input::placeholder { color: var(--input-ph); }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border-field);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 15px;
  position: relative;
  color: var(--text-muted);
  text-decoration: none;
}

.icon-btn:hover { background: var(--nav-hover-bg); }

/* Small borderless icon button — row actions (kebab menus, inline ✎/✕
   replacements with templates/_icons.html). Formalizes the markup
   already used in order_list/category_list kebab buttons, which can now
   drop their inline styles. Always give it a title= / aria-label=. */
.icon-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.icon-btn-sm:hover { background: var(--nav-hover-bg); color: var(--text-secondary); }
.icon-btn-sm svg { display: block; flex-shrink: 0; }

.notif-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #E24B4A;
  border: 1.5px solid var(--notif-dot-border);
}

/* ── Scrollable content ─────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  scrollbar-gutter: stable; /* reserves scrollbar space so content width never shifts */
  padding: 24px;
  background: var(--page-bg);
}

/* ── Page header ────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-white);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Buttons ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.1s ease-out;
  white-space: nowrap;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: #7c5cdb; color: #fff; }
.btn-primary:hover { background: #6b4ec8; color: #fff; }

.btn-secondary {
  background: var(--input-bg);
  color: var(--text-secondary);
  border: 1px solid var(--border-field);
}
.btn-secondary:hover { background: var(--nav-hover-bg); color: var(--text-white); }

.btn-ghost {
  /* Standalone ghost button — includes all base .btn properties so elements
     using only class="btn-ghost" render correctly without also adding class="btn" */
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.1s ease-out;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-field);
}
.btn-ghost:hover { background: var(--nav-hover-bg); color: var(--text-white); border-color: var(--border); }
.btn-ghost:active { transform: scale(0.97); }

.btn-danger {
  background: rgba(226,75,74,0.12);
  color: #E24B4A;
  border: 1px solid rgba(226,75,74,0.2);
}

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Small ghost button — absorbs the repeated inline
   `font-size:12px;padding:4px 10px` pattern on .btn-ghost links
   (audit batch 7). Usage: class="btn-ghost btn-sm". The explicit
   compound selector makes the size win regardless of rule order. */
.btn-ghost.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Alert / alert-banner ───────────────────────────── */
.alert-banner,
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 13px;
  margin-bottom: 16px;
}

.alert-banner.danger,
.alert-danger {
  background: rgba(226,75,74,0.08);
  border: 1px solid rgba(226,75,74,0.2);
  color: var(--text-secondary);
}

.alert-banner.warn,
.alert-warn {
  background: rgba(239,159,39,0.08);
  border: 1px solid rgba(239,159,39,0.2);
  color: var(--text-secondary);
}

.alert-banner-icon,
.alert-icon { font-size: 16px; }

/* ── KPI cards ──────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* KPI band INSIDE a list card: a distinct "summary" zone with padding and a
   divider, separating the metrics from the filters/table below (list-screen
   hierarchy, 2026-06-19). Standalone kpi-grids (e.g. the dashboard) keep the
   default margin-based spacing above. */
.table-card .kpi-grid {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
/* When the KPI band is the last thing in the card (e.g. the inventory
   overview), drop the divider — nothing follows it to separate from. */
.table-card .kpi-grid:last-child { border-bottom: none; }

.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: inherit;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.1s ease-out;
}
@media (hover: hover) and (pointer: fine) {
  .kpi-card:hover { border-color: rgba(124,92,219,0.4); box-shadow: 0 2px 12px rgba(0,0,0,0.12); }
}
.kpi-card:active { transform: scale(0.99); }

/* Dashboard sparkline: full-width row below icon+text */
.kpi-card > .kpi-spark {
  flex: 0 0 100%;
  margin-top: 0;
}

.kpi-icon-row {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  margin-bottom: 0;
}

.kpi-body {
  flex: 1;
  min-width: 0;
}

.kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}
.kpi-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
  flex-shrink: 0;
}

.kpi-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-white);
  line-height: 1;
}

.kpi-trend {
  font-size: 12px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.trend-up     { color: #5DCAA5; }
.trend-down   { color: #E24B4A; }
.trend-neutral{ color: var(--text-muted); }

/* ── Tables ─────────────────────────────────────────── */
.table-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.03);
}

.table-toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.table-toolbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.toolbar-spacer { flex: 1; }

.filter-tabs {
  display: flex;
  flex-wrap: wrap; /* long strips (products_list) wrap instead of squishing;
                      lets _module_subnav.html absorb the old inline
                      style="flex-wrap:wrap" without a param */
  gap: 2px;
}

.ftab {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
  border: none;
  background: transparent;
  text-decoration: none;
  display: inline-block;
}

.ftab:hover { color: var(--text-secondary); }
.ftab.active { background: var(--nav-active-bg); color: var(--nav-active-clr); }

/* ── Module-level navigation tabs (page navigation, not filters) ──── */
/* Visually heavier than .ftab — underline indicator, not background pill */
.module-tabs {
  display: flex;
  gap: 0;
}

.mtab {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.12s;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  margin-bottom: -1px; /* overlap the container border-bottom */
}

.mtab:hover { color: var(--text-secondary); }
.mtab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}
[data-theme="light"] .mtab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Toolbar variant with module tabs: no extra border-bottom on toolbar,
   the tab underline provides the visual separation */
.table-toolbar.module-nav {
  padding-bottom: 0;
  gap: 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: nowrap;
  overflow-x: auto;
}

/* ── Invoice chip (orders list) ───────────────────────────────────── */
.invoice-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  padding: 3px 0;
}
.invoice-chip:hover .invoice-num { text-decoration: underline; }
.invoice-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge-xs {
  font-size: 10px !important;
  padding: 2px 6px !important;
  line-height: 1.2 !important;
}

/* Larger badge for page headers (order/invoice detail status) */
.badge-lg {
  font-size: 13px;
  padding: 4px 10px;
}

/* ── Numeric alignment ───────────────────────────────────────────────
   tabular-nums keeps digits a fixed width so amount columns and KPI
   values don't jiggle between rows/updates. */
.num,
.kpi-value,
.stat-mini-value,
.aging-count,
.aging-amount {
  font-variant-numeric: tabular-nums;
}
td.num { text-align: right; font-weight: 600; white-space: nowrap; }
.num-unit { color: var(--text-dim); font-weight: 400; font-size: 0.85em; }

/* ── Due chip (relative delivery/due dates with severity dot) ──────── */
.due-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  white-space: nowrap;
}
.due-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}
.due-danger { color: var(--danger); font-weight: 600; }
.due-danger .due-dot { background: var(--danger); }
.due-warn { color: var(--warn); font-weight: 600; }
.due-warn .due-dot { background: var(--warn); }
.due-none { color: var(--text-muted); }

/* Signed quantities (stock movements ledger) */
.qty-pos { color: var(--success) !important; }
.qty-neg { color: var(--danger) !important; }

/* Warehouse utilization mini-bar */
.util-bar-track {
  background: var(--surface-pill);
  border-radius: 4px;
  height: 6px;
  width: 90px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}
.util-bar { height: 100%; border-radius: 4px; background: var(--brand); }

/* QC pass-rate trend mini-bars */
.trend-bars { display: flex; align-items: flex-end; gap: 3px; height: 28px; margin-top: 10px; }
.trend-bars span {
  flex: 1;
  border-radius: 2px 2px 0 0;
  background: var(--brand);
  opacity: 0.75;
  min-height: 2px;
}

/* ── KPI sparkline + money-first tiles ──────────────────────────────── */
.kpi-spark { display: block; margin-top: 10px; width: 100%; height: 28px; }
.kpi-delta-up   { color: var(--success); font-weight: 600; }
.kpi-delta-down { color: var(--danger);  font-weight: 600; }
.kpi-money {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-white);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-money-sub { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* Count pill inside filter tabs */
.ftab-count {
  display: inline-block;
  background: var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 4px;
  vertical-align: middle;
}
.ftab.active .ftab-count {
  background: rgba(124,92,219,0.22);
  color: var(--nav-active-clr);
}

/* Danger (overdue) variant for filter tabs */
.ftab-danger {
  color: var(--danger);
}
.ftab-danger .ftab-count {
  background: rgba(220,53,69,0.12);
  color: var(--danger);
}
.ftab-danger.active {
  color: var(--danger);
  border-bottom-color: var(--danger);
}
.ftab-danger.active .ftab-count { background: var(--danger); color: var(--text-white); }

/* Sortable table headers — shared across all list screens
   (consolidated 2026-06-19; was duplicated in ~14 per-page <style> blocks). */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text-primary); }
th.sortable.sort-active { color: var(--brand); }
.sort-icon { margin-left: 3px; font-size: 10px; opacity: 0.45; transition: opacity 0.12s; }
th.sortable:hover .sort-icon { opacity: 0.85; }
th.sortable.sort-active .sort-icon { opacity: 1; color: var(--brand); }

/* Ready (logistics disabled) variant — purple accent */
.ftab-ready {
  color: #7c3aed;
}
.ftab-ready .ftab-count {
  background: rgba(124,58,237,0.10);
  color: #7c3aed;
}
.ftab-ready.active {
  color: #7c3aed;
  border-bottom-color: #7c3aed;
}

/* Awaiting logistics — teal accent (production done, waiting to forward) */
.ftab-teal { color: #5DCAA5; }
.ftab-teal .ftab-count { background: rgba(93,202,165,0.12); color: #5DCAA5; }
.ftab-teal.active { color: #5DCAA5; border-bottom-color: #5DCAA5; }
.ftab-teal.active .ftab-count { background: #5DCAA5; color: #fff; }

/* At logistics — blue accent (forwarded, in transit) */
.ftab-blue { color: #85B7EB; }
.ftab-blue .ftab-count { background: rgba(55,138,221,0.12); color: #85B7EB; }
.ftab-blue.active { color: #85B7EB; border-bottom-color: #85B7EB; }
.ftab-blue.active .ftab-count { background: #85B7EB; color: #fff; }

.mini-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--input-bg);
  border: 1px solid var(--border-field);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--input-ph);
  width: 160px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: transparent !important;
}

td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

/* Pointer cursor only on rows that actually navigate (onclick rows).
   Sub-rows (price breakdowns, totals) keep the default cursor so the
   UI never promises an interaction it can't deliver. */
tbody tr[onclick] { cursor: pointer; }

@media (hover: hover) and (pointer: fine) {
  tbody tr[onclick]:hover td { background: var(--row-hover); }
}

.td-primary { color: var(--text-white) !important; font-weight: 500; }
.td-muted   { color: var(--text-muted) !important; font-size: 12px; }

.table.mb-0, table.mb-0 { margin-bottom: 0; }

/* ── .data-table — THE blessed table component ────────────────────────
   Product-owner decision (UI wave 2026-06-12): every record table uses
   class="data-table". Until now the class had no rules of its own and
   relied on the generic table/th/td styles above; this block makes it
   self-contained so the component survives future changes to the
   generic styles. Values intentionally mirror the generic styles, so
   existing .data-table usages (audit_log, po_detail, production_queue,
   plan_overview, the rebuilt screens) render pixel-identical.

   Usage:
     <table class="data-table">…</table>
   Inside a .table-card or a section-card with padding:0.

   Optional responsive wrapper for wide tables (horizontal scroll on
   narrow viewports — wrap the table, never the card):
     <div class="data-table-wrap"><table class="data-table">…</table></div>

   Row hover follows the project rule: only rows that navigate
   (tbody tr[onclick]) get a hover wash + pointer cursor. Static rows
   must not promise interaction. */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: transparent !important;
}

.data-table td {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr[onclick] { cursor: pointer; }

@media (hover: hover) and (pointer: fine) {
  .data-table tbody tr[onclick]:hover td { background: var(--row-hover); }
}

.data-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Badges ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success { background: rgba(93,202,165,0.12);  color: #5DCAA5; }
.badge-warn    { background: rgba(239,159,39,0.12);  color: #EF9F27; }
.badge-danger  { background: rgba(226,75,74,0.12);   color: #E24B4A; }
.badge-info    { background: rgba(124,92,219,0.15);  color: #b09aea; }
.badge-gray    { background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.45); }
.badge-blue    { background: rgba(55,138,221,0.12);  color: #85B7EB; }
.badge-teal    { background: rgba(29,158,117,0.12);  color: #5DCAA5; }

[data-theme="light"] .badge-gray {
  background: rgba(0,0,0,0.07);
  color: rgba(0,0,0,0.45);
}

/* ── Two-column detail layout ───────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
}

@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.detail-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Section card ───────────────────────────────────── */
.section-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.03);
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 16px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
}

.field-row:last-child { border-bottom: none; }

.field-label { font-size: 12px; color: var(--text-dim); }

.field-value {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  text-align: right;
}

/* ── Detail-page premium layer ─────────────────────────── */
.detail-grid--full { grid-template-columns: 1fr; }

.entity-avatar {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand-tint-strong);
  color: var(--brand-light);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.5px;
  text-transform: uppercase;
}
.entity-avatar svg { width: 22px; height: 22px; }

.hover-lift { transition: transform 0.12s ease-out, box-shadow 0.12s ease-out; }
.hover-lift:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0,0,0,0.10); }
@media (prefers-reduced-motion: reduce) {
  .hover-lift, .hover-lift:hover { transition: none; transform: none; }
}

/* ── Timeline ───────────────────────────────────────── */
.timeline {
  display: flex;
  flex-direction: column;
}

.tl-item {
  display: flex;
  gap: 12px;
  padding-bottom: 16px;
  position: relative;
}

.tl-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 14px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.tl-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 3px;
  border: 2px solid var(--page-bg);
}

.tl-content { flex: 1; }
.tl-text { font-size: 13px; color: var(--text-secondary); }
.tl-time { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* ── Form ───────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field.full { grid-column: 1 / -1; }

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.form-input {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--input-color);
  outline: none;
  width: 100%;
  transition: border 0.12s;
}

.form-input:focus { border-color: #7c5cdb; }

.form-select {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  outline: none;
  width: 100%;
  appearance: none;
}

.form-textarea {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--input-color);
  outline: none;
  width: 100%;
  resize: vertical;
  min-height: 80px;
}

.form-divider {
  grid-column: 1 / -1;
  border-bottom: 1px solid var(--border);
  margin: 4px 0;
}

.form-section-label {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding-top: 4px;
}

/* ── Kanban ─────────────────────────────────────────── */
.kanban {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.k-col {
  background: var(--surface-tint);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  min-height: 300px;
}

.k-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.k-col-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.k-count {
  background: var(--surface-pill);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
}

.k-card {
  background: var(--card-bg);
  border: 1px solid var(--border-field);
  border-radius: 9px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.12s;
}

.k-card:hover { border-color: rgba(124,92,219,0.4); }
.k-card-title { font-size: 13px; color: var(--text-secondary); font-weight: 500; margin-bottom: 6px; }
.k-card-meta  { font-size: 11px; color: var(--text-muted); display: flex; align-items: center; justify-content: space-between; }

/* ── Stats row ──────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-mini {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
}

.stat-mini-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.stat-mini-value { font-size: 22px; font-weight: 700; color: var(--text-white); }
.stat-mini-sub   { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ── Pagination ─────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

.page-btns { display: flex; gap: 3px; }

.pg-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  text-decoration: none;
}

.pg-btn.active { background: rgba(124,92,219,0.2); color: #b09aea; }
.pg-btn:hover:not(.active) { background: var(--nav-hover-bg); }

/* Non-interactive "…" gap in the page-number strip (see _pagination.html).
   Replaces the inline cursor/opacity styles in older paginators. */
.pg-btn.pg-ellipsis { cursor: default; opacity: 0.4; pointer-events: none; }

/* Range text inside .pagination ("1–25 / 312") — replaces the inline
   font-size/color span used in older paginators. */
.pagination-range { font-size: 13px; color: var(--text-dim); }

/* ── Two-col dashboard bottom ───────────────────────── */
.dash-bottom {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

@media (max-width: 900px) {
  .dash-bottom { grid-template-columns: 1fr; }
}

/* ── Dashboard analytics row ─────────────────────────────────────── */
.dash-analytics-row {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.dash-chart-card { padding: 18px 20px 14px; }
.dash-aging-card { padding: 18px 20px 14px; }

/* Invoice aging */
.aging-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.aging-bucket {
  display: grid;
  grid-template-columns: 60px 28px 1fr 70px;
  align-items: center;
  gap: 8px;
}

.aging-label {
  font-size: 11px;
  color: var(--page-text-muted);
  white-space: nowrap;
}

.aging-count {
  font-size: 13px;
  font-weight: 700;
  text-align: right;
  color: var(--page-text);
}

.aging-bar-track {
  background: var(--sidebar-hover);
  border-radius: 4px;
  height: 6px;
  overflow: hidden;
}

.aging-bar {
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s;
}

.aging-amount {
  font-size: 11px;
  color: var(--page-text-muted);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Today's work panel */
.today-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--page-text-muted);
  margin-bottom: 6px;
}

.today-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--page-text);
  transition: background 0.12s;
  margin-bottom: 4px;
}

.today-item:hover { background: var(--sidebar-hover); color: var(--page-text); }

.today-item-icon {
  font-size: 14px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.today-icon-active { color: #EF9F27; }
.today-icon-pending { color: var(--page-text-muted); }

.today-item-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.today-item-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.today-item-sub {
  font-size: 11px;
  color: var(--page-text-muted);
  margin-top: 1px;
}

@media (max-width: 1100px) {
  .dash-analytics-row { grid-template-columns: 1fr 1fr; }
  .dash-chart-card:last-child { grid-column: 1 / -1; }
}

@media (max-width: 700px) {
  .dash-analytics-row { grid-template-columns: 1fr; }
}

/* ── Back link ──────────────────────────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 16px;
  transition: color 0.12s;
}

.back-link:hover { color: var(--text-secondary); }

/* ── Progress bar ───────────────────────────────────── */
.progress-bar {
  height: 4px;
  background: var(--surface-pill);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-fill { height: 100%; border-radius: 99px; }

/* ── Avatar stack ───────────────────────────────────── */
.avatar-sm {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #7c5cdb;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 600;
  color: #fff;
  border: 2px solid var(--card-bg);
  margin-left: -6px;
}

.avatar-sm:first-child { margin-left: 0; }

/* ── Finance chart placeholder ──────────────────────── */
.chart-placeholder {
  height: 160px;
  background: var(--surface-tint);
  border-radius: 8px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 12px 12px 0;
  border: 1px solid var(--border-soft);
}

.chart-bar {
  flex: 1;
  border-radius: 4px 4px 0 0;
  opacity: 0.85;
}

/* ── Invoice preview ────────────────────────────────── */
.invoice-preview {
  background: var(--inv-preview-bg);
  border-radius: 10px;
  padding: 32px;
  color: var(--inv-preview-clr);
}

.inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 28px; }
.inv-company { font-size: 20px; font-weight: 700; color: #7c5cdb; }
.inv-title   { font-size: 24px; font-weight: 700; color: #1a1a2e; text-align: right; }
.inv-num     { font-size: 13px; color: #666; text-align: right; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.inv-party-label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #999; margin-bottom: 6px; }
.inv-party-name  { font-size: 14px; font-weight: 600; color: #1a1a2e; }
.inv-party-info  { font-size: 12px; color: #666; margin-top: 2px; }
.inv-table th { background: #f5f5f8; color: #666; font-size: 11px; letter-spacing: 0.05em; padding: 8px 12px; text-transform: none; letter-spacing: normal; }
.inv-table td { padding: 10px 12px; font-size: 13px; color: #333; border-bottom: 1px solid #eee; }
.inv-total       { text-align: right; margin-top: 20px; }
.inv-total-label { font-size: 12px; color: #666; }
.inv-total-value { font-size: 22px; font-weight: 700; color: #7c5cdb; }

/* ── Settings layout ────────────────────────────────── */
/* (layout and nav rules are defined in the Settings page section below) */

/* ── Theme switcher (settings page) ────────────────── */
.theme-switcher { display: flex; gap: 6px; }

.theme-opt {
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-field);
  background: var(--input-bg);
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.theme-opt:hover { background: var(--nav-hover-bg); color: var(--text-secondary); }
.theme-opt.active { background: var(--nav-active-bg); color: var(--nav-active-clr); border-color: rgba(124,92,219,0.3); }

/* ── Warehouse stock indicator ──────────────────────── */
.stock-bar-wrap { width: 80px; }
.stock-label    { font-size: 11px; margin-bottom: 3px; }

/* ── Flash messages ─────────────────────────────────── */
.flash-messages { margin-bottom: 16px; }
.flash-messages .alert-success { background: rgba(93,202,165,0.1); border: 1px solid rgba(93,202,165,0.25); color: #5DCAA5; }
.flash-messages .alert-warning { background: rgba(239,159,39,0.08); border: 1px solid rgba(239,159,39,0.2); color: #EF9F27; }
.flash-messages .alert-info    { background: rgba(124,92,219,0.1); border: 1px solid rgba(124,92,219,0.25); color: #b09aea; }

/* Flash message — entry + auto-dismiss animations */
@keyframes flashSlideIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.flash-messages .alert {
  animation: flashSlideIn 0.22s ease forwards;
}

.flash-messages .alert.flash-out {
  transition: opacity 0.4s ease, transform 0.4s ease,
              max-height 0.4s ease, padding-top 0.4s ease,
              padding-bottom 0.4s ease, margin-bottom 0.4s ease,
              border-width 0.4s ease;
  opacity: 0 !important;
  transform: translateY(-6px) !important;
  overflow: hidden;
  max-height: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  margin-bottom: 0 !important;
  border-width: 0 !important;
}

.btn-close {
  background: transparent;
  border: none;
  cursor: pointer;
  opacity: 0.5;
  font-size: 16px;
  color: currentColor;
  padding: 0 4px;
  line-height: 1;
}
.btn-close:hover { opacity: 1; }

/* ── Footer ─────────────────────────────────────────── */
.app-footer {
  padding: 12px 24px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--topbar-bg);
}

/* ── Scrollbar ──────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 99px; }

/* ── Bootstrap table override ───────────────────────── */
/* Prevent Bootstrap from injecting white backgrounds */
.table > :not(caption) > * > * {
  background-color: transparent !important;
  box-shadow: none !important;
}

/* Bootstrap form controls inherit our tokens */
.form-control,
select.form-select {
  background-color: var(--input-bg) !important;
  border-color: var(--input-border) !important;
  color: var(--input-color) !important;
}
.form-control:focus,
select.form-select:focus {
  background-color: var(--input-bg) !important;
  border-color: #7c5cdb !important;
  box-shadow: 0 0 0 3px rgba(124,92,219,0.15) !important;
  color: var(--input-color) !important;
}

/* ── Native <select> dropdown contrast fix ───────────────────────────
   Browser-native <option> elements cannot use rgba/transparent
   backgrounds — they fall through to the OS default and produce
   near-invisible dark-on-dark text in dark mode.
   We must supply solid opaque colors and a color-scheme hint so the
   browser renders the popup panel with the correct palette.         */
:root select,
[data-theme="dark"] select {
  color-scheme: dark;
}
[data-theme="light"] select {
  color-scheme: light;
}

/* Solid option backgrounds — applied in both themes */
:root select option,
[data-theme="dark"] select option {
  background-color: #1d2035;   /* solid equivalent of dark card-bg */
  color: #e2e4ec;
}
[data-theme="light"] select option {
  background-color: #ffffff;
  color: #1a1c2e;
}

/* Hover/selected state for option rows */
:root select option:hover,
:root select option:checked,
[data-theme="dark"] select option:hover,
[data-theme="dark"] select option:checked {
  background-color: #2d2f52;
  color: #ffffff;
}
[data-theme="light"] select option:hover,
[data-theme="light"] select option:checked {
  background-color: #ede9fd;
  color: #1a1c2e;
}

/* Bootstrap dropdown overrides */
.dropdown-menu {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
}
.dropdown-item {
  color: var(--text-secondary);
  font-size: 13px;
  border-radius: 6px;
  padding: 7px 10px;
}
.dropdown-item:hover,
.dropdown-item:focus {
  background: var(--nav-hover-bg);
  color: var(--text-white);
}
.dropdown-divider { border-color: var(--border); }

/* ── Bootstrap component overrides for dark theme ───── */
/* Bootstrap cards used in secondary/admin pages */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
}
.card-body { color: var(--text-primary); }

/* btn-outline-primary → brand purple */
.btn-outline-primary {
  color: #b09aea;
  border-color: rgba(124,92,219,0.4);
}
.btn-outline-primary:hover {
  background: rgba(124,92,219,0.16);
  border-color: #7c5cdb;
  color: #b09aea;
}

/* Bootstrap text-muted in dark mode */
.text-muted { color: var(--text-muted) !important; }
.small { font-size: 12px; }

/* Bootstrap badge overrides */
.badge.bg-secondary  { background: rgba(255,255,255,0.07) !important; color: rgba(255,255,255,0.45) !important; }
.badge.bg-primary    { background: rgba(124,92,219,0.18) !important; color: #b09aea !important; }
.badge.bg-success    { background: rgba(93,202,165,0.12) !important; color: #5DCAA5 !important; }
.badge.bg-warning    { background: rgba(239,159,39,0.12) !important; color: #EF9F27 !important; }
.badge.bg-danger     { background: rgba(226,75,74,0.12)  !important; color: #E24B4A !important; }
.badge.rounded-pill  { border-radius: 99px !important; }

/* Bootstrap alert overrides */
.alert-warning { background: rgba(239,159,39,0.08); border-color: rgba(239,159,39,0.2); color: #EF9F27; }
.alert-success { background: rgba(93,202,165,0.1);  border-color: rgba(93,202,165,0.25); color: #5DCAA5; }
.alert-info    { background: rgba(124,92,219,0.1);  border-color: rgba(124,92,219,0.25); color: #b09aea; }

/* ── Utility ────────────────────────────────────────── */
.text-decoration-none { text-decoration: none; }
.mb-0 { margin-bottom: 0 !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-0 { margin-top: 0 !important; }

/* ── Settings page ──────────────────────────────────── */
.settings-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 20px;
  align-items: start;
}

.settings-nav {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  position: sticky;
  top: 0;
}

.settings-nav-label {
  padding: 8px 10px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.snav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
}

.snav-item:hover {
  background: var(--nav-hover-bg);
  color: var(--text-secondary);
  text-decoration: none;
}

.snav-item.active {
  background: var(--nav-active-bg);
  color: var(--nav-active-clr);
}

.snav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.snav-icon svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
  flex-shrink: 0;
}

/* Tab panels */
.stab-panel { display: none; }
.stab-panel.active { display: block; }

.stab-header { margin-bottom: 20px; }

.stab-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-white);
}

.stab-desc {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}

.stab-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  margin-top: 4px;
}

/* Inline row for field + control (used in Appearance) */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
}

.settings-row:not(:last-child) {
  border-bottom: 1px solid var(--border-soft);
}

.settings-row-info {}
.settings-row-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}
.settings-row-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Toggle switch (profile / settings) ─────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}
.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-field);
  border-radius: 24px;
  transition: background 0.2s;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
  background: #7c5cdb;
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}
.toggle-switch input:focus-visible + .toggle-slider {
  outline: 2px solid #7c5cdb;
  outline-offset: 2px;
}

/* ── Audit log ───────────────────────────────────────────────────── */
.audit-filters { width: 100%; }

.audit-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}

.filter-actions {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-top: 18px;
}

/* Action badges */
.audit-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.audit-badge-create       { background: rgba(76,175,80,0.18);  color: #66bb6a; }
.audit-badge-update       { background: rgba(33,150,243,0.18); color: #42a5f5; }
.audit-badge-delete       { background: rgba(244,67,54,0.18);  color: #ef5350; }
.audit-badge-view_sensitive { background: rgba(255,152,0,0.18); color: #ffa726; }

/* Changed field chips */
.audit-changes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.audit-field-chip {
  font-size: 11px;
  font-family: monospace;
  background: var(--sidebar-hover);
  color: var(--page-text-muted);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--card-border);
}

/* Pagination row */
.pagination-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 0;
}

.pagination-info {
  font-size: 13px;
  color: var(--page-text-muted);
}

/* ── Toggle button group (view switchers: Kanban / List, etc.) ──────── */
/* Replaces inline-styled toggle buttons in production_queue and similar */
.btn-toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.btn-toggle {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-toggle:hover { background: var(--nav-hover-bg); color: var(--text-white); }
.btn-toggle.active { background: var(--brand); color: #fff; }
.btn-toggle + .btn-toggle { border-left: 1px solid var(--border); }

/* Cut/whole-sheet line-mode toggle: hug its two buttons instead of stretching
   the full row width (the group is block-level flex by default). */
.sqm-mode-row .btn-toggle-group { display: inline-flex; }

/* Compact toggle for the finishing drawer's „Цял детайл | Частично“ switch —
   sized to line up with the row's form-control-sm / form-select-sm controls. */
.fin-mode-sm { align-self: stretch; }
.fin-mode-sm .btn-toggle { padding: 0 12px; font-size: 12px; line-height: 1; display: flex; align-items: center; }

/* ── Empty state ────────────────────────────────────────────────────── */
/* Use inside table-card when there are no records to display */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 56px 24px;
  text-align: center;
  gap: 12px;
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--surface-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.empty-state-icon svg {
  width: 22px;
  height: 22px;
  stroke: var(--text-dim);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-state-body {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 300px;
  line-height: 1.5;
}

/* ── Tooltip on truncated text (add title="" to element) ────────────── */
/* Ensures truncated text is always inspectable on hover */
.text-truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ── Keyboard focus visibility ───────────────────────────────────────
   ERP operators are keyboard-heavy. Every interactive element must
   show focus when reached via Tab — and only then (:focus-visible
   keeps mouse clicks clean). */
.btn:focus-visible,
.btn-ghost:focus-visible,
.btn-toggle:focus-visible,
.icon-btn:focus-visible,
.icon-btn-sm:focus-visible,
.nav-item:focus-visible,
.snav-item:focus-visible,
.ftab:focus-visible,
.mtab:focus-visible,
.pg-btn:focus-visible,
.theme-opt:focus-visible,
.kpi-card:focus-visible,
.user-row:focus-visible,
.back-link:focus-visible,
.today-item:focus-visible,
.search-result-item:focus-visible,
.dropdown-item:focus-visible,
tbody tr[onclick]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 8px;
}

.form-input:focus-visible,
.form-select:focus-visible,
.form-textarea:focus-visible {
  border-color: #7c5cdb;
  box-shadow: 0 0 0 3px rgba(124,92,219,0.15);
  outline: none;
}

.search-box:focus-within {
  border-color: rgba(124,92,219,0.5);
}

/* ── Reduced motion ──────────────────────────────────────────────────
   Fewer and gentler animations, not zero: opacity transitions that aid
   comprehension stay; positional movement goes. */
@media (prefers-reduced-motion: reduce) {
  .btn, .btn-ghost, .kpi-card { transition-property: background, color, border-color; }
  .btn:active, .btn-ghost:active, .kpi-card:active { transform: none; }
  .search-dropdown { animation: searchDropdownFade 120ms ease; }
  .flash-messages .alert { animation: searchDropdownFade 150ms ease; }
  .sidebar { transition: none; }
  .toggle-slider, .toggle-slider::before { transition: none; }
  .aging-bar { transition: none; }
}

@keyframes searchDropdownFade {
  from { opacity: 0; }
}

/* ── Form utilities (legacy-island rebuild, 2026-06) ─────────────────
   Token-only additions used by the rebuilt form / confirm screens. */

/* Inline field error under a widget */
.form-error {
  font-size: 12px;
  color: var(--danger);
}

/* Narrow single-card form wrapper */
.form-narrow { max-width: 560px; }

/* Input with a unit/currency suffix */
.input-suffix-row { display: flex; align-items: center; gap: 6px; }
.input-suffix-row > :first-child { flex: 1; }
.input-suffix {
  min-width: 40px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Footer action row inside a form card */
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}

/* Checkbox + label row inside a form-field */
.form-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Segmented binary choice (QC pass/fail) */
.choice-toggle { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.choice-toggle input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.choice-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--input-bg);
  border: 1px solid var(--border-field);
  color: var(--text-secondary);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.choice-toggle input:focus-visible + .choice-option {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.choice-toggle input:checked + .choice-option.success {
  background: var(--success-tint);
  border-color: var(--success-tint-strong);
  color: var(--success);
}
.choice-toggle input:checked + .choice-option.danger {
  background: var(--danger-tint);
  border-color: var(--danger-tint-strong);
  color: var(--danger);
}

/* Destructive confirmation card */
.confirm-card { max-width: 460px; text-align: center; }
.confirm-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
  color: var(--danger);
}
.confirm-icon svg { width: 44px; height: 44px; }
.confirm-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-white);
  margin-bottom: 8px;
}
.confirm-text {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 18px;
}
.confirm-actions { display: flex; justify-content: center; gap: 8px; }

/* ── Subscriptions & HQ screens (legacy-island rebuild, 2026-06) ─────
   Token-only additions used by the rebuilt subscriptions / tenant-HQ
   screens. */

/* Small stroke icon used inline in buttons / list rows / banners */
.icon-inline {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -2px;
}

/* Narrow centered page body for single-column forms / gate screens */
.page-narrow { max-width: 640px; margin: 0 auto; }

/* Inline field + button form (e.g. HQ assign-plan table row) */
.inline-form { display: flex; align-items: center; gap: 8px; }
.inline-form .form-select { width: auto; min-width: 150px; }

/* Form error banner above a form (replaces per-template inline styles) */
.form-error-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: var(--danger-tint);
  border: 1px solid var(--danger-tint-strong);
  border-radius: 10px;
  font-size: 13px;
  color: var(--danger);
}
.form-error-banner .icon-inline { margin-top: 2px; }

/* Flush table cell — hosts an empty-state inside a colspan */
.td-flush { padding: 0; }

/* Right-aligned header / action cells (numeric columns, row buttons) */
th.num { text-align: right; }
.td-right { text-align: right; white-space: nowrap; }

/* Centered CTA row under an empty-state */
.empty-state-actions { display: flex; gap: 8px; justify-content: center; margin-top: 4px; }

/* Full-width button (plan-card CTA, narrow form footers) */
.btn-block { width: 100%; display: block; text-align: center; }

/* Plan cards (subscriptions comparison) */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.plan-card { display: flex; flex-direction: column; }

.plan-card.current {
  border-color: var(--brand-tint-strong);
  box-shadow: 0 0 0 1px var(--brand-tint-strong);
}

.plan-card-head { min-height: 22px; margin-bottom: 6px; }

.plan-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-white);
  letter-spacing: 0.03em;
}

.plan-price {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-white);
  margin-top: 2px;
}

.plan-features {
  list-style: none;
  margin: 14px 0 18px;
  padding: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.plan-features li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}
.plan-features li .icon-inline { color: var(--success); }
.plan-features li.off { color: var(--text-dim); }
.plan-features li.off .icon-inline { color: var(--text-dim); }

.plan-note { text-align: center; font-size: 12px; color: var(--text-muted); }

/* Current-plan hero (plan overview) */
.plan-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--brand-tint), var(--card-bg) 65%);
  border-color: var(--brand-tint-strong);
}

.plan-hero-value { font-size: 24px; font-weight: 700; color: var(--text-white); }
.plan-hero-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Shared modal / styled confirm (replaces native confirm + ad-hoc overlays) ── */
.lx-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lx-modal-overlay.open { display: flex; }
.lx-modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.30);
  overflow: hidden;
}
.lx-modal-head {
  padding: 18px 20px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}
.lx-modal-body {
  padding: 8px 20px 18px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.lx-modal-actions {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
/* Free-form variant: hosts a full form/body with its own internal markup. */
.lx-modal.lx-modal--pad { max-width: 480px; padding: 28px; }
.lx-modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-primary);
}
.lx-modal-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ── HQ control center — tenant overview cards ────────────────────── */
.hq-kpi-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(180px,1fr)); gap:16px; margin-bottom:24px; }
.tenant-card-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(280px,1fr)); gap:16px; }
.tenant-card { display:block; padding:18px; border:1px solid var(--border); border-radius:12px; background:var(--card-bg); text-decoration:none; color:inherit; transition:border-color .15s ease, transform .15s ease; }
.tenant-card:hover { border-color:var(--brand); transform:translateY(-1px); }
.tenant-card-head { display:flex; justify-content:space-between; align-items:center; gap:8px; }
.tenant-card-head .td-primary { font-weight:600; }
.tenant-card-sub { margin:6px 0; }
.tenant-card-meta { display:flex; gap:12px; flex-wrap:wrap; margin-top:10px; font-size:13px; }

.hq-filter-bar { display:flex; gap:8px; flex-wrap:wrap; align-items:center; margin-bottom:20px; }

/* ── Shape gallery — parametric-template picker (STATE-2 library pane) ──
   The curated row of big cards is the friendly front door; the full
   searchable grid sits below it. Cards are finger-friendly (touch +
   desktop). All colour comes from tokens so both themes render. */
.shape-gallery { margin-bottom: 16px; }
.shape-gallery__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(102px, 1fr));
  gap: 10px;
}
.shape-more__heading {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin: 4px 0 8px;
}

/* Base card — gives the (previously unstyled) .shape-card a real surface,
   plus the hover + selected states shared by curated and grid cards. */
.shape-card {
  cursor: pointer;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color .15s ease, background .15s ease,
              box-shadow .15s ease, transform .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.shape-card:hover { border-color: var(--brand); }
.shape-card--selected {
  border-color: var(--brand);
  background: var(--brand-tint);
  box-shadow: 0 0 0 1px var(--brand-tint-strong);
}
/* Cap the preview height so grid cards stay compact — the cached SVG is
   200px and would otherwise stretch to the (wide) grid column. The bigger
   curated cards override this with their own .shape-card--gallery rule. */
.shape-card__preview svg,
.shape-card__preview img { max-width: 100%; height: auto; max-height: 72px; }
.shape-card__name { color: var(--text-primary); }

/* „More forms" grid — deliberately SECONDARY to the curated row above:
   smaller columns and smaller previews than .shape-card--gallery, so the
   friendly front-door gallery stays the visual priority. Was a Bootstrap
   .row/.col-4 (3 full-width columns) which rendered these bigger than the
   curated cards — inverting the intended hierarchy. */
.shape-more__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
}
.shape-more__grid .shape-card {
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.shape-more__grid .shape-card__preview {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shape-more__grid .shape-card__preview svg,
.shape-more__grid .shape-card__preview img { max-height: 44px; }
.shape-more__grid .shape-card__name {
  font-size: 11.5px;
  line-height: 1.2;
  color: var(--text-muted);
}
.shape-more__empty { grid-column: 1 / -1; }

/* Big curated cards. */
.shape-card--gallery {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 118px;
  padding: 12px 8px;
}
.shape-card--gallery .shape-card__preview {
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shape-card--gallery .shape-card__preview svg { max-height: 60px; }
.shape-card--gallery .shape-card__name {
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 8px;
  line-height: 1.2;
}

/* „Draw your own" door — dashed + brand-tinted so it reads as an action,
   not a template. */
.shape-card--draw {
  border-style: dashed;
  border-color: var(--brand);
  background: var(--brand-tint);
}
.shape-card--draw:hover { background: var(--brand-tint-strong); }
.shape-card--draw .shape-card__icon {
  font-size: 26px;
  line-height: 1;
  color: var(--brand-light);
}
.shape-card--draw .shape-card__name { color: var(--brand-light); }

/* ── Polygon editor toolbar — button affordance + grouping ──────────
   polygon_editor.js builds Bootstrap outline buttons; on the dark canvas
   toolbar `btn-outline-secondary` renders as transparent-bg + low-contrast
   text, so operators can't tell the controls are clickable or how they
   group. Give each functional row a faint panel (view controls / actions /
   corners), give the buttons a real surface, and make hover + active
   (snap toggle, selected corner) states obvious. Tokens only → both themes. */
.polygon-editor__controls,
.polygon-editor__actions,
.polygon-editor__corners {
  padding: 8px 10px;
  background: var(--surface-tint);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
}
.polygon-editor .btn-sm {
  --bs-btn-padding-y: .32rem;
  --bs-btn-padding-x: .62rem;
  font-weight: 500;
}
/* Neutral buttons: a real, tappable surface instead of bare text. */
.polygon-editor .btn-outline-secondary {
  color: var(--text-primary);
  background: var(--input-bg);
  border-color: var(--border-field);
}
.polygon-editor .btn-outline-secondary:hover {
  color: var(--text-primary);
  background: var(--brand-tint);
  border-color: var(--brand);
}
/* Toggle-ON (snap) and selected corner mode read as clearly pressed. */
.polygon-editor .btn-outline-secondary.active,
.polygon-editor .btn-check:checked + .btn-outline-secondary {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}
/* Clear stays danger-flavoured but gets a surface so it's visibly a button. */
.polygon-editor .btn-outline-danger { background: var(--input-bg); }
.polygon-editor .btn:disabled { opacity: .5; }

/* ═══════════════════════════════════════════════════════
   Mobile responsiveness layer (2026-07)
   Target widths: 320 / 360 / 375 / 390 / 412 / 425 / 768 / 1024.
   Extends the existing breakpoints (767 / 900 / 1100) — desktop
   rules above are untouched; everything here only *adds* narrow-
   viewport behaviour. Keep new mobile rules in this section.
   ═══════════════════════════════════════════════════════ */

/* ── Always-on safety rules (no layout change on desktop) ─────────── */

/* Media must never push the layout past the viewport. Chart.js manages
   its canvas size itself, but max-width is a no-op for it and a guard
   for every other canvas/img (logos, shape previews). */
img, canvas { max-width: 100%; }

/* Server-rendered shape preview SVGs carry fixed width/height attributes;
   scale them down instead of overflowing their card on small screens. */
.shape-preview__svg svg { max-width: 100%; height: auto; }

/* Tall confirm/quick-create modals must fit the visual viewport. */
.lx-modal {
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
.lx-modal-actions { flex-wrap: wrap; }

/* ─────────────────────────────────────────────────────────────────────
   RESPONSIVE TABLE SYSTEM — one system, three treatments.
   Pick per table in the markup; desktop rendering is never changed.

   1. DEFAULT · horizontal scroll (the blessed wrapper, already used by
      every table). Preserves all columns, sort headers, row links and
      action menus; the wrapper scrolls, never the page:
          <div class="data-table-wrap"><table class="data-table">…</table></div>

   2. STICKY IDENTIFIER · add the modifier on very wide numeric/financial
      tables so the first column stays pinned while the rest scrolls:
          <div class="data-table-wrap data-table-wrap--sticky">…

   3. STACKED CARDS · for lists of independent records. Add .table-cards
      to the <table>, data-label="<header>" to each <td>, and .cell-title
      to the primary cell. Below the phone breakpoint each row becomes a
      titled card; the full sortable table returns ≥768px. Header sorting
      is hidden on phones (narrowing is done with the filter tabs + search
      that remain) — an intentional, documented trade-off.

   COLUMN PRIORITY · add .cell-hide-sm to a <th> AND its matching <td> to
   drop a genuinely secondary column on phones (the value stays on the
   record's detail page, and on scroll tables it's still reachable by
   scrolling). Breakpoints reuse the project's existing 900 / 767. */

/* Base wrapper already sets overflow-x:auto + touch scrolling above;
   this only guarantees it can never exceed the viewport. */
.data-table-wrap { max-width: 100%; }

/* 2 · Sticky first column (opt-in) — pin the identifier while scrolling.
   Needs an opaque background so scrolled cells don't bleed underneath. */
@media (max-width: 900px) {
  .data-table-wrap--sticky > table th:first-child,
  .data-table-wrap--sticky > table td:first-child {
    position: sticky;
    left: 0;
    background: var(--card-bg);
  }
  .data-table-wrap--sticky > table th:first-child { z-index: 2; }
  .data-table-wrap--sticky > table td:first-child { z-index: 1; }
}

/* 3 · Column priority — hide a genuinely secondary column on phones. */
@media (max-width: 767px) {
  .cell-hide-sm { display: none !important; }
}

/* 3 · Stacked cards (opt-in) — record rows become titled cards on phones.
   Desktop/tablet keep the normal sortable table (rules are scoped to the
   phone breakpoint only). */
@media (max-width: 767px) {
  table.table-cards { display: block; width: 100%; }
  table.table-cards tbody { display: block; width: 100%; }

  /* Visually-hide the header row but keep it for assistive tech. */
  table.table-cards thead {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0);
    white-space: nowrap; border: 0;
  }

  table.table-cards tr {
    display: block;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px 14px;
    margin-bottom: 10px;
  }

  table.table-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border: none;
    border-bottom: 1px solid var(--border-soft);
    text-align: right;
    white-space: normal;
  }
  table.table-cards td:last-child { border-bottom: none; }

  /* Label column, drawn from the real header via data-label. */
  table.table-cards td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 auto;
    margin-right: auto;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
    text-align: left;
  }

  /* Primary cell → card title (no label, left-aligned, prominent). */
  table.table-cards td.cell-title {
    display: block;
    text-align: left;
    padding-top: 10px;
    border-bottom: 1px solid var(--border);
  }
  table.table-cards td.cell-title::before { content: none; }

  /* Full-width rows: empty state / colspan cells. */
  table.table-cards td[colspan] {
    display: block;
    text-align: center;
    border-bottom: none;
  }

  /* Action cell (no data-label): keep the menu button right-aligned. */
  table.table-cards td:not([data-label]):not(.cell-title) { justify-content: flex-end; }
}

/* Page header: title block + actions wrap instead of colliding. */
.page-header { flex-wrap: wrap; gap: 10px 16px; }
.header-actions { flex-wrap: wrap; }

/* Generic kanban (HQ tenant detail): was fixed 4 columns at all widths. */
@media (max-width: 1100px) {
  .kanban { grid-template-columns: repeat(2, 1fr); }
}

/* Utilities: collapse inline-styled desktop grids on small screens.
   Several templates define their grid columns in the style="" attribute
   (the desktop design); inline styles beat any stylesheet selector, so
   these helpers intentionally use !important to reclaim control at
   narrow widths. Tag the element:  class="... grid-collapse-sm". */
@media (max-width: 900px) {
  .grid-collapse-md { grid-template-columns: 1fr !important; }
}
@media (max-width: 767px) {
  .grid-collapse-sm { grid-template-columns: 1fr !important; }
}

/* ── ≤900px — small tablets / large phones ────────────────────────── */
@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }

  /* Settings: side nav becomes a horizontal, scrollable pill row. */
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav {
    position: static;
    display: flex;
    align-items: center;
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .settings-nav-label { display: none; }
  .snav-item { width: auto; white-space: nowrap; flex: 0 0 auto; }
}

/* ── ≤767px — phones (matches the sidebar off-canvas breakpoint) ──── */
@media (max-width: 767px) {
  .content { padding: 14px 12px; }

  .topbar { padding: 0 10px; gap: 8px; }

  /* Global search: flex into the remaining space instead of fixed 240px. */
  .topbar .search-box {
    width: auto;
    flex: 1 1 110px;
    min-width: 0;
    max-width: 240px;
  }
  /* 340px dropdown would overflow a 320–375px viewport. */
  .search-dropdown { min-width: 0; }

  /* Toolbar search boxes carry inline width:220-240px for the desktop
     layout; !important is required (and intentional) to beat those
     inline styles from one shared place on narrow screens. */
  .table-toolbar .search-box {
    width: auto !important;
    flex: 1 1 160px;
    min-width: 120px;
  }
  .table-toolbar { gap: 8px; }
  /* The search <form> wrappers are inline-styled flex rows; let them
     take the full row so the input inside has room. */
  .table-toolbar form { flex: 1 1 100%; }
  .table-toolbar form .search-box { width: 100% !important; max-width: none; }

  /* Forms: single column; full-width fields. */
  .form-grid { grid-template-columns: 1fr; }
  .inline-form { flex-wrap: wrap; }

  /* 16px inputs stop iOS Safari's automatic zoom-on-focus. */
  .form-input, .form-select, .form-textarea,
  .form-control, select.form-select,
  .search-box input { font-size: 16px; }

  /* Generic kanban stacks. */
  .kanban { grid-template-columns: 1fr; }
  .k-col { min-height: 0; }

  /* Detail side column reads better after the main column. */
  .detail-grid { gap: 12px; }

  /* Compact cards + section padding. */
  .section-card { padding: 16px; }
  .table-toolbar { padding: 10px 12px; }
  .table-card .kpi-grid { padding: 10px 12px; }
  th, td, .data-table th, .data-table td { padding-left: 12px; padding-right: 12px; }

  /* Footer stacks instead of squeezing. */
  .app-footer { flex-direction: column; gap: 2px; padding: 10px 12px; }

  /* Modals: use nearly the full width. */
  .lx-modal-overlay { padding: 12px; }
  .lx-modal.lx-modal--pad { padding: 20px; }

  /* Plan cards / tenant cards: one per row is more readable. */
  .plan-grid { grid-template-columns: 1fr; }
  .tenant-card-grid { grid-template-columns: 1fr; }
}

/* ── ≤600px — small phones ────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Page titles carry the context on phones; the topbar breadcrumb
     doesn't fit next to search + icon buttons. */
  .breadcrumb { display: none; }

  .stats-row { grid-template-columns: 1fr; }

  /* KPI cards: keep the 2-up grid but compact them. */
  .kpi-grid { gap: 8px; }
  .kpi-card { padding: 12px; gap: 10px; }
  .kpi-value { font-size: 22px; }

  .page-title { font-size: 18px; }

  /* Aging rows: slightly tighter fixed columns. */
  .aging-bucket { grid-template-columns: 52px 24px 1fr 62px; gap: 6px; }
}

/* ── Touch ergonomics (any touch-first device, all widths) ────────── */
@media (pointer: coarse) {
  .icon-btn { width: 38px; height: 38px; }
  .icon-btn-sm { width: 32px; height: 32px; }
  .pg-btn { width: 34px; height: 34px; }
  .ftab { padding: 7px 12px; }
  .nav-item { padding: 10px 12px; }
  .dropdown-item { padding: 9px 12px; }
  .btn-sm, .btn-ghost.btn-sm { padding: 6px 12px; }
}
