:root {
  --bg: #f5f7f8;
  --panel: #fff;
  --ink: #17212f;
  --muted: #667587;
  --line: #d9e1ea;
  --brand: #176b5d;
  --brand-soft: #e9f3f1;
  --blue: #2563a8;
  --warn: #b45309;
  --danger: #b42318;
  --radius: 8px;
}

.location-picker { display: grid; gap: 4px; color: var(--brand); font-size: 12px; font-weight: 700; }
.location-picker select { min-width: 165px; max-width: 240px; border: 2px solid var(--brand); border-radius: 8px; padding: 7px 10px; background: var(--brand-soft); color: var(--ink); }
.location-context { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding: 14px 16px; background: var(--brand-soft); border-left: 4px solid var(--brand); border-radius: 8px; margin-bottom: 14px; }
.location-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.location-editor { border: 2px solid var(--brand); margin-bottom: 16px; }
.location-lines { display: grid; gap: 12px; }
.location-line { display: grid; grid-template-columns: minmax(160px, 1fr) 130px auto; gap: 10px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.location-line input, .location-line select, .location-editor input, .location-editor textarea { min-width: 0; max-width: 100%; }
.location-fixed { align-self: center; font-weight: 700; color: var(--brand); }
.location-stock-table small, .location-sale-stock small { display: block; margin-top: 5px; }
.table-wrap { width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 620px; }
.location-documents { display: grid; gap: 16px; }
.location-document { padding: 15px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; }
.location-sale-stock { grid-column: 1 / -1; padding: 8px 12px; color: var(--brand); background: var(--brand-soft); border-radius: 6px; }
@media (max-width: 680px) {
  .location-picker { width: 100%; }
  .location-picker select { max-width: 100%; width: 100%; }
  .location-line { grid-template-columns: 1fr auto; }
  .location-line label:first-child { grid-column: 1 / -1; }
  .location-tabs .btn { flex: 1 0 40%; }
  .location-editor .panel-title { flex-wrap: wrap; }
  .location-context { flex-direction: column; }
  .location-stock-table { min-width: 640px; }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 22px;
  box-shadow: 0 18px 42px rgba(17, 24, 39, .08);
}

.shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .95);
  padding: 12px 18px;
  backdrop-filter: blur(8px);
}

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

.logo {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 15px;
}

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

.top-actions,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.offline-mode-tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid #b42318;
  border-radius: 6px;
  background: #fff1f0;
  padding: 4px 9px;
  color: #8a1c13;
  font-size: 12px;
  font-weight: 800;
}

.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #eef3f6;
  padding: 2px;
}

.segmented button {
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
  white-space: nowrap;
}

.segmented button.active {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 1px 3px rgba(17, 24, 39, .08);
  font-weight: 750;
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  max-width: 1360px;
  margin: 0 auto;
}

.side {
  position: sticky;
  top: 61px;
  height: calc(100vh - 61px);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-right: 1px solid var(--line);
  background: #fff;
  padding: 14px 10px;
}

.side-title {
  margin: 8px 10px 10px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 5px;
}

.nav button {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  padding: 9px 10px;
  text-align: left;
}

.nav button.active {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 750;
}

.main {
  min-width: 0;
  padding: 18px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.page-head h1 {
  margin: 0;
  font-size: 22px;
}

.page-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid > * {
  min-width: 0;
}

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

.management-layout {
  display: grid;
  align-items: start;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 12px;
}

.management-layout > * {
  min-width: 0;
}

.entity-table-scroll {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.entity-table-scroll table {
  margin: 0;
}

.salesperson-summary-table {
  min-width: 940px;
}

.salesperson-category-metric {
  display: grid;
  min-width: 150px;
  gap: 3px;
}

.salesperson-category-metric strong {
  white-space: nowrap;
}

.salesperson-category-metric small {
  color: var(--muted);
  white-space: nowrap;
}

.user-access-layout {
  grid-template-columns: minmax(290px, 320px) minmax(0, 1fr);
}

.user-access-editor {
  min-width: 300px;
  gap: 6px;
}

.user-account-table {
  min-width: 740px;
}

.user-account-table th:nth-child(1) {
  width: 18%;
}

.user-account-table th:nth-child(2) {
  width: 17%;
}

.user-account-table th:nth-child(3) {
  width: 45%;
}

.user-account-table th:nth-child(4),
.user-account-table th:nth-child(5) {
  width: 10%;
}

.user-account-actions {
  margin: 0;
  flex-direction: column;
  align-items: stretch;
}

.special-price-audit-scroll {
  width: 100%;
  height: 240px;
  min-height: 150px;
  max-height: 60vh;
  overflow: auto;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.special-price-audit-scroll table {
  min-width: 1040px;
  margin: 0;
}

.special-price-audit-scroll th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.product-price-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(128px, 1fr));
  gap: 3px 12px;
  min-width: 280px;
  font-size: 12px;
  line-height: 1.35;
}

.product-price-list span {
  white-space: nowrap;
}

.contract-list-table table {
  min-width: 1040px;
}

.customer-list-table table {
  min-width: 820px;
}

.contract-list-table th:last-child,
.contract-list-table td:last-child {
  min-width: 230px;
}

.customer-list-table th:last-child,
.customer-list-table td:last-child {
  min-width: 96px;
}

.contract-list-table th:last-child,
.contract-list-table td:last-child,
.customer-list-table th:last-child,
.customer-list-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 1;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.contract-list-table th:last-child,
.customer-list-table th:last-child {
  z-index: 2;
  background: #fafbfd;
}

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

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

.panel,
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.panel {
  padding: 14px;
}

.card {
  padding: 14px;
}

.customer-box {
  margin-bottom: 12px;
  background: #fbfdfc;
}

.contract-summary {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #bdd7cd;
  border-radius: var(--radius);
  background: #f3fbf7;
  color: var(--text);
  font-size: 13px;
}

.contract-summary strong {
  font-size: 14px;
}

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

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

.metric small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.valuation-metrics,
.valuation-actions-panel,
.cost-warning-panel {
  margin-bottom: 12px;
}

.petty-cash-metrics {
  margin-bottom: 12px;
}

.petty-cash-closing {
  border-left: 4px solid var(--brand);
  background: #f3fbf7;
}

.valuation-actions-panel .form {
  margin-bottom: 12px;
}

.valuation-category-table {
  margin-top: 4px;
}

.valuation-snapshot-history {
  margin-top: 14px;
}

.valuation-snapshot-history > strong {
  display: block;
  margin-bottom: 8px;
}

.inbound-history-filters {
  margin-bottom: 14px;
}

.inbound-history-filter-actions {
  grid-column: 1 / -1;
  margin: 0;
}

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

.inbound-summary-item {
  min-width: 0;
  padding: 12px 14px;
}

.inbound-summary-item + .inbound-summary-item {
  border-left: 1px solid var(--line);
}

.inbound-summary-item strong {
  overflow-wrap: anywhere;
  font-size: 18px;
}

.inbound-history-table {
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.inbound-history-table table {
  min-width: 1180px;
}

.inbound-history-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.danger-text {
  color: var(--danger) !important;
}

.dashboard-total-metric {
  margin-bottom: 12px;
  padding: 18px 20px;
  border-left: 4px solid var(--brand);
}

.dashboard-total-metric strong {
  font-size: 34px;
}

.dashboard-payment-breakdown {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 18px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.dashboard-payment-breakdown span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  font-size: 13px;
}

.dashboard-payment-breakdown b {
  color: var(--muted);
  font-weight: 600;
}

.dashboard-detail-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.dashboard-date-actions {
  align-items: flex-end;
}

.dashboard-date-field {
  min-width: 154px;
  font-size: 12px;
}

.dashboard-date-field input {
  min-height: 38px;
}

.icon-button {
  width: 40px;
  min-width: 40px;
  height: 38px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

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

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.product-tool-tabs {
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.bulk-selection-status {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: flex-end;
}

.compact-actions {
  margin: 0;
}

.bulk-product-table {
  max-height: 430px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.bulk-product-table table {
  min-width: 860px;
}

.bulk-product-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.bulk-check-column {
  width: 42px;
  text-align: center;
}

.bulk-product-check {
  width: 18px;
  min-height: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--brand);
}

.btn,
.tab {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
}

.btn.primary,
.tab.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.btn.danger {
  border-color: #f2b8b5;
  color: var(--danger);
}

.btn.small {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.form {
  display: grid;
  gap: 12px;
}

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

.form.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.form.five {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

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

label.inline-check {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  align-self: end;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
}

label.inline-check input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--brand);
}

.inline-field {
  min-width: 160px;
}

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

input[readonly] {
  background: #f3f6f8;
  color: var(--muted);
}

textarea {
  min-height: 74px;
  resize: vertical;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

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

th {
  background: #fafbfd;
  color: var(--muted);
}

tfoot th {
  border-top: 2px solid var(--line);
  background: var(--brand-soft);
  color: var(--ink);
  font-weight: 800;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}

.tag.warn {
  background: #fff7ed;
  color: var(--warn);
}

.tag.danger {
  background: #fff1f0;
  color: var(--danger);
}

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

.compact {
  margin: 4px 0 0;
  font-size: 12px;
}

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

.sale-line {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1.4fr auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.sale-line.service-line {
  background: #fbfdfc;
  border-color: #b7d5ce;
}

.sale-line.custom-line {
  background: #fffdf7;
  border-color: #e4c56a;
}

.sale-product-picker { position: relative; grid-column: span 2; min-width: 0; }
.sale-product-picker > label { display: grid; gap: 6px; }
.sale-product-picker > small { display: block; margin-top: 6px; color: var(--muted); overflow-wrap: anywhere; }
.sale-product-results { position: absolute; z-index: 30; top: 66px; left: 0; width: 100%; max-height: 320px; overflow: auto; padding: 6px; border: 1px solid var(--line); border-radius: 10px; background: #fff; box-shadow: 0 8px 24px #173f3320; }
.sale-product-results[hidden] { display: none; }
.sale-product-choice { display: grid; gap: 4px; width: 100%; padding: 10px; border: 0; border-radius: 6px; text-align: left; background: #fff; color: var(--text); cursor: pointer; overflow-wrap: anywhere; }
.sale-product-choice:hover, .sale-product-choice.is-active { background: #e8f3f0; }
.sale-product-choice small { color: var(--muted); }
.sales-commission-basis { margin-top: 12px; padding: 12px; background: #f4f9f7; border: 1px solid var(--line); border-radius: 10px; }
.sales-commission-basis summary { cursor: pointer; color: var(--primary); font-weight: 600; }
@media (max-width: 760px) { .sale-product-picker { grid-column: 1 / -1; } }

.timber-conversion {
  grid-column: 1 / -1;
  padding: 10px 12px;
  background: var(--soft, #edf6f3);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
}

.timber-editor {
  margin-bottom: 16px;
  border-color: #8fbeb0;
  scroll-margin-top: 20px;
}

.edge-suggestions {
  grid-column: 1 / -1;
}

.edge-suggestion-title {
  margin: 2px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.edge-suggestion-list {
  display: grid;
  gap: 8px;
}

.edge-suggestion-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
  padding: 8px;
}

.edge-suggestion-item strong,
.edge-suggestion-item span,
.edge-suggestion-item small {
  display: block;
}

.edge-suggestion-item span,
.edge-suggestion-item small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 40;
  max-width: 420px;
  border: 1px solid #b7d5ce;
  border-radius: var(--radius);
  background: #fff;
  color: var(--brand);
  box-shadow: 0 12px 28px rgba(17, 24, 39, .12);
  padding: 10px 12px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  overflow-y: auto;
  background: rgba(23, 33, 47, .48);
  padding: 20px;
}

.modal-card {
  width: min(680px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(17, 24, 39, .24);
  padding: 18px;
}

.modal-card .panel-title {
  align-items: flex-start;
}

.modal-card .panel-title p {
  max-width: 520px;
  margin: 5px 0 0;
}

.balance-payment-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.balance-payment-summary span {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafb;
  color: var(--muted);
  padding: 9px 10px;
  font-size: 12px;
}

.balance-payment-summary strong {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 14px;
}

.balance-payment-check {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: var(--radius);
  background: var(--brand-soft);
  padding: 10px 12px;
  color: var(--brand);
}

.form-error {
  margin: 0;
  border: 1px solid #f2b8b5;
  border-radius: var(--radius);
  background: #fff1f0;
  color: var(--danger);
  padding: 9px 10px;
  font-size: 12px;
  font-weight: 700;
}

.modal-actions {
  justify-content: flex-end;
}

.mobile-switch {
  display: none;
}

.employee-workspace {
  display: grid;
  grid-template-columns: minmax(300px, 0.78fr) minmax(0, 2fr);
  gap: 14px;
  align-items: start;
}

.employee-list-panel {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 110px);
  overflow: hidden;
}

.employee-search {
  width: 100%;
  margin-bottom: 10px;
}

.employee-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 215px);
  overflow-y: auto;
  padding-right: 3px;
}

.employee-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.employee-card > .tag {
  grid-column: 2;
  justify-self: start;
}

.employee-card:hover,
.employee-card.selected {
  border-color: var(--brand);
  background: #f0f8f6;
}

.employee-avatar {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.employee-card-main {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.employee-card-main strong,
.employee-card-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-card-main small {
  color: var(--muted);
}

.employee-editor-head {
  align-items: flex-start;
  gap: 12px;
}

.employee-editor-head > div:first-child {
  display: grid;
  gap: 3px;
}

.employee-editor-head small {
  color: var(--muted);
}

.employee-info-form {
  gap: 12px;
}

.employee-contract-actions { margin: 0; flex-wrap: wrap; }
.employee-contract-error { color: #9f2922; background: #fff1ef; border: 1px solid #edc6c0; padding: 12px; border-radius: 10px; white-space: pre-wrap; }
.employee-contract-extra { margin: 12px 0; }
.employee-contract-extra summary { cursor: pointer; color: var(--brand); margin-bottom: 12px; }
.employee-contract-bonuses { margin-top: 16px; }
.employee-document-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.employee-document-row small { display: block; color: var(--muted); margin-top: 4px; }
.employee-card[hidden] { display: none; }

.employee-section {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfd;
}

.employee-section-title {
  margin-bottom: 10px;
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
}

.employee-form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.cash-control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
  margin: 12px 0;
}

.cash-control-card {
  border-top: 3px solid var(--brand);
}

.owner-withdrawal-card {
  border-top-color: #b7791f;
}

.debt-payment-history {
  margin-top: 5px;
  min-width: 165px;
}

.debt-payment-history summary {
  color: var(--brand);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.debt-payment-row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 3px 7px;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid var(--line);
  font-size: 11px;
}

.debt-payment-row strong {
  text-align: right;
}

.debt-payment-row small {
  grid-column: 1 / -1;
}

.cash-status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.cash-status-strip span {
  display: grid;
  gap: 4px;
  padding: 9px;
  border-radius: 10px;
  background: #f2f6f7;
  color: var(--muted);
  font-size: 11px;
}

.cash-status-strip strong {
  color: var(--ink);
  font-size: 14px;
}

@media (max-width: 860px) {
  .layout {
    display: block;
  }

  .side {
    display: none;
  }

  .main {
    padding-bottom: 80px;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .management-layout,
  .dashboard-detail-metrics,
  .form.two,
  .form.three,
  .form.four,
  .form.five,
  .sale-line {
    grid-template-columns: 1fr;
  }

  .employee-workspace,
  .cash-control-grid {
    grid-template-columns: 1fr;
  }

  .employee-list-panel {
    position: static;
    max-height: none;
  }

  .employee-list {
    max-height: 360px;
  }

  .employee-editor-head,
  .employee-form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .cash-status-strip {
    grid-template-columns: 1fr;
  }

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

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

  .inbound-summary-item + .inbound-summary-item {
    border-left: 0;
  }

  .inbound-summary-item:nth-child(even) {
    border-left: 1px solid var(--line);
  }

  .inbound-summary-item:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

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

  .modal-backdrop {
    place-items: start center;
    padding: 10px;
  }

  .modal-card {
    max-height: calc(100vh - 20px);
    padding: 14px;
  }

  .balance-payment-summary,
  .balance-payment-splits {
    grid-template-columns: 1fr;
  }

  .bulk-selection-status {
    justify-content: flex-start;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  .mobile-switch {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: flex;
    overflow-x: auto;
    border-top: 1px solid var(--line);
    background: #fff;
  }

  .mobile-switch button {
    flex: 0 0 86px;
    min-height: 56px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
  }

  .mobile-switch button.active {
    color: var(--brand);
    font-weight: 800;
  }
}

@media (min-width: 861px) and (max-width: 1180px) {
  .dashboard-detail-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.connection-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}
.connection-error { background: #fff4e6; color: #8a3900; border-color: #e7b97c; }
.financial-request-recovery:not(:empty) { padding: 12px; background: #fff4e6; border-radius: 10px; }
.financial-request-recovery .btn { margin-top: 8px; }
.mobile-menu-panel { display: none; }
.backup-fingerprint { overflow-wrap: anywhere; }

.payroll-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.payroll-workspace { display: grid; grid-template-columns: minmax(0,1fr); gap: 16px; min-width: 0; max-width: 100%; }
.payroll-workspace > *, .payroll-workspace form, .payroll-workspace .panel { min-width: 0; max-width: 100%; }
.payroll-workspace .panel { margin-bottom: 0; }
.payroll-toolbar { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.payroll-month { display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }
.payroll-month label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.payroll-month input { max-width: 180px; }
.payroll-safety-note { padding: 10px 12px; border-left: 3px solid var(--brand); background: #eff7f5; font-size: 13px; line-height: 1.6; }
.payroll-warning { border-color: #e7b97c; background: #fff8ec; }
.payroll-source-cards { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; margin: 16px 0; }
.payroll-source-cards > div { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: grid; gap: 6px; }
.payroll-source-cards span, .payroll-source-cards small { color: var(--muted); font-size: 12px; }
.payroll-source-cards strong { font-size: 19px; }
.payroll-source-cards strong span { color: inherit; font-size: inherit; }
.payroll-table-scroll { min-width: 0; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.payroll-team-table { width: 100%; min-width: 1040px; margin: 0; }
.payroll-team-table th { white-space: normal; background: #f3f7fb; vertical-align: middle; }
.payroll-team-table td { vertical-align: top; white-space: normal; padding: 14px 10px; }
.payroll-team-table td > small { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.payroll-team-table td:last-child > small { margin-top: 8px; max-width: 160px; }
.payroll-team-table input[type=number] { width: 104px; padding: 8px; }
.payroll-employee-cell { width: 218px; min-width: 190px; }
.payroll-employee-cell > .tag { margin: 4px 0 8px; display: inline-block; }
.payroll-employee-cell > button { display: block; margin-top: 10px; }
.payroll-include, .payroll-participation label, .payroll-confirm-check { display: flex; align-items: center; gap: 8px; }
.payroll-team-table input[type=checkbox], .payroll-confirm-check input[type=checkbox] { width: 17px; min-width: 17px; height: 17px; min-height: 17px; accent-color: var(--brand); }
.payroll-include { margin-bottom: 6px; align-items: flex-start; }
.payroll-include input { margin-top: 3px; }
.payroll-days { display: flex; align-items: center; gap: 5px; }
.payroll-days input[type=number] { width: 68px; }
.payroll-participation { display: grid; gap: 8px; min-width: 120px; }
.payroll-participation label { font-size: 12px; white-space: nowrap; }
.payroll-excluded { background: #f7f8fa; color: var(--muted); }
.payroll-row-errors { background: #fff8ec; padding-top: 0 !important; }
.payroll-row-errors p { margin: 6px 0; }
.payroll-detail-row > td { background: #f7faf9; padding: 16px; }
.payroll-detail-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
.payroll-detail-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.payroll-detail-grid input[type=number], .payroll-detail-grid input { width: 100%; }
.payroll-note { grid-column: 1 / -1; }
.payroll-detail-totals { display: flex; gap: 12px 24px; flex-wrap: wrap; font-size: 12px; margin-top: 14px; }
.payroll-total-strip { display: flex; justify-content: flex-end; gap: 14px 24px; flex-wrap: wrap; padding: 16px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.payroll-total-strip strong { color: var(--brand); }
.payroll-save-actions { padding-top: 8px; }
.payroll-confirm-panel { border: 2px solid var(--brand); }
.payroll-confirm-panel > label:not(.payroll-confirm-check) { display: grid; max-width: 240px; gap: 6px; }
.payroll-confirm-check { margin: 16px 0; line-height: 1.6; }

.private-settlement-workspace { display: grid; grid-template-columns: minmax(0,1fr); gap: 16px; min-width: 0; max-width: 100%; }
.private-settlement-workspace > *, .private-settlement-workspace .panel, .private-settlement-workspace form, .private-document { min-width: 0; max-width: 100%; }
.private-settlement-workspace .panel, .private-settlement-workspace .page-head { margin: 0; }
.private-settlement-workspace .page-head p { max-width: 900px; line-height: 1.7; }
.private-settlement-metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; }
.private-settlement-metrics > div { display: grid; gap: 8px; padding: 18px; border: 1px solid var(--line); background: #fff; border-radius: 12px; }
.private-settlement-metrics span { color: var(--muted); font-size: 12px; }
.private-settlement-metrics strong { color: var(--brand); font-size: clamp(18px,2vw,25px); overflow-wrap: anywhere; }
.private-settlement-section-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.private-settlement-section-head p { margin-bottom: 0; line-height: 1.6; max-width: 750px; }
.private-customer-search { width: min(100%,320px); }
.private-customer-list { display: grid; gap: 10px; }
.private-customer-card { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(0,1fr) minmax(80px,.45fr); align-items: center; gap: 12px 24px; width: 100%; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); text-align: left; cursor: pointer; }
.private-customer-card:hover { border-color: var(--brand); background: #f6faf9; }
.private-customer-card:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.private-customer-card > div { display: grid; gap: 6px; min-width: 0; }
.private-customer-card strong { font-size: 17px; overflow-wrap: anywhere; }
.private-customer-card small, .private-customer-card p { color: var(--muted); font-size: 12px; }
.private-customer-card p { grid-column: 1 / -1; margin: 0; padding-top: 10px; border-top: 1px solid var(--line); line-height: 1.6; }
.private-customer-title { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin: 16px 0; }
.private-customer-title h2 { margin: 0; }
.private-customer-title span { color: var(--muted); }
.private-first-open { margin-bottom: 0; font-size: 13px; line-height: 1.7; }
.private-settlement-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.private-toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.private-toggle input { width: 16px; min-height: 16px; height: 16px; accent-color: var(--brand); }
.private-settlement-documents { display: grid; gap: 12px; }
.private-document { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.private-document-head { display: flex; align-items: center; gap: 12px 20px; flex-wrap: wrap; padding: 16px; }
.private-document-head > div:first-child { display: grid; gap: 6px; min-width: 150px; }
.private-document-head small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.private-document-value { margin-left: auto; text-align: right; }
.private-document-head .actions { margin: 0; }
.private-document > p { margin: 0; padding: 0 16px 12px; }
.private-settlement-scroll { min-width: 0; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.private-settlement-scroll table { width: 100%; margin: 0; }
.private-settlement-items { min-width: 1000px; }
.private-settlement-prices { min-width: 630px; }
.private-settlement-scroll td { vertical-align: middle; }
.private-settlement-scroll td > small { display: block; margin-top: 6px; color: var(--muted); }
.private-price-input { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.private-price-input input { width: 125px; }
.private-price-input span { color: var(--muted); font-size: 12px; }
.private-settlement-items input[data-private-remark] { min-width: 170px; }
.private-settlement-preview { border: 2px solid var(--brand); background: #f7fbfa; }
.private-settlement-preview h2 { margin-top: 0; }
.private-settlement-preview > p { font-size: 13px; line-height: 1.8; }
.private-preview-summary { display: flex; gap: 16px 28px; flex-wrap: wrap; padding: 14px 0; font-size: 14px; }
.private-preview-list { max-height: 290px; border: 1px solid var(--line); border-radius: 8px; margin: 14px 0; }
.private-preview-list table { min-width: 500px; }
.private-confirm-form { margin-top: 16px; }
.private-reverse-form { display: grid; gap: 12px; padding: 16px; border-top: 1px solid var(--line); background: #fff8ec; }
.private-reverse-form label { display: grid; gap: 8px; font-size: 13px; }
.private-reverse-form textarea { width: 100%; }
.private-new-customer { display: grid; gap: 8px; margin-bottom: 18px; color: var(--muted); font-size: 12px; max-width: 440px; }
.private-new-price { display: grid; gap: 14px; margin-bottom: 24px; padding: 16px; background: var(--brand-soft); border-radius: 10px; }
.private-new-price > button { justify-self: start; }
.private-settlement-prices td:last-child .btn { margin: 3px 6px 3px 0; }
@media (max-width: 700px) {
  .private-settlement-metrics { grid-template-columns: minmax(0,1fr); gap: 8px; }
  .private-settlement-metrics > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; }
  .private-settlement-metrics strong { font-size: 18px; }
  .private-customer-card { grid-template-columns: minmax(0,1fr) minmax(75px,.4fr); padding: 14px; gap: 12px; }
  .private-customer-name { grid-column: 1 / -1; }
  .private-document-head { gap: 12px; padding: 14px; }
  .private-document-head .actions { flex: 1 1 100%; }
  .private-document-head .actions .btn { flex-grow: 1; }
  .private-document-value { width: 100%; text-align: left; }
  .private-settlement-tabs .btn { flex: 1 1 100px; }
  .private-settlement-scroll table { display: table; overflow: visible; }
  .private-price-input input { padding: 8px; }
}

@media (max-width: 860px) {
  .payroll-source-cards { grid-template-columns: 1fr; }
  .payroll-month { gap: 5px; }
  .payroll-month .btn { padding: 7px 10px; }
  .payroll-team-table { display: table; overflow: visible; }
  .payroll-detail-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .payroll-save-actions .btn { flex: 1 1 180px; }
}

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 10px 12px; }
  .brand { min-width: 0; }
  .brand strong { font-size: 15px; }
  .brand span { font-size: 11px; }
  .top-actions { flex-wrap: wrap; gap: 6px; width: 100%; justify-content: space-between; }
  .top-actions .btn { padding: 7px 10px; min-height: 38px; }
  .main { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); min-width: 0; }
  .page-head { flex-wrap: wrap; gap: 10px; }
  .page-head h1 { font-size: 22px; }
  .page-head .actions { flex-wrap: wrap; }
  .connection-banner { align-items: flex-start; flex-wrap: wrap; }
  .btn, input, select { min-height: 44px; }
  input, select, textarea { font-size: 16px; max-width: 100%; }
  .mobile-switch { padding-bottom: env(safe-area-inset-bottom); overflow-x: hidden; }
  .mobile-switch button { flex: 1 1 0; min-width: 0; padding: 7px 4px; }
  .mobile-menu-panel { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; position: fixed; left: 10px; right: 10px; bottom: calc(66px + env(safe-area-inset-bottom)); max-height: 65vh; overflow-y: auto; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 14px; z-index: 31; box-shadow: 0 6px 24px #0002; }
  .modal-card { max-height: calc(100dvh - 30px); overflow-y: auto; }
  .dashboard-total-metric strong { font-size: clamp(26px,8vw,42px); overflow-wrap: anywhere; }
}
.private-customer-entry { border: 1px solid var(--border, #d5dfdf); border-radius: 12px; padding: 10px; min-width: 0; }
.private-customer-entry .private-customer-card { width: 100%; box-sizing: border-box; }
.private-customer-actions { margin-top: 10px; flex-wrap: wrap; }
.private-internal-filter { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin: 16px 0; }
.private-internal-filter label { display: grid; gap: 5px; }
.private-internal-customer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; border-top: 1px solid #e2e9e9; padding: 8px 0; }
.private-internal-document { border: 1px solid #d5dfdf; border-radius: 10px; padding: 14px; margin: 12px 0; min-width: 0; }
.private-internal-document summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; cursor: pointer; }
/* Returns workspace: inline forms, no prompt/modal bookkeeping. */
.return-editor, .return-detail, .return-search, .return-actions { margin: 16px 0; }
.return-editor fieldset, .return-detail fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.return-editor label, .return-detail label { display: flex; flex-direction: column; gap: 7px; margin-bottom: 12px; }
.return-detail .inline-check, .return-editor .inline-check { flex-direction: row; align-items: flex-start; }
.return-editor input[type="number"] { min-width: 125px; }
.return-editor small, .return-detail small, .return-records small { display: block; margin-top: 4px; }
.return-preview { margin-top: 18px; border-left: 4px solid #19766a; background: #edf6f4; padding: 18px; border-radius: 8px; }
.return-preview strong { display: block; font-size: 22px; margin-top: 6px; }
.return-candidates { display: grid; grid-template-columns: repeat(auto-fit,minmax(250px,1fr)); gap: 10px; margin-top: 12px; }
.return-candidates button { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 6px; white-space: normal; }
.selling-store-label { white-space: normal; max-width: 240px; }
.inventory-picker { background: #f4f8f7; border: 1px solid #d5e2df; border-radius: 12px; padding: 14px; }
.inventory-picker-results { max-height: 275px; overflow: auto; display: grid; gap: 6px; margin: 12px 0; }
.inventory-product-option { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 12px; border: 1px solid #d5e2df; background: white; border-radius: 8px; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.inventory-product-option:hover { border-color: #176b5d; }
.inventory-product-option.selected { background: #e6f1ed; opacity: .7; cursor: default; }
.inventory-product-option small, .location-line small { display: block; color: #64776f; margin-top: 5px; }
.location-editor .location-line { display: grid; grid-template-columns: minmax(180px,2fr) repeat(4,minmax(100px,1fr)) auto; align-items: end; padding: 12px; background: #f8faf9; border: 1px solid #dce7e2; border-radius: 10px; }
.location-editor .location-line input, .location-editor .location-line select { min-width: 0; width: 100%; box-sizing: border-box; }
.location-tabs { flex-wrap: wrap; }
.panel-title > select[onchange="state.inventoryOverviewScope=this.value;render()"] { width: min(100%,360px); flex: 0 1 360px; }
.panel-title:has(> select[onchange="state.inventoryOverviewScope=this.value;render()"]) h2 { flex-shrink: 0; white-space: nowrap; }
@media(max-width:1100px) { .location-editor .location-line { grid-template-columns: repeat(3,minmax(0,1fr)); } }
@media(max-width:640px) { .location-editor .location-line { grid-template-columns: repeat(2,minmax(0,1fr)); } .inventory-product-option { align-items: flex-start; flex-direction: column; gap: 6px; } }
