:root {
  color-scheme: light;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #d9d9de;
  --green: #0066cc;
  --green2: #0674df;
  --cream: #f2f4f7;
  --red: #d70015;
  --amber: #a85f00;
  --blue: #0066cc;
  --blue-pressed: #0053a8;
  --surface: rgba(255, 255, 255, .92);
  --surface-solid: #fff;
  --sidebar: rgba(244, 247, 251, .78);
  --shadow-surface: 0 12px 36px rgba(48, 55, 66, .08);
  --shadow-float: 0 24px 70px rgba(24, 31, 42, .2);
}

* {
  scrollbar-color: #b6bbc4 transparent;
  scrollbar-width: thin;
}

::selection {
  background: rgba(0, 122, 255, .22);
  color: var(--ink);
}

html {
  background: #e8edf4;
}

html,
body {
  min-height: 100%;
  background: #eef1f5;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
}

body {
  caret-color: var(--blue);
}

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

button {
  -webkit-tap-highlight-color: transparent;
}

button:active {
  transform: scale(.97);
  transition: transform 90ms ease-out;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(0, 122, 255, .38) !important;
  outline-offset: 2px;
}

.login-screen {
  min-height: 100vh;
  padding: 24px;
  background: #e8edf4;
}

.login-card {
  width: min(420px, 100%);
  gap: 22px;
  padding: 34px;
  border: 0;
  border-radius: 22px;
  background: rgba(255, 255, 255, .82);
  box-shadow: var(--shadow-float);
  backdrop-filter: blur(28px) saturate(150%);
  -webkit-backdrop-filter: blur(28px) saturate(150%);
}

.login-brand {
  gap: 12px;
}

.login-brand span,
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font: 700 20px/1 -apple-system, BlinkMacSystemFont, sans-serif;
  box-shadow: 0 8px 20px rgba(0, 122, 255, .22);
}

.brand-icon {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-card h1 {
  margin: 0 0 8px;
  font: 700 32px/1.08 -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: -.025em;
}

.login-card p {
  color: var(--muted);
  line-height: 1.45;
}

.login-card label,
.field {
  min-width: 0;
  max-width: 100%;
  gap: 7px;
  color: #4c4c50;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

/* Keep native iOS date controls inside their grid column without disabling the picker. */
.field input[type="date"],
.field input[type="month"] {
  display: block;
  inline-size: 100%;
  min-inline-size: 0;
  max-inline-size: 100%;
  overflow: hidden;
}

.field input[type="date"]::-webkit-date-and-time-value,
.field input[type="month"]::-webkit-date-and-time-value {
  inline-size: 100%;
  min-inline-size: 0;
  margin: 0;
  text-align: left;
}

.field input[type="date"]::-webkit-datetime-edit,
.field input[type="month"]::-webkit-datetime-edit {
  display: block;
  min-inline-size: 0;
  padding: 0;
  overflow: hidden;
}

/* iOS keeps an intrinsic width for native date controls until their outer appearance is reset. */
@supports (-webkit-touch-callout: none) {
  .field input[type="date"],
  .field input[type="month"] {
    box-sizing: border-box !important;
    width: -webkit-fill-available !important;
    inline-size: -webkit-fill-available !important;
    min-width: 0 !important;
    min-inline-size: 0 !important;
    max-width: 100% !important;
    max-inline-size: 100% !important;
    justify-self: stretch;
    -webkit-appearance: none;
    appearance: none;
  }
}

.login-card input,
.field input,
.field select,
.field textarea,
.search,
.inline-form input,
.rename-form input,
.category-row input,
.purchase-row .purchase-qty,
.inline-min input {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #d2d5da;
  border-radius: 10px;
  background: rgba(255, 255, 255, .94);
  color: var(--ink);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, .025);
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.login-card input:hover,
.field input:hover,
.field select:hover,
.field textarea:hover,
.search:hover {
  border-color: #b8bcc3;
}

.login-card input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus,
.search:focus,
.rename-form input:focus,
.category-row input:focus {
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, .12);
}

input::placeholder,
textarea::placeholder {
  color: #86868b;
  opacity: 1;
}

.form-error {
  min-height: 18px;
  color: var(--red) !important;
  font-size: 13px;
}

.app-shell {
  min-height: 100vh;
  grid-template-columns: 248px minmax(0, 1fr);
  background: #eef1f5;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 100vh;
  padding: 22px 16px 18px;
  overflow: hidden;
  background: var(--sidebar);
  color: var(--ink);
  border-right: 1px solid rgba(112, 118, 130, .15);
  backdrop-filter: blur(30px) saturate(160%);
  -webkit-backdrop-filter: blur(30px) saturate(160%);
}

.brand {
  gap: 12px;
  padding: 4px 8px 26px;
  color: var(--ink);
}

.brand > span:last-child {
  display: grid;
  gap: 2px;
}

.brand strong {
  font-size: 15px;
  letter-spacing: -.01em;
}

.brand small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.sidebar nav {
  gap: 4px;
}

.nav-item {
  min-height: 42px;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 10px;
  color: #4e535b;
  font-size: 14px;
  font-weight: 500;
  transition: color 160ms ease, background 160ms ease, transform 90ms ease-out;
}

.nav-item:hover {
  background: rgba(0, 0, 0, .045);
  color: var(--ink);
}

.nav-item.active {
  color: var(--blue);
  background: rgba(0, 122, 255, .11);
}

.nav-item b {
  display: grid;
  width: 20px;
  place-items: center;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item:first-child svg rect {
  fill: currentColor;
  stroke: none;
}

.sidebar-note {
  gap: 5px;
  padding: 14px;
  border: 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, .62);
  box-shadow: 0 6px 20px rgba(45, 52, 64, .06);
}

.sidebar-note strong {
  color: var(--ink);
  font-size: 12px;
}

.sidebar-note span {
  color: var(--muted);
  font-size: 11px;
}

.sidebar-note button {
  min-height: 30px;
  margin-top: 4px;
  padding: 0;
  color: var(--blue);
  font-weight: 600;
}

.workspace {
  padding: 34px clamp(24px, 3.3vw, 54px) 64px;
}

.topbar {
  align-items: flex-end;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.install-app {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--blue);
  white-space: nowrap;
}

.install-app svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.topbar h1 {
  margin: 0;
  font: 700 clamp(32px, 3.2vw, 42px)/1.04 -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: -.035em;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.primary,
.secondary {
  min-height: 42px;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 650;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 90ms ease-out;
}

.primary {
  border: 0;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 7px 18px rgba(0, 122, 255, .18);
}

.primary:hover {
  background: var(--blue-pressed);
}

.primary:disabled,
.secondary:disabled {
  opacity: .58;
  cursor: progress;
  box-shadow: none;
  transform: none;
}

.secondary {
  border: 1px solid #d2d5da;
  background: rgba(255, 255, 255, .84);
  color: var(--blue);
}

.secondary:hover {
  background: #fff;
}

.filters {
  gap: 10px;
  margin: 26px 0 14px;
  padding: 10px;
  width: max-content;
  max-width: 100%;
  border-radius: 14px;
  background: rgba(255, 255, 255, .72);
  box-shadow: 0 7px 24px rgba(45, 52, 64, .06);
}

.filters .field {
  min-width: 188px;
}

.kpi-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-surface);
}

.kpi {
  min-height: 132px;
  gap: 8px;
  padding: 22px 24px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.kpi + .kpi {
  border-left: 1px solid #e5e5ea;
}

.kpi.warning {
  border-color: #e5e5ea;
  background: rgba(255, 149, 0, .055);
}

.kpi span,
.kpi small {
  color: var(--muted);
  font-size: 12px;
}

.kpi strong {
  font: 650 34px/1 -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: -.025em;
}

.kpi.warning strong {
  color: var(--amber);
}

.content-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  gap: 16px;
}

.panel,
.warehouse-card {
  margin-top: 16px;
  padding: 22px;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-surface);
}

.panel-head {
  align-items: center;
  gap: 20px;
}

.panel h2 {
  color: var(--ink);
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: -.012em;
}

.panel p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.bars {
  position: relative;
  height: 222px;
  padding: 34px 12px 0;
  border-bottom-color: #e5e5ea;
}

.bar-wrap {
  color: var(--muted);
}

.bar-wrap em {
  color: var(--ink);
}

.bar {
  width: min(34px, 46%);
  min-height: 0;
  border-radius: 7px 7px 3px 3px;
  background: var(--blue);
  box-shadow: 0 5px 12px rgba(0, 122, 255, .14);
  transform-origin: bottom;
  animation: bar-rise 440ms cubic-bezier(.16, 1, .3, 1) both;
}

.bar.zero {
  box-shadow: none;
}

@keyframes bar-rise {
  from { transform: scaleY(.12); opacity: .65; }
  to { transform: scaleY(1); opacity: 1; }
}

.activity {
  margin-top: 12px;
}

.activity-row {
  grid-template-columns: 9px 1fr auto;
  padding: 13px 2px;
  border-top-color: #e5e5ea;
}

.dot {
  background: var(--blue);
  box-shadow: 0 0 0 4px rgba(0, 122, 255, .1);
}

.data-scroll {
  margin-top: 14px;
  border-radius: 10px;
}

.data-row,
.purchase-row,
.catalog-row {
  border-top-color: #e5e5ea;
}

.data-row {
  padding: 12px 8px;
  color: #3b3b3f;
}

.data-row.head,
.purchase-row.head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.stock-sort-button {
  display: inline-flex;
  min-width: 0;
  min-height: 34px;
  align-items: center;
  gap: 5px;
  padding: 5px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.stock-sort-button:hover {
  background: rgba(0, 122, 255, .07);
  color: var(--blue);
}

.stock-sort-button:focus-visible {
  outline: 3px solid rgba(0, 122, 255, .38);
  outline-offset: 1px;
}

.stock-sort-button.active {
  color: var(--blue);
}

.stock-sort-button svg {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .62;
}

.stock-sort-button.active svg {
  opacity: 1;
}

.stock-table .data-row {
  min-width: 0;
}

.stock-column-picker {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
}

.stock-column-picker summary {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid #d2d5da;
  border-radius: 10px;
  background: rgba(255, 255, 255, .9);
  color: var(--blue);
  font-size: 12px;
  font-weight: 650;
  list-style: none;
  cursor: pointer;
}

.stock-column-picker summary::-webkit-details-marker {
  display: none;
}

.stock-column-picker summary::after {
  width: 6px;
  height: 6px;
  margin-inline-start: 2px;
  border-right: 1.7px solid currentColor;
  border-bottom: 1.7px solid currentColor;
  content: '';
  transform: rotate(45deg) translateY(-2px);
  transition: transform 160ms ease;
}

.stock-column-picker[open] summary::after {
  transform: rotate(225deg) translate(-1px, -1px);
}

.stock-column-picker summary span {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stock-column-picker summary:focus-visible {
  outline: 3px solid rgba(0, 122, 255, .38);
  outline-offset: 2px;
}

.stock-column-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  width: 248px;
  padding: 8px;
  border: 1px solid rgba(112, 118, 130, .18);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(30, 35, 44, .2);
}

.stock-column-menu label {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
}

.stock-column-menu label:hover {
  background: rgba(0, 122, 255, .065);
}

.stock-column-menu input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--blue);
}

@media (max-width: 760px) {
  .stock-sort-button {
    min-height: 44px;
  }

  .stock-column-picker summary {
    min-height: 44px;
  }

  .stock-column-menu {
    width: min(248px, calc(100vw - 64px));
  }
}

/* One sorting language for every operational table. */
.table-sort-button {
  display: inline-flex;
  width: 100%;
  min-width: 0;
  min-height: 34px;
  align-items: center;
  gap: 5px;
  padding: 5px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.table-sort-button:hover {
  background: rgba(0, 122, 255, .07);
  color: var(--blue);
}

.table-sort-button:focus-visible {
  outline: 3px solid rgba(0, 122, 255, .38);
  outline-offset: 1px;
}

.table-sort-button.active {
  color: var(--blue);
}

.table-sort-button svg {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .62;
}

.table-sort-button.active svg {
  opacity: 1;
}

.sortable-head > [role="columnheader"] {
  min-width: 0;
}

.catalog-row.head,
.inventory-row.head,
.inventory-results-head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.catalog-table {
  margin-top: 14px;
}

@media (max-width: 760px) {
  .shortage-row.head.sortable-head,
  .workshop-matrix-row.head.sortable-head,
  .purchase-row.head.sortable-head,
  .inventory-row.head.sortable-head,
  .catalog-row.head.sortable-head,
  .inventory-results-head.sortable-head {
    display: flex;
    width: 100%;
    min-width: 0;
    gap: 8px;
    padding: 8px 0 12px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .sortable-head::-webkit-scrollbar {
    display: none;
  }

  .sortable-head > [role="columnheader"] {
    position: static;
    flex: none;
    background: transparent;
  }

  .sortable-head .table-sort-button {
    width: auto;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, .94);
    white-space: nowrap;
  }

  .sortable-head .table-sort-button.active {
    border-color: rgba(0, 102, 204, .32);
    background: rgba(0, 122, 255, .1);
  }

  .inventory-results-head.sortable-head {
    position: sticky;
    top: -10px;
  }
}

.data-row strong small {
  color: var(--muted);
}

.data-row:not(.head):hover,
.purchase-row:not(.head):hover,
.catalog-row:hover {
  background: rgba(0, 122, 255, .035);
}

.data-row:not(.head):focus-within,
.purchase-row:not(.head):focus-within,
.catalog-row:focus-within {
  background: rgba(0, 122, 255, .035);
}

.shortage-row.is-low,
.purchase-row.is-low {
  margin-inline: 0;
  padding-inline: 8px;
  border-left: 0;
  background: rgba(255, 149, 0, .055);
}

.shortage-row.is-low > strong:last-child,
.deficit {
  color: var(--red);
}

.status {
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 600;
}

.status.ok {
  color: #16713b;
  background: #e7f7ed;
}

.status.mid {
  color: #7c5800;
  background: #fff3c4;
}

.status.low {
  color: #a34100;
  background: #ffead8;
}

.doc-layout {
  gap: 18px;
}

.doc-header {
  gap: 12px;
}

.line-row {
  grid-template-columns: minmax(240px, 1fr) 120px auto;
  gap: 10px;
  padding: 12px 0;
  border-top-color: #e5e5ea;
}

.line-row .remove-line {
  min-height: 40px;
  padding: 8px 2px;
  color: var(--red);
  font-size: 12px;
  font-weight: 600;
}

.add-line-row {
  display: flex;
  justify-content: flex-start;
  margin-top: 12px;
}

.summary-label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}

.summary-number {
  margin: 14px 0;
  font: 650 28px/1.1 -apple-system, BlinkMacSystemFont, sans-serif;
  letter-spacing: -.02em;
}

.summary-list {
  border-color: #e5e5ea;
}

.summary-list b:has(small) {
  display: grid;
  gap: 3px;
}

.summary-list b small {
  color: var(--muted);
  font-weight: 500;
}

.doc-header.transfer-header {
  grid-template-columns: minmax(120px, .7fr) repeat(4, minmax(150px, 1fr));
}

.route-label {
  margin: 0 0 4px !important;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
}

.document-list {
  gap: 8px;
}

.document-card {
  padding: 15px 16px;
  border: 0;
  border-radius: 12px;
  background: #f7f8fa;
  transition: background 160ms ease;
}

.document-card:hover {
  background: #f1f3f6;
}

.draft-card {
  background: rgba(0, 122, 255, .055);
  box-shadow: inset 0 0 0 1px rgba(0, 122, 255, .14);
}

.draft-card:hover {
  background: rgba(0, 122, 255, .08);
}

.server-draft {
  background: rgba(255, 149, 0, .055);
  box-shadow: inset 0 0 0 1px rgba(168, 95, 0, .14);
}

.server-draft:hover {
  background: rgba(255, 149, 0, .08);
}

.server-draft .draft-badge {
  background: #fff3c4;
  color: #7c5800;
}

.server-draft-note {
  margin: 10px 0 0 !important;
  color: #7c5800 !important;
  font-weight: 600;
}

.draft-title,
.draft-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.draft-title {
  flex-wrap: wrap;
}

.draft-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.draft-badge {
  padding: 4px 7px;
  border-radius: 999px;
  background: rgba(0, 122, 255, .11);
  color: var(--blue);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
  line-height: 1;
}

.document-lines {
  border-top-color: #dedee3;
}

.document-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  flex-wrap: wrap;
}

.document-submit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-submit-actions {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.summary-submit-actions .summary-submit {
  margin-top: 0;
}

.document-history {
  display: none;
  gap: 8px;
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px solid #dedee3;
}

.document-card.history-open .document-history {
  display: grid;
}

.history-heading,
.history-entry summary,
.history-meta {
  display: flex;
  align-items: center;
}

.history-heading {
  justify-content: space-between;
  color: var(--ink);
  font-size: 13px;
}

.history-heading span {
  min-width: 25px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .06);
  color: var(--muted);
  text-align: center;
}

.history-entry {
  overflow: hidden;
  border: 1px solid #dedee3;
  border-radius: 10px;
  background: rgba(255, 255, 255, .7);
}

.history-entry summary {
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}

.history-entry summary small {
  color: var(--muted);
  font-weight: 500;
}

.history-meta {
  gap: 12px;
  padding: 9px 12px;
  border-top: 1px solid #e9e9ed;
  color: var(--muted);
  font-size: 12px;
  flex-wrap: wrap;
}

.history-lines {
  padding: 0 12px 8px;
}

.history-lines .document-line {
  padding-block: 8px;
}

.inventory-history-line {
  display: grid;
  grid-template-columns: minmax(180px, 1.5fr) repeat(3, minmax(80px, .7fr));
  gap: 12px;
  align-items: center;
  min-width: 0;
  padding-block: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.inventory-history-line:last-child {
  border-bottom: 0;
}

.inventory-history-line > * {
  min-width: 0;
  overflow-wrap: anywhere;
}

.inventory-history-line > b {
  text-align: right;
}

@media (max-width: 760px) {
  .inventory-history-line {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .inventory-history-line > :first-child {
    grid-column: 1 / -1;
    font-weight: 650;
  }
}

.link-btn,
.danger {
  min-height: 34px;
  padding: 6px 8px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
}

.link-btn:hover {
  background: rgba(0, 122, 255, .08);
}

.danger {
  color: var(--red);
}

.danger:hover {
  background: rgba(215, 0, 21, .07);
}

.danger:disabled {
  color: #9b9ba1;
  background: transparent;
  cursor: not-allowed;
  opacity: .72;
  transform: none;
}

.catalog-form {
  gap: 11px;
}

.catalog-row {
  padding: 14px 6px;
}

.warehouse-grid {
  gap: 16px;
}

.warehouse-card {
  margin-top: 0;
}

.add-category-form {
  max-width: 620px;
  margin-top: 16px;
}

.category-list {
  display: grid;
  margin-top: 14px;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 110px auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  border-top: 1px solid #e5e5ea;
}

.category-row > span {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.directory-tabs {
  margin-top: 26px;
  padding: 4px;
  border: 0;
  border-radius: 10px;
  background: rgba(118, 118, 128, .12);
}

.directory-tab {
  min-height: 34px;
  padding: 7px 15px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.directory-tab:hover {
  background: rgba(255, 255, 255, .55);
}

.directory-tab.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(38, 44, 54, .1);
}

.workshop-section {
  border-top-color: #e5e5ea;
}

.modal {
  padding: 24px;
  background: rgba(27, 31, 39, .34);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal-dialog {
  width: min(1160px, 100%);
  padding: 28px;
  border-radius: 20px;
  background: rgba(251, 252, 254, .96);
  box-shadow: var(--shadow-float);
  animation: sheet-in 300ms cubic-bezier(.16, 1, .3, 1) both;
}

@keyframes sheet-in {
  from { transform: translateY(14px) scale(.985); opacity: 0; backdrop-filter: blur(0); }
  to { transform: translateY(0) scale(1); opacity: 1; backdrop-filter: blur(24px); }
}

.modal-close {
  min-height: 36px;
  margin: -2px -2px 0 16px;
  padding: 7px 11px;
  border: 0;
  border-radius: 9px;
  background: #e9e9ee;
  color: #48484a;
  font-size: 12px;
  font-weight: 600;
}

.modal-close:hover {
  background: #dedee3;
}

.modal-doc-layout .doc-summary {
  padding: 20px;
  border-radius: 14px;
  background: #eef1f5;
}

.purchase-row input[type="checkbox"] {
  accent-color: var(--blue);
}

.toast {
  right: 24px;
  bottom: 24px;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(35, 35, 38, .92);
  color: #fff;
  box-shadow: 0 16px 44px rgba(0, 0, 0, .22);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.toast.error {
  background: rgba(170, 19, 34, .94);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .brand {
    justify-content: flex-start;
  }

  .brand > span:last-child {
    display: grid;
  }

  .sidebar-note {
    display: grid;
  }

  .nav-item span {
    display: inline;
  }

  .nav-item {
    justify-content: flex-start;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    height: 72px;
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
    flex-direction: row;
    border: 0;
    border-top: 1px solid rgba(112, 118, 130, .18);
  }

  .brand,
  .sidebar-note {
    display: none;
  }

  .sidebar nav {
    width: 100%;
    grid-template-columns: repeat(6, 1fr);
    gap: 3px;
  }

  .nav-item {
    min-height: 52px;
    flex-direction: column;
    gap: 3px;
    padding: 5px 2px;
    font-size: 10px;
  }

  .nav-item span {
    display: block;
  }

  .nav-item b,
  .nav-item svg {
    width: 18px;
    height: 18px;
  }

  .workspace {
    padding: 24px 16px calc(96px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: center;
  }

  .topbar h1 {
    font-size: 31px;
  }

  .topbar p {
    display: none;
  }

  .topbar .primary {
    max-width: 148px;
    min-height: 40px;
    padding-inline: 12px;
    font-size: 12px;
  }

  .filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    overflow: visible;
  }

  .filters .field {
    min-width: 0;
  }

  .data-scroll {
    box-shadow: inset -16px 0 18px -20px rgba(29, 29, 31, .9);
  }

  .data-row > :first-child,
  .purchase-row > :first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: rgba(255, 255, 255, .98);
  }

  .data-row:not(.head):hover > :first-child,
  .data-row:not(.head):focus-within > :first-child,
  .purchase-row:not(.head):hover > :first-child,
  .purchase-row:not(.head):focus-within > :first-child {
    background: #f6faff;
  }

  .data-row.is-low > :first-child,
  .purchase-row.is-low > :first-child {
    background: #fff8ef;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .kpi {
    min-height: 104px;
  }

  .kpi + .kpi {
    border-left: 0;
    border-top: 1px solid #e5e5ea;
  }

  .panel,
  .warehouse-card {
    padding: 18px;
    border-radius: 15px;
  }

  .panel-head {
    align-items: flex-start;
  }

  .shortage-panel .panel-head {
    flex-direction: column;
  }

  .shortage-panel .panel-head .primary {
    width: 100%;
  }

  .panel-head .primary,
  .panel-head .secondary {
    white-space: nowrap;
  }

  .catalog-form,
  .purchase-header {
    grid-template-columns: 1fr;
  }

  .category-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .category-row > span {
    text-align: right;
  }

  .category-row .link-btn,
  .category-row .danger {
    justify-self: start;
  }

  .document-main {
    gap: 12px;
  }

  .line-row {
    grid-template-columns: 1fr 92px;
  }

  .line-row .remove-line {
    grid-column: 1 / -1;
    justify-self: end;
  }

  .modal {
    padding: 0;
    place-items: stretch;
  }

  .modal-dialog {
    width: 100%;
    max-height: 100vh;
    padding: 20px 16px 28px;
    border-radius: 0;
  }

  .toast {
    left: 16px;
    right: 16px;
    bottom: calc(88px + env(safe-area-inset-bottom));
    text-align: center;
  }
}

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

  button:active {
    transform: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .sidebar,
  .login-card,
  .modal,
  .toast {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .sidebar,
  .login-card,
  .panel,
  .kpi-grid {
    background: #fff;
  }
}

@media (prefers-contrast: more) {
  .sidebar,
  .panel,
  .kpi-grid,
  .login-card {
    background: #fff;
    outline: 1px solid #6e6e73;
  }

  .muted,
  .panel p,
  .topbar p {
    color: #3a3a3c;
  }
}

/* Inventory and access management extend the same calm operations surface. */
.inventory-editor {
  min-width: 0;
}

.bar-level-0 { height: 0; }
.bar-level-1 { height: 12%; }
.bar-level-2 { height: 20%; }
.bar-level-3 { height: 30%; }
.bar-level-4 { height: 40%; }
.bar-level-5 { height: 50%; }
.bar-level-6 { height: 60%; }
.bar-level-7 { height: 70%; }
.bar-level-8 { height: 80%; }
.bar-level-9 { height: 90%; }
.bar-level-10 { height: 100%; }

.bar-wrap > span {
  max-width: 110px;
  line-height: 1.2;
  text-align: center;
}

.workshop-matrix-row {
  grid-template-columns: 280px;
  grid-auto-flow: column;
  grid-auto-columns: 150px;
  min-width: max-content;
}

.workshop-matrix-table {
  border: 1px solid var(--line);
  border-radius: 10px;
}

.workshop-matrix-table .workshop-matrix-row {
  gap: 0;
  padding: 0;
  border: 0;
}

.workshop-matrix-table .workshop-matrix-row > * {
  display: flex;
  min-width: 0;
  min-height: 52px;
  align-items: center;
  justify-content: flex-end;
  padding: 11px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.workshop-matrix-table .workshop-matrix-row > :first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  justify-content: flex-start;
  background: #fff;
  text-align: left;
}

.workshop-matrix-table .workshop-matrix-row:not(.head) > strong:first-child {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
}

.workshop-matrix-table .workshop-matrix-row > :last-child {
  border-right: 0;
}

.workshop-matrix-table > .workshop-matrix-row:last-child > * {
  border-bottom: 0;
}

.workshop-matrix-empty {
  margin: 0;
  border-top: 1px solid var(--line);
}

.workshop-matrix-table .workshop-matrix-row.head {
  background: #f5f5f7;
}

.workshop-matrix-table .workshop-matrix-row.head > :first-child {
  z-index: 2;
  background: #f5f5f7;
}

.workshop-matrix-table .workshop-matrix-row.head > * {
  min-height: 58px;
  padding: 6px;
}

.workshop-matrix-table .workshop-matrix-row.head .table-sort-button {
  height: 100%;
  justify-content: flex-end;
  padding: 7px 6px;
  text-align: right;
  white-space: normal;
}

.workshop-matrix-table .workshop-matrix-row.head > :first-child .table-sort-button {
  justify-content: flex-start;
  text-align: left;
}

.inventory-header,
.user-create-form {
  display: grid;
  grid-template-columns: 180px minmax(210px, 1fr) minmax(240px, 1.4fr) minmax(210px, 1fr);
  gap: 11px;
  margin-top: 22px;
  align-items: end;
}

.inventory-header {
  grid-template-columns: 160px minmax(180px, .8fr) minmax(180px, .8fr) minmax(220px, 1fr) minmax(210px, 1fr);
}

.inventory-table {
  margin-top: 24px;
  overflow-x: auto;
}

.inventory-row {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(130px, .8fr) minmax(130px, .8fr) minmax(100px, .6fr);
  min-width: 760px;
  align-items: center;
  gap: 14px;
  padding: 11px 6px;
  border-top: 1px solid #e5e5ea;
  font-size: 13px;
}

.inventory-row.head {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.inventory-row strong small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.inventory-actual,
.user-row input,
.user-row select,
.role-row input,
.role-create-form input {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid #d2d5da;
  border-radius: 10px;
  background: rgba(255, 255, 255, .94);
  color: var(--ink);
}

.inventory-actual:focus,
.user-row input:focus,
.user-row select:focus,
.role-row input:focus,
.role-create-form input:focus {
  border-color: var(--blue);
  outline: 0;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, .12);
}

.inventory-difference {
  justify-self: start;
  min-width: 58px;
  padding: 6px 9px;
  border-radius: 999px;
  font-weight: 650;
  text-align: center;
}

.inventory-difference.neutral {
  color: var(--muted);
  background: #ededf1;
}

.inventory-difference.positive,
.positive-text {
  color: #16713b;
}

.inventory-difference.positive {
  background: #e7f7ed;
}

.inventory-difference.negative,
.negative-text {
  color: var(--red);
}

.inventory-difference.negative {
  background: rgba(215, 0, 21, .075);
}

.inventory-footer {
  position: static;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 20px -28px -28px;
  padding: 16px 28px;
  border-top: 1px solid rgba(112, 118, 130, .14);
  background: rgba(251, 252, 254, .94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.inventory-footer-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.inventory-footer-actions button {
  min-height: 44px;
}

.inventory-footer > div {
  display: grid;
  gap: 2px;
}

.inventory-footer strong {
  font-size: 20px;
}

.inventory-footer span {
  color: var(--muted);
  font-size: 11px;
}

.inventory-result {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 110px 110px 120px;
  gap: 12px;
  padding: 7px 0;
  font-size: 12px;
}

.inventory-result b {
  text-align: right;
}

.compact-catalog-form {
  grid-template-columns: minmax(220px, 1.7fr) minmax(170px, 1.2fr) 100px 110px auto;
}

.stock-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(190px, 1fr)) minmax(220px, 1.35fr);
  width: min(100%, 820px);
}

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(0, 122, 255, .18);
  border-radius: 10px;
  background: rgba(0, 122, 255, .075);
  color: var(--blue);
}

.icon-button:hover {
  border-color: rgba(0, 122, 255, .32);
  background: rgba(0, 122, 255, .13);
}

.icon-button.danger-icon {
  border-color: rgba(215, 0, 21, .16);
  background: rgba(215, 0, 21, .055);
  color: var(--red);
}

.icon-button.danger-icon:hover {
  border-color: rgba(215, 0, 21, .28);
  background: rgba(215, 0, 21, .1);
}

.icon-button:disabled,
.icon-button:disabled:hover {
  border-color: #e5e5ea;
  background: #f5f5f7;
  color: #9b9ba1;
  cursor: not-allowed;
  opacity: .72;
  transform: none;
}

.icon-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.directory-actions,
.directory-name-row,
.modal-form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.directory-name-row {
  justify-content: space-between;
  min-height: 42px;
}

.directory-name-row h3,
.directory-name-row span {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.workshop-name {
  padding: 7px 0;
  border-top: 1px solid #e5e5ea;
}

.workshop-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-inline-start: auto;
}

.workshop-balance-lock {
  color: var(--amber);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.compact-modal {
  width: min(560px, calc(100vw - 32px));
}

.directory-edit-form {
  display: grid;
  gap: 18px;
  padding: 8px 2px 2px;
}

.directory-edit-form h2 {
  margin: 0 0 5px;
}

.directory-edit-form p {
  margin: 0;
  color: var(--muted);
}

.modal-form-actions {
  justify-content: flex-end;
  padding-top: 6px;
}

.draft-status {
  margin: -3px 0 15px;
  color: #16713b;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.document-warning {
  margin: 14px 0 4px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 149, 0, .1);
  color: #8a4b00;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.primary.compact {
  min-height: 34px;
  padding: 7px 11px;
  font-size: 12px;
}

.editor-page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 24px 0 12px;
}

.back-to-journal {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 5px;
  padding: 8px 12px 8px 8px;
  border: 0;
  border-radius: 10px;
  background: rgba(0, 122, 255, .08);
  color: var(--blue);
  font-size: 13px;
  font-weight: 650;
}

.back-to-journal:hover {
  background: rgba(0, 122, 255, .14);
}

.back-to-journal svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.editor-export-document {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  text-decoration: none;
}

.editor-export-document svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.document-editor-page {
  margin-top: 0;
  padding: 24px;
  border-radius: 16px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-surface);
}

.document-editor-page.modal-doc-layout .doc-form {
  padding-right: 26px;
}

.document-editor-page.modal-doc-layout .doc-lines {
  max-height: none;
  overflow: visible;
  padding-right: 0;
}

.document-editor-page.modal-doc-layout .doc-summary {
  top: 24px;
}

.inventory-editor.document-editor-page .inventory-footer {
  margin-bottom: -24px;
}

@media (max-width: 900px) {
  .document-editor-page {
    padding: 20px;
  }

  .document-editor-page.modal-doc-layout {
    grid-template-columns: 1fr;
  }

  .document-editor-page.modal-doc-layout .doc-form {
    padding-right: 0;
  }

  .document-editor-page.modal-doc-layout .doc-summary {
    position: static;
    margin-top: 18px;
  }

  .doc-header.transfer-header {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .editor-page-toolbar {
    margin-top: 18px;
  }

  .editor-export-document {
    min-width: 44px;
    padding-inline: 12px;
  }

  .editor-export-document span {
    display: none;
  }

  .document-editor-page {
    padding: 16px;
    border-radius: 16px;
  }

  .inventory-editor.document-editor-page .inventory-footer {
    position: sticky;
    z-index: 6;
    bottom: calc(72px + env(safe-area-inset-bottom));
    margin-bottom: -16px;
  }

  .inventory-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .inventory-footer-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .doc-header.transfer-header {
    grid-template-columns: 1fr;
  }
}

.settings-grid {
  display: grid;
  gap: 16px;
  margin-top: 30px;
}

.user-create-form {
  grid-template-columns: minmax(180px, 1fr) minmax(160px, .8fr) minmax(180px, .9fr) minmax(170px, .8fr) auto;
}

.user-list,
.role-list {
  display: grid;
  margin-top: 16px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(150px, .8fr) minmax(160px, .8fr) minmax(180px, .9fr) 110px auto;
  align-items: end;
  gap: 11px;
  padding: 14px 4px;
  border-top: 1px solid #e5e5ea;
}

.user-identity {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: end;
  gap: 10px;
}

.user-avatar {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: rgba(0, 122, 255, .11);
  color: var(--blue);
  font-weight: 700;
}

.active-switch,
.permission-check {
  display: flex;
  align-items: center;
  gap: 7px;
  color: #4c4c50;
  font-size: 12px;
  font-weight: 600;
}

.active-switch {
  min-height: 42px;
}

.active-switch input,
.permission-check input {
  width: 17px;
  height: 17px;
  min-height: 0;
  accent-color: var(--blue);
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-height: 42px;
}

.role-create-form,
.role-row {
  display: grid;
  grid-template-columns: minmax(180px, .8fr) minmax(0, 2fr) auto;
  align-items: center;
  gap: 16px;
}

.role-create-form {
  margin-top: 18px;
  padding-bottom: 18px;
}

.role-row {
  padding: 16px 4px;
  border-top: 1px solid #e5e5ea;
}

.role-heading {
  display: grid;
  gap: 5px;
}

.role-heading > span,
.system-label {
  color: var(--muted);
  font-size: 11px;
}

.role-heading input:disabled {
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  opacity: 1;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 9px 14px;
}

@media (max-width: 1440px) {
  .user-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .user-identity {
    grid-column: 1 / -1;
  }

  .row-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .inventory-header,
  .user-create-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .role-create-form,
  .role-row {
    grid-template-columns: 1fr;
    align-items: start;
  }
}

@media (max-width: 760px) {
  .sidebar nav {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(72px, 1fr);
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .sidebar nav::-webkit-scrollbar {
    display: none;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 128px;
    gap: 10px;
  }

  .topbar h1 {
    font-size: 28px;
  }

  .topbar .primary {
    width: 100%;
    max-width: none;
  }

  .document-journal .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .document-journal .panel-head .primary {
    width: 100%;
  }

  .inventory-header,
  .user-create-form,
  .user-row {
    grid-template-columns: 1fr;
  }

  .dashboard-filters {
    grid-template-columns: 1fr;
    width: 100%;
    min-width: 0;
  }

  .stock-filters {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .dashboard-filters .field,
  .dashboard-filters #month-filter {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .dashboard-month-field,
  .field:has(> input[type="date"]),
  .field:has(> input[type="month"]) {
    contain: inline-size;
  }

  .dashboard-filters #month-filter {
    display: block;
    box-sizing: border-box;
    inline-size: -webkit-fill-available;
    -webkit-appearance: none;
    appearance: none;
    overflow: hidden;
  }

  .dashboard-filters #month-filter::-webkit-date-and-time-value {
    width: 100%;
    min-width: 0;
    margin: 0;
    text-align: left;
  }

  .dashboard-filters #month-filter::-webkit-datetime-edit {
    display: block;
    min-width: 0;
    padding: 0;
    overflow: hidden;
  }

  .inventory-footer {
    margin-inline: -16px;
    padding-inline: 16px;
  }

  .permission-grid {
    grid-template-columns: 1fr 1fr;
  }

  .inventory-result {
    grid-template-columns: minmax(160px, 1fr) repeat(3, 90px);
    min-width: 500px;
  }

  .compact-catalog-form {
    grid-template-columns: 1fr;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .topbar-actions {
    gap: 6px;
  }

  .install-app {
    padding: 9px 11px;
    justify-content: center;
  }
}

@media (max-width: 360px) {
  .install-app {
    width: 40px;
    min-width: 40px;
    padding: 9px;
  }

  .install-app span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

/* Mobile interaction pass: stable five-item navigation, readable forms and touch targets. */
@media (max-width: 760px) {
  .sidebar nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: auto;
    overflow: visible;
  }

  .sidebar .nav-item[data-view="inventory"],
  .sidebar .nav-item[data-view="purchase"],
  .sidebar .nav-item[data-view="directories"],
  .sidebar .nav-item[data-view="users"],
  .sidebar .nav-item[data-view="trash"] {
    display: none;
  }

  .sidebar .mobile-more {
    display: flex;
  }

  .mobile-more-menu {
    position: fixed;
    z-index: 64;
    right: 12px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    left: 12px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    max-height: calc(100dvh - 96px - env(safe-area-inset-bottom));
    padding: 10px;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid rgba(112, 118, 130, .2);
    border-radius: 20px;
    background: rgba(249, 249, 251, .96);
    box-shadow: 0 20px 60px rgba(20, 25, 30, .24);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
  }

  .mobile-more-menu button {
    display: grid;
    min-height: 64px;
    gap: 4px;
    padding: 11px 12px;
    border: 0;
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    text-align: left;
  }

  .mobile-more-menu button:active {
    background: rgba(0, 122, 255, .1);
  }

  .mobile-more-menu button span {
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-more-menu button small {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.25;
  }

  .mobile-more-menu .mobile-logout span {
    color: var(--red);
  }

  .field input,
  .field select,
  .field textarea,
  .search,
  .login-card input,
  .inline-form input {
    min-height: 46px;
    font-size: 16px;
  }

  .primary,
  .secondary,
  .link-btn,
  .danger,
  .remove-line,
  .icon-button,
  .edit-directory {
    min-height: 44px;
  }

  .line-row .remove-line {
    grid-column: 1 / -1;
    width: auto;
    min-width: 44px;
    justify-self: end;
    padding-inline: 8px;
  }

  .doc-lines > .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  .add-line-row .secondary {
    width: 100%;
  }

  .doc-actions {
    align-items: stretch;
  }

  .document-submit-actions {
    display: grid;
    width: 100%;
  }

  .history-entry summary {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Short touch viewports keep every navigation action reachable in landscape. */
@media (orientation: landscape) and (max-height: 560px) and (min-width: 761px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    padding-block: 12px;
  }

  .brand {
    flex: none;
    padding-bottom: 12px;
  }

  .sidebar nav {
    flex: 1 1 auto;
    min-height: 0;
    padding-right: 3px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-note {
    flex: none;
    margin-top: 10px;
  }
}

@media (orientation: landscape) and (max-height: 560px) and (max-width: 760px) {
  .mobile-more-menu {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.trash-list {
  margin-top: 20px;
  border-top: 1px solid var(--line);
}

.trash-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(190px, .55fr) auto;
  align-items: center;
  gap: 24px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.trash-identity,
.trash-audit {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.trash-identity strong {
  overflow-wrap: anywhere;
}

.trash-identity small,
.trash-audit small,
.trash-audit span {
  color: var(--muted);
}

.trash-kind {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 7px;
  background: rgba(0, 122, 255, .09);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.trash-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.trash-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 64px 20px;
  text-align: center;
}

.trash-empty span {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(52, 199, 89, .12);
  color: #248a3d;
}

.trash-empty svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.trash-empty p {
  max-width: 46ch;
  margin: 0;
  color: var(--muted);
}

@media (max-width: 760px) {
  .trash-row {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 20px 0;
  }

  .trash-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .trash-actions button {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 420px) {
  .sidebar {
    min-width: 0;
    max-width: 100vw;
  }

  .sidebar nav {
    min-width: 0;
  }

  .sidebar .nav-item {
    min-width: 0;
  }

  .sidebar .nav-item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar-actions .install-app span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .install-app {
    width: 42px;
    min-width: 42px;
  }
}

/* Mobile data rows replace wide tables while preserving every operational value. */
.purchase-choice {
  display: flex;
  align-items: center;
  justify-content: center;
}

.purchase-choice > span:last-child {
  display: none;
}

.purchase-quantity,
.inventory-actual-field {
  min-width: 0;
}

.inventory-actual-field .inventory-actual {
  width: 100%;
}

@media (max-width: 760px) {
  .line-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .line-row > .field:first-child {
    grid-column: 1 / -1;
  }

  .line-row > .field:nth-child(2) {
    grid-column: 1;
    width: min(128px, 100%);
  }

  .line-row .remove-line {
    grid-column: 2;
    grid-row: 2;
    align-self: end;
  }

  .data-scroll,
  .inventory-table {
    overflow: visible;
    box-shadow: none;
  }

  .shortage-row.head,
  .workshop-matrix-row.head,
  .purchase-row.head,
  .inventory-row.head {
    display: none;
  }

  .mobile-table-row,
  .stock-table .mobile-table-row,
  .inventory-result.mobile-table-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    grid-auto-columns: auto;
    width: 100%;
    min-width: 0;
    gap: 12px 16px;
    padding: 15px 0;
    align-items: start;
  }

  .mobile-table-row > :first-child,
  .data-row.mobile-table-row > :first-child,
  .purchase-row.mobile-table-row > :first-child {
    position: static;
    z-index: auto;
    grid-column: 1 / -1;
    min-width: 0;
    background: transparent;
  }

  .mobile-table-row > :first-child,
  .mobile-table-row > :first-child strong,
  .mobile-table-row > strong:first-child {
    overflow: visible;
    overflow-wrap: anywhere;
    text-overflow: clip;
    white-space: normal;
  }

  .mobile-table-row > [data-label] {
    display: grid;
    min-width: 0;
    gap: 4px;
    justify-items: start;
    text-align: left;
    overflow-wrap: anywhere;
  }

  .mobile-table-row > [data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
  }

  .workshop-matrix-row.mobile-table-row {
    grid-auto-flow: row;
    grid-auto-columns: auto;
  }

  .workshop-matrix-table {
    border: 0;
    border-radius: 0;
  }

  .workshop-matrix-table .workshop-matrix-row.mobile-table-row {
    gap: 12px 16px;
    padding: 15px 0;
    border-top: 1px solid var(--line);
  }

  .workshop-matrix-table .workshop-matrix-row.mobile-table-row > * {
    display: grid;
    position: static;
    min-height: 0;
    padding: 0;
    border: 0;
    justify-content: start;
    text-align: left;
  }

  .stock-table .stock-head {
    display: flex;
    width: 100%;
    min-width: 0;
    gap: 8px;
    padding: 8px 0 12px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .stock-table .stock-head::-webkit-scrollbar {
    display: none;
  }

  .stock-table .stock-head > span {
    position: static;
    flex: none;
    background: transparent;
  }

  .stock-table .stock-sort-button {
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, .94);
  }

  .stock-table .stock-sort-button.active {
    border-color: rgba(0, 102, 204, .32);
    background: rgba(0, 122, 255, .1);
  }

  .purchase-row.mobile-table-row > strong {
    grid-column: 1 / -1;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .purchase-choice {
    justify-content: flex-start;
    min-height: 32px;
    gap: 9px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 650;
  }

  .purchase-choice > span:last-child {
    display: inline;
  }

  .purchase-quantity .purchase-qty {
    width: min(128px, 100%);
  }

  .inventory-actual-field {
    align-self: stretch;
  }

  .inventory-result.mobile-table-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .inventory-result.mobile-table-row > :first-child {
    grid-column: 1 / -1;
  }

  .catalog-row.mobile-table-row > .directory-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .shortage-row.is-low > :first-child,
  .purchase-row.is-low > :first-child {
    background: transparent;
  }
}

/* Desktop keeps every table as a horizontal column row; only mobile stacks values. */
@media (min-width: 761px) {
  .shortage-row.mobile-table-row {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(150px, 1fr) repeat(3, minmax(90px, 1fr));
    min-width: 720px;
  }

  .workshop-matrix-row.mobile-table-row {
    display: grid;
    grid-template-columns: 280px;
    grid-auto-flow: column;
    grid-auto-columns: 150px;
    min-width: max-content;
  }

  .stock-table .stock-data.mobile-table-row {
    display: grid;
  }

  .stock-table.stock-columns-1 .data-row { grid-template-columns: minmax(220px, 2fr) minmax(85px, 1fr); min-width: 350px; }
  .stock-table.stock-columns-2 .data-row { grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(85px, 1fr)); min-width: 460px; }
  .stock-table.stock-columns-3 .data-row { grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(85px, 1fr)); min-width: 570px; }
  .stock-table.stock-columns-4 .data-row { grid-template-columns: minmax(220px, 2fr) repeat(4, minmax(85px, 1fr)); min-width: 680px; }
  .stock-table.stock-columns-5 .data-row { grid-template-columns: minmax(220px, 2fr) repeat(5, minmax(85px, 1fr)); min-width: 790px; }
  .stock-table.stock-columns-6 .data-row { grid-template-columns: minmax(220px, 2fr) repeat(6, minmax(85px, 1fr)); min-width: 900px; }

  .purchase-row.mobile-table-row {
    display: grid;
    grid-template-columns: 34px minmax(230px, 2fr) repeat(4, minmax(95px, 1fr));
    min-width: 820px;
  }

  .inventory-row.mobile-table-row {
    display: grid;
    grid-template-columns: minmax(260px, 2fr) minmax(130px, .8fr) minmax(130px, .8fr) minmax(100px, .6fr);
    min-width: 760px;
  }

  .inventory-result.mobile-table-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 110px 110px 120px;
  }

  .catalog-row.mobile-table-row {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) 1fr 1fr 1fr auto;
  }

  .mobile-table-row > [data-label] {
    display: block;
  }
}

/* Large inventory results stay inside their card instead of growing past the viewport. */
.inventory-card,
.inventory-card .document-main,
.inventory-card .document-main > *,
.inventory-results-list,
.inventory-result > * {
  min-width: 0;
}

.inventory-stock-count {
  display: grid;
  gap: 2px;
}

.inventory-card-actions {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.inventory-card-actions .link-btn,
.inventory-card-actions .danger {
  min-height: 36px;
  padding: 7px 8px;
  white-space: nowrap;
}

.inventory-edit-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.inventory-edit-action svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (min-width: 761px) and (max-width: 1280px) {
  .inventory-card .document-main {
    grid-template-columns: minmax(120px, .8fr) minmax(180px, 1.25fr) minmax(140px, .9fr) minmax(120px, .65fr);
    align-items: start;
  }

  .inventory-card-actions {
    grid-column: 1 / -1;
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }
}

.inventory-results-list {
  width: 100%;
  max-width: 100%;
  max-height: min(60vh, 560px);
  padding-right: 6px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.inventory-results-head {
  position: sticky;
  z-index: 2;
  top: -10px;
  padding: 12px 0 9px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.inventory-results-head span:last-child {
  text-align: right;
}

.inventory-result > strong {
  overflow-wrap: anywhere;
  white-space: normal;
}

@media (max-width: 760px) {
  .inventory-card .document-main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .inventory-card .document-main > :nth-child(3),
  .inventory-card-actions {
    grid-column: 1 / -1;
  }

  .inventory-card-actions {
    justify-content: flex-start;
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }

  .inventory-card-actions .link-btn,
  .inventory-card-actions .danger,
  .inventory-card-actions .icon-button {
    min-height: 44px;
  }

  .inventory-results-list {
    max-height: min(55vh, 500px);
    padding-right: 4px;
  }

  .inventory-results-head {
    display: none;
  }

  .inventory-result.mobile-table-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
  }
}

/* Sorting controls remain reachable after the later mobile table overrides. */
@media (max-width: 760px) {
  .shortage-row.head.sortable-head,
  .workshop-matrix-row.head.sortable-head,
  .purchase-row.head.sortable-head,
  .inventory-row.head.sortable-head,
  .catalog-row.head.sortable-head,
  .inventory-results-head.sortable-head {
    display: flex;
  }
}

/* Shared ruled grid for operational tables on desktop. Mobile keeps card rows. */
@media (min-width: 761px) {
  .ruled-table {
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow-x: auto;
  }

  .ruled-table :is(.data-row, .purchase-row, .catalog-row, .inventory-row, .inventory-result) {
    gap: 0;
    padding: 0;
    border: 0;
  }

  .ruled-table :is(.data-row, .purchase-row, .catalog-row, .inventory-row, .inventory-result) > * {
    display: flex;
    min-width: 0;
    min-height: 52px;
    align-items: center;
    justify-content: flex-end;
    padding: 11px 12px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  .ruled-table :is(.data-row, .purchase-row, .catalog-row, .inventory-row, .inventory-result) > :first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    background: inherit;
    text-align: left;
  }

  .ruled-table :is(.data-row, .purchase-row, .catalog-row, .inventory-row, .inventory-result) > :last-child {
    border-right: 0;
  }

  .ruled-table > :is(.data-row, .purchase-row, .catalog-row, .inventory-result):last-child > *,
  .ruled-table #inventory-lines > .inventory-row:last-child > * {
    border-bottom: 0;
  }

  .ruled-table :is(.data-row, .purchase-row, .catalog-row, .inventory-row, .inventory-result).head {
    background: #f5f5f7;
  }

  .ruled-table :is(.data-row, .purchase-row, .catalog-row, .inventory-row, .inventory-result).head > * {
    z-index: 2;
    min-height: 56px;
    padding: 6px;
    background: inherit;
  }

  .ruled-table .head :is(.table-sort-button, .stock-sort-button) {
    height: 100%;
    justify-content: flex-end;
    padding: 7px 6px;
    text-align: right;
    white-space: normal;
  }

  .ruled-table .head > :first-child :is(.table-sort-button, .stock-sort-button) {
    justify-content: flex-start;
    text-align: left;
  }

  .ruled-table .mobile-table-row {
    background: #fff;
    transition: background-color 140ms ease-out;
  }

  .ruled-table .mobile-table-row:hover,
  .ruled-table .mobile-table-row:focus-within {
    background: #f6faff;
  }

  .ruled-table :is(.shortage-row, .purchase-row).is-low {
    background: #fff8ef;
  }

  .ruled-table .shortage-row > :nth-child(2),
  .ruled-table .catalog-row > :nth-child(2) {
    align-items: center;
    justify-content: flex-start;
    text-align: left;
  }

  .ruled-table .purchase-row > :first-child {
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .ruled-table .purchase-row > :nth-child(2) {
    align-items: flex-start;
    justify-content: center;
    text-align: left;
  }

  .ruled-table .purchase-row.head > :nth-child(2) {
    align-items: center;
  }

  .ruled-table .purchase-row.head > :nth-child(2) .table-sort-button,
  .ruled-table .shortage-row.head > :nth-child(2) .table-sort-button,
  .ruled-table .catalog-row.head > :nth-child(2) .table-sort-button {
    justify-content: flex-start;
    text-align: left;
  }

  .ruled-table .purchase-choice {
    flex-direction: row;
  }
}
