/* MechQC — giao diện kiểm tra cơ khí: gọn, số liệu rõ, thao tác bàn phím */
:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --line: #dde2e8;
  --text: #1b2430;
  --muted: #6c7887;
  --accent: #1f5fd0;
  --accent-2: #153f8c;
  --pass: #0f7a55;
  --pass-bg: #e4f5ec;
  --fail: #c22b2b;
  --fail-bg: #fdecec;
  --warn: #8a6413;
  --warn-bg: #fdf5e0;
  --purple: #6b3fa0;
  --purple-bg: #f1ebfa;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 4px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0; text-transform: uppercase; letter-spacing: .04em; color: #3a4655; }

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 52px;
  background: #0f172a;
  color: #cfd8e6;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 800; letter-spacing: .08em; color: #fff; font-size: 16px; }
.brand span { color: #5b9dff; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #cfd8e6; padding: 6px 10px; border-radius: 6px; font-weight: 500; }
.topbar nav a:hover { background: #1c2740; text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .hint { font-size: 12px; color: #8b9ab0; }

.crumbs {
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 20px 0;
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.wrap { max-width: 1320px; margin: 0 auto; padding: 14px 20px 48px; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin-bottom: 2px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.head-card { padding: 18px 20px; }
.head-main { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.head-card .note {
  margin: 10px 0 0;
  padding: 8px 12px;
  background: #f7f9fc;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  white-space: pre-wrap;
}

.kv { display: flex; gap: 22px; margin: 0; flex-wrap: wrap; }
.kv div { display: flex; flex-direction: column; gap: 2px; }
.kv dt { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.w40 { width: 40px; }
.w110 { width: 110px; }
.w240 { width: 240px; }
.w300 { width: 320px; }

/* badges & verdict */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.b-gray { background: #eef1f4; color: #4a5563; border-color: #dde2e8; }
.b-blue { background: #e7f0fd; color: #1c4ea6; }
.b-indigo { background: #e9ecfd; color: #333fa8; }
.b-amber { background: var(--warn-bg); color: var(--warn); }
.b-purple { background: var(--purple-bg); color: var(--purple); }
.b-green { background: var(--pass-bg); color: var(--pass); }
.b-teal { background: #e0f4f3; color: #0f6f6a; }
.b-orange { background: #fdf0e3; color: #9a5209; }
.b-red { background: var(--fail-bg); color: var(--fail); }
.b-empty { background: transparent; color: var(--muted); border-color: var(--line); }

.verdict {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .03em;
  white-space: nowrap;
}
.v-pass { background: var(--pass-bg); color: var(--pass); }
.v-fail { background: var(--fail-bg); color: var(--fail); }
.v-pending { background: #f1f3f6; color: var(--muted); }
.v-na { background: #eef1f4; color: #4a5563; }


/* buttons & inputs */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: #c3cbd6; background: #f8fafc; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-sm { padding: 3px 9px; font-size: 12px; }

.input, .select {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font: inherit;
  min-width: 0;
}
.input:focus, .select:focus { outline: 2px solid #b9d0f7; border-color: var(--accent); }
.input:disabled, .select:disabled { background: #f5f7fa; color: var(--muted); }
.input.grow, .select.grow { flex: 1; }

.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 12px; }
.form-grid .field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span3 { grid-column: span 3; }
.form-grid .actions { display: flex; justify-content: flex-end; }

.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }

details.create { border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
details.create > summary { cursor: pointer; color: var(--accent); }
details.create[open] > summary { margin-bottom: 12px; }

/* tables */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fafbfd;
}
.table td { padding: 9px 10px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
.table tbody tr:hover { background: #fafcff; }
.table.compact td, .table.compact th { padding: 6px 8px; }
.table .empty { padding: 26px; text-align: center; color: var(--muted); }

.progress { height: 6px; background: #e9edf2; border-radius: 999px; overflow: hidden; margin-bottom: 4px; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress.slim { height: 4px; margin-top: 4px; margin-bottom: 2px; }

.tag-crit {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .04em;
  color: #a3231f;
  border: 1px solid #f0c2c0;
  background: #fff5f4;
  padding: 0 5px;
  border-radius: 4px;
  vertical-align: 1px;
}
.tag-danger { color: var(--fail); font-size: 11px; font-weight: 700; margin-left: 4px; }
.danger { color: var(--fail); }

/* trang kiểm tra: viewer trái, checklist phải */
.inspect-grid {
  display: grid;
  grid-template-columns: minmax(380px, 42%) minmax(520px, 1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 1180px) {
  .inspect-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
  .form-grid .span3 { grid-column: span 2; }
}

.viewer { position: sticky; top: 68px; }
.pdf-frame {
  width: 100%;
  height: 68vh;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e9edf2;
}
.placeholder {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 26px 18px;
  text-align: center;
  background: #fafbfd;
}
.placeholder p { margin: 4px 0; }
.upload { display: flex; gap: 8px; margin-top: 12px; }
.upload .input { flex: 1; }

/* checklist */
.summary { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  background: #f4f6f9;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--muted);
}
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip-pass { background: var(--pass-bg); border-color: #c7e8d8; color: var(--pass); }
.chip-pass b { color: var(--pass); }
.chip-fail { background: var(--fail-bg); border-color: #f3caca; color: var(--fail); }
.chip-fail b { color: var(--fail); }
.chip-pending { background: var(--warn-bg); border-color: #efe0b4; color: var(--warn); }
.chip-pending b { color: var(--warn); }

.checklist-table td { vertical-align: middle; }
.group-row td {
  background: #f7f9fc;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #5a6675;
  padding: 6px 10px;
}
.override { width: 100%; margin-top: 4px; font-size: 11px; padding: 3px 6px; }
.checklist-table .item-row.vrow-fail { background: #fffafa; }
.checklist-table .item-row.vrow-pass { background: #fbfefc; }
.item-label { font-weight: 600; }
.item-spec { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 2px; }
.item-spec .dot { margin: 0 6px; color: #b9c2cd; }

.measure { display: flex; gap: 6px; align-items: center; }
.measure .measured { width: 110px; font-family: var(--mono); font-size: 14px; font-weight: 600; }
.measure .note { flex: 1; min-width: 70px; font-size: 12px; }
.verdict-cell { width: 110px; }

.check-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.check-actions .inline-form { margin-top: 0; }
.chips { display: flex; gap: 8px; align-items: center; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed #edf0f4;
  font-size: 13px;
  flex-wrap: wrap;
}
.timeline .when { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 120px; }
.timeline .who { color: var(--muted); }
.timeline .why { color: var(--muted); font-style: italic; }

/* trang lỗi */
.err { max-width: 640px; margin: 15vh auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.err-code { font-family: var(--mono); font-size: 44px; font-weight: 800; color: var(--fail); margin: 0; line-height: 1; }
.err-msg { color: var(--muted); }


/* tab Bản vẽ / 3D trên trang kiểm tra */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef1f5;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1);
}
.pane[hidden] { display: none; }
.cad-host {
  position: relative;
  width: 100%;
  height: 68vh;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f5f8;
  overflow: hidden;
}
.cad-host canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.cad-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.cad-bar #cad-status { flex: 1 1 auto; min-width: 180px; }
.cad-bar label { display: inline-flex; align-items: center; gap: 5px; }

/* --- Soát bản vẽ tổng hợp --- */
.row-warn { background: #fff8e1; }
.warn-list {
  margin: .25rem 0 0;
  padding-left: 1.1rem;
  color: #8a6d00;
  font-size: .78rem;
  line-height: 1.35;
}
.warn-list li { margin: .1rem 0; }

/* --- Soát thông số trích từ bản vẽ (Phase 2) --- */
/* Dòng đã tạo mục kiểm tra: xám đi để phân biệt với dòng còn chờ quyết định. */
.row-done { background: #f4f6f8; color: #5b6670; }
.row-done td { opacity: .85; }
/* Dòng đã loại: vẫn liệt kê để đối chiếu, nhưng mờ đi và không có ô tick. */
.row-reject { background: #f7f7f8; color: #98a0a8; }
.row-reject td { opacity: .7; }
.row-reject strong { text-decoration: line-through; }
/* Cờ cảnh báo ngắn ngay trong ô "Cần chú ý". */
.warn-inline {
  color: #8a6d00;
  font-size: .76rem;
  line-height: 1.3;
}
/* Nút nhỏ đặt cạnh từng dòng (Loại / Hồi phục). */
.btn-mini {
  padding: .1rem .45rem;
  font-size: .74rem;
  line-height: 1.4;
}

