/*
 * Tự cấu hình PC. Mobile: ô linh kiện xếp dọc, cấu hình bên dưới, thanh tổng tiền dính đáy.
 * Máy tính (64em): ô linh kiện bên trái, cấu hình dính bên phải. Chỉ dùng biến semantic trong tokens.css.
 */

.pcb { padding-bottom: var(--space-7); }
.pcb-head { padding: 0 var(--space-4) var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); }
.pcb-head h1 { margin: 0 0 6px; }
.pcb-head p { margin: 0; color: var(--color-text-muted); }
.pcb-head-btns { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pcb-head-btns .btn, .pcb-sum-btns .btn, .pcb-pick, .pcb-buy, .pcb-dlg-ft .btn { gap: 6px; }
.pcb-head-btns .icon, .pcb-sum-btns .icon, .pcb-pick .icon, .pcb-buy .icon, .pcb-dlg-ft .icon { width: 18px; height: 18px; }
.pcb-head-btns .btn[hidden] { display: none; }
.pcb-nojs { margin: 0 var(--space-4) var(--space-4); padding: var(--space-3); border-radius: var(--radius-sm); background: var(--color-warning-bg); }

.pcb-layout { display: flex; flex-direction: column; gap: var(--space-4); }
.pcb-step { padding: var(--space-4); background: var(--color-surface); }
.pcb-step-h { margin: 0 0 var(--space-3); font-size: var(--text-lg); display: flex; align-items: center; gap: var(--space-2); }
.pcb-goal-pick { margin: 0 0 var(--space-4); padding: 0; border: 0; min-width: 0; }
.pcb-goal-pick legend { padding: 0; margin-bottom: var(--space-2); font-weight: var(--weight-strong); }
.pcb-goal-pick legend small { display: block; font-weight: normal; font-size: var(--text-sm); color: var(--color-text-muted); }
.pcb-goal-opts { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pcb-goal-opts label { position: relative; cursor: pointer; }
.pcb-goal-opts input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pcb-goal-opts span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-full); background: var(--color-surface); font-size: var(--text-sm); }
.pcb-goal-opts input:checked + span { border-color: var(--color-action); background: var(--color-action); color: var(--color-on-action); font-weight: var(--weight-strong); }
.pcb-goal-opts input:focus-visible + span { outline: 2px solid var(--color-action); outline-offset: 2px; }
.pcb-goals { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0; }
.pcb-goal { padding: 0 6px; border-radius: var(--radius-sm); background: var(--color-surface-sunken); color: var(--color-text-muted); font-size: var(--text-xs); line-height: 1.6; }
.pcb-goal.is-match { background: var(--color-success-bg); color: var(--color-success); font-weight: var(--weight-strong); }
.pcb-step-h span { width: 28px; height: 28px; border-radius: var(--radius-full); background: var(--color-action); color: var(--color-on-action); font-size: var(--text-sm); display: grid; place-items: center; }
.pcb-sub { margin: var(--space-5) 0 var(--space-3); font-size: var(--text-base); }
.pcb-sub small { margin-left: var(--space-1); font-weight: var(--weight-regular); color: var(--color-text-muted); }

/* Ô linh kiện */
.pcb-slots { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-2); }
.pcb-slot { padding: var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-md); display: flex; flex-direction: column; gap: var(--space-2); }
.pcb-slot.is-filled { border-color: var(--color-border-strong); }
.pcb-slot-hd { display: flex; align-items: center; gap: var(--space-2); }
.pcb-slot-ic { width: 32px; height: 32px; flex: none; border-radius: var(--radius-sm); background: var(--color-surface-sunken); color: var(--color-text-muted); display: grid; place-items: center; }
.pcb-slot-ic .icon { width: 20px; height: 20px; }
.pcb-slot.is-filled .pcb-slot-ic { background: var(--color-action-bg); color: var(--color-action); }
.pcb-slot-name { font-weight: var(--weight-strong); }
.pcb-tag { margin-left: auto; padding: 2px 8px; border-radius: var(--radius-full); background: var(--color-surface-sunken); color: var(--color-text-muted); font-size: var(--text-xs); white-space: nowrap; }
.pcb-tag.is-req { background: var(--color-action-bg); color: var(--color-action); font-weight: var(--weight-strong); }
.pcb-slot-body { display: flex; flex-direction: column; gap: var(--space-2); }
.pcb-slot-empty { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); display: flex; flex-direction: column; gap: 2px; }
.pcb-hint { color: var(--color-success); font-weight: var(--weight-strong); }
.pcb-pick { align-self: flex-start; }

.pcb-sel { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: var(--space-2) var(--space-3); }
.pcb-sel-img { width: 56px; height: 56px; border-radius: var(--radius-sm); overflow: hidden; background: var(--color-surface-sunken); }
.pcb-sel-img img, .pcb-item-img img { width: 100%; height: 100%; object-fit: contain; }
.pcb-sel-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pcb-sel-name { color: var(--color-text); font-size: var(--text-sm); font-weight: var(--weight-strong); line-height: var(--leading-tight); text-decoration: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcb-sel-price { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2); font-size: var(--text-sm); }
.pcb-sel-price b { color: var(--color-price); }
.pcb-sel-price small { color: var(--color-text-muted); }
.pcb-sel-price s { font-size: var(--text-xs); color: var(--color-text-muted); }
.pcb-sel-act { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--space-1) var(--space-3); flex-wrap: wrap; }
.pcb-lnk { min-height: 40px; padding: 0 var(--space-1); border: 0; background: none; color: var(--color-link); font: inherit; font-size: var(--text-sm); cursor: pointer; }
.pcb-lnk:last-child { color: var(--color-text-muted); }
.pcb-qty { margin-right: auto; display: inline-flex; align-items: center; border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); }
.pcb-qty button { width: 40px; height: 38px; border: 0; background: none; color: var(--color-text); font: inherit; font-size: 1.125rem; cursor: pointer; }
.pcb-qty button:disabled { color: var(--color-text-muted); opacity: .5; cursor: default; }
.pcb-qty span { min-width: 28px; text-align: center; font-weight: var(--weight-strong); }

/* Trạng thái tương thích */
.pcb-st { margin: 0; padding-left: 20px; position: relative; font-size: var(--text-xs); line-height: 1.4; }
.pcb-st::before { position: absolute; left: 0; top: 0; width: 16px; text-align: center; font-weight: var(--weight-strong); }
.pcb-st.is-ok { color: var(--color-success); }
.pcb-st.is-ok::before { content: "✓"; }
.pcb-st.is-bad { color: var(--color-danger); }
.pcb-st.is-bad::before { content: "!"; }
.pcb-st.is-unk { color: var(--color-text-muted); }
.pcb-st.is-unk::before { content: "?"; }

/* Cấu hình của bạn */
.pcb-sum-box { display: flex; flex-direction: column; gap: var(--space-3); }
.pcb-count { margin: 0; font-size: var(--text-sm); color: var(--color-text-muted); }
.pcb-count b { color: var(--color-text); }
.pcb-sum-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
.pcb-sum-list li { padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px var(--space-3); font-size: var(--text-sm); }
.pcb-sum-list .pcb-sum-empty { display: block; border: 0; color: var(--color-text-muted); }
.pcb-sum-slot { grid-column: 1 / -1; font-size: var(--text-xs); color: var(--color-text-muted); }
.pcb-sum-name { min-width: 0; line-height: var(--leading-tight); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcb-sum-price { font-weight: var(--weight-strong); white-space: nowrap; }
.pcb-checks { padding: var(--space-3); border-radius: var(--radius-sm); background: var(--color-surface-sunken); }
.pcb-checks-h { margin: 0 0 var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-strong); }
.pcb-checks ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.pcb-checks li { padding-left: 20px; position: relative; font-size: var(--text-xs); line-height: 1.4; }
.pcb-checks li::before { position: absolute; left: 0; top: 0; width: 16px; text-align: center; font-weight: var(--weight-strong); }
.pcb-checks li.is-ok { color: var(--color-success); }
.pcb-checks li.is-ok::before { content: "✓"; }
.pcb-checks li.is-bad { color: var(--color-danger); }
.pcb-checks li.is-bad::before { content: "!"; }
.pcb-checks li.is-unk { color: var(--color-text-muted); }
.pcb-checks li.is-unk::before { content: "?"; }
.pcb-watt { margin: 0; font-size: var(--text-sm); }
.pcb-total { margin: 0; padding-top: var(--space-2); display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); font-weight: var(--weight-strong); }
.pcb-total b { color: var(--color-price); font-size: var(--text-xl); }
.pcb-note, .pcb-need { margin: 0; font-size: var(--text-xs); color: var(--color-text-muted); }
.pcb-need.is-warn { color: var(--color-warning); font-weight: var(--weight-strong); }
.pcb-buy { width: 100%; }
.pcb-buy.is-busy { opacity: .6; pointer-events: none; }
.pcb-err { margin: 0; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--color-danger-bg); color: var(--color-danger); font-size: var(--text-sm); }
.pcb-sum-btns { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-2); }

.pcb-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: var(--z-sticky);
  padding: var(--space-2) var(--space-4) calc(var(--space-2) + env(safe-area-inset-bottom));
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.pcb-bar[hidden] { display: none; }
.pcb-bar p { flex: 1; margin: 0; display: flex; flex-direction: column; line-height: 1.2; }
.pcb-bar span { font-size: var(--text-xs); color: var(--color-text-muted); }
.pcb-bar p > b { color: var(--color-price); font-size: var(--text-lg); }

/* Bảng chọn */
.pcb-dlg {
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  color: var(--color-text);
  background: var(--color-surface);
}
.pcb-dlg::backdrop { background: var(--color-overlay); }
.pcb-dlg-in { height: 100%; display: flex; flex-direction: column; }
.pcb-dlg-hd { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.pcb-dlg-h { margin: 0; font-size: var(--text-lg); font-weight: var(--weight-strong); }
.pcb-dlg-sub { margin: 2px 0 0; font-size: var(--text-sm); color: var(--color-text-muted); }
.pcb-x { width: var(--tap-min); height: var(--tap-min); margin: -8px -12px 0 0; flex: none; border: 0; background: none; color: var(--color-text); display: grid; place-items: center; cursor: pointer; }
.pcb-dlg-tools { padding: var(--space-3) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); border-bottom: 1px solid var(--color-border); }
.pcb-search { position: relative; }
.pcb-search .icon { position: absolute; left: 12px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); color: var(--color-text-muted); pointer-events: none; }
.pcb-search input, .pcb-sort, .pcb-pfields input, .pcb-pfields textarea {
  width: 100%;
  min-height: var(--tap-min);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: 1rem;
}
.pcb-search input { padding-left: 40px; }
.pcb-dlg-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.pcb-only { min-height: 40px; display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); cursor: pointer; }
.pcb-only input { width: 20px; height: 20px; margin: 0; accent-color: var(--color-action); }
.pcb-sort { width: auto; min-height: 40px; font-size: var(--text-sm); }
.pcb-dlg-hint { margin: 0; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); background: var(--color-success-bg); color: var(--color-success); font-size: var(--text-sm); font-weight: var(--weight-strong); }
.pcb-items { flex: 1; margin: 0; padding: 0 var(--space-4); list-style: none; overflow-y: auto; overscroll-behavior: contain; }
.pcb-item { padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: var(--space-2) var(--space-3); align-items: start; }
.pcb-item.is-bad { opacity: .7; }
.pcb-item.is-cur { background: var(--color-action-bg); margin: 0 calc(-1 * var(--space-4)); padding-left: var(--space-4); padding-right: var(--space-4); }
.pcb-item-img { width: 56px; height: 56px; border-radius: var(--radius-sm); overflow: hidden; background: var(--color-surface-sunken); }
.pcb-item-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pcb-item-name { color: var(--color-text); font-size: var(--text-sm); font-weight: var(--weight-strong); line-height: var(--leading-tight); text-decoration: none; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcb-item-price { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2); }
.pcb-item-price b { color: var(--color-price); }
.pcb-item-price b.is-muted { color: var(--color-text-muted); font-weight: var(--weight-regular); }
.pcb-item-price s { font-size: var(--text-xs); color: var(--color-text-muted); }
.pcb-item-fit { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2); }
.pcb-item-fit small { font-size: var(--text-xs); color: var(--color-text-muted); line-height: 1.4; }
.pcb-fit { padding: 1px 8px; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: var(--weight-strong); white-space: nowrap; }
.pcb-fit.is-ok { background: var(--color-success-bg); color: var(--color-success); }
.pcb-fit.is-bad { background: var(--color-danger-bg); color: var(--color-danger); }
.pcb-fit.is-unk { background: var(--color-surface-sunken); color: var(--color-text-muted); }
.pcb-item .btn { grid-column: 2; justify-self: start; min-width: 96px; }
.pcb-items-none { padding: var(--space-6) 0; text-align: center; color: var(--color-text-muted); }
.pcb-dlg-ft { padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom)); border-top: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.pcb-dlg-status { margin: 0; font-size: var(--text-xs); color: var(--color-text-muted); }
.pcb-dlg-ft .btn[hidden] { display: none; }

/* Hộp in */
.pcb-dlg--print { height: auto; max-height: 100%; margin: auto 0 0; border-radius: var(--radius-md) var(--radius-md) 0 0; }
.pcb-pfields { padding: var(--space-3) var(--space-4); overflow-y: auto; display: grid; gap: var(--space-3); }
.pcb-pfields label { display: flex; flex-direction: column; gap: 4px; font-size: var(--text-sm); font-weight: var(--weight-strong); }
.pcb-pfields input, .pcb-pfields textarea { font-weight: var(--weight-regular); }
.pcb-pfields textarea { min-height: 88px; padding: var(--space-2) var(--space-3); resize: vertical; }
.pcb-pform .pcb-dlg-ft { justify-content: flex-end; }

.pcb-printout { display: none; }

@media (min-width: 40em) {
  .pcb-pfields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pcb-pfields .is-wide { grid-column: 1 / -1; }
  .pcb-item { grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; }
  .pcb-item-img { width: 64px; height: 64px; }
  .pcb-item .btn { grid-column: auto; }
}

@media (min-width: 64em) {
  .pcb { max-width: var(--page-max); margin: 0 auto; padding-left: var(--space-4); padding-right: var(--space-4); }
  .pcb-head { padding: var(--space-2) 0 var(--space-4); flex-direction: row; align-items: flex-end; justify-content: space-between; }
  .pcb-head h1 { font-size: var(--text-2xl); }
  .pcb-head p { max-width: 720px; }
  .pcb-head-btns { flex: none; }
  .pcb-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--space-5); align-items: start; }
  .pcb-step { padding: var(--space-5); border-radius: var(--radius-md); }
  .pcb-sum { position: sticky; top: 88px; max-height: calc(100vh - 104px); overflow-y: auto; }
  .pcb-slot { padding: var(--space-3) var(--space-4); display: grid; grid-template-columns: 240px minmax(0, 1fr); align-items: center; gap: var(--space-3); }
  .pcb-slot-hd { flex-wrap: wrap; }
  .pcb-tag { margin-left: 40px; }
  .pcb-slot-body { flex-direction: row; align-items: center; justify-content: space-between; gap: var(--space-3); }
  .pcb-sel { flex: 1; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; }
  .pcb-sel-img { width: 64px; height: 64px; }
  .pcb-sel-act { grid-column: auto; flex-wrap: nowrap; }
  .pcb-qty { margin-right: var(--space-2); }
  .pcb-pick { align-self: center; flex: none; }
  .pcb-bar { display: none; }

  .pcb-dlg { width: min(860px, 100% - 64px); height: min(820px, 100% - 64px); margin: auto; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); }
  .pcb-dlg--print { width: min(620px, 100% - 64px); height: auto; margin: auto; border-radius: var(--radius-md); }
  .pcb-dlg-tools { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .pcb-search { flex: 1; min-width: 280px; }
  .pcb-dlg-row { flex: none; }
  .pcb-dlg-hint { flex-basis: 100%; }
}

/* In cấu hình: chỉ in khối pcb-printout */
@media print {
  body.pcb-printing { background: #fff; }
  body.pcb-printing > *:not(.pcb-printout) { display: none !important; }
  body.pcb-printing > .pcb-printout { display: block; color: #000; font-size: 12px; }
  .pcb-po-hd { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 12px; border-bottom: 2px solid #000; }
  .pcb-po-hd p { margin: 0 0 2px; }
  .pcb-po-shop, .pcb-po-title { font-size: 16px; font-weight: 700; }
  .pcb-po-meta { text-align: right; }
  .pcb-po-cust { margin: 12px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; }
  .pcb-po-cust div { display: flex; gap: 6px; }
  .pcb-po-cust dt { font-weight: 700; }
  .pcb-po-cust dd { margin: 0; }
  .pcb-printout table { width: 100%; margin-top: 12px; border-collapse: collapse; }
  .pcb-printout th, .pcb-printout td { padding: 6px; border: 1px solid #999; text-align: left; vertical-align: top; }
  .pcb-printout td:nth-child(n+4), .pcb-printout th:nth-child(n+4) { text-align: right; white-space: nowrap; }
  .pcb-printout tfoot td { font-weight: 700; }
  .pcb-po-note { margin-top: 12px; font-size: 11px; color: #333; word-break: break-all; }
}
