:root {
  --blue-light: #00ade5;       /* 浅蓝分隔线 / 装饰 */
  --blue-dark: #0077e2;        /* 船期列头、费用汇总条、页脚 */
  --section-title: #00ade5;    /* 客户信息 / 运输信息 标题 */
  --module-title: #0077e2;     /* 费用模块 / 其他说明 标题文字 */
  --module-title-bg: #00ade5;  /* 费用模块 / 其他说明 标题背景 */
  --row-alt: #eeeeee;          /* 表格隔行浅灰底 */
  --text: #1a1a1a;
  --muted: #6a6a6a;
  --border: #d8d8d8;
  --bg-notes: #f9f9f9;
  --radius: 4px;
}

* { box-sizing: border-box; }
body { font-family: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif; }

.btn-primary { background-color: var(--blue-dark); color: white; }
.btn-primary:hover { background-color: #005fb8; }

.btn-secondary { background-color: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }
.btn-secondary:hover { background-color: #e5e7eb; }

.btn-danger { background-color: #ef4444; color: white; }
.btn-danger:hover { background-color: #dc2626; }

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

/* ---------- Quotation preview (strictly matches reference PDF) ---------- */

.quote-preview { background: white; width: 210mm; max-width: 210mm; margin: 0 auto; color: var(--text); font-size: 11px; padding: 14px 18px 16px; }

/* A4 sheet used by both the preview window and the exported PDF so they stay identical */
.a4-sheet { width: 210mm; min-height: 297mm; box-sizing: border-box; padding: 15mm 15mm 0 15mm; margin: 0 auto 16px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.25); display: flex; flex-direction: column; position: relative; }
.a4-sheet:last-child { margin-bottom: 0; }
.a4-sheet .flow { flex: 1; padding-bottom: 0; }
.a4-sheet .preview-footer { position: absolute; bottom: 0; left: 0; right: 0; width: 100%; margin-top: 0; padding: 10px 15mm; box-sizing: border-box; }
/* Keep major structural blocks from splitting; tables are split manually by buildSheets,
   so leave them free to break if a fragment ever overflows its assigned sheet. */
.preview-header, .preview-section-bar, .preview-info, .preview-module-title,
.total-bar, .notes-section, .preview-footer { break-inside: avoid; page-break-inside: avoid; }
.preview-table { break-inside: auto; page-break-inside: auto; }
/* Neutralize screen-only styling when rendering to PDF. Each sheet is rendered independently as one A4 page. */
.pdf-render .a4-sheet { box-shadow: none; margin: 0; height: 297mm; min-height: 297mm; display: block; position: relative; }
.pdf-render .a4-sheet .flow { flex: none; padding-bottom: 0; }
.pdf-render .preview-footer { position: absolute; bottom: 0; left: 0; right: 0; width: 100%; margin-top: 0; padding: 10px 15mm; box-sizing: border-box; }

/* White header with blue logo, black title and gray meta */
.preview-header {
  background: white;
  padding: 0 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--blue-light);
}
.preview-header-left { display: flex; flex-direction: column; align-items: flex-start; }
.preview-header-left img { height: 70px; margin-left: -2mm; }
.preview-header-left .company-name { font-size: 15px; font-weight: 700; color: var(--text); margin-top: 6px; }
.preview-header-left .company-en { font-size: 10px; color: var(--muted); }

.preview-header-right { text-align: right; }
.preview-header-right h1 { font-size: 30px; font-weight: 700; color: var(--text); margin: 0 0 8px; letter-spacing: 1px; text-align: right; }
.preview-header-right .meta-table { border-collapse: collapse; margin: 0 0 0 auto; width: auto; font-size: 9px; }
.preview-header-right .meta-table td { padding: 1px 0; vertical-align: baseline; }
.preview-header-right .meta-table .label { color: #9e9e9e; text-align: right; padding-right: 0; white-space: nowrap; }
.preview-header-right .meta-table .value { color: var(--text); text-align: right; min-width: 4em; }

/* Two-column section header (客户信息 / 运输信息) — 装饰线中间断开、间隔 10mm、颜色 #e2e2e2 */
.preview-section-bar {
  display: flex;
  gap: 10mm;
  margin-top: 14px;
}
.preview-section-bar > div { flex: 1; color: var(--section-title); font-size: 12px; font-weight: 700; text-align: left; border-bottom: 1px solid #e2e2e2; padding-bottom: 4px; }

/* Two-column info layout — 列与上方标题左对齐 */
.preview-info { display: flex; gap: 10mm; padding: 10px 0 2px; font-size: 11px; }
.preview-info > div { flex: 1; }
.preview-info .row { margin-bottom: 5px; }
.preview-info .label { color: var(--text); font-weight: 600; }
.preview-info .value { font-weight: 400; }

/* Module title: gray color block with #0077e2 text and #00ade5 top accent line */
.preview-module-title {
  background-color: #f0f0f0;
  color: #0077e2;
  font-size: 11px;
  font-weight: 900;
  margin-top: 14px;
  margin-left: 0;
  margin-right: 0;
  padding: 6px 10px 2px;
  display: block;
  width: 100%;
  text-align: left;
  border-top: 1px solid #00ade5;
  break-after: avoid;
  page-break-after: avoid;
}

/* Actual-reimbursement module: gray title text, dark gray accent line and table header */
.preview-module-title.actual-fee-module {
  color: #333333;
  border-top: 1px solid #333333;
}
.total-bar + .actual-fee-module {
  margin-top: 28px;
}
.preview-table.fee-header.actual-fee-table thead tr {
  background-color: #333333;
}

/* Tables — color blocks, no borders */
.preview-table { width: 100%; border-collapse: collapse; border: none; font-size: 10px; margin-bottom: 10px; }
.preview-table thead tr { color: #fff; }
.preview-table th {
  padding: 7px 10px;
  text-align: center;
  vertical-align: middle;
  font-weight: 600;
  border: none;
}
.preview-table td {
  padding: 6px 10px;
  border: none;
  text-align: center;
  vertical-align: middle;
  color: var(--text);
}
/* Fee module tables: distribute columns by content area, center header and cell content */
.preview-table.fee-header th:first-child,
.preview-table.fee-header td:first-child { width: 50px; min-width: 50px; white-space: nowrap; }
.preview-table.fee-header th:nth-child(2),
.preview-table.fee-header td:nth-child(2) { width: 158px; min-width: 158px; }
.preview-table.fee-header th:nth-child(3),
.preview-table.fee-header td:nth-child(3) { width: 70px; min-width: 70px; }
.preview-table.fee-header th:nth-child(4),
.preview-table.fee-header td:nth-child(4) { width: 70px; min-width: 70px; }
.preview-table.fee-header th:nth-child(5),
.preview-table.fee-header td:nth-child(5) { width: 100px; min-width: 100px; }
.preview-table.fee-header th:nth-child(6),
.preview-table.fee-header td:nth-child(6) { width: auto; min-width: 60px; text-align: center; }

/* English preview: keep table cells on a single line to avoid wrapping */
.preview-root.en .preview-table.fee-header th,
.preview-root.en .preview-table.fee-header td,
.preview-root.en .preview-table.ship-header th,
.preview-root.en .preview-table.ship-header td { white-space: nowrap; }

/* Remarks column should still wrap in English preview */
.preview-root.en .preview-table.fee-header td:nth-child(6) { white-space: normal; }

.preview-table tbody tr:nth-child(even) { background-color: #e0e0e0; }
.preview-table tbody tr:nth-child(odd) { background-color: #f0f0f0; }

/* Ship schedule header = dark blue #0077e2; fee module column header = light blue #00ade5. */
.preview-table.ship-header thead tr { background-color: #0077e2; }
.preview-table.fee-header thead tr { background-color: #00ade5; }

/* Total summary dark-blue bar */
.total-bar {
  background-color: #0077e2;
  color: #fff;
  padding: 9px 16px;
  display: flex;
  justify-content: flex-end;
  gap: 28px;
  font-weight: 700;
  font-size: 12px;
  margin-top: 4px;
}
.total-bar .amount { color: #ffff3a; margin-left: 4px; font-size: 14px; }

/* Notes — dark gray text and dark gray top decoration line */
.notes-title {
  background-color: #ffffff;
  color: #333333;
  font-size: 11px;
  font-weight: 900;
  margin-top: 14px;
  margin-left: 0;
  margin-right: 0;
  padding: 6px 0;
  display: block;
  width: 100%;
  text-align: left;
  border-top: 1px solid #333333;
}
.notes-box { background: #f9f9f9; border: 1px solid #e0e0e0; padding: 10px 14px; font-size: 11px; line-height: 1.7; }

/* Footer dark-blue bar (last page only) */
.preview-footer {
  background-color: #0077e2;
  color: #fff;
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: auto;
}
.preview-footer img { height: 28px; }
.preview-footer .footer-meta { text-align: right; font-size: 11px; line-height: 1.5; color: #8acdff; }

.hidden { display: none; }

/* Full-screen preview overlay (DingTalk-friendly, no popup window) */
#preview-overlay { -webkit-overflow-scrolling: touch; }
#preview-overlay-content { padding: 0; }
#preview-overlay-content .sheets-preview { padding: 0; }
#preview-overlay-content .a4-sheet {
  margin: 0 auto 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
#preview-overlay-content .a4-sheet:last-child { margin-bottom: 0; }
@media print {
  .no-print, #preview-overlay > div > .sticky { display: none !important; }
  #preview-overlay { position: static; background: #fff; overflow: visible; }
  #preview-overlay-content { padding: 0; }
  #preview-overlay-content .a4-sheet {
    margin: 0;
    box-shadow: none;
    page-break-after: always;
  }
  #preview-overlay-content .a4-sheet:last-child { page-break-after: auto; }
}

/* print-specific */
@media print {
  .no-print { display: none !important; }
  .quote-preview { padding: 0; margin: 0; max-width: 100%; }
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* Routes table: inputs should fit cell width */
.routes-table th,
.routes-table td { min-width: 80px; }
.routes-table input[type="text"],
.routes-table input[type="date"],
.routes-table input[type="number"],
.routes-table select { width: 100%; min-width: 0; box-sizing: border-box; }
.routes-table input[type="date"] { min-width: 130px; }
.routes-table td .flex.items-center input { flex: 1 1 auto; min-width: 0; }

/* Fee module tables: every input/select fills its cell */
.fee-module-table th,
.fee-module-table td { min-width: 60px; }
.fee-module-table input[type="text"],
.fee-module-table input[type="number"],
.fee-module-table select,
.fee-module-table textarea {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
.fee-module-table th.col-price,
.fee-module-table th.col-cost,
.fee-module-table td.col-price,
.fee-module-table td.col-cost { width: 110px; }
.fee-module-table th.col-action,
.fee-module-table td.col-action { width: 50px; text-align: center; }
.fee-module-table th.col-name,
.fee-module-table td.col-name { width: 180px; min-width: 180px; }
.fee-module-table th.col-unit,
.fee-module-table td.col-unit { width: 90px; min-width: 90px; }
.fee-module-table th.col-qty,
.fee-module-table td.col-qty { width: 70px; text-align: center; }
.fee-module-table th.col-remark,
.fee-module-table td.col-remark { text-align: left; }
.fee-module-table textarea.remark-textarea {
  display: block;
  text-align: left;
  vertical-align: top;
  resize: none;
  overflow: hidden;
  min-height: 30px;
  height: auto;
  line-height: 1.4;
  field-sizing: content; /* modern browsers auto-size by content */
}

/* Unit combobox */
.unit-combobox { position: relative; display: flex; align-items: center; width: 100%; }
.unit-input { width: 100%; padding-right: 22px; min-width: 0; }
.unit-dropdown-toggle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 22px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 11px;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  outline: none;
}
.unit-dropdown-toggle:hover { color: #334155; }
.unit-dropdown-list {
  position: fixed;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 9999;
  font-size: 13px;
  min-width: 100px;
}
.unit-dropdown-list ul { list-style: none; margin: 0; padding: 0; }
.unit-dropdown-list li { padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.unit-dropdown-list li:hover { background: #eff6ff; }
.unit-dropdown-empty { padding: 8px 12px; color: #94a3b8; }

/* Fee module editing UI cards */
.module-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.module-header { background: #f8fafc; border-bottom: 1px solid var(--border); padding: 12px 14px; }
.module-header-top { display: flex; align-items: center; justify-content: space-between; }
.module-title-input {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 1px solid #cbd5e1;
  color: #1e293b;
  font-size: 15px;
  font-weight: 700;
  flex: 1;
  padding: 2px 6px;
  min-width: 0;
}
.module-title-input:hover, .module-title-input:focus { border-bottom-color: #3b82f6; background: #fff; outline: none; }
.module-delete { background: #ef4444; color: #fff; border: none; border-radius: 4px; width: 28px; height: 28px; font-size: 18px; line-height: 1; cursor: pointer; margin-left: 10px; }
.module-delete:hover { background: #dc2626; }
.module-body { padding: 12px 14px 16px; background: #fff; }

/* ===================================================================
   Mobile adaptation (phones, < 768px)
   Desktop layout is untouched; the sidebar becomes an off-canvas drawer,
   wide tables scroll horizontally, and tap targets grow a little.
   =================================================================== */

/* Hide scrollbars on swipeable bars (mobile only nicety) */
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

@media (max-width: 767px) {
  /* Modal action bar: never shrink buttons, let them scroll sideways */
  #modal-actions { -webkit-overflow-scrolling: touch; }
  #modal-actions > button { flex: 0 0 auto; white-space: nowrap; }

  /* Fee-module editing tables scroll instead of overflowing the card */
  .module-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* A4 quotation preview is 210mm wide — allow horizontal scroll on phones */
  #preview-section { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  #preview-section .quote-preview { width: 210mm; max-width: none; }

  /* List / users tables keep readable column widths and scroll in their card */
  #page-list table, #page-users table { min-width: 680px; }

  /* Bigger, finger-friendly tap targets on touch screens */
  main button, .page button, #modal-actions button { min-height: 38px; }

  /* Shrink oversized page titles so they don't dominate a phone screen */
  #page-list h2, #page-settings h2, #page-users h2, #page-password h2 { font-size: 1.25rem; }

  /* Stack the settings fee-grid already uses grid-cols-1 on mobile; give the
     bottom save bar comfortable spacing */
  #page-settings .flex.justify-end { padding: 12px 0; }
}

/* Very small phones: a touch more breathing room for form inputs */
@media (max-width: 380px) {
  .module-card .module-header-top { flex-wrap: wrap; gap: 8px; }
  #modal-actions > button { padding-left: 10px; padding-right: 10px; }
}

