/* style.css — Premium blue/grey UI for Stock Inventory.
   Single-file stylesheet, no framework. Designed for clarity on desktop and
   touch-friendliness on phones. All animations respect prefers-reduced-motion. */

/* The HTML `hidden` attribute must always win over author `display:` rules
   (e.g. flex/grid containers) — otherwise JS toggling `.hidden = true` fails
   silently on styled elements. */
[hidden] { display: none !important; }

/* ---- Design tokens ----------------------------------------------------- */
:root {
  /* Surfaces — deep cyber/neon dark palette */
  --bg:             #07091a;   /* page background */
  --bg-tint:        #050717;   /* for the soft radial accent */
  --surface:        #10132a;
  --surface-2:      #161a36;   /* table header, muted panels */
  --surface-3:      #1d2244;

  /* Borders */
  --border:         #2a315a;
  --border-strong:  #3e4680;

  /* Text */
  --text:           #e8ecff;   /* near-white with cool cast */
  --text-secondary: #b8c1e8;
  --text-muted:     #7c86b3;

  /* Brand — neon cyan */
  --primary:        #00e0ff;
  --primary-hover:  #22efff;
  --primary-active: #00b8d4;
  --primary-soft:   rgba(0, 224, 255, 0.18);
  --primary-ring:   rgba(0, 224, 255, 0.35);

  /* Status — neon variants */
  --success:        #39ff14;
  --success-soft:   rgba(57, 255, 20, 0.16);
  --warn:           #ffb800;
  --warn-soft:      rgba(255, 184, 0, 0.18);
  --danger:         #ff2d6f;
  --danger-hover:   #ff4d88;
  --danger-soft:    rgba(255, 45, 111, 0.18);

  /* Row highlights */
  --low-bg:         rgba(255, 184, 0, 0.08);
  --low-border:     #ffb800;
  --low-text:       #ffcf55;
  --out-bg:         rgba(255, 45, 111, 0.08);
  --out-border:     #ff2d6f;
  --out-text:       #ff8aa8;

  /* Neon accents used for descriptions + highlight glows */
  --neon-cyan:      #00ffff;
  --neon-magenta:   #ff3df0;
  --neon-lime:      #b6ff3a;
  --neon-pink:      #ff10a0;

  /* Layered shadows */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-md:  0 4px 10px -2px rgba(0, 0, 0, 0.55), 0 2px 4px -2px rgba(0, 0, 0, 0.35);
  --shadow-lg:  0 12px 28px -8px rgba(0, 0, 0, 0.65), 0 4px 10px -4px rgba(0, 0, 0, 0.5);
  --shadow-xl:  0 24px 60px -12px rgba(0, 0, 0, 0.8);
  --shadow-ring: 0 0 0 4px var(--primary-ring);
  --shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.06);

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  /* Motion */
  --ease:     cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in:  cubic-bezier(0.4, 0, 1, 1);
  --dur-1:    120ms;
  --dur-2:    200ms;
  --dur-3:    320ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 40% at 50% -10%, rgba(0, 224, 255, 0.12), transparent 70%),
    radial-gradient(ellipse 50% 35% at 90% 110%, rgba(255, 61, 240, 0.09), transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-tint) 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.015em; font-weight: 600; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  background: var(--surface-3);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ---- Top bar ----------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: rgba(16, 19, 42, 0.72);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  text-shadow: 0 0 18px rgba(0, 255, 255, 0.25);
}
.topbar h1.brand-home {
  cursor: pointer;
  transition: filter var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
  user-select: none;
}
.topbar h1.brand-home:hover { filter: brightness(1.15); }
.topbar h1.brand-home:active { transform: translateY(1px); }
.topbar h1.brand-home:focus-visible {
  outline: none;
  box-shadow: var(--shadow-ring);
  border-radius: 6px;
}
.topbar h1::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, var(--neon-cyan), var(--neon-magenta));
  box-shadow: 0 0 10px rgba(0, 255, 255, 0.75), 0 0 18px rgba(255, 61, 240, 0.45);
}
/* Topbar layout is h1 · primary nav · utility cluster · account area.
   Nav takes the flexible middle space so the right-hand controls stay
   anchored while the brand sits on the left. */
.topbar { gap: 16px; }
.topbar h1 { flex: 0 0 auto; }
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  margin-left: 8px;
}
.topbar-utility {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  position: relative;
}

/* Primary-nav links. Quieter than a full button — just a subtle hover chip
   plus a distinct "active" state so users can tell which page they're on. */
.topbar-nav-link,
a.topbar-nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  text-decoration: none;
  box-shadow: none;
  transition: background-color var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease),
              border-color var(--dur-1) var(--ease);
}
.topbar-nav-link:hover,
a.topbar-nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.topbar-nav-link.active,
a.topbar-nav-link.active {
  color: var(--text);
  background: var(--surface-3);
  border-color: var(--border-strong);
  box-shadow: inset 0 0 0 1px rgba(0, 255, 255, 0.08);
}
.topbar-nav-icon { font-size: 14px; line-height: 1; }
.topbar-nav-label { white-space: nowrap; }

/* Account menu: username chip acts as trigger; panel drops out below it. */
#current-user {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  background: var(--surface-3);
  border-radius: 999px;
}
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 6px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: none;
  transition: background-color var(--dur-1) var(--ease),
              border-color var(--dur-1) var(--ease);
}
.user-menu-trigger:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.user-menu-trigger[aria-expanded="true"] {
  background: var(--surface-3);
  border-color: var(--primary);
  box-shadow: var(--shadow-ring);
}
/* Inside the trigger, the #current-user chip is redundant styling — flatten
   it so the trigger itself reads as the pill. */
.user-menu-trigger #current-user {
  background: transparent;
  padding: 0;
  color: var(--text);
  border-radius: 0;
}
.user-menu-caret {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1;
  transition: transform var(--dur-1) var(--ease);
}
.user-menu-trigger[aria-expanded="true"] .user-menu-caret { transform: rotate(180deg); }

.user-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 240px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: 0 12px 32px -6px rgba(0, 0, 0, 0.55), var(--shadow-inset);
  z-index: 20;
  animation: user-menu-in 0.12s var(--ease);
}
@keyframes user-menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.user-menu-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 8px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.user-menu-meta-label {
  grid-column: 1 / -1;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.user-menu-meta-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.user-menu-meta-role {
  align-self: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.user-menu-meta-role.role-badge-admin {
  color: #0b1020;
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-magenta));
  border-color: transparent;
}
/* Master admin (cross-tenant operator) — gold gradient sets it apart from
   the cyan/magenta used for the per-tenant admin tier. */
.user-menu-meta-role.role-badge-operator {
  color: #1a1200;
  background: linear-gradient(90deg, #ffd24a, #ff8a00);
  border-color: transparent;
  box-shadow: 0 0 0 1px rgba(255, 210, 74, 0.4),
              0 0 12px rgba(255, 138, 0, 0.35);
}

.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}

/* Menu items share one look whether they're anchor links (Settings/Users)
   or the reparented Log out button. */
.user-menu-item,
a.user-menu-item,
button.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  box-shadow: none;
  transition: background-color var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.user-menu-item:hover,
a.user-menu-item:hover,
button.user-menu-item:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
}
.user-menu-item.active { background: var(--surface-3); }
.user-menu-item .user-menu-icon {
  display: inline-flex;
  width: 20px;
  justify-content: center;
  font-size: 14px;
  color: var(--text-muted);
}
.user-menu-logout { color: #fecaca; }
.user-menu-logout:hover { background: rgba(239, 68, 68, 0.12); color: #fee2e2; }

/* ---- Low-stock badge (topbar) ----------------------------------------- */
.low-stock-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: linear-gradient(180deg, #fef3c7, #fde68a);
  border: 1px solid #f59e0b;
  color: #78350f;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 2px 6px rgba(245, 158, 11, 0.25);
  animation: badge-pulse 2.4s var(--ease) infinite;
  min-height: auto;
}
.low-stock-badge:hover {
  background: linear-gradient(180deg, #fde68a, #fcd34d);
  border-color: #d97706;
  transform: translateY(-1px);
}
.low-stock-badge:active { transform: translateY(0); }
.low-stock-badge.active {
  background: linear-gradient(180deg, #f59e0b, #d97706);
  color: white;
  border-color: #b45309;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 4px 10px rgba(245, 158, 11, 0.45);
  animation: none;
}
.low-stock-badge .badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  font-size: 13px;
  font-weight: 700;
}
@keyframes badge-pulse {
  0%, 100% {
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.5) inset,
      0 2px 6px rgba(245, 158, 11, 0.25),
      0 0 0 0 rgba(245, 158, 11, 0);
  }
  50% {
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.5) inset,
      0 2px 6px rgba(245, 158, 11, 0.25),
      0 0 0 8px rgba(245, 158, 11, 0.18);
  }
}

/* ---- Toolbar ----------------------------------------------------------- */
.toolbar {
  display: flex;
  gap: 10px;
  padding: 20px 28px 14px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar input[type="search"],
.toolbar select {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 14px;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-2) var(--ease),
              box-shadow  var(--dur-2) var(--ease);
}
.toolbar input[type="search"] {
  flex: 1;
  min-width: 220px;
  max-width: 420px;
  /* Search icon — pure SVG data URI, no external dep. */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2300e0ff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m20 20-3.5-3.5'/></svg>");
  background-repeat: no-repeat;
  background-position: 12px center;
  padding-left: 38px;
}
.toolbar input[type="search"]:focus,
.toolbar select:focus,
.toolbar input[type="search"]:hover,
.toolbar select:hover {
  outline: none;
  border-color: var(--primary);
}
.toolbar input[type="search"]:focus,
.toolbar select:focus {
  box-shadow: var(--shadow-sm), var(--shadow-ring);
}

/* ---- Buttons ----------------------------------------------------------- */
/* Anchors that carry a button class (.btn-ghost / .btn-primary / .btn-danger)
   are treated as buttons so topbar nav links match real buttons visually. */
button,
a.btn-ghost,
a.btn-primary,
a.btn-danger {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--r-md);
  padding: 9px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm), var(--shadow-inset);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.2;
  transition: transform var(--dur-1) var(--ease),
              background-color var(--dur-2) var(--ease),
              border-color var(--dur-2) var(--ease),
              box-shadow var(--dur-2) var(--ease),
              color var(--dur-2) var(--ease);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button:hover,
a.btn-ghost:hover,
a.btn-primary:hover,
a.btn-danger:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
button:active,
a.btn-ghost:active,
a.btn-primary:active,
a.btn-danger:active { transform: translateY(1px); box-shadow: var(--shadow-sm); }
button:focus-visible,
a.btn-ghost:focus-visible,
a.btn-primary:focus-visible,
a.btn-danger:focus-visible {
  outline: none;
  box-shadow: var(--shadow-sm), var(--shadow-ring);
  border-color: var(--primary);
}

.btn-primary {
  background: linear-gradient(180deg, #3b82f6, var(--primary));
  color: white;
  border-color: var(--primary-hover);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 1px 2px rgba(37, 99, 235, 0.3),
    0 4px 12px -4px rgba(37, 99, 235, 0.4);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #2f7af4, var(--primary-hover));
  border-color: var(--primary-active);
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 2px 4px rgba(37, 99, 235, 0.35),
    0 8px 18px -4px rgba(37, 99, 235, 0.45);
}
.btn-primary:active {
  transform: translateY(0);
  background: linear-gradient(180deg, var(--primary-hover), var(--primary-active));
}

.btn-ghost {
  background: var(--surface);
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: linear-gradient(180deg, #ef4444, var(--danger));
  color: white;
  border-color: var(--danger-hover);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 1px 2px rgba(220, 38, 38, 0.3),
    0 4px 12px -4px rgba(220, 38, 38, 0.4);
}
.btn-danger:hover {
  background: linear-gradient(180deg, #dc2626, var(--danger-hover));
  border-color: #991b1b;
  transform: translateY(-1px);
}
.btn-danger:active { transform: translateY(0); }

/* ---- Main + table ------------------------------------------------------ */
main { padding: 6px 28px 40px; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
}
th, td {
  text-align: left;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
tbody tr {
  transition: background-color var(--dur-2) var(--ease);
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td strong { font-weight: 600; color: var(--text); }
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* Stock status rows */
tr.low-stock    { background: var(--low-bg); }
tr.low-stock:hover { background: #fef7e0; }
tr.low-stock td:first-child {
  position: relative;
  box-shadow: inset 3px 0 0 var(--low-border);
}
tr.out-of-stock { background: var(--out-bg); }
tr.out-of-stock:hover { background: #fee7e7; }
tr.out-of-stock td:first-child {
  position: relative;
  box-shadow: inset 3px 0 0 var(--out-border);
}
tr.out-of-stock .num,
tr.low-stock .num { font-weight: 600; }

/* Items-table presentation: colored swatch + name, mono SKU, large stock
   number, and a status pill. Mirrors the landing-page hero mockup so the
   product looks consistent end-to-end. */
.item-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.item-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--sw, var(--primary));
  box-shadow: 0 0 8px var(--sw, var(--primary));
  flex-shrink: 0;
}
.item-cell__text { min-width: 0; }
.item-desc {
  margin: 2px 0 0;
  font-size: 12px;
}
.sku-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.qty-big {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.stock-status {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid;
  white-space: nowrap;
}
.stock-status--ok  {
  color: var(--success);
  border-color: rgba(57, 255, 20, 0.4);
  background: var(--success-soft);
}
.stock-status--low {
  color: var(--low-text);
  border-color: rgba(255, 184, 0, 0.45);
  background: var(--low-bg);
}
.stock-status--out {
  color: var(--out-text);
  border-color: rgba(255, 45, 111, 0.5);
  background: var(--out-bg);
}

/* Per-row action buttons */
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions button {
  padding: 5px 10px;
  font-size: 12px;
  line-height: 1.2;
  border-radius: var(--r-sm);
  font-weight: 500;
}
.row-actions button[data-action="add"],
.row-actions button[data-action="remove"] {
  font-size: 15px;
  font-weight: 600;
  padding: 4px 10px;
  min-width: 32px;
}
.row-actions button[data-action="add"]:hover    { color: var(--success); border-color: var(--success); }
.row-actions button[data-action="remove"]:hover { color: var(--warn);    border-color: var(--warn); }

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 24px;
  font-size: 14px;
}

/* ---- Modals (native <dialog>) ----------------------------------------- */
dialog {
  border: none;
  border-radius: var(--r-xl);
  padding: 28px;
  max-width: 520px;
  width: calc(100% - 32px);
  background: var(--surface);
  box-shadow: var(--shadow-xl);
  color: var(--text);
}
dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
dialog[open] {
  animation: dialog-in var(--dur-3) var(--ease);
}
dialog[open]::backdrop {
  animation: fade-in var(--dur-3) var(--ease);
}
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

dialog h2 {
  margin-bottom: 6px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

dialog form label {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
dialog form input,
dialog form textarea,
dialog form select {
  display: block;
  width: 100%;
  padding: 10px 12px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 400;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  text-transform: none;
  letter-spacing: normal;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-2) var(--ease),
              box-shadow var(--dur-2) var(--ease);
}
dialog form input:hover,
dialog form textarea:hover,
dialog form select:hover {
  border-color: var(--border-strong);
}
dialog form input:focus,
dialog form textarea:focus,
dialog form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm), var(--shadow-ring);
}
dialog form .row { display: flex; gap: 14px; }
dialog form .row label { flex: 1; }

dialog .actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
  margin: -4px 0 14px;
}
.form-error, .error {
  color: var(--danger);
  font-size: 13px;
  margin: 10px 0 0;
  padding: 10px 12px;
  background: var(--danger-soft);
  border: 1px solid #fca5a5;
  border-radius: var(--r-sm);
  white-space: pre-wrap;
  line-height: 1.45;
}

/* History modal is wider so the columns breathe */
#history-modal { max-width: 740px; }
#history-modal table {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.history-wrap { display: flex; flex-direction: column; gap: 10px; }

/* ---- Categories home view --------------------------------------------- */
/* The default screen: a grid of category tiles. Clicking a tile drills
   into that category's items. Tiles highlight with an amber left border
   when any of their items are at or below minimum stock. */
.home-toolbar,
.items-toolbar {
  align-items: center;
}
.view-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-right: auto; /* pushes subsequent toolbar items to the right */
}
.items-toolbar .view-title {
  margin-right: 8px;
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 4px;
}
.category-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 22px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  box-shadow: var(--shadow-sm);
  min-height: 110px;
  transition: transform 140ms var(--ease, ease),
              box-shadow 140ms var(--ease, ease),
              border-color 140ms var(--ease, ease);
}
.category-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}
.category-card:focus-visible {
  outline: none;
  box-shadow: var(--shadow-md), var(--shadow-ring);
  border-color: var(--primary);
}
.category-card.has-low {
  border-left: 4px solid var(--warn);
}
.category-card-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  word-break: break-word;
}
.category-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-muted);
  align-items: center;
}
.low-pill {
  background: var(--warn-soft);
  color: var(--warn);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11.5px;
}

/* ---- Usage report range picker ---------------------------------------- */
/* Dialog with sections for each report type (Usage / Reorder / By person).
   Each section groups a label and one row of buttons or controls. */
.report-wrap { display: flex; flex-direction: column; gap: 14px; min-width: 360px; max-width: 480px; }
.report-section { display: flex; flex-direction: column; gap: 6px; }
.report-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}
.report-range {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.report-range button {
  flex: 1 1 140px;
  min-width: 140px;
  padding: 14px 12px;
  font-size: 14px;
  font-weight: 600;
}
.report-person-row select {
  flex: 1 1 140px;
  min-width: 0;
  padding: 10px 12px;
}
.report-person-row button { flex: 0 0 auto; }

/* ---- Item-modal inline camera ----------------------------------------- */
/* Compact camera picker that lives inside the Add/Edit Item modal, so
   users can scan a new item's barcode at creation time. Shares the camera
   engine logic with Scan Mode via a shared factory in app.js. */
.item-camera {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.item-camera button {
  width: 100%;
  padding: 10px 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.item-camera .camera-stage {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 10;
  background: #0f172a;
  border-radius: var(--r-md);
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow-md);
}
.item-camera .camera-stage video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---- Scan Mode modal --------------------------------------------------- */
.scan-modal { max-width: 600px; }
.scan-wrap { display: flex; flex-direction: column; gap: 16px; }
.scan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.scan-config {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.scan-direction, .scan-mode { display: flex; gap: 8px; }
.scan-direction .pill, .scan-mode .pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  margin: 0;
  text-transform: none;
  letter-spacing: normal;
  box-shadow: var(--shadow-sm);
  transition: all var(--dur-2) var(--ease);
}
.scan-direction .pill:hover, .scan-mode .pill:hover {
  border-color: var(--border-strong);
  color: var(--text);
}
.scan-direction .pill input, .scan-mode .pill input { display: none; }
.scan-direction .pill:has(input:checked), .scan-mode .pill:has(input:checked) {
  background: linear-gradient(180deg, #3b82f6, var(--primary));
  border-color: var(--primary-hover);
  color: white;
  font-weight: 600;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 4px 12px -4px rgba(37, 99, 235, 0.45);
}
.scan-config .row label { margin-bottom: 0; }

.scan-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}
#scan-input {
  width: 100%;
  padding: 20px 18px;
  font-size: 22px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border: 2px solid var(--primary);
  border-radius: var(--r-lg);
  text-align: center;
  letter-spacing: 0.06em;
  color: var(--neon-cyan);
  background: linear-gradient(180deg, #0d1230, #151a3d);
  outline: none;
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.6);
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.5),
    0 0 18px rgba(0, 224, 255, 0.25);
  transition: box-shadow var(--dur-2) var(--ease);
}
#scan-input:focus {
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.5),
    0 0 24px rgba(0, 224, 255, 0.55),
    var(--shadow-ring);
  animation: scan-pulse 1.6s var(--ease) infinite;
}
@keyframes scan-pulse {
  0%, 100% { box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5), 0 0 18px rgba(0, 224, 255, 0.35), 0 0 0 0 var(--primary-ring); }
  50%      { box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5), 0 0 28px rgba(0, 224, 255, 0.7),  0 0 0 8px var(--primary-ring); }
}
.scan-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.scan-feed-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  max-height: 280px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.scan-feed-header {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.scan-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.scan-feed:empty::before {
  content: "Waiting for scans…";
  display: block;
  padding: 22px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.scan-entry {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  animation: scan-flash 500ms var(--ease);
}
.scan-entry:last-child { border-bottom: none; }
.scan-entry .icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: white;
  box-shadow: 0 2px 8px -2px rgba(15, 23, 42, 0.3);
}
.scan-entry.ok   .icon { background: linear-gradient(135deg, #10b981, var(--success)); }
.scan-entry.warn .icon { background: linear-gradient(135deg, #f59e0b, var(--warn)); }
.scan-entry.err  .icon { background: linear-gradient(135deg, #ef4444, var(--danger)); }
.scan-entry .text { flex: 1; min-width: 0; }
.scan-entry .title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.scan-entry .detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
@keyframes scan-flash {
  from { background: var(--primary-soft); }
  to   { background: transparent; }
}

/* ---- Scan Mode camera panel ------------------------------------------- */
.scan-camera {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
#camera-toggle {
  width: 100%;
  padding: 12px;
  font-size: 14px;
  font-weight: 500;
}
.camera-stage {
  position: relative;
  width: 100%;
  max-width: 460px;
  aspect-ratio: 4 / 3;
  background: #0f172a;
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
#scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.camera-reticle {
  position: absolute;
  inset: 15% 10%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--r-md);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

/* ---- Login page -------------------------------------------------------- */
.login-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(0, 224, 255, 0.18), transparent 70%),
    radial-gradient(ellipse 60% 40% at 90% 100%, rgba(255, 61, 240, 0.14), transparent 70%),
    linear-gradient(180deg, var(--bg), var(--bg-tint));
}
.login-page .login-card { margin: auto; }
.login-card {
  background: rgba(16, 19, 42, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 36px 32px;
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl), 0 0 40px rgba(0, 224, 255, 0.1);
  width: 100%;
  max-width: 380px;
  animation: dialog-in var(--dur-3) var(--ease);
}
.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 24px rgba(0, 255, 255, 0.25);
}
.login-card .subtitle {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 14px;
}
.login-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 14px;
}
.login-card input {
  display: block;
  width: 100%;
  padding: 12px 14px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-2) var(--ease),
              box-shadow var(--dur-2) var(--ease);
}
.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm), var(--shadow-ring);
}
.login-card button {
  width: 100%;
  padding: 12px;
  background: linear-gradient(180deg, #3b82f6, var(--primary));
  color: white;
  border: 1px solid var(--primary-hover);
  border-radius: var(--r-md);
  font-size: 15px;
  font-weight: 600;
  margin-top: 6px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 4px 12px -4px rgba(37, 99, 235, 0.45);
  transition: transform var(--dur-1) var(--ease),
              box-shadow var(--dur-2) var(--ease),
              background var(--dur-2) var(--ease);
}
.login-card button:hover {
  background: linear-gradient(180deg, #2f7af4, var(--primary-hover));
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 8px 18px -4px rgba(37, 99, 235, 0.5);
}
.login-card button:active { transform: translateY(0); }

/* ---- Mobile / narrow-viewport responsive rules ------------------------- */
@media (max-width: 640px) {
  body { font-size: 16px; } /* 16px to stop iOS form-zoom */

  .topbar {
    padding: 12px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar h1 { font-size: 17px; }
  /* Phones: brand + utility + account stay on row 1; the primary nav wraps
     to row 2 and collapses each link to just its icon (title attribute still
     explains on long-press). */
  .topbar h1 { order: 1; }
  .topbar-utility { order: 2; margin-left: auto; }
  .topbar-right { order: 3; }
  .topbar-nav {
    order: 4;
    flex-basis: 100%;
    margin-left: 0;
    gap: 2px;
    overflow-x: auto;
    justify-content: space-around;
  }
  .topbar-nav-link { padding: 6px 10px; }
  .topbar-nav-label { display: none; }
  /* Trigger collapses to the caret + role badge — username lives in the panel. */
  .user-menu-trigger #current-user { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-menu-panel { right: 0; left: auto; min-width: 220px; }

  .toolbar {
    padding: 14px 14px 10px;
    gap: 8px;
  }
  .toolbar input[type="search"] {
    flex: 1 1 100%;
    max-width: none;
  }
  .toolbar select { flex: 1 1 45%; }
  .toolbar button { flex: 1 1 45%; }

  main { padding: 4px 10px 28px; }

  /* Keep Item, SKU, Stock, Status, Actions visible; hide Location on phones. */
  #items-table th:nth-child(3),
  #items-table td:nth-child(3) {
    display: none;
  }

  th, td { padding: 12px 12px; }

  /* Bigger tap targets. */
  button {
    min-height: 44px;
    padding: 11px 16px;
  }
  .row-actions button {
    min-height: 36px;
    font-size: 13px;
    padding: 6px 12px;
  }

  /* Near-full-screen dialogs on phones. */
  dialog {
    max-width: 100%;
    width: calc(100% - 12px);
    max-height: calc(100vh - 12px);
    margin: 6px auto;
    padding: 20px;
    border-radius: var(--r-lg);
    overflow-y: auto;
  }
  #history-modal, .scan-modal { max-width: 100%; }

  dialog form .row {
    flex-direction: column;
    gap: 0;
  }
  dialog form input,
  dialog form select,
  dialog form textarea {
    font-size: 16px; /* prevent iOS auto-zoom */
  }

  #scan-input {
    font-size: 20px;
    padding: 16px 14px;
  }
  .scan-feed-wrap { max-height: 200px; }
  .scan-entry { padding: 10px 12px; }
  .scan-entry .title { font-size: 13px; }

  .login-card {
    box-shadow: var(--shadow-lg);
    border-radius: var(--r-lg);
    max-width: 100%;
    padding: 28px 22px;
    margin: 12px;
  }
}

/* Extra-narrow phones — one-per-row toolbar controls. */
@media (max-width: 380px) {
  .toolbar button,
  .toolbar select { flex: 1 1 100%; }
}

/* ---- Toast notifications ---------------------------------------------- */
/* Stacked top-right, slide in from the side, auto-dismiss after a few
   seconds. Used primarily for low-stock alerts but generic enough to reuse. */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
  max-width: calc(100vw - 40px);
}
.toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xl);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: toast-in 340ms var(--ease);
}
.toast.toast-out {
  animation: toast-out 240ms var(--ease-in) forwards;
}
.toast.warn { border-left-color: var(--warn); }
.toast.err  { border-left-color: var(--danger); }
.toast.ok   { border-left-color: var(--success); }

/* Clickable toasts (e.g. low-stock alerts) — opening a details popup on
   click. Slight lift + tinted background on hover to hint it's interactive. */
.toast.clickable {
  cursor: pointer;
  transition: transform var(--dur-2) var(--ease),
              box-shadow var(--dur-2) var(--ease),
              background-color var(--dur-2) var(--ease);
}
.toast.clickable:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-xl), 0 0 0 1px var(--border);
  background: var(--surface-2, var(--surface));
}

.toast .toast-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: white;
  background: linear-gradient(135deg, #60a5fa, var(--primary));
  box-shadow: 0 2px 8px -2px rgba(15, 23, 42, 0.25);
}
.toast.warn .toast-icon { background: linear-gradient(135deg, #fbbf24, var(--warn)); }
.toast.err  .toast-icon { background: linear-gradient(135deg, #f87171, var(--danger)); }
.toast.ok   .toast-icon { background: linear-gradient(135deg, #34d399, var(--success)); }

.toast .toast-body { flex: 1; min-width: 0; }
.toast .toast-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  line-height: 1.35;
}
.toast .toast-msg {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.4;
}
.toast .toast-close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: var(--r-sm);
  box-shadow: none;
  min-height: auto;
  transition: background-color var(--dur-2) var(--ease), color var(--dur-2) var(--ease);
}
.toast .toast-close:hover {
  background: var(--surface-3);
  color: var(--text);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px) scale(0.96); }
  to   { opacity: 1; transform: translateX(0)    scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}

@media (max-width: 640px) {
  #toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
  .toast {
    min-width: 0;
    max-width: none;
    width: 100%;
  }
}

/* Respect users who prefer reduced motion — disable all non-essential
   animations and transitions. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  #scan-input:focus { animation: none; }
  .low-stock-badge { animation: none; }
  .item-description-cell,
  dialog form textarea[name="description"] { animation: none !important; }
}

/* ---- Neon descriptions ------------------------------------------------- */
/* Bright neon styling for item descriptions, secondary/muted copy, and
   the description textarea in the Add/Edit Item modal. */
.muted,
.category-card-meta,
.scan-hint,
.scan-entry .detail,
.toast .toast-msg,
.login-card .subtitle {
  color: var(--neon-cyan);
  text-shadow:
    0 0 6px rgba(0, 255, 255, 0.55),
    0 0 14px rgba(0, 255, 255, 0.25);
}

/* Item description row under each item name in the table */
tbody td .muted {
  color: var(--neon-magenta);
  font-weight: 500;
  text-shadow:
    0 0 6px rgba(255, 61, 240, 0.6),
    0 0 14px rgba(255, 61, 240, 0.3);
  letter-spacing: 0.01em;
  animation: neon-flicker 4.5s ease-in-out infinite;
}

/* The description field inside the Add/Edit Item modal */
dialog form textarea[name="description"] {
  color: var(--neon-magenta);
  caret-color: var(--neon-magenta);
  background: #0c0f26;
  border-color: rgba(255, 61, 240, 0.55);
  text-shadow:
    0 0 4px rgba(255, 61, 240, 0.55),
    0 0 10px rgba(255, 61, 240, 0.3);
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.5),
    0 0 12px rgba(255, 61, 240, 0.18);
}
dialog form textarea[name="description"]:focus {
  border-color: var(--neon-magenta);
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.5),
    0 0 0 4px rgba(255, 61, 240, 0.22),
    0 0 20px rgba(255, 61, 240, 0.45);
}
dialog form textarea[name="description"]::placeholder {
  color: rgba(255, 61, 240, 0.45);
}

@keyframes neon-flicker {
  0%, 100%   { opacity: 1; }
  47%        { opacity: 1; }
  48%        { opacity: 0.72; }
  49%        { opacity: 1; }
  82%        { opacity: 1; }
  83%        { opacity: 0.65; }
  84%        { opacity: 1; }
}

/* ---- Orders: draft CTA + open orders cross-reference ------------------- */
#draft-order-section {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  margin: 0 0 22px;
  background: linear-gradient(135deg, rgba(0, 224, 255, 0.08), rgba(255, 61, 240, 0.06));
  border: 1px solid rgba(0, 224, 255, 0.4);
  border-radius: var(--r-md);
  box-shadow: 0 0 24px -4px rgba(0, 224, 255, 0.25);
  animation: draft-pulse 3.2s var(--ease) infinite;
}

.draft-banner-label {
  flex: 1;
  font-weight: 600;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.4);
  letter-spacing: 0.01em;
}
#place-order-btn {
  font-size: 15px;
  font-weight: 700;
  padding: 12px 20px;
  letter-spacing: 0.01em;
}
.draft-count-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  margin-left: 4px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
@keyframes draft-pulse {
  0%, 100% { box-shadow: 0 0 24px -4px rgba(0, 224, 255, 0.25); }
  50%      { box-shadow: 0 0 36px -2px rgba(0, 224, 255, 0.45), 0 0 24px -8px rgba(255, 61, 240, 0.3); }
}

/* Home-toolbar Place Order button. Subtle when no draft (just a way to
   navigate to the Open Orders sub-view). When a draft is awaiting Accept/
   Decline the button gains a magenta count pill, a glowing border, and a
   slow pulsing aura so the user can't miss it. */
#place-order-home-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#place-order-home-btn .draft-count-pill {
  background: linear-gradient(135deg, var(--neon-magenta), #ff10a0);
  color: #fff;
  text-shadow: 0 0 6px rgba(255, 61, 240, 0.6);
  box-shadow: 0 0 12px rgba(255, 61, 240, 0.45);
}
#place-order-home-btn.has-draft {
  border-color: var(--neon-magenta);
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 61, 240, 0.18), rgba(255, 61, 240, 0.08));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05) inset,
    0 0 18px -2px rgba(255, 61, 240, 0.4);
  animation: home-place-pulse 2.4s ease-in-out infinite;
}
#place-order-home-btn.has-draft:hover {
  border-color: var(--neon-magenta);
  background: linear-gradient(180deg, rgba(255, 61, 240, 0.28), rgba(255, 61, 240, 0.14));
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05) inset,
    0 0 26px -2px rgba(255, 61, 240, 0.6);
}
@keyframes home-place-pulse {
  0%, 100% { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 0 18px -2px rgba(255, 61, 240, 0.4); }
  50%      { box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 0 28px -2px rgba(255, 61, 240, 0.65); }
}

#open-orders-section {
  margin: 0 0 28px;
}
.open-orders-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 12px;
}
.open-orders-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 8px;
  background: var(--surface-3);
  color: var(--neon-cyan);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 0 6px rgba(0, 255, 255, 0.45);
}

.open-order-supplier-group {
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.open-order-supplier {
  margin: 0;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--neon-cyan);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  text-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
}
.open-order-lines {
  list-style: none;
  margin: 0;
  padding: 0;
}
.open-order-line {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  transition: background-color var(--dur-2) var(--ease);
}
.open-order-line:last-child { border-bottom: none; }
.open-order-line:hover { background: var(--surface-2); }
.open-order-info { flex: 1; min-width: 0; }
.open-order-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  margin-bottom: 4px;
}
.open-order-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.open-order-qtys {
  font-size: 13px;
  color: var(--neon-magenta);
  text-shadow: 0 0 6px rgba(255, 61, 240, 0.35);
  font-variant-numeric: tabular-nums;
}
.open-order-qtys b { font-weight: 700; }
.open-order-outstanding {
  margin-left: 8px;
  color: var(--text-muted);
  text-shadow: none;
  font-size: 12px;
}

.open-order-receive {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.receive-input {
  width: 76px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-2) var(--ease),
              box-shadow var(--dur-2) var(--ease);
}
.receive-input:focus {
  outline: none;
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(57, 255, 20, 0.22), 0 0 16px rgba(57, 255, 20, 0.25);
}
.receive-btn {
  background: linear-gradient(180deg, #4ade80, var(--success));
  border-color: #2ec40a;
  color: #07140a;
  font-weight: 700;
  text-shadow: none;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.2) inset,
    0 0 16px rgba(57, 255, 20, 0.3);
}
.receive-btn:hover {
  background: linear-gradient(180deg, var(--success), #2ec40a);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.2) inset,
    0 0 24px rgba(57, 255, 20, 0.55);
  transform: translateY(-1px);
}
.receive-btn:active { transform: translateY(0); }
.receive-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Place Order modal — wider table to fit item/supplier/cost columns */
#place-order-modal { max-width: 720px; }
.place-order-wrap { display: flex; flex-direction: column; gap: 12px; }
.place-order-table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: auto;
  max-height: 50vh;
}
#place-order-table { width: 100%; border-collapse: collapse; }
#place-order-table th,
#place-order-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
#place-order-table th {
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
#place-order-table tfoot td {
  background: var(--surface-2);
  border-top: 1px solid var(--border-strong);
  border-bottom: none;
  font-size: 14px;
}

/* Supplier-facing notes on the Place Order modal. Shipping, tax, and
   expected delivery are intentionally NOT here — those are filled in on
   the PO detail view once the supplier replies with a quote. */
.place-order-meta { padding-top: 4px; }
.place-order-meta label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.place-order-meta textarea {
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 7px 10px;
  font-family: inherit;
  resize: vertical;
  min-height: 52px;
}

/* Mobile tweaks */
@media (max-width: 640px) {
  .open-order-line {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .open-order-receive { justify-content: flex-end; }
  #draft-order-section { padding: 12px 14px; }
  #place-order-btn { flex: 1 1 100%; }
}

/* PO-number link inside the Open Orders sub-view. Inherits the meta row's
   muted tone but gains an underline on hover so users notice it's clickable. */
.open-order-po-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dashed var(--border-strong);
}
.open-order-po-link:hover { color: var(--text); border-bottom-color: var(--text); }

/* Status pills on the All-POs list. Green for completed, amber for partial,
   neutral for pending, dim for cancelled. Reused by the PO detail header. */
.status-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface-2);
}
.status-pill.status-completed { color: var(--success); border-color: var(--success); background: var(--success-soft); }
.status-pill.status-partial   { color: var(--warn);    border-color: var(--warn);    background: var(--warn-soft); }
.status-pill.status-pending   { color: var(--text-muted); }
.status-pill.status-cancelled { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }

/* PO list row: clickable, shows a subtle hover so users know it's a link. */
.orders-row { cursor: pointer; }
.orders-row:hover { background: var(--surface-2); }
.orders-row td .muted { font-size: 11px; }

/* PO detail page layout. Header block up top, metadata edit form below
   it, lines table at the bottom with a totals footer. */
.po-detail { display: flex; flex-direction: column; gap: 18px; padding: 14px 0; }
.po-detail-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 14px;
}
.po-detail-header h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.01em;
}
.po-detail-header .muted { font-size: 13px; }
.po-detail-header #po-cancel-btn { margin-left: auto; }

.po-cancelled-banner {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--r-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.po-cancelled-banner strong { font-size: 14px; }
.po-cancelled-banner .muted { font-size: 12px; color: var(--danger); opacity: 0.8; }
.po-cancelled-banner p { margin: 0; font-size: 13px; color: var(--text); }

.po-meta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.po-meta-card h3 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.po-meta-card .row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.po-meta-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.po-meta-card input,
.po-meta-card textarea {
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 7px 10px;
  font-family: inherit;
}
.po-meta-card textarea { resize: vertical; min-height: 56px; }
.po-meta-card .actions { justify-content: flex-end; }

/* Attachments card. Same surface/border/radius as the meta card so the PO
   detail page reads as a stack of equal-weight sections. Dropzone gets a
   dashed border and a highlight state on drag-over; the list below it
   shows one row per uploaded file. */
.po-attachments-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.po-attachments-card h3 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.po-attach-dropzone {
  position: relative;
  border: 1.5px dashed var(--border-strong, var(--border));
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 18px 16px;
  transition: background 120ms ease, border-color 120ms ease;
}
.po-attach-dropzone.is-dragging {
  border-color: var(--accent, #3b82f6);
  background: var(--accent-soft, rgba(59, 130, 246, 0.08));
}
.po-attach-dropzone__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.po-attach-dropzone__icon { color: var(--text-muted); }
.po-attach-dropzone__title {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}
.po-attach-dropzone__sub { margin: 0; font-size: 12px; }
.po-attach-browse {
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent, #3b82f6);
  cursor: pointer;
  text-decoration: underline;
}
.po-attach-browse:hover { text-decoration: none; }
.po-attach-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.po-attach-progress__bar {
  height: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.po-attach-progress__fill {
  height: 100%;
  width: 0%;
  background: var(--accent, #3b82f6);
  transition: width 120ms ease;
}
.po-attach-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.po-attach-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.po-attach-item__icon {
  flex: 0 0 auto;
  color: var(--text-muted);
  display: inline-flex;
}
.po-attach-item__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.po-attach-item__name {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}
.po-attach-item__name:hover { text-decoration: underline; }
.po-attach-item__meta {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.po-attach-item__actions {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
}

/* Receive-history expand toggle and inline sub-table. The sub-row spans the
   full line table via colspan so the timeline reads next to its parent line
   without needing a separate section. */
.po-history-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--r-sm, 4px);
  cursor: pointer;
}
.po-history-toggle:hover { border-color: var(--border-strong); color: var(--text); }
.po-history-row > td {
  background: var(--surface-2);
  padding: 8px 12px;
}
.po-history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.po-history-table th,
.po-history-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.po-history-table thead th {
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  color: var(--text-muted);
}
.po-history-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Per-line status badges: over-receive, damaged total, short-closed. */
.line-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: middle;
  border: 1px solid transparent;
}
.line-badge.badge-over    { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.line-badge.badge-damaged { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.line-badge.badge-short   { color: var(--text-muted); border-color: var(--border); background: var(--surface-2); }
.damaged-pill {
  color: var(--danger);
  font-weight: 600;
}
.line-short-note {
  font-size: 11px;
  margin-top: 2px;
}
.btn-small {
  font-size: 11px;
  padding: 2px 8px;
}

/* Open-order receive row: two compact labelled inputs + Receive button. */
.open-order-receive-field {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.open-order-receive-field input { width: 64px; }

/* PO totals summary. Right-aligned card so the label and value sit close
   together instead of stretching the full table width with a dead gap in
   the middle. Grand total is separated by a top border and picks up the
   primary accent for emphasis. */
.po-totals {
  display: grid;
  grid-template-columns: auto auto;
  justify-content: space-between;
  column-gap: 40px;
  row-gap: 10px;
  align-items: baseline;
  font-size: 14px;
  margin: 18px 0 0 auto;
  max-width: 380px;
  padding: 18px 22px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.po-totals .po-total-label {
  color: var(--text-secondary);
  font-size: 13px;
  letter-spacing: 0.01em;
}
.po-totals .po-total-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 500;
}
.po-totals .po-total-grand {
  font-weight: 700;
  font-size: 18px;
  padding-top: 12px;
  margin-top: 4px;
  border-top: 1px solid var(--border-strong);
  letter-spacing: 0.01em;
}
.po-totals .po-total-value.po-total-grand {
  color: var(--primary);
  font-size: 22px;
  text-shadow: 0 0 24px var(--primary-soft);
}
.po-totals .po-total-label.po-total-grand {
  color: var(--text);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.08em;
  align-self: center;
}

@media (max-width: 640px) {
  .po-totals {
    max-width: none;
    margin-left: 0;
  }
  .po-meta-card .row { grid-template-columns: 1fr; }
}

/* ---- What's New drawer ------------------------------------------------- */

.changelog-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.changelog-btn-icon {
  color: var(--primary);
  font-size: 14px;
  line-height: 1;
  text-shadow: 0 0 6px var(--primary-ring);
}
.changelog-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 2px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 0 0 2px var(--bg), 0 0 10px rgba(255, 45, 111, 0.55);
}

.changelog-panel {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}
.changelog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 23, 0.55);
  opacity: 0;
  transition: opacity var(--dur-3) var(--ease);
  pointer-events: none;
  backdrop-filter: blur(2px);
}
.changelog-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--dur-3) var(--ease);
  pointer-events: auto;
}
.changelog-panel.is-open { pointer-events: auto; }
.changelog-panel.is-open .changelog-backdrop { opacity: 1; pointer-events: auto; }
.changelog-panel.is-open .changelog-drawer { transform: translateX(0); }

.changelog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.changelog-header h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}
.changelog-counter {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}
.changelog-close {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur-1), color var(--dur-1), border-color var(--dur-1);
}
.changelog-close:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--border);
}

.changelog-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px 20px;
  scrollbar-width: thin;
}
.changelog-body::-webkit-scrollbar { width: 8px; }
.changelog-body::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: 4px;
}
.changelog-empty {
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 0;
  text-align: center;
}

.changelog-month + .changelog-month { margin-top: 20px; }
.changelog-month-heading {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 6px 0 10px;
  text-transform: uppercase;
}

.changelog-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.changelog-entry {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 15px 13px;
  transition: border-color var(--dur-1), background var(--dur-1);
}
.changelog-entry.is-unread {
  border-color: var(--primary-ring);
  background: linear-gradient(180deg, rgba(0, 224, 255, 0.04), var(--surface-2));
}
.changelog-entry-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.changelog-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--primary-ring);
}
.changelog-date {
  color: var(--text-muted);
  font-size: 12px;
}
.changelog-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary-ring);
  margin-left: auto;
}
.changelog-entry-title {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.changelog-entry-body {
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.55;
}
.changelog-entry-body strong {
  color: var(--text);
  font-weight: 600;
}

.changelog-footer {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}
.changelog-caught-up {
  min-width: 160px;
}

body.changelog-open { overflow: hidden; }

/* ---- Role-based UI visibility ----------------------------------------- */
/* .requires-admin    — visible only to the admin role (per-tenant top tier).
   .requires-writer   — hidden for the read-only `staff` role.
   .requires-operator — visible only to the master admin (is_operator flag). */
body:not(.role-admin) .requires-admin { display: none !important; }
body.role-staff .requires-writer { display: none !important; }
body:not(.is-operator) .requires-operator { display: none !important; }

/* ---- Master-admin impersonation banner -------------------------------- */
.impersonation-banner {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 18px;
  background: linear-gradient(90deg, #ffd24a, #ff8a00);
  color: #1a1200;
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: 0.01em;
  box-shadow: 0 2px 12px rgba(255, 138, 0, 0.35);
}
.impersonation-banner-icon { font-size: 16px; }
.impersonation-banner-text strong { font-weight: 700; }
.impersonation-banner-exit {
  margin-left: 8px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #1a1200;
  background: rgba(255, 255, 255, 0.25);
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  cursor: pointer;
}
.impersonation-banner-exit:hover { background: rgba(255, 255, 255, 0.4); }
.impersonation-banner-exit:disabled { opacity: 0.6; cursor: progress; }

/* ---- Users admin page -------------------------------------------------- */

.role-select {
  min-width: 110px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.user-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.user-status.active {
  background: var(--success-soft);
  color: var(--success);
  border-color: rgba(57, 255, 20, 0.35);
}
.user-status.inactive {
  background: var(--surface-3);
  color: var(--text-muted);
  border-color: var(--border);
}
tr.row-inactive td { opacity: 0.6; }
tr.row-inactive td:last-child { opacity: 1; } /* keep action buttons readable */
.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---- Activity feed ---------------------------------------------------- */

.activity-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
}
.activity-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.activity-chip {
  appearance: none;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-1), color var(--dur-1), border-color var(--dur-1);
}
.activity-chip:hover { color: var(--text); border-color: var(--border-strong); }
.activity-chip.is-active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary-ring);
}
.activity-user-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.activity-user-filter input {
  min-width: 160px;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.activity-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.activity-day { }
.activity-day-heading {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  font-weight: 600;
  margin: 0 0 10px;
  text-transform: uppercase;
}
.activity-day-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-left: 1px solid var(--border);
  padding-left: 14px;
}
.activity-item {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  transition: background var(--dur-1);
  position: relative;
}
.activity-item:hover { background: var(--surface-2); }
.activity-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
}
.activity-type-stock_change .activity-icon { color: var(--warn); background: var(--warn-soft); }
.activity-type-receive      .activity-icon { color: var(--success); background: var(--success-soft); }
.activity-type-po_placed    .activity-icon { color: var(--primary); background: var(--primary-soft); }
.activity-type-po_completed .activity-icon { color: var(--success); background: var(--success-soft); }
.activity-type-po_cancelled .activity-icon { color: var(--danger); background: var(--danger-soft); }

.activity-body {
  min-width: 0;
}
.activity-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 2px;
}
.activity-actor {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.activity-actor.muted { color: var(--text-muted); font-weight: 500; }
.activity-time {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.activity-text {
  font-size: 14px;
  color: var(--text-secondary);
}
.activity-text a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px dotted var(--primary-ring);
}
.activity-text a:hover { border-bottom-style: solid; }
.activity-text b { color: var(--text); font-weight: 600; }

.activity-more-wrap {
  margin-top: 24px;
  display: flex;
  justify-content: center;
}

@media (max-width: 640px) {
  .activity-toolbar { flex-direction: column; align-items: stretch; }
  .activity-user-filter input { width: 100%; }
}

/* ---- Settings page ---------------------------------------------------- */

.settings-wrap {
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.settings-card {
  width: min(680px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 28px 30px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.settings-card h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
}
.settings-card .row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.settings-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
.settings-card input,
.settings-card textarea {
  padding: 9px 12px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.settings-card input:focus,
.settings-card textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-ring);
}
.settings-card .actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
@media (max-width: 640px) {
  .settings-card .row { grid-template-columns: 1fr; }
  .settings-wrap { padding: 18px 12px; }
}

/* ---- Data import (Settings page) -------------------------------------- */

.import-block {
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.import-block + .import-block { margin-top: 4px; }
.import-block h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.import-block-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.import-block-header > div { flex: 1 1 auto; min-width: 0; }
.import-block-header > div p { margin: 4px 0 0; font-size: 12.5px; line-height: 1.5; }

.import-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.import-actions input[type="file"] {
  flex: 1 1 240px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
}
.import-actions input[type="file"]::file-selector-button {
  margin-right: 10px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.import-result {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.import-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.import-summary-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.import-summary-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.import-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
}
.import-pill b { color: var(--text); font-size: 13.5px; }
.import-pill-new    { border-color: rgba(34, 197, 94, 0.45); background: rgba(34, 197, 94, 0.08); }
.import-pill-new b  { color: #86efac; }
.import-pill-update { border-color: rgba(56, 189, 248, 0.45); background: rgba(56, 189, 248, 0.08); }
.import-pill-update b { color: #7dd3fc; }
.import-pill-skip   { border-color: rgba(234, 179, 8, 0.45); background: rgba(234, 179, 8, 0.08); }
.import-pill-skip b { color: #fde047; }
.import-pill-error  { border-color: rgba(239, 68, 68, 0.45); background: rgba(239, 68, 68, 0.08); }
.import-pill-error b { color: #fca5a5; }

.import-errors,
.import-preview {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  padding: 8px 12px;
  font-size: 12.5px;
}
.import-errors summary,
.import-preview summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 2px 0;
}
.import-errors ul,
.import-preview ul {
  margin: 8px 0 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
}
.import-errors li { color: #fecaca; }

.import-row-action {
  display: inline-block;
  min-width: 58px;
  text-align: center;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-secondary);
  margin-right: 6px;
}
.import-row-new    { color: #86efac; border-color: rgba(34, 197, 94, 0.4); background: rgba(34, 197, 94, 0.1); }
.import-row-update { color: #7dd3fc; border-color: rgba(56, 189, 248, 0.4); background: rgba(56, 189, 248, 0.1); }
.import-row-skip   { color: #fde047; border-color: rgba(234, 179, 8, 0.4); background: rgba(234, 179, 8, 0.1); }
.import-row-has-error {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(248, 113, 113, 0.12);
}
.import-row-errfields {
  margin-left: 6px;
  font-size: 12px;
  color: #fca5a5;
}
.import-error-truncation { font-style: italic; }

/* Column mapping UI — shown between file pick and preview. Each row:
   source column name → target <select>. Ignored columns and missing
   required name get a muted/red affordance. */
.import-mapping {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}
.import-mapping-heading {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.import-mapping-table {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.import-mapping-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface-1);
  border: 1px solid transparent;
}
.import-mapping-source {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.import-mapping-arrow {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}
.import-mapping-row select.import-mapping-target {
  width: 100%;
  min-width: 0;
  padding: 4px 8px;
  font-size: 13px;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.import-mapping-row.import-mapping-unset {
  opacity: 0.7;
}
.import-mapping-row.import-mapping-unset select.import-mapping-target {
  color: var(--text-secondary);
  font-style: italic;
}
.import-mapping.import-mapping-missing-name {
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(248, 113, 113, 0.06);
}

@media (max-width: 640px) {
  .import-block-header { flex-direction: column; align-items: stretch; }
  .import-mapping-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
  .import-mapping-arrow { display: none; }
}

@media (max-width: 640px) {
  .changelog-btn-label { display: none; }
  .changelog-drawer { width: 100vw; }
}

@media (prefers-reduced-motion: reduce) {
  .changelog-backdrop,
  .changelog-drawer { transition: none; }
}

/* ---- Links ------------------------------------------------------------- */
/* Default browser link colour (underlined blue / visited purple) is hard to
   read on the dark surface *and* clashes with the brand palette. Route all
   anchors through the cyan `--primary` token instead, and keep the same
   colour for :visited so history state doesn't mute them into invisibility. */
a,
a:link,
a:visited {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-color: rgba(0, 224, 255, 0.5);
  text-underline-offset: 3px;
  transition: color var(--dur-1) var(--ease),
              text-decoration-color var(--dur-1) var(--ease);
}
a:hover {
  color: var(--primary-hover);
  text-decoration-color: var(--primary-hover);
}
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 3px;
}
/* Buttons styled as anchors should not inherit underline. */
a.btn-primary,
a.btn-ghost,
a.btn-danger { text-decoration: none; }

/* ---- System modal popups (app-modals.js) ------------------------------- */
/* Replaces Chrome-native `alert` / `confirm` / `prompt`. Inherits the
   existing `dialog` shell styles defined earlier in this file, plus a few
   app-modal-specific tweaks so the message body and buttons sit nicely. */
dialog.app-modal {
  max-width: 460px;
}
.app-modal-title {
  margin: 0 0 14px 0;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.app-modal-title-danger {
  color: var(--danger-hover);
}
.app-modal-message {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.55;
  margin-bottom: 18px;
  white-space: pre-wrap;
  max-height: 50vh;
  overflow-y: auto;
}
.app-modal-form input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  margin-bottom: 14px;
  outline: none;
  transition: border-color var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease);
}
.app-modal-form input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.app-modal-form .actions,
.app-modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0;
}

/* ==========================================================================
   Bug-report feature: floating pill (all pages) + triage card (settings).
   ========================================================================== */

#bug-report-fab {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  cursor: pointer;
  transition: transform var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease),
              background var(--dur-1) var(--ease);
}
#bug-report-fab:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  background: var(--surface-3, var(--surface-2));
}
#bug-report-fab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-ring), 0 6px 20px rgba(0, 0, 0, 0.22);
}
#bug-report-fab .bug-fab-icon {
  font-size: 16px;
  line-height: 1;
}
@media (max-width: 720px) {
  #bug-report-fab .bug-fab-label { display: none; }
  #bug-report-fab {
    padding: 12px;
    width: 44px;
    height: 44px;
    justify-content: center;
  }
}

/* Bug-report submission modal ------------------------------------------- */
.bug-report-modal .modal-body,
.bug-detail-modal .modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.bug-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.bug-report-modal label,
.bug-detail-modal label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
.bug-report-modal label input,
.bug-report-modal label select,
.bug-report-modal label textarea,
.bug-detail-modal label input,
.bug-detail-modal label select,
.bug-detail-modal label textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  outline: none;
}
.bug-report-modal label input:focus,
.bug-report-modal label select:focus,
.bug-report-modal label textarea:focus,
.bug-detail-modal label input:focus,
.bug-detail-modal label select:focus,
.bug-detail-modal label textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.bug-screenshot-block {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px;
  background: var(--surface-2);
}
.bug-screenshot-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.bug-screenshot-actions { display: inline-flex; gap: 6px; }
.bug-screenshot-preview {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  padding: 6px;
}
.bug-screenshot-preview img {
  max-width: 100%;
  max-height: 260px;
  display: block;
  border-radius: var(--r-sm);
}

/* Triage table on Settings --------------------------------------------- */
.bug-triage-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 6px 0 14px;
}
.bug-triage-filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.bug-triage-filters select,
.bug-triage-filters input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  min-width: 150px;
}
.bug-triage-filters .bug-filter-search { flex: 1 1 220px; }
.bug-triage-filters .bug-filter-search input { width: 100%; }

.bug-triage-table-wrap { overflow-x: auto; }
.bug-triage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.bug-triage-table thead th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--surface);
}
.bug-triage-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.bug-triage-table tbody tr.bug-row { cursor: pointer; }
.bug-triage-table tbody tr.bug-row:hover { background: var(--surface-2); }
.bug-row-title { font-weight: 500; }
.bug-row-shot {
  display: inline-block;
  margin-left: 6px;
  font-size: 12px;
  opacity: 0.75;
}

/* Tag pills used in the triage table ----------------------------------- */
.bug-kind, .bug-pri, .bug-status {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}
.bug-kind-feature_request {
  background: rgba(124, 92, 255, 0.12);
  border-color: rgba(124, 92, 255, 0.35);
}
.bug-pri-critical {
  background: rgba(220, 38, 38, 0.14);
  border-color: rgba(220, 38, 38, 0.4);
  color: #f2c1c1;
}
.bug-pri-high {
  background: rgba(234, 88, 12, 0.14);
  border-color: rgba(234, 88, 12, 0.4);
  color: #f2cfae;
}
.bug-pri-medium { opacity: 0.85; }
.bug-pri-low    { opacity: 0.65; }
.bug-status-resolved {
  background: rgba(22, 163, 74, 0.14);
  border-color: rgba(22, 163, 74, 0.4);
  color: #bce9c6;
}
.bug-status-wont_fix { opacity: 0.55; }
.bug-status-in_progress {
  background: rgba(234, 179, 8, 0.14);
  border-color: rgba(234, 179, 8, 0.4);
  color: #f1e0a7;
}

/* Triage detail modal -------------------------------------------------- */
.bug-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 13px;
}
.bug-detail-page {
  word-break: break-all;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 12px;
  opacity: 0.9;
}
.bug-detail-heading {
  margin: 6px 0 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.bug-detail-description {
  white-space: pre-wrap;
  margin: 0;
}
.bug-detail-screenshot-wrap img {
  max-width: 100%;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  display: block;
}
.bug-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (max-width: 640px) {
  .bug-detail-grid { grid-template-columns: 1fr; }
  .bug-form-grid   { grid-template-columns: 1fr; }
}
.bug-detail-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.bug-detail-footer-right {
  display: inline-flex;
  gap: 10px;
}
