:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d9dee7;
  --primary: #214d8f;
  --primary-strong: #17396a;
  --secondary: #e9eef5;
  --danger: #b42318;
  --success: #1a7f37;
  --shadow: 0 8px 24px rgba(31, 41, 55, 0.08);
}

@media (max-width: 640px) {
  body {
    padding-bottom: calc(68px + env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: 56px;
  }

  .topbar .nav {
    position: fixed;
    z-index: 50;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
    gap: 4px;
    margin: 0;
    padding: 7px max(8px, env(safe-area-inset-left)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(31, 41, 55, 0.1);
    backdrop-filter: blur(10px);
  }

  .topbar .navlink,
  .topbar .settings-icon,
  .topbar .recheck-icon {
    display: inline-flex;
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 48px;
    padding: 6px 4px;
    border-radius: 10px;
    font-size: 0.72rem;
    line-height: 1.1;
    text-align: center;
  }

  .topbar .user-chip {
    display: none;
  }

  .shell {
    padding-bottom: 18px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .entry-list-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .entry-list-filters .button {
    grid-column: 1 / -1;
    width: 100%;
  }

  body[data-page="entry"] #entriesTable,
  body[data-page="recheck"] #recheckEntriesTable,
  body[data-page="activity"] .activity-table {
    display: block;
    min-width: 0;
  }

  body[data-page="entry"] #entriesTable thead,
  body[data-page="recheck"] #recheckEntriesTable thead,
  body[data-page="activity"] .activity-table thead {
    display: none;
  }

  body[data-page="entry"] #entriesTable tbody,
  body[data-page="recheck"] #recheckEntriesTable tbody,
  body[data-page="activity"] .activity-table tbody {
    display: grid;
    gap: 10px;
  }

  body[data-page="entry"] #entriesTable tr,
  body[data-page="recheck"] #recheckEntriesTable tr,
  body[data-page="activity"] .activity-table tr {
    display: block;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 4px 12px rgba(31, 41, 55, 0.06);
  }

  body[data-page="entry"] #entriesTable td,
  body[data-page="recheck"] #recheckEntriesTable td,
  body[data-page="activity"] .activity-table td {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    font-size: 0.84rem;
    text-align: left;
    overflow-wrap: anywhere;
  }

  body[data-page="entry"] #entriesTable td:last-child,
  body[data-page="recheck"] #recheckEntriesTable td:last-child,
  body[data-page="activity"] .activity-table td:last-child {
    border-bottom: 0;
  }

  body[data-page="entry"] #entriesTable td::before,
  body[data-page="recheck"] #recheckEntriesTable td::before,
  body[data-page="activity"] .activity-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  body[data-page="entry"] #entriesTable td.muted,
  body[data-page="recheck"] #recheckEntriesTable td.muted,
  body[data-page="activity"] .activity-table td.muted {
    display: block;
  }

  body[data-page="entry"] #entriesTable td input {
    min-height: 44px;
  }

  body[data-page="entry"] #entriesTable .table-actions,
  body[data-page="entry"] #entriesTable .table-actions .button {
    width: 100%;
  }

  body[data-page="recheck"] #recheckEntriesTable .check-col,
  body[data-page="recheck"] #recheckEntriesTable .edit-col {
    width: 100%;
    text-align: left;
  }

  body[data-page="recheck"] #recheckEntriesTable input[type="checkbox"] {
    width: 24px;
    height: 24px;
    min-height: 24px;
  }

  body[data-page="details"] .details-table {
    min-width: 0;
    table-layout: fixed;
  }

  body[data-page="details"] .details-summary-actions {
    justify-content: flex-start;
  }

  body[data-page="details"] .details-summary-actions .button {
    width: auto;
  }

  body[data-page="differences"] .difference-filters {
    grid-template-columns: 1fr;
  }

  body[data-page="differences"] .difference-filter-actions {
    grid-column: 1;
    flex-wrap: wrap;
  }

  body[data-page="differences"] .difference-table {
    min-width: 900px;
    font-size: 0.7rem;
  }

  body[data-page="differences"] .difference-table th:first-child,
  body[data-page="differences"] .difference-table td:first-child {
    width: 105px;
    min-width: 105px;
    max-width: 105px;
  }

  body[data-page="differences"] .difference-table th:nth-child(2),
  body[data-page="differences"] .difference-table td:nth-child(2) {
    left: 105px;
    width: 145px;
    min-width: 145px;
    max-width: 145px;
  }

  .sticky-footer-actions {
    gap: 8px;
    flex-direction: column;
  }

  .sticky-footer-actions .button {
    width: 100%;
  }

  .toast {
    right: 10px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    left: 10px;
    max-width: none;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #fbfcfe 0%, var(--bg) 100%);
  color: var(--text);
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: rgba(245, 246, 248, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.brand { font-size: 1.08rem; font-weight: 900; color: #c1121f; letter-spacing: 0.02em; }
.brand:hover { opacity: 0.86; }
.subbrand { color: var(--muted); font-size: 0.92rem; }
.nav { display: flex; gap: 10px; flex-wrap: wrap; }
.navlink, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 700;
  cursor: pointer;
}
.navlink { background: var(--card); border-color: var(--line); }
.navlink.active { background: var(--primary); color: white; border-color: var(--primary); }
.icon-button {
  min-width: 44px;
  padding: 10px 12px;
  font-size: 1.1rem;
  line-height: 1;
}
.button.primary { background: var(--primary); color: white; }
.button.primary:hover { background: var(--primary-strong); }
.button.secondary { background: var(--secondary); border-color: var(--line); }

.shell { max-width: 1180px; margin: 0 auto; padding: 94px 20px 20px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.page-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.page-head h1, .card h2 { margin: 0 0 6px; }
.compact-nav-button { white-space: nowrap; }
.muted { color: var(--muted); }

.timestamp-main {
  display: block;
  font-weight: 700;
  white-space: nowrap;
}

.timestamp-sub {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
  white-space: nowrap;
}
.card {
  background: var(--card);
  border: 1px solid rgba(217, 222, 231, 0.9);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.compact { gap: 12px; }
.stack { display: grid; gap: 12px; }
label { display: grid; gap: 8px; font-weight: 700; }
input, select, textarea {
  width: 100%;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  background: white;
  color: var(--text);
}
textarea { resize: vertical; min-height: 96px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-title-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.section-title-row h2 { margin: 0; }
.settings-inline {
  min-width: 32px;
  min-height: 32px;
  padding: 0 8px;
  font-size: 0.9rem;
  border-radius: 10px;
}
.recheck-icon,
.settings-icon {
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  line-height: 1;
}
.location-pick {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.download-select-note {
  grid-column: 1 / -1;
  padding: 4px 2px 0;
  font-size: 0.76rem;
}
.location-card, .search-item, .entry-row {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.location-card {
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.location-card label { display: flex; align-items: center; gap: 10px; font-weight: 700; }
body[data-page="settings"] .location-pick {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px;
  margin: 10px 0;
}
body[data-page="settings"] .location-card {
  padding: 6px 8px;
  border-radius: 10px;
  gap: 6px;
  font-size: 0.88rem;
}
body[data-page="settings"] .location-card input[type="checkbox"] {
  width: 15px;
  height: 15px;
  min-height: 15px;
  margin: 0 4px 0 0;
}
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf2ff;
  color: #214d8f;
  font-size: 0.76rem;
  font-weight: 800;
}
.counts-table {
  display: grid;
  gap: 8px;
}
.counts-row {
  display: grid;
  grid-template-columns: 2fr 120px;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.counts-row strong { display: block; }
.search-results {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.search-item {
  padding: 10px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 60px 40px;
  align-items: center;
  gap: 10px;
}
.details-search-item {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}
.details-view-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #edf2ff;
  color: #214d8f;
  font-size: 0.78rem;
  font-weight: 800;
}
.result-qty {
  min-height: 34px;
  padding: 5px 6px;
  text-align: center;
  font-weight: 800;
}
.search-item-main { min-width: 0; }
.add-icon-button {
  width: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: 999px;
  font-size: 1.2rem;
  line-height: 1;
}
.entry-panel .grid.two.compact {
  gap: 10px;
}
body[data-page="entry"] .entry-panel label {
  gap: 6px;
  font-size: 0.86rem;
  min-width: 0;
}
body[data-page="entry"] .section-head,
body[data-page="entry"] .section-title-row,
body[data-page="entry"] .section-head .muted,
body[data-page="entry"] .section-head h2,
body[data-page="entry"] .table th,
body[data-page="entry"] .table td,
body[data-page="entry"] .page-head h1,
body[data-page="entry"] .page-head p {
  font-size: 0.86rem;
}
body[data-page="entry"] .section-head { margin-bottom: 8px; }
body[data-page="entry"] .section-title-row h2 { font-size: 0.9rem; }
body[data-page="entry"] .settings-inline {
  min-width: 28px;
  min-height: 28px;
  padding: 0 6px;
  font-size: 0.82rem;
}
body[data-page="entry"] .entry-panel input,
body[data-page="entry"] .entry-panel select {
  min-height: 40px;
  padding: 9px 10px;
  border-radius: 10px;
  touch-action: manipulation;
  width: 100%;
}
body[data-page="entry"] .entry-panel input[type="date"] {
  padding-right: 8px;
}
body[data-page="entry"] .entry-panel {
  padding-bottom: 14px;
}

.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}
.table th, .table td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}
.table th { font-size: 0.92rem; color: #374151; }
.table td input {
  min-height: 40px;
  padding: 10px 12px;
}
.recheck-table .check-col {
  width: 62px;
  text-align: center;
}
.recheck-table input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  vertical-align: middle;
  accent-color: var(--primary);
}
.recheck-table tr.is-reviewed {
  background: #f5fbf7;
}
.recheck-table .edit-col {
  width: 48px;
  text-align: center;
}
.recheck-edit-link {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
}
.recheck-edit-link:hover,
.recheck-edit-link:focus-visible {
  border-color: var(--primary);
  background: #fff1f2;
}
body[data-page="entry"] #entriesTable tr.linked-entry-highlight {
  background: #fff1b8;
  box-shadow: inset 4px 0 0 var(--primary);
}
.recheck-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 12px;
}
.recheck-filters label {
  gap: 6px;
  font-size: 0.82rem;
}
.recheck-filters input {
  min-height: 40px;
  padding: 9px 10px;
  font-size: 0.94rem;
}

.entry-list-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin: 0 0 12px;
}
.entry-list-filters label {
  gap: 6px;
  min-width: 0;
  font-size: 0.82rem;
}
.entry-list-filters input {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  font-size: 0.94rem;
}
.entry-list-filters .button {
  min-height: 40px;
  white-space: nowrap;
}

body.preview-open { overflow: hidden; }
.stock-print-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: #fff;
}
.stock-print-preview-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.stock-print-preview-loading {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  font-weight: 700;
}

@media print {
  body {
    background: white;
  }
  .topbar,
  .page-head-actions,
  .recheck-filters,
  #toast {
    display: none !important;
  }
  .shell {
    padding-top: 0;
    max-width: none;
  }
  .card {
    box-shadow: none;
    border: 0;
    padding: 0;
    margin: 0;
  }
  .table-wrap {
    overflow: visible;
  }
  .recheck-table {
    min-width: 0;
  }
  .recheck-table th,
  .recheck-table td {
    padding: 8px 6px;
  }
  .recheck-table .check-col {
    display: none;
  }
}

.details-table .summary-total {
  background: #f8fafc;
}
.details-summary-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.details-summary-row {
  background: #fff;
}
.details-summary-row td {
  vertical-align: middle;
}
.details-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}
.details-toggle-caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  font-size: 1.05rem;
  line-height: 1;
}
.details-child-row td {
  padding: 0 10px 12px;
  border-bottom: 1px solid var(--line);
}
.details-child-wrap {
  background: #f9fbff;
  border: 1px solid #dbe7ff;
  border-radius: 12px;
  padding: 10px;
}
.details-child-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 8px;
}
.details-subtable {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
}
.details-subtable th,
.details-subtable td {
  border-bottom: 1px solid rgba(217, 222, 231, 0.8);
  padding: 8px 8px;
  text-align: left;
  vertical-align: top;
  font-size: 0.85rem;
}
.details-subtable th {
  color: #374151;
}
.details-detail-row:last-child td {
  border-bottom: 0;
}
.details-entry-link {
  color: #1d4ed8;
  font-weight: 700;
  text-decoration: none;
}
.details-entry-link:hover,
.details-entry-link:focus {
  text-decoration: underline;
}
.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.refresh-actions {
  align-items: center;
  justify-content: flex-end;
}
.refresh-counts-meta {
  font-size: 0.78rem;
  white-space: nowrap;
}
.product-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.product-actions .button {
  flex: 1 1 0;
  min-width: 0;
}
.template-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-start;
}
.product-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin: 6px 0 8px;
}
.product-filter-label {
  gap: 6px;
}
.product-filter-label span {
  font-size: 0.8rem;
}
.product-filter-meta {
  font-size: 0.8rem;
  text-align: right;
  white-space: nowrap;
}
.product-help {
  font-size: 0.82rem;
  margin-bottom: 10px;
}
.callout-inline {
  padding: 10px 12px;
  margin: 6px 0 10px;
  border: 1px solid #dbe7ff;
  border-radius: 12px;
  background: #f8fbff;
  color: #334155;
  font-size: 0.82rem;
  line-height: 1.35;
}
.product-editor-table tr[hidden] {
  display: none;
}
.button.small {
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}
.button.danger { background: #fee4e2; border-color: #fecdca; color: var(--danger); }
.button.ghost { background: white; border-color: var(--line); }
.sticky-footer-actions { display: flex; justify-content: flex-end; margin-top: 12px; }
.danger-zone {
  border-color: rgba(180, 35, 24, 0.25);
  background: linear-gradient(180deg, rgba(254, 242, 242, 0.8), #fff);
}
.danger-zone h2 {
  color: var(--danger);
}
.danger-confirm {
  gap: 10px;
}
.danger-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}
.danger-row input {
  border-color: #f2c2bd;
  background: #fffdfd;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(92vw, 420px);
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(17, 24, 39, 0.94);
  color: #fff;
  box-shadow: var(--shadow);
}
.alert {
  padding: 12px 14px;
  border-radius: 12px;
}
.alert-error { background: #fee4e2; color: #7a271a; border: 1px solid #fecdca; }
.alert-success { background: #dcfce7; color: #14532d; border: 1px solid #bbf7d0; }
.login-card { max-width: 460px; margin: 48px auto; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: min(86vh, 920px);
  overflow: auto;
  background: #fff;
  border-radius: 20px;
  border: 1px solid rgba(217, 222, 231, 0.95);
  box-shadow: 0 24px 72px rgba(15, 23, 42, 0.24);
  padding: 18px;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.modal-head h2 {
  margin: 0 0 4px;
}
.modal-head p {
  margin: 0;
}
.modal-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.product-editor-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.product-editor-table {
  min-width: 0;
}
.product-editor-table th:last-child,
.product-editor-table td:last-child {
  width: 132px;
  white-space: nowrap;
}
.product-editor-table input {
  min-height: 40px;
  padding: 10px 12px;
}
.product-editor-row-delete {
  min-height: 40px;
}
.product-editor-empty {
  padding: 18px;
  text-align: center;
}

.differences-card { padding: 0; overflow: hidden; }
body[data-page="differences"] .shell { max-width: min(1800px, 98vw); padding-left: 8px; padding-right: 8px; }
.difference-filters { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.4fr) minmax(170px, 0.8fr) minmax(200px, 1fr) auto; gap: 10px; align-items: end; padding: 14px; border-bottom: 1px solid var(--border); }
.difference-filters label { display: grid; gap: 5px; font-size: 0.8rem; font-weight: 700; }
.difference-filters input, .difference-filters select { min-height: 40px; }
.searchable-multiselect { position: relative; }
.searchable-multiselect > input { padding-right: 30px; }
.searchable-multiselect::after { content: "▾"; position: absolute; right: 11px; top: 10px; color: var(--muted); pointer-events: none; }
.multiselect-menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; width: max(100%, 260px); max-height: 280px; overflow-y: auto; padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 28px rgba(31, 41, 55, 0.18); }
.multiselect-option { display: flex !important; grid-template-columns: none !important; flex-direction: row; align-items: center; gap: 8px !important; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 0.8rem !important; font-weight: 600 !important; }
.multiselect-option[hidden] { display: none !important; }
.multiselect-option:hover { background: #eef4fb; }
.multiselect-option input { width: 16px; min-width: 16px; height: 16px; min-height: 16px; margin: 0; padding: 0; }
.multiselect-empty { padding: 9px; font-size: 0.8rem; }
.difference-filter-actions { display: flex; align-items: center; gap: 9px; min-height: 40px; white-space: nowrap; }
.status-option-manager {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 250, 252, 0.72);
}
.status-option-manager-title {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}
.status-option-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 4px 8px 4px 10px;
  font-size: 0.82rem;
  font-weight: 700;
}
.status-option-delete {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
  cursor: pointer;
  font-weight: 900;
  line-height: 1;
}
.status-option-delete:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}
.difference-table-wrap { overflow: auto; max-height: calc(100vh - 190px); }
.difference-table { width: 100%; min-width: 1120px; border-collapse: separate; border-spacing: 0; font-size: 0.78rem; }
.difference-table th, .difference-table td { padding: 7px 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); white-space: nowrap; }
.difference-table th { position: sticky; top: 0; z-index: 2; background: #eef2f7; text-align: center; }
.difference-table th:first-child, .difference-table td:first-child { position: sticky; left: 0; width: 180px; min-width: 180px; max-width: 180px; z-index: 3; background: #fff; overflow: hidden; text-overflow: ellipsis; }
.difference-table th:nth-child(2), .difference-table td:nth-child(2) { position: sticky; left: 180px; width: 205px; min-width: 205px; max-width: 205px; z-index: 3; background: #fff; box-shadow: 3px 0 5px rgba(31, 41, 55, 0.08); overflow: hidden; text-overflow: ellipsis; }
.difference-table th:first-child, .difference-table th:nth-child(2) { z-index: 5; background: #eef2f7; }
.difference-sort-button { width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 800; cursor: pointer; white-space: nowrap; }
.difference-sort-button:hover, .difference-sort-button:focus-visible { color: var(--primary); }
.difference-sort-button .sort-indicator { width: 0.9em; text-align: center; font-size: 0.8em; line-height: 1; color: var(--muted); }
.difference-sort-button.is-sorted .sort-indicator { color: var(--primary); }
.difference-sort-button[data-sort-direction="asc"] .sort-indicator::after { content: "▲"; }
.difference-sort-button[data-sort-direction="desc"] .sort-indicator::after { content: "▼"; }
.difference-table tbody tr:nth-child(even) td { background: #f8fafc; }
.difference-table tbody tr:hover td { background: #fff7d6 !important; }
.difference-table tbody tr:hover { cursor: default; }
.difference-table .number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.difference-table .code-cell, .difference-table .total-cell { font-weight: 700; }
.difference-item-link { color: #0f4c81; text-decoration: none; border-bottom: 1px dashed currentColor; }
.difference-item-link:hover, .difference-item-link:focus { color: #1d4ed8; border-bottom-style: solid; }
.difference-table .diff-negative { color: #b91c1c; background: #fef2f2 !important; font-weight: 700; }
.difference-table .diff-positive { color: #1d4ed8; background: #eff6ff !important; font-weight: 700; }
.difference-table .diff-zero { color: #15803d; background: #f0fdf4 !important; font-weight: 700; }
.difference-status { min-width: 155px; min-height: 32px; padding: 5px 7px; font-size: 0.78rem; }
.difference-select { width: 17px; min-width: 17px; height: 17px; min-height: 17px; margin: 0; padding: 0; accent-color: var(--primary); }
.code-heading, .code-with-select { display: flex; align-items: center; gap: 7px; min-width: 0; }
.code-with-select .difference-item-link { overflow: hidden; text-overflow: ellipsis; }
.selected-count { color: var(--primary); font-weight: 800; }

@media (max-width: 860px) {
  .difference-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .difference-filter-actions { grid-column: 1 / -1; justify-content: space-between; }
  .entry-list-filters { display: none; }
  .grid.two { grid-template-columns: 1fr; }
  .page-head, .section-head, .topbar { flex-direction: column; align-items: stretch; }
  .nav { justify-content: flex-start; }
  .counts-row { grid-template-columns: 1fr auto; }
  .page-head-actions {
    width: 100%;
  }
}

@media (max-width: 640px) {
  body[data-page="products"] .page-head,
  body[data-page="locations"] .page-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
  }
  body[data-page="products"] .page-head > div:first-child,
  body[data-page="locations"] .page-head > div:first-child {
    min-width: 0;
    flex: 1 1 auto;
  }
  body[data-page="products"] .page-head h1,
  body[data-page="locations"] .page-head h1 {
    margin-bottom: 2px;
    font-size: 1.02rem;
    line-height: 1.1;
  }
  body[data-page="products"] .page-head p,
  body[data-page="locations"] .page-head p {
    margin: 0;
    font-size: 0.72rem;
    line-height: 1.2;
  }
  body[data-page="products"] .page-head-actions,
  body[data-page="locations"] .page-head-actions {
    width: auto;
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
    align-items: center;
  }
  body[data-page="products"] .page-head-actions .button,
  body[data-page="locations"] .page-head-actions .button {
    width: auto;
    min-width: 0;
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.8rem;
    border-radius: 10px;
    white-space: nowrap;
  }
  body[data-page="products"] .page-head-actions .button.small,
  body[data-page="locations"] .page-head-actions .button.small {
    min-height: 34px;
  }
  body[data-page="products"] .card h2,
  body[data-page="locations"] .card h2 {
    font-size: 0.96rem;
    line-height: 1.15;
  }
  body[data-page="products"] .product-toolbar,
  body[data-page="locations"] .product-toolbar {
    grid-template-columns: 1fr;
    gap: 6px;
    align-items: stretch;
  }
  body[data-page="products"] .product-filter-meta,
  body[data-page="locations"] .product-filter-meta {
    text-align: left;
  }
  body[data-page="products"] .product-help,
  body[data-page="locations"] .product-help {
    font-size: 0.75rem;
    margin-bottom: 8px;
  }
  body[data-page="products"] .callout-inline,
  body[data-page="locations"] .callout-inline {
    padding: 8px 10px;
    margin: 4px 0 8px;
    font-size: 0.74rem;
  }
  body[data-page="products"] .product-editor-table th:last-child,
  body[data-page="products"] .product-editor-table td:last-child,
  body[data-page="locations"] .product-editor-table th:last-child,
  body[data-page="locations"] .product-editor-table td:last-child {
    width: 84px;
  }
  body[data-page="settings"] .page-head {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
  }
  body[data-page="settings"] .page-head > div:first-child {
    min-width: 0;
    flex: 1 1 auto;
  }
  body[data-page="settings"] .page-head h1 {
    margin-bottom: 2px;
    font-size: 1.12rem;
    line-height: 1.1;
  }
  body[data-page="settings"] .page-head p {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.2;
  }
  body[data-page="settings"] .page-head-actions {
    width: auto;
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
    align-items: center;
  }
  body[data-page="settings"] .page-head-actions .button {
    min-height: 34px;
    padding: 6px 10px;
    font-size: 0.82rem;
    border-radius: 10px;
    white-space: nowrap;
  }
  body[data-page="settings"] .page-head-actions .button.small {
    min-height: 34px;
  }
  body[data-page="settings"] .card h2 {
    font-size: 0.98rem;
    line-height: 1.15;
  }
  body[data-page="settings"] .card p.muted,
  body[data-page="settings"] .card .muted {
    font-size: 0.78rem;
    line-height: 1.25;
  }
  body[data-page="settings"] .card {
    padding: 14px;
  }
  body[data-page="settings"] .product-actions {
    gap: 6px;
    flex-wrap: nowrap;
  }
  body[data-page="settings"] .refresh-actions {
    gap: 6px;
  }
  body[data-page="settings"] .refresh-counts-meta {
    font-size: 0.7rem;
  }
  body[data-page="settings"] .product-actions .button {
    width: auto;
    min-width: 0;
    padding: 6px 10px;
    font-size: 0.8rem;
    white-space: nowrap;
  }
  body[data-page="settings"] .template-actions {
    margin-top: 8px;
  }
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    flex-wrap: nowrap;
  }
  .topbar > div {
    min-width: 0;
    flex: 1 1 auto;
  }
  .topbar .subbrand,
  .topbar .navlink:not(.settings-icon):not(.recheck-icon) {
    display: none;
  }
  .topbar .nav {
    margin-left: auto;
    gap: 0;
    flex: 0 0 auto;
  }
  .topbar .settings-icon,
  .topbar .recheck-icon {
    display: inline-flex;
  }
  .topbar .brand {
    display: block;
    font-size: clamp(1rem, 4.8vw, 1.28rem);
    line-height: 1.1;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar .settings-icon {
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    font-size: 1.25rem;
    border-radius: 12px;
  }
  .topbar .recheck-icon {
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    font-size: 1.05rem;
    border-radius: 12px;
  }
  body[data-page="settings"] .location-pick {
    grid-template-columns: 1fr;
    gap: 5px;
    margin: 8px 0;
  }
  body[data-page="settings"] .download-select-note {
    font-size: 0.7rem;
    padding: 2px 0 0;
  }
  body[data-page="settings"] .location-card {
    padding: 7px 8px;
    border-radius: 10px;
    gap: 6px;
  }
  body[data-page="settings"] .location-card > span:first-child {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.84rem;
  }
  body[data-page="settings"] .location-card > span:first-child input[type="checkbox"] {
    width: 15px;
    height: 15px;
    min-height: 15px;
    margin: 0;
    flex: 0 0 auto;
    accent-color: var(--primary);
  }
  body[data-page="settings"] .location-card > span:last-child {
    flex: 0 0 auto;
  }
  body[data-page="settings"] .badge {
    min-width: 28px;
    height: 22px;
    padding: 0 7px;
    font-size: 0.7rem;
  }
  body[data-page="settings"] .counts-table {
    gap: 5px;
  }
  body[data-page="settings"] .counts-row {
    grid-template-columns: 1fr auto;
    gap: 6px;
    padding: 8px 9px;
    border-radius: 10px;
  }
  body[data-page="settings"] .counts-row strong {
    font-size: 0.8rem;
    line-height: 1.15;
  }
  body[data-page="settings"] .counts-row .muted {
    font-size: 0.7rem;
    line-height: 1.1;
  }
  body[data-page="details"] .details-panel {
    padding-bottom: 12px;
  }
  body[data-page="details"] .details-search-item {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 9px 10px;
  }
  body[data-page="details"] .details-view-badge {
    min-width: 46px;
    height: 24px;
    font-size: 0.72rem;
  }
  body[data-page="details"] .details-table th,
  body[data-page="details"] .details-table td {
    padding: 8px 8px;
    font-size: 0.82rem;
  }
  body[data-page="details"] .details-toggle {
    gap: 6px;
    font-size: 0.84rem;
  }
  body[data-page="details"] .details-child-wrap {
    padding: 8px;
  }
  body[data-page="details"] .details-subtable th,
  body[data-page="details"] .details-subtable td {
    padding: 7px 6px;
    font-size: 0.76rem;
  }
  .modal {
    padding: 10px;
  }
  .modal-panel {
    padding: 14px;
    border-radius: 16px;
  }
  .modal-head {
    flex-direction: column;
    align-items: stretch;
  }
  .modal-toolbar {
    flex-direction: column;
  }
  .modal-toolbar .button {
    width: 100%;
  }
  .product-editor-table th:last-child,
  .product-editor-table td:last-child {
    width: 92px;
  }
  .shell { padding: 60px 14px 14px; }
  .card { padding: 14px; border-radius: 16px; }
  .button, .navlink { width: 100%; }
  .topbar .navlink { display: none; }
  body[data-page="entry"] .button,
  body[data-page="entry"] .navlink {
    width: auto;
  }
  body[data-page="entry"] .page-head .icon-button {
    min-width: 34px;
    padding: 4px 8px;
    font-size: 0.95rem;
  }
  body[data-page="entry"] .brand {
    font-size: clamp(1rem, 4.8vw, 1.28rem);
  }
  body[data-page="entry"] .subbrand {
    display: none;
  }
  body[data-page="entry"] .page-head {
    gap: 6px;
    margin-bottom: 10px;
  }
  body[data-page="entry"] .page-head h1,
  body[data-page="entry"] .page-head p {
    display: none;
  }
  body[data-page="entry"] .entry-panel .grid.two.compact {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 24px;
    row-gap: 10px;
    padding-inline: 2px;
    align-items: end;
  }
  body[data-page="entry"] .entry-panel .grid.two.compact > label {
    min-width: 0;
    width: 100%;
  }
  body[data-page="entry"] .entry-panel .grid.two.compact > label:first-child {
    justify-self: start;
    max-width: 100%;
  }
  body[data-page="entry"] .entry-panel .grid.two.compact > label:last-child {
    justify-self: end;
    max-width: 100%;
  }
  body[data-page="entry"] .entry-panel .grid.two.compact > label > input,
  body[data-page="entry"] .entry-panel .grid.two.compact > label > select {
    min-width: 0;
    width: 100%;
  }
  body[data-page="entry"] .entry-panel label {
    gap: 4px;
    font-size: 0.8rem;
  }
  body[data-page="entry"] .entry-panel input,
  body[data-page="entry"] .entry-panel select {
    min-height: 36px;
    padding: 7px 8px;
    border-radius: 9px;
    font-size: 0.86rem;
  }
  body[data-page="entry"] .entry-panel input[type="search"] {
    background: #fffdf4;
    border-color: #d7b95f;
    box-shadow: 0 0 0 3px rgba(215, 185, 95, 0.16);
    font-size: 16px !important;
    font-weight: 700;
  }
  body[data-page="entry"] .entry-panel input[type="search"] {
    min-height: 44px;
    padding: 11px 12px;
  }
  body[data-page="entry"] .entry-panel input[type="search"]::placeholder {
    color: #8a6d1d;
  }
  body[data-page="recheck"] .page-head {
    margin-bottom: 10px;
  }
  body[data-page="recheck"] .page-head h1 {
    font-size: 1.18rem;
    margin-bottom: 2px;
  }
  body[data-page="recheck"] .page-head p {
    font-size: 0.78rem;
    line-height: 1.2;
  }
  body[data-page="recheck"] .page-head .page-head-actions {
    width: auto;
    flex: 0 0 auto;
  }
  body[data-page="recheck"] .page-head .page-head-actions .button {
    width: auto;
    min-width: 0;
    padding: 7px 10px;
    font-size: 0.8rem;
    white-space: nowrap;
  }
  body[data-page="recheck"] .card {
    padding: 12px;
  }
  body[data-page="recheck"] .section-head {
    margin-bottom: 8px;
  }
  body[data-page="recheck"] .section-head h2 {
    font-size: 0.92rem;
  }
  body[data-page="recheck"] .section-head .muted {
    font-size: 0.72rem;
  }
  body[data-page="recheck"] .recheck-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
  }
  body[data-page="recheck"] .recheck-filters label {
    font-size: 0.72rem;
    gap: 4px;
  }
  body[data-page="recheck"] .recheck-filters input {
    min-height: 36px;
    padding: 7px 8px;
    font-size: 0.84rem;
  }
  body[data-page="recheck"] .table {
    min-width: 560px;
  }
  body[data-page="recheck"] .recheck-table th,
  body[data-page="recheck"] .recheck-table td {
    padding: 8px 7px;
    font-size: 0.78rem;
  }
  body[data-page="recheck"] .recheck-table .check-col {
    width: 48px;
  }
  body[data-page="recheck"] .recheck-table input[type="checkbox"] {
    width: 16px;
    height: 16px;
    min-height: 16px;
  }
  .location-pick { grid-template-columns: 1fr; }
  .search-item { grid-template-columns: minmax(0, 1fr) 82px 40px; }
  .result-qty {
    min-width: 82px;
    font-size: 16px !important;
    line-height: 1.1;
    touch-action: manipulation;
  }
  .table { min-width: 640px; }
  .brand { font-size: 0.98rem; }
  .danger-row {
    grid-template-columns: 1fr;
  }
  .danger-row .button {
    width: 100%;
  }
}

/* Final phone overrides must follow the legacy responsive rules above. */
@media (max-width: 640px) {
  .topbar {
    backdrop-filter: none;
  }

  .topbar .nav {
    position: fixed;
    z-index: 50;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    display: flex;
    align-items: stretch;
    gap: 4px;
    margin: 0;
    padding: 7px max(8px, env(safe-area-inset-left)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
  }

  .topbar .nav .navlink.primary-nav-link,
  .topbar .settings-icon,
  .topbar .recheck-icon {
    display: inline-flex;
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    min-height: 48px;
    padding: 6px 4px;
    border-radius: 10px;
    font-size: 0.72rem;
    line-height: 1.1;
  }

  .topbar .user-chip {
    display: none;
  }

  .entry-list-filters {
    display: grid;
  }

  .toast {
    right: 10px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    left: 10px;
    max-width: none;
  }
}
