:root {
  color-scheme: light;
  --bg: #f3f0e8;
  --ink: #0a0a09;
  --muted: #6f6a60;
  --line: #ddd7cb;
  --panel: #fffdf8;
  --blue: #0a0a09;
  --green: #13795b;
  --red: #b42318;
  --cream: #f3f0e8;
}

* {
  box-sizing: border-box;
}

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

body.locked .topbar,
body.locked .appShell {
  display: none;
}

.loginScreen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: var(--cream);
  padding: 20px;
}

.loginCard {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 20px 48px rgba(23, 32, 51, .14);
}

.loginBrand {
  display: flex;
  justify-content: center;
  padding: 6px 0 8px;
}

.loginBrand img {
  width: 180px;
  max-width: 70%;
  display: block;
}

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

.accountBox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.accountBox .status {
  border: 0;
  padding: 0 8px 0 10px;
  font-size: 13px;
  font-weight: 700;
}

.accountBox button {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
}

#apiStatus {
  display: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--cream);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}

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

.brandMark img {
  width: 92px;
  height: 64px;
  object-fit: contain;
  border-radius: 6px;
}

.brandMark strong {
  color: var(--ink);
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 18px;
}

p, span, .muted {
  color: var(--muted);
}

main {
  min-width: 0;
  width: 100%;
  margin: 0;
}

.appShell {
  width: min(1480px, calc(100% - 24px));
  margin: 14px auto 36px;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 86px;
  max-height: calc(100dvh - 102px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  display: grid;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.sidebar::-webkit-scrollbar {
  width: 8px;
}

.sidebar::-webkit-scrollbar-thumb {
  background: #c7c2b8;
  border-radius: 8px;
}

.marketplacePanel summary {
  font-size: 14px;
}

.sidebarTitle {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  padding: 4px 2px 6px;
}

.sideNav {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  background: #f8f5ee;
  color: var(--ink);
  border: 1px solid var(--line);
}

.sideNav.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.sidePanel {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.legacyInvoicePanel {
  display: none;
}

.sidePanel summary {
  min-height: 36px;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  list-style-position: inside;
}

.sideActions,
.sideControls {
  display: grid;
  gap: 8px;
  padding: 4px 0 8px;
}

.sideForm {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.sideActions button,
.sideControls button {
  width: 100%;
  justify-content: center;
}

.sideControls label {
  font-size: 12px;
}

.sideControls small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.sideStatus .status,
.sideStatus span {
  width: 100%;
  display: block;
  text-align: center;
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 14px;
  white-space: nowrap;
}

.status.ok {
  border-color: #9bd4c2;
  color: var(--green);
}

.status.warn {
  border-color: #f6c6c2;
  color: var(--red);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.tab {
  background: #eef3fb;
  color: var(--blue);
  border: 1px solid #c9d9f2;
}

.tab.active {
  background: var(--blue);
  color: #fff;
}

.hidden {
  display: none !important;
}

body[data-role="warehouse"] [data-admin-only] {
  display: none !important;
}

.metrics div,
.panel,
.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics div {
  padding: 8px 10px;
}

.metrics strong {
  display: block;
  font-size: 17px;
  margin-bottom: 1px;
}

.metrics span {
  font-size: 11px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.notice {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  color: var(--muted);
}

.notice strong {
  color: var(--green);
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  padding: 0 14px;
  cursor: pointer;
}

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

button.secondary {
  background: #f8f5ee;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.dangerButton {
  background: #fff1f0;
  color: var(--red);
  border: 1px solid #f6c6c2;
}

.panel {
  padding: 12px;
  margin-top: 10px;
}

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

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

.autocompleteWrap {
  position: relative;
  display: block;
  width: 100%;
  color: inherit;
}

.autocompleteResults {
  position: absolute;
  z-index: 8;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  min-width: min(560px, calc(100vw - 48px));
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(23, 32, 51, .15);
  padding: 6px;
}

.autocompleteItem {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 42px minmax(220px, 1fr) auto;
  gap: 10px;
  align-items: center;
  background: #fff;
  color: var(--ink);
  border: 0;
  border-radius: 6px;
  text-align: left;
  padding: 6px;
}

.autocompleteItem:hover {
  background: #f4f7fb;
}

.autocompleteItem .productImage,
.autocompleteItem .imageFallback {
  width: 42px;
  height: 54px;
}

.autocompleteItem span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.autocompleteItem strong,
.autocompleteItem small {
  overflow-wrap: anywhere;
}

.autocompleteItem strong {
  color: var(--ink);
  line-height: 1.25;
}

.autocompleteItem small {
  color: var(--muted);
}

.autocompleteItem b {
  color: var(--green);
  white-space: nowrap;
}

.autocompleteEmpty {
  padding: 14px;
  color: var(--muted);
  text-align: center;
}

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

.sectionHead input {
  max-width: 320px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(170px, 220px) minmax(160px, 220px) minmax(190px, 240px) minmax(220px, 320px);
  gap: 10px;
}

.hbFilters {
  grid-template-columns: minmax(170px, 220px) minmax(240px, 360px);
}

.tableWrap {
  overflow: auto;
}

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

th, td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
}

tr.stockMismatch {
  background: #fff8f7;
}

.stockColumn,
.stockValue,
.stockCell {
  text-align: center;
  width: 116px;
}

.stockValue {
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
}

.stockValue span {
  display: block;
}

.marketLink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 22px;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  text-decoration: none;
}

.marketLink:hover {
  border-color: var(--blue);
  background: #eef4ff;
}

.stockValue.warn {
  color: var(--red);
}

.hbStock {
  color: var(--green);
}

.priceValue {
  font-size: 18px;
  color: var(--ink);
}

.unmatchedCell {
  text-align: center;
  width: 116px;
  color: var(--muted);
  font-size: 12px;
  padding-top: 18px;
}

.productImage {
  width: 58px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #eef1f6;
  display: block;
}

.imageFallback {
  width: 58px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef1f6;
}

.hbFallback {
  display: grid;
  place-items: center;
  color: #f56600;
  font-size: 15px;
  font-weight: 800;
}

.matchBadge {
  display: inline-block;
  color: var(--green);
  font-weight: 700;
  margin-bottom: 4px;
}

.compactButton {
  min-height: 30px;
  padding: 5px 10px;
  margin-bottom: 4px;
}

.matchDialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(720px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
}

.matchDialog::backdrop {
  background: rgba(24, 32, 48, .45);
}

.matchDialogHead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px 12px;
  border-bottom: 1px solid var(--line);
}

.matchDialogHead h2,
.matchDialogHead p {
  margin: 0;
}

.iconButton {
  width: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.matchSearch {
  width: calc(100% - 40px);
  margin: 16px 20px 10px;
}

.matchResults {
  max-height: 520px;
  overflow-y: auto;
  padding: 0 20px 20px;
}

.matchResult {
  width: 100%;
  min-height: 92px;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 72px;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: white;
  color: var(--ink);
  text-align: left;
}

.matchResult:hover {
  background: #f6f8fb;
}

.matchResultInfo {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.matchResultInfo strong,
.matchResultInfo span,
.matchResultInfo small {
  overflow-wrap: anywhere;
}

.matchResultInfo span,
.matchResultInfo small {
  color: var(--muted);
}

.matchResultStock {
  color: var(--green);
  font-weight: 700;
  text-align: right;
}

.emptyState {
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
}

@media (max-width: 600px) {
  .matchResult {
    grid-template-columns: 58px minmax(0, 1fr);
  }

  .matchResultStock {
    grid-column: 2;
    text-align: left;
  }
}

.productTitle {
  font-size: 15px;
  line-height: 1.35;
}

.statusLine {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.statePill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.statePill.ok {
  color: var(--green);
  border-color: #9bd4c2;
  background: #f3fbf8;
}

.statePill.warn {
  color: var(--red);
  border-color: #f6c6c2;
  background: #fff7f6;
}

.statePill.closed {
  color: #7a4c00;
  border-color: #f1d08a;
  background: #fff8e6;
}

.productCodes {
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
  word-break: break-word;
}

.stockEditor {
  display: inline-grid;
  grid-template-columns: 24px 52px 24px;
  gap: 3px;
  align-items: center;
  justify-content: center;
  width: 106px;
}

.stockEditor .stockButton {
  width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  background: #eef3fb;
  color: var(--blue);
  border: 1px solid #c9d9f2;
}

.stockEditor .stockInput {
  min-height: 34px;
  height: 34px;
  text-align: center;
  font-weight: 700;
  font-size: 24px;
  padding: 0 4px;
  border-color: transparent;
  background: transparent;
  max-width: 64px;
  -moz-appearance: textfield;
}

.stockInput::-webkit-outer-spin-button,
.stockInput::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.movementList {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.compactList {
  max-height: 340px;
  overflow: auto;
  margin-top: 4px;
}

.movement {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.movement:last-child {
  border-bottom: 0;
}

.pendingList {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.invoiceForm,
.pdfForm,
.inboundForm,
.userForm {
  display: grid;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-top: 14px;
}

.invoiceForm {
  grid-template-columns: 1.1fr 1fr 1fr 1.5fr .6fr auto;
}

.pdfForm {
  grid-template-columns: minmax(260px, 1fr) auto;
}

.inboundForm {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.userForm {
  grid-template-columns: 1fr 1fr minmax(180px, .6fr) auto;
}

.invoiceCenterHead p {
  margin-top: 4px;
  font-size: 13px;
}

.monthPicker {
  display: grid;
  gap: 5px;
  min-width: 380px;
}

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

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

.monthNavigator select {
  min-width: 150px;
}

.monthNavigator .iconButton {
  flex: 0 0 36px;
  font-size: 22px;
}

.invoiceSummary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-top: 14px;
}

.invoiceSummary div {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border-right: 1px solid var(--line);
}

.invoiceSummary div:last-child {
  border-right: 0;
}

.invoiceSummary span {
  font-size: 12px;
}

.invoiceSummary strong {
  font-size: 20px;
}

.invoiceSummary .accountingBand {
  border-left: 3px solid #26734d;
}

.invoiceSummary .saleBand {
  border-left-color: #315ea8;
}

.invoiceSummary .vatBalance {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  border-right: 0;
  background: #f7f5ef;
}

.negativeBalance {
  color: #26734d;
}

.reportHead p {
  margin-top: 4px;
  font-size: 13px;
}

.reportControls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reportControls select {
  min-width: 150px;
}

.dateRangeControl {
  display: grid;
  gap: 4px;
}

.dateRangeControl span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.dateRangeControl input {
  min-width: 145px;
}

.reportKpis {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-top: 14px;
}

.reportKpis > div {
  display: grid;
  gap: 6px;
  padding: 15px;
  border-right: 1px solid var(--line);
}

.reportKpis > div:last-child {
  border-right: 0;
}

.reportKpis span,
.profitFlow span,
.reportAccounting span {
  color: var(--muted);
  font-size: 12px;
}

.reportKpis strong {
  font-size: 20px;
}

.reportKpis .primaryKpi {
  background: #f5f3ed;
}

.profitFlow {
  display: grid;
  grid-template-columns: repeat(9, auto);
  align-items: stretch;
  gap: 8px;
  padding: 18px 0;
  overflow-x: auto;
}

.profitFlow > div {
  display: grid;
  gap: 5px;
  min-width: 145px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.profitFlow .flowResult {
  border-color: #26734d;
  background: #f1f7f3;
}

.flowOperator {
  align-self: center;
  font-size: 22px !important;
  font-weight: 800;
  color: #161616 !important;
}

.reportAccounting {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 20px;
}

.reportAccounting > div {
  display: grid;
  gap: 5px;
  padding: 13px 15px;
  border-right: 1px solid var(--line);
}

.reportAccounting p {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px 15px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
  background: #faf9f6;
}

.reportTableHead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.reportTableHead h3 {
  margin: 0;
}

.financeTable {
  width: 100%;
  min-width: 760px;
  table-layout: fixed;
}

.financeTable th,
.financeTable td {
  white-space: nowrap;
}

.financeTable th:first-child,
.financeTable td:first-child {
  width: 140px;
  text-align: left;
}

.profitabilityNotice {
  margin-top: 14px;
  padding: 11px 14px;
  border-left: 3px solid #26734d;
  background: #f1f7f3;
  font-size: 13px;
}

.profitabilityNotice.warn {
  border-left-color: #b45309;
  background: #fff8eb;
}

.financeKpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.financeKpis > div {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding: 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.financeKpis > div:nth-child(4n) {
  border-right: 0;
}

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

.financeKpis strong {
  font-size: 19px;
  overflow-wrap: anywhere;
}

.financeKpis .primaryKpi {
  background: #f5f3ed;
}

.profitExpenseStrip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin: 18px 0;
  border: 1px solid var(--line);
}

.profitExpenseStrip > div {
  display: grid;
  gap: 4px;
  padding: 11px 13px;
  border-right: 1px solid var(--line);
}

.profitExpenseStrip > div:last-child {
  border-right: 0;
}

.profitTools {
  display: grid;
  grid-template-columns: auto minmax(220px, 360px) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  margin: 14px 0 9px;
}

.profitTools input[type="search"] {
  width: 100%;
}

.profitabilityTable {
  min-width: 1620px;
  table-layout: fixed;
}

.profitColProduct {
  width: 310px;
}

.profitColStock,
.profitColQuantity,
.profitColMargin {
  width: 82px;
}

.profitColMoney {
  width: 125px;
}

.profitColEditor {
  width: 330px;
}

.profitabilityTable th,
.profitabilityTable td {
  box-sizing: border-box;
}

.profitabilityTable thead th {
  vertical-align: middle;
  white-space: nowrap;
}

.profitabilityTable th:first-child,
.profitabilityTable td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--line);
}

.profitabilityTable thead th:first-child {
  z-index: 2;
}

.profitProduct {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.profitProduct img,
.profitProduct .imageFallback {
  width: 46px;
  height: 56px;
  border-radius: 4px;
  object-fit: contain;
  background: #f5f3ed;
}

.profitProduct div:last-child {
  min-width: 0;
}

.profitProduct strong,
.profitProduct span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profitProduct span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.costEditor {
  display: grid;
  grid-template-columns: 88px 58px 118px 58px;
  gap: 5px;
  align-items: center;
}

.costEditor input,
.costEditor select,
.costEditor button {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 5px 7px;
  font-size: 11px;
}

.missingCost {
  color: #b45309;
  font-weight: 800;
}

.negativeProfit {
  color: #b42318;
}

.positiveProfit {
  color: #26734d;
}

@media (max-width: 900px) {
  .invoiceCostSuggestion {
    grid-template-columns: 1fr;
    gap: 9px;
    padding: 11px 0;
    -webkit-text-size-adjust: 100%;
  }

  .invoiceCostSource {
    gap: 4px;
  }

  .invoiceCostSource span,
  .invoiceCostSource small {
    font-size: 11px;
    line-height: 1.25;
  }

  .invoiceCostSource strong {
    font-size: 14px;
    line-height: 1.25;
  }

  .invoiceCostArrow {
    display: none;
  }

  .invoiceCostActions button {
    flex: 1;
  }

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

  .financeKpis > div:nth-child(2n) {
    border-right: 0;
  }

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

  .profitExpenseStrip > div {
    border-bottom: 1px solid var(--line);
  }

  .profitExpenseStrip > div:nth-child(2n) {
    border-right: 0;
  }

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

.financeTable th:nth-child(2),
.financeTable td:nth-child(2) {
  width: 90px;
  text-align: center;
}

.financeTable th:nth-child(n + 3),
.financeTable td:nth-child(n + 3) {
  text-align: right;
}

.purchaseInvoiceForm {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 10px;
  align-items: end;
  margin-top: 18px;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--line);
}

.purchaseInvoiceForm .formSectionTitle {
  grid-column: 1 / -1;
  font-size: 15px;
  font-weight: 800;
}

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

.purchaseInvoiceForm small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.invoiceUploadForm {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--line);
}

.invoiceUploadForm .formSectionTitle {
  font-size: 15px;
  font-weight: 800;
}

.invoiceUploadHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.directionControl {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.directionControl label {
  cursor: pointer;
}

.directionControl input {
  position: absolute;
  width: 1px;
  min-height: 0;
  opacity: 0;
}

.directionControl span {
  display: block;
  padding: 8px 18px;
  color: var(--muted);
  background: #fff;
}

.directionControl input:checked + span {
  color: #fff;
  background: var(--ink);
}

.invoiceDirection {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  color: #26734d;
  background: #e8f4ed;
}

.invoiceDirection.sale {
  color: #315ea8;
  background: #eaf0fa;
}

.documentPicker {
  min-height: 92px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 16px;
  border: 1px dashed #9b9488;
  border-radius: 8px;
  background: #faf8f3;
  color: var(--ink);
  cursor: pointer;
}

.documentPicker > span {
  color: var(--ink);
  font-weight: 800;
}

.documentPicker input {
  flex: 1 1 300px;
  width: auto;
  max-width: 100%;
  padding: 8px;
}

.documentPicker small {
  color: var(--muted);
}

.invoiceAnalyzeStatus {
  min-height: 22px;
  font-size: 13px;
}

.invoiceAnalyzeStatus.analyzing {
  color: #8a5a00;
}

.invoiceAnalyzeStatus.success {
  color: var(--green);
}

.invoiceAnalyzeStatus.duplicate {
  color: var(--red);
}

.invoiceDuplicateWarning {
  padding: 12px 14px;
  border: 1px solid #f6c6c2;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--red);
  font-weight: 700;
}

.invoiceAnalysisPanel {
  display: grid;
  gap: 14px;
  padding-top: 6px;
}

.invoiceAnalysisPanel.hidden {
  display: none;
}

.analysisTitle,
.detectedItemsHead,
.analysisActions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.analysisFields {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
}

.analysisMeta {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.invoiceDetectedItems {
  display: grid;
  border-top: 1px solid var(--line);
}

.detectedInvoiceItem {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) 90px minmax(260px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detectedInvoiceItem strong {
  display: block;
  color: var(--ink);
}

.matchStatus {
  align-self: center;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.matchStatus.matched {
  color: var(--green);
}

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

.analysisActions small {
  color: var(--muted);
}

.invoiceSection {
  margin-top: 22px;
}

.compactHead {
  margin-bottom: 8px;
}

.numberCell,
.moneyCell {
  text-align: right;
  white-space: nowrap;
}

.invoiceMissing {
  color: var(--red);
  font-weight: 800;
}

.documentLink {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #f8f5ee;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.pendingItem {
  display: grid;
  grid-template-columns: 58px 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.compactList .pendingItem {
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
}

.compactList .pendingItem .productImage,
.compactList .pendingItem .imageFallback {
  width: 42px;
  height: 54px;
}

.compactList .pendingActions {
  grid-column: 1 / -1;
}

.compactList .movement {
  grid-template-columns: 1fr;
  gap: 4px;
  font-size: 12px;
}

.inboundList,
.userList {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.inboundItem {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 150px;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.shipmentProgress {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
  font-size: 13px;
}

.shipmentProgress strong {
  color: var(--green);
}

.receiveBox {
  display: grid;
  gap: 8px;
}

.inboundEdit {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 110px 150px 90px minmax(140px, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.inboundCostSummary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.inboundCostSummary strong {
  color: var(--text);
}

.inboundEdit input {
  min-height: 34px;
}

.userItem {
  display: grid;
  grid-template-columns: minmax(180px, .8fr) minmax(0, 2fr);
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.userEdit {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(110px, 1fr) minmax(140px, .8fr) auto auto auto;
  gap: 8px;
  align-items: center;
}

.inlineCheck {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.inlineCheck input {
  width: auto;
  min-height: auto;
}

.pendingActions {
  display: flex;
  gap: 8px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100% - 36px));
  background: #172033;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  transform: translateY(90px);
  opacity: 0;
  transition: .2s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
  }

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

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

  .notice {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .sectionHead input {
    max-width: none;
  }

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

  .reportHead,
  .reportTableHead {
    align-items: stretch;
    flex-direction: column;
  }

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

  .dateRangeControl,
  .dateRangeControl input,
  .reportControls select,
  .reportControls button {
    width: 100%;
  }

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

  .reportKpis > div {
    border-bottom: 1px solid var(--line);
  }

  .reportKpis > div:nth-child(2n) {
    border-right: 0;
  }

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

  .reportAccounting > div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .invoiceForm,
  .pdfForm,
  .inboundForm,
  .userForm {
    grid-template-columns: 1fr;
  }

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

  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebarTitle {
    display: none;
  }

  .sideNav {
    text-align: center;
    justify-content: center;
    padding: 0 8px;
  }

  .inboundItem {
    grid-template-columns: 58px minmax(0, 1fr);
  }

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

  .userItem,
  .userEdit {
    grid-template-columns: 1fr;
  }

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

  .invoiceSummary,
  .purchaseInvoiceForm {
    grid-template-columns: 1fr;
  }

  .invoiceSummary div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .invoiceSummary div:last-child {
    border-bottom: 0;
  }

  .invoiceCenterHead,
  .invoiceUploadHead {
    align-items: stretch;
    flex-direction: column;
  }

  .monthPicker {
    min-width: 0;
    width: 100%;
  }

  .monthNavigator {
    flex-wrap: wrap;
  }

  .monthNavigator select {
    flex: 1;
  }

  .monthNavigator #invoiceZipExport {
    width: 100%;
  }

  .purchaseInvoiceForm .wideField {
    grid-column: auto;
  }

  .analysisFields,
  .detectedInvoiceItem {
    grid-template-columns: 1fr;
  }

  .analysisTitle,
  .detectedItemsHead,
  .analysisActions {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .monthPicker {
    width: 100%;
  }

  .autocompleteItem {
    grid-template-columns: 46px minmax(0, 1fr);
  }

  .autocompleteItem b {
    grid-column: 2;
  }
}

.autoSyncControls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-top: 12px;
}

.autoSyncControls label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.switchLabel {
  cursor: pointer;
  user-select: none;
}

.switchLabel input {
  width: 18px;
  height: 18px;
  accent-color: #16a34a;
}

.autoSyncControls select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d4d4d8;
}

#autoSyncInfo {
  margin: 10px 0 0;
  font-size: 13px;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 14px 0 4px;
}

.pager span {
  font-size: 13px;
  color: #52525b;
  min-width: 160px;
  text-align: center;
}

.pager select {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #d4d4d8;
}

.pager button:disabled {
  opacity: 0.4;
}

@media (max-width: 720px) {
  .autoSyncControls {
    align-items: stretch;
    flex-direction: column;
  }
}
