:root {
  --ink: #18312b;
  --muted: #687c76;
  --paper: #f5f7f2;
  --card: #ffffff;
  --brand: #12382f;
  --brand-2: #1f6b55;
  --accent: #d97731;
  --accent-soft: #fff2e7;
  --line: #dbe3de;
  --good: #16774d;
  --warn: #a96512;
  --bad: #b93a35;
  --blue: #2364aa;
  --shadow: 0 14px 34px rgba(22, 47, 39, 0.09);
  --radius: 18px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 90% -10%, rgba(205, 226, 206, 0.75), transparent 30rem),
    var(--paper);
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.boot-screen,
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.boot-screen {
  align-content: center;
  gap: 10px;
  color: var(--muted);
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  font-size: 23px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.login-card {
  width: min(440px, 100%);
  padding: 34px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 28px 80px rgba(18, 56, 47, 0.16);
  backdrop-filter: blur(14px);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 30px;
}

.login-brand h1 {
  margin: 0 0 3px;
  font-size: 24px;
}

.login-brand p,
.subtle {
  margin: 0;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 15px;
}

.field > span,
.field > label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 650;
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

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

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

input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  accent-color: var(--brand-2);
}

input[type="number"] {
  font-variant-numeric: tabular-nums;
}

.btn {
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
  font-weight: 720;
  transition: transform 0.12s, opacity 0.12s, background 0.12s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.btn.secondary {
  background: #fff;
  color: var(--brand);
  border-color: var(--line);
}

.btn.ghost {
  background: transparent;
  color: var(--brand);
  border-color: transparent;
}

.btn.warn {
  background: var(--accent);
}

.btn.danger {
  background: var(--bad);
}

.btn.small {
  min-height: 34px;
  padding: 6px 11px;
  border-radius: 10px;
  font-size: 13px;
}

.btn.full {
  width: 100%;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 72px;
  padding: 10px max(20px, calc((100vw - 1320px) / 2));
  background: rgba(245, 247, 242, 0.9);
  border-bottom: 1px solid rgba(219, 227, 222, 0.88);
  backdrop-filter: blur(16px);
}

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

.brand .brand-mark {
  width: 42px;
  height: 42px;
  font-size: 18px;
  border-radius: 13px;
  box-shadow: none;
}

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

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav::-webkit-scrollbar {
  display: none;
}

.mobile-nav {
  display: none;
}

.nav button {
  white-space: nowrap;
  padding: 9px 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

.nav button.active {
  color: var(--brand);
  background: #e5ece7;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-copy {
  text-align: right;
}

.user-copy strong,
.user-copy small {
  display: block;
}

.user-copy small {
  color: var(--muted);
  font-size: 11px;
}

.main {
  width: min(1320px, calc(100% - 40px));
  margin: 0 auto;
  padding: 30px 0 72px;
}

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

.page-head h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  letter-spacing: -0.02em;
}

.page-head p {
  max-width: 720px;
  margin: 7px 0 0;
  color: var(--muted);
}

.head-actions,
.inline-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.form-actions {
  margin-top: 18px;
}

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

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

.stat-card,
.card {
  border: 1px solid rgba(214, 224, 218, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 24px rgba(22, 47, 39, 0.045);
}

.stat-card {
  min-height: 132px;
  padding: 19px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  font-size: 31px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.025em;
}

.stat-card em {
  font-style: normal;
  color: var(--brand-2);
  font-size: 12px;
}

.card {
  padding: 20px;
}

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

.card-title h2,
.card-title h3 {
  margin: 0;
  font-size: 18px;
}

.notice {
  padding: 14px 16px;
  border: 1px solid #f0d4bd;
  border-radius: 14px;
  background: var(--accent-soft);
  color: #855029;
}

.notice.good {
  border-color: #bfddce;
  background: #edf8f2;
  color: var(--good);
}

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

.sticky {
  position: sticky;
  top: 92px;
}

.product-tools {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

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

.product-card {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 13px;
  min-height: 126px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.product-image {
  width: 76px;
  height: 76px;
  border-radius: 12px;
  object-fit: cover;
  background: linear-gradient(145deg, #dfe9e2, #f5e6d7);
}

.product-placeholder {
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.product-card h3 {
  margin: 1px 0 4px;
  font-size: 15px;
}

.product-card p {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  min-height: 33px;
}

.price {
  color: var(--brand);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
}

.qty-control input {
  min-height: 36px;
  padding: 5px 8px;
}

.cart-lines {
  display: grid;
  gap: 9px;
  max-height: 380px;
  overflow: auto;
}

.cart-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding-bottom: 9px;
  border-bottom: 1px dashed var(--line);
}

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

.cart-total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 18px 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.cart-total strong {
  font-size: 24px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #edf1ee;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tag.pending_review,
.tag.draft {
  background: #fff2db;
  color: var(--warn);
}

.tag.reviewed,
.tag.shipped,
.tag.enabled {
  background: #e8f6ee;
  color: var(--good);
}

.tag.cancelled,
.tag.disabled {
  background: #fae9e8;
  color: var(--bad);
}

.tag.hq_warehouse {
  background: #e8f0fb;
  color: var(--blue);
}

.tag.supplier_direct,
.tag.hq_direct {
  background: #f4eafb;
  color: #7b3fa0;
}

.order-list,
.shipment-list {
  display: grid;
  gap: 14px;
}

.order-card {
  padding: 0;
  overflow: hidden;
}

.order-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 19px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.order-head strong,
.order-head small {
  display: block;
}

.order-head small {
  margin-top: 3px;
  color: var(--muted);
}

.order-meta {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: start;
}

.order-body {
  padding: 17px 19px;
}

.payment-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #e7cda1;
  border-radius: 12px;
  background: #fff8e9;
}

.payment-panel > div {
  display: grid;
  gap: 2px;
}

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

.payment-panel.paid {
  border-color: #a6d2b5;
  background: #eef9f1;
}

.payment-panel.unavailable {
  border-color: var(--line);
  background: #f7f6f2;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th {
  padding: 10px;
  color: var(--muted);
  font-weight: 700;
  text-align: left;
  background: #f5f8f5;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 11px 10px;
  border-bottom: 1px solid #edf1ee;
  vertical-align: top;
}

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

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.warn-text {
  color: var(--warn);
}

.good-text {
  color: var(--good);
}

.review-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) repeat(3, minmax(100px, 0.45fr)) minmax(150px, 0.8fr);
  gap: 10px;
  align-items: end;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

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

.review-product strong,
.review-product small {
  display: block;
}

.review-product small {
  color: var(--muted);
  margin-top: 3px;
}

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

.tabs button {
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--muted);
  white-space: nowrap;
}

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

.filter-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 18px;
}

.filter-bar .field {
  margin: 0;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 17px;
}

.summary-item {
  padding: 12px;
  border-radius: 12px;
  background: #f5f8f5;
}

.summary-item span,
.summary-item strong {
  display: block;
}

.summary-item span {
  color: var(--muted);
  font-size: 11px;
}

.summary-item strong {
  margin-top: 5px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

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

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

.compact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}

.compact-item strong,
.compact-item small {
  display: block;
}

.compact-item small {
  margin-top: 3px;
  color: var(--muted);
}

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

.loading {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 28px;
  max-width: min(520px, calc(100% - 32px));
  padding: 12px 17px;
  border-radius: 13px;
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s, transform 0.2s;
}

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

.toast.error {
  background: var(--bad);
}

.order-alert-bar {
  width: min(1320px, calc(100% - 40px));
  margin: 18px auto -8px;
  padding: 13px 16px;
  border: 1px solid #b9d8cb;
  border-radius: 16px;
  background: #f2faf6;
  box-shadow: 0 8px 22px rgba(18, 56, 47, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.alert-status,
.alert-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-status > div {
  display: grid;
  gap: 3px;
}

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

.alert-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #37a06f;
  box-shadow: 0 0 0 5px rgba(55, 160, 111, 0.13);
}

.alert-dot.new {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(217, 132, 44, 0.16);
  animation: alert-pulse 1.2s ease-in-out infinite;
}

.alert-dot.error {
  background: var(--bad);
  box-shadow: 0 0 0 5px rgba(180, 65, 59, 0.13);
}

@keyframes alert-pulse {
  50% {
    transform: scale(1.25);
  }
}

.print-root {
  display: none;
}

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

.code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
}

.address {
  margin: 12px 0 0;
  padding: 11px 12px;
  border-radius: 11px;
  background: #f5f8f5;
  color: var(--muted);
  font-size: 12px;
}

.metric-highlight {
  color: var(--accent);
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

@media (max-width: 1080px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .split,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .sticky {
    position: static;
  }

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

@media (max-width: 760px) {
  .topbar {
    align-items: center;
    min-height: 62px;
    padding: 8px 14px;
  }

  .brand {
    min-width: auto;
  }

  .brand-copy,
  .user-copy {
    display: none;
  }

  .desktop-nav {
    display: none;
  }

  .mobile-nav {
    display: flex;
    position: fixed;
    z-index: 30;
    left: 0;
    right: 0;
    bottom: 0;
    justify-content: flex-start;
    padding: 8px max(10px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 26px rgba(22, 47, 39, 0.08);
    overflow: hidden;
  }

  .mobile-nav button {
    flex: 1 1 0;
    min-width: 66px;
    padding: 8px 9px;
    font-size: 12px;
  }

  .main {
    width: min(100% - 24px, 1320px);
    padding-top: 20px;
    padding-bottom: 110px;
  }

  .order-alert-bar {
    width: calc(100% - 24px);
    margin-top: 12px;
    margin-bottom: 0;
    align-items: flex-start;
    flex-direction: column;
  }

  .alert-actions {
    width: 100%;
    flex-wrap: wrap;
  }

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

  .stats,
  .product-grid,
  .field-row,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .stat-card {
    min-height: 104px;
  }

  .stat-card strong {
    font-size: 27px;
  }

  .product-card {
    grid-template-columns: 68px minmax(0, 1fr);
  }

  .product-image {
    width: 68px;
    height: 68px;
  }

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

  .review-product {
    grid-column: 1 / -1;
  }

  .review-row .field:last-child {
    grid-column: 1 / -1;
  }

  .filter-bar {
    grid-template-columns: 1fr 1fr;
  }

  .filter-bar .btn {
    grid-column: 1 / -1;
  }

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

  .order-meta {
    justify-content: flex-start;
  }

  .login-card {
    padding: 25px 21px;
  }
}

@media print {
  .topbar,
  .mobile-nav,
  .order-alert-bar,
  .no-print,
  .head-actions,
  .tabs,
  .filter-bar,
  .btn,
  .toast {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .main {
    width: 100%;
    padding: 0;
  }

  .card {
    box-shadow: none;
    break-inside: avoid;
  }

  body.print-single-order > * {
    display: none !important;
  }

  body.print-single-order > #print-root {
    display: block !important;
  }

  .print-document {
    color: #111;
    font-size: 10.5pt;
  }

  .print-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #111;
  }

  .print-title p,
  .print-title h1 {
    margin: 0;
  }

  .print-title p {
    margin-bottom: 3px;
    color: #555;
    font-size: 9pt;
  }

  .print-title h1 {
    font-size: 22pt;
    letter-spacing: 0.12em;
  }

  .print-order-code {
    display: grid;
    gap: 4px;
    text-align: right;
  }

  .print-order-code strong {
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12pt;
  }

  .print-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0;
    margin: 14px 0 0;
    border-top: 1px solid #bbb;
    border-left: 1px solid #bbb;
  }

  .print-meta-grid > div {
    display: grid;
    grid-template-columns: 78px 1fr;
    gap: 8px;
    padding: 7px 9px;
    border-right: 1px solid #bbb;
    border-bottom: 1px solid #bbb;
  }

  .print-meta-grid span,
  .print-address span {
    color: #555;
  }

  .print-address {
    display: grid;
    grid-template-columns: 90px 1fr;
    gap: 8px;
    padding: 9px;
    margin-bottom: 12px;
    border: 1px solid #bbb;
    border-top: 0;
  }

  .print-document .table-wrap {
    overflow: visible;
  }

  .print-document table {
    font-size: 9pt;
  }

  .print-document th,
  .print-document td {
    padding: 7px 6px;
    border-color: #aaa;
  }

  .print-totals {
    display: flex;
    justify-content: flex-end;
    gap: 20px;
    padding: 10px 0;
    border-bottom: 1px solid #bbb;
  }

  .print-notes {
    padding: 8px 0;
  }

  .print-notes p {
    margin: 4px 0;
  }

  .print-no-price-notice {
    margin-top: 10px;
    padding: 7px 9px;
    border: 1px solid #aaa;
    background: #f7f7f7;
    font-size: 9pt;
    text-align: center;
  }

  .print-footer {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    margin-top: 18px;
    padding-top: 8px;
    border-top: 1px solid #aaa;
    color: #555;
    font-size: 8.5pt;
  }
}

@page {
  size: A4 portrait;
  margin: 12mm;
}
