:root {
  --ink: #17211e;
  --muted: #687570;
  --line: #dce4e1;
  --soft: #f4f7f6;
  --green: #0b6b57;
  --green-dark: #075043;
  --green-soft: #e8f4f0;
  --red: #d4473f;
  --amber: #fff2bf;
  --white: #fff;
  --shadow: 0 14px 40px rgba(26, 53, 45, .12);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: #eef2f1; }
body { margin: 0; color: var(--ink); font-family: "Microsoft YaHei UI", "Microsoft YaHei", Arial, sans-serif; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-shell { min-height: 100vh; padding-bottom: 280px; }
.topbar { height: 68px; padding: 0 max(24px, calc((100vw - 1180px) / 2)); display: flex; align-items: center; justify-content: space-between; background: var(--white); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border: 2px solid var(--red); border-radius: 50%; color: var(--red); font-weight: 800; font-size: 13px; }
.brand div:last-child { display: grid; gap: 1px; }
.brand strong { font-size: 16px; }
.brand span { font-size: 11px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 14px; }
.save-state { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.save-state i { width: 7px; height: 7px; border-radius: 50%; background: #27a47e; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; color: var(--green); background: var(--green-soft); border: 0; border-radius: 6px; }

.view-tabs { height: 49px; padding: 0 max(24px, calc((100vw - 1180px) / 2)); display: flex; align-items: flex-end; gap: 28px; background: var(--white); border-bottom: 1px solid var(--line); }
.view-tab { height: 49px; padding: 0 2px; color: var(--muted); background: transparent; border: 0; border-bottom: 3px solid transparent; font-weight: 600; }
.view-tab.active { color: var(--green); border-color: var(--green); }
main { width: min(1180px, calc(100% - 48px)); margin: 0 auto; }
.view-panel { display: none; }
.view-panel.active { display: block; }
.form-heading, .preview-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 30px 0 20px; }
.eyebrow { margin: 0 0 5px; color: var(--green); font-size: 11px; font-weight: 800; text-transform: uppercase; }
h1 { margin: 0; font-size: 25px; line-height: 1.25; }
.order-badge { padding: 6px 12px; border-radius: 99px; background: #e8eceb; color: var(--muted); font-size: 12px; }

#orderForm { background: var(--white); border: 1px solid var(--line); border-radius: 8px; }
.form-section { display: grid; grid-template-columns: 180px 1fr; gap: 28px; padding: 27px 30px; border-bottom: 1px solid var(--line); }
.last-section { border-bottom: 0; }
.section-title { display: flex; align-items: flex-start; gap: 12px; min-width: 0; }
.section-title > span { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 11px; font-weight: 800; }
.section-title h2 { margin: 2px 0 5px; font-size: 16px; }
.section-title p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.title-with-action { position: relative; }
.text-button { display: inline-flex; align-items: center; gap: 5px; margin-top: 18px; padding: 5px 0; color: var(--green); background: transparent; border: 0; font-size: 12px; font-weight: 700; }
.text-button svg { width: 16px; }
.field-grid { display: grid; gap: 17px; min-width: 0; }
.four-columns { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.three-columns { grid-template-columns: 1.35fr .8fr .8fr; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fee-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.field { display: grid; gap: 7px; min-width: 0; }
.field > span { color: #42504c; font-size: 12px; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; padding: 10px 11px; color: var(--ink); background: var(--white); border: 1px solid #cfd9d5; border-radius: 5px; outline: none; transition: border-color .2s, box-shadow .2s, background .2s; }
.field input, .field select { height: 42px; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(11, 107, 87, .1); }
.field input.voice-filled, .field select.voice-filled, .field textarea.voice-filled { background: var(--amber); border-color: #e7c85f; }
.field.full { grid-column: 1 / -1; }
.party-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
fieldset { min-width: 0; margin: 0; padding: 17px; border: 1px solid var(--line); border-radius: 6px; }
legend { padding: 0 7px; font-size: 13px; font-weight: 700; }
legend i { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; vertical-align: 1px; }
.sender-dot { background: #d89a22; }
.receiver-dot { background: var(--green); }
.money { position: relative; }
.money input { padding-left: 25px; }
.money::after { content: "¥"; position: absolute; left: 10px; top: 35px; color: var(--muted); font-size: 12px; }
.total-line { display: flex; justify-content: flex-end; align-items: baseline; gap: 18px; margin-top: 19px; padding-top: 16px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 12px; }
.total-line strong { color: var(--green); font-size: 15px; }
.total-line b { font-size: 23px; }
.control-field { grid-column: auto; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); height: 42px; padding: 3px; background: var(--soft); border: 1px solid var(--line); border-radius: 5px; }
.segmented button { min-width: 0; padding: 0 6px; color: var(--muted); background: transparent; border: 0; border-radius: 3px; font-size: 12px; }
.segmented button.active { color: var(--green); background: var(--white); box-shadow: 0 1px 5px rgba(24, 52, 44, .12); font-weight: 700; }

.cargo-list { display: grid; gap: 10px; }
.cargo-item { display: grid; grid-template-columns: 1.4fr .6fr .7fr .7fr .7fr 34px; gap: 9px; align-items: end; padding: 14px; background: var(--soft); border: 1px solid transparent; border-radius: 6px; }
.cargo-item .field span { font-size: 11px; }
.cargo-item input { background: var(--white); }
.cargo-item.voice-filled { background: var(--amber); border-color: #e7c85f; }
.remove-cargo { width: 34px; height: 42px; display: grid; place-items: center; color: #8b4c48; background: #f8e9e7; border: 0; border-radius: 5px; }
.remove-cargo svg { width: 17px; }

.preview-toolbar .primary-button { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border: 0; border-radius: 5px; color: var(--white); background: var(--green); font-weight: 700; }
.paper-wrap { overflow-x: auto; padding: 22px; background: #dfe5e3; border-radius: 8px; }
.waybill { width: 1050px; min-height: 620px; margin: 0 auto; padding: 35px 40px; color: #152357; background: var(--white); box-shadow: var(--shadow); font-family: SimSun, serif; }
.waybill-brand { position: relative; display: flex; align-items: center; gap: 8px; margin-bottom: 14px; color: #c8232c; }
.waybill-brand > span { width: 30px; height: 30px; display: grid; place-items: center; border: 2px solid currentColor; border-radius: 50%; font: 700 11px Arial; }
.waybill-brand > b { font-size: 20px; letter-spacing: 2px; }
.waybill-brand h2 { position: absolute; left: 50%; margin: 0; transform: translateX(-50%); color: #152357; font-size: 24px; letter-spacing: 10px; white-space: nowrap; }
.waybill-meta { display: grid; grid-template-columns: 1fr 1fr 1fr 1.3fr; padding: 5px 0; font-size: 12px; }
.waybill table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.waybill th, .waybill td { height: 35px; padding: 5px; border: 1px solid #56618a; font-size: 12px; text-align: center; word-break: break-all; }
.waybill th { background: #f6f7fb; font-weight: 400; }
.cargo-table th { height: 46px; }
.capital-line { display: flex; justify-content: space-between; padding: 10px 6px; border-left: 1px solid #56618a; border-right: 1px solid #56618a; font-size: 12px; }
.capital-line i { font-style: normal; }
.remark-row td, .remark-row th { height: 58px; }
.notice { margin-top: 10px; color: #d0252c; font-size: 10px; line-height: 1.6; }
.signatures { display: grid; grid-template-columns: 1fr 1fr 1.5fr; margin-top: 28px; color: #152357; font-size: 12px; }

.voice-dock { position: fixed; z-index: 20; left: 50%; bottom: 14px; width: min(820px, calc(100% - 28px)); transform: translateX(-50%); background: var(--white); border: 1px solid #cfd9d5; border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; transition: height .2s; }
.assistant-head { min-height: 55px; display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.assistant-avatar { flex: none; width: 34px; height: 34px; display: grid; place-items: center; color: var(--green); background: var(--green-soft); border-radius: 50%; }
.assistant-avatar svg { width: 19px; }
.assistant-head > div:nth-child(2) { display: grid; gap: 2px; min-width: 0; }
.assistant-head strong { font-size: 13px; }
.assistant-head span { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.dock-toggle { margin-left: auto; width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); background: transparent; border: 0; }
.voice-dock.collapsed .dock-toggle svg { transform: rotate(180deg); }
.voice-dock.collapsed > :not(.assistant-head) { display: none; }
.dialog-history { max-height: 68px; padding: 9px 12px 0; overflow-y: auto; }
.message { width: fit-content; max-width: 80%; margin-bottom: 7px; padding: 7px 10px; border-radius: 6px; font-size: 12px; line-height: 1.45; }
.assistant-message { background: var(--soft); color: #42504c; }
.user-message { margin-left: auto; color: var(--white); background: var(--green); }
.quick-actions { display: flex; gap: 7px; padding: 2px 12px 7px; overflow-x: auto; }
.quick-actions button { flex: none; padding: 5px 9px; color: var(--green); background: var(--green-soft); border: 0; border-radius: 4px; font-size: 11px; }
.composer { display: grid; grid-template-columns: 40px 1fr 40px; gap: 8px; align-items: center; margin: 0 12px; padding: 7px; background: var(--soft); border: 1px solid var(--line); border-radius: 6px; }
.composer textarea { width: 100%; max-height: 70px; padding: 7px 2px; resize: none; color: var(--ink); background: transparent; border: 0; outline: 0; font-size: 13px; }
.mic-button, .send-button { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 50%; }
.mic-button { color: var(--green); background: var(--green-soft); }
.mic-button.listening { color: var(--white); background: var(--red); animation: pulse 1.3s infinite; }
.send-button { color: var(--white); background: var(--green); }
.debug-panel { margin: 8px 12px 0; padding: 10px; background: #fbfcfc; border: 1px solid var(--line); border-radius: 6px; }
.debug-panel.collapsed .debug-grid, .debug-panel.collapsed .debug-note { display: none; }
.debug-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.debug-panel.collapsed .debug-head { margin-bottom: 0; }
.debug-head strong { font-size: 12px; }
.debug-head-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.debug-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.debug-meta span { padding: 2px 7px; color: var(--green); background: var(--green-soft); border-radius: 999px; font-size: 10px; }
.debug-toggle { height: 28px; padding: 0 10px; color: var(--green); background: var(--green-soft); border: 0; border-radius: 4px; font-size: 11px; font-weight: 700; }
.debug-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.debug-block { min-width: 0; display: grid; gap: 5px; }
.debug-block > span { color: #42504c; font-size: 11px; font-weight: 700; }
.debug-block pre { min-height: 88px; max-height: 160px; margin: 0; padding: 8px; overflow: auto; color: #264039; background: var(--soft); border-radius: 5px; font: 12px/1.45 Consolas, "Courier New", monospace; white-space: pre-wrap; word-break: break-word; }
.debug-note { margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.privacy-note { margin: 6px 0 8px; color: #89938f; font-size: 9px; text-align: center; }
.toast { position: fixed; z-index: 40; top: 82px; left: 50%; padding: 10px 15px; transform: translate(-50%, -15px); color: var(--white); background: #253b34; border-radius: 5px; box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transition: .22s; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(212, 71, 63, .15); } }

@media (max-width: 960px) {
  .form-section { grid-template-columns: 1fr; }
  .section-title { min-height: 35px; }
  .title-with-action .text-button { position: absolute; right: 0; top: -16px; }
  .fee-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .four-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .app-shell { padding-bottom: 265px; }
  .topbar { height: 60px; padding: 0 15px; }
  .save-state { display: none; }
  .view-tabs { padding: 0 16px; }
  main { width: 100%; }
  .form-heading, .preview-toolbar { padding: 22px 16px 15px; }
  h1 { font-size: 22px; }
  #orderForm { border-left: 0; border-right: 0; border-radius: 0; }
  .form-section { gap: 16px; padding: 22px 16px; }
  .party-grid { grid-template-columns: 1fr; }
  .three-columns, .fee-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .control-field { grid-column: 1 / -1; }
  .cargo-item { grid-template-columns: repeat(2, minmax(0, 1fr)); position: relative; padding-right: 50px; }
  .remove-cargo { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }
  .paper-wrap { border-radius: 0; }
  .voice-dock { bottom: 8px; }
  .debug-grid { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .four-columns, .two-columns, .three-columns { grid-template-columns: 1fr; }
  .fee-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .brand span { display: none; }
  .dialog-history { max-height: 60px; }
  .message { max-width: 94%; }
}

@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body { background: #fff; }
  .topbar, .view-tabs, .preview-toolbar, .voice-dock, .toast { display: none !important; }
  .app-shell { padding: 0; }
  main, #previewView, .paper-wrap { display: block !important; width: 100%; margin: 0; padding: 0; background: #fff; }
  #formView { display: none !important; }
  .waybill { width: 100%; min-height: auto; padding: 0; box-shadow: none; }
}
