/* ============================================================================
 * 壓鑄機電控測試 SOP 系統樣式表 (工業現場高對比 RWD + A4 專業列印)
 * ============================================================================ */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --text-light: #64748b;

  --navy: #0f172a;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;

  --pass: #15803d;
  --pass-bg: #dcfce7;
  --pass-border: #86efac;

  --fail: #dc2626;
  --fail-bg: #fee2e2;
  --fail-border: #fca5a5;

  --warn: #b45309;
  --warn-bg: #fef3c7;
  --warn-border: #fcd34d;

  --na: #475569;
  --na-bg: #e2e8f0;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.16);
  --font-sans: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font-sans); font-size: 15px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.print-only { display: none; }
.mono { font-family: var(--font-mono); }
.mb-12 { margin-bottom: 12px; }
.req { color: var(--fail); font-weight: 700; }

/* ---------------- Topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  min-height: 58px; padding: env(safe-area-inset-top, 0px) 16px 0;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 8px;
  background: #2563eb; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 11px; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.autosave-pill, .pwa-status-pill {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: rgba(34, 197, 94, 0.18); color: #86efac; border: 1px solid rgba(134, 239, 172, 0.35);
  white-space: nowrap;
}
.pwa-status-pill.is-offline {
  background: rgba(245, 158, 11, 0.22); color: #fde68a; border-color: rgba(252, 211, 77, 0.45);
}
.pwa-install-btn {
  background: rgba(255, 255, 255, 0.12); color: #fff; border-color: rgba(255, 255, 255, 0.32);
}
.pwa-install-btn:hover { background: rgba(255, 255, 255, 0.22); border-color: rgba(255, 255, 255, 0.55); }
.pwa-ios-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 14px; border-radius: var(--radius);
  background: #eff6ff; border: 1px solid #93c5fd; color: #1e3a8a; font-size: 13.5px;
}
.pwa-update-bar {
  position: sticky; top: 58px; z-index: 48;
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 9px 16px; background: #fef3c7; border-bottom: 2px solid #f59e0b;
  color: #78350f; font-size: 13.5px; font-weight: 700;
}
.app-footer-bar {
  margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--text-light);
}

/* ---------------- Buttons & Inputs ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-lg { min-height: 46px; padding: 10px 22px; font-size: 15px; }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-amber { background: #d97706; color: #fff; }
.btn-amber:hover { background: #b45309; }
.btn-danger { background: var(--fail); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-alt); border-color: #94a3b8; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--border-light); color: var(--text); }
.btn-icon {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08); color: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; font-size: 16px;
}
.modal-header .btn-icon, .sidebar-header .btn-icon {
  border-color: var(--border); background: var(--surface-alt); color: var(--text);
}

.input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); font-family: inherit; font-size: 14px;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15); }
.textarea { min-height: 76px; resize: vertical; }
.input-icon-wrap { position: relative; display: flex; align-items: center; }
.input-icon-wrap svg { position: absolute; left: 11px; color: var(--text-light); pointer-events: none; }
.input-icon-wrap .input { padding-left: 34px; }

.card {
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}

/* ---------------- Home View ---------------- */
.app-main { max-width: 1280px; margin: 0 auto; padding: 18px 16px 32px; }
.home-hero {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.home-title { margin: 0 0 4px; font-size: 22px; font-weight: 800; color: var(--navy); }
.home-desc { margin: 0; font-size: 13.5px; color: var(--text-muted); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.kpi-val { font-size: 26px; font-weight: 800; margin-top: 2px; font-family: var(--font-mono); }
.kpi-pass .kpi-val { color: var(--pass); }
.kpi-warn .kpi-val { color: var(--warn); }
.kpi-fail .kpi-val { color: var(--fail); }

.toolbar-card { margin-bottom: 16px; padding: 14px 16px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.flex-grow { flex: 1 1 240px; }
.select-sm { width: auto; min-width: 148px; }
.date-sm { width: auto; min-width: 135px; }
.date-sep { color: var(--text-light); }
.export-row {
  display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; justify-content: space-between;
  padding-top: 10px; border-top: 1px dashed var(--border-light);
}
.export-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.export-label { font-size: 12.5px; font-weight: 700; color: var(--text-muted); }

/* Records Table / Cards */
.records-table-wrap { overflow-x: auto; }
.records-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.records-table th {
  text-align: left; padding: 10px 12px; background: var(--surface-alt);
  border-bottom: 2px solid var(--border-light); color: var(--text-muted); font-size: 12.5px; white-space: nowrap;
}
.records-table td { padding: 12px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.records-table tr:hover td { background: #f8fafc; }
.rec-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.rec-cards-mobile { display: none; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge-pass { background: var(--pass-bg); color: var(--pass); }
.badge-fail { background: var(--fail-bg); color: var(--fail); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-na { background: var(--na-bg); color: var(--na); }
.badge-info { background: var(--primary-soft); color: var(--primary); }
.badge-opt { background: #ede9fe; color: #6d28d9; border: 1px solid #ddd6fe; }

.empty-state {
  text-align: center; padding: 48px 20px; background: var(--surface);
  border: 2px dashed var(--border); border-radius: var(--radius); color: var(--text-muted);
}
.empty-state h3 { margin: 0 0 6px; color: var(--text); }

/* ---------------- Wizard Layout ---------------- */
.wizard-layout {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px;
  align-items: start; padding-bottom: 78px;
}
.wizard-sidebar {
  position: sticky; top: 74px; max-height: calc(100vh - 150px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.sidebar-header {
  padding: 12px 14px; background: var(--surface-alt); border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.sidebar-machine { font-weight: 800; font-size: 15px; color: var(--navy); }
.sidebar-meta { font-size: 12px; color: var(--text-muted); }
.sidebar-progress { padding: 10px 14px; border-bottom: 1px solid var(--border-light); }
.progress-text-row { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.progress-track { height: 8px; background: var(--border-light); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); transition: width 0.25s; }
.mini-stat-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; font-size: 11.5px; }
.mini-pill { padding: 1px 7px; border-radius: 4px; font-weight: 700; }

.sidebar-nav { overflow-y: auto; padding: 8px; flex: 1; }
.nav-group-title {
  font-size: 11.5px; font-weight: 800; color: var(--text-light); text-transform: uppercase;
  padding: 10px 8px 4px; letter-spacing: 0.02em;
}
.nav-item {
  width: 100%; text-align: left; border: none; background: transparent;
  padding: 7px 9px; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; font-family: inherit; font-size: 13px; color: var(--text);
}
.nav-item:hover { background: var(--surface-alt); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.nav-item.locked { opacity: 0.48; }
.nav-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; background: #cbd5e1; }
.nav-dot.PASS { background: var(--pass); }
.nav-dot.FAIL { background: var(--fail); }
.nav-dot.NA { background: #64748b; }
.nav-dot.PARTIAL { background: #f59e0b; }
.nav-code { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-light); min-width: 34px; }
.nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ---------------- Step Card ---------------- */
.step-card { background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.step-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border-light); }
.step-kicker { font-size: 12.5px; font-weight: 700; color: var(--primary); margin-bottom: 2px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.step-title { margin: 0; font-size: 20px; font-weight: 800; color: var(--navy); }

.banner {
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 14px;
  border-left: 4px solid;
}
.banner-amber { background: var(--warn-bg); border-color: #d97706; color: #78350f; }
.banner-red { background: var(--fail-bg); border-color: var(--fail); color: #7f1d1d; }
.banner-blue { background: var(--primary-soft); border-color: var(--primary); color: #1e3a8a; }

.signal-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 14px; }
.signal-chip {
  font-family: var(--font-mono); font-size: 12.5px; font-weight: 700;
  padding: 4px 10px; border-radius: 6px; background: #0f172a; color: #f8fafc;
}
.signal-arrow { color: var(--text-light); font-weight: 800; }

.sop-boxes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.sop-box { background: var(--surface-alt); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 12px 14px; }
.sop-box-title { font-size: 12px; font-weight: 800; color: var(--text-muted); margin-bottom: 4px; }
.sop-box-body { font-size: 14px; white-space: pre-line; }

.section-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border-light); }
.section-block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.section-block-title { font-size: 14px; font-weight: 800; color: var(--navy); }

/* Measurements */
.meas-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.meas-field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.meas-input-row { display: flex; align-items: stretch; }
.meas-input-row .input { border-top-right-radius: 0; border-bottom-right-radius: 0; font-family: var(--font-mono); font-weight: 700; }
.meas-unit {
  display: inline-flex; align-items: center; padding: 0 10px;
  background: var(--surface-alt); border: 1px solid var(--border); border-left: none;
  border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm);
  font-size: 13px; font-family: var(--font-mono); color: var(--text-muted); white-space: nowrap;
}
.meas-feedback { font-size: 12px; margin-top: 4px; font-weight: 600; }
.meas-feedback.ok { color: var(--pass); }
.meas-feedback.fail { color: var(--fail); }
.meas-feedback.warn { color: var(--warn); }
.hint-text { font-size: 12px; color: var(--text-light); }

/* Sub-checklist */
.subcheck-list { display: flex; flex-direction: column; gap: 8px; }
.subcheck-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer;
}
.subcheck-item:hover { background: var(--surface-alt); }
.subcheck-item.checked { background: #f0fdf4; border-color: var(--pass-border); }
.subcheck-item input[type="checkbox"] { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--pass); flex-shrink: 0; cursor: pointer; }

/* Safety Rules */
.safety-card { border: 2px solid #f59e0b; background: #fffbeb; border-radius: var(--radius); padding: 16px; margin-top: 16px; }
.safety-card.all-ok { border-color: var(--pass); background: #f0fdf4; }
.safety-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.safety-title { font-size: 16px; font-weight: 800; color: #92400e; }
.safety-card.all-ok .safety-title { color: var(--pass); }

/* Large 3-way Judgment Buttons */
.judge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.judge-btn {
  min-height: 52px; border-radius: 8px; border: 2px solid var(--border);
  background: #fff; color: var(--text); font-family: inherit; font-size: 15px; font-weight: 800;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 0.15s;
}
.judge-btn:hover { border-color: #94a3b8; }
.judge-btn.active-PASS { background: var(--pass); border-color: var(--pass); color: #fff; box-shadow: 0 3px 10px rgba(21,128,61,0.3); }
.judge-btn.active-FAIL { background: var(--fail); border-color: var(--fail); color: #fff; box-shadow: 0 3px 10px rgba(220,38,38,0.3); }
.judge-btn.active-NA { background: #475569; border-color: #475569; color: #fff; }

.fail-prompt {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--fail-bg); border: 1px solid var(--fail-border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}

/* Form Grids */
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.form-field { margin-bottom: 12px; }
.form-field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; color: var(--text); }
.power-select-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; }

/* Machine Options Box */
.options-box {
  background: var(--surface-alt); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px;
}
.options-box-title { font-size: 13.5px; font-weight: 800; color: var(--navy); margin-bottom: 10px; }
.opt-pairs-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.opt-pair-group { background: #fff; border: 1px solid var(--border-light); border-radius: 6px; padding: 8px 10px; }
.opt-pair-label { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; }
.opt-pair-btns { display: flex; gap: 6px; }
.opt-pair-btn {
  flex: 1; min-height: 36px; padding: 4px 8px; border-radius: 6px;
  border: 1.5px solid var(--border); background: #fff; color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  transition: all 0.14s;
}
.opt-pair-btn:hover { border-color: var(--primary); }
.opt-pair-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.opt-checks-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.opt-check-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px;
  border: 1.5px solid var(--border); border-radius: 8px; background: #fff;
  font-size: 13.5px; font-weight: 600; cursor: pointer; user-select: none;
}
.opt-check-chip:hover { border-color: var(--primary); }
.opt-check-chip.checked { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.opt-check-chip input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; margin: 0; }
.opt-other-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.opt-other-row .input { flex: 1 1 220px; min-height: 36px; }

/* HMI Parameter Cards */
.hmi-param-card {
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 14px; margin-bottom: 12px; background: var(--surface-alt);
}
.hmi-param-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.hmi-param-name { font-weight: 800; font-size: 15px; color: var(--navy); }
.hmi-std-pill { font-family: var(--font-mono); font-size: 12.5px; padding: 2px 9px; border-radius: 6px; background: #e0f2fe; color: #0369a1; font-weight: 700; }
.hmi-param-controls { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 10px; align-items: start; margin-top: 8px; }
.judge-compact { display: flex; gap: 6px; }
.judge-compact .judge-btn { min-height: 40px; padding: 0 12px; font-size: 13px; }
.temp4-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }

/* Auto Cycle Timeline Strip */
.seq-strip { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 14px; }
.seq-dot-btn {
  min-width: 34px; height: 32px; border-radius: 6px; border: 1px solid var(--border);
  background: #fff; font-family: var(--font-mono); font-size: 12px; font-weight: 700; cursor: pointer;
}
.seq-dot-btn.current { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(29,78,216,0.25); color: var(--primary); }
.seq-dot-btn.PASS { background: var(--pass-bg); border-color: var(--pass-border); color: var(--pass); }
.seq-dot-btn.FAIL { background: var(--fail-bg); border-color: var(--fail-border); color: var(--fail); }
.seq-dot-btn.NA { background: var(--na-bg); color: var(--na); }

/* Home Check Grid */
.home-check-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  background: #fff; margin-bottom: 10px;
}

/* Issues */
.issue-card {
  border: 1px solid var(--border-light); border-left: 4px solid var(--fail);
  border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px; background: #fff;
}
.issue-card.status-RESOLVED { border-left-color: var(--pass); }
.issue-card.status-IN_PROGRESS { border-left-color: #d97706; }
.issue-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.photo-preview-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.photo-thumb-wrap { position: relative; width: 84px; height: 84px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.photo-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.photo-remove-btn {
  position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(15,23,42,0.78); color: #fff; cursor: pointer; font-size: 12px;
}

/* Signature Pad */
.sign-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.sign-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; background: var(--surface-alt); }
.sign-canvas-wrap {
  background: #fff; border: 1px dashed #94a3b8; border-radius: 6px;
  overflow: hidden; margin: 8px 0; touch-action: none;
}
.sign-canvas { display: block; width: 100%; height: 140px; cursor: crosshair; }

/* Bottom Bar */
.wizard-bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border); padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.bottom-center-actions { display: flex; align-items: center; gap: 8px; }
.step-counter { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); font-weight: 700; }

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-panel {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-lg { max-width: 820px; }
.modal-xl { max-width: 980px; }
.modal-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal-header h2 { margin: 0; font-size: 17px; font-weight: 800; }
.modal-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--text-muted); }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border-light); margin-top: 8px; }
.preview-header-actions { display: flex; align-items: center; gap: 8px; }
.preview-scroll-body { background: #cbd5e1; padding: 18px; }
.preview-paper { background: #fff; max-width: 820px; margin: 0 auto; padding: 24px 28px; box-shadow: 0 4px 18px rgba(0,0,0,0.18); border-radius: 4px; }

/* Alarm Cards */
.alarm-list { display: flex; flex-direction: column; gap: 10px; }
.alarm-card {
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 12px 14px; background: var(--surface-alt);
}
.alarm-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.alarm-code-badge {
  font-family: var(--font-mono); font-weight: 800; font-size: 13px;
  padding: 2px 9px; border-radius: 5px; background: var(--fail); color: #fff;
}
.alarm-title { font-weight: 800; font-size: 15px; margin-left: 6px; }
.alarm-detail { font-size: 13.5px; margin: 4px 0; }

/* Lightbox & Toast */
.lightbox-wrap { position: relative; max-width: 92vw; max-height: 90vh; }
.lightbox-wrap img { max-width: 92vw; max-height: 88vh; border-radius: 8px; display: block; }
.lightbox-close { position: absolute; top: -14px; right: -14px; background: #0f172a; color: #fff; border-color: #fff; }
.toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%); z-index: 120;
  background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg);
}

.mobile-only { display: none; }
.desktop-only { display: inline-flex; }

/* ---------------- Responsive Mobile (< 860px) ---------------- */
@media (max-width: 860px) {
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .sop-boxes, .form-grid-2, .form-grid-3, .sign-grid, .opt-pairs-grid { grid-template-columns: 1fr; }
  .temp4-grid { grid-template-columns: repeat(2, 1fr); }
  .hmi-param-controls { grid-template-columns: 1fr; }

  .records-table-wrap { display: none; }
  .rec-cards-mobile { display: flex; flex-direction: column; gap: 10px; }
  .rec-mobile-card {
    background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius);
    padding: 14px; box-shadow: var(--shadow);
  }
  .rec-mobile-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }

  .wizard-layout { grid-template-columns: 1fr; }
  .wizard-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 84vw; max-width: 320px;
    max-height: none; z-index: 90; border-radius: 0;
    transform: translateX(-105%); transition: transform 0.22s ease;
  }
  .wizard-sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 85; }
  .step-card { padding: 15px; }
  .step-title { font-size: 18px; }
  .judge-btn { min-height: 50px; font-size: 14px; padding: 6px 4px; }
  .autosave-pill, .pwa-status-pill { display: none; }
  .wizard-bottom-bar { padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px)); gap: 6px; }
  .wizard-bottom-bar .btn { padding: 6px 10px; font-size: 13px; min-height: 40px; }
  .bottom-center-actions { gap: 4px; }
}

/* ============================================================================
 * 報告書預覽 & A4 列印 / PDF 專用排版
 * ============================================================================ */
.print-doc { color: #0f172a; font-family: var(--font-sans); font-size: 11.5px; line-height: 1.45; }
.p-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2.5px solid #0f172a; padding-bottom: 8px; margin-bottom: 10px; gap: 12px; }
.p-header h1 { margin: 0; font-size: 18px; letter-spacing: 0.04em; }
.p-sub { font-size: 10.5px; color: #475569; margin-top: 2px; }
.p-header-right { text-align: right; }
.p-doc-id { font-family: var(--font-mono); font-size: 10.5px; color: #334155; margin-bottom: 4px; }
.p-overall-box { display: inline-block; padding: 3px 10px; border-radius: 4px; font-weight: 800; font-size: 12px; border: 1.5px solid currentColor; }

.p-meta-table, .p-data-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.p-meta-table th, .p-meta-table td, .p-data-table th, .p-data-table td {
  border: 1px solid #94a3b8; padding: 4px 6px; vertical-align: top;
}
.p-meta-table th { background: #f1f5f9; font-weight: 700; width: 13%; white-space: nowrap; }
.p-data-table th { background: #e2e8f0; font-weight: 700; text-align: left; }
.p-data-table thead { display: table-header-group; }
.p-data-table tr { break-inside: avoid; page-break-inside: avoid; }

.p-section { margin-top: 12px; }
.p-section h2 {
  font-size: 13px; margin: 0 0 6px; padding: 4px 8px;
  background: #0f172a; color: #fff; border-radius: 3px;
  display: flex; justify-content: space-between; align-items: center;
}
.p-section h3 { font-size: 11.5px; margin: 8px 0 4px; color: #1e293b; }
.p-sec-note { font-size: 10px; font-weight: 400; color: #cbd5e1; }

.p-safety-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; border: 1px solid #94a3b8; padding: 6px 8px; background: #f8fafc; }
.p-safety-item { display: flex; gap: 6px; font-size: 10.5px; }
.p-chk { font-size: 13px; font-weight: 800; }

.p-home-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.p-home-item { border: 1px solid #94a3b8; padding: 4px 7px; display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 10.5px; }

.p-center { text-align: center; }
.p-mono { font-family: var(--font-mono); }
.p-small { font-size: 10.5px; }
.p-muted { color: #64748b; }
.p-subchk { font-size: 10px; color: #475569; margin-top: 2px; }
.p-opt { font-size: 9.5px; color: #6d28d9; font-weight: 700; }
.p-text-fail { color: #dc2626; }
.p-empty-note { padding: 8px; border: 1px dashed #94a3b8; color: #475569; margin: 0; }

.p-badge { display: inline-block; padding: 1px 6px; border-radius: 3px; font-weight: 700; font-size: 10.5px; white-space: nowrap; }
.p-pass { background: #dcfce7; color: #15803d; }
.p-fail { background: #fee2e2; color: #dc2626; }
.p-warn { background: #fef3c7; color: #b45309; }
.p-na { background: #e2e8f0; color: #475569; }
.p-pending { background: #f1f5f9; color: #64748b; }

.p-photo-strip { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0; }
.p-photo-strip figure { margin: 0; width: 150px; text-align: center; }
.p-photo-strip img { width: 150px; height: 110px; object-fit: cover; border: 1px solid #94a3b8; display: block; }
.p-photo-strip figcaption { font-size: 9.5px; color: #475569; margin-top: 2px; }

.p-sign-section { break-inside: avoid; page-break-inside: avoid; }
.p-comment-box { border: 1px solid #94a3b8; padding: 8px 10px; margin-bottom: 10px; background: #f8fafc; }
.p-sign-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.p-sign-box { border: 1px solid #94a3b8; padding: 8px 10px; }
.p-sign-title { font-weight: 700; margin-bottom: 6px; }
.p-sign-pad { height: 74px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid #cbd5e1; margin-bottom: 6px; }
.p-sign-pad img { max-height: 70px; max-width: 100%; }
.p-sign-placeholder { color: #94a3b8; font-size: 10.5px; }
.p-sign-date { font-size: 10.5px; color: #475569; }
.p-footer { margin-top: 10px; font-size: 9.5px; color: #64748b; text-align: right; }

@media print {
  @page { size: A4 portrait; margin: 10mm 10mm 12mm 10mm; }
  body { background: #fff !important; }
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  body.print-mode-landscape .print-landscape { width: 100%; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}
