:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687386;
  --line: #dbe3ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

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

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

button.secondary {
  background: #0f172a;
}

button.text-button {
  background: transparent;
  color: var(--primary);
  min-height: auto;
  padding: 4px 0;
}

button.small {
  min-height: 34px;
  padding: 0 12px;
}

button.icon-button {
  background: transparent;
  color: var(--text);
  font-size: 24px;
  min-height: 32px;
  padding: 0 8px;
}

button.icon-button:hover {
  background: #edf2f7;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 42px;
  padding: 8px 10px;
  outline: none;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 42px;
  padding: 8px 10px;
  outline: none;
  background: #fff;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #0f172a;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 14px;
  position: sticky;
  top: 0;
}

.brand {
  padding: 4px 6px 8px;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.25;
  margin: 0;
}

.brand p {
  color: #94a3b8;
  font-size: 13px;
  margin: 8px 0 0;
}

.sidebar-status p {
  color: #cbd5e1;
  margin: 8px 0 0;
}

.sidebar-status {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin-top: auto;
  padding: 14px 6px 4px;
}

.status-pill {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  display: inline-flex;
  padding: 8px 12px;
}

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

.dashboard {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, 1fr);
  margin-bottom: 16px;
}

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

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

.metric strong {
  display: block;
  font-size: 28px;
  margin-top: 8px;
}

.sensitive-metric {
  cursor: default;
  user-select: none;
}

.account-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.account-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 8px;
}

.account-row strong {
  font-size: 20px;
  margin-top: 0;
}

.account-row .text-button {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.account-row .text-button:hover {
  color: var(--primary);
}

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

.tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  color: #94a3b8;
  font-size: 12px;
  font-weight: 700;
  padding: 0 8px 8px;
}

.tab {
  background: transparent;
  color: #dbeafe;
  justify-content: flex-start;
  text-align: left;
  width: 100%;
}

.tab.active {
  background: #2563eb;
  color: #fff;
}

.tab:hover {
  background: rgba(37, 99, 235, 0.25);
}

.panel {
  display: none;
  padding: 18px;
}

.panel.active {
  display: block;
}

.panel-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: 360px 1fr;
}

.sale-layout {
  display: grid;
  gap: 16px;
}

.form-block,
.list-block {
  min-width: 0;
}

.form-block.narrow {
  max-width: 420px;
}

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

label {
  color: var(--muted);
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
}

label input {
  color: var(--text);
  font-weight: 400;
  margin-top: 6px;
}

label select {
  color: var(--text);
  font-weight: 400;
  margin-top: 6px;
}

.two-cols {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

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

.section-title h2 {
  margin: 0;
}

.section-title input {
  max-width: 300px;
}

.product-toolbar {
  align-items: center;
  display: flex;
  gap: 10px;
}

#openCreateProduct,
#clearProductFilter {
  white-space: nowrap;
}

.product-actions {
  margin-top: 8px;
}

.stock-in-card {
  margin-bottom: 20px;
  padding-bottom: 14px;
}

.stock-in-grid {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(220px, 1.5fr) minmax(90px, 0.7fr) minmax(110px, 0.8fr) minmax(160px, 1fr) auto;
}

.stock-in-grid label {
  margin-bottom: 0;
}

.stock-in-grid button {
  white-space: nowrap;
}

#inBarcode,
#saleBarcode {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.stock-in-card .suggestions {
  margin-top: 8px;
}

.product-list-title {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

#productFilterText {
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}

.product-table {
  table-layout: auto;
  width: 100%;
}

.product-table th:first-child,
.product-table td:first-child {
  width: 56px;
}

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

.product-table .barcode-cell {
  min-width: 130px;
  white-space: normal;
}

.customer-toolbar {
  align-items: center;
  display: flex;
  gap: 10px;
}

.customer-toolbar input {
  width: 360px;
}

#openCreateCustomer {
  white-space: nowrap;
}

.customer-table {
  min-width: 860px;
}

.customer-table th:first-child,
.customer-table td:first-child {
  width: 90px;
}

.product-stock {
  text-align: right;
  white-space: nowrap;
}

th.product-stock {
  text-align: right;
}

.product-stock strong {
  font-size: 16px;
}

.sale-scan-card {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.sale-scan-card .section-title {
  margin-bottom: 8px;
}

.sale-customer-grid {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns:
    minmax(170px, 1fr)
    minmax(150px, 1fr)
    minmax(130px, 0.8fr)
    minmax(180px, 1.2fr)
    minmax(160px, 1fr)
    minmax(150px, 0.8fr);
}

.sale-customer-grid label {
  margin-bottom: 0;
}

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

.checkbox-label input {
  min-height: auto;
  width: auto;
}

.sale-scan-grid {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns:
    minmax(230px, 1.75fr)
    minmax(170px, 1.1fr)
    minmax(90px, 0.65fr)
    minmax(70px, 0.45fr)
    minmax(80px, 0.5fr)
    minmax(90px, 0.55fr)
    minmax(90px, 0.55fr)
    auto;
}

.sale-scan-grid label {
  margin-bottom: 0;
}

.sale-scan-grid button {
  white-space: nowrap;
}

.sale-cart-actions {
  display: flex;
  gap: 10px;
}

.sale-cart-heading {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.sale-cart-heading h2 {
  margin: 0;
}

#saleCustomerSummary {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.sale-cart-card {
  min-height: 420px;
  margin-top: 30px;
  overflow-x: auto;
}

.sale-cart-title {
  margin-bottom: 10px;
}

.cart-table,
.product-list,
.scan-log {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.cart-table {
  max-height: 460px;
  overflow: auto;
}

.cart-table-head,
.cart-table-row {
  display: grid;
  gap: 0;
  grid-template-columns: 64px minmax(150px, 1.3fr) minmax(100px, 0.85fr) minmax(140px, 1.1fr) minmax(90px, 0.8fr) minmax(80px, 0.7fr) minmax(110px, 0.8fr) minmax(120px, 0.75fr) minmax(90px, 0.7fr);
  min-width: 1040px;
}

.cart-table-head {
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  position: sticky;
  top: 0;
  z-index: 1;
}

.cart-table-head > div,
.cart-table-row > div {
  align-items: center;
  border-right: 1px solid var(--line);
  display: flex;
  min-width: 0;
  padding: 10px;
}

.cart-table-head > .amount-cell,
.cart-table-row > .amount-cell {
  justify-content: flex-end;
  text-align: right;
}

.cart-table-head > .operation-cell,
.cart-table-row > .operation-cell {
  justify-content: center;
  text-align: center;
}

.cart-table-head > div:last-child,
.cart-table-row > div:last-child {
  border-right: 0;
}

.cart-table-body {
  min-width: 1040px;
}

.cart-table-row {
  border-bottom: 1px solid var(--line);
}

.cart-table-row:last-child {
  border-bottom: 0;
}

.cart-product-name {
  font-weight: 700;
}

.barcode-cell {
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-all;
}

.cost-trigger {
  cursor: help;
}

.cost-trigger:hover {
  background: #eff6ff;
}

.cart-edit.compact {
  min-height: 34px;
  padding: 6px 8px;
}

.cart-unit {
  color: var(--muted);
  font-size: 12px;
  margin-left: 6px;
  white-space: nowrap;
}

.danger-text {
  color: #c26a6a !important;
  font-size: 12px;
  font-weight: 600;
}

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

.edit-text {
  color: #64748b !important;
  font-size: 12px;
  font-weight: 600;
}

.edit-text:hover {
  color: var(--primary) !important;
}

.product-list,
.scan-log {
  min-height: 260px;
}

.product-list {
  overflow-x: auto;
  overflow-y: hidden;
}

.suggestions {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: none;
  margin: -4px 0 12px;
  max-height: 260px;
  overflow: auto;
}

.suggestions.show {
  display: block;
}

.suggestion-item {
  background: #fff;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  padding: 10px 12px;
}

.suggestion-item:last-child {
  border-bottom: 0;
}

.suggestion-item:hover,
.suggestion-item.active {
  background: #eff6ff;
}

.suggestion-title {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.suggestion-title strong {
  min-width: 0;
}

.suggestion-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 4px;
}

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

.row-item {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
  padding: 12px;
}

.row-item:last-child {
  border-bottom: 0;
}

.row-main strong {
  display: block;
}

.row-main span,
.row-side {
  color: var(--muted);
  font-size: 13px;
}

.cart-line-meta {
  display: block;
  margin-top: 4px;
}

.cart-edit-grid {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(96px, 120px) minmax(120px, 150px) auto;
  margin-top: 10px;
}

.cart-edit-grid label {
  margin-bottom: 0;
}

.cart-edit-grid input {
  height: 38px;
  margin-top: 4px;
}

.cart-edit-grid span {
  color: var(--muted);
  padding-bottom: 10px;
}

.cart-subtotal {
  color: var(--text);
  font-size: 15px;
}

.cart-total {
  align-items: center;
  row-gap: 8px;
  display: grid;
  font-size: 18px;
  grid-template-columns: 64px minmax(150px, 1.3fr) minmax(100px, 0.85fr) minmax(140px, 1.1fr) minmax(90px, 0.8fr) minmax(80px, 0.7fr) minmax(110px, 0.8fr) minmax(96px, 0.65fr) minmax(90px, 0.7fr);
  margin-top: 14px;
  min-width: 1040px;
}

.cart-total-label,
.cart-discount-label,
.cart-final-label {
  grid-column: 8;
  text-align: right;
  white-space: nowrap;
}

#cartProductTotal,
#cartTotal {
  grid-column: 9;
  text-align: right;
}

#cartProductTotal {
  font-weight: 400;
}

.cart-discount-label,
#cartDiscount {
  grid-row: 2;
}

.cart-final-label,
#cartTotal {
  grid-row: 3;
}

#cartDiscount {
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  box-shadow: none;
  color: var(--text);
  font-size: 20px;
  font-weight: 400;
  grid-column: 9;
  min-height: 34px;
  padding: 0;
  text-align: right;
}

#cartDiscount:focus {
  border-bottom-color: var(--primary);
  box-shadow: none;
}

.cart-final-label,
#cartTotal {
  color: var(--text);
  font-size: 20px;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

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

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

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

.order-action-button {
  min-width: 76px;
  padding: 0 14px;
}

.order-title .order-action-button {
  margin-right: 22px;
}

.order-table th:last-child,
.order-table td:last-child {
  text-align: center;
  width: 120px;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
}

.badge.pending {
  background: #fef3c7;
  color: var(--warning);
}

.toast {
  background: #0f172a;
  border-radius: 8px;
  bottom: 18px;
  color: #fff;
  left: 50%;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 20px);
  transition: all 0.2s ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hint {
  color: var(--muted);
  line-height: 1.5;
}

.modal-backdrop {
  align-items: center;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  inset: 0;
  justify-content: center;
  padding: 18px;
  position: fixed;
  z-index: 20;
}

.modal-backdrop.show {
  display: flex;
}

.modal {
  background: #fff;
  border-radius: 8px;
  max-height: 92vh;
  max-width: 560px;
  overflow: auto;
  width: 100%;
}

.draggable-modal.dragging {
  user-select: none;
}

.draggable-handle {
  cursor: move;
}

.draggable-handle .icon-button {
  cursor: pointer;
}

#productModal .modal {
  max-width: 860px;
}

#customerModal .modal {
  max-width: 720px;
}

.sale-customer-modal {
  max-width: 760px;
}

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

.sale-customer-modal .wide-field {
  grid-column: 1 / -1;
}

.sale-customer-modal .suggestions {
  margin: 0;
  max-height: 220px;
}

.cost-modal {
  max-width: 560px;
}

.cost-detail {
  display: grid;
  gap: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cost-detail div {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
}

.cost-detail span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-bottom: 4px;
}

.cost-detail strong {
  display: block;
  overflow-wrap: anywhere;
}

.product-form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.customer-form-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.product-form-grid label {
  margin-bottom: 0;
}

.customer-form-grid label {
  margin-bottom: 0;
}

.product-form-grid .wide-field {
  grid-column: span 2;
}

.customer-form-grid .wide-field {
  grid-column: span 2;
}

.product-form-grid .hint {
  grid-column: 1 / -1;
  margin: 0;
}

.receipt-modal {
  max-width: 820px;
}

.data-summary-grid,
.settings-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.data-summary-card,
.settings-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.data-summary-card h3,
.data-section h3,
.settings-card h3 {
  font-size: 16px;
  margin: 0 0 12px;
}

.data-section {
  margin-top: 16px;
}

.data-value-row {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
}

.data-value-row:first-of-type {
  border-top: 0;
}

.data-value-row span {
  color: var(--muted);
}

.data-value-row strong {
  font-size: 22px;
}

.analytics-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

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

.analytics-table th,
.analytics-table td {
  font-size: 15px;
  padding: 12px 14px;
}

.analytics-table th:first-child,
.analytics-table td:first-child {
  width: 70px;
}

.analytics-table .amount-cell {
  text-align: right;
  white-space: nowrap;
}

.settings-card label:last-child {
  margin-bottom: 0;
}

.guide-list {
  color: var(--muted);
  line-height: 1.8;
  margin: 0;
  padding-left: 20px;
}

.receipt-body {
  padding: 18px;
}

.receipt-paper h1 {
  font-size: 22px;
  margin: 0 0 12px;
  text-align: center;
}

.receipt-store {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 8px 18px;
  justify-content: center;
  margin-bottom: 12px;
}

.receipt-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 10px 18px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.receipt-customer {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 8px 18px;
  margin-bottom: 12px;
  padding: 8px 10px;
}

.receipt-table {
  min-width: 0;
}

.receipt-table th,
.receipt-table td {
  padding: 8px;
}

.receipt-table th:last-child,
.receipt-table td:last-child {
  text-align: right;
}

.receipt-total {
  display: grid;
  gap: 8px 16px;
  grid-template-columns: 1fr 120px;
  justify-content: end;
  margin-left: auto;
  margin-top: 14px;
  max-width: 280px;
}

.receipt-total span {
  color: var(--muted);
  text-align: right;
}

.receipt-total strong {
  text-align: right;
}

.receipt-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  margin-top: 16px;
  padding-top: 10px;
  text-align: center;
}

.modal-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 14px 16px;
}

.modal-header h2 {
  margin: 0;
}

.modal-body {
  padding: 16px;
}

.modal-actions {
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 16px;
}

.split-actions {
  align-items: center;
}

.action-spacer {
  flex: 1;
}

button.light {
  background: #eef2f7;
  color: var(--text);
}

button.light:hover {
  background: #e2e8f0;
}

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

  .sidebar {
    gap: 12px;
    height: auto;
    overflow-y: visible;
    padding: 14px;
    position: static;
  }

  .brand {
    padding: 0;
  }

  .brand h1 {
    font-size: 18px;
  }

  .sidebar-status {
    margin-top: 0;
    padding: 10px 0 0;
  }

  .tabs {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .nav-label {
    display: none;
  }

  .tab {
    flex: 0 0 auto;
    width: auto;
  }

  .main-content {
    padding: 14px;
  }

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

  .data-summary-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .stock-in-grid {
    grid-template-columns: 1fr;
  }

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

  .sale-scan-grid,
  .sale-customer-grid {
    grid-template-columns: 1fr 1fr;
  }

  .sale-scan-grid label:first-child,
  .sale-scan-grid label:nth-child(2),
  .sale-scan-grid label:nth-child(7),
  .sale-scan-grid button,
  .sale-customer-grid label:nth-child(4),
  .sale-customer-grid label:nth-child(5),
  .sale-customer-grid .checkbox-label {
    grid-column: 1 / -1;
  }

  .row-item {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .row-side {
    text-align: right;
  }

  .cart-edit-grid {
    grid-template-columns: 1fr 1fr auto;
  }

  .section-title,
  .product-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .section-title input {
    max-width: none;
  }

  .product-form-grid,
  .customer-form-grid {
    grid-template-columns: 1fr;
  }

  .product-form-grid .wide-field,
  .customer-form-grid .wide-field {
    grid-column: auto;
  }
}

@media print {
  body {
    background: #fff;
  }

  body * {
    visibility: hidden;
  }

  #receiptModal,
  #receiptModal * {
    visibility: visible;
  }

  #receiptModal {
    background: #fff;
    display: block !important;
    inset: 0;
    padding: 0;
    position: absolute;
  }

  .receipt-modal {
    border-radius: 0;
    box-shadow: none;
    max-height: none;
    max-width: none;
    overflow: visible;
  }

  .receipt-body {
    padding: 0;
  }

  .no-print {
    display: none !important;
  }
}
