/* ============================================================
   品保外掛系統 — 樣式 (styles.css)
   ============================================================ */
:root {
  --brand: #1f4e79;
  --brand-light: #2e75b6;
  --brand-bg: #eaf1f8;
  --ink: #1a2733;
  --muted: #6b7a89;
  --line: #d5dde5;
  --line-strong: #b9c4cf;
  --bg: #f4f6f9;
  --card: #ffffff;
  --ok: #1e8e3e;
  --ng: #c62828;
  --warn: #b9770e;
  --urgent: #d84315;
  --shadow: 0 1px 3px rgba(20, 40, 60, 0.08), 0 4px 16px rgba(20, 40, 60, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "微軟正黑體", "Microsoft JhengHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 頂部 ---------- */
.app-header {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-light) 100%);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow);
}
.app-header .logo {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.app-header .logo .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #7fd1ae; box-shadow: 0 0 0 4px rgba(127,209,174,.25);
}
.app-header .sub { font-size: 12px; opacity: .85; font-weight: 400; }
.app-header .spacer { flex: 1; }
.app-header .env-tag {
  font-size: 11px; background: rgba(255,255,255,.18);
  padding: 3px 10px; border-radius: 20px; letter-spacing: .5px;
}

/* ---------- 導覽列 ---------- */
.nav {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex;
  padding: 0 16px;
  gap: 2px;
  position: sticky; top: 0; z-index: 20;
}
.nav a {
  padding: 13px 22px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
  border-bottom: 3px solid transparent;
  transition: all .15s;
}
.nav a:hover { color: var(--brand); background: var(--brand-bg); }
.nav a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- 版面 ---------- */
.page { padding: 22px 24px 60px; max-width: 1500px; margin: 0 auto; }
.page-title {
  display: flex; align-items: center; gap: 12px;
  margin: 0 0 4px;
}
.page-title h1 { font-size: 20px; margin: 0; color: var(--brand); }
.page-desc { color: var(--muted); font-size: 12.5px; margin: 0 0 18px; }

.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar .spacer { flex: 1; }
.scan-note {
  font-size: 12px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
}
.scan-note .pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(30,142,62,.4); }
  70% { box-shadow: 0 0 0 7px rgba(30,142,62,0); }
  100% { box-shadow: 0 0 0 0 rgba(30,142,62,0); }
}

/* ---------- 分類頁籤（含徽章） ---------- */
.cat-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.cat-tab {
  position: relative;
  padding: 9px 20px; border-radius: 8px; cursor: pointer;
  background: var(--card); border: 1px solid var(--line);
  font-weight: 600; color: var(--muted); font-size: 14px;
  display: inline-flex; align-items: center; gap: 8px;
  transition: all .15s;
}
.cat-tab:hover { border-color: var(--brand-light); }
.cat-tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.cat-tab.urgent.active { background: var(--urgent); border-color: var(--urgent); }
.cat-tab.super.active { background: var(--ng); border-color: var(--ng); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--ng); color: #fff;
  font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 2px #fff;
}
.cat-tab.active .badge { box-shadow: 0 0 0 2px rgba(255,255,255,.5); }
.badge.zero { display: none; }

/* ---------- 按鈕 ---------- */
.btn {
  border: 1px solid var(--line-strong); background: var(--card);
  color: var(--ink); padding: 8px 16px; border-radius: 7px;
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  transition: all .15s; font-family: inherit;
}
.btn:hover { border-color: var(--brand-light); color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-light); color: #fff; }
.btn.ghost { background: transparent; }
.btn svg { width: 15px; height: 15px; }

/* ---------- 卡片 / 表格 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.grid th {
  background: var(--brand); color: #fff; font-weight: 600;
  padding: 10px 12px; text-align: left; position: sticky; top: 0;
  border-right: 1px solid rgba(255,255,255,.15);
}
table.grid th:last-child { border-right: none; }
table.grid td {
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  border-right: 1px solid #eef2f6;
}
table.grid td:last-child { border-right: none; }
table.grid tbody tr:hover { background: var(--brand-bg); }
table.grid tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }

/* 判定標籤 */
.verdict { font-weight: 700; padding: 2px 10px; border-radius: 12px; font-size: 12px; }
.verdict.ok { background: #e6f4ea; color: var(--ok); }
.verdict.ng { background: #fdecea; color: var(--ng); }
.verdict.wait { background: #fff4e0; color: var(--warn); }

/* 版次異動高亮（P-10） */
tr.rev-changed td { background: #fff8e6; }
tr.rev-changed:hover td { background: #fff2cc; }
.rev-arrow { color: var(--urgent); font-weight: 700; }
.chip-old { color: var(--muted); text-decoration: line-through; }
.chip-new { color: var(--urgent); font-weight: 700; }

/* 連結型儲存格 */
.link-cell { color: var(--brand-light); cursor: pointer; font-weight: 600; }
.link-cell:hover { text-decoration: underline; }

/* 列印張數輸入（P-09） */
.print-cell { display: inline-flex; align-items: center; gap: 5px; }
.print-cell input {
  width: 46px; padding: 3px 6px; border: 1px solid var(--line-strong);
  border-radius: 5px; text-align: center; font-family: inherit; font-size: 12.5px;
}
.icon-btn {
  border: 1px solid var(--line-strong); background: var(--card);
  width: 28px; height: 26px; border-radius: 5px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { border-color: var(--brand-light); color: var(--brand); }

/* 保留欄位標註（P-12） */
th.reserved { background: #5a6b7a; font-style: italic; font-weight: 500; }
td.reserved { background: #fafbfc; color: #c2ccd6; text-align: center; }

/* ---------- 篩選列 ---------- */
.filter-bar {
  display: flex; align-items: flex-end; gap: 18px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 18px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field select, .field input {
  padding: 7px 10px; border: 1px solid var(--line-strong);
  border-radius: 7px; font-family: inherit; font-size: 13.5px; min-width: 140px;
  background: #fff;
}
.field .range { display: flex; align-items: center; gap: 8px; }
.field .range span { color: var(--muted); }
.shared-note {
  font-size: 11.5px; color: var(--brand-light); background: var(--brand-bg);
  padding: 3px 10px; border-radius: 6px; align-self: center;
}

/* ---------- 檢驗分析：可捲動圖表區（P-15） ---------- */
.charts-scroll {
  max-height: 620px; overflow-y: auto; padding-right: 6px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(440px, 1fr)); gap: 16px;
}
.chart-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px 10px; box-shadow: var(--shadow);
}
.chart-card h3 {
  margin: 0 0 2px; font-size: 14.5px; color: var(--brand);
  display: flex; align-items: center; justify-content: space-between;
}
.chart-card .spec { font-size: 11.5px; color: var(--muted); margin-bottom: 8px; }
.chart-legend { display: flex; gap: 14px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg-line { width: 16px; height: 2px; background: var(--brand-light); }
.lg-tol { width: 16px; height: 0; border-top: 2px dashed var(--ng); }
.lg-pt-ng { width: 9px; height: 9px; border-radius: 50%; background: var(--ng); }

/* ---------- Modal（檢驗表單 P-06） ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20,35,50,.5);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 100; overflow-y: auto;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--card); border-radius: 12px; width: 100%; max-width: 860px;
  box-shadow: 0 12px 48px rgba(0,0,0,.3); overflow: hidden;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  background: var(--brand); color: #fff; padding: 15px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-head .meta { font-size: 12px; opacity: .9; margin-top: 3px; }
.modal-close { background: rgba(255,255,255,.15); border: none; color: #fff;
  width: 30px; height: 30px; border-radius: 6px; cursor: pointer; font-size: 18px; }
.modal-close:hover { background: rgba(255,255,255,.3); }
.modal-body { padding: 18px 20px; max-height: 62vh; overflow-y: auto; }
.sample-info {
  display: flex; gap: 22px; flex-wrap: wrap; background: var(--brand-bg);
  border: 1px solid #d3e2f2; border-radius: 8px; padding: 10px 16px; margin-bottom: 16px;
  font-size: 13px;
}
.sample-info b { color: var(--brand); }
.modal-foot {
  padding: 14px 20px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px; justify-content: flex-end;
  background: #fafbfc;
}
.modal-foot .verdict-live { margin-right: auto; font-size: 14px; font-weight: 700; }

/* 檢驗表單量測輸入 */
table.inspect { width: 100%; border-collapse: collapse; font-size: 13px; }
table.inspect th, table.inspect td { padding: 8px 10px; border: 1px solid var(--line); text-align: center; }
table.inspect th { background: #eef3f8; color: var(--brand); font-weight: 600; }
table.inspect td.name { text-align: left; font-weight: 600; }
table.inspect input.meas {
  width: 78px; padding: 5px 6px; border: 1px solid var(--line-strong);
  border-radius: 5px; text-align: center; font-family: inherit; font-size: 13px;
}
/* 超公差自動標紅（P-08） */
table.inspect input.meas.out { color: var(--ng); font-weight: 700; border-color: var(--ng); background: #fff5f5; }
.tol-range { color: var(--muted); font-size: 12px; }
.item-verdict.ok { color: var(--ok); font-weight: 700; }
.item-verdict.ng { color: var(--ng); font-weight: 700; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 22px; border-radius: 24px;
  font-size: 13.5px; box-shadow: 0 6px 24px rgba(0,0,0,.25); z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* 空狀態 */
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty svg { width: 44px; height: 44px; opacity: .4; margin-bottom: 10px; }

.footer-note {
  text-align: center; color: var(--muted); font-size: 11.5px;
  padding: 24px; border-top: 1px solid var(--line); margin-top: 20px;
}
