/*
 * Design tokens. Every value below is reused by the components; avoid
 * one-off values. Text colors meet WCAG AA (4.5:1) on their backgrounds and
 * control borders meet 3:1.
 */
:root {
  color-scheme: light;

  /* Color: neutrals */
  --color-bg: #f6f7f9;
  --color-surface: #ffffff;
  --color-surface-subtle: #eef1f5;
  --color-text: #1f2733;
  --color-text-muted: #5b6575;
  --color-border: #e1e5eb;
  --color-border-control: #848d9a;

  /* Color: brand. Strong primary is for primary actions and current state only. */
  --color-primary: #1d5fbf;
  --color-primary-hover: #174c99;
  --color-primary-soft: #e6effc;
  --color-primary-text: #174c99;
  --color-on-primary: #ffffff;

  /* Color: status */
  --color-success: #1d6b45;
  --color-success-soft: #e2f4ea;
  --color-warning: #7f4d00;
  --color-warning-soft: #fdf0d5;
  --color-error: #a61e3d;
  --color-error-soft: #fce6ea;
  --color-info: #45358f;
  --color-info-soft: #ece8fa;

  /* Color: category tags (text is --color-text) */
  --tag-pink: #fbdbe7;
  --tag-mint: #d3f0e3;
  --tag-lavender: #e3ddf7;
  --tag-peach: #fde2cf;
  --tag-sky: #d6e9fa;
  --tag-lemon: #fbf0bd;

  /* Spacing: 8px base, 4px for fine adjustments */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Typography */
  --font-sans: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-xs: 0.8125rem;  /* 13px: badges, metadata */
  --text-sm: 0.875rem;   /* 14px: labels, helper text */
  --text-md: 1rem;       /* 16px: body, inputs */
  --text-lg: 1.25rem;    /* 20px: section titles */
  --text-xl: 1.5rem;     /* 24px: emphasized numbers */
  --text-2xl: 1.875rem;  /* 30px: page titles */
  --leading-tight: 1.25;
  --leading-normal: 1.5;

  /* Shape */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(31, 39, 51, 0.06);
  --shadow-md: 0 4px 16px rgba(31, 39, 51, 0.08);

  /* Controls */
  --control-height: 44px;
  --control-height-sm: 36px;
  --focus-ring: 0 0 0 3px var(--color-primary-soft);

  /* Motion */
  --duration-fast: 120ms;
  --ease-standard: cubic-bezier(0.2, 0, 0, 1);
}

/* Dark theme, chosen in Settings or following the device ("Match device"). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #12161c;
  --color-surface: #1b212a;
  --color-surface-subtle: #252c36;
  --color-text: #eef2f7;
  --color-text-muted: #a9b3c1;
  --color-border: #333c48;
  --color-border-control: #7c8796;
  --color-primary: #7fb2ff;
  --color-primary-hover: #a3c8ff;
  --color-primary-soft: #1e3352;
  --color-primary-text: #9cc3ff;
  --color-on-primary: #0b1a33;
  --color-success: #8ee0b3;
  --color-success-soft: #183427;
  --color-warning: #f5c46b;
  --color-warning-soft: #3a2c12;
  --color-error: #ff9aac;
  --color-error-soft: #401c25;
  --color-info: #c2b4ff;
  --color-info-soft: #2b2547;
  --tag-pink: #5b2c42;
  --tag-mint: #1f4636;
  --tag-lavender: #3b3366;
  --tag-peach: #5a3a24;
  --tag-sky: #1f3f5c;
  --tag-lemon: #4f4515;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --color-bg: #12161c;
    --color-surface: #1b212a;
    --color-surface-subtle: #252c36;
    --color-text: #eef2f7;
    --color-text-muted: #a9b3c1;
    --color-border: #333c48;
    --color-border-control: #7c8796;
    --color-primary: #7fb2ff;
    --color-primary-hover: #a3c8ff;
    --color-primary-soft: #1e3352;
    --color-primary-text: #9cc3ff;
    --color-on-primary: #0b1a33;
    --color-success: #8ee0b3;
    --color-success-soft: #183427;
    --color-warning: #f5c46b;
    --color-warning-soft: #3a2c12;
    --color-error: #ff9aac;
    --color-error-soft: #401c25;
    --color-info: #c2b4ff;
    --color-info-soft: #2b2547;
    --tag-pink: #5b2c42;
    --tag-mint: #1f4636;
    --tag-lavender: #3b3366;
    --tag-peach: #5a3a24;
    --tag-sky: #1f3f5c;
    --tag-lemon: #4f4515;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  }
}

/* Large text: every size is in rem, so this scales all text at once. */
:root[data-text-size="large"] { font-size: 112.5%; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Base */
* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
}

h1, h2, h3 { margin: 0; line-height: var(--leading-tight); }
h1 { font-size: var(--text-2xl); font-weight: 800; }
h2 { font-size: var(--text-lg); font-weight: 700; }
p { margin: 0; }

a { color: var(--color-primary-text); }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.icon { display: block; flex-shrink: 0; }
.muted { color: var(--color-text-muted); }
.small { font-size: var(--text-sm); }
.strong { font-weight: 700; }
.block { display: block; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* App shell */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 248px;
  height: 100vh;
  padding: var(--space-5) var(--space-4);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-2) var(--space-5);
  font-size: var(--text-lg);
  font-weight: 800;
  line-height: var(--leading-tight);
}
.brand-icon { display: flex; color: var(--color-primary); }

.nav-links { display: flex; flex-direction: column; gap: var(--space-1); }
.nav-divider { height: 1px; margin: var(--space-2) var(--space-2); background: var(--color-border); }

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: none;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.nav-link:hover { background: var(--color-surface-subtle); }
/* Current page: tint, bold text and an indicator bar, so it does not rely on color alone. */
.nav-link.active {
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--color-primary);
}
.nav-icon { display: flex; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text);
  text-decoration: none;
}
.user-chip:hover { background: var(--color-surface-subtle); }
.user-chip.active { background: var(--color-primary-soft); }
.user-text { display: flex; flex-direction: column; min-width: 0; line-height: var(--leading-tight); }
.user-name { overflow: hidden; font-weight: 700; text-overflow: ellipsis; }
.user-role { color: var(--color-text-muted); font-size: var(--text-sm); }

.avatar {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-pill);
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
}
.avatar-lg { width: 56px; height: 56px; }

.topbar { display: none; }

.content { flex: 1; min-width: 0; padding: var(--space-6); }

/* Page structure */
/* Pages fill the space next to the sidebar. */
.page {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* Product page: stock beside the product details on wide screens. */
.product-layout { display: flex; flex-direction: column; gap: var(--space-5); }
.product-side { display: flex; flex-direction: column; gap: var(--space-5); min-width: 0; }
@media (min-width: 1200px) {
  .product-layout.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}

/* Groups of cards that sit side by side when there is room. */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: var(--space-5); align-items: start; }
.split-even { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: var(--space-5); align-items: start; }

/* Edit-batch panel sections */
.edit-section { display: flex; flex-direction: column; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--color-border); }
.edit-section h4 { margin: 0; font-size: var(--text-md); }

.page-header { display: flex; flex-direction: column; gap: var(--space-1); }
.page-header-row {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--space-4);
}
.header-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  width: fit-content;
  min-height: var(--control-height);
  color: var(--color-text-muted);
  font-weight: 700;
  text-decoration: none;
}
.back-link:hover { color: var(--color-primary-text); }

/* Surfaces */
.card {
  padding: var(--space-5);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.section-title { display: flex; flex-direction: column; gap: var(--space-1); }

/* Buttons */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-weight: 700;
  line-height: var(--leading-tight);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard),
    transform var(--duration-fast) var(--ease-standard);
}
.button:hover { background: var(--color-surface-subtle); }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }

.button-primary {
  border-color: var(--color-primary);
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.button-primary:hover { border-color: var(--color-primary-hover); background: var(--color-primary-hover); }

.button-danger { border-color: var(--color-error); color: var(--color-error); }
.button-danger:hover { background: var(--color-error-soft); }

.button-small { min-height: var(--control-height-sm); padding: 0 var(--space-3); font-size: var(--text-sm); }
.button-block { width: 100%; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.icon-button:hover { background: var(--color-surface-subtle); }
.icon-button-danger:hover { background: var(--color-error-soft); color: var(--color-error); }

/* Forms */
.form-stack { display: flex; flex-direction: column; gap: var(--space-5); }
.form-card { display: flex; flex-direction: column; gap: var(--space-4); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }
.form-actions-start { justify-content: flex-start; }

.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field-label { font-size: var(--text-sm); font-weight: 700; }
.optional { margin-left: var(--space-2); color: var(--color-text-muted); font-weight: 600; }
.field-help { color: var(--color-text-muted); font-size: var(--text-sm); }
.field-error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-1);
  color: var(--color-error);
  font-size: var(--text-sm);
  font-weight: 600;
}
.field-error .icon { margin-top: 2px; }

input, select {
  width: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  transition: border-color var(--duration-fast) var(--ease-standard),
    box-shadow var(--duration-fast) var(--ease-standard);
}
input::placeholder { color: var(--color-text-muted); opacity: 1; }
input:focus, select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--color-error); }
input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--color-error-soft); }
input:disabled, select:disabled { background: var(--color-surface-subtle); color: var(--color-text-muted); cursor: not-allowed; }
input[readonly] { background: var(--color-surface-subtle); }
.select-sm { width: auto; min-height: var(--control-height-sm); font-size: var(--text-sm); }

/* Input with a leading "$" or icon. The wrapper draws the border. */
.input-affix {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-weight: 700;
  transition: border-color var(--duration-fast) var(--ease-standard),
    box-shadow var(--duration-fast) var(--ease-standard);
}
.input-affix:focus-within { border-color: var(--color-primary); box-shadow: var(--focus-ring); }
.input-affix:has(input[aria-invalid="true"]) { border-color: var(--color-error); }
.input-affix input { min-height: calc(var(--control-height) - 2px); padding: 0; border: none; font-weight: 400; }
.input-affix input:focus { box-shadow: none; }

.check {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  font-weight: 600;
  cursor: pointer;
}
.check input { width: 20px; height: 20px; min-height: 0; margin: 0; flex-shrink: 0; accent-color: var(--color-primary); }
.check-card {
  align-items: flex-start;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.check-card input { margin-top: 2px; }
.check-card:has(input:checked) { border-color: var(--color-primary); background: var(--color-primary-soft); }

.inline-form { display: flex; flex-direction: column; gap: var(--space-3); }
.inline-form .field { max-width: 420px; }

/* Feedback */
.alert {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-weight: 600;
}
.alert-error { background: var(--color-error-soft); border-color: var(--color-error); color: var(--color-error); }
.alert-success { background: var(--color-success-soft); border-color: var(--color-success); color: var(--color-success); }
.alert-info { background: var(--color-info-soft); border-color: var(--color-info); color: var(--color-info); }
.alert-text { flex: 1; min-width: 180px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  white-space: nowrap;
}
.badge-ok { background: var(--color-success-soft); color: var(--color-success); }
.badge-warn { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-bad { background: var(--color-error-soft); color: var(--color-error); }
.badge-muted { background: var(--color-surface-subtle); color: var(--color-text-muted); }
.badge-owner { background: var(--color-info-soft); color: var(--color-info); }
.badge-staff { background: var(--color-success-soft); color: var(--color-success); }

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  color: var(--color-text-muted);
  font-weight: 600;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: var(--radius-pill);
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  color: var(--color-text-muted);
  text-align: center;
}
.empty-state .empty-title { color: var(--color-text); font-size: var(--text-lg); font-weight: 700; }
.empty-icon { display: inline-flex; color: var(--color-text-muted); }

.splash {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--color-primary);
}

/* Dashboard */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }
.stat-card { display: flex; flex-direction: column; gap: var(--space-2); }
.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--color-text);
}
.stat-value { font-size: var(--text-xl); font-weight: 800; line-height: var(--leading-tight); }
.stat-label { color: var(--color-text-muted); font-size: var(--text-sm); font-weight: 600; }

/* Category tags and color swatches */
.tag {
  display: inline-block;
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  color: var(--color-text);
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
}
.tone-pink, .tag-pink { background: var(--tag-pink); }
.tone-mint, .tag-mint { background: var(--tag-mint); }
.tone-lavender, .tag-lavender { background: var(--tag-lavender); }
.tone-peach, .tag-peach { background: var(--tag-peach); }
.tone-sky, .tag-sky { background: var(--tag-sky); }
.tone-lemon, .tag-lemon { background: var(--tag-lemon); }

.swatches { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.swatch {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--control-height);
  height: var(--control-height);
  padding: 0;
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-pill);
  color: var(--color-text);
  cursor: pointer;
}
.swatch.selected { box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--color-primary); }

/* Toolbar: search and filters */
.toolbar { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-4); }
.search-box {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 48px;
  padding: 0 var(--space-4);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: border-color var(--duration-fast) var(--ease-standard),
    box-shadow var(--duration-fast) var(--ease-standard);
}
.search-box:focus-within { border-color: var(--color-primary); box-shadow: var(--focus-ring); }
.search-box input { min-height: 46px; padding: 0; border: none; font-size: var(--text-md); }
.search-box input:focus { box-shadow: none; }
.toolbar-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--space-3); }
.toolbar-filters { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard);
}
.chip:hover { background: var(--color-surface-subtle); }
.chip[aria-pressed="true"] {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
}
.chip-count {
  min-width: 22px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--color-surface-subtle);
  color: var(--color-text);
  font-size: var(--text-xs);
  text-align: center;
}
.chip[aria-pressed="true"] .chip-count { background: var(--color-surface); color: var(--color-primary-text); }

/* Tables */
.table-card { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); text-align: left; vertical-align: middle; }
.table th {
  background: var(--color-surface-subtle);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: 700;
}
.table tr:last-child td { border-bottom: none; }
.table-clickable tbody tr { cursor: pointer; transition: background-color var(--duration-fast) var(--ease-standard); }
.table-clickable tbody tr:hover { background: var(--color-surface-subtle); }
.actions-cell { width: 1%; white-space: nowrap; }
.row-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }
.reset-row td { background: var(--color-surface-subtle); }
.cell-sub { color: var(--color-text-muted); font-size: var(--text-sm); }
.text-warn { color: var(--color-warning); font-size: var(--text-sm); font-weight: 700; }

.product-name { margin-right: var(--space-2); color: var(--color-text); font-weight: 700; text-decoration: none; }
.product-name:hover { color: var(--color-primary-text); text-decoration: underline; }

/* Product form and details */
.pack-fields { padding: var(--space-4); border-radius: var(--radius-md); background: var(--color-surface-subtle); }

.summary-strip { display: flex; flex-wrap: wrap; gap: var(--space-6); }
.summary-strip > div { display: flex; flex-direction: column; gap: var(--space-1); }
.summary-strip strong { font-size: var(--text-lg); }

.detail-list { margin: 0; padding: var(--space-1) var(--space-5); }
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}
.detail-row:last-child { border-bottom: none; }
.detail-row dt { color: var(--color-text-muted); font-weight: 600; }
.detail-row dd { margin: 0; font-weight: 700; text-align: right; }

.profile-card { display: flex; align-items: center; gap: var(--space-4); }
.profile-card h2 { margin-bottom: var(--space-1); }

/* Simple lists (categories) */
.list-card { padding: var(--space-2) var(--space-5); }
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  min-height: 60px;
  border-bottom: 1px solid var(--color-border);
}
.list-row:last-child { border-bottom: none; }
.list-card .inline-editor { padding: var(--space-3) 0; border: none; border-bottom: 1px solid var(--color-border); border-radius: 0; box-shadow: none; }
.editor-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.editor-row input { flex: 1; min-width: 200px; }


/* Choice cards: radio buttons shown as cards (theme, text size) */
.choice-group { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; border: none; }
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: var(--space-3); }
.choice {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 88px;
  padding: var(--space-3);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard),
    border-color var(--duration-fast) var(--ease-standard);
}
.choice:hover { background: var(--color-surface-subtle); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
  box-shadow: inset 0 0 0 1px var(--color-primary);
}
.choice:has(input:focus-visible) { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.choice-sample { font-weight: 800; line-height: 1; }
.sample-standard { font-size: 1.25rem; }
.sample-large { font-size: 1.6rem; }


/* Product picker (Sell, Receive) */
.picker { display: flex; flex-direction: column; gap: var(--space-3); }
.picker-results { display: flex; flex-direction: column; gap: var(--space-1); margin: 0; padding: 0; list-style: none; }
.picker-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 56px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}
.picker-result:hover:not(:disabled) { border-color: var(--color-primary); background: var(--color-primary-soft); }
.picker-result:disabled { opacity: 0.55; cursor: not-allowed; }
.picker-main, .picker-side { display: flex; flex-direction: column; gap: 2px; }
.picker-side { align-items: flex-end; text-align: right; }
.picker-empty { padding: var(--space-2) 0; }

/* Two columns: products and cart */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); gap: var(--space-5); align-items: start; }
.cart { position: sticky; top: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.cart-header { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); }
.cart-empty { padding: var(--space-6) var(--space-2); }
.cart-lines { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.cart-line { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); }
.cart-line:first-child { padding-top: 0; }
.cart-line-over .stepper input { border-color: var(--color-warning); }
.cart-line-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
.cart-line-controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.cart-line-total { margin-left: auto; font-weight: 800; }
.cart-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: var(--space-2); font-size: var(--text-lg); }
.cart-total strong { font-size: var(--text-xl); }
.button-large { min-height: 52px; font-size: var(--text-lg); }

.stepper { display: inline-flex; align-items: center; gap: var(--space-1); }
.stepper input { width: 72px; text-align: center; }
.stepper .icon-button { border: 1px solid var(--color-border-control); }
.stepper .icon-button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Segmented choice (units or packs) */
.segmented { display: inline-flex; flex-wrap: wrap; gap: var(--space-2); }
.segment { position: relative; display: inline-flex; cursor: pointer; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-height-sm);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: 700;
}
.segment input:checked + span { border-color: var(--color-primary); background: var(--color-primary-soft); color: var(--color-primary-text); }
.segment input:focus-visible + span { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.selected-product { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: var(--space-3); }

/* Dashboard */
.stat-sub { color: var(--color-text-muted); font-size: var(--text-sm); }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-4); }
.dash-grid > .card { display: flex; flex-direction: column; gap: var(--space-3); }
.dash-wide { grid-column: 1 / -1; }
.mini-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.mini-list li { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); min-height: 52px; padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); }
.mini-list li:last-child { border-bottom: none; }
.mini-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; }
.mini-empty { padding: var(--space-2) 0; }
.expired-note { display: flex; align-items: center; gap: var(--space-2); }

.chart { display: flex; flex-direction: column; gap: var(--space-2); }
.chart-svg { display: block; width: 100%; height: 180px; overflow: visible; }
.chart-baseline { stroke: var(--color-border-control); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-hit { fill: transparent; }
.chart-bar { fill: var(--color-primary); transition: fill var(--duration-fast) var(--ease-standard); }
.chart-slot:hover .chart-bar { fill: var(--color-primary-hover); }
.chart-slot:hover .chart-hit { fill: var(--color-surface-subtle); }
.chart-labels { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); color: var(--color-text-muted); font-size: var(--text-xs); text-align: center; }
.chart-table summary, .history summary { min-height: var(--control-height); display: flex; align-items: center; color: var(--color-primary-text); font-weight: 700; cursor: pointer; }

/* Stock section on the product page */
.table-scroll { overflow-x: auto; margin: 0 calc(-1 * var(--space-5)); }
.table-scroll .table th:first-child, .table-scroll .table td:first-child { padding-left: var(--space-5); }
.correction-form { align-items: start; }
.correction-panel { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-4); border-radius: var(--radius-md); background: var(--color-surface-subtle); }
.correction-panel h3 { font-size: var(--text-md); }
.table-batches td[data-label="Left"], .table-batches td[data-label="Unit cost"], .table-batches td[data-label="Received"] { white-space: nowrap; }
.correction-actions { grid-column: 1 / -1; }
.history-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.history-list li { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); }
.history-list li:last-child { border-bottom: none; }
.history-main { display: flex; flex-direction: column; gap: 2px; }
.history-side { text-align: right; }
.num { text-align: right; }
.table th.num, .table td.num { text-align: right; }

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-5) var(--space-4);
}
.login-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: 100%;
  max-width: 400px;
  padding: var(--space-6) var(--space-5);
  box-shadow: var(--shadow-md);
}
.login-header { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); text-align: center; }
.login-header h1 { font-size: var(--text-xl); }
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-lg);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

/* Phone */
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .content { padding: var(--space-4) var(--space-4) 104px; }
  .card { padding: var(--space-4); }
  .table-card { padding: 0; }
  .page { gap: var(--space-4); }
  h1 { font-size: var(--text-xl); }

  /* Touch targets: no small controls on phones */
  .button-small, .chip, .select-sm { min-height: var(--control-height); }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
  }
  .topbar .brand { padding: 0; font-size: var(--text-md); }
  .topbar-actions { display: flex; gap: var(--space-1); }
  /* Keep the edit panel's title clear of the sticky top bar when it scrolls into view. */
  .correction-panel { scroll-margin-top: calc(var(--control-height) + var(--space-2) * 2 + var(--space-3)); }

  .sidebar {
    position: fixed;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    width: auto;
    height: auto;
    padding: var(--space-1) var(--space-2) calc(var(--space-1) + env(safe-area-inset-bottom));
    border-top: 1px solid var(--color-border);
    border-right: none;
    box-shadow: var(--shadow-md);
  }
  .sidebar .brand, .sidebar-footer, .nav-divider { display: none; }
  .nav-links { flex-direction: row; justify-content: space-around; }
  .nav-links .nav-link:nth-child(n + 7) { display: none; }
  .nav-link {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-height: 56px;
    padding: var(--space-1);
    font-size: 0.75rem;
  }
  .nav-link.active { box-shadow: inset 0 3px 0 var(--color-primary); }

  .page-header-row { align-items: stretch; }
  .header-actions { width: 100%; }
  .header-actions .button { flex: 1; }
  .summary-strip { gap: var(--space-4); }
  .detail-list { padding: var(--space-1) var(--space-4); }
  .list-card { padding: var(--space-1) var(--space-4); }

  /* Tables become stacked cards */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); }
  .table tr:last-child { border-bottom: none; }
  .table td { padding: var(--space-1) 0; border: none; }
  .table td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
  }
  .actions-cell { width: 100%; white-space: normal; }
  .row-actions { flex-wrap: wrap; justify-content: flex-start; padding-top: var(--space-2); }
  .list-row .row-actions { padding-top: 0; }

  .split { grid-template-columns: 1fr; }
  .cart { position: static; }
  .dash-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .stat-value { font-size: var(--text-lg); }
  .segment span { min-height: var(--control-height); }
  .table-scroll { margin: 0; }
  .table-scroll .table td:first-child { padding-left: 0; }
  .table th.num, .table td.num { text-align: left; }
  .history-list li { grid-template-columns: auto 1fr; }
  .history-side { grid-column: 2; text-align: left; }

  /* Compact product cards: name and status, category, then stock and price */
  .table-clickable tr { display: grid; grid-template-columns: 1fr auto; gap: var(--space-1) var(--space-3); }
  .table-clickable td[data-label]::before { display: none; }
  .table-clickable td[data-label="Status"] { grid-row: 1; grid-column: 2; text-align: right; }
  .table-clickable td[data-label="Category"] { grid-column: 1 / -1; }
  .table-clickable td[data-label="Price"] { text-align: right; }
  .table-clickable td[data-label="Sold"] { display: none; }
}
