:root {
  --teal: #0F766E;
  --teal-dark: #134E4A;
  --teal-soft: #CCFBF1;
  --amber: #F59E0B;
  --bg: #F1F5F9;
  --card: #FFFFFF;
  --border: #E2E8F0;
  --muted: #64748B;
  --dark: #1E293B;
  --status-bg: #ECFDF5;
  --status-fg: #065F46;
  --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%;
  max-width: none;
  margin: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  gap: 8px;
  box-sizing: border-box;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: var(--teal);
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 16px;
  flex-shrink: 0;
}
.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.sm { padding: 6px 10px; font-size: 12px; }
.btn.ghost {
  background: var(--teal-dark);
  color: #fff;
}
.btn.primary { background: var(--teal); color: #fff; }
.btn.accent {
  background: var(--amber);
  color: #1c1917;
  font-weight: 700;
  font-size: 14px;
  padding: 8px 16px;
}
.btn.danger {
  background: transparent;
  color: #b91c1c;
  padding: 4px 8px;
}

.layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  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;
  height: 100%;
  max-height: none;
  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-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.card-head h2 { margin: 0; }

.grid2, .grid3 {
  display: grid;
  gap: 10px 12px;
}
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 1fr 1fr; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}
input, select, textarea {
  font: inherit;
  font-size: 13px;
  color: var(--dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #99f6e4;
  border-color: var(--teal);
}
textarea { resize: vertical; min-height: 64px; }

.total-box {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
}
.total-box .muted { font-size: 11px; color: var(--muted); }
.total-box strong {
  font-size: 20px;
  color: var(--teal);
  font-weight: 700;
}

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
table.items {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 920px;
}
table.items th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.items td {
  padding: 4px 4px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
table.items input {
  padding: 6px 6px;
  font-size: 12px;
  border-radius: 4px;
}
table.items .amt {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding: 0 6px;
  color: var(--dark);
}

.preview-pane {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: none;
  overflow: hidden;
}
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  color: #475569;
  font-size: 13px;
}
.preview-scroll {
  overflow: auto;
  padding: 16px;
  flex: 1;
  background: #fff;
}

.preview-sheet {
  font-size: 12px;
  line-height: 1.45;
  color: var(--dark);
}
.preview-sheet .bar {
  height: 4px;
  background: var(--teal);
  border-radius: 2px;
  margin-bottom: 8px;
}
.preview-sheet .co-zh { font-size: 12px; font-weight: 600; }
.preview-sheet .co-en { font-size: 13px; font-weight: 700; color: var(--teal); }
.preview-sheet .muted { color: var(--muted); font-size: 11px; }
.preview-sheet .title {
  margin: 12px 0 0;
  font-size: 20px;
  font-weight: 700;
  color: var(--teal);
  letter-spacing: 0.04em;
}
.preview-sheet .qno { font-size: 13px; font-weight: 700; }
.preview-sheet h3 {
  margin: 12px 0 4px;
  font-size: 12px;
  color: var(--teal);
  font-weight: 700;
}
.preview-sheet .item-line { font-weight: 600; margin-top: 6px; }
.preview-sheet .item-meta { color: var(--muted); font-size: 11px; margin-left: 1em; }
.preview-sheet .totals { text-align: right; margin-top: 12px; }
.preview-sheet .grand {
  font-size: 16px;
  font-weight: 700;
  color: var(--teal);
  margin-top: 4px;
}
.preview-sheet .footer-addr {
  margin-top: 16px;
  font-size: 10px;
  color: var(--muted);
}

.statusbar {
  background: var(--status-bg);
  color: var(--status-fg);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* PDF / print sheet */
.pdf-host {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 794px; /* ~A4 @ 96dpi */
  background: #fff;
  z-index: -1;
}
.pdf-sheet {
  width: 794px;
  padding: 40px 48px;
  font-family: var(--font);
  color: #1e293b;
  background: #fff;
  box-sizing: border-box;
}
.pdf-sheet .bar { height: 5px; background: #0F766E; border-radius: 2px; margin-bottom: 12px; }
.pdf-sheet .co-zh { font-size: 13px; font-weight: 600; }
.pdf-sheet .co-en { font-size: 16px; font-weight: 700; color: #0F766E; margin: 2px 0; }
.pdf-sheet .muted { color: #64748b; font-size: 11px; line-height: 1.4; }
.pdf-sheet .title {
  margin: 18px 0 4px;
  font-size: 26px;
  font-weight: 700;
  color: #0F766E;
  letter-spacing: 0.06em;
}
.pdf-sheet .qno { font-size: 14px; font-weight: 700; }
.pdf-sheet h3 {
  margin: 16px 0 6px;
  font-size: 13px;
  color: #0F766E;
  font-weight: 700;
}
.pdf-sheet table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 11px;
}
.pdf-sheet th, .pdf-sheet td {
  border: 1px solid #e2e8f0;
  padding: 6px 7px;
  text-align: left;
  vertical-align: top;
}
.pdf-sheet th { background: #f0fdfa; color: #0f766e; font-weight: 600; }
.pdf-sheet td.num, .pdf-sheet th.num { text-align: right; white-space: nowrap; }
.pdf-sheet .totals { text-align: right; margin-top: 14px; font-size: 12px; }
.pdf-sheet .grand {
  font-size: 18px;
  font-weight: 700;
  color: #0F766E;
  margin-top: 6px;
}
.pdf-sheet .note-block { margin-top: 10px; font-size: 12px; }
.pdf-sheet .note-block strong { color: #0F766E; display: block; margin-bottom: 2px; }
.pdf-sheet .footer-addr {
  margin-top: 24px;
  padding-top: 10px;
  border-top: 1px solid #e2e8f0;
  font-size: 10px;
  color: #64748b;
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  .layout { grid-template-columns: 1fr; overflow: visible; }
  .form-pane, .preview-pane { max-height: none; height: auto; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .span3 { grid-column: span 2; }
  .preview-pane { min-height: 360px; }
}
@media (max-width: 640px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: span 1; }
  .topbar { padding: 10px 12px; }
  .brand h1 { font-size: 18px; }
}

@media print {
  body * { visibility: hidden !important; }
  #pdfHost, #pdfHost * { visibility: visible !important; }
  #pdfHost {
    position: static !important;
    left: auto !important;
    width: auto !important;
    z-index: 1 !important;
  }
  #pdfSheet {
    width: auto !important;
    padding: 0 !important;
  }
}

/* Product image + company logo */
.logo-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  padding: 10px;
  background: #f8fafc;
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.logo-preview-wrap {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.logo-preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.logo-placeholder {
  font-size: 11px;
  color: var(--muted);
}
.logo-actions .hint {
  margin: 6px 0 0;
  font-size: 11px;
  color: var(--muted);
}
.logo-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.thumb-cell {
  width: 56px;
  vertical-align: middle !important;
}
.thumb-box {
  width: 48px;
  height: 48px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.thumb-box img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.thumb-box .thumb-add {
  font-size: 10px;
  color: var(--teal);
  text-align: center;
  line-height: 1.2;
  padding: 2px;
}
.thumb-box input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  border: none;
}
.thumb-clear {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: #b91c1c;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.preview-sheet .item-with-img,
.pdf-sheet .item-with-img {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.preview-sheet .item-thumb,
.pdf-sheet .item-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.pdf-sheet .item-thumb { width: 64px; height: 64px; }
.preview-sheet .co-logo,
.pdf-sheet .co-logo {
  max-height: 48px;
  max-width: 140px;
  object-fit: contain;
  margin-bottom: 6px;
}
.pdf-sheet .co-logo { max-height: 56px; max-width: 160px; }
.pdf-sheet td.img-cell { width: 72px; text-align: center; }
.pdf-sheet td.img-cell img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 3px;
}
table.items { min-width: 860px; }


.statusbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.admin-link { color: #64748b; font-size: 0.85rem; text-decoration: none; white-space: nowrap; }
.admin-link:hover { color: #0b5fff; text-decoration: underline; }

table.items input.qty-ro {
  background: #f1f5f9;
  color: var(--muted);
  cursor: default;
}
table.items input.num-sm {
  min-width: 64px;
  max-width: 88px;
}

.page-credit {
  color: #94a3b8;
  font-size: 11px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  user-select: none;
}
