/* ==========================================================================
   MEXOS Design System v3 — single source of truth for every page.

   Replaces the previous patched-together system (two parallel button
   naming conventions, two status-pill color maps, glassmorphism panels,
   no shared navigation). Every class name emitted dynamically by page
   JS (status pills/badges, icon buttons, spreadsheet inputs, timeline,
   product-search dropdown, etc.) is preserved here so no .js file needs
   to change — only the visual language underneath it.
   ========================================================================== */

:root {
  /* ---- Brand (teal + navy). Variable names kept as --brand-orange* for
     back-compat; they now hold the teal primary. ---- */
  --brand-orange: #007a7c;
  --brand-orange-hover: #006d6e;
  --brand-orange-tint: rgba(0, 122, 124, 0.1);
  --brand-navy: #111e3b;
  --brand-navy-soft: #16233f;

  /* ---- Neutral ramp (cool, slightly navy-tinted) ---- */
  --gray-50: oklch(0.985 0.003 260);
  --gray-100: oklch(0.967 0.005 260);
  --gray-200: oklch(0.928 0.007 260);
  --gray-300: oklch(0.869 0.011 260);
  --gray-400: oklch(0.704 0.015 260);
  --gray-500: oklch(0.554 0.017 260);
  --gray-600: oklch(0.446 0.019 260);
  --gray-700: oklch(0.371 0.021 260);
  --gray-800: oklch(0.278 0.022 260);
  --gray-900: oklch(0.21 0.02 260);
  --color-white: #ffffff;
  --color-black: #000000;

  /* ---- Semantic status colors (one canonical mapping, used by every
     status-pill / status-badge across the app) ---- */
  --color-success: oklch(0.52 0.14 155); /* was 0.6 -- 3.32:1 on --color-success-bg, below 4.5:1 AA. 0.52 -> 4.58:1 */
  --color-success-bg: oklch(0.96 0.03 155);
  --color-warning: oklch(0.54 0.16 65); /* was 0.6 -- 3.70:1 on --color-warning-bg, below 4.5:1 AA. 0.54 -> 4.77:1 */
  --color-warning-bg: oklch(0.97 0.04 80);
  --color-danger: oklch(0.55 0.2 25);
  --color-danger-bg: oklch(0.96 0.035 25);
  --color-info: oklch(0.52 0.16 250); /* was 0.56 -- 4.14:1 on --color-info-bg, below 4.5:1 AA. 0.52 -> 4.89:1 */
  --color-info-bg: oklch(0.96 0.02 250);
  --color-neutral-bg: var(--gray-100);
  --color-neutral-text: var(--gray-600);

  /* ---- Aliases used throughout markup / inline styles ---- */
  --color-primary: var(--brand-orange);
  --color-primary-hover: var(--brand-orange-hover);
  --color-primary-dark: var(--brand-orange-hover);
  --color-primary-light: var(--brand-orange-tint);
  --color-secondary: var(--gray-500);
  --color-brand-primary: var(--brand-orange);
  --color-brand-primary-hover: var(--brand-orange-hover);
  --color-brand-navy: var(--brand-navy);
  --brand-slate: var(--gray-800);

  --color-text-primary: var(--gray-900);
  --color-text-secondary: var(--gray-600);
  --color-text-tertiary: var(--gray-500); /* 4.77:1 on white, passes WCAG AA for placeholder/label text */

  --color-bg-primary: var(--gray-50);
  --color-bg-secondary: var(--color-white);
  --color-bg-tertiary: var(--gray-100);
  --color-bg-brand: var(--brand-orange-tint);

  --color-border-primary: var(--gray-200);
  --color-border-secondary: var(--gray-300);
  --color-border-brand: var(--brand-orange);

  --color-gray-50: var(--gray-50);
  --color-gray-100: var(--gray-100);
  --color-gray-200: var(--gray-200);
  --color-gray-300: var(--gray-300);
  --color-gray-400: var(--gray-400);
  --color-gray-500: var(--gray-500);
  --color-gray-600: var(--gray-600);
  --color-gray-700: var(--gray-700);
  --color-gray-800: var(--gray-800);
  --color-gray-900: var(--gray-900);

  /* ---- Elevation ---- */
  --shadow-sm: 0 1px 2px 0 rgba(17, 30, 59, 0.05);
  --shadow-md: 0 4px 10px -2px rgba(17, 30, 59, 0.08), 0 2px 4px -2px rgba(17, 30, 59, 0.05);
  --shadow-lg: 0 12px 24px -6px rgba(17, 30, 59, 0.12), 0 4px 8px -4px rgba(17, 30, 59, 0.06);
  --glass-bg: var(--color-bg-secondary);
  --glass-border: var(--color-border-primary);
  --glass-shadow: var(--shadow-sm);

  /* ---- Spacing ---- */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  /* ---- Radius ---- */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* ---- Type: fixed rem scale, tight ratio (product UI, not fluid) ---- */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.8125rem;
  --font-size-base: 0.875rem;
  --font-size-md: 0.9375rem;
  --font-size-lg: 1.0625rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;

  /* ---- Layout ---- */
  --header-height: 64px;
  --sidebar-width: 248px;
  --sidebar-width-collapsed: 76px;
  --container-width: 1400px;
  --container-max-width: var(--container-width);

  /* ---- Z-index scale ---- */
  --z-dropdown: 1000;
  --z-sticky: 1100;
  --z-modal-backdrop: 1200;
  --z-modal: 1210;
  --z-toast: 1300;
  --z-tooltip: 1400;

  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  background-color: var(--color-bg-primary);
  color: var(--color-text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }

h1, h2, h3, h4, h5, h6 { text-wrap: balance; }
p { text-wrap: pretty; }

a { color: var(--color-text-primary); }
a:not([class*="btn"]):hover { color: var(--color-primary); }

button, input, select, textarea { font-family: inherit; }

::selection { background: var(--brand-orange-tint); color: var(--color-text-primary); }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

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

  /* Movement is suppressed above; keep color/opacity feedback perceptible
     rather than instant, since those aid comprehension (hover/focus states,
     error banners, dropdown reveals) rather than causing motion discomfort.
     `display` stays in the list (with allow-discrete) purely so the
     @starting-style opacity reveals above still fade instead of hard-cutting;
     transform is deliberately excluded so drawers/scale entrances still snap. */
  *, *::before, *::after {
    transition-property: opacity, color, background-color, border-color, box-shadow, display !important;
    transition-duration: 0.15s !important;
    transition-behavior: allow-discrete !important;
  }
}

.container {
  width: min(100%, var(--container-width));
  margin-inline: auto;
  padding-inline: 1.5rem;
}

/* ==========================================================================
   App Shell — persistent sidebar + topbar, injected by js/layout.js
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
}

.app-sidebar {
  background: var(--color-white);
  color: var(--color-text-primary);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: var(--z-sticky);
}

.app-sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  padding: 1.25rem 1.25rem 1rem;
  text-decoration: none;
  flex-shrink: 0;
}

.app-sidebar__brand img { height: 32px; width: auto; max-width: 100%; object-fit: contain; }

.app-sidebar__nav {
  flex: 1;
  overflow-y: auto;
  /* No right padding: the active item runs to the sidebar edge and opens
     into the content area. */
  padding: 0.5rem 0 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.app-sidebar__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  /* Rounded on the left, flat/open on the right so the item runs to the
     sidebar edge and connects into the content area. */
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  color: var(--color-text-secondary);
  text-decoration: none;
  font-size: var(--font-size-base);
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.app-sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; }

.app-sidebar__link:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

/* Active item: a tab filled with the content-area colour that bulges out to
   the sidebar edge and merges into the content. The ::before/::after notches
   carve concave corners above and below so the white sidebar curves smoothly
   into the tab. */
.app-sidebar__link.is-active {
  background: var(--color-bg-primary);
  color: var(--brand-orange);
  font-weight: 600;
  border-radius: var(--radius-xl) 0 0 var(--radius-xl);
  z-index: 1;
}

.app-sidebar__link.is-active svg { color: var(--brand-orange); }

.app-sidebar__link.is-active::before,
.app-sidebar__link.is-active::after {
  content: "";
  position: absolute;
  right: 0;
  width: var(--radius-xl);
  height: var(--radius-xl);
  background: var(--color-bg-primary);
  pointer-events: none;
}

/* Top notch: fill the concave sliver above the tab's outer corner. */
.app-sidebar__link.is-active::before {
  top: calc(var(--radius-xl) * -1);
  -webkit-mask: radial-gradient(circle var(--radius-xl) at top left, transparent 0 var(--radius-xl), #000 calc(var(--radius-xl) + 0.5px));
  mask: radial-gradient(circle var(--radius-xl) at top left, transparent 0 var(--radius-xl), #000 calc(var(--radius-xl) + 0.5px));
}

/* Bottom notch: mirror of the top. */
.app-sidebar__link.is-active::after {
  bottom: calc(var(--radius-xl) * -1);
  -webkit-mask: radial-gradient(circle var(--radius-xl) at bottom left, transparent 0 var(--radius-xl), #000 calc(var(--radius-xl) + 0.5px));
  mask: radial-gradient(circle var(--radius-xl) at bottom left, transparent 0 var(--radius-xl), #000 calc(var(--radius-xl) + 0.5px));
}

.app-sidebar__footer {
  padding: 0.75rem;
  border-top: 1px solid var(--color-border-primary);
}

.app-sidebar__footer .app-sidebar__link { color: var(--color-text-secondary); }

.app-topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--color-bg-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-height);
  padding: 0 1.5rem;
}

.app-topbar__left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.app-topbar__right { display: flex; align-items: center; gap: 0.5rem; }

/* Mobile-only brand mark: the real logo lives inside .app-sidebar, which is
   off-canvas until the drawer is opened — without this, the topbar shows no
   branding at all below 960px. Hidden on desktop where the sidebar is
   always visible. */
.app-topbar__brand { display: none; align-items: center; flex-shrink: 0; }
.app-topbar__brand img { height: 24px; width: auto; max-width: 120px; object-fit: contain; }

/* ==========================================================================
   Global search (topbar) — search customers, products, orders, etc.
   ========================================================================== */
.app-topbar__search { position: relative; flex: 1 1 auto; max-width: 520px; margin: 0 auto; }

.app-topbar__search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.app-topbar__search-input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-md);
  background: var(--color-bg-primary);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.app-topbar__search-input:focus {
  outline: none;
  background: var(--color-bg-secondary);
  border-color: var(--color-border-brand);
  box-shadow: 0 0 0 3px var(--brand-orange-tint);
}

.app-topbar__search-shortcut {
  position: absolute;
  right: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-tertiary);
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-sm);
  padding: 0.125rem 0.375rem;
  pointer-events: none;
}

.app-topbar__search-input:focus ~ .app-topbar__search-shortcut { display: none; }

.app-topbar__search-results {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg, var(--shadow-md));
  z-index: var(--z-dropdown, var(--z-sticky));
  padding: 0.5rem;
}

.app-topbar__search-group + .app-topbar__search-group { margin-top: 0.375rem; padding-top: 0.5rem; border-top: 1px solid var(--color-border-primary); }
.app-topbar__search-group-label {
  padding: 0.25rem 0.625rem;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-tertiary);
}

.app-topbar__search-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.app-topbar__search-item:hover,
.app-topbar__search-item.is-active { background: var(--color-bg-tertiary); }
.app-topbar__search-item-title { font-size: var(--font-size-sm); font-weight: 600; color: var(--color-text-primary); }
.app-topbar__search-item-subtitle { font-size: var(--font-size-xs); color: var(--color-text-secondary); }

.app-topbar__search-empty,
.app-topbar__search-hint {
  padding: 0.75rem 0.625rem;
  font-size: var(--font-size-sm);
  color: var(--color-text-tertiary);
  text-align: center;
}

@media (max-width: 720px) {
  .app-topbar__search { display: none; }
}

.app-sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  padding: 0.5rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--color-text-secondary);
}

/* Bug fix: without an explicit size, this bare <svg> (no viewBox-driven
   intrinsic size, no shared .btn-icon/.icon-btn class to inherit sizing
   from) computes to 0x0 — the button was present and clickable but
   rendered nothing, so mobile users had no visible way to open the nav. */
.app-sidebar-toggle svg { width: 22px; height: 22px; flex-shrink: 0; }

.app-sidebar-toggle:hover { background: var(--color-bg-tertiary); }

.app-content {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-main {
  flex: 1;
  padding: var(--space-xl) var(--space-lg);
  max-width: var(--container-max-width);
  width: 100%;
  margin: 0 auto;
}

.app-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(17, 30, 59, 0.55);
  z-index: var(--z-modal-backdrop);
  opacity: 1;
  transition: opacity 0.2s ease-out, display 0.2s allow-discrete;
}

@starting-style {
  .app-sidebar-backdrop { opacity: 0; }
}

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }

  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease-out-expo);
    z-index: var(--z-modal);
  }

  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open .app-sidebar-backdrop { display: block; }

  .app-topbar__brand { display: flex; }

  .app-sidebar-toggle { display: inline-flex; }
}

/* ==========================================================================
   Typography
   ========================================================================== */
.eyebrow {
  display: inline-block;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  font-weight: 600;
  margin: 0 0 var(--space-xs);
}

.breadcrumbs { background: transparent; margin-bottom: var(--space-lg); }

.breadcrumbs__inner { padding: 0; }

.breadcrumbs ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.breadcrumbs li { display: flex; align-items: center; gap: var(--space-xs); }

.breadcrumbs li + li::before { content: '/'; color: var(--color-text-tertiary); margin-right: var(--space-xs); }

.breadcrumbs a { text-decoration: none; color: var(--color-text-secondary); font-weight: 500; transition: color 0.15s ease; }

.breadcrumbs a:hover { color: var(--color-primary); }

.breadcrumbs [aria-current='page'] { color: var(--color-text-primary); font-weight: 500; }

/* Page header used at the top of every list/form/detail page */
.page-header {
  margin-bottom: var(--space-xl);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.page-header h1 {
  margin: 0 0 0.25rem;
  font-size: var(--font-size-3xl);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text-primary);
}

.page-header p,
.page-header #page-subtitle {
  color: var(--color-text-secondary);
  font-size: var(--font-size-base);
  margin: 0;
  max-width: 60ch;
}

.page-header__actions { display: flex; gap: var(--space-sm); flex-wrap: wrap; align-items: center; }

.autosave-status {
  font-size: var(--font-size-sm, 13px);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

/* ==========================================================================
   Buttons — both naming conventions supported (.btn-x and .btn--x)
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.625rem 1.125rem;
  font-size: var(--font-size-base);
  font-weight: 500;
  line-height: 1.4;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, color 0.15s ease, transform 120ms ease-out;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn:active:not(:disabled) { transform: scale(0.97); }

.btn-primary, .btn--primary {
  background-color: var(--color-primary);
  color: var(--color-white);
  border-color: var(--color-primary);
}

.btn-primary:hover, .btn--primary:hover {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-secondary, .btn--secondary {
  background-color: var(--color-bg-secondary);
  color: var(--color-text-primary);
  border-color: var(--color-border-primary);
}

.btn-secondary:hover, .btn--secondary:hover {
  background-color: var(--color-bg-tertiary);
  border-color: var(--color-border-secondary);
}

.btn-ghost, .btn--ghost, .btn.ghost {
  background-color: transparent;
  color: var(--color-text-secondary);
  border-color: transparent;
}

.btn-ghost:hover, .btn--ghost:hover, .btn.ghost:hover {
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.btn-danger, .btn--danger {
  background-color: var(--color-danger);
  color: var(--color-white);
  border-color: var(--color-danger);
}

.btn-danger:hover, .btn--danger:hover { filter: brightness(0.92); }

.btn-success, .btn--success {
  background-color: var(--color-success);
  color: var(--color-white);
  border-color: var(--color-success);
}

.btn-success:hover, .btn--success:hover { filter: brightness(0.94); }

.btn-sm, .btn--sm { padding: 0.4375rem 0.875rem; font-size: var(--font-size-sm); }
.btn-lg, .btn--lg { padding: 0.875rem 1.75rem; font-size: var(--font-size-md); font-weight: 600; }

.btn-icon, .btn--icon, .icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 120ms ease-out;
}

.icon-btn { border-color: var(--color-border-primary); background: var(--color-bg-secondary); }

.btn-icon svg, .btn--icon svg, .icon-btn svg { width: 17px; height: 17px; }
.icon-btn svg { fill: none; stroke: currentColor; }

.btn-icon:hover, .btn--icon:hover, .icon-btn:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-primary);
  border-color: var(--color-border-secondary);
}

.btn-icon:active:not(:disabled), .btn--icon:active:not(:disabled), .icon-btn:active:not(:disabled) { transform: scale(0.94); }

.btn-icon--danger:hover, .icon-btn--danger:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.btn-icon.is-active, .icon-btn.is-active {
  background: var(--brand-orange-tint);
  color: var(--brand-orange);
  border-color: transparent;
}

/* ==========================================================================
   Forms
   ========================================================================== */
.input-group { margin-bottom: var(--space-md); position: relative; }

.form-input, .input-enhanced {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--color-border-primary);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-size: var(--font-size-base);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus, .input-enhanced:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--brand-orange-tint);
}

.form-input::placeholder, .input-enhanced::placeholder { color: var(--color-text-tertiary); }

/* Urdu remarks (PO remarks template + per-order remarks): right-to-left,
   Nastaliq calligraphic style. Requires the page to load the
   "Noto Nastaliq Urdu" webfont (see purchase-order-form.html/view.html). */
.urdu-text {
  direction: rtl;
  text-align: right;
  font-family: 'Noto Nastaliq Urdu', 'Jameel Noori Nastaleeq', serif;
  font-size: 1.15rem;
  line-height: 2.1;
  unicode-bidi: plaintext;
}

/* Sets a section (e.g. PO Terms) visually apart from the content above it
   with a thin dashed rule, echoing a perforated/"tear here" line on a
   printed document. */
.section-divider-dashed {
  border-top: 1px dashed var(--color-border-primary);
  padding-top: var(--space-lg);
  margin-top: var(--space-lg);
}

/* Authentic-PO-style signature footer: two blank signature lines side by side. */
.signature-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-xl);
  margin-top: var(--space-xl);
}
.signature-block__line {
  border-top: 1px solid var(--color-text-primary);
  padding-top: var(--space-xs);
  text-align: center;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

select.input-enhanced {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 500;
  margin-bottom: var(--space-xs);
  color: var(--color-text-secondary);
}

.form-label-enhanced {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: var(--font-size-md);
  color: var(--color-text-primary);
  margin-bottom: 0.5rem;
}

.required-star { color: var(--color-danger); margin-left: 2px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-md);
}

.form-grid label, .form-stack label, .simple-grid label {
  font-weight: 500;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
}

/* Only labels that wrap their input directly (no `for`, e.g. `<label>Name *<input></label>`)
   need flex-column to stack label text above the input. Labels using the for/id sibling
   pattern (`<label for="x">Name <span>*</span></label>` + separate `<input id="x">`) must
   stay in normal flow -- flexing a label containing text + a required-marker <span> as
   column splits them onto two lines instead of keeping "Name *" together. */
.form-grid label:not([for]), .form-stack label:not([for]), .simple-grid label:not([for]) {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-grid input, .form-grid select, .form-grid textarea,
.form-stack input, .form-stack select, .form-stack textarea,
.simple-grid input, .simple-grid select, .simple-grid textarea {
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-primary);
  padding: 0.625rem 0.875rem;
  font: inherit;
  font-size: var(--font-size-base);
  resize: none;
  overflow: hidden;
}

.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus,
.form-stack input:focus, .form-stack select:focus, .form-stack textarea:focus,
.simple-grid input:focus, .simple-grid select:focus, .simple-grid textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--brand-orange-tint);
}

.form-stack { display: flex; flex-direction: column; gap: var(--space-md); }
.form-stack textarea { min-height: 80px; }

.simple-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

/* Named column-count variants — prefer these over an inline grid-template-columns override */
.simple-grid--2 { grid-template-columns: repeat(2, 1fr); }
.simple-grid--3 { grid-template-columns: repeat(3, 1fr); }
.simple-grid--4 { grid-template-columns: repeat(4, 1fr); }

.form-section {
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-xl);
  border-bottom: 1px solid var(--color-border-primary);
}

.form-section:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.checkbox-row { display: flex; gap: var(--space-lg); margin-top: var(--space-md); flex-wrap: wrap; }
.checkbox-label { display: flex; align-items: center; cursor: pointer; gap: var(--space-sm); }
.checkbox-label input[type='checkbox'] { width: auto; }

.form-section h3 {
  margin: 0 0 var(--space-lg);
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-field label {
  font-weight: 500;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
}

.form-field input, .form-field select, .form-field textarea {
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-primary);
  padding: 0.625rem 0.875rem;
  font: inherit;
  font-size: var(--font-size-base);
  background: var(--color-bg-secondary);
  resize: none;
  overflow: hidden;
}

.form-field textarea { line-height: 1.5; min-height: 96px; }

.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--brand-orange-tint);
}

.form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border-primary);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.form-header h1 { margin: 0; font-size: var(--font-size-2xl); color: var(--color-text-primary); }
.form-header p { margin: 0.25rem 0 0; color: var(--color-text-secondary); font-size: var(--font-size-sm); }

.upload-stack { display: flex; flex-direction: column; gap: var(--space-sm); }
.upload-hint { font-size: var(--font-size-xs); color: var(--color-text-secondary); margin: 0; }

.photo-gallery { display: flex; flex-direction: column; gap: var(--space-md); }
.gallery-title { font-size: var(--font-size-sm); font-weight: 500; color: var(--color-text-primary); margin: 0 0 var(--space-xs); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: var(--space-sm); }

/* View-only fields on detail pages */
.view-field { display: flex; flex-direction: column; gap: 0.375rem; }
.view-field label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
}
.view-field p { margin: 0; font-size: var(--font-size-base); color: var(--color-text-primary); font-weight: 500; }

.info-box {
  background: var(--color-bg-brand);
  border: 1px solid var(--color-border-brand);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}
.info-box p { margin: 0 0 var(--space-sm); }
.info-box ul { margin: var(--space-sm) 0; padding-left: var(--space-lg); }
.info-box code {
  background: var(--color-white);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-family: 'Courier New', monospace;
}

/* Filters bar above data tables */
.filters-bar, .glass-panel.filters-bar {
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.filters-group { display: flex; gap: var(--space-md); flex-wrap: wrap; flex: 1; align-items: center; }

.filters-group input[type='text'],
.filters-group input[type='search'] { flex: 1 1 220px; min-width: 180px; }

.filters-group select { flex: 0 0 auto; }

.filter-item { display: flex; flex-direction: column; gap: 0.375rem; min-width: 180px; }
.filter-item label { font-size: var(--font-size-xs); font-weight: 500; color: var(--color-text-secondary); }
.filter-item input, .filter-item select { margin: 0; }

/* ==========================================================================
   Cards / surfaces — one plain, non-decorative surface used everywhere.
   `.glass-panel` kept as an alias (no blur/gradient) since dozens of pages
   already carry the class name.
   ========================================================================== */
.card, .glass-panel {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-lg);
}

a.card {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s var(--ease-out-expo);
}

a.card:hover { border-color: var(--color-border-secondary); box-shadow: var(--shadow-md); transform: translateY(-2px); }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-container, .table-wrapper, .spreadsheet-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-primary);
  background: var(--color-bg-secondary);
}

.data-table, .spreadsheet-table, .line-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  text-align: left;
}

.data-table th, .spreadsheet-table th, .line-items-table th {
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
  font-weight: 600;
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border-primary);
  white-space: nowrap;
}

.data-table td, .spreadsheet-table td, .line-items-table td {
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--color-border-primary);
  color: var(--color-text-primary);
  vertical-align: middle;
}

.data-table tbody tr:last-child td,
.spreadsheet-table tbody tr:last-child td,
.line-items-table tbody tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover td,
.spreadsheet-table tbody tr:hover td,
.line-items-table tbody tr:hover td { background: var(--color-bg-primary); }

.spreadsheet-table tbody tr, .line-items-table tbody tr {
  opacity: 1;
  transition: opacity 0.1s ease-out;
}

@starting-style {
  .spreadsheet-table tbody tr, .line-items-table tbody tr { opacity: 0; }
}

.spreadsheet-table thead { position: sticky; top: 0; z-index: 1; }

/* Inline inputs used inside spreadsheet/line-item rows */
.spreadsheet-table input, .spreadsheet-table select,
.qty-input, .price-input, .total-input, .discount-input, .notes-input, .line-item-input, .product-search-input {
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
}

.spreadsheet-table input:focus, .spreadsheet-table select:focus,
.qty-input:focus, .price-input:focus, .total-input:focus, .discount-input:focus,
.notes-input:focus, .line-item-input:focus, .product-search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  background: var(--color-bg-secondary);
  box-shadow: 0 0 0 3px var(--brand-orange-tint);
}

.spreadsheet-table input[readonly], .line-item-input[readonly], .total-input[readonly] {
  background-color: var(--color-bg-primary);
  color: var(--color-text-secondary);
  font-weight: 500;
}

.row-number { text-align: center; color: var(--color-text-secondary); font-weight: 500; font-size: var(--font-size-sm); }

/* Line-item cells that don't apply to the current row type */
.spreadsheet-table td.cell-na { text-align: center; color: var(--color-text-tertiary); }

/* Manually entered new-product rows (vs. catalog search rows) */
.spreadsheet-table tbody tr.row-new-product td,
.spreadsheet-table tbody tr.row-new-product:hover td { background: rgba(0, 122, 124, 0.05); }

/* "Add as new product" action at the bottom of the product search dropdown */
.product-search-create {
  display: block;
  width: 100%;
  padding: 0.625rem 1rem;
  border: none;
  border-top: 1px solid var(--color-border-primary);
  background: transparent;
  color: var(--color-primary);
  font: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.product-search-create:hover { background: var(--color-bg-brand); }

.delete-row, .remove-line, .line-item-remove {
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.delete-row:hover, .remove-line:hover, .line-item-remove:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.add-product-row {
  margin-top: var(--space-md);
  padding: var(--space-md);
  background: var(--color-bg-primary);
  border-radius: var(--radius-md);
  border: 1px dashed var(--color-border-secondary);
}

.line-item-product-info { display: flex; flex-direction: column; gap: 2px; }
.line-item-code { font-weight: 600; color: var(--color-text-primary); font-size: var(--font-size-sm); }
.line-item-desc { color: var(--color-text-secondary); font-size: var(--font-size-xs); }

.table-actions { display: flex; gap: 0.5rem; align-items: center; }

.table-link, .btn-link {
  color: var(--color-text-primary);
  text-decoration: none;
  font-weight: 600;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.table-link:hover, .btn-link:hover { color: var(--color-primary); text-decoration: underline; }

/* A table cell whose primary line is a name/title (the thing worth reading
   and clicking) with a secondary reference id/number beneath it, de-emphasized
   rather than given its own column — e.g. CRM account/lead/opportunity number. */
.cell-stack { display: flex; flex-direction: column; gap: 2px; }
.cell-subtext { font-size: var(--font-size-xs); color: var(--color-text-tertiary); }

.product-checkbox { width: 16px; height: 16px; cursor: pointer; }

.product-desc { max-width: 320px; white-space: normal; word-wrap: break-word; }

/* Totals summary under a line-items table */
.totals-summary, .totals-bar {
  margin-top: var(--space-lg);
  margin-left: auto;
  width: fit-content;
  min-width: 300px;
  max-width: 420px;
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border-primary);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}

.totals-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-xl); width: 100%; max-width: 320px; font-size: var(--font-size-base); }
.totals-row.total { border-top: 1px solid var(--color-border-secondary); margin-top: 0.5rem; padding-top: 0.75rem; font-size: var(--font-size-lg); font-weight: 700; }
.totals-label { color: var(--color-text-secondary); font-weight: 500; }
.totals-value { color: var(--color-text-primary); font-weight: 600; }

.totals-item { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.totals-item span { font-size: var(--font-size-xs); color: var(--color-text-secondary); font-weight: 500; }
.totals-item strong { font-size: var(--font-size-lg); color: var(--color-text-primary); }
.totals-item.total strong { font-size: var(--font-size-xl); color: var(--color-text-primary); }

/* ==========================================================================
   Status badges / pills — ONE canonical color mapping. `.status-pill`,
   `.status-badge`, and the `.status-badge--{status}` BEM form all resolve
   here; the status word itself carries the color regardless of wrapper.
   Background is each status color mixed 16% into white — a soft pastel
   tint, not the near-white `-bg` tokens (too pale to read as "colored" at
   a glance) and not the 40% mix used previously (read as too vibrant/bold).
   Text stays the solid color for contrast.
   ========================================================================== */
.status-pill, .status-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: capitalize;
  background: color-mix(in oklch, var(--color-neutral-text) 16%, white);
  color: var(--color-neutral-text);
  white-space: nowrap;
}

.status-draft, .status-badge--draft,
.status-expired, .status-badge--expired,
.status-void, .status-badge--void,
.status-requested, .status-badge--requested,
.status-not_shipped, .status-badge--not_shipped {
  background: color-mix(in oklch, var(--color-neutral-text) 16%, white);
  color: var(--color-neutral-text);
}

.status-sent, .status-badge--sent,
.status-processing, .status-badge--processing,
.status-in_process, .status-badge--in_process,
.status-shipped, .status-badge--shipped,
.status-confirmed, .status-badge--confirmed,
.status-invoiced, .status-badge--invoiced,
.status-submitted, .status-badge--submitted,
.status-filed, .status-badge--filed,
.status-in_customs, .status-badge--in_customs,
.status-consignment_shipped, .status-badge--consignment_shipped,
.status-prc_applied, .status-badge--prc_applied,
.status-gd_assigned_to_rebate_officer, .status-badge--gd_assigned_to_rebate_officer {
  background: color-mix(in oklch, var(--color-info) 16%, white);
  color: var(--color-info);
}

.status-accepted, .status-badge--accepted,
.status-fulfilled, .status-badge--fulfilled,
.status-paid, .status-badge--paid,
.status-delivered, .status-badge--delivered,
.status-cleared, .status-badge--cleared,
.status-received, .status-badge--received,
.status-ready, .status-badge--ready,
.status-approved, .status-badge--approved,
.status-closed, .status-badge--closed,
.status-final, .status-badge--final,
.status-feedback_received, .status-badge--feedback_received,
.status-rebate_credited, .status-badge--rebate_credited {
  background: color-mix(in oklch, var(--color-success) 16%, white);
  color: var(--color-success);
}

.status-partially_paid, .status-badge--partially_paid,
.status-pending, .status-badge--pending,
.status-partially_shipped, .status-badge--partially_shipped,
.status-loading_allowed, .status-badge--loading_allowed,
.status-prc_pending, .status-badge--prc_pending {
  background: color-mix(in oklch, var(--color-warning) 16%, white);
  color: var(--color-warning);
}

.status-rejected, .status-badge--rejected,
.status-cancelled, .status-badge--cancelled,
.status-overdue, .status-badge--overdue {
  background: color-mix(in oklch, var(--color-danger) 16%, white);
  color: var(--color-danger);
}

/* ==========================================================================
   Tabs
   ========================================================================== */
.tab-nav, .price-list-tabs {
  display: flex;
  gap: 1.5rem;
  border-bottom: 1px solid var(--color-border-primary);
  margin-bottom: var(--space-lg);
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.75rem 0;
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover { color: var(--color-text-primary); }
.tab-btn.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ==========================================================================
   Modals
   ========================================================================== */
.modal, .login-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(17, 30, 59, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.login-modal { display: none; }
.login-modal[aria-hidden='false'] { display: flex; }

.modal-overlay, .login-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 30, 59, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  animation: dialog-overlay-in 0.15s ease-out;
}

.modal-content, .login-modal__panel {
  position: relative;
  z-index: var(--z-modal);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  animation: dialog-box-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-modal__panel { padding: clamp(1.75rem, 6vw, 2.5rem); width: min(480px, 92%); }

.payment-modal-content { max-width: 600px !important; }

.modal-header {
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--color-border-primary);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
}

.modal-header h2 { margin: 0; font-size: var(--font-size-xl); font-weight: 600; }

.modal-close, .close-btn, .btn-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.close-btn { position: absolute; top: 1.25rem; right: 1.25rem; border-radius: 50%; }

.modal-close:hover, .close-btn:hover, .btn-close:hover { background: var(--color-bg-tertiary); color: var(--color-text-primary); }

.modal-body { padding: var(--space-xl); max-height: 60vh; overflow-y: auto; }
.modal-body .form-field { margin-bottom: var(--space-md); }
.modal-body .form-field:last-child { margin-bottom: 0; }

.modal-footer {
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--color-border-primary);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background: var(--color-bg-tertiary);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.payment-info-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  padding: 1.25rem;
  background: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-primary);
  margin-bottom: 1.75rem;
}

/* ==========================================================================
   Unified confirm()/alert() replacement dialogs
   ========================================================================== */
@keyframes dialog-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes dialog-box-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.dialog-open { overflow: hidden; }

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(17, 30, 59, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  animation: dialog-overlay-in 0.15s ease-out;
}

.dialog-box {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--color-bg-secondary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: var(--space-xl) var(--space-xl) var(--space-lg);
  text-align: center;
  animation: dialog-box-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.dialog-box:focus { outline: none; }

.dialog-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-md);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialog-icon--danger { background: var(--color-danger-bg); color: var(--color-danger); }
.dialog-icon--warning { background: var(--color-warning-bg); color: var(--color-warning); }
.dialog-icon--success { background: var(--color-success-bg); color: var(--color-success); }
.dialog-icon--info { background: var(--color-info-bg); color: var(--color-info); }

.dialog-title {
  margin: 0 0 var(--space-sm);
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
}

.dialog-message {
  color: var(--color-text-secondary);
  font-size: var(--font-size-base);
  line-height: 1.5;
}

.dialog-message p { margin: 0 0 var(--space-sm); }
.dialog-message p:last-child { margin-bottom: 0; }

.dialog-actions {
  display: flex;
  justify-content: center;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

.dialog-actions .btn { min-width: 96px; }

.payment-info-item { display: flex; flex-direction: column; gap: 0.375rem; }
.payment-info-highlight {
  background: var(--color-bg-secondary);
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-secondary);
}
.payment-info-label { font-size: var(--font-size-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-secondary); }
.payment-info-value { font-size: var(--font-size-xl); font-weight: 700; color: var(--color-text-primary); }
.payment-info-paid { color: var(--color-success); }
.payment-info-due { color: var(--color-text-primary); font-size: var(--font-size-2xl); }
.payment-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }

/* ==========================================================================
   Product search dropdown (customer/product autocomplete)
   ========================================================================== */
.product-search-wrapper { position: relative; width: 100%; }

.product-search-icon {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-secondary);
  pointer-events: none;
}

.product-search-results, .product-search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-md);
  margin-top: 4px;
  max-height: 300px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown);
  display: none;
  opacity: 1;
  transform: translateY(0) scale(1);
  transform-origin: top;
  transition: opacity 120ms ease-out, transform 120ms ease-out, display 120ms allow-discrete;
}

@starting-style {
  .product-search-results, .product-search-dropdown {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

.product-search-results.active { display: block; }

.product-search-item, .product-search-result {
  padding: 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border-primary);
  transition: background-color 0.15s ease;
}

.product-search-item:last-child, .product-search-result:last-child { border-bottom: none; }

.product-search-item:hover, .product-search-item.selected, .product-search-result:hover {
  background-color: var(--color-bg-primary);
}

.product-search-item-code { font-weight: 600; color: var(--color-text-primary); font-size: var(--font-size-sm); }
.product-search-item-desc { color: var(--color-text-secondary); font-size: var(--font-size-xs); margin-top: 2px; display: block; }
.product-search-item-meta { display: flex; gap: 0.75rem; margin-top: 4px; font-size: var(--font-size-xs); color: var(--color-text-secondary); }
.product-search-empty { padding: var(--space-md); text-align: center; color: var(--color-text-secondary); font-size: var(--font-size-sm); }

/* Standalone product-search input for a single field outside spreadsheet rows
   (e.g. modal/detail forms) — bordered like .form-input, unlike the borderless
   .product-search-input used inside .spreadsheet-table cells. */
.product-search-field {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--color-border-primary);
  background: var(--color-bg-secondary);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font: inherit;
  font-size: var(--font-size-base);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.product-search-field::placeholder { color: var(--color-text-tertiary); }
.product-search-field:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--brand-orange-tint);
}

/* ==========================================================================
   Activity tab layout (customer/supplier detail) — composer sidebar +
   a wide feed so the timeline stretches to fill the tab instead of being
   pinned to a narrow centered column.
   ========================================================================== */
.activity-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: var(--space-lg);
  align-items: start;
}

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

.activity-type-picker { display: flex; flex-wrap: wrap; gap: var(--space-xs); margin-bottom: var(--space-md); }

.activity-type-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.375rem 0.8125rem;
  border-radius: 9999px;
  border: 1px solid var(--color-border-primary);
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
  font: inherit;
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.activity-type-chip:hover { background: var(--color-bg-tertiary); }

.activity-type-chip.is-active {
  background: var(--brand-orange-tint);
  color: var(--brand-orange);
  border-color: transparent;
  font-weight: 600;
}

.activity-composer__actions { display: flex; justify-content: flex-end; margin-top: var(--space-sm); }

/* ==========================================================================
   Timeline (customer/supplier activity streams)
   ========================================================================== */
.activity-timeline, .record-list { display: flex; flex-direction: column; }

.timeline-item {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-xs);
  border-radius: var(--radius-lg);
  transition: background-color 0.15s ease;
}

.timeline-item + .timeline-item { margin-top: var(--space-xs); border-top: 1px solid var(--color-border-primary); padding-top: var(--space-md); }

.timeline-item:hover { background: var(--color-bg-tertiary); }

.timeline-marker {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--color-border-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
  font-size: 0.6875rem;
  font-weight: 700;
}

.timeline-marker svg { width: 14px; height: 14px; }

.timeline-content { flex: 1; min-width: 0; }

.timeline-header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-sm); flex-wrap: wrap; }
.timeline-title { font-weight: 600; color: var(--color-text-primary); font-size: var(--font-size-base); }
.timeline-meta { display: flex; align-items: center; gap: var(--space-xs); flex-shrink: 0; }
.timeline-date { font-size: var(--font-size-xs); color: var(--color-text-tertiary); white-space: nowrap; }
.timeline-body { margin-top: 0.25rem; color: var(--color-text-secondary); font-size: var(--font-size-sm); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }

.timeline-delete, .timeline-action {
  width: 26px;
  height: 26px;
  opacity: 0;
  transition: opacity 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.timeline-delete svg, .timeline-action svg { width: 14px; height: 14px; }
.timeline-item:hover .timeline-delete, .timeline-item:hover .timeline-action,
.timeline-delete:focus-visible, .timeline-action:focus-visible { opacity: 1; }

.timeline-marker.order, .timeline-marker.sales_order { background: var(--color-info-bg); color: var(--color-info); border-color: transparent; }
.timeline-marker.purchase, .timeline-marker.purchase_order { background: var(--color-warning-bg); color: var(--color-warning); border-color: transparent; }
.timeline-marker.invoice { background: var(--color-success-bg); color: var(--color-success); border-color: transparent; }
.timeline-marker.quote { background: var(--color-neutral-bg); color: var(--color-neutral-text); border-color: transparent; }
.timeline-marker.shipment { background: var(--color-info-bg); color: var(--color-info); border-color: transparent; }
.timeline-marker.note { background: var(--color-warning-bg); color: var(--color-warning); border-color: transparent; }
.timeline-marker.call, .timeline-marker.email { background: var(--color-info-bg); color: var(--color-info); border-color: transparent; }
.timeline-marker.meeting { background: var(--color-success-bg); color: var(--color-success); border-color: transparent; }
.timeline-marker.task { background: var(--color-neutral-bg); color: var(--color-neutral-text); border-color: transparent; }

.timeline-item--clickable { align-items: center; cursor: pointer; }
.timeline-chevron { flex-shrink: 0; align-self: center; color: var(--color-text-tertiary); }

/* Small pipeline-stage dot, used in place of an icon marker on dense record
   rows (opportunities) — HubSpot-style: a colour cue, not another icon. Sits
   in a slot the same width as .timeline-marker so rows stay aligned. */
.timeline-dot-slot { flex-shrink: 0; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; }
.stage-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--color-neutral-text); }
.stage-dot.stage-prospecting { background: var(--color-neutral-text); }
.stage-dot.stage-quotation { background: var(--color-info); }
.stage-dot.stage-negotiation { background: var(--color-warning); }
.stage-dot.stage-won { background: var(--color-success); }
.stage-dot.stage-lost { background: var(--color-danger); }

/* ==========================================================================
   Detail-page hero (customer/supplier profile header)
   ========================================================================== */
.customer-hero__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-lg);
  flex-wrap: wrap;
}

.hero__identity {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-width: 0;
}

.hero__avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand-navy);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xl);
  font-weight: 700;
  flex-shrink: 0;
}

.hero__identity h1 { margin: 0; }

.hero__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.625rem;
  margin-top: var(--space-xs);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

.hero__meta-item { display: inline-flex; align-items: center; gap: 0.375rem; }
.hero__meta-item[hidden] { display: none; }
.hero__meta-item svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--color-text-tertiary); }
.hero__meta-sep { color: var(--color-border-secondary); }

.hero__actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-shrink: 0;
}

.hero__activity {
  margin-top: var(--space-lg);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--color-border-primary);
}

.hero__activity-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-sm);
  flex-wrap: wrap;
  margin-bottom: var(--space-sm);
}

.hero__activity-header h3 {
  margin: 0;
  font-size: var(--font-size-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary);
}

.hero__activity-hint { font-size: var(--font-size-xs); color: var(--color-text-tertiary); }

/* ==========================================================================
   KPI / metric cards (dashboard, hub pages, detail pages)
   ========================================================================== */
.metric { display: flex; flex-direction: column; gap: 0.375rem; text-align: center; padding: var(--space-md); }
.metric__label { font-size: var(--font-size-xs); font-weight: 500; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.metric__value { font-size: var(--font-size-xl); font-weight: 700; color: var(--color-text-primary); }

.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-md); }
.metrics-grid div { background: var(--color-bg-primary); border-radius: var(--radius-md); padding: var(--space-md); border: 1px solid var(--color-border-primary); text-align: center; }
.metrics-grid p { margin: 0 0 var(--space-xs); color: var(--color-text-secondary); font-size: var(--font-size-sm); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.metrics-grid strong { font-size: var(--font-size-lg); font-weight: 700; color: var(--color-text-primary); display: block; }

.amount.positive { color: var(--color-success); }
.amount.negative { color: var(--color-danger); }

.detail-info-grid, .detail-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-lg); margin-top: var(--space-md); }
.info-item { display: flex; flex-direction: column; gap: var(--space-xs); }
.info-item label { font-size: var(--font-size-xs); font-weight: 500; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }
.info-item p { margin: 0; font-size: var(--font-size-base); color: var(--color-text-primary); font-weight: 500; }

/* Used across the accounting pages' .info-item summary cards (invoice/voucher
   detail headers) -- previously had no rule at all, so labels/values rendered
   as plain unstyled text. */
.stat-label { display: block; font-size: var(--font-size-xs); font-weight: 500; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { display: block; font-size: var(--font-size-base); color: var(--color-text-primary); font-weight: 600; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: var(--space-lg); margin-bottom: var(--space-lg); align-items: start; }
.detail-card header { margin-bottom: var(--space-md); padding-bottom: var(--space-sm); border-bottom: 1px solid var(--color-border-primary); }
.detail-card header h2 { margin: 0; font-size: var(--font-size-lg); font-weight: 600; color: var(--color-text-primary); }
.detail-card header.header--split { display: flex; justify-content: space-between; align-items: center; }
.detail-card + .detail-card,
.detail-grid + .detail-card { margin-top: var(--space-lg); }
/* ...but not for cards that are side-by-side siblings within a .detail-grid —
   the grid's own `gap` already spaces those out, and an extra margin-top only
   on the 2nd/3rd+ card (not the 1st) breaks `align-items: start`, visibly
   knocking later cards a row-gap's-worth downward relative to the first. */
.detail-grid > .detail-card { margin-top: 0; }

/* ==========================================================================
   Contribution heatmap ("365 dots") — GitHub/ERPNext-style activity grid.
   Rendered by public/js/heatmap.js into any container.
   ========================================================================== */
/* 12 months of daily cells are wider than a phone viewport — scroll the
   heatmap itself rather than letting it stretch the whole page's layout
   viewport (the classic "one wide element zooms out the entire mobile
   page" bug). */
.heatmap {
  --heatmap-cell: 10px;
  --heatmap-gap: 2px;
  --heatmap-month-gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.heatmap-months {
  display: flex;
  justify-content: center;
  gap: var(--heatmap-month-gap);
  margin-left: 28px;
  margin-bottom: 4px;
}
.heatmap-month {
  display: inline-block;
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
}
.heatmap-body { display: flex; gap: 6px; width: 100%; }
.heatmap-weekdays { display: grid; grid-template-rows: repeat(7, var(--heatmap-cell)); gap: var(--heatmap-gap); width: 22px; flex-shrink: 0; }
.heatmap-weekday { font-size: 10px; color: var(--color-text-tertiary); line-height: var(--heatmap-cell); }
.heatmap-grid { display: flex; justify-content: center; gap: var(--heatmap-month-gap); flex: 1; }
.heatmap-month-group {
  display: flex;
  gap: var(--heatmap-gap);
  flex-shrink: 0;
}
.heatmap-week { display: grid; grid-template-rows: repeat(7, var(--heatmap-cell)); gap: var(--heatmap-gap); flex-shrink: 0; }

.heatmap-cell {
  width: var(--heatmap-cell);
  height: var(--heatmap-cell);
  border-radius: 2px;
  background: var(--color-bg-tertiary);
  display: inline-block;
  cursor: default;
  transition: transform 0.1s ease;
}
.heatmap-cell--empty { background: transparent; cursor: default; }
.heatmap-cell[data-date] { cursor: pointer; }

@media (hover: hover) and (pointer: fine) {
  .heatmap-cell[data-date]:hover { transform: scale(1.3); outline: 1px solid var(--color-border-secondary); z-index: 1; position: relative; }
}

.heatmap-cell[data-level="0"] { background: var(--color-bg-tertiary); }
.heatmap-cell[data-level="1"] { background: rgba(0, 122, 124, 0.25); }
.heatmap-cell[data-level="2"] { background: rgba(0, 122, 124, 0.48); }
.heatmap-cell[data-level="3"] { background: rgba(0, 122, 124, 0.72); }
.heatmap-cell[data-level="4"] { background: var(--brand-orange); }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--space-sm);
  font-size: var(--font-size-xs);
  color: var(--color-text-tertiary);
}
.heatmap-legend .heatmap-cell { cursor: default; }
.heatmap-legend .heatmap-cell:hover { transform: none; outline: none; }

.heatmap-tooltip {
  position: fixed;
  z-index: var(--z-tooltip, 1000);
  background: var(--brand-navy);
  color: var(--color-white);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: var(--font-size-xs);
  line-height: 1.5;
  pointer-events: none;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

/* ==========================================================================
   Hub pages (Sales / Purchase / Inventory / Shipments / Settings)
   One shared class family — .module-hero / .module-grid / .module-panel —
   used identically across every hub page. Don't reintroduce per-module names.
   ========================================================================== */
/* Screen-reader-only content: keeps an accessible page heading without
   rendering marketing text in the metric-focused module heroes. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Module heroes are a full-width KPI band: no prose, just the key metrics
   that matter for the module, sitting directly under the breadcrumb. Same
   flat hairline vocabulary as the dashboard's .dash-strip/.dash-stat (see
   below) — module-hero wraps that identical stat strip plus an optional
   module title, it does not define its own card/box treatment. */
.module-hero {
  margin-bottom: var(--space-2xl);
}

.module-hero h1 {
  margin: 0 0 var(--space-md);
  font-size: var(--font-size-2xl);
  font-weight: 650;
  color: var(--color-text-primary);
}

/* .hero-panel is a thin alias for .dash-strip so existing module-hero
   markup keeps working; new markup should reach for .dash-strip directly. */
.hero-panel { display: flex; flex-wrap: wrap; row-gap: var(--space-lg); }

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.module-grid article {
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-primary);
  padding: var(--space-md) var(--space-lg);
  min-height: 4.5rem;
  display: flex;
  align-items: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  cursor: default;
}

.module-grid article[data-link] { cursor: pointer; }

.module-grid article:hover, .module-grid article.active {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.module-grid h3 { margin: 0; font-size: var(--font-size-lg); font-weight: 600; color: var(--color-text-primary); }

.module-panel {
  background: var(--color-bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-primary);
  padding: var(--space-lg);
}
.module-panel header h2 { margin: 0; font-size: var(--font-size-xl); font-weight: 600; color: var(--color-text-primary); }
.module-panel header p { margin-top: var(--space-xs); color: var(--color-text-secondary); }
.panel-content ul { padding-left: var(--space-lg); color: var(--color-text-secondary); margin: 0; }
.panel-content li { margin-bottom: var(--space-xs); }

/* ==========================================================================
   Dashboard — operational KPI grid, sales trend + financial snapshot
   ========================================================================== */
/* Dashboard — compact operations brief. Flat hairline vocabulary: no cards,
   no icon chips, no shadows. Every number is a link into its module.

   .dash-strip/.dash-stat are also the stat strip used inside every module
   hub page's .module-hero (§ above) — one shared stat-strip component for
   the whole app, not a dashboard-only pattern. Module heroes reuse it as
   plain (non-link) divs since their stats don't have a single obvious
   drill-down target; .dash-stat works identically either way. */

.dash-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-md) var(--space-xl);
  flex-wrap: wrap;
  margin-bottom: var(--space-xl);
}

.dash-head h1 { margin: 0 0 2px; font-size: var(--font-size-2xl); }
.dash-head p { margin: 0; color: var(--color-text-secondary); font-size: var(--font-size-base); }

.dash-quick { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-sm); }

.dash-quick__link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.dash-quick__link svg { color: var(--color-text-tertiary); transition: color 0.15s ease; }
.dash-quick__link:hover,
.dash-quick__link:focus-visible { color: var(--color-text-primary); border-color: var(--color-border-secondary); }
.dash-quick__link:hover svg { color: var(--color-primary); }

/* Stat strip: hairline tick before every stat so wrapped rows stay uniform. */
.dash-strip {
  display: flex;
  flex-wrap: wrap;
  row-gap: var(--space-lg);
  margin-bottom: var(--space-2xl);
}

.dash-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px var(--space-md) 2px 12px;
  border-left: 1px solid var(--color-border-secondary);
  text-decoration: none;
  min-width: 88px;
}

.dash-stat__value {
  font-size: var(--font-size-xl);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  color: var(--color-text-primary);
  transition: color 0.15s ease;
}

.dash-stat__label {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  line-height: 1.3;
  white-space: nowrap;
}

.dash-stat:hover .dash-stat__value,
.dash-stat:focus-visible .dash-stat__value { color: var(--color-primary); }
.dash-stat.is-warning .dash-stat__value { color: var(--color-warning); }
.dash-stat.is-danger .dash-stat__value { color: var(--color-danger); }
.dash-stat.is-warning:hover .dash-stat__value,
.dash-stat.is-danger:hover .dash-stat__value { text-decoration: underline; text-underline-offset: 3px; }

.dash-split {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: var(--space-2xl);
  align-items: start;
}

.dash-panel { border-top: 1px solid var(--color-border-secondary); padding-top: var(--space-md); min-width: 0; }

.dash-panel__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.dash-panel__head h2 { margin: 0; font-size: var(--font-size-base); font-weight: 600; color: var(--color-text-primary); }
.dash-panel__head span { font-size: var(--font-size-xs); color: var(--color-text-secondary); white-space: nowrap; }

.dash-chart { position: relative; height: 230px; }

.dash-ledger { margin: 0; }

.dash-ledger__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
}

.dash-ledger__row + .dash-ledger__row { border-top: 1px solid var(--color-border-primary); }

.dash-ledger__row dt { font-size: var(--font-size-sm); color: var(--color-text-secondary); }

.dash-ledger__row dd {
  margin: 0;
  font-size: var(--font-size-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
  text-align: right;
}

.dash-ledger__row dd.is-positive { color: var(--color-success); }
.dash-ledger__row dd.is-negative { color: var(--color-danger); }

/* Horizontal bar-per-category component (e.g. CRM pipeline by stage). One
   thin pill track per row; the fill uses the app's existing status color
   tokens so a stage's bar color always matches its badge color elsewhere. */
.bar-rows { display: flex; flex-direction: column; gap: var(--space-sm); }

.bar-row {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  align-items: center;
  gap: var(--space-sm);
}

.bar-row__label { font-size: var(--font-size-sm); color: var(--color-text-secondary); }

.bar-row__track {
  height: 10px;
  border-radius: 9999px;
  background: var(--color-bg-tertiary);
  overflow: hidden;
}

.bar-row__fill {
  height: 100%;
  border-radius: 9999px;
  min-width: 2px;
  transition: width 0.3s ease;
}

.bar-row__value {
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-primary);
  white-space: nowrap;
  text-align: right;
}

.dash-panel__foot-link {
  display: inline-block;
  margin-top: var(--space-md);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  text-decoration: none;
  transition: color 0.15s ease;
}

.dash-panel__foot-link:hover { color: var(--color-primary); }

@media (max-width: 900px) {
  .dash-split { grid-template-columns: 1fr; gap: var(--space-xl); }
}

@media (prefers-reduced-motion: reduce) {
  .dash-quick__link,
  .dash-quick__link svg,
  .dash-stat__value,
  .dash-panel__foot-link { transition: none; }
}

/* ==========================================================================
   Login page
   ========================================================================== */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-lg);
  background:
    radial-gradient(circle at 12% 20%, rgba(0, 122, 124, 0.06), transparent 32%),
    radial-gradient(circle at 88% 78%, rgba(17, 30, 59, 0.05), transparent 32%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

.login-brand img { height: 32px; width: auto; }

.login-title { font-size: var(--font-size-xl); font-weight: 700; margin: 0 0 0.25rem; }
.login-subtitle { color: var(--color-text-secondary); margin: 0; font-size: var(--font-size-sm); }

.login__form { display: flex; flex-direction: column; gap: 1rem; }
.login__form label { font-weight: 600; font-size: var(--font-size-sm); }
.login__form .btn { margin-top: 0.25rem; }

/* Icon-prefixed inputs, shared by email/password fields. */
.input-with-icon { position: relative; display: flex; align-items: center; }

.input-with-icon svg {
  position: absolute;
  left: 0.875rem;
  width: 16px;
  height: 16px;
  color: var(--color-text-tertiary);
  pointer-events: none;
}

.input-with-icon .form-input { padding-left: 2.375rem; }
.input-with-icon .form-input:focus ~ svg,
.input-with-icon:focus-within svg { color: var(--color-primary); }

.password-toggle {
  position: absolute;
  right: 0.375rem;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.password-toggle:hover { background: var(--color-bg-tertiary); color: var(--color-text-secondary); }
.password-toggle svg { width: 16px; height: 16px; }
.input-with-icon:has(.password-toggle) .form-input { padding-right: 2.25rem; }

/* Inline spinner inside the primary submit button while a request is in flight. */
.btn .btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: var(--color-white);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

.btn.is-loading .btn-spinner { display: inline-block; }
.btn.is-loading { cursor: wait; }

.login-alert {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  background: var(--color-danger-bg);
  color: var(--color-danger);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.15s ease-out, transform 0.15s ease-out, display 0.15s allow-discrete;
}

@starting-style {
  .login-alert { opacity: 0; transform: translateY(-4px); }
}

.login-alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 0.0625rem; }
.login-alert[hidden] { display: none; }

.login__helper { font-size: var(--font-size-sm); color: var(--color-text-secondary); }
.login__helper a { font-weight: 600; color: var(--color-text-primary); }
.login__helper a:hover { color: var(--color-primary); }

/* ==========================================================================
   Loading / empty states
   ========================================================================== */
@keyframes spin { to { transform: rotate(360deg); } }

.loading-spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto;
  border: 3px solid var(--color-border-primary);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.empty-state {
  text-align: center;
  padding: var(--space-2xl) var(--space-lg);
  color: var(--color-text-secondary);
}

.empty-state h3 { margin: 0 0 var(--space-xs); color: var(--color-text-primary); font-size: var(--font-size-lg); }
.empty-state p { margin: 0; font-size: var(--font-size-sm); max-width: 40ch; margin-inline: auto; }

/* ==========================================================================
   Utility
   ========================================================================== */
.products-table { min-width: 100%; table-layout: auto; }
.products-table th, .products-table td { white-space: nowrap; padding: 0.625rem 0.875rem; }
.products-table .product-desc { max-width: 300px; white-space: normal; word-wrap: break-word; }

input[type='number']::-webkit-inner-spin-button,
input[type='number']::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type='number'] { -moz-appearance: textfield; appearance: textfield; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1024px) {
  .detail-grid { grid-template-columns: 1fr; }
  .payment-info-card, .payment-form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .page-header { flex-direction: column; align-items: stretch; }
  .filters-bar { flex-direction: column; align-items: stretch; }
  .filters-group { flex-direction: column; }
  .filters-group input[type='text'],
  .filters-group input[type='search'],
  .filters-group select { width: 100%; flex: 1 1 auto; }
  .filter-item { min-width: 100%; }
  .table-actions { flex-wrap: wrap; }
  .app-main { padding: var(--space-lg) var(--space-md); }

  /* Tabs: many pages (customer/supplier detail, quality, accounting) render
     more tab-btns than fit a phone width. Scroll instead of wrapping/clipping. */
  .tab-nav, .price-list-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  .tab-nav .tab-btn, .price-list-tabs .tab-btn { white-space: nowrap; }

  .totals-summary, .totals-bar { min-width: 0; max-width: 100%; width: 100%; }
}

/* Below ~640px: collapse every fixed-column-count grid to a single column.
   Covers both the named .simple-grid--N variants and the many pages/JS
   templates that set grid-template-columns as an inline style (form
   sections, modal field pairs, spreadsheet-row-style JS-rendered rows) —
   the inline styles need !important to win over the inline declaration. */
@media (max-width: 640px) {
  .simple-grid,
  .simple-grid--2,
  .simple-grid--3,
  .simple-grid--4,
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Inputs below 16px trigger iOS Safari's auto-zoom-on-focus, which is
     jarring on a form-heavy app like this. Bump to 16px only at phone
     widths so desktop density is untouched. */
  .form-input, .input-enhanced,
  .form-grid input, .form-grid select, .form-grid textarea,
  .form-stack input, .form-stack select, .form-stack textarea,
  .simple-grid input, .simple-grid select, .simple-grid textarea,
  .form-field input, .form-field select, .form-field textarea,
  .product-search-field,
  .spreadsheet-table input, .spreadsheet-table select,
  .qty-input, .price-input, .total-input, .discount-input, .notes-input, .line-item-input {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .app-main { padding: var(--space-md) var(--space-sm); }
  .modal-header, .modal-body, .modal-footer { padding-left: var(--space-md); padding-right: var(--space-md); }
  .dialog-box { padding: var(--space-lg) var(--space-md) var(--space-md); }
}

/* Touch targets: coarse pointer (touch) gets bigger hit areas regardless of
   screen size — a touchscreen laptop needs this as much as a phone, and a
   mouse-driven narrow window doesn't need it at all. */
@media (pointer: coarse) {
  .btn-icon, .btn--icon, .icon-btn { width: 40px; height: 40px; }
  .delete-row, .remove-line, .line-item-remove { width: 38px; height: 38px; }
  .product-checkbox, .checkbox-label input[type='checkbox'] { width: 20px; height: 20px; }
  .app-sidebar__link { padding: 0.875rem 1rem; }
  .app-sidebar-toggle { padding: 0.625rem; }
  .tab-btn { padding: 0.875rem 0; }
}

/* ============================================================
   Label printing module (labels page + label designer)
   ============================================================ */

.label-print-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.2fr);
  gap: var(--space-lg);
}

.label-preview-scroll {
  overflow: auto;
  max-height: 380px;
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  background: var(--color-bg-tertiary);
}

.label-preview-stage {
  box-shadow: var(--shadow-md);
  border-radius: 4px;
  margin: 0 auto;
}

.label-tspl-pre {
  max-height: 220px;
  overflow: auto;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  font-size: var(--font-size-xs);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Rendered label elements (shared by designer + print preview).
   Labels are always black-on-white regardless of app theme. */
.label-el {
  color: #000;
  /* Matches the server print rasterizer (Arial via opentype.js) so preview
     and print are pixel-equivalent — true Helvetica isn't freely
     redistributable, and Arial is its de facto metric-compatible stand-in. */
  font-family: Arial, Helvetica, sans-serif;
  font-weight: 400;
  box-sizing: border-box;
  overflow: visible;
}

.label-el--text.label-el--bold {
  font-weight: 700;
}

.label-el--error {
  background: repeating-linear-gradient(45deg, #fee, #fee 6px, #fdd 6px, #fdd 12px);
  border: 1px dashed var(--color-danger);
}

/* Designer */
.designer-layout {
  display: grid;
  grid-template-columns: 200px 1fr 300px;
  gap: var(--space-md);
  align-items: start;
}

.designer-tools,
.designer-props {
  position: sticky;
  top: calc(var(--header-height) + var(--space-md));
}

.designer-canvas-wrap {
  overflow: auto;
  padding: var(--space-xl);
  background:
    linear-gradient(45deg, var(--color-bg-tertiary) 25%, transparent 25%, transparent 75%, var(--color-bg-tertiary) 75%),
    linear-gradient(45deg, var(--color-bg-tertiary) 25%, transparent 25%, transparent 75%, var(--color-bg-tertiary) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-md);
  min-height: 420px;
}

.designer-stage {
  box-shadow: var(--shadow-lg);
  cursor: default;
}

.designer-stage .label-el {
  cursor: move;
  user-select: none;
}

.designer-stage .label-el--selected {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

.designer-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: var(--color-primary);
  border: 2px solid #fff;
  border-radius: 3px;
  cursor: nwse-resize;
  z-index: 5;
}

/* Text elements only resize width — height is locked to the font size, so the
   handle sits mid-edge with a horizontal cursor instead of a corner. */
.designer-handle--h-only {
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.designer-props .form-stack label,
.designer-props .form-stack .form-field {
  font-size: var(--font-size-sm);
}

.designer-props .props-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.designer-tool-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  margin-bottom: 0.35rem;
}

@media (max-width: 1024px) {
  .designer-layout { grid-template-columns: 1fr; }
  .designer-tools, .designer-props { position: static; }
  .label-print-grid { grid-template-columns: 1fr; }
}

.designer-props input,
.designer-props select,
.designer-props textarea {
  width: 100%;
  min-width: 0;
}

.designer-props .props-row label {
  min-width: 0;
}
