/* 威銓・全進營造 鋼筋檢料系統 */

:root {
  --brand: #00a7e1;
  --navy: #0a1045;
  --navy-soft: #1b2560;
  --ink: #16213a;
  --muted: #6b7794;
  --line: #d8dfea;
  --line-soft: #eef2f7;
  --bg: #f5f7fb;
  --paper: #fff;
  --warn: #d6432a;
  --ok: #15855b;
  --radius: 8px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

p, li, h1, h2, h3, h4, h5 { text-wrap: pretty; }

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

/* ── 版頭 ─────────────────────────────────────────── */

.topbar {
  background: var(--navy);
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
}

.topbar h1 span { color: var(--brand); }

.topbar .ver { font-size: 12px; color: #8e9bc4; }

.topbar .spacer { flex: 1; }

.topbar button {
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .22);
  color: #fff;
  border-radius: var(--radius);
  padding: 6px 13px;
  cursor: pointer;
}

.topbar button:hover { background: rgba(255, 255, 255, .2); }

.topbar button.primary { background: var(--brand); border-color: var(--brand); font-weight: 700; }

.topbar button.primary:hover { background: #12b9f2; }

/* ── 版面 ─────────────────────────────────────────── */

.wrap { max-width: 1560px; margin: 0 auto; padding: 18px 20px 64px; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.card > h2 {
  margin: 0;
  padding: 11px 16px;
  font-size: 14px;
  letter-spacing: .06em;
  color: var(--navy);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 12px;
}

.card > h2 .hint { font-weight: 400; font-size: 12px; color: var(--muted); letter-spacing: 0; }

.card > h2 .spacer { flex: 1; }

.card-body { padding: 14px 16px; }

/* ── 表單 ─────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px 18px;
}

label.f { display: block; }

label.f > span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 3px;
}

input[type=text], input[type=number], input[type=date], select, textarea {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(0, 167, 225, .35);
  border-color: var(--brand);
}

.opts { display: flex; gap: 20px; flex-wrap: wrap; align-items: center; }

.opts label { display: flex; align-items: center; gap: 6px; font-size: 14px; }

.opts .sep { width: 1px; height: 22px; background: var(--line); }

/* ── 明細表 ───────────────────────────────────────── */

.table-scroll { overflow-x: auto; }

table.detail {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 1180px;
}

table.detail th {
  background: #f0f4fa;
  color: var(--navy);
  font-weight: 700;
  font-size: 12px;
  border: 1px solid var(--line);
  padding: 6px 4px;
  text-align: center;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}

table.detail td {
  border: 1px solid var(--line);
  padding: 3px 4px;
  text-align: center;
  vertical-align: middle;
}

table.detail td.num { text-align: right; font-variant-numeric: tabular-nums; padding-right: 7px; }

table.detail td input, table.detail td select {
  border: 1px solid transparent;
  background: transparent;
  padding: 4px 5px;
  border-radius: 4px;
  text-align: center;
}

table.detail td input:hover, table.detail td select:hover { border-color: var(--line); }

table.detail td input:focus, table.detail td select:focus { background: #fff; }

table.detail td input.dim { color: #b9c2d4; }

table.detail td.calc { background: #fafcff; color: var(--navy-soft); font-variant-numeric: tabular-nums; }

table.detail tr.err td { background: #fff5f3; }

table.detail td.seq { color: var(--muted); width: 34px; }

.w-part { width: 108px; }
.w-dia { width: 96px; }
.w-sp { width: 60px; }
.w-p { width: 62px; }
.w-qty { width: 66px; }
.w-hook { width: 96px; }
.w-grade { width: 92px; }
.w-remark { width: 110px; }

.shape-cell { width: 132px; padding: 2px !important; }

.shape-btn {
  width: 100%;
  border: 1px dashed var(--line);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
  display: block;
}

.shape-btn:hover { border-color: var(--brand); background: #f2fbff; }

.shape-btn .code { font-size: 10px; color: var(--muted); display: block; }

.shape-svg { width: 100%; height: 62px; display: block; }

.shape-line { stroke: var(--navy); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; fill: none; }

.shape-label { font-size: 11px; fill: var(--brand); font-weight: 700; }

.shape-note { font-size: 9px; fill: var(--muted); }

.shape-none { font-size: 12px; fill: var(--muted); }

.rowbtn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 5px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

.rowbtn:hover { border-color: var(--brand); color: var(--brand); }

.rowbtn.del:hover { border-color: var(--warn); color: var(--warn); }

.rowerr { font-size: 11px; color: var(--warn); }

.addrow {
  margin-top: 10px;
  border: 1px dashed var(--line);
  background: #fff;
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  color: var(--navy);
  font-weight: 700;
}

.addrow:hover { border-color: var(--brand); color: var(--brand); background: #f2fbff; }

/* ── 小計 ─────────────────────────────────────────── */

.sum-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.sum-cell {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 11px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  background: #fafcff;
}

.sum-cell.zero { opacity: .38; }

.sum-cell b { color: var(--navy); font-size: 13px; }

.sum-cell .v { font-variant-numeric: tabular-nums; font-weight: 700; }

.totals {
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 13px;
  border-top: 2px solid var(--navy);
}

.totals div span { display: block; font-size: 12px; color: var(--muted); }

.totals div b { font-size: 22px; color: var(--navy); font-variant-numeric: tabular-nums; }

.totals div b em { font-size: 13px; font-style: normal; color: var(--muted); font-weight: 400; }

.totals .hl b { color: var(--brand); }

/* ── 料形選擇 ─────────────────────────────────────── */

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 69, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal {
  background: #fff;
  border-radius: 12px;
  max-width: 1000px;
  width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
}

.modal header h3 { margin: 0; font-size: 16px; color: var(--navy); }

.modal header .spacer { flex: 1; }

.modal .body { overflow: auto; padding: 16px 18px; }

.shape-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 11px;
}

.shape-pick {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  padding: 7px 6px 9px;
  text-align: center;
}

.shape-pick:hover { border-color: var(--brand); box-shadow: 0 2px 10px rgba(0, 167, 225, .18); }

.shape-pick.on { border-color: var(--brand); border-width: 2px; background: #f2fbff; }

.shape-pick .nm { font-size: 12.5px; font-weight: 700; color: var(--navy); display: block; margin-top: 3px; }

.shape-pick .fm { font-size: 11px; color: var(--brand); font-family: ui-monospace, Consolas, monospace; }

.shape-pick .cd { font-size: 10px; color: var(--muted); }

.bendrow { margin: 4px 0 9px; font-size: 12px; color: var(--muted); letter-spacing: .08em; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 6px 13px;
  cursor: pointer;
}

.btn:hover { border-color: var(--brand); color: var(--brand); }

.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }

.btn.primary:hover { background: #12b9f2; color: #fff; }

.note {
  font-size: 12.5px;
  color: var(--muted);
  background: #f8fafd;
  border-left: 3px solid var(--brand);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
}

/* ── 套裁計畫表 ──────────────────────────────────── */

/* ── 雲端訂料單清單 ─────────────────────────────── */

/* .opts 是 display:flex，特異性比 UA 的 [hidden]{display:none} 高，
   不加這條的話 hidden 屬性對它完全無效（登入列會一直掛在那）。 */
[hidden] { display: none !important; }

.cloud-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.cloud-table th {
  background: #f4f7fb;
  border: 1px solid #dde5ef;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--navy);
  font-weight: 700;
  white-space: nowrap;
}

.cloud-table td {
  border: 1px solid #e6ecf4;
  padding: 5px 8px;
  vertical-align: middle;
}

.cloud-table td.nm { font-weight: 700; color: var(--navy); white-space: nowrap; }
.cloud-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cloud-table td.ops { white-space: nowrap; text-align: center; }
.cloud-table tbody tr:hover td { background: #f8fbff; }

/* 目前正在編輯的那一張，左邊打一條亮藍 */
.cloud-table tr.cur td { background: #eef8ff; }
.cloud-table tr.cur td:first-child { box-shadow: inset 3px 0 0 var(--brand); }

.cloud-msg {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  background: #eef8ff;
  color: #0b5f86;
  border: 1px solid #cfe7f5;
}

.cloud-msg.ok { background: #eaf7ee; color: #1b6b34; border-color: #cfe9d8; }
.cloud-msg.err { background: #fdecea; color: #a3271c; border-color: #f5cdc7; }
.cloud-msg a { color: inherit; font-weight: 700; }

.btn.danger { color: #a3271c; }
.btn.danger:hover { background: #fdecea; border-color: #f5cdc7; }

.cut-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 12px;
}

.cut-table th {
  background: #f4f7fb;
  border: 1px solid #dde5ef;
  padding: 6px 8px;
  font-size: 12px;
  color: var(--navy);
  font-weight: 700;
  white-space: nowrap;
}

.cut-table td {
  border: 1px solid #e6ecf4;
  padding: 6px 9px;
  vertical-align: middle;
}

.cut-table td.nm { font-weight: 700; color: var(--navy); text-align: center; white-space: nowrap; }

.cut-table td.num { text-align: center; font-variant-numeric: tabular-nums; white-space: nowrap; }

.cut-table td.pat { font-variant-numeric: tabular-nums; }

.cut-table td.pat b { color: var(--navy); }

.cut-table .waste { color: var(--muted); font-size: 12px; }

.cut-table .nowaste { color: #0f9d58; font-size: 12px; font-weight: 600; }

.cut-table tr.tip td {
  background: #eef8ff;
  font-size: 12px;
  color: #0b5f86;
  line-height: 1.7;
}

.cut-table tr.tip:hover td { background: #eef8ff; }

.cut-table tr.over td {
  background: #fff8e6;
  font-size: 12px;
  color: #8a6100;
  line-height: 1.7;
}

.cut-table tbody tr:hover td { background: #fafcff; }

.cut-table tr.over:hover td { background: #fff8e6; }

/* ── 列印（A4 橫向，比照現行訂料單版面） ────────────── */

.print-only { display: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm 8mm; }

  body { background: #fff; font-size: 10pt; }

  .topbar, .card > h2, .no-print, .addrow { display: none !important; }

  .wrap { max-width: none; padding: 0; }

  .card { border: 0; margin: 0; }

  .card-body { padding: 0; }

  .print-only { display: block; }

  .print-title { text-align: center; font-size: 16pt; font-weight: 700; margin-bottom: 2mm; font-family: "標楷體", "DFKai-SB", serif; }

  .print-head { display: flex; justify-content: space-between; font-size: 9pt; margin-bottom: 2mm; }

  /* 螢幕版靠 min-width + 橫向捲軸，紙上沒有捲軸可捲，右邊會整片被裁掉 */
  .table-scroll { overflow: visible !important; }

  #errBox { display: none; }

  table.print-table {
    width: 100%;
    min-width: 0 !important;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 8.5pt;
  }

  table.print-table td, table.print-table th { overflow: hidden; word-break: break-all; }

  /* 讓固定表格把寬度讓給形狀與數字欄 */
  .w-part { width: 7%; }
  .w-dia { width: 6.5%; }
  .w-sp { width: 4.5%; }
  .shape-cell { width: 11%; }
  .w-p { width: 4.6%; }
  .w-hook { width: 7%; }
  .w-qty { width: 4.6%; }
  .w-grade { width: 6.5%; }
  .w-remark { width: 7.5%; }

  /* 彙總改成紙感：3 欄九宮格，照現行訂料單的排法 */
  .sum-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin-top: 4mm; }

  .sum-cell {
    border: 1px solid #000;
    border-radius: 0;
    background: #fff;
    opacity: 1 !important;
    padding: 0.6mm 3mm;
    font-size: 9pt;
  }

  .sum-grid { margin-top: 2mm; }

  .totals { border-top: 1.5px solid #000; margin-top: 2mm; padding-top: 1.5mm; gap: 12mm; }

  .totals div b { font-size: 13pt; }

  .totals div b em { font-size: 9pt; }

  table.print-table th, table.print-table td { border: 1px solid #000; padding: 0.6mm 1mm; text-align: center; }

  table.print-table th { background: #eee; }

  /* 輸入框在紙上要看起來像純文字 */
  table.print-table input, table.print-table select {
    border: 0 !important;
    background: transparent !important;
    padding: 0 !important;
    appearance: none;
    -webkit-appearance: none;
    text-align: center;
    width: 100%;
  }

  table.print-table input.dim { color: #000; }

  table.print-table td.num { text-align: right; padding-right: 2mm; }

  table.print-table .shape-svg { height: 40px; }

  table.print-table .shape-btn { border: 0; padding: 0; }

  table.print-table .shape-btn .code { font-size: 7pt; }

  .shape-line { stroke: #000; stroke-width: 2; }

  .shape-label { fill: #000; }

  /* 收件三行 + 簽核欄是一組，不准被切到兩頁（實測會從「工區」那行斷開） */
  .print-foot { margin-top: 3mm; font-size: 10pt; line-height: 1.7; break-inside: avoid; page-break-inside: avoid; }

  .foot-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 10mm; break-inside: avoid; }

  .foot-left { white-space: nowrap; }

  table.sign-table { border-collapse: collapse; font-size: 9pt; }

  table.sign-table th, table.sign-table td { border: 1px solid #000; text-align: center; }

  table.sign-table th { background: #eee; padding: 1mm 6mm; font-weight: 400; }

  table.sign-table td { height: 12mm; min-width: 24mm; }

  tr, table { page-break-inside: avoid; }
}
