@font-face {
  font-family: 'Google Sans';
  src: url('../fonts/GoogleSans-VariableFont_GRAD,opsz,wght.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Google Sans';
  src: url('../fonts/GoogleSans-Italic-VariableFont_GRAD,opsz,wght.ttf') format('truetype');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

:root {
  /* Flat 2D theme — white surface everywhere, no drop shadows on
     page-level elements. Floating elements (modals, popovers, FAB)
     keep their own inline shadows defined on each rule. */
  --bg: #ffffff;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --secondary: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --border: #cbd5e1;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 8px;
  --shadow: none;
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  /* Lock the page to the visual viewport so iOS Safari's address bar
   * doesn't cause the whole HTML to scroll/inset. The inner panes
   * (#content, sidebar nav, etc.) own their own scrolling. */
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}
body { font-family: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* Layout */
/* Use dynamic viewport units so the app fits exactly the visible area
 * on mobile browsers where the toolbar grows/shrinks. Falls back to
 * 100vh on browsers that don't support dvh. */
#app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
#sidebar { width: var(--sidebar-width, 220px); background: #111827; color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; transition: width 0.2s ease; overflow: hidden; position: relative; height: 100vh; height: 100dvh; }
#sidebar.collapsed { width: 48px; }
#sidebar.resizing { transition: none; }
#sidebar-resizer {
  position: absolute; right: 0; top: 0; height: 100%; width: 5px;
  cursor: col-resize; z-index: 20; background: transparent;
}
#sidebar-resizer:hover, #sidebar-resizer.dragging { background: rgba(255,255,255,0.15); }
#sidebar .logo { padding: 12px 14px; min-height: 60px; font-size: 17px; font-weight: 700; color: #fff; border-bottom: 1px solid #1f2937; display: flex; align-items: center; gap: 10px; flex-shrink: 0; cursor: pointer; transition: background 0.15s; }
#sidebar .logo:hover { background: #1f2937; }
#sidebar .logo .logo-mark { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
#sidebar .logo .logo-mark svg { display: block; }
#sidebar .logo .logo-text { white-space: nowrap; overflow: hidden; letter-spacing: -0.01em; }
#sidebar .logo .logo-text span { color: #60a5fa; }
#sidebar.collapsed .logo .logo-text { display: none; }
#sidebar nav { padding: 8px; flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: #374151 transparent; }
#sidebar nav::-webkit-scrollbar { width: 6px; }
#sidebar nav::-webkit-scrollbar-track { background: transparent; }
#sidebar nav::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
#sidebar nav::-webkit-scrollbar-thumb:hover { background: #4b5563; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #475569; padding: 8px 8px 4px; white-space: nowrap; overflow: hidden; }
#sidebar.collapsed .nav-section { opacity: 0; height: 0; padding: 0; margin: 8px 12px; border-top: 1px solid #1f2937; }
#sidebar.collapsed .nav-section:first-of-type { display: none; }
#sidebar.collapsed .logo { padding: 12px 0; justify-content: center; }
#sidebar.collapsed nav { padding: 12px 0; }
#sidebar.collapsed .nav-item { padding: 8px 14px; gap: 0; font-size: 0; }
#sidebar.collapsed .nav-item .icon { width: 20px; margin: 0; font-size: 16px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; cursor: pointer; font-size: 13.5px; margin-bottom: 2px; transition: background 0.15s; white-space: nowrap; }
.nav-item:hover { background: #1f2937; color: #f1f5f9; }
.nav-item.active { background: #2563eb; color: #fff; }
.nav-item .icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.nav-item .icon img { width: 18px; height: 18px; object-fit: contain; }
.btn .print-icon { width: 14px; height: 14px; vertical-align: -2px; object-fit: contain; display: inline-block; padding: 0; }
.btn .dl-icon { width: 14px; height: 14px; vertical-align: -2px; object-fit: contain; display: inline-block; padding: 0; }
.btn .search-icon { width: 13px; height: 13px; vertical-align: -2px; object-fit: contain; display: inline-block; padding: 0; }
#sidebar .sidebar-footer { padding: 8px; border-top: 1px solid #1f2937; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 6px; }
#sidebar.collapsed .sidebar-footer { justify-content: center; padding: 8px 0; flex-direction: column; gap: 6px; }
#sidebar .sidebar-footer .sidebar-toggle { background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 16px; width: 36px; height: 32px; display: flex; align-items: center; justify-content: center; line-height: 1; border-radius: 6px; transition: color 0.15s, background 0.15s; flex-shrink: 0; }
#sidebar .sidebar-footer .sidebar-toggle:hover { color: #fff; background: #1f2937; }
#sidebar .sidebar-footer .sidebar-account {
  background: none; border: none; color: #cbd5e1; cursor: pointer;
  display: flex; align-items: center; gap: 8px; padding: 4px 8px;
  border-radius: 6px; font-family: inherit; font-size: 13px;
  min-width: 0; flex: 1 1 auto; transition: background 0.15s, color 0.15s;
}
#sidebar .sidebar-footer .sidebar-account:hover { background: #1f2937; color: #fff; }
.sidebar-account-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.sidebar-account-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sidebar.collapsed .sidebar-account-label { display: none; }
#sidebar.collapsed .sidebar-account { padding: 4px; }

/* ============================================================
 * DOE Analyze workspace — full-screen overlay with chart + stats
 * ============================================================ */
.asm-analyze-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 24px;
}
.asm-analyze-panel {
  background: #fff;
  width: 100%; max-width: 1400px; height: 92vh;
  border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
}
.asm-analyze-header {
  padding: 12px 16px; background: #111827; color: #f1f5f9;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.asm-analyze-header strong { color: #fff; }
.asm-analyze-tabs { display: flex; gap: 4px; }
.asm-analyze-tabs .asm-tab {
  background: transparent; color: #cbd5e1;
  border: 1px solid #334155; border-radius: 6px;
  padding: 5px 12px; font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.asm-analyze-tabs .asm-tab:hover { background: #1f2937; color: #fff; }
.asm-analyze-tabs .asm-tab.on { background: #fff; color: #0f172a; border-color: #fff; }
.asm-analyze-close {
  background: transparent; color: #cbd5e1; border: none;
  font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 4px;
}
.asm-analyze-close:hover { background: #1f2937; color: #fff; }
.asm-analyze-body { flex: 1; display: flex; min-height: 0; }
.asm-analyze-sidebar {
  width: 260px; flex-shrink: 0;
  background: #f8fafc; border-right: 1px solid var(--border);
  padding: 12px 14px; overflow-y: auto;
}
.asm-analyze-main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  padding: 14px;
  background: #fff;
  overflow: hidden;
}
.asm-side-section { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px dashed var(--border); }
.asm-side-section:last-child { border-bottom: none; }
.asm-side-title {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: #64748b; margin-bottom: 8px;
}
/* Field labels: keep uppercase styling that matches the global label rule,
 * but lock down the size + spacing so they fit our narrow sidebar. */
.asm-analyze-sidebar label.asm-side-label {
  display: block; font-size: 11px; color: #475569; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 8px;
}
/* Select inside a labelled field — beat the global input/select rule */
.asm-analyze-sidebar .asm-side-label select,
.asm-analyze-sidebar select.asm-side-select {
  width: 100%; margin-top: 4px;
  padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 5px; font-size: 12.5px; font-family: inherit;
  font-weight: 400; letter-spacing: normal; text-transform: none;
  color: var(--text); background: #fff;
}
/* Numeric inputs (X min, X max, …) — also beat the global rule */
.asm-analyze-sidebar input.asm-side-input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 5px; font-size: 12px; font-family: inherit;
  font-weight: 400; letter-spacing: normal; text-transform: none;
}
.asm-analyze-sidebar input.asm-side-input::placeholder {
  text-transform: none; letter-spacing: normal; color: #94a3b8;
}
/* Inline checkbox labels: keep them sentence case so the checkbox reads
 * naturally next to its text. Also constrain the checkbox to its native
 * size — the global input rule was stretching it to 100% width. */
.asm-analyze-sidebar label.asm-side-check {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: #475569; cursor: pointer; margin-top: 6px;
  font-weight: 500;
  text-transform: none; letter-spacing: normal;
  white-space: nowrap;
}
.asm-analyze-sidebar label.asm-side-check input[type="checkbox"] {
  width: 14px; height: 14px; padding: 0; margin: 0; flex-shrink: 0;
  accent-color: var(--primary);
}
/* Range-input grids (X min/max, Y min/max) — make sure the two columns
 * actually let inputs shrink to fit instead of overflowing. */
.asm-analyze-sidebar .asm-side-grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 6px;
}
.asm-side-help {
  font-size: 11.5px; color: #64748b; line-height: 1.45;
  background: #fff; border: 1px solid var(--border);
  border-radius: 5px; padding: 8px 10px;
}
.asm-toggle-group {
  display: flex; gap: 4px; margin-bottom: 8px;
  border: 1px solid var(--border); background: #fff;
  border-radius: 6px; padding: 2px;
}
.asm-toggle {
  flex: 1; background: transparent; border: none;
  padding: 5px 8px; font-size: 11.5px; font-weight: 500;
  cursor: pointer; border-radius: 4px; color: #475569; font-family: inherit;
}
.asm-toggle:hover:not(.on) { background: #f1f5f9; }
.asm-toggle.on { background: var(--primary); color: #fff; }

/* Chart + stats */
.asm-chart-wrap {
  flex: 1; min-height: 0;
  position: relative; background: #fff;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px;
}
.asm-stats-panel {
  flex-shrink: 0; max-height: 38%; overflow-y: auto;
  margin-top: 10px; padding: 10px 12px;
  background: #f8fafc; border: 1px solid var(--border); border-radius: 6px;
  font-size: 12px; color: #1e293b;
}
.asm-stats-title {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: #64748b; margin-bottom: 6px;
}
.asm-stat-line {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 6px; padding: 3px 0;
}
.asm-stat-chip {
  background: #fff; border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 7px; font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.asm-series-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; flex-shrink: 0;
}

/* Per-point color picker popup */
.asm-color-menu {
  position: fixed; z-index: 300;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  padding: 8px; box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
  min-width: 180px;
}
.asm-color-menu-title {
  font-size: 11px; font-weight: 600; color: #475569;
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px;
}
.asm-color-swatches {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-bottom: 8px;
}
.asm-color-swatch {
  width: 26px; height: 22px; border-radius: 4px; border: 1px solid rgba(0,0,0,0.1);
  cursor: pointer; padding: 0;
}
.asm-color-swatch:hover { transform: scale(1.08); }
.asm-color-clear {
  width: 100%; background: #f1f5f9; border: 1px solid var(--border);
  border-radius: 4px; padding: 5px 8px; font-size: 11.5px;
  cursor: pointer; font-family: inherit;
}

/* Correlation heatmap */
.asm-hm-legend {
  display: flex; align-items: center; gap: 8px;
  font-size: 11.5px; color: #475569; margin-bottom: 10px;
}
.asm-hm-bar {
  flex: 0 0 180px; height: 12px; border-radius: 3px;
  background: linear-gradient(to right, rgb(255, 38, 38), #fff, rgb(38, 38, 255));
  border: 1px solid var(--border);
}
.asm-hm-sigkey { color: #94a3b8; }
.asm-hm-scroll { flex: 1; min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
.asm-hm-grid {
  display: grid;
  gap: 0;
}
.asm-hm-cell {
  font-size: 11px; padding: 6px 8px;
  border-right: 1px solid #e2e8f0; border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; justify-content: center;
  text-align: center; min-height: 30px;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}
.asm-hm-corner { background: #f1f5f9; border-bottom: 1px solid #cbd5e1; height: 150px; }
/* Column headers rotated 45° so long labels fit above narrow cells. */
.asm-hm-colhdr {
  background: #f1f5f9; font-weight: 600; color: #334155;
  font-size: 11px; padding: 0;
  border-bottom: 1px solid #cbd5e1;
  position: relative;
  height: 150px;
  display: flex; align-items: flex-end; justify-content: flex-start;
  overflow: visible;
}
.asm-hm-colhdr-inner {
  transform: rotate(-45deg);
  transform-origin: left bottom;
  white-space: nowrap;
  padding: 0 6px 4px 4px;
  line-height: 1.2;
  position: absolute;
  bottom: 6px;
  left: 50%;
  pointer-events: none;
}
.asm-hm-rowhdr {
  background: #f1f5f9; font-weight: 600; color: #334155;
  font-size: 11px; padding: 6px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-right: 1px solid #cbd5e1;
  text-align: right; justify-content: flex-end; align-items: center;
  min-width: 160px; max-width: 220px;
}
.asm-hm-data {
  background: #fff; border: none; cursor: pointer;
  font-weight: 600; font-family: inherit;
  border-right: 1px solid rgba(0,0,0,0.05);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  display: flex; flex-direction: column; gap: 0;
  padding: 4px 6px; min-height: 32px;
}
.asm-hm-data:hover:not(.asm-hm-diag) { outline: 2px solid #0f172a; outline-offset: -2px; }
.asm-hm-diag { cursor: default; opacity: 0.6; }
.asm-hm-val { font-size: 11.5px; line-height: 1.2; }
.asm-hm-stars { font-size: 9px; opacity: 0.85; line-height: 1; }

@media (max-width: 768px) {
  .asm-analyze-overlay { padding: 0; }
  .asm-analyze-panel { height: 100vh; height: 100dvh; max-width: none; border-radius: 0; }
  .asm-analyze-body { flex-direction: column; }
  .asm-analyze-sidebar { width: 100%; max-height: 35%; border-right: none; border-bottom: 1px solid var(--border); }
}

/* Account popup — floats above the account button when toggled */
.sidebar-account-wrap { position: relative; flex: 1 1 auto; min-width: 0; display: flex; }
.sidebar-account-popup {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  background: #1f2937;
  color: #f1f5f9;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  display: none;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  z-index: 60;
}
.sidebar-account-popup.open { display: inline-flex; }
.sidebar-account-popup::after {
  /* Arrow pointing down at the account button */
  content: "";
  position: absolute;
  top: 100%;
  left: 14px;
  border: 6px solid transparent;
  border-top-color: #1f2937;
}
.sidebar-account-popup-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--warning);
  flex-shrink: 0;
}

#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 24px; height: 56px; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); }
#topbar h1 { font-size: 17px; font-weight: 600; }
#back-btn:hover { background: #f1f5f9; color: #1e293b; }
#topbar .actions { display: flex; gap: 8px; }
#content { flex: 1; padding: 24px; overflow-y: auto; }

/* Cards / panels */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body { padding: 18px; }

/* Ingredient filter row */
.ing-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  align-items: flex-start;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.ing-filter-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ing-filter-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.ing-filter-chips { display: flex; flex-wrap: wrap; gap: 4px; max-width: 320px; }

/* Compact filter row: each filter group is one horizontal line
 * (label on the left, chips inline to the right) so the panel
 * doesn't grow tall with many chip values. */
.test-filter-row-compact { flex-direction: column; gap: 8px; }
.ing-filter-group-h {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  width: 100%;
}
.ing-filter-group-h .ing-filter-label {
  flex: 0 0 100px;
  text-align: right;
}
.ing-filter-group-h .ing-filter-chips {
  flex: 1 1 auto;
  max-width: none;
  min-width: 0;
}
.ing-filter-row-clear { align-self: flex-end; }
@media (max-width: 768px) {
  .ing-filter-group-h { flex-wrap: wrap; }
  .ing-filter-group-h .ing-filter-label { flex-basis: auto; text-align: left; }
}
.ing-filter-chip {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.ing-filter-chip:hover:not(.on) { background: #f1f5f9; border-color: #94a3b8; }
.ing-filter-chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.ing-filter-chip-picto { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 4px; }
.ing-filter-chip-picto .picto-mini { display: inline-flex; align-items: center; justify-content: center; }
.ing-filter-chip-picto .picto-mini svg { display: block; }
.ing-filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}

/* View mode toggle (Table / Cards / Group) */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; flex-shrink: 0; }
.view-toggle-btn { background: #fff; border: none; padding: 5px 12px; font-size: 12px; color: var(--text-muted); cursor: pointer; transition: background 0.15s, color 0.15s; border-right: 1px solid var(--border); white-space: nowrap; }
.view-toggle-btn:last-child { border-right: none; }
.view-toggle-btn:hover:not(.on) { background: #f1f5f9; color: var(--text); }
.view-toggle-btn.on { background: var(--primary); color: #fff; }

/* Cards view */
.ing-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; padding: 14px; }
.ing-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; display: flex; flex-direction: column; position: relative; }
.ing-card:hover { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
/* Always-visible kebab menu used by every list card variant
 * (Projects / Ingredients / Formulations / Batches / Samples).
 * Tucks into the top-right corner; opens a popup menu on click. */
.card-kebab-wrap {
  position: absolute;
  top: 6px; left: 6px;
  z-index: 3;
}
.card-kebab {
  width: 22px; height: 22px;
  padding: 0;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid transparent;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.card-kebab:hover,
.card-kebab.open { color: var(--text); background: #fff; border-color: var(--border); }
.card-kebab-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px); left: 0;
  min-width: 140px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  padding: 4px;
  flex-direction: column;
  z-index: 10;
}
.card-kebab-menu.open { display: flex; }
.card-kebab-menu button {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 6px 10px;
  background: none; border: none;
  font-size: 12.5px; text-align: left;
  color: var(--text);
  cursor: pointer; border-radius: 4px;
  white-space: nowrap;
  font-family: inherit;
}
.card-kebab-menu button:hover { background: #f1f5f9; }
.card-kebab-menu button.danger { color: var(--danger); }
.card-kebab-menu button.danger:hover { background: #fee2e2; }
/* Push the first content row right so it doesn't collide with the
 * kebab in the top-left corner. The kebab-wrap itself is absolute-
 * positioned, so we want the padding on the next sibling. */
.ing-card .ing-card-body > div:first-child,
.ing-group-card > .card-kebab-wrap + div { padding-left: 28px; }
.ing-card-thumb { background: #f8fafc; padding: 4px; height: 120px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--border); }
.ing-card-body { padding: 10px 12px 12px; }

/* Group / kanban view */
.ing-group-board { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); align-items: start; gap: 12px; padding: 14px; }
.ing-group-col { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; display: flex; flex-direction: column; max-height: 70vh; min-width: 0; }
.ing-group-head { padding: 10px 12px; border-bottom: 1px solid #1f2937; background: #111827; color: #fff; border-radius: 8px 8px 0 0; }
.ing-group-list { padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.ing-group-card { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; cursor: pointer; transition: border-color 0.15s; position: relative; }
.ing-group-card:hover { border-color: var(--primary); }

/* Data view */
.data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  max-width: 900px;
}
.data-grid > .card:first-child { grid-column: 1 / -1; }
.data-grid > .data-danger-card {
  grid-column: 1 / -1;
  border: 2px solid var(--danger);
}

/* Chart-type selector in arrange-mode panel headers */
.dash-chart-type {
  display: none;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
}
.dash-edit .dash-chart-type { display: inline-block; }

/* Cost basis selector — sits inline in the composition table header */
.cost-basis-select {
  font-family: inherit;
  font-size: 12px;
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  width: auto;          /* don't stretch inside flex containers */
}
.cost-basis-select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Pricing & Margin — single-line basis bar above the input grid */
.pricing-basis-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-bottom: 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  flex-wrap: wrap;     /* graceful wrap only if absolutely needed */
}
.pricing-basis-bar .pbb-label  { color: var(--text-muted); }
.pricing-basis-bar .pbb-value  { color: var(--primary); font-weight: 700; }
.pricing-basis-bar .pbb-select {
  flex: 0 0 auto;
  width: auto;
  min-width: 80px;
  padding: 3px 8px;
}
.pricing-basis-bar .pbb-hint {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 11px;
  font-style: italic;
}

/* Cost change indicator */
.cost-change-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.cost-change-chip.up   { background: #fef2f2; color: var(--danger); }
.cost-change-chip.down { background: #f0fdf4; color: #16a34a; }

/* Sort panel — popover anchored to ⇅ Sort button */
.sort-panel {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
  z-index: 90;
  font-family: inherit;
}
.sort-panel-header {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sort-panel-close {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  color: #94a3b8;
  padding: 0 4px;
  line-height: 1;
}
.sort-panel-close:hover { color: var(--text); }
.sort-panel-body { padding: 6px 14px; }
.sort-panel-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sort-key-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
}
.sort-key-num {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: #eff6ff;
  border-radius: 4px;
  padding: 2px 0;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}
.sort-key-col {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #fff;
}
.sort-dir-toggle {
  display: inline-flex;
  flex-shrink: 0;
}
.sort-dir-btn {
  border: 1px solid var(--border);
  background: #fff;
  font-size: 11px;
  padding: 4px 8px;
  cursor: pointer;
  line-height: 1.4;
  color: var(--text);
}
.sort-dir-btn:first-child { border-radius: 5px 0 0 5px; }
.sort-dir-btn:last-child  { border-radius: 0 5px 5px 0; margin-left: -1px; }
.sort-dir-btn.on { background: var(--primary); color: #fff; border-color: var(--primary); z-index: 1; position: relative; }
.sort-key-move,
.sort-key-remove {
  width: 24px;
  height: 24px;
  font-size: 11px;
  background: #f1f5f9;
  color: #475569;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
}
.sort-key-move:hover:not(:disabled),
.sort-key-remove:hover { background: #e2e8f0; }
.sort-key-move:disabled { opacity: 0.35; cursor: not-allowed; }
.sort-key-remove:hover { background: #fee2e2; color: var(--danger); }
.sort-empty {
  padding: 14px 4px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

/* Floating Feedback button — collapsed icon by default, expands on hover/focus */
.feedback-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  padding: 0;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
  z-index: 50;
  transition:
    width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
    padding 0.28s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.2s ease,
    background 0.15s ease,
    transform 0.15s ease;
}
.feedback-fab-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}
.feedback-fab-label {
  opacity: 0;
  margin-right: 14px;
  transition: opacity 0.18s ease 0.06s;
}
.feedback-fab:hover,
.feedback-fab:focus-visible {
  width: 132px;
  background: #1d4ed8;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
  transform: translateY(-1px);
}
.feedback-fab:hover .feedback-fab-label,
.feedback-fab:focus-visible .feedback-fab-label { opacity: 1; }
.feedback-fab:focus-visible { outline: 2px solid #1d4ed8; outline-offset: 3px; }
.feedback-fab:active { transform: translateY(0); }
.data-snapshot {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 24px;
}
.data-section-title {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 6px 4px 0 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-top: 4px;
}
.data-section-title.danger { color: var(--danger); border-bottom-color: #fecaca; }
.data-grid .card .card-body p:last-of-type { margin-bottom: 14px; }
.data-grid .card .demo-bullets {
  color: var(--text-muted);
  font-size: 12.5px;
  margin: 0 0 12px 18px;
  line-height: 1.65;
}
.data-snapshot > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.data-snapshot .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.data-snapshot .value { font-size: 16px; font-weight: 600; }

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card.blue .value { color: var(--primary); }
.stat-card.green .value { color: var(--success); }
.stat-card.amber .value { color: var(--warning); }

/* Dashboard draggable grid */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 220px;
  grid-auto-flow: row dense;
  gap: 16px;
  align-items: stretch;
}
.dash-panel { min-width: 0; min-height: 0; position: relative; }
.dash-panel > .card { height: 100%; overflow: hidden; }

/* Drag handle — hidden until Arrange mode */
.dash-drag-handle {
  display: none; cursor: grab; font-size: 18px; color: #94a3b8;
  line-height: 1; flex-shrink: 0; padding: 2px;
  border-radius: 4px; transition: color 0.15s;
}
.dash-drag-handle:active { cursor: grabbing; }
.dash-edit .dash-drag-handle { display: block; }
.dash-edit .dash-drag-handle:hover { color: var(--primary); }

/* Close button — floats top-right of panel, only in arrange mode */
.dash-close {
  position: absolute;
  top: -8px; right: -8px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  color: #64748b;
  font-size: 15px; line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  transition: all 0.15s;
  z-index: 2;
}
.dash-close:hover { background: var(--danger); color: #fff; border-color: var(--danger); transform: scale(1.05); }
.dash-edit .dash-close { display: inline-flex; }

/* Resize handle — bottom-right corner, only in arrange mode */
.dash-resize-handle {
  position: absolute;
  bottom: 2px; right: 2px;
  width: 16px; height: 16px;
  cursor: nwse-resize;
  display: none;
  z-index: 2;
  background:
    linear-gradient(135deg,
      transparent 0%, transparent 55%,
      #94a3b8 55%, #94a3b8 65%,
      transparent 65%, transparent 75%,
      #94a3b8 75%, #94a3b8 85%,
      transparent 85%);
  border-radius: 0 0 var(--radius) 0;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.dash-resize-handle:hover { opacity: 1; }
.dash-edit .dash-resize-handle { display: block; }
.dash-panel.dash-resizing { user-select: none; }
.dash-panel.dash-resizing > .card { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Add-panel tile — sibling below the grid, only in arrange mode */
.dash-add-tile {
  display: none;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 16px;
  padding: 14px 20px;
  background: transparent;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  color: #64748b;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.dash-add-tile:hover { border-color: var(--primary); color: var(--primary); background: #f8fafc; }
.dash-add-plus { font-size: 22px; line-height: 1; font-weight: 300; }
.dash-grid.dash-edit + .dash-add-tile { display: flex; }

.dash-add-menu {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  min-width: 220px;
  padding: 6px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dash-add-item {
  background: transparent;
  border: none;
  padding: 8px 12px;
  text-align: left;
  font-size: 13px;
  border-radius: 4px;
  cursor: pointer;
  color: #1e293b;
}
.dash-add-item:hover { background: #f1f5f9; color: var(--primary); }
.dash-add-empty { padding: 10px 12px; font-size: 13px; color: #94a3b8; font-style: italic; }

/* Drag states */
.dash-panel.dash-dragging { opacity: 0.3; }
.dash-panel.dash-over > .card {
  outline: 2px dashed var(--primary);
  outline-offset: 3px;
  background: #eff6ff;
}

/* Edit mode — highlight panels */
.dash-edit .dash-panel > .card {
  outline: 1px dashed #cbd5e1;
  outline-offset: 2px;
}
.dash-edit .dash-panel:hover > .card { outline-color: #94a3b8; }
.stat-card.red .value { color: var(--danger); }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { background: #f8fafc; text-align: left; padding: 10px 14px; font-weight: 400; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); border-bottom: 2px solid var(--border); white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 10px 14px; vertical-align: middle; }
.empty-row td { text-align: center; color: var(--text-muted); padding: 32px; font-style: italic; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: all 0.15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f1f5f9; }
.btn-print { background: #0f172a; color: #fff; border-color: #0f172a; }
.btn-print:hover { background: #1e293b; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: #dcfce7; color: var(--success); }
.btn-success:hover { background: #bbf7d0; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 5px 8px; }

/* Forms */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 10px; width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 25px rgba(0,0,0,0.15); }
.modal.wide { max-width: 860px; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }
label { font-size: 12px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit; color: var(--text); background: #fff; transition: border-color 0.15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
textarea { resize: vertical; min-height: 70px; }
.section-divider { margin: 16px 0; border: none; border-top: 1px solid var(--border); }
.section-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 10px; padding-bottom: 6px; border-bottom: 2px solid var(--primary); display: inline-block; }

/* Audit badge — small pill used in the audit log table */
.audit-badge { display: inline-block; padding: 2px 8px; border-radius: 9999px; font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em; }

/* Notebook entry — Quill HTML is rendered raw, so re-apply the formatting
   styles outside the editor's own scoped CSS. */
.notebook-entry p          { margin: 0 0 6px; }
.notebook-entry p:last-child { margin-bottom: 0; }
.notebook-entry h2         { font-size: 16px; font-weight: 700; margin: 8px 0 6px; }
.notebook-entry h3         { font-size: 14px; font-weight: 600; margin: 8px 0 6px; }
.notebook-entry ul, .notebook-entry ol { margin: 4px 0 6px 22px; padding: 0; }
.notebook-entry li         { margin-bottom: 2px; }
.notebook-entry blockquote { border-left: 3px solid var(--border); padding: 2px 10px; margin: 6px 0; color: var(--text-muted); }
.notebook-entry pre, .notebook-entry .ql-code-block { background: #f1f5f9; padding: 8px 10px; border-radius: 4px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; white-space: pre-wrap; margin: 6px 0; }
.notebook-entry a          { color: var(--primary); text-decoration: underline; }

/* Grouped form / detail sections (Ingredient modal + detail view) */
.form-section { display: flex; flex-direction: column; gap: 8px; padding-top: 14px; margin-top: 10px; border-top: 1px solid var(--border); }
.form-section:first-of-type { padding-top: 0; margin-top: 0; border-top: none; }
.ing-section-h { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin: 0 0 10px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }

/* GHS pictograms + H/P code pills */
.ghs-pictogram { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; }
.ghs-code-pill { display: inline-block; padding: 2px 8px; border-radius: 9999px; font-size: 11.5px; font-weight: 600; border: 1px solid; background: #fff; cursor: help; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 9999px; font-size: 11.5px; font-weight: 500; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

/* Composition table */
.comp-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1.5fr 36px; gap: 6px; align-items: center; margin-bottom: 6px; }
.comp-header { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); padding-bottom: 4px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.step-row { display: grid; grid-template-columns: 40px 1fr 80px 80px 100px 36px; gap: 6px; align-items: start; margin-bottom: 8px; }
.step-num { background: var(--primary); color: #fff; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; flex-shrink: 0; margin-top: 2px; }

/* Detail view */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-field { }
.detail-field .label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 3px; }
.detail-field .value { font-size: 14px; }
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 18px; }
.tab { padding: 8px 16px; font-size: 13.5px; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; color: var(--text-muted); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover:not(.active) { color: var(--text); }

/* Alerts */
.alert { padding: 12px 14px; border-radius: 6px; font-size: 13.5px; margin-bottom: 16px; }
.alert-info { background: #eff6ff; color: #1d4ed8; border-left: 3px solid var(--primary); }

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.breadcrumb a { color: var(--primary); cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--border); }

/* Legacy responsive block removed — the mobile drawer + media query
 * below now handle sidebar / form-grid layout on narrow viewports. */

/* Tier 3 mobile-utility classes:
 *   .desktop-only — hidden below 768px (mobile)
 *   .mobile-warn  — a small banner that's hidden on desktop and
 *                   shown above content that doesn't translate well
 *                   to mobile (DOE Matrix, Composition editor, etc.) */
.mobile-warn { display: none; }
.mobile-warn-banner {
  align-items: flex-start; gap: 10px;
  background: #fffbeb; border: 1px solid #f59e0b; border-radius: 8px;
  padding: 10px 12px; margin: 0 0 14px 0;
  font-size: 13px; color: #92400e; line-height: 1.45;
}
.mobile-warn-banner .icon { font-size: 16px; flex-shrink: 0; line-height: 1; }
@media (max-width: 768px) {
  .desktop-only { display: none !important; }
  .mobile-warn { display: flex; }
}
thead th { position: relative; }
.col-rh { position: absolute; right: 0; top: 0; height: 100%; width: 5px; cursor: col-resize; z-index: 2; user-select: none; }
.col-rh:hover, .col-rh:active { background: var(--primary); opacity: 0.4; border-radius: 2px; }
.col-picker-item:hover { background: #f1f5f9; }
.col-picker-item .col-drag-grip { opacity: 0.4; }
/* Column drag-to-reorder — data tables and compare table */
thead th[draggable="true"] { cursor: grab; }
thead th[draggable="true"]:active { cursor: grabbing; }
thead th.col-drag-over { box-shadow: -3px 0 0 var(--primary); }
.col-picker-item:hover .col-drag-grip { opacity: 1; }

/* Formula Analysis tabs */
.fa-tab {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 14px; cursor: pointer; font-size: 13px; color: var(--text-muted);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.fa-tab:hover { background: #f1f5f9; color: var(--text); }
.fa-tab-on { background: var(--primary); color: #fff; border-color: var(--primary); }
.fa-tab-on:hover { background: var(--primary-dark); }

/* ============================================================
   COLUMN HEADER FILTERS
   ============================================================ */
tr.filter-row th {
  background: #f1f5f9; padding: 5px 8px; border-bottom: 2px solid var(--border);
}
.col-filter {
  width: 100%; padding: 3px 6px; font-size: 12px;
  border: 1px solid #cbd5e1; border-radius: 4px;
  font-family: inherit; color: var(--text); background: #fff;
}
.col-filter:focus { outline: none; border-color: var(--primary); }
.col-filter-clear {
  background: none; border: none; cursor: pointer;
  color: #94a3b8; font-size: 14px; padding: 2px 4px;
  border-radius: 4px; line-height: 1;
}
.col-filter-clear:hover { color: var(--danger); background: #fee2e2; }

/* ============================================================
   BULK SELECTION
   ============================================================ */
.bulk-check-col { width: 36px; padding: 0 8px !important; text-align: center; }
.bulk-check-col input[type="checkbox"] {
  cursor: pointer; width: 15px; height: 15px;
  accent-color: var(--primary); vertical-align: middle;
}
.bulk-bar {
  display: none; align-items: center; gap: 10px;
  padding: 8px 18px; background: #eff6ff;
  border-bottom: 1px solid #bfdbfe; font-size: 13px; color: #1d4ed8;
}
.bulk-bar .bulk-count { font-weight: 600; flex: 1; }

/* ============================================================
   PRINT / PDF  (Dashboard only)
   ============================================================ */
@media print {
  /* Force color printing */
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide all chrome except the dashboard content */
  #sidebar,
  #topbar,
  .breadcrumb,
  #import-file { display: none !important; }

  /* Remove arrange/print controls from output */
  #dash-arrange-btn,
  .dash-drag-handle,
  .dash-close,
  .dash-resize-handle,
  .dash-add-tile,
  .dash-add-menu,
  .feedback-fab,
  .sort-panel,
  .btn { display: none !important; }

  /* Make layout take full page width */
  body, #app, #main { display: block !important; width: 100% !important; }
  #content { padding: 0 !important; overflow: visible !important; }
  #main { overflow: visible !important; }

  /* Print header — date + title */
  #dash-grid::before {
    content: "FormLab Dashboard  ·  " attr(data-print-date);
    display: block;
    font-size: 11px;
    color: #64748b;
    text-align: right;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e2e8f0;
    grid-column: 1 / -1;
  }

  /* Keep grid structure, allow wrapping across pages */
  .dash-grid {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    grid-auto-rows: auto !important;
    gap: 12px !important;
  }

  /* Avoid splitting a panel card across a page break */
  .dash-panel { break-inside: avoid; }

  /* Stat grid */
  .stat-grid {
    display: grid !important;
    grid-template-columns: repeat(7, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 14px !important;
  }
  .stat-card { padding: 10px 12px !important; }
  .stat-card .value { font-size: 20px !important; }

  /* Tables */
  .table-wrap { overflow: visible !important; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; }

  /* Cards */
  .card { box-shadow: none !important; border: 1px solid #e2e8f0 !important; }
  .card-header { padding: 8px 12px !important; }
}

/* ============================================================
 * Mobile (Tier 1) — viewport <= 768px
 * Sidebar becomes a slide-in drawer, modals go full-screen,
 * form grids stack, topbar actions scroll horizontally.
 * ============================================================ */

/* Backdrop + burger are off by default; the @media block below
 * makes the burger visible and lets the backdrop show when the
 * sidebar's .mobile-open class is on. */
#sidebar-backdrop { display: none; }
#mobile-menu-btn {
  display: none;
  background: none; border: none; cursor: pointer;
  color: var(--text); padding: 4px 8px;
  font-size: 22px; line-height: 1;
  border-radius: 6px;
}
#mobile-menu-btn:hover { background: #f1f5f9; }

@media (max-width: 768px) {
  #mobile-menu-btn { display: inline-flex; }

  /* Sidebar becomes a fixed drawer that slides in from the left */
  #sidebar {
    position: fixed; top: 0; left: 0;
    width: 240px !important;
    height: 100vh;
    height: 100dvh;
    z-index: 120;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.3);
  }
  #sidebar.mobile-open { transform: translateX(0); }
  /* On mobile, ignore desktop "collapsed" mode — drawer is binary */
  #sidebar.collapsed { width: 240px !important; }
  #sidebar.collapsed .logo-text,
  #sidebar.collapsed .nav-section,
  #sidebar.collapsed .nav-item { font-size: inherit; opacity: 1; height: auto; }
  #sidebar.collapsed .nav-item { padding: 8px 14px; gap: 10px; }
  #sidebar.collapsed .nav-item .icon { font-size: 16px; margin-right: 6px; }
  #sidebar-resizer { display: none; }
  /* Hide the collapse toggle on mobile (drawer is binary) but keep
   * the account button visible at the bottom of the drawer. */
  #sidebar .sidebar-footer { justify-content: flex-start; }
  #sidebar .sidebar-footer .sidebar-toggle { display: none; }

  /* Backdrop — visible whenever the drawer is open */
  #sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 110;
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
  }
  body.sidebar-open #sidebar-backdrop { opacity: 1; pointer-events: auto; }

  /* Main takes the full viewport — sidebar overlays it */
  #main { width: 100%; }
  #topbar { padding: 0 12px; gap: 8px; }
  #topbar h1 { font-size: 15px; }

  /* Topbar actions: scroll horizontally instead of wrapping */
  #topbar .actions {
    overflow-x: auto; overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: thin;
    margin-left: 8px;
    padding: 4px 0;
  }
  #topbar .actions::-webkit-scrollbar { height: 4px; }
  #topbar .actions .btn { flex-shrink: 0; }

  /* Modal: full-screen */
  .modal-backdrop { padding: 0; }
  .modal, .modal.wide {
    width: 100%; max-width: none;
    height: 100vh; max-height: 100vh;
    border-radius: 0;
  }
  .modal-body { padding: 14px; }
  .modal-header { padding: 12px 14px; }
  .modal-footer { padding: 12px 14px; }

  /* Form grids collapse to single column */
  .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; }
  .form-group.span-2, .form-group.span-3 { grid-column: span 1; }

  /* Bigger tap targets for primary interactive elements */
  .btn { padding: 9px 14px; min-height: 36px; }
  .btn-sm { padding: 6px 10px; min-height: 32px; }
  .btn-icon { min-width: 32px; min-height: 32px; padding: 4px 8px; }
  input, select, textarea { padding: 10px 12px; font-size: 15px; }
  .nav-item { min-height: 40px; }

  /* Data view grid collapses */
  .data-grid { grid-template-columns: 1fr; }

  /* ---- Tier 2: read-optimized detail / dashboard / table layouts ---- */

  /* Detail panel grids (info / stats / etc.) → single column. Several
   * call sites set grid-template-columns inline (e.g., "repeat(3,1fr)")
   * so we use !important to win the cascade. */
  .detail-grid { grid-template-columns: 1fr !important; }
  .detail-field[style*="grid-column"] { grid-column: span 1 !important; }

  /* Tabs scroll horizontally instead of wrapping */
  .tabs {
    overflow-x: auto; overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tabs::-webkit-scrollbar { height: 3px; }
  .tab { flex-shrink: 0; white-space: nowrap; padding: 8px 12px; font-size: 13px; }

  /* Dashboard draggable grid → stack panels vertically */
  .dash-grid {
    grid-template-columns: 1fr !important;
    grid-auto-rows: auto !important;
    gap: 12px;
  }
  .dash-panel {
    grid-column: span 1 !important;
    grid-row: auto !important;
  }
  .dash-panel > .card { height: auto; min-height: 180px; overflow: visible; }
  /* Hide arrange/resize affordances on mobile — desktop-only workflow */
  .dash-resize-handle, .dash-close { display: none !important; }

  /* Stat grid: 2 columns instead of auto-fill minmax-180 (which leaves
   * too much padding on narrow viewports) */
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card .value { font-size: 22px; }

  /* Breadcrumb tighter */
  .breadcrumb { font-size: 12px; margin-bottom: 12px; }

  /* Tables already scroll horizontally via .table-wrap, but we add a
   * shadow hint at the right edge so users see they can swipe. */
  .table-wrap { position: relative; }
  .table-wrap::after {
    content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 12px;
    background: linear-gradient(to left, rgba(0,0,0,0.07), transparent);
    pointer-events: none;
  }
}
