:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #64748b;
  --line: #d8dee8;
  --panel: #ffffff;
  --soft: #f5f7fb;
  --primary: #0f766e;
  --primary-dark: #115e59;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--soft);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brandBlock {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brandLogo {
  width: 54px;
  height: 54px;
  border: 1px solid #cfd5df;
  border-radius: 50%;
  flex: 0 0 auto;
  object-fit: cover;
}

.topActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbarAction {
  flex: 0 0 auto;
}

.moduleNav {
  display: flex;
  gap: 6px;
  padding: 10px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.moduleTab {
  min-height: 34px;
  white-space: nowrap;
}

.moduleTab.active {
  border-color: var(--primary);
  background: #e7f4f2;
  color: var(--primary-dark);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
}

.brandTitleRow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.environmentBadge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #d8dee8;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.environmentBadge[data-environment="qa"] {
  border-color: #e0a817;
  background: #fff7db;
  color: #8a5a00;
}

.environmentBadge[data-environment="production"],
.environmentBadge[data-environment="prod"] {
  border-color: #b91c1c;
  background: #fef2f2;
  color: #991b1b;
}

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

main {
  padding: 18px 24px 28px;
}

.hidden {
  display: none !important;
}

.loginBody {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #eef3f7;
}

.loginShell {
  width: 100%;
  max-width: 420px;
  padding: 24px;
}

.loginPanel {
  display: grid;
  gap: 14px;
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.12);
}

.loginLogo {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 1px solid #cfd5df;
  object-fit: cover;
}

.loginPanel h1 {
  font-size: 24px;
}

.loginPanel label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.loginPanel input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  color: var(--ink);
}

.googleLoginButton {
  min-height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  background: #fff;
}

.googleLoginButton:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.loginDivider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.loginDivider::before,
.loginDivider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

button, input, select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  cursor: pointer;
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

button.primary:hover {
  background: var(--primary-dark);
}

button.danger {
  border-color: #b42318;
  background: #fff5f5;
  color: #9f1a12;
}

button.danger:hover {
  background: #fee4e2;
}

button:disabled {
  cursor: default;
  opacity: .55;
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.metricButton {
  display: block;
  width: 100%;
  min-height: 72px;
  text-align: left;
  cursor: default;
}

.metricButton[data-filter] {
  cursor: pointer;
}

.metricButton[data-filter]:hover,
.metricButton.active {
  border-color: #e0a817;
  background: #fff7db;
}

.metric strong {
  display: block;
  font-size: 24px;
}

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

.toolbar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 120px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.bulkRuleBar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.bulkRuleBar span {
  min-width: 120px;
  color: var(--muted);
  font-size: 13px;
  line-height: 36px;
}

.bulkRuleBar label {
  min-width: 170px;
}

.bulkRuleBar input,
.bulkRuleBar select {
  min-width: 160px;
}

.bulkRuleBar #bulkRuleFactorInput {
  min-width: 95px;
  width: 95px;
}

.archivedToolbar {
  grid-template-columns: minmax(260px, 1fr) auto;
  margin-bottom: 0;
}

.maintenancePanel {
  max-width: 760px;
}

.maintenanceRestorePanel {
  max-width: 760px;
  margin-top: 12px;
}

.maintenanceRestorePanel .restoreGrid {
  grid-template-columns: 1fr;
}

.maintenanceActions {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.maintenanceActions div {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.maintenanceActions strong {
  display: block;
  margin-bottom: 4px;
}

.maintenanceActions p {
  margin: 0;
  color: #5f6673;
}

.maintenanceWarning {
  border: 1px solid #f2c94c;
  background: #fff8db;
  border-radius: 8px;
  padding: 12px;
}

.maintenanceWarning strong {
  display: block;
  margin-bottom: 4px;
  color: #6b4e00;
}

.maintenanceWarning p {
  margin: 0;
  color: #5f6673;
}

.importPanel .tableWrap {
  margin-top: 0;
}

.importPanel table {
  min-width: 820px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 12px;
}

.panelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panelActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.productForm {
  display: grid;
  grid-template-columns: 140px minmax(260px, 2fr) repeat(4, minmax(130px, 1fr));
  gap: 10px;
  align-items: end;
}

.securityGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
  align-items: end;
}

.securityGrid .checkLabel {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.securityGrid .checkLabel input {
  width: auto;
}

.securityTableWrap table {
  min-width: 720px;
}

.centerCell {
  text-align: center;
}

.selectableRow {
  cursor: pointer;
}

.selectedRow {
  background: #e6f4f1;
}

.productEditModalPanel {
  max-width: min(1160px, calc(100vw - 36px));
}

.productEditForm {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}

.productEditField.wideField {
  grid-column: span 2;
}

.wideField {
  grid-column: 1 / -1;
}

.inlineStatus {
  min-height: 18px;
  margin-top: 10px;
}

.restoreMain {
  max-width: 760px;
  margin: 0 auto;
}

.restorePanel {
  margin-top: 12px;
}

.restoreGrid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.fileDrop {
  min-height: 74px;
  padding: 12px;
  border: 1px dashed #aab5c4;
  border-radius: 8px;
  background: #f8fafc;
}

.fileDrop input {
  padding-top: 7px;
}

.restoreActions {
  display: flex;
  justify-content: flex-end;
}

.progressShell {
  height: 12px;
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2f7;
}

.progressBar {
  width: 0;
  height: 100%;
  background: var(--primary);
  transition: width .18s ease;
}

.restoreResult {
  padding: 12px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  white-space: pre-wrap;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

input, select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0 10px;
  color: var(--ink);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.pager div {
  display: flex;
  gap: 8px;
}

.tableWrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.compactTable {
  margin-top: 12px;
}

.compactTable table {
  min-width: 1050px;
}

.secondTable {
  margin-top: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1900px;
}

.archivedTableWrap table {
  min-width: 980px;
}

.productRulesTableWrap table {
  min-width: 1080px;
}

.reportStats {
  margin-bottom: 0;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.reportSelector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.reportTypeButton.active {
  border-color: var(--primary);
  background: #e7f7f4;
  color: #075d55;
  font-weight: 700;
}

.reportFilters {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr)) auto auto minmax(120px, auto);
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}

.reportSection {
  margin-bottom: 14px;
}

.reportTableWrap table {
  min-width: 1500px;
}

.staleReportTableWrap table {
  min-width: 980px;
}

.staleReportProvider {
  max-width: 170px;
}

.staleReportCategory {
  max-width: 160px;
}

.reportTableWrap td.numCell,
.reportTableWrap th.numCell {
  text-align: right;
}

.reportDescription {
  min-width: 300px;
}

.staleReportDescription {
  min-width: 360px;
}

.reportReason {
  min-width: 260px;
  color: #4b5563;
}

.reportDifference {
  font-weight: 700;
  color: #92400e;
}

.emptyReportRow {
  text-align: center;
  color: var(--muted);
  padding: 18px 10px;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid #edf1f6;
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #e9f1f7;
  font-weight: 700;
}

.sortButton {
  display: block;
  width: 100%;
  min-height: 24px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font-weight: 700;
}

.sortButton.active {
  color: #084c61;
}

th.focusHeader {
  background: #f8d77a;
  color: #3d2b00;
}

th:nth-child(1),
td:nth-child(1) {
  min-width: 42px;
  width: 42px;
  text-align: center;
}

th:nth-child(2),
td:nth-child(2) {
  min-width: 140px;
}

th:nth-child(3),
td:nth-child(3) {
  min-width: 290px;
}

th:nth-child(4),
td:nth-child(4),
th:nth-child(5),
td:nth-child(5) {
  min-width: 140px;
}

.selectCell input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
}

td.num {
  text-align: right;
}

td.priceFocus {
  background: #fff3bf;
  color: #111827;
  font-weight: 700;
  border-left: 1px solid #e7bd45;
  border-right: 1px solid #e7bd45;
}

.cellInput {
  width: 100%;
  min-width: 92px;
  height: 30px;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  padding: 0 6px;
}

.cellInput:focus {
  border-color: #0f766e;
  background: #fff;
  outline: none;
}

.numCell .cellInput,
.priceFocus .cellInput {
  text-align: right;
}

.codeCell .cellInput {
  min-width: 120px;
}

.descriptionCell .cellInput {
  min-width: 260px;
}

.actionCell {
  display: flex;
  gap: 6px;
  align-items: center;
}

.modalOverlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(15, 23, 42, .45);
}

.ruleModalPanel {
  width: min(1180px, 96vw);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24);
}

.ruleModalPanel .inlineStatus {
  margin-top: 0;
  line-height: 36px;
}

.ruleSelect,
.ruleFactor {
  min-width: 180px;
}

.ruleFactor:disabled {
  background: #f8fafc;
  color: #94a3b8;
}

.ruleOrigin {
  color: var(--muted);
}

.ruleLiveValue.priceLiveValue {
  background: #fff3bf;
  font-weight: 700;
}

.ruleStatusIssue {
  color: #9f1a12;
  font-weight: 700;
}

.archivedRow td {
  color: #475569;
  background: #fbfcfe;
}

.archivedDate {
  color: var(--muted);
}

.urlCell .cellInput {
  min-width: 320px;
}

.urlIssueCell {
  background: #fff1f2;
}

.urlIssueCell .cellInput {
  color: #7f1d1d;
  font-weight: 700;
}

.recalcIssueRow td {
  background: #fff7ed;
}

.recalcIssueRow .priceFocus {
  background: #fed7aa;
}

.readonlyCell {
  display: inline-block;
  min-width: 86px;
}

.staleDateCell {
  background: #fff7db;
  color: #7a4a00;
  font-weight: 700;
}

.actionCell {
  position: sticky;
  right: 0;
  background: #fff;
  box-shadow: -1px 0 0 #edf1f6;
}

.saveRowButton {
  min-height: 30px;
}

.ruleChoice {
  min-width: 220px;
}

.ruleFactorInput {
  margin-top: 6px;
  min-width: 120px;
}

.liveValue {
  min-width: 150px;
  text-align: right;
  font-weight: 700;
}

.livePriceFocus {
  background: #fff3bf;
  color: #111827;
  border-left: 1px solid #e7bd45;
  border-right: 1px solid #e7bd45;
}

.missingLiveValue {
  color: var(--muted);
  font-weight: 400;
}

tr.dirty td {
  background: #fffdf2;
}

tr.dirty .saveRowButton {
  border-color: #0f766e;
  color: #0f766e;
  font-weight: 700;
}

tr:hover td {
  background: #f8fafc;
}

tr:hover td.priceFocus {
  background: #ffe59b;
}

tr:hover .actionCell {
  background: #f8fafc;
}

.printControls {
  margin-bottom: 12px;
}

.printPreviewSheet {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  padding: 10px;
}

.printTable {
  width: max-content;
  min-width: 0;
  table-layout: auto;
  border-collapse: collapse;
  border: 1px solid #111827;
}

.printTable th,
.printTable td {
  border: 1px solid #9ca3af;
  color: #111827;
  font-size: 11px;
  line-height: 1.15;
  min-width: 0;
  padding: 4px 5px;
  white-space: nowrap;
}

.printTable th {
  position: static;
  background: #dbeafe;
  text-transform: uppercase;
}

.printTable .printCategoryRow td {
  background: #fde68a;
  border-top: 2px solid #111827;
  border-bottom: 2px solid #111827;
  font-weight: 700;
  text-transform: uppercase;
}

.printCategoryGroup {
  break-inside: avoid;
  page-break-inside: avoid;
}

.printCategoryRow {
  break-after: avoid;
  page-break-after: avoid;
}

.print_category,
.print_code,
.print_provider_internal_code,
.print_cost,
.print_profit_factor,
.print_sale_price,
.print_wholesale_price,
.print_presentation {
  width: 1%;
}

.print_provider_internal_code {
  text-align: center;
}

.print_description {
  width: auto;
}

.print_cost,
.print_profit_factor,
.print_sale_price,
.print_wholesale_price {
  text-align: right;
}

.printTable .print_cost,
.printTable .print_profit_factor {
  color: #6b7280;
  font-size: 7px;
}

.printTable .print_sale_price {
  font-weight: 700;
}

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topActions { justify-content: flex-start; }
  .panelHeader { align-items: flex-start; flex-direction: column; }
  .panelActions { justify-content: flex-start; }
  .stats { grid-template-columns: repeat(2, minmax(140px, 1fr)); }
  .toolbar { grid-template-columns: 1fr; }
  .productForm { grid-template-columns: 1fr; }
  .maintenanceActions { grid-template-columns: 1fr; }
  .restoreGrid { grid-template-columns: 1fr; }
  .restoreActions { justify-content: stretch; }
  .restoreActions button { width: 100%; }
  .pager { align-items: flex-start; flex-direction: column; }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 3mm;
  }

  body {
    background: #fff;
  }

  .topbar,
  .moduleNav,
  .printControls,
  #stockView,
  #newProductView,
  #rulesView {
    display: none !important;
  }

  main {
    padding: 0;
  }

  #printView {
    display: block !important;
  }

  body:not(.printingReports) .moduleView {
    display: none !important;
  }

  body:not(.printingReports) #printView {
    display: block !important;
  }

  body.printingReports .moduleView,
  body.printingReports #printView {
    display: none !important;
  }

  body.printingReports #reportsView {
    display: block !important;
  }

  body.printingReports #reportsView > .panel {
    display: none !important;
  }

  body.printingReports #calculationsReportSections {
    display: block !important;
  }

  body.printingReports .reportSection {
    display: block !important;
    margin: 0;
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  body.printingReports .reportSection .panelHeader {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4mm;
  }

  body.printingReports .reportSection h2 {
    margin: 0;
    font-size: 13pt;
  }

  body.printingReports [data-report-section="stale_price"] .reportPrintHeader {
    align-items: baseline;
    margin-bottom: 2mm;
  }

  body.printingReports [data-report-section="stale_price"] .reportPrintHeader h2 {
    font-size: 10pt;
  }

  body.printingReports [data-report-section="stale_price"] .reportPrintHeader .inlineStatus {
    min-height: 0;
    margin-top: 0;
    font-size: 8pt;
  }

  body.printingReports .reportTableWrap {
    border: 0;
    border-radius: 0;
    overflow: visible;
  }

  body.printingReports .reportTableWrap table {
    width: 100%;
    min-width: 0;
    table-layout: auto;
  }

  body.printingReports .reportTableWrap thead {
    display: table-header-group;
  }

  body.printingReports .reportTableWrap tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body.printingReports .reportTableWrap th,
  body.printingReports .reportTableWrap td {
    border-color: #333;
    font-size: 7.2pt;
    line-height: 1.08;
    padding: 2.2px 2.5px;
    white-space: nowrap;
  }

  body.printingReports .reportTableWrap th {
    background: #e5e7eb !important;
  }

  body.printingReports .staleReportTableWrap table {
    width: 100%;
    min-width: 0;
    table-layout: auto;
    border-collapse: collapse;
  }

  body.printingReports .staleReportTableWrap th,
  body.printingReports .staleReportTableWrap td {
    min-width: 0 !important;
    overflow: visible;
    font-size: 7.6pt;
    line-height: 1.1;
    padding: 2.2px 3px;
    white-space: nowrap;
    word-break: normal;
    overflow-wrap: normal;
    vertical-align: middle;
  }

  body.printingReports .staleReportCodeCol {
    width: 1%;
  }

  body.printingReports .staleReportDescriptionCol {
    width: auto;
  }

  body.printingReports .staleReportProviderCol {
    width: 1%;
  }

  body.printingReports .staleReportCategoryCol {
    width: 1%;
  }

  body.printingReports .staleReportPackPriceCol,
  body.printingReports .staleReportBlankCol {
    width: 22mm;
  }

  body.printingReports .staleReportDateCol {
    width: 18mm;
  }

  body.printingReports .staleReportDescription {
    white-space: normal;
  }

  body.printingReports .staleReportProvider,
  body.printingReports .staleReportCategory,
  body.printingReports .staleReportPackPrice,
  body.printingReports .staleReportDate,
  body.printingReports .staleReportBlank {
    max-width: none;
    min-width: 0;
  }

  .printPreviewSheet {
    border: 0;
    border-radius: 0;
    overflow: visible;
    padding: 0;
  }

  .printTable {
    width: 100%;
    min-width: 0;
    table-layout: auto;
  }

  .printTable thead {
    display: table-header-group;
  }

  .printCategoryGroup {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .printTable tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .printTable th,
  .printTable td {
    border-color: #333;
    font-size: 7pt;
    line-height: 1.05;
    padding: 1.8px 2px;
    white-space: nowrap;
  }

  .printTable th {
    background: #e5e7eb !important;
  }

  .printTable .printCategoryRow td {
    background: #f3f4f6 !important;
    border-top: 1.5pt solid #111;
    border-bottom: 1pt solid #111;
  }

  .printTable .print_cost,
  .printTable .print_profit_factor {
    color: #666 !important;
    font-size: 4.6pt;
  }

  .printTable .print_sale_price {
    font-weight: 700;
  }
}
