:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-soft: #f9faf7;
  --text: #1f2a2e;
  --muted: #66737a;
  --line: #dfe4df;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --danger: #b42318;
  --warning-bg: #fff7d6;
  --warning-text: #7a5600;
  --shadow: 0 10px 30px rgba(27, 42, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  overflow-x: hidden;
}

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

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
  padding: 0 18px;
  font-weight: 700;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary {
  background: var(--primary);
  color: white;
}

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

.secondary {
  background: #e7ece8;
  color: var(--text);
}

.secondary:hover:not(:disabled) {
  background: #d9e2dc;
}

.topbar {
  align-items: stretch;
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 0 auto;
  max-width: 920px;
  padding: 22px clamp(16px, 4vw, 40px) 14px;
}

.topbar > div {
  width: 100%;
}

.header-actions,
.more-menu-panel,
.small-menu {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.more-menu {
  align-self: start;
  position: relative;
}

.more-menu summary,
.management-links summary {
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
  min-height: 44px;
  padding: 10px 0;
}

.more-menu-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  justify-content: flex-start;
  min-width: 220px;
  padding: 10px;
  position: absolute;
  right: 0;
  z-index: 4;
}

.text-link {
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 0 8px;
  text-align: left;
}

.text-link:hover {
  color: var(--text);
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
}

h2 {
  font-size: 20px;
}

.status,
.message {
  margin: 8px 0 0;
  min-height: 24px;
}

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

.message.error,
.status.error {
  color: var(--danger);
  font-weight: 700;
}

.message.warning,
.status.warning {
  color: var(--warning-text);
  font-weight: 700;
}

.message.success,
.status.success {
  color: var(--primary-dark);
  font-weight: 700;
}

.ai-status-panel {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  gap: 4px 12px;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  margin-top: 8px;
  padding: 10px 12px;
}

.ai-status-panel:empty {
  display: none;
}

.ai-status-panel b {
  color: var(--text);
}

.ai-status-panel .full {
  grid-column: 1 / -1;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 0 clamp(16px, 4vw, 40px) 18px;
}

.compact-tabs {
  display: none;
}

.tab {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.tab.active {
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
}

main {
  padding: 0 clamp(16px, 4vw, 40px) 96px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.workbench {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(320px, 0.9fr) minmax(420px, 1.3fr);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.unified-panel {
  margin: 0 auto 18px;
  max-width: 860px;
}

.unified-panel h2 {
  font-size: clamp(26px, 6vw, 42px);
  margin-bottom: 14px;
  text-align: center;
}

.unified-input {
  font-size: 18px;
  line-height: 1.5;
  min-height: 210px;
}

.draft-shelf {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 12px;
}

.draft-shelf.empty {
  display: none;
}

.draft-shelf-title {
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 8px;
}

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

.draft-card {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  padding: 8px;
}

.draft-main {
  background: transparent;
  color: var(--text);
  display: grid;
  justify-items: start;
  min-height: 40px;
  padding: 0;
  text-align: left;
}

.draft-main span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.draft-delete {
  background: #f3e7e4;
  color: var(--danger);
  min-height: 40px;
  padding: 0 12px;
}

.large-action {
  font-size: 20px;
  min-height: 56px;
  width: 100%;
}

.unified-result {
  margin-top: 14px;
}

.unified-result.empty,
.unified-result.muted,
.unified-result.error {
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.unified-result.error {
  color: var(--danger);
  font-weight: 800;
}

.intent-card {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.intent-head {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

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

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

.summary-grid div {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

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

.summary-grid dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.summary-grid dd {
  font-weight: 900;
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.mini-items,
.choice-list {
  display: grid;
  gap: 8px;
}

.mini-items div {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.success-card {
  border-color: rgba(15, 118, 110, 0.35);
}

.management-links {
  box-shadow: none;
  margin: 0 auto 18px;
  max-width: 860px;
}

.small-menu {
  justify-content: flex-start;
}

.quick-grid,
.stat-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.quick-card,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--text);
  display: grid;
  min-height: 112px;
  padding: 18px;
  text-align: left;
}

.quick-card strong,
.stat-card strong {
  font-size: 20px;
}

.quick-card span,
.stat-card span {
  color: var(--muted);
  line-height: 1.35;
}

.stat-card .value {
  font-size: 26px;
  font-weight: 900;
  margin-top: 8px;
}

.entry-panel {
  align-self: start;
}

.field-label {
  display: block;
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 10px;
}

textarea {
  border: 2px solid var(--line);
  border-radius: 8px;
  min-height: 260px;
  outline: none;
  padding: 16px;
  resize: vertical;
  width: 100%;
}

textarea:focus,
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.actions,
.searchbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

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

.badge {
  background: #edf3ef;
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  padding: 6px 10px;
  white-space: nowrap;
}

.badge.saved {
  background: #dff4ec;
  color: var(--primary-dark);
}

.preview.empty {
  align-items: center;
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: flex;
  min-height: 360px;
  justify-content: center;
  text-align: center;
}

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

.manual-banner {
  background: var(--warning-bg);
  border: 1px solid #eedc91;
  border-radius: 6px;
  color: var(--warning-text);
  font-weight: 800;
  margin-bottom: 14px;
  padding: 10px 12px;
}

.issue-form {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
}

.issue-form select,
.issue-form textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 40px;
  padding: 8px 10px;
}

.issue-form textarea {
  min-height: 76px;
}

.issue-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

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

.form-grid label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

.form-grid label.full {
  grid-column: 1 / -1;
}

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

select {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

.items-wrap {
  margin-top: 18px;
  overflow-x: hidden;
}

.item-cards {
  display: grid;
  gap: 12px;
}

.item-card,
.order-card,
.profile-panel {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.item-card label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

.item-card-head,
.item-card-row,
.order-card,
.customer-stats,
.profile-grid {
  display: grid;
  gap: 10px;
}

.item-card-head {
  align-items: center;
  grid-template-columns: 1fr auto;
}

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

.amount-box {
  align-items: end;
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
}

.amount-box span {
  color: var(--text);
  font-size: 18px;
  font-weight: 900;
}

.order-card {
  align-items: center;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) auto;
  margin-bottom: 12px;
}

.customer-stats {
  color: var(--muted);
  font-size: 13px;
}

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

.candidate-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.candidate-card,
.mini-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: grid;
  gap: 4px;
  padding: 10px;
  text-align: left;
}

.mini-card span {
  color: var(--muted);
}

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

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

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

td input {
  min-width: 72px;
}

.number {
  text-align: right;
}

.amount-cell,
.total {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.history-hint {
  color: var(--warning-text);
  font-size: 12px;
  line-height: 1.4;
  min-width: 120px;
}

.history-hint strong {
  color: #593f00;
}

.table-actions {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
}

.tiny {
  min-height: 34px;
  padding: 0 10px;
}

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

.orders-list {
  margin-top: 14px;
  overflow-x: hidden;
}

.orders-list .empty-list {
  background: var(--surface-soft);
  border-radius: 8px;
  color: var(--muted);
  padding: 30px;
  text-align: center;
}

.nowrap {
  white-space: nowrap;
}

#printArea {
  display: none;
}

.print-sheet {
  color: #111;
  font-family: "Songti SC", "SimSun", serif;
  padding: 0;
}

.print-copy {
  break-after: page;
  min-height: 270mm;
  page-break-after: always;
  padding: 8mm 0;
}

.print-copy:last-child {
  break-after: auto;
  page-break-after: auto;
}

.print-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 12px;
  text-align: center;
}

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

.print-meta-full {
  grid-column: 1 / -1;
}

.print-table th,
.print-table td {
  border: 1px solid #333;
  padding: 7px;
}

.print-footer {
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr 1fr;
  margin-top: 24px;
}

.print-summary {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

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

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

  .header-actions {
    justify-content: flex-start;
  }

  .more-menu-panel {
    position: static;
  }

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

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

  .quick-grid,
  .stat-grid {
    grid-template-columns: 1fr;
  }

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

  .draft-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  button {
    border-radius: 8px;
    min-height: 50px;
    width: 100%;
  }

  .topbar,
  main,
  .tabs {
    padding-left: 12px;
    padding-right: 12px;
  }

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

  textarea {
    min-height: 190px;
  }

  .panel {
    padding: 14px;
  }

  .actions,
  .searchbar,
  .table-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .item-card-row,
  .profile-grid,
  .order-card {
    grid-template-columns: 1fr;
  }
}

.bottom-action-bar {
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  bottom: 0;
  box-shadow: 0 -8px 24px rgba(27, 42, 38, 0.08);
  display: none;
  gap: 8px;
  grid-template-columns: 1.2fr 1fr 1fr;
  left: 0;
  padding: 10px 12px;
  position: fixed;
  right: 0;
  z-index: 10;
}

.bottom-action-bar.show {
  display: grid;
}

@media print {
  @page {
    margin: 12mm;
  }

  body {
    background: white;
  }

  #app {
    display: none;
  }

  .no-print,
  button,
  input,
  textarea,
  nav {
    display: none !important;
  }

  #printArea {
    display: block;
  }
}
