:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --border: #d9e0e6;
  --text: #1c2733;
  --muted: #5f6f7e;
  --primary: #1f5f8b;
  --primary-dark: #174a6d;
  --primary-soft: #e8f1f8;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #067647;
  --success-soft: #e7f6ee;
  --warning: #8a5a00;
  --warning-soft: #fff5db;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.05);
  --font: system-ui, -apple-system, "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

h1,
h2 {
  margin: 0;
  line-height: 1.3;
}

/* ---------- 登录 ---------- */

.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(circle at 15% 10%, rgba(31, 95, 139, 0.16), transparent 42%),
    radial-gradient(circle at 90% 90%, rgba(31, 95, 139, 0.1), transparent 45%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px 28px;
}

.login-card h1 {
  font-size: 26px;
  letter-spacing: 0.01em;
  color: var(--primary);
}

.login-subtitle {
  margin: 4px 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.form-row {
  margin-bottom: 14px;
}

.form-row label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
}

.form-row input,
.form-row select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  min-height: 42px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.15);
}

.form-row.invalid input {
  border-color: var(--danger);
}

.field-error {
  margin: 5px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.field-hint {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
}

.check-row input {
  width: 18px;
  height: 18px;
  min-height: 0;
}

/* ---------- 通用控件 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover {
  background: #f6f8fa;
}

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

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

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

.btn.danger {
  color: var(--danger);
  border-color: #efc4bf;
  background: #fff;
}

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

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.ghost:hover {
  background: rgba(16, 24, 40, 0.06);
}

.btn.small {
  min-height: 34px;
  padding: 5px 11px;
  font-size: 14px;
}

.btn.block {
  width: 100%;
}

.btn.icon {
  min-height: 34px;
  width: 34px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.alert {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.alert.error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f4c7c3;
}

.alert.info {
  background: var(--primary-soft);
  color: var(--primary-dark);
  border: 1px solid #c6ddec;
}

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

/* ---------- 应用外壳 ---------- */

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 60px;
  padding: 0 24px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 4px rgba(16, 24, 40, 0.18);
}

.brand {
  color: #fff;
  text-decoration: none;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

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

.user-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.role-badge {
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 12px;
  line-height: 1.6;
  white-space: nowrap;
}

.topbar .btn.ghost {
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.45);
}

.topbar .btn.ghost:hover {
  background: rgba(255, 255, 255, 0.14);
}

.layout {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  min-height: calc(100vh - 60px);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.side-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.side-nav a:hover {
  background: #f2f6f9;
}

.side-nav a.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: #eef2f5;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

.side-nav a.active .nav-icon {
  background: var(--primary);
  color: #fff;
}

.main {
  min-width: 0;
  padding: 24px 28px 40px;
  outline: none;
}

.loading {
  color: var(--muted);
  padding: 24px 0;
}

/* ---------- 页面 ---------- */

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

.page-head h1 {
  font-size: 24px;
}

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

.search-form {
  display: flex;
  gap: 8px;
  flex: 1 1 320px;
  max-width: 460px;
}

.search-form input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  min-height: 40px;
  background: #fff;
}

.search-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.15);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}

.segmented button.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #f8fafb;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid #edf1f4;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

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

tbody tr:hover {
  background: #fafcfd;
}

td.col-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  font-weight: 600;
}

td.col-name {
  font-weight: 600;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

td.actions .btn + .btn {
  margin-left: 6px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status.on {
  background: var(--success-soft);
  color: var(--success);
}

.status.off {
  background: #eef1f4;
  color: var(--muted);
}

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

.empty-state strong {
  display: block;
  color: var(--text);
  margin-bottom: 4px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #fbfcfd;
  font-size: 14px;
  color: var(--muted);
}

.pager-actions {
  display: flex;
  gap: 8px;
}

.list-feedback {
  margin-bottom: 14px;
}

.list-feedback .alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ---------- 弹窗 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(16, 24, 40, 0.45);
}

.modal-panel {
  width: min(580px, 100%);
  max-height: min(86vh, 860px);
  overflow: auto;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 48px rgba(16, 24, 40, 0.24);
}

.modal-panel.narrow {
  width: min(420px, 100%);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.modal-head h2 {
  font-size: 18px;
}

.modal-body {
  padding: 18px 20px 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.form-actions .btn {
  min-width: 96px;
}

.modal-body .alert {
  margin-bottom: 14px;
}

.confirm-text {
  margin: 0 0 4px;
  font-size: 15px;
}

.confirm-hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  border-radius: 9px;
  background: #1c2733;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.22);
  display: flex;
  align-items: center;
  gap: 12px;
}

.toast.success {
  background: #0b5136;
}

.toast.error {
  background: #7a1a12;
}

.toast button {
  border: 0;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- 销售单（Phase 2A） ---------- */

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

.filter-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  min-height: 40px;
}

.link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.link:hover,
.link:focus-visible {
  text-decoration: underline;
}

.sub-text {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.detail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.detail-status {
  margin-bottom: 4px;
}

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

.detail-grid > div {
  min-width: 0;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.detail-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.section-title {
  font-size: 17px;
  margin: 22px 0 10px;
}

.status.draft {
  background: #eef1f4;
  color: var(--muted);
}

.status.confirmed {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.status.awaiting,
.status.partial {
  background: var(--warning-soft);
  color: var(--warning);
}

.status.done {
  background: var(--success-soft);
  color: var(--success);
}

.status.cancelled {
  background: #f4f1f0;
  color: #8a3b32;
}

/* Phase 2B：采购/审批状态 */
.status.submitted {
  background: #fff6e5;
  color: #b54708;
}

.status.approved {
  background: var(--success-soft);
  color: var(--success);
}

.status.rejected {
  background: #fdecec;
  color: #b42318;
}

.detail-grid .span-2 {
  grid-column: 1 / -1;
}

/* Phase 2B：附件 */
.attachment-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attachment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.attachment-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.attachment-main strong {
  overflow-wrap: anywhere;
}

.attachment-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.upload-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 12px;
  background: #f8fafb;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.upload-box select,
.upload-box input[type="file"] {
  min-height: 38px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.upload-box input[type="file"] {
  flex: 1 1 220px;
  min-width: 0;
}

.empty-inline {
  padding: 18px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* Phase 2B：审批 */
.approval-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.approval-item {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.approval-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.approval-comment {
  margin: 8px 0 0;
  padding: 8px 10px;
  background: #f8fafb;
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.decision-card {
  margin-top: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.decision-card label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.decision-card textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  resize: vertical;
}

.decision-card textarea:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(31, 95, 139, 0.15);
}

.decision-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

.totals {
  display: flex;
  justify-content: flex-end;
  gap: 28px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 14px 18px;
  background: #f8fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.totals > div {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

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

.totals strong {
  font-size: 18px;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

.sales-form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
}

.sales-form-card .form-row textarea,
.modal-body .form-row textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
  resize: vertical;
  min-height: 72px;
}

.sales-form-card .form-row textarea:focus,
.modal-body .form-row textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.15);
}

.line-item {
  display: grid;
  grid-template-columns: minmax(180px, 2fr) 0.7fr 1fr 0.8fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin-bottom: 10px;
  background: #fbfcfd;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.line-field {
  min-width: 0;
}

.line-field label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.line-field input,
.line-field select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  min-height: 38px;
}

.line-field input:focus,
.line-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.15);
}

.line-field input[readonly] {
  background: #f1f4f6;
  color: var(--muted);
}

.li-amount {
  display: flex;
  align-items: center;
  min-height: 38px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.line-remove {
  align-self: end;
}

.so-total {
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 10px;
  padding: 8px 2px 0;
  color: var(--muted);
}

.so-total strong {
  font-size: 22px;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}

#so-add-line {
  margin-top: 2px;
}

/* ---------- 响应式：手机 ---------- */

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

  .topbar {
    height: 54px;
    padding: 0 12px;
    gap: 8px;
  }

  .brand {
    font-size: 17px;
  }

  .user-name {
    max-width: 96px;
    font-size: 14px;
  }

  .role-badge {
    font-size: 11px;
    padding: 0 7px;
  }

  .topbar .btn.small {
    min-height: 32px;
    padding: 4px 9px;
    font-size: 13px;
  }

  .layout {
    display: block;
    min-height: calc(100vh - 54px);
  }

  .side-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    flex-direction: row;
    gap: 0;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom, 0px));
    border-right: 0;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(16, 24, 40, 0.07);
  }

  .side-nav a {
    flex: 1;
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px;
    font-size: 12px;
    text-align: center;
    border-radius: 7px;
  }

  .nav-icon {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .main {
    padding: 16px 14px calc(88px + env(safe-area-inset-bottom, 0px));
  }

  .page-head {
    margin-bottom: 12px;
  }

  .page-head h1 {
    font-size: 20px;
  }

  .page-head .btn {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 14px;
  }

  .toolbar {
    gap: 8px;
  }

  .search-form {
    flex-basis: 100%;
    max-width: none;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
    padding: 6px 8px;
  }

  .table-card {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
  }

  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td {
    display: block;
    width: 100%;
  }

  .table-wrap thead {
    display: none;
  }

  .table-wrap tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 6px 14px;
    margin-bottom: 10px;
  }

  .table-wrap tbody tr:hover {
    background: var(--surface);
  }

  .table-wrap tbody td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 7px 0;
    border-bottom: 1px dashed #e8edf1;
    font-size: 14px;
    text-align: right;
  }

  .table-wrap tbody tr td:last-child {
    border-bottom: 0;
  }

  .table-wrap tbody td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
  }

  .table-wrap tbody td.col-code,
  .table-wrap tbody td.col-name {
    font-size: 14.5px;
  }

  .table-wrap tbody td.actions {
    justify-content: flex-end;
    padding-top: 10px;
    border-bottom: 0;
  }

  .table-wrap tbody td.actions::before {
    content: none;
  }

  .table-wrap tbody td.actions .btn {
    flex: 1;
    min-height: 36px;
  }

  .pager {
    padding: 10px 2px;
  }

  .pager-actions {
    width: 100%;
  }

  .pager-actions .btn {
    flex: 1;
  }

  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-panel {
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }

  .modal-panel.narrow {
    width: 100%;
  }

  .modal-head {
    padding: 14px 16px;
  }

  .modal-body {
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  }

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

  .form-actions {
    position: sticky;
    bottom: 0;
    background: var(--surface);
    padding-top: 12px;
  }

  .form-actions .btn {
    flex: 1;
  }

  .page-head {
    flex-wrap: wrap;
  }

  .head-actions {
    width: 100%;
  }

  .head-actions .btn {
    flex: 1;
    min-width: 0;
  }

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

  .totals {
    gap: 14px;
    padding: 12px 14px;
  }

  .totals > div {
    flex: 1 1 30%;
    align-items: flex-start;
  }

  .sales-form-card {
    padding: 14px 14px 18px;
  }

  .line-item {
    grid-template-columns: 1fr 1fr;
    padding: 12px;
  }

  .line-field.grow {
    grid-column: 1 / -1;
  }

  .line-remove {
    grid-column: 1 / -1;
    width: 100%;
  }

  .section-title {
    margin-top: 18px;
  }

  .attachment-item {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .attachment-actions {
    justify-content: stretch;
  }

  .attachment-actions .btn {
    flex: 1;
    min-height: 36px;
  }

  .upload-box {
    flex-direction: column;
    align-items: stretch;
  }

  .upload-box select,
  .upload-box input[type="file"],
  .upload-box .btn {
    width: 100%;
  }

  .upload-box input[type="file"] {
    flex: 0 0 auto;
    height: auto;
  }

  .approval-item-head {
    flex-wrap: wrap;
  }

  .decision-actions {
    flex-wrap: wrap;
  }

  .decision-actions .btn {
    flex: 1;
    min-width: 0;
  }

  .toast {
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ---------- Phase 2C：付款、发票、业务链全景 ---------- */

.doc-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
}
.doc-type.purchase {
  background: #e8f1f8;
  color: #1f5f8b;
}
.doc-type.payment {
  background: #fdf0e3;
  color: #9a5b12;
}

.approval-type-line {
  margin: 0 0 10px;
}

.summary-box {
  margin: 14px 0;
  padding: 12px 16px;
  border: 1px solid var(--border, #d8dee4);
  border-radius: 10px;
  background: var(--surface-muted, #f7f9fb);
}
.summary-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0;
  font-size: 14px;
}
.summary-row span {
  color: var(--muted, #6b7785);
}
.summary-row strong {
  font-variant-numeric: tabular-nums;
}

.tax-preview {
  margin: 8px 0 0;
  color: var(--muted, #6b7785);
  font-size: 13px;
}

.invoice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}
.invoice-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border, #d8dee4);
  border-radius: 10px;
  background: #fff;
}
.invoice-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.invoice-main strong {
  font-size: 15px;
}
.invoice-amount {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.invoice-status {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.sub-text {
  color: var(--muted, #6b7785);
  font-size: 12px;
  font-weight: 400;
}

.upload-hint {
  color: var(--muted, #6b7785);
  font-size: 13px;
}

.chain-card {
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border, #d8dee4);
  border-radius: 10px;
  background: #fff;
}
.chain-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.chain-card-head strong {
  font-size: 15px;
}

.timeline {
  list-style: none;
  margin: 0 0 18px;
  padding: 0 0 0 6px;
}
.timeline-item {
  position: relative;
  display: flex;
  gap: 12px;
  padding: 0 0 18px 20px;
  border-left: 2px solid var(--border, #d8dee4);
}
.timeline-item:last-child {
  border-left-color: transparent;
  padding-bottom: 0;
}
.timeline-dot {
  position: absolute;
  left: -7px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #8aa4b8;
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--border, #d8dee4);
}
.timeline-dot.purchase_request {
  background: #1f5f8b;
}
.timeline-dot.payment_request {
  background: #b8741f;
}
.timeline-dot.invoice {
  background: #2f7d55;
}
.timeline-dot.attachment {
  background: #7a6bb0;
}
.timeline-body {
  flex: 1 1 auto;
  min-width: 0;
}
.timeline-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 3px;
}
.timeline-head strong {
  font-size: 14px;
}
.timeline-time {
  color: var(--muted, #6b7785);
  font-size: 12px;
  white-space: nowrap;
}
.timeline-link {
  margin-top: 4px;
  font-size: 13px;
}

@media (max-width: 640px) {
  .invoice-item {
    flex-wrap: wrap;
    gap: 8px;
  }
  .invoice-main {
    flex-basis: 100%;
  }
  .invoice-amount {
    align-items: flex-start;
  }
  .invoice-status {
    flex: 1 1 auto;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
  }
  .timeline-head {
    flex-direction: column;
    gap: 2px;
  }
  .summary-row {
    font-size: 13px;
  }
}

/* 单号在窄屏卡片里不因连字符折行 */
.detail-grid dd a,
td.col-code a,
td.col-code .sub-text {
  white-space: nowrap;
}

/* Phase 3A：库存统计卡片与入库行内只读字段 */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 14px 0 18px;
}
.stat-card {
  border: 1px solid var(--border, #d8dee4);
  border-radius: 10px;
  padding: 12px 16px;
  background: var(--surface-muted, #f7f9fb);
}
.stat-card span {
  display: block;
  color: var(--muted, #6b7785);
  font-size: 13px;
}
.stat-card strong {
  display: block;
  margin-top: 4px;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}
.line-static {
  padding: 9px 0;
  font-size: 14px;
  line-height: 1.4;
}
.line-static .sub-text {
  margin-left: 6px;
}
.toolbar .check-row {
  margin: 0;
  white-space: nowrap;
}

/* ---------- 报表（Phase 4A） ---------- */

.report-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 14px;
}

.report-tabs button {
  white-space: nowrap;
}

.report-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.report-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.report-field > span:first-child {
  font-weight: 600;
}

.report-field input:not([type="checkbox"]),
.report-field select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-height: 38px;
  background: #fff;
  color: var(--text);
  min-width: 150px;
}

.report-field input:focus,
.report-field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.15);
}

.report-field .check-row {
  min-height: 38px;
  white-space: nowrap;
  color: var(--text);
}

.report-field .check-row input {
  width: 18px;
  height: 18px;
  min-width: 0;
  min-height: 0;
}

.report-filter-actions {
  margin-left: auto;
}

@media (max-width: 760px) {
  .report-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  .report-tabs button {
    flex: 0 0 auto;
    padding: 6px 12px;
  }

  .report-filters {
    padding: 10px 12px;
  }

  .report-field {
    flex: 1 1 calc(50% - 8px);
  }

  .report-field input:not([type="checkbox"]),
  .report-field select {
    width: 100%;
    min-width: 0;
  }

  .report-field.report-check {
    flex-basis: 100%;
  }

  .report-filter-actions {
    flex-basis: 100%;
    margin-left: 0;
  }

  .report-filter-actions .btn {
    width: 100%;
  }
}

/* 手机底部导航：条目多时横向滚动，避免中文标签逐字换行 */
@media (max-width: 760px) {
  .side-nav {
    overflow-x: auto;
    scrollbar-width: none;
    justify-content: flex-start;
  }

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

  .side-nav a {
    flex: 1 1 0;
    min-width: 44px;
    white-space: nowrap;
  }
}

/* ---------- 期初库存导入（Phase 4B） ---------- */

.alert.success {
  background: var(--success-soft);
  color: var(--success);
  border: 1px solid #b7e3c9;
}

.opening-panel {
  margin-top: 22px;
}

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

.opening-section-head .section-title {
  margin: 0;
}

.opening-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip-path: inset(50%);
}

.opening-file-button {
  cursor: pointer;
}

.opening-file-input:focus-visible + .opening-file-button {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.table-wrap td.col-nowrap {
  white-space: nowrap;
}

.opening-date-label {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.opening-date-label input {
  min-height: 38px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.opening-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin: 4px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.batch-no {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.opening-actions {
  margin-top: 14px;
}

.opening-errors {
  margin-bottom: 14px;
}

@media (max-width: 760px) {
  .opening-date-label {
    width: 100%;
    justify-content: space-between;
  }

  .opening-date-label input {
    flex: 1;
    min-width: 0;
  }

  .opening-actions .btn {
    width: 100%;
  }

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

/* ---------- Agent 令牌（Phase 4C，仅 admin） ---------- */

.agent-token-panel {
  margin-top: 22px;
}

.agent-token-form .form-grid {
  margin-bottom: 4px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.scope-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

.scope-option {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.scope-option input {
  width: 18px;
  height: 18px;
  min-height: 0;
  margin: 3px 0 0;
  padding: 0;
  flex: none;
  accent-color: var(--primary);
}

.scope-option strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
}

.scope-option small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.scope-chip {
  display: inline-block;
  margin: 1px 2px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 12px;
  white-space: nowrap;
}

.token-plain {
  margin: 10px 0 12px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

.token-plain code {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-all;
  user-select: all;
}

.alert.warning {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid #ecd9a5;
}

#agent-token-form .form-actions {
  margin-top: 14px;
}

@media (max-width: 760px) {
  .scope-grid {
    grid-template-columns: 1fr;
  }

  .agent-token-form .form-actions .btn {
    width: 100%;
  }

  .token-plain code {
    font-size: 12px;
  }
}
