:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f6f9fc;
  --line: #d8e0e8;
  --text: #15202b;
  --muted: #637381;
  --primary: #0f6cbd;
  --primary-dark: #0a4f8a;
  --success: #12724f;
  --warning: #9a6700;
  --danger: #b42318;
  --shadow: 0 12px 32px rgba(21, 32, 43, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(15, 108, 189, 0.08), transparent 30%),
    linear-gradient(180deg, #f7fafc 0%, #edf3f8 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  width: calc(100% - 60px);
  max-width: 1800px;
  margin: 32px auto;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(216, 224, 232, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-panel {
  width: min(460px, 100%);
  margin: 72px auto;
  padding: 32px;
}

.brand h1,
.topbar h2,
.section-head h3,
.group-title h4 {
  margin: 0;
}

.brand p,
.eyebrow,
.demo-note,
.stat-card span {
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-grid span {
  font-size: 14px;
  color: var(--muted);
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  outline: 2px solid rgba(15, 108, 189, 0.18);
  border-color: var(--primary);
}

.primary-btn,
.ghost-btn,
.text-btn {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.primary-btn {
  padding: 12px 16px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.ghost-btn {
  padding: 11px 15px;
  background: #eef5fb;
  color: var(--primary-dark);
}

.text-btn {
  padding: 0;
  color: var(--primary);
  background: transparent;
}

.danger-text-btn {
  color: var(--danger);
}

.small {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.demo-note {
  margin-top: 20px;
  padding: 16px;
  border-radius: 12px;
  background: var(--panel-soft);
  font-size: 14px;
}

.auth-panel .brand {
  text-align: center;
}

.auth-panel .brand h1 {
  font-size: 30px;
  letter-spacing: 0.04em;
}

.auth-panel .form-grid {
  grid-template-columns: 1fr;
  margin-top: 28px;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.dashboard {
  display: grid;
  gap: 20px;
}

.section-head,
.inline-actions,
.group-title,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head {
  margin-bottom: 18px;
}

.filter-row {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter-row input,
.filter-row select,
.filter-row button {
  height: 40px;
}

.filter-row input,
.filter-row select {
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.section-tip {
  color: var(--muted);
  font-size: 13px;
}

.stats-grid {
  display: grid;
  gap: 16px;
}

.stats-stack {
  display: grid;
  gap: 16px;
}

.stats-grid-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-grid-feature-split {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.stat-card strong {
  display: block;
  margin-top: 10px;
  font-size: 24px;
}

.stat-card-feature strong {
  font-size: 36px;
}

.stat-card-action {
  width: 100%;
  text-align: left;
}

.stat-card-action em {
  display: block;
  margin-top: 8px;
  color: var(--primary);
  font-style: normal;
  font-size: 13px;
}

.detail-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
}

.detail-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-panel-head h4 {
  margin: 0;
}

.dashboard > .panel,
#admin-view .panel,
#sales-view .panel {
  padding: 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th,
.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
  background: #f8fbfd;
}

.compact-table {
  font-size: 12px;
}

.compact-table th,
.compact-table td {
  padding: 9px 8px;
}

.compact-text td:nth-child(3),
.compact-text th:nth-child(3) {
  min-width: 150px;
}

.compact-text td,
.compact-text th {
  white-space: normal;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.success {
  background: #dcfae6;
  color: var(--success);
}

.badge.muted {
  background: #edf1f5;
  color: #52606d;
}

.table-scroll {
  overflow-x: auto;
}

.wide {
  min-width: 1030px;
}

.order-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-flow: row dense;
}

.full-width {
  grid-column: 1 / -1;
}

.order-form .order-field-date { grid-column: 1; }
.order-form .order-field-product { grid-column: 2; }
.order-form .order-field-quantity { grid-column: 3; }
.order-form .order-field-wechat { grid-column: 1; }
.order-form .order-field-name { grid-column: 2; }
.order-form .order-field-phone { grid-column: 3; }
.order-form .order-field-address { grid-column: 1 / -1; }
.order-form .order-field-order-amount { grid-column: 1; }
.order-form .order-field-cod-received { grid-column: 2; }
.order-form .order-field-online { grid-column: 1; }
.order-form .order-field-cod { grid-column: 2; }
.order-form .order-field-deposit { grid-column: 3; }
.order-form .order-field-remark { grid-column: 1 / -1; }
.order-form .order-field-express-company { grid-column: 1; }
.order-form .order-field-express-no { grid-column: 2; }
.order-form .order-field-express-status { grid-column: 3; }

.group-block {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfdff;
}

.sales-order-groups {
  display: grid;
  gap: 16px;
}

.group-title {
  margin-bottom: 14px;
}

.month-total {
  margin-top: 16px;
  text-align: right;
  color: var(--primary-dark);
}

.table-input {
  width: 100%;
  min-width: 96px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
}

.mini-form-grid {
  display: grid;
  grid-template-columns: 2fr repeat(4, minmax(0, 0.45fr));
  gap: 12px;
  margin-bottom: 16px;
}

.mini-form-grid label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mini-form-grid span {
  font-size: 13px;
  color: var(--muted);
}

.mini-form-grid input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.mini-form-grid select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.mini-form-grid label:first-child {
  grid-column: span 1;
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
}

.table-pagination .ghost-btn.small {
  min-width: 72px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: #fff;
}

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

.account-form-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.entry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.entry-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f4f9fe 100%);
  text-align: left;
  cursor: pointer;
}

.entry-card strong {
  font-size: 18px;
}

.entry-card span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.entry-card.is-active {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px rgba(15, 108, 189, 0.16);
}

.admin-section-panel {
  padding: 20px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(21, 32, 43, 0.42);
}

.modal-card {
  position: relative;
  width: min(980px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 20px;
}

.align-table {
  table-layout: fixed;
}

.align-table th,
.align-table td {
  word-break: break-word;
}

.admin-order-table {
  table-layout: fixed;
}

.admin-order-table th,
.admin-order-table td {
  white-space: nowrap;
  padding-left: 6px;
  padding-right: 6px;
}

.admin-order-table th:nth-child(1),
.admin-order-table td:nth-child(1) {
  width: 86px;
}

.admin-order-table .wrap-product-name {
  display: block;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.admin-order-table th:nth-child(2),
.admin-order-table td:nth-child(2) {
  width: 50px;
}

.admin-order-table th:nth-child(3),
.admin-order-table td:nth-child(3) {
  width: 320px;
}

.admin-order-table th:nth-child(4),
.admin-order-table td:nth-child(4) {
  width: 90px;
}

.admin-order-table th:nth-child(5),
.admin-order-table td:nth-child(5) {
  width: 56px;
}

.admin-order-table th:nth-child(6),
.admin-order-table td:nth-child(6) {
  width: 64px;
}

.admin-order-table th:nth-child(7),
.admin-order-table td:nth-child(7),
.admin-order-table th:nth-child(8),
.admin-order-table td:nth-child(8),
.admin-order-table th:nth-child(9),
.admin-order-table td:nth-child(9) {
  width: 64px;
}

.admin-order-table th:nth-child(10),
.admin-order-table td:nth-child(10),
.admin-order-table th:nth-child(11),
.admin-order-table td:nth-child(11) {
  width: 72px;
}

.admin-order-table th:nth-child(12),
.admin-order-table td:nth-child(12) {
  width: 72px;
}

.admin-order-table th:nth-child(13),
.admin-order-table td:nth-child(13) {
  width: 180px;
}

.admin-order-table th:nth-child(14),
.admin-order-table td:nth-child(14) {
  width: 132px;
}

.admin-order-table th:nth-child(15),
.admin-order-table td:nth-child(15) {
  width: 104px;
  text-align: center;
}

.admin-order-table th:nth-child(16),
.admin-order-table td:nth-child(16) {
  width: 116px;
  text-align: right;
}

.admin-order-table .inline-actions {
  flex-wrap: nowrap;
}

#orders-panel .section-head {
  flex-wrap: nowrap;
}

#orders-panel .section-head .inline-actions {
  flex-wrap: nowrap;
  align-items: center;
}

.admin-order-table .express-no-input {
  min-width: 132px;
  width: 132px;
  white-space: nowrap;
}

.admin-order-table .express-status-input {
  min-width: 96px;
  width: 96px;
  text-align: center;
  text-align-last: center;
}

.admin-order-table .express-company-select {
  min-width: 72px;
  width: 72px;
}

.admin-extra-cost-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.admin-order-table .extra-cost-input {
  min-width: 56px;
  width: 56px;
  flex: 0 0 56px;
}

.admin-order-table .admin-remark-input {
  min-width: 74px;
  width: 74px;
  padding: 4px 8px;
  color: var(--danger);
  font-weight: 700;
}

.admin-order-table .admin-product-select {
  min-width: 126px;
  width: 126px;
}

.admin-order-table .admin-money-input {
  min-width: 58px;
  width: 58px;
}

.admin-extra-cost-cell .extra-note-btn {
  min-width: 46px;
  flex: 0 0 46px;
  white-space: nowrap;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  padding: 7px 6px;
}

.table-cell-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.table-cell-actions.inline {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.admin-order-table .table-cell-actions {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.admin-action-btn {
  min-width: 48px;
  padding: 7px 7px;
}

.danger-btn {
  background: #fde8e8;
  color: var(--danger);
}

.button-disabled {
  background: #e5ebf1;
  color: #8a96a3;
  cursor: not-allowed;
}

.sales-record-table {
  table-layout: fixed;
  font-size: 12px;
}

.sales-record-table th,
.sales-record-table td {
  padding: 8px 4px;
  white-space: nowrap;
}

.sales-record-table th:nth-child(1),
.sales-record-table td:nth-child(1) {
  width: 240px;
}

.sales-record-table th:nth-child(2),
.sales-record-table td:nth-child(2) {
  width: 92px;
}

.sales-record-table th:nth-child(3),
.sales-record-table td:nth-child(3) {
  width: 92px;
}

.sales-record-table th:nth-child(4),
.sales-record-table td:nth-child(4) {
  width: 92px;
}

.sales-record-table th:nth-child(5),
.sales-record-table td:nth-child(5) {
  width: 100px;
}

.sales-record-table th:nth-child(6),
.sales-record-table td:nth-child(6),
.sales-record-table th:nth-child(7),
.sales-record-table td:nth-child(7),
.sales-record-table th:nth-child(8),
.sales-record-table td:nth-child(8),
.sales-record-table th:nth-child(9),
.sales-record-table td:nth-child(9) {
  width: 92px;
}

.sales-record-table th:nth-child(10),
.sales-record-table td:nth-child(10) {
  width: 92px;
}

.sales-record-table th:nth-child(11),
.sales-record-table td:nth-child(11) {
  width: 92px;
}

.sales-record-table th:nth-child(12),
.sales-record-table td:nth-child(12) {
  width: 92px;
}

.sales-record-table th:nth-child(13),
.sales-record-table td:nth-child(13) {
  width: 88px;
}

.sales-record-table th:nth-child(14),
.sales-record-table td:nth-child(14) {
  width: 70px;
}

.sales-record-table .sales-express-status-input {
  min-width: 76px;
  width: 76px;
  padding: 4px 18px 4px 8px;
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  text-align-last: center;
}

.express-status-input option[value="拒签"],
.sales-express-status-input option[value="拒签"] {
  color: var(--danger);
  font-weight: 700;
}

.express-status-input.is-rejected,
.sales-express-status-input.is-rejected {
  color: var(--danger);
  font-weight: 700;
}

.sales-record-table .sales-remark-input {
  min-width: 88px;
  width: 88px;
  padding: 4px 8px;
  color: var(--danger);
  font-weight: 700;
}

.sales-product-preview {
  display: inline-block;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
  line-height: 1.4;
  max-height: calc(1.4em * 2);
  max-width: 20em;
}

.product-edit-input {
  min-width: 0;
  width: 100%;
}

.products-panel .table-cell-actions.inline {
  justify-content: flex-end;
}

#products-panel table th:nth-child(1),
#products-panel table td:nth-child(1) {
  width: 80ch;
}

#products-panel table th:nth-child(2),
#products-panel table td:nth-child(2) {
  width: 16ch;
}

#products-panel table th:nth-child(3),
#products-panel table td:nth-child(3),
#products-panel table th:nth-child(4),
#products-panel table td:nth-child(4),
#products-panel table th:nth-child(5),
#products-panel table td:nth-child(5) {
  width: 16ch;
}

.customer-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.customer-popover-layer {
  position: fixed;
  z-index: 9999;
  display: none;
  min-width: 240px;
  max-width: 360px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(21, 32, 43, 0.96);
  color: #fff;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.22);
  white-space: normal;
  word-break: break-word;
  line-height: 1.5;
  pointer-events: none;
}

.customer-popover-layer.is-visible {
  display: block;
}

.customer-popover-layer span {
  display: block;
}

.customer-popover-layer span:last-child {
  margin-top: 6px;
  color: #c5d4e6;
}

#audit-log-table th:nth-child(1),
#audit-log-table td:nth-child(1) {
  width: 180px;
}

#audit-log-table th:nth-child(2),
#audit-log-table td:nth-child(2) {
  width: 120px;
}

#audit-log-table th:nth-child(3),
#audit-log-table td:nth-child(3) {
  width: 140px;
}

.sales-record-table td:nth-child(10) {
  overflow: hidden;
  text-overflow: ellipsis;
}

.sales-product-cell {
  white-space: normal !important;
  word-break: break-word;
  line-height: 1.4;
}

.remark-text {
  color: var(--danger);
  font-weight: 700;
}

.remark-preview {
  display: inline-block;
  max-width: 15em;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.4;
}

@media (max-width: 960px) {
  .stats-grid-three,
  .order-form,
  .form-grid,
  .mini-form-grid,
  .entry-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    width: calc(100% - 30px);
    max-width: 1800px;
    margin: 20px auto;
  }

  .dashboard > .panel,
  .admin-section-panel,
  .modal-card {
    padding: 16px;
  }

  .auth-panel {
    margin: 32px auto;
    padding: 20px;
  }

  .topbar,
  .section-head,
  .inline-actions,
  .group-title,
  .form-actions,
  .detail-panel-head {
    flex-direction: column;
    align-items: stretch;
  }

  #orders-panel .section-head,
  #orders-panel .section-head .inline-actions {
    flex-direction: row;
    align-items: center;
  }

  .data-table {
    min-width: 760px;
  }

  .table-scroll {
    margin: 0 -4px;
    padding-bottom: 4px;
  }
}
