:root {
  --bg: #edf2ee;
  --panel: #ffffff;
  --ink: #1d2521;
  --muted: #6c7772;
  --line: #d9e0dc;
  --brand: #1f6f5b;
  --brand-dark: #174f42;
  --warn: #b45309;
  --danger: #b42318;
  --soft: #f7faf8;
  --shadow: 0 16px 36px rgba(23, 42, 34, 0.08);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

.partner-edit-table {
  min-width: 920px;
}

.partner-edit-table input {
  min-width: 120px;
}

.carrier-alert {
  border-left: 4px solid var(--warn);
}

.carrier-table {
  min-width: 1180px;
}

.carrier-table td {
  vertical-align: top;
}

.stocktake-workbench {
  border-top: 4px solid var(--brand);
}

.stocktake-scan-form {
  padding: 14px;
  margin-bottom: 14px;
  border-radius: 12px;
  background: #eef8f3;
}

.stocktake-manual-form {
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft);
}

.stocktake-header-form {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}

.stocktake-line-note {
  min-width: 190px;
}

.stocktake-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.stocktake-page-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.stocktake-pagination .btn {
  min-width: 42px;
}

.stocktake-scan-form input {
  min-height: 54px;
  font-size: 20px;
  font-weight: 750;
}

.stocktake-table {
  min-width: 760px;
}

.stocktake-table .stocktake-diff {
  background: #fff8ed;
}

.stocktake-actual {
  width: 90px;
}

.stocktake-workbench details {
  margin-top: 14px;
}

.stocktake-workbench summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--warn);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(31, 111, 91, 0.12), transparent 42%),
    linear-gradient(315deg, rgba(180, 83, 9, 0.08), transparent 38%),
    var(--bg);
}

.login-box {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.login-box h1,
.topbar h2 {
  margin: 0;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
}

.small {
  font-size: 12px;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-height: 0;
  background: #16231d;
  color: #eef7f2;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: hidden;
}

.brand {
  padding: 8px 10px;
  display: grid;
  gap: 5px;
}

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

.brand span {
  color: rgba(238, 247, 242, 0.68);
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
  overflow-y: auto;
  padding-right: 2px;
}

.nav-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border-radius: 8px;
}

.nav-item.dragging {
  opacity: 0.45;
}

.nav-view {
  width: 100%;
  border: 0;
  background: transparent;
  color: rgba(238, 247, 242, 0.78);
  border-radius: 8px;
  padding: 11px 12px;
  text-align: left;
  font-weight: 750;
}

.nav-view.active {
  background: var(--brand);
  color: #ffffff;
}

.nav-sort-toggle {
  margin: -8px 10px 0;
  border: 1px solid rgba(238, 247, 242, 0.25);
  background: transparent;
  color: rgba(238, 247, 242, 0.82);
  border-radius: 8px;
  padding: 8px 10px;
}

.nav-order-actions {
  display: none;
  gap: 3px;
  padding-right: 4px;
}

.nav.sorting .nav-item {
  background: rgba(255, 255, 255, 0.07);
  cursor: grab;
}

.nav.sorting .nav-order-actions {
  display: flex;
}

.nav-move {
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  padding: 6px 8px;
}

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

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

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

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

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

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

.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(23, 42, 34, 0.05);
}

.panel {
  padding: 14px;
}

.card {
  padding: 12px;
}

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

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

.metric strong {
  font-size: 26px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

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

.section-title h3 {
  margin: 0;
  font-size: 16px;
}

form.compact {
  display: grid;
  gap: 10px;
}

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

.line-row {
  display: grid;
  grid-template-columns:
    minmax(140px, 0.9fr)
    minmax(140px, 0.9fr)
    minmax(190px, 1.3fr)
    90px
    120px
    minmax(180px, 1fr)
    42px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.product-select-actions {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) auto;
  gap: 6px;
}

.quick-product-dialog {
  width: min(820px, calc(100vw - 24px));
  border: 0;
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.32);
}

.transaction-preview-dialog {
  width: min(900px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  overflow: auto;
  border: 0;
  border-radius: 12px;
  padding: 18px;
}

.transaction-preview-dialog::backdrop {
  background: rgba(10, 20, 16, 0.55);
}

.negative-stock-option {
  display: flex;
  grid-template-rows: none;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
}

.negative-stock-option input {
  width: auto;
  min-height: 0;
}

.negative-stock-option span {
  color: var(--warn);
}

.repair-section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 10px;
}

.customer-repair-section {
  border: 1px solid #a7d7c4;
  background: #f3fbf7;
}

.provider-repair-section {
  border: 1px solid #fed7aa;
  background: #fffaf3;
}

.quick-product-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.split-view {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.tree-list {
  display: grid;
  gap: 6px;
}

.tree-list button {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 9px 10px;
  text-align: left;
  font-weight: 800;
}

.tree-list button.active {
  border-color: var(--brand);
  background: #e7f5ef;
  color: var(--brand-dark);
}

.brand-group {
  display: grid;
  gap: 8px;
}

.brand-heading {
  margin: 0;
  font-size: 15px;
}

label {
  display: grid;
  grid-template-rows: auto minmax(38px, auto);
  gap: 6px;
  min-width: 0;
}

label span {
  display: block;
  position: relative;
  z-index: 1;
  min-height: 16px;
  line-height: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}

.product-category-field select {
  position: relative;
  z-index: 0;
  margin: 0;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 111, 91, 0.12);
}

.btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 800;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

.btn.ghost {
  background: var(--soft);
}

.btn.full {
  width: 100%;
}

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

.qr-field {
  display: grid;
  gap: 6px;
  align-items: start;
}

.compact-qr {
  min-width: 118px;
}

.qr-preview {
  min-height: 44px;
  display: flex;
  align-items: center;
}

.qr-thumb {
  width: 58px;
  height: 58px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  padding: 3px;
}

.qr-cell input[type="file"] {
  width: 128px;
  font-size: 12px;
}

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

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

.product-edit-table {
  min-width: 980px;
  table-layout: fixed;
  font-size: 12px;
}

.product-edit-table th,
.product-edit-table td {
  padding: 5px;
}

.product-edit-table input,
.product-edit-table select {
  min-height: 32px;
  padding: 5px 6px;
  font-size: 12px;
}

.product-edit-table th:nth-child(1),
.product-edit-table td:nth-child(1) { width: 82px; }
.product-edit-table th:nth-child(2),
.product-edit-table td:nth-child(2) { width: 82px; }
.product-edit-table th:nth-child(3),
.product-edit-table td:nth-child(3) { width: 88px; }
.product-edit-table th:nth-child(4),
.product-edit-table td:nth-child(4) { width: 92px; }
.product-edit-table th:nth-child(5),
.product-edit-table td:nth-child(5) { width: 100px; }
.product-edit-table th:last-child,
.product-edit-table td:last-child { width: 140px; }

.product-edit-table .actions {
  flex-wrap: wrap;
}

.store-edit-table {
  min-width: 760px;
}

.store-edit-table th:last-child,
.store-edit-table td:last-child {
  width: 150px;
}

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

th {
  color: var(--muted);
  background: var(--soft);
  font-size: 12px;
}

tr:last-child td {
  border-bottom: 0;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.tabs button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 7px;
  padding: 8px 12px;
  font-weight: 800;
  white-space: nowrap;
}

.tabs button.active {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e7f5ef;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
}

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

.print-designer {
  padding: 0;
  overflow: hidden;
}

.designer-head {
  min-height: 56px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.designer-head h3,
.designer-right h3 {
  margin: 0;
}

.designer-grid {
  min-height: 620px;
  display: grid;
  grid-template-columns: 230px minmax(620px, 1fr) 270px;
  background: #d9dde4;
}

.designer-left,
.designer-right {
  background: var(--panel);
  padding: 14px;
  overflow: auto;
}

.designer-left {
  border-right: 1px solid var(--line);
}

.designer-right {
  border-left: 1px solid var(--line);
  display: grid;
  align-content: start;
  gap: 12px;
}

.designer-left details {
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.designer-left summary {
  cursor: pointer;
  font-weight: 800;
}

.field-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.field-chip {
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
}

.designer-stage {
  overflow: auto;
  padding: 12px;
}

.designer-toolbar {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.template-preview-compare {
  display: grid;
  grid-template-columns: repeat(2, minmax(360px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.template-preview-compare section {
  min-width: 0;
}

.template-preview-compare h4,
.designer-edit-heading {
  margin: 0 0 8px;
  color: #344054;
}

.actual-print-preview,
.template-card-preview {
  background: #ffffff;
  color: #111827;
  border: 1px solid var(--line);
}

.actual-print-preview {
  min-height: 270px;
  padding: 14px;
  overflow: auto;
}

.actual-print-preview h2,
.template-card-preview h2 {
  text-align: center;
  margin: 0 0 10px;
}

.actual-print-preview p,
.template-card-preview p {
  margin: 5px 0;
}

.actual-print-preview table,
.template-card-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
}

.actual-print-preview th,
.actual-print-preview td,
.template-card-preview th,
.template-card-preview td {
  border: 1px solid #667085;
  padding: 4px;
  white-space: normal;
}

.saved-print-preview {
  background: #f8fafc;
}

.template-card-preview {
  height: 190px;
  overflow: hidden;
  padding: 10px;
  font-size: 9px;
  pointer-events: none;
}

.paper-preview {
  margin: 0 auto;
  background: #ffffff;
  border: 1px dashed #9aa5b1;
  box-shadow: 0 12px 30px rgba(30, 41, 59, 0.18);
  padding: 18px;
  color: #111827;
}

.paper-preview input,
.paper-preview textarea {
  border: 1px dashed transparent;
  background: transparent;
  padding: 2px 4px;
}

.paper-preview input:focus,
.paper-preview textarea:focus {
  border-color: var(--brand);
  background: #f8fffb;
}

.designer-title {
  width: 100%;
  text-align: center;
  font-size: 22px;
  font-weight: 900;
  margin-bottom: 16px;
}

.designer-info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 26px;
  margin-bottom: 12px;
}

.designer-info-grid label {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
}

.designer-info-grid span,
.designer-footer-line span {
  color: #111827;
}

.designer-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  margin: 8px 0 12px;
}

.designer-table th,
.designer-table td {
  border: 1px solid #222;
  padding: 7px;
  text-align: center;
  white-space: nowrap;
}

.designer-table th {
  background: #f2f2f2;
}

.designer-table input {
  width: 100%;
  text-align: center;
  font-weight: 800;
}

.designer-footer-line {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

.designer-footer-line input {
  width: 90px;
  text-align: right;
}

.designer-wide {
  display: grid;
  gap: 5px;
  margin-top: 8px;
}

.designer-wide span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.check-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.check-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
  font-weight: 700;
}

.check-list input {
  width: auto;
  min-height: 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(380px, calc(100vw - 36px));
  background: #16231d;
  color: #ffffff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 10px;
    overflow: visible;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .nav-item {
    flex: 0 0 auto;
    display: flex;
  }

  .nav-view {
    width: auto;
  }

  .brand {
    display: none;
  }

  .nav-sort-toggle {
    align-self: flex-start;
    margin: 0;
  }

  .main {
    padding: 12px;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .split-view,
  .designer-grid,
  .form-grid,
  .line-row,
  .check-list {
    grid-template-columns: 1fr;
  }

  .designer-grid {
    min-height: 0;
  }

  .template-preview-compare {
    grid-template-columns: 1fr;
  }

  .designer-left,
  .designer-right {
    max-height: none;
  }

  .paper-preview {
    width: 720px !important;
  }

  .topbar {
    align-items: flex-start;
  }

  table {
    min-width: 660px;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 15px;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 15;
    inset: auto 0 0 0;
    height: 68px;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: rgba(22, 35, 29, 0.97);
    box-shadow: 0 -8px 24px rgba(15, 23, 19, 0.18);
  }

  .nav {
    height: 100%;
    display: flex;
    align-items: stretch;
    gap: 4px;
  }

  .nav-item {
    flex: 1 0 70px;
    min-width: 70px;
  }

  .nav-view {
    width: 100%;
    padding: 8px 4px;
    text-align: center;
    font-size: 12px;
    border-radius: 10px;
  }

  .nav-sort-toggle,
  .nav-order-actions {
    display: none !important;
  }

  .main {
    padding: 10px 10px 92px;
  }

  .topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    margin: -10px -10px 12px;
    padding: 10px 12px;
    background: rgba(237, 242, 238, 0.94);
    backdrop-filter: blur(10px);
  }

  .topbar h2 {
    font-size: 20px;
  }

  .panel {
    padding: 14px;
    border-radius: 14px;
  }

  .card.metric {
    min-height: 86px;
    border-radius: 14px;
  }

  .btn {
    min-height: 42px;
  }

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

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

  .carrier-metrics .metric {
    padding: 10px;
  }

  .carrier-metrics .metric strong {
    font-size: 24px;
  }

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