/* ============================================================================
   CHEN Production OS — theme áp ngôn ngữ thiết kế CHEN Growth OS
   (quiet-luxury: nền off-white, card trắng viền mảnh, gần như không shadow,
    pink là ACCENT, nút primary near-black, Inter, light-only)
   ============================================================================ */
:root {
  /* nền & mực (stock Tailwind gray) */
  --bg: #f9fafb; /* page bg (gray-50) */
  --panel: #ffffff; /* card / panel */
  --line: #f3f4f6; /* border mặc định (gray-100) */
  --line-2: #e5e7eb; /* border input / mạnh hơn (gray-200) */
  --fg: #111827; /* text chính (gray-900) */
  --fg-2: #374151; /* text đậm (gray-700) */
  --muted: #6b7280; /* text phụ (gray-500) */
  --faint: #9ca3af; /* text mờ / placeholder (gray-400) */
  /* brand pink — chỉ dùng làm accent */
  --brand: #db2777; /* pink-600 */
  --brand-dark: #be185d; /* pink-700 */
  --brand-bg: #fdf2f8; /* pink-50 */
  /* nút primary = near-black (Growth OS) */
  --primary: #111827;
  --primary-hover: #1f2937;
  /* semantic (tint nhạt) */
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --ok-line: #d1fae5;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --warn-line: #fde68a;
  --err: #dc2626;
  --err-bg: #fef2f2;
  --err-line: #fecaca;
  --info: #1d4ed8;
  --info-bg: #eff6ff;
  /* accent (link/nav) = pink; giữ tên --accent cho tương thích code cũ */
  --accent: var(--brand-dark);
  /* hình khối */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font: 14px / 1.5 "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
a {
  color: var(--brand-dark);
  text-decoration: none;
  cursor: pointer;
}
a:hover {
  text-decoration: underline;
}

/* ---- sign-in ---- */
.signin {
  max-width: 420px;
  margin: 12vh auto;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  text-align: center;
}
.signin h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}
.signin p {
  color: var(--muted);
  margin: 0 0 24px;
}
.roles {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- buttons (primary near-black; ghost = outline) ---- */
button {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
button.ghost {
  background: var(--panel);
  color: var(--fg-2);
  border: 1px solid var(--line-2);
}
button.ghost:hover {
  background: var(--bg);
  color: var(--fg);
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- app shell ---- */
.layout {
  display: grid;
  grid-template-columns: 224px 1fr;
  min-height: 100vh;
}
.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
}
.side h2 {
  font-size: 13px;
  color: var(--fg);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 4px 8px 14px;
}
.nav a {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 2px;
  transition: background 0.12s, color 0.12s;
}
.nav a:hover {
  background: var(--bg);
  color: var(--fg);
  text-decoration: none;
}
.nav a.active {
  background: var(--brand-bg);
  color: var(--brand-dark);
}
/* Khối người dùng nằm NGAY DƯỚI logo, giống CHEN Studio — không nằm dưới đáy thanh bên:
   danh tính là thứ người dùng liếc để biết mình đang là ai, không phải thứ phải cuộn xuống tìm. */
.side .who {
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}
.who-row { display: flex; align-items: center; gap: 10px; }
.who-avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--brand-bg);
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.who-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.who-id { min-width: 0; flex: 1; }
.who-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.who-title { font-size: 11.5px; color: var(--muted); }
/* Nút thoát: nền TRONG SUỐT, không dùng nền tối mặc định của button — nó nằm cạnh avatar. */
button.who-out {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 4px 6px;
  font-size: 14px;
  line-height: 1;
}
button.who-out:hover { background: var(--brand-bg); color: var(--brand-dark); }
.who-back {
  display: block;
  margin-top: 10px;
  padding: 6px 4px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}
.who-back:hover { color: var(--brand-dark); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.badge.role {
  background: var(--brand-bg);
  color: var(--brand-dark);
}

/* ---- main ---- */
.main {
  padding: 28px 32px;
  overflow: auto;
  max-width: 1400px;
}
.main h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.crumb {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
}

/* ---- KPI cards ---- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.card .k {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.card .v {
  font-size: 26px;
  font-weight: 700;
  margin-top: 4px;
}
.card .v.ok {
  color: var(--ok);
}
.card .v.off {
  color: var(--faint);
}
.card .v.small {
  font-size: 18px;
  margin-top: 10px;
}
.cards.compact {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin: 16px 0;
}
.section-title {
  margin: 28px 0 12px;
  font-size: 16px;
  font-weight: 600;
}

/* ---- system flow ---- */
.system-flow {
  display: grid;
  grid-template-columns: minmax(190px, 1.35fr) auto repeat(3, minmax(150px, 1fr) auto);
  align-items: stretch;
  gap: 8px;
}
.system {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.system.primary {
  border-color: var(--brand);
  background: var(--brand-bg);
}
.system span {
  color: var(--muted);
  font-size: 12px;
}
.arrow {
  align-self: center;
  color: var(--faint);
  font-size: 20px;
}
.boundary {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: var(--radius-sm);
  color: var(--warn);
}

/* ---- tables ---- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
th,
td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover td {
  background: var(--bg);
}
.num {
  text-align: right;
}
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

/* ---- inputs ---- */
/* `input:not([type])`: ô nhập dựng bằng pcInput() không khai type, nên trước đây rơi ra ngoài
   theme và hiện bằng kiểu mặc định của trình duyệt — viền dày, bo tròn khác hẳn phần còn lại. */
input:not([type]),
input[type="search"],
input[type="text"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  font: inherit;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input::placeholder,
textarea::placeholder {
  color: var(--faint);
}
input:not([type]):focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--faint);
  box-shadow: 0 0 0 3px var(--line);
}
input[type="search"],
.toolbar input[type="text"] {
  min-width: 220px;
}

/* ---- pills / status ---- */
.pill {
  display: inline-block;
  /* Không cho xuống dòng: "Cần đặt sản xuất" bị bẻ thành 3 dòng làm cả hàng cao gấp ba. */
  white-space: nowrap;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: var(--line);
  color: var(--muted);
}
.pill.APPROVED,
.pill.ACTIVE,
.pill.VERIFIED,
.pill.OK {
  background: var(--ok-bg);
  color: var(--ok);
}
.pill.DRAFT,
.pill.CONFIG_COMPLETE,
.pill.PENDING,
.pill.UNKNOWN {
  background: var(--warn-bg);
  color: var(--warn);
}
.pill.FAILED {
  background: var(--err-bg);
  color: var(--err);
}
.pill.NOT_CONFIGURED {
  background: var(--line);
  color: var(--muted);
}

/* ---- misc ---- */
.err {
  color: var(--err);
  background: var(--err-bg);
  border: 1px solid var(--err-line);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}
.muted {
  color: var(--muted);
}
.right {
  text-align: right;
}
.kv {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 6px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  max-width: 640px;
}
.kv.wide {
  max-width: 900px;
}
.kv .k {
  color: var(--muted);
}
.note {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

@media (max-width: 1100px) {
  .system-flow {
    grid-template-columns: 1fr;
  }
  .system-flow .arrow {
    transform: rotate(90deg);
    justify-self: center;
  }
}
@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .side {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .main {
    padding: 18px 14px;
  }
}

/* ---- modal / drawer ---- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.2);
  backdrop-filter: blur(1px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px;
  z-index: 50;
  overflow: auto;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2xl);
  width: 100%;
  max-width: 560px;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}
.modal-head .x {
  background: transparent;
  color: var(--faint);
  border: 0;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.modal-head .x:hover {
  background: var(--bg);
  color: var(--fg);
}
.modal-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.flabel {
  color: var(--fg-2);
  font-size: 12px;
  font-weight: 500;
}
.field input,
.field select {
  width: 100%;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}
.modal-msg .ok,
.ok {
  color: var(--ok);
  background: var(--ok-bg);
  border: 1px solid var(--ok-line);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
}
.blocked {
  background: var(--err-bg);
  border: 1px solid var(--err-line);
  color: var(--err);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
}
.blocked strong {
  color: var(--err);
}

/* ---- status boxes ---- */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin: 12px 0;
}
.status-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.status-box .k {
  color: var(--muted);
  font-size: 12px;
}
.status-box .v {
  font-weight: 600;
  margin-top: 3px;
}
.line-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
  align-items: end;
}

/* ---- (legacy dual-line editor — giữ để không vỡ) ---- */
.pc-lines {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.pc-line-edit {
  display: grid;
  grid-template-columns: 1.2fr 1.4fr 1.6fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}
.pc-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pc-col.actual {
  border-left: 3px solid var(--ok);
  padding-left: 8px;
}
.pc-col.invoice {
  border-left: 3px solid var(--warn);
  padding-left: 8px;
}
.pc-col-h {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
@media (max-width: 720px) {
  .pc-line-edit {
    grid-template-columns: 1fr;
  }
}
pre.code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow: auto;
  max-height: 50vh;
  font-size: 12px;
  white-space: pre;
  color: var(--fg-2);
}

/* ── Purchase Case full-width drawer ── */
.modal.drawer-wide {
  max-width: 1120px;
  /* Panel rộng CUỘN BÊN TRONG, không cuộn cả nền: có vậy thanh nút mới đứng yên ở đáy panel.
     Trước đây cả lớp nền cuộn nên sticky không bám vào đâu, phải để nút trôi theo nội dung —
     bảng định mức dài vài chục dòng là mỗi lần bấm nút phải kéo xuống cuối tìm. */
  display: flex;
  flex-direction: column;
  max-height: 88vh;
}
.modal.drawer-wide > .modal-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.pc-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--panel);
}
.pc-section > h4 {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.pc-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pc-field > label {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-2);
}
.pc-field input,
.pc-field select {
  width: 100%;
  box-sizing: border-box;
}
.pc-line {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin-bottom: 8px;
}
.pc-line-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.pc-line-cols .col-actual {
  border-right: 1px solid var(--line);
  padding-right: 12px;
}
.pc-col-head {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.pc-col-head.actual {
  color: var(--ok);
}
.pc-col-head.invoice {
  color: var(--info);
}
.pc-fincode {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  margin-top: 6px;
  color: var(--muted);
}
.pc-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
}
.pc-badge.exists {
  background: var(--ok-bg);
  color: var(--ok);
}
.pc-badge.new {
  background: var(--warn-bg);
  color: var(--warn);
}
.pc-footer {
  position: sticky;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 14px 4px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.pc-footer .totals {
  margin-right: auto;
  font-size: 13px;
}
.pc-footer .totals b {
  font-variant-numeric: tabular-nums;
}
.pc-line-total {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  text-align: right;
}

/* ── Settings sub-sidebar ── */
.settings-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: start;
}
.settings-subnav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--panel);
}
.settings-subnav .subnav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.settings-subnav .subnav-item:hover {
  background: var(--bg);
  color: var(--fg);
}
.settings-subnav .subnav-item.active {
  background: var(--brand-bg);
  color: var(--brand-dark);
  font-weight: 600;
}
.settings-subnav .subnav-ico {
  width: 18px;
  text-align: center;
}
.settings-content {
  min-width: 0;
}
.settings-content .status-box,
.settings-content .provider-card {
  margin-bottom: 0;
}
.provider-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
@media (max-width: 780px) {
  .settings-layout {
    grid-template-columns: 1fr;
  }
  .settings-subnav {
    flex-direction: row;
    overflow-x: auto;
    position: static;
  }
}

/* ── comboBox (dropdown search + thêm mới) ── */
.combo {
  position: relative;
}
.combo > input {
  width: 100%;
  box-sizing: border-box;
}
.combo-panel {
  position: absolute;
  z-index: 60;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  max-height: 260px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.combo-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.combo-item:last-child {
  border-bottom: 0;
}
.combo-item:hover {
  background: var(--bg);
}
.combo-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.combo-add {
  color: var(--brand-dark);
  font-weight: 600;
}
.combo-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
}

/* ── line table (Lark Base style) ── */
.pc-ltable-wrap {
  overflow-x: auto;
}
.pc-ltable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 880px;
  border: 0;
  border-radius: 0;
}
.pc-ltable th {
  text-align: left;
  background: var(--bg);
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 6px;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
.pc-ltable td {
  padding: 4px 5px;
  vertical-align: middle;
  border-bottom: 0;
}
.pc-ltable input,
.pc-ltable .combo > input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
}
.pc-ltable tr.pc-lrow {
  border-top: 1px solid var(--line);
}
.pc-ltable tr.pc-lrow:hover td {
  background: transparent;
}
.pc-ltable td.num input {
  text-align: right;
}
.pc-ltable td.total {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--fg);
  font-weight: 500;
}
.pc-ltable td.fincode {
  font-size: 11px;
  color: var(--muted);
}
.pc-lrow-x {
  background: transparent;
  border: 0;
  color: var(--err);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
}
.pc-lrow-x:hover {
  background: var(--err-bg);
}
.pc-inv-toggle {
  font-size: 12px;
  color: var(--brand-dark);
  cursor: pointer;
  user-select: none;
}
.pc-inv-toggle:hover {
  text-decoration: underline;
}

/* ── Bảng dòng hàng rộng (Hoá đơn | Thực tế | Thuế) — 1 dòng/mục kiểu Lark Base ── */
.pc-ltable-wide {
  min-width: 1560px;
  font-size: 12.5px;
}
.pc-ltable-wide th {
  text-align: center;
  padding: 5px 6px;
  border-right: 1px solid var(--line);
}
.pc-ltable-wide td {
  padding: 4px 4px;
  border-right: 1px solid var(--line);
}
.pc-ltable-wide input {
  padding: 5px 6px;
  font-size: 12.5px;
}
/* Nhóm cột — tiêu đề nhóm + nền nhạt cho toàn cột trong nhóm */
.pc-ltable-wide th.grp {
  font-size: 11px;
  letter-spacing: 0.04em;
}
.pc-ltable-wide th.grp-inv,
.pc-ltable-wide td.grp-inv {
  background: #fef6fb;
}
.pc-ltable-wide th.grp-act,
.pc-ltable-wide td.grp-act {
  background: #f2f8ff;
}
.pc-ltable-wide th.grp-tax,
.pc-ltable-wide td.grp-tax {
  background: #f6f7f9;
}
.pc-ltable-wide td.c-name {
  min-width: 210px;
}
/* Hàng gợi ý FIN-CODE nằm DƯỚI dòng hàng, chiếm trọn bề ngang — mã dài mấy cũng không đẩy
   lệch lưới ô nhập phía trên. */
.pc-ltable-wide tr.pc-lhint td {
  padding: 0 6px 8px 6px;
  border-bottom: 1px solid var(--line);
}
.pc-fincode {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 0;
  min-width: 0;
}
.pc-fincode-k {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 0 0 auto;
}
.pc-fincode-v {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--text, #0f172a);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  /* Một dòng, dài quá thì cắt bằng "…" — rê chuột có tooltip đủ mã. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 620px;
}
.pc-fincode-err { color: var(--err, #b91c1c); }
/* Cột "Nhóm" + ô quy cách đổi theo nhóm (3 ô chất liệu ↔ 1 ô phiên bản) */
.pc-ltable-wide td.c-group {
  min-width: 132px;
}
.pc-ltable-wide td.c-spec {
  min-width: 280px;
}
.pc-spec-fabric {
  display: grid;
  grid-template-columns: 1fr 1fr 0.8fr;
  gap: 4px;
}
.pc-spec-label .combo {
  width: 100%;
}
.pc-ltable-wide input.w-uom {
  width: 56px;
}
.pc-ltable-wide input.w-vat {
  width: 60px;
}
.pc-auto {
  display: block;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding: 5px 4px;
}
.pc-auto.strong {
  color: var(--fg);
  font-weight: 600;
}
.pc-ltable-wide td.c-img {
  text-align: center;
}
.pc-img-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  padding: 3px 7px;
  line-height: 1;
}
.pc-img-btn:hover {
  background: var(--bg);
}
/* Hàng "Tổng cộng" */
.pc-ltable-wide tfoot tr.pc-lfoot td {
  border-top: 2px solid var(--line);
  font-weight: 700;
  padding: 8px 6px;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.pc-ltable-wide tfoot tr.pc-lfoot td:first-child {
  text-align: left;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}
input.pc-date {
  cursor: pointer;
}

/* nav group (Danh mục) + children */
.nav-group {
  padding: 12px 12px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--faint);
}
.nav a.nav-child {
  margin-left: 10px;
  padding: 6px 12px;
  font-size: 13px;
}

/* purchase case: view group (Lark Base style) + pill trạng thái Lark sync */
.pc-groups { display: flex; flex-direction: column; gap: 12px; }
.pc-group { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.pc-group-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 14px; background: var(--bg); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.pc-group .pc-ltable { min-width: 0; }
.pc-group .pc-ltable td { padding: 6px 10px; }
.pc-group .pc-ltable tr.pc-lrow:hover td { background: var(--bg); }

.pill.SYNCED { background: var(--ok-bg); color: var(--ok); }
.pill.READY, .pill.PROCESSING { background: var(--warn-bg); color: var(--warn); }
.pill.NOT_QUEUED { background: var(--line); color: var(--muted); }
.pill.BLOCKED { background: var(--err-bg); color: var(--err); }

/* ── Chi tiết phiếu mua hàng — layout đọc như Lark Approval ── */
.la-doc { max-width: 1100px; }
.la-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
}
.la-sec {
  font-size: 13px;
  font-weight: 700;
  color: var(--fg);
  margin: 20px 0 10px;
  padding-left: 8px;
  border-left: 3px solid var(--brand-600, #db2777);
}
.la-row {
  display: flex;
  gap: 16px;
  padding: 7px 0;
  border-bottom: 1px solid var(--bg);
  font-size: 13.5px;
}
.la-label { width: 190px; flex: none; color: var(--muted); }
.la-val { flex: 1; color: var(--fg); }
.la-fields { margin-top: 6px; }
.la-idbox { display: inline-flex; align-items: center; gap: 6px; }
.la-copy {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  padding: 1px 6px;
  line-height: 1.3;
}
.la-copy:hover { background: var(--bg); }
.la-open {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--brand-700, #be185d);
  font-weight: 600;
}
.la-table-wrap { overflow-x: auto; }
table.la-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.la-table th {
  text-align: left;
  background: var(--bg);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.la-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--bg);
  vertical-align: top;
}
table.la-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.la-table tr.la-foot td {
  border-top: 2px solid var(--line);
  border-bottom: 0;
  font-weight: 700;
  background: var(--bg);
}

/* ── Fix căn hàng ô Nguyên vật liệu + đồng bộ input/select bảng dòng hàng với theme ── */
.pc-fincode:empty { display: none; }
.pc-ltable-wide td { vertical-align: middle; }
.pc-ltable-wide td.c-name { vertical-align: middle; }
.pc-ltable-wide td.c-name .combo { display: block; width: 100%; }
.pc-ltable-wide input,
.pc-ltable-wide select,
.pc-ltable-wide .combo > input {
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--panel);
  height: 34px;
}
.pc-ltable-wide select.w-uom { width: 64px; padding: 5px 4px; }
/* section card: viền mảnh sạch như ô ngày (theme Growth OS) */
.pc-section { border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.pc-field input,
.pc-field select {
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
}

/* Đồng bộ mọi ô nhập trong pc-field (Nhà cung cấp/Người thụ hưởng/…) với ô Ngày dự kiến */
.pc-field input:not([type="checkbox"]):not([type="file"]),
.pc-field select,
.pc-field .combo > input {
  height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--panel);
  box-sizing: border-box;
}
.pc-field .combo { width: 100%; }

/* Dòng phiếu bấm được → mở panel chi tiết */
tr.pc-row-click, .pc-group-head.pc-row-click { cursor: pointer; }
tr.pc-row-click:hover td { background: var(--brand-bg); }
.pc-group-head.pc-row-click:hover { background: var(--brand-bg); }
.btn-link {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-sm);
  color: var(--fg-2);
  font-weight: 500;
  background: var(--panel);
}
.btn-link:hover { background: var(--bg); text-decoration: none; }

/* Checkbox trong pc-field: KHÔNG kéo full-width thành card — giữ ô vuông nhỏ */
.pc-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  align-self: flex-start;
  box-sizing: border-box;
}

/* Nút xoá (nguy hiểm) trong panel chi tiết */
button.ghost.danger { color: var(--err); border-color: var(--err-line); }
button.ghost.danger:hover { background: var(--err-bg); color: var(--err); }

/* Thumbnail sản phẩm ở bảng Định mức BOM (ảnh mức biến thể) */
.bom-thumb {
  width: 44px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  display: block;
  background: var(--bg);
}
.bom-thumb-empty { background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 5px, #f3f4f6 5px, #f3f4f6 10px); }

/* Editor định mức: kéo-thả dòng + hộp cảnh báo */
.bom-drag-cell { width: 26px; text-align: center; }
.bom-drag { cursor: grab; color: var(--faint); user-select: none; font-size: 13px; letter-spacing: -2px; }
tr.bom-row.dragging { opacity: 0.45; }
tr.bom-row.drop-target td { border-top: 2px solid var(--brand); }
.bom-warn {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: var(--radius-sm);
  color: var(--warn);
  font-size: 13px;
  line-height: 1.6;
}

/* Ảnh sản phẩm lớn trong panel định mức */
.bom-thumb-lg {
  width: 88px;
  height: 112px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: block;
  background: var(--bg);
  flex: none;
}

/* Product pricing — sửa TẠI CHỖ: mỗi ô là nhãn + input/số đã tính */
.pr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  align-items: stretch;
}
.pr-cell {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pr-cell .pr-k {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.35;
}
.pr-cell .pr-body { margin-top: auto; }
.pr-out {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding: 7px 0;
}
input.pr-in { width: 100%; box-sizing: border-box; text-align: right; }
input.pr-in-pct { max-width: 88px; }
.pr-cell.calc { background: var(--bg); }
.pr-cell.strong { border-color: var(--line-2); }
.pr-cell.strong .pr-out { font-size: 18px; font-weight: 700; }
.pr-cell.accent .pr-body input { color: var(--brand-dark); font-weight: 600; }
/* Ô 3 phần: trước thuế · thuế % · sau thuế */
.pr-taxcell { grid-column: span 2; }
.pr-tax-row {
  display: grid;
  grid-template-columns: 1fr 84px 1fr;
  gap: 8px;
  align-items: end;
}
.pr-sub { font-size: 10px; color: var(--faint); margin-bottom: 3px; text-transform: none; letter-spacing: 0; }
.pr-savebar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
@media (max-width: 720px) { .pr-taxcell { grid-column: span 1; } }

/* Nhãn nhóm vật tư trong danh mục + dấu hiệu "họ nổ theo size" */
.pill.grp-CHAT_LIEU {
  background: #eef4ff;
  color: #2a4d8f;
}
.pill.grp-PHU_LIEU {
  background: #fff6e8;
  color: #8a5a12;
}
.pill.grp-NHAN_BAO_BI {
  background: #fdeef6;
  color: #94255f;
}
.pill.size {
  background: #eef7ee;
  color: #2f6b33;
  margin-left: 6px;
}
.pill.anchor {
  background: #f3eefd;
  color: #5b3aa6;
  margin-left: 6px;
}

/* ── Panel định mức: card sản phẩm (ảnh + thông tin) ── */
.bom-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  margin-bottom: 18px;
}
.bom-card .bom-thumb-lg {
  width: 104px;
  height: 132px;
  flex: 0 0 auto;
}
.bom-card-main {
  flex: 1 1 auto;
  min-width: 0;
}
.bom-card-head {
  display: flex;
  gap: 10px;
  align-items: center;
}
.bom-card-head h1 {
  margin: 0;
  font-size: 20px;
}
.bom-card-sub {
  margin-top: 2px;
  font-size: 13px;
}
/* Thông tin theo CỘT: hàng nhãn trên, hàng giá trị dưới — đọc ngang một nhịp như bảng. */
.bom-card-cols {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 4px 24px;
}
.bom-col-k {
  color: var(--muted);
  font-size: 12px;
}
.bom-col-v {
  font-size: 14px;
  margin-top: 2px;
}
.bom-card-ver {
  margin-top: 10px;
  font-size: 12px;
}

/* ── Chi phí / giá bán: mỗi khoản một DÒNG, tiền dồn về một cột dọc ──
   Cột số rộng bằng cột "Thành tiền" của bảng NVL phía trên → đọc dọc xuống là ra cơ cấu giá. */
.pr-rows {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.pr-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto 180px;
  align-items: center;
  gap: 12px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line);
}
.pr-row:last-child {
  border-bottom: 0;
}
.pr-row-k {
  color: var(--muted);
  font-size: 13px;
}
.pr-row-in {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  justify-self: end;
}
.pr-row-in input {
  width: 104px;
  text-align: right;
}
.pr-pct {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.pr-pct input {
  width: 62px;
}
.pr-row-v {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
/* Ô nhập trong khối chi phí dùng ĐÚNG hộp nhập chuẩn của theme (cùng cao/bo góc/viền với form khác). */
.pr-row-in input {
  height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
}
.pr-row-in input:disabled {
  background: transparent;
  border-color: transparent;
  color: var(--text);
  padding-right: 0;
}
.pr-row-in input:focus {
  outline: none;
  border-color: var(--brand);
}
.pr-row-in input.w-pct {
  width: 64px;
}
/* Sửa TẠI CHỖ cho riêng "Giá bán chính thức" */
.pr-gb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}
.pr-inline-edit {
  display: inline-flex;
  gap: 6px;
}
.pr-iconbtn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 12px;
  cursor: pointer;
  line-height: 1.6;
}
.pr-iconbtn:hover {
  border-color: var(--brand);
}
button.pr-minibtn {
  padding: 4px 10px;
  font-size: 12px;
}
/* Ô nhập trong màn SỬA ĐỊNH MỨC dùng chung cỡ chữ với panel — không để to hơn phần còn lại. */
.pc-section .pr-row input,
.pc-section .pr-row {
  font-size: 13px;
}
.pr-row.calc {
  background: #fafafa;
}
/* Dòng tổng: CÙNG cỡ chữ với các dòng khác, chỉ khác ở chỗ IN ĐẬM — số to hơn làm gãy nhịp đọc dọc. */
.pr-row.strong .pr-row-k,
.pr-row.strong .pr-row-v {
  color: var(--text);
  font-weight: 600;
}
.pr-row.accent .pr-row-in input {
  color: var(--brand);
  font-weight: 600;
}

/* Thanh nút của panel: DÍNH đáy panel. Được như vậy vì .drawer-wide đã cho cuộn bên trong
   (xem trên) — cuộn ở lớp nền thì sticky neo lơ lửng giữa nội dung. */
.la-doc .pc-footer {
  position: sticky;
  bottom: 0;
  margin-top: 22px;
  /* Kéo hết bề ngang panel để nền che nội dung phía sau khi cuộn. */
  margin-left: -22px;
  margin-right: -22px;
  padding-left: 22px;
  padding-right: 22px;
  z-index: 2;
  box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.06);
}

/* Giá bán chính thức nổi bật bằng màu thương hiệu — nó là con số người dùng tìm đầu tiên. */
.pr-row.accent .pr-row-v {
  color: var(--brand);
  font-weight: 600;
}

/* ── Hồ sơ phê duyệt & nhật ký sửa định mức ── */
.bom-log {
  border-left: 2px solid var(--line);
  margin-left: 9px;
  padding-left: 18px;
}
.bom-log-item {
  position: relative;
  padding: 10px 0;
}
.bom-log-item + .bom-log-item {
  border-top: 1px solid var(--line);
}
.bom-log-dot {
  position: absolute;
  left: -28px;
  top: 10px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  background: #eef1f5;
  color: #55606e;
  border: 2px solid #fff;
}
.bom-log-item.approve .bom-log-dot {
  background: #e6f6ec;
  color: #1c7a3e;
}
.bom-log-item.reject .bom-log-dot {
  background: #fdeaea;
  color: #b42318;
}
.bom-log-item.submit .bom-log-dot {
  background: #fff4e5;
  color: #8a5a12;
}
.bom-log-item.create .bom-log-dot,
.bom-log-item.pricing .bom-log-dot {
  background: #fdeef6;
  color: #94255f;
}
.bom-log-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}
.bom-log-time {
  margin-left: auto;
  font-size: 12px;
}
.pill.ver {
  background: #eef4ff;
  color: #2a4d8f;
}
.bom-log-changes {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: var(--text);
}
.bom-log-changes li {
  padding: 1px 0;
}

/* ── Trang Sản xuất ── */
.run-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 4px 0 14px;
}
.run-kpi {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  /* Thẻ là NÚT lọc — phải trông bấm được, và canh trái như text chứ không như nút thường.
     `color` là bắt buộc: button mặc định của theme là chữ TRẮNG, để nguyên thì số trắng trên
     nền trắng, mất hút (đã thấy đúng vậy khi chạy thử). */
  text-align: left;
  font: inherit;
  color: var(--fg);
  cursor: pointer;
  transition: box-shadow .12s, transform .12s;
}
.run-kpi:hover {
  box-shadow: 0 2px 10px rgba(0, 0, 0, .07);
  background: #fff;
  border-color: var(--line);
}
.run-kpi.overdue:hover {
  background: #fdf3f2;
  border-color: #f3c2bd;
}
.run-kpi.overdue-none:hover {
  background: #fbeae8;
  border-color: #e8b4ae;
}
.run-kpi.on {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}
.run-kpi .kpi-sub {
  font-size: 11px;
  opacity: .75;
}
.run-kpi .k {
  color: var(--muted);
  font-size: 12px;
}
.run-kpi .v {
  font-size: 22px;
  font-weight: 600;
  margin-top: 2px;
}
/* Quá hạn / sắp đến hạn phải bật ra ngay — đó là việc cần gọi xưởng hôm nay. */
.run-kpi.overdue {
  border-color: #f3c2bd;
  background: #fdf3f2;
}
.run-kpi.overdue .v {
  color: #b42318;
}
.run-kpi.soon {
  border-color: #f3ddb8;
  background: #fffaf0;
}
.run-kpi.soon .v {
  color: #8a5a12;
}
.pill.due-OVERDUE {
  background: #fdeaea;
  color: #b42318;
  margin-left: 6px;
}
.pill.due-DUE_SOON {
  background: #fff4e5;
  color: #8a5a12;
  margin-left: 6px;
}
.pill.WAITING_RECEIPT {
  background: #eef1f5;
  color: #55606e;
}
.pill.PARTIAL {
  background: #fff4e5;
  color: #8a5a12;
}
.pill.CLOSED {
  background: #f3eefd;
  color: #5b3aa6;
}
.pill.adj {
  background: #fdeef6;
  color: #94255f;
  margin-left: 6px;
}
.run-adj {
  color: var(--brand);
  font-weight: 600;
}
.run-detail-req {
  margin-top: 10px;
}
.run-detail-req summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  padding: 6px 0;
}

/* ── Cấu hình MISA: bố cục theo màn AMIS đội đang dùng ── */
.misa-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 18px 20px;
}
.misa-card h3 {
  margin: 0;
  font-size: 17px;
}
.misa-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}
.misa-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 4px 24px;
  margin-top: 16px;
}
.misa-actions {
  margin-top: 14px;
}
.misa-result {
  margin-top: 10px;
  font-size: 13px;
}
.misa-result.ok {
  color: #1c7a3e;
}
.misa-result.err {
  color: #b42318;
}

/* ---- chứng từ MISA của lệnh sản xuất ---- */
.pill.misa-POSTED {
  background: var(--ok-bg);
  color: var(--ok);
}
.pill.misa-QUEUED {
  background: var(--warn-bg);
  color: var(--warn);
}
.pill.misa-FAILED {
  background: var(--err-bg);
  color: var(--err);
}
.misa-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.misa-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.misa-row:last-child {
  border-bottom: 0;
}
.misa-row-main {
  flex: 1;
  min-width: 0;
}
.misa-row-title {
  font-size: 13px;
  font-weight: 600;
}
.misa-row-hint,
.misa-row-err {
  font-size: 12px;
  margin-top: 2px;
}
.misa-row-state {
  text-align: right;
  font-size: 12px;
  min-width: 110px;
}
.misa-row-act {
  min-width: 140px;
  text-align: right;
  font-size: 12px;
}
.misa-note {
  font-size: 12px;
  margin-top: 8px;
}

.run-kpi.overdue-none {
  border-color: #e8b4ae;
  background: #fbeae8;
}
.run-kpi.overdue-none .v {
  color: #912018;
}
/* ---- chứng từ nhập/trả gộp theo số chứng từ ---- */
.rc-list {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.rc-doc {
  border-bottom: 1px solid var(--line);
}
.rc-doc:last-child {
  border-bottom: 0;
}
.rc-doc > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
}
.rc-doc[open] > summary {
  background: var(--bg);
}
.rc-no {
  font-weight: 600;
}
.rc-meta {
  font-size: 12px;
}
.rc-date {
  margin-left: auto;
  font-size: 12px;
}
.rc-doc .la-table {
  margin: 0 14px 12px;
  width: calc(100% - 28px);
}
.link-btn {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  padding: 0 4px;
}
.link-btn:hover {
  color: var(--err);
}


/* ---- tag giao sớm/muộn ---- */
.due-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.due-tag.late {
  background: var(--err-bg);
  color: var(--err);
}
.due-tag.soon {
  background: var(--warn-bg);
  color: var(--warn);
}
.due-tag.ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.due-nowrap {
  white-space: nowrap;
}

.run-foot-note {
  font-size: 12px;
}

.run-products {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

/* ---- trang hướng dẫn ---- */
.guide-who {
  font-size: 12px;
  color: var(--brand);
  font-weight: 500;
  margin-bottom: 6px;
}
.guide-intro {
  color: var(--fg-2);
  max-width: 72ch;
  margin: 0 0 16px;
  line-height: 1.6;
}
.guide-flow {
  margin: 0 0 22px;
  max-width: 640px;
}
.guide-flow svg {
  width: 100%;
  height: auto;
}
.guide-step {
  margin-bottom: 20px;
  max-width: 72ch;
}
.guide-step h3 {
  font-size: 14px;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.guide-num {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--brand-bg);
  color: var(--brand-dark);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.guide-step p {
  color: var(--fg-2);
  font-size: 13px;
  line-height: 1.65;
  margin: 0 0 6px;
}
.guide-tip {
  font-size: 12.5px;
  color: var(--fg-2);
  background: var(--info-bg);
  border-left: 3px solid var(--info);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
  margin-top: 8px;
  line-height: 1.55;
}
.guide-warn {
  margin-top: 26px;
  padding: 14px 16px;
  border: 1px solid var(--warn-line);
  background: var(--warn-bg);
  border-radius: 10px;
  max-width: 72ch;
}
.guide-warn h3 {
  font-size: 13px;
  margin: 0 0 6px;
}
.guide-warn ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--fg-2);
}

.cfg-advanced {
  grid-column: 1 / -1;
  margin-top: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.cfg-advanced > summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}
.cfg-advanced[open] > summary {
  margin-bottom: 10px;
}

.mono-sm {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
}

/* ---- sort trên header bảng ---- */
th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
}
th.sortable:hover {
  color: var(--fg);
}
th.sortable::after {
  content: '↕';
  margin-left: 5px;
  font-size: 10px;
  opacity: .25;
}
th.sortable[data-sort='asc']::after {
  content: '↑';
  opacity: 1;
  color: var(--brand);
}
th.sortable[data-sort='desc']::after {
  content: '↓';
  opacity: 1;
  color: var(--brand);
}

/* ---- logo ---- */
.side h2.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand-mark {
  flex: 0 0 auto;
  line-height: 0;
}
.brand-mark svg {
  width: 30px;
  height: 30px;
  display: block;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-text b {
  font-size: 14px;
  letter-spacing: .08em;
}
.brand-text > span {
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .14em;
}

/* ---- panel nguyên vật liệu ---- */
.mat-fincode {
  font-weight: 500;
}
.mat-image {
  flex: 0 0 auto;
  width: 190px;
}
.mat-image img {
  width: 190px;
  height: 190px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: block;
}
.mat-image-empty {
  width: 190px;
  height: 190px;
  border-radius: 10px;
  border: 1px dashed var(--line-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
  font-size: 12px;
}
.mat-image-edit {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mat-image-edit input {
  width: 100%;
  box-sizing: border-box;
  font-size: 12px;
}

.toolbar label.chk {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--fg-2);
  cursor: pointer;
}
.toolbar label.chk input {
  margin: 0;
}

/* ---- tồn kho thành phẩm ---- */
.pill.st-out, .run-kpi.st-out .v { color: var(--err); }
.pill.st-out { background: var(--err-bg); }
.run-kpi.st-out { border-color: #f3c2bd; background: #fdf3f2; }
.pill.st-need, .run-kpi.st-need .v { color: var(--warn); }
.pill.st-need { background: var(--warn-bg); }
.run-kpi.st-need { border-color: var(--warn-line); background: var(--warn-bg); }
.pill.st-onorder { background: var(--info-bg); color: var(--info); }
.pill.st-ok { background: var(--ok-bg); color: var(--ok); }
.pill.st-slow { background: var(--line); color: var(--muted); }
.sales-chart svg { width: 100%; height: auto; }

/* Bản tin Lark: giữ nguyên xuống dòng và thụt đầu dòng như lúc gửi đi. */
.digest-preview {
  margin-top: 12px;
  padding: 14px 16px;
  background: var(--panel, #fff);
  border: 1px solid var(--line);
  border-radius: 10px;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.6;
  overflow-x: auto;
}

/* ── công tắc bật/tắt ── */
.switch {
  width: 44px;
  height: 24px;
  padding: 0;
  border-radius: 999px;
  border: none;
  background: #d1d5db;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex: 0 0 auto;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch.on { background: var(--brand, #db2777); }
.switch.on::after { transform: translateX(20px); }
.switch-row { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.digest-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.digest-hour { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.digest-hour select { min-width: 110px; }
button.danger {
  background: #fff;
  color: #e0533d;
  border: 1px solid #f3c8bf;
}

/* ── thẻ "bán tăng đột biến" ở Tổng quan ── */
.spike-head { margin: 18px 0 8px; font-size: 13px; }
.spike-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
}
.spike-card {
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.12s;
}
/* PHẢI khai lại nền: `button:hover` toàn cục đổi sang nền tối, thẻ này nền trắng nên rê chuột
   vào là cả thẻ đen sì, chữ trắng trên trắng. */
.spike-card:hover {
  background: #fff;
  border-color: var(--brand, #db2777);
  transform: translateY(-1px);
}
.spike-card:hover .spike-name { color: var(--text, #0f172a); }
/* Nút mặc định của app là nền tối chữ trắng — thẻ này nền trắng nên phải ép lại màu chữ,
   không thì tên sản phẩm trắng trên nền trắng, nhìn như thẻ trống. */
.spike-name { font-weight: 600; font-size: 13px; color: var(--text, #0f172a); }
.spike-size { font-size: 11px; color: var(--muted); margin-top: 2px; }
.spike-num { margin-top: 8px; display: flex; align-items: baseline; gap: 6px; }
.spike-num .was { color: var(--muted); font-size: 14px; }
.spike-num .arr { color: var(--muted); font-size: 12px; }
.spike-num .now { font-size: 20px; font-weight: 700; color: var(--brand, #db2777); }
.spike-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── danh sách người dùng & phân quyền ── */
.usr-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.usr-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.usr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.usr-row:last-child { border-bottom: none; }
.usr-name { font-weight: 600; font-size: 14px; }
.usr-name-lg { font-weight: 700; font-size: 18px; }
.usr-mail { font-size: 12px; color: var(--muted); margin-top: 2px; }
.usr-right { display: flex; align-items: center; gap: 12px; }
.usr-none { font-size: 12px; }
.pill.role-on { background: #fce7f3; color: #9d174d; }

/* ── nút "?" cạnh tiêu đề + panel hướng dẫn bên phải ── */
.help-btn {
  margin-left: 10px;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}
.help-btn:hover { border-color: var(--brand, #db2777); color: var(--brand, #db2777); }
.help-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(460px, 92vw);
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
  z-index: 60;
  animation: help-in 0.16s ease-out;
}
@keyframes help-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.help-body { padding: 16px 18px 28px; overflow-y: auto; }
.help-body .guide-step h3 { font-size: 14px; }
.help-more { margin-top: 18px; font-size: 13px; }

/* ── hộp xác nhận của OS (thay confirm/alert của trình duyệt) ── */
.confirm-msg { font-size: 14px; line-height: 1.55; }
.confirm-detail {
  margin-top: 8px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
  border-left: 3px solid var(--line);
  padding-left: 10px;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
button.danger-solid { background: #dc2626; color: #fff; border: 1px solid #dc2626; }
button.danger-solid:hover { background: #b91c1c; border-color: #b91c1c; }

/* Cảnh báo FIN-CODE gần trùng, nằm cùng hàng gợi ý dưới dòng hàng. */
.pc-dup {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 2px 8px;
}
.pc-dup.hard { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.pc-dup.soft { color: var(--muted); background: var(--bg); border-color: var(--line); }
/* Mã gợi ý là NÚT bấm được — bấm là điền ngược vào dòng, khỏi gõ lại bốn ô. */
button.pc-dup-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: baseline;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
button.pc-dup-code:hover { background: #fff; }

/* Số phiếu + link mở bên Haravan */
.run-no { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.ext-link { text-decoration: none; font-size: 12px; opacity: 0.55; }
.ext-link:hover { opacity: 1; }
.run-head-actions { margin-left: auto; display: inline-flex; align-items: center; gap: 10px; }

/* ── thanh "Xem như" ── */
.viewas-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #7c2d12;
  color: #fff;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 70;
}
.viewas-bar b { font-weight: 700; }
.viewas-role {
  background: rgba(255, 255, 255, 0.18);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
}
.viewas-note { opacity: 0.75; font-size: 12px; }
.viewas-bar button {
  margin-left: auto;
  background: #fff;
  color: #7c2d12;
  border: none;
  font-size: 12px;
  padding: 4px 12px;
}

/* Ô sửa "Tổng cần xuất" nằm TRONG ô bảng: rộng vừa đủ con số, canh phải như mọi cột số khác.
   Để nó giãn hết bề ngang thì hàng nào cũng thành một hộp to, bảng mất dáng bảng. */
.la-table input.num {
  width: 110px;
  text-align: right;
  padding: 5px 8px;
}

/* Ô lý do trong thanh nút khi đang sửa định mức — chiếm hết chỗ trống bên trái.
   `.totals` vốn chỉ margin-right:auto nên không nở ra; phải cho nó flex thì ô nhập mới đủ rộng
   để đọc được câu mình vừa gõ. */
.pc-footer .totals:has(.run-reason) { flex: 1; min-width: 240px; }
.pc-footer .run-reason { width: 100%; }
