:root {
  --teal: #0F766E;
  --teal-dark: #134E4A;
  --teal-soft: #CCFBF1;
  --amber: #F59E0B;
  --bg: #F1F5F9;
  --card: #FFFFFF;
  --border: #E2E8F0;
  --muted: #64748B;
  --dark: #1E293B;
  --radius: 10px;
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--dark);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  gap: 8px;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--teal);
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 16px;
  flex-shrink: 0;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand strong { font-size: 18px; letter-spacing: 0.02em; }
.brand span { font-size: 13px; opacity: 0.85; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

.btn {
  appearance: none;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  background: #e2e8f0;
  color: var(--dark);
}
.btn:hover { filter: brightness(0.97); }
.btn.ghost {
  background: var(--teal-dark);
  color: #fff;
}
.btn.accent {
  background: var(--amber);
  color: #1c1917;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 0.95fr) minmax(420px, 1.25fr);
  gap: 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.form-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  min-height: 0;
  padding-right: 2px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--teal);
  font-weight: 700;
}
.card.collapsed { padding: 0; overflow: hidden; }
.card-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 12px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--teal);
  font-weight: 600;
  cursor: pointer;
}
.extra-body { padding: 0 14px 14px; }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
}
.span2 { grid-column: 1 / -1; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
input, select, textarea {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--teal-soft);
  border-color: var(--teal);
}
input[readonly] {
  background: #f8fafc;
  color: var(--muted);
}
.inline { display: flex; gap: 6px; }
.inline input { flex: 1; }
.inline select { width: auto; min-width: 78px; }
.hint { font-weight: 400; color: #94a3b8; font-size: 11px; }

.page-credit {
  text-align: center;
  color: #94a3b8;
  font-size: 12px;
  margin: 4px 0 8px;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.tab {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { background: #fff; }
.tab.active {
  background: #fff;
  color: var(--teal);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.preview-scroll {
  flex: 1;
  overflow: auto;
  padding: 16px;
  background: #e2e8f0;
}
.doc-panel {
  display: none;
  background: #fff;
  margin: 0 auto;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}
.doc-panel.active { display: block; }

/* Shared doc chrome */
.doc {
  width: 210mm;
  max-width: 100%;
  min-height: 260mm;
  padding: 14mm 12mm;
  color: #111;
  font-size: 12px;
  line-height: 1.35;
  background: #fff;
}
.doc table { border-collapse: collapse; width: 100%; }
.doc .muted { color: #555; }
.doc .right { text-align: right; }
.doc .center { text-align: center; }
.doc .bold { font-weight: 700; }
.doc pre.addr {
  margin: 0;
  font: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Packing list / Invoice shared header style */
.pl-head, .inv-head {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 8px;
  margin-bottom: 8px;
}
.pl-title, .inv-title {
  text-align: right;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.pl-sub, .inv-sub {
  text-align: right;
  font-size: 16px;
  font-weight: 700;
  margin-top: 18px;
}
.meta-box {
  border: 1px solid #222;
  margin-top: 8px;
}
.meta-box td, .meta-box th {
  border: 1px solid #222;
  padding: 4px 6px;
  vertical-align: top;
}
.line-table th, .line-table td {
  border: 1px solid #222;
  padding: 5px 6px;
  vertical-align: top;
}
.line-table th {
  background: #f3f4f6;
  font-weight: 700;
  text-align: center;
}

/* Sales confirmation */
.sc-title-zh {
  font-size: 20px;
  font-weight: 700;
  text-align: right;
}
.sc-title-en {
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}
.sc-company {
  font-size: 16px;
  font-weight: 700;
}
.sc-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr;
  gap: 8px;
  margin: 10px 0;
}
.sc-terms { margin-top: 14px; }
.sc-terms p { margin: 4px 0; }
.sc-sign {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 36px;
  text-align: center;
}

/* Customs declaration */
.cd {
  width: 210mm;
  max-width: 100%;
  padding: 6mm 5mm;
  font-size: 11px;
  background: #fff;
  color: #111;
}
.cd h1 {
  margin: 0 0 6px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.18em;
}
.cd-top {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 1fr auto;
  gap: 8px;
  margin-bottom: 4px;
  color: #111;
  font-size: 11px;
}
.cd-table {
  width: 100%;
  border: 1.5px solid #111;
  border-collapse: collapse;
  table-layout: fixed;
}
.cd-table td, .cd-table th {
  border: 1px solid #111;
  padding: 2px 4px;
  vertical-align: top;
  word-break: break-word;
}
.cd-table .lab {
  color: #111;
  font-size: 10px;
  line-height: 1.2;
}
.cd-table .val {
  font-weight: 600;
  min-height: 14px;
  line-height: 1.25;
  font-size: 11px;
}
.cd-tall-sm { min-height: 22px; }
.cd-tall { min-height: 48px; }
.cd-meta td { height: 38px; }
.cd-items {
  border-top: none;
}
.cd-items th {
  background: #fff;
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  padding: 3px 2px;
}
.cd-items td {
  font-size: 10px;
  height: 22px;
}
.cd-items .center { text-align: center; vertical-align: middle; }
.cd-items .bold { font-weight: 700; }
.cd-spec {
  margin-top: 2px;
  font-size: 9px;
  font-weight: 400;
  color: #222;
  line-height: 1.3;
}
.cd-price { line-height: 1.25; }
.cd-empty td {
  height: 18px;
  border-top-style: dashed;
  border-top-color: #666;
}
.cd-confirm {
  border-top: none;
  font-size: 10px;
}
.cd-confirm td {
  border: 1px solid #111;
  padding: 3px 4px;
  vertical-align: middle;
  white-space: nowrap;
}
.cd-sign {
  border-top: none;
}
.cd-sign-left {
  width: 72%;
  height: 88px;
  position: relative;
  padding: 4px 6px !important;
}
.cd-sign-top {
  display: flex;
  gap: 28px;
  font-size: 10px;
}
.cd-legal {
  position: absolute;
  right: 10px;
  top: 28px;
  font-size: 10px;
  max-width: 55%;
  text-align: right;
  line-height: 1.35;
}
.cd-sign-bottom {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  justify-content: space-between;
  font-size: 10px;
}
.cd-seal-label { margin-right: 40px; }
.cd-customs-note {
  width: 28%;
  padding: 4px !important;
}
.cd-stamp-box {
  min-height: 64px;
}

.print-root { display: none; }

@media (max-width: 1100px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; overflow: visible; }
  .layout {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .form-pane, .preview-pane { max-height: none; overflow: visible; }
  .preview-scroll { max-height: none; }
}

@media print {
  body { background: #fff; overflow: visible; }
  .app, .topbar, .form-pane, .tabs, .page-credit { display: none !important; }
  .preview-pane, .preview-scroll, .layout, .app {
    display: block !important;
    overflow: visible !important;
    height: auto !important;
    background: #fff !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  .doc-panel { display: none !important; box-shadow: none !important; }
  .doc-panel.print-now { display: block !important; page-break-after: always; }
  .print-root.print-mode {
    display: block !important;
  }
  .print-root.print-mode .doc-panel {
    display: block !important;
    page-break-after: always;
    box-shadow: none !important;
  }
  .doc, .cd { width: auto; min-height: auto; }
}
