/* sheet.css - trang so va giay in gia chu */
.sheet {
  direction: rtl;
  display: flex;
  gap: 30px;
  overflow-x: auto;
  padding: 26px;
  background: #f3d51e;
  color: #000;
  border: 2px solid #b89a00;
  min-height: 300px;
}
.grp {
  display: flex;
  gap: 7px;
}
.col {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.sheet i {
  font:
    700 15px/1.3 "Times New Roman",
    "Noto Serif CJK SC",
    SimSun,
    serif;
  font-style: normal;
  direction: ltr;
  display: block;
  white-space: nowrap;
}
.sheetfit {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin: 8px 0;
}
.sheetfit label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  font-size: 12px;
  color: var(--mut);
}
.sheetfit input {
  width: auto;
  padding: 4px 6px;
}
.sheetfit input[type="number"] {
  width: 64px;
}
.big i {
  font-size: 26px;
}
.pd {
  padding-top: 3em;
}
.giatop {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #7a4a21;
  color: #f7ead2;
  padding: 10px 14px;
  border-radius: 10px 10px 0 0;
}
.giatop b {
  flex: 1;
  text-align: center;
  font:
    700 17px "Times New Roman",
    Georgia,
    serif;
  color: #f7ead2;
}
.giatop button {
  background: #fffdf9;
  color: #2b2118;
  border: 1px solid #e0d5c6;
}
.giawrap {
  background: #f6f1ea;
  padding: 18px 14px 30px;
  display: flex;
  justify-content: center;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
}
.giapaper {
  background: #fff;
  color: #14100b;
  width: 100%;
  max-width: 800px;
  min-height: 1000px;
  padding: 52px 48px;
  box-shadow: 0 10px 30px #0002;
  font-family: "Times New Roman", Georgia, serif;
  font-size: 17px;
  line-height: 1.65;
}
.giatitle {
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 24px;
  letter-spacing: 0.5px;
  margin: 0 0 14px;
}
.giayear {
  margin: 10px 0;
  break-inside: avoid;
}
.giayear .gl {
  font-weight: 700;
}
.giasec {
  margin-top: 20px;
  break-inside: auto;
}
.giasec h3 {
  margin: 0 0 8px;
  font-size: 18px;
  color: #7a4a21;
  border-bottom: 1px solid #d9bd93;
  padding-bottom: 4px;
}
.giarow {
  display: flex;
  gap: 10px;
  margin: 6px 0;
  break-inside: avoid;
}
.giarow .gl {
  flex: 0 0 140px;
  font-weight: 700;
}
.giarow .gv {
  flex: 1;
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.giablock {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 6px 0;
  break-inside: avoid;
}
.giaperson {
  margin: 6px 0;
  break-inside: avoid;
}
.giatable {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 2px;
  font-size: 16px;
}
.giatable th,
.giatable td {
  border: 1px solid #d9c7a8;
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}
.giatable thead th {
  background: #f3e7d3;
  font-weight: 700;
}
.giatable .c-stt {
  width: 44px;
  text-align: center;
}
.giatable tbody tr {
  break-inside: avoid;
}
@media (max-width: 600px) {
  .giawrap {
    padding: 10px 8px 20px;
  }
  .giapaper {
    padding: 28px 20px;
    font-size: 16px;
  }
  .giarow .gl {
    flex-basis: 110px;
  }
}

/* === SO PHAT DUONG - to so canvas co dinh 1226x874 (doc tu phai sang trai) ===
   Chi dung cho mau "So Phat Duong" (so-phat-duong.js). KHONG dung flex/grid/
   writing-mode/%/vw de dinh vi chu: moi cot = 1 div absolute, moi TU = 1 dong. */
.sopd-frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  touch-action: pan-x pan-y pinch-zoom;
}
.sopd-scale {
  position: relative;
}
/* To so Phat Duong: MOT CO CHU + MOT TY LE CO NGANG DUY NHAT cho moi tu
   (giong trang mau: font 15px + scaleX(0.75) cho moi .word).
   14px Times New Roman bold, scaleX(0.72) cho TAT CA tu, buoc dong 23px.
   Da tinh: tu rong nhat (~45px) van cach tu cot ke >= 4px, khong cham nhau.
   KHONG doi font-size / scaleX theo tung tu hay tung cot (khong con JS co chu). */
#so-canvas {
  position: relative;
  width: 1226px;
  height: 874px;
  background: #ffff00;
  overflow: hidden;
  transform-origin: top left;
  font: 700 14px/23px "Times New Roman", "Liberation Serif", serif;
  letter-spacing: -0.2px;
  color: #000;
  text-transform: uppercase;
}
.sopd-col {
  position: absolute;
  width: 46px;
  text-align: center;
}
/* Moi tu = 1 dong. Can giua bang flex (justify-content:center) de tu rong hon
   o van lech DEU 2 ben tam cot - text-align:center thuong se de tran hang ve
   ben phai lam tu dai (THUONG, PHUNG...) khong thang hang doc voi tu ngan. */
.sopd-w {
  display: flex;
  justify-content: center;
  width: 46px;
  height: 23px;
  line-height: 23px;
  margin: 0 auto;
  white-space: nowrap;
  overflow: visible;
  transform: scaleX(0.72);
  transform-origin: center;
}

/* === CHE DO CHINH SUA TRUC TIEP (chi man hinh; an het khi in/xuat PDF) === */
.sopd-bar {
  position: sticky;
  top: 6px;
  z-index: 30;
  display: flex;
  flex-wrap: wrap; /* nhom nut tu xuong dong, luon thay Luu/Xong */
  align-items: stretch;
  gap: 8px;
  padding: 8px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  color: var(--ink);
  font: 400 13px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.sopd-grp {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 8px 6px;
  background: var(--bg);
  border-radius: 9px;
}
.sopd-cap {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--mut);
  white-space: nowrap;
}
.sopd-row {
  display: flex;
  gap: 4px;
}
.sopd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  font: inherit;
  font-weight: 600;
  white-space: nowrap;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.sopd-btn:hover:not(:disabled) {
  border-color: var(--acc);
  color: var(--acc);
}
.sopd-btn:active:not(:disabled) {
  transform: translateY(1px);
}
.sopd-btn:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: 1px;
}
.sopd-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.sopd-ic {
  padding: 0;
  width: 34px;
  font-size: 17px;
}
.sopd-primary {
  background: var(--acc);
  border-color: var(--acc);
  color: #fff;
}
.sopd-primary:hover:not(:disabled) {
  color: #fff;
  filter: brightness(1.1);
}
.sopd-danger {
  color: #c62828;
}
.sopd-danger:hover:not(:disabled) {
  background: rgba(198, 40, 40, 0.1);
  border-color: #c62828;
  color: #c62828;
}
/* Nut phu "Huy chinh sua": vien xam, hover chu do nhat; mo khi chua sua. */
.sopd-cancel {
  border-color: #c9c2b8;
  color: #5b554e;
}
.sopd-cancel:hover:not(:disabled) {
  border-color: #c62828;
  color: #e57373;
  background: rgba(198, 40, 40, 0.06);
}
.sopd-cancel:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.sopd-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  order: 2;
}
.sopd-more {
  position: relative;
}
.sopd-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 40;
}
.sopd-menu[hidden] {
  display: none;
}
.sopd-mi {
  display: block;
  width: 100%;
  height: auto;
  padding: 9px 12px;
  text-align: left;
  font-weight: 500;
  border: 0;
  background: none;
}
.sopd-mi:hover:not(:disabled) {
  background: var(--bg);
}
.sopd-info {
  flex: 1 1 180px;
  order: 1;
  align-self: center;
  padding: 0 4px;
  font-size: 12px;
  color: var(--mut);
}
.sopd-status {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  padding: 3px 9px;
  border-radius: 999px;
}
.sopd-status:empty {
  display: none;
}
.sopd-st-dirty {
  color: #c76a00;
  background: rgba(199, 106, 0, 0.12);
}
.sopd-st-saved {
  color: #1a7f37;
  background: rgba(26, 127, 55, 0.12);
}
.sopd-st-error {
  color: #c62828;
  background: rgba(198, 40, 40, 0.12);
}
@media (max-width: 640px) {
  .sopd-bar {
    top: 0;
  }
  .sopd-btn {
    height: 40px;
    min-width: 40px;
  }
  .sopd-ic {
    width: 40px;
  }
  .sopd-right {
    width: 100%;
    margin-left: 0;
    justify-content: flex-end;
  }
}
.sopd-editing .sopd-col {
  cursor: grab;
}
.sopd-editing .sopd-col:hover {
  outline: 1px dashed rgba(0, 0, 0, 0.4);
}
.sopd-editing .sopd-w:hover {
  background: rgba(0, 0, 0, 0.06);
}
.sopd-w.sopd-sel {
  outline: 2px solid #2e7d32;
  outline-offset: -1px;
}
.sopd-col.sopd-colsel {
  outline: 2px solid #1565c0;
}
.sopd-canvas.sopd-add {
  cursor: crosshair;
}
/* Duong gong keo tha cot - vi tri tuyet doi trong canvas, khong in ra PDF */
.sopd-guide {
  position: absolute;
  background: rgba(211, 47, 47, 0.7);
  z-index: 9;
  pointer-events: none;
  display: none;
}
.sopd-guide-h {
  left: 0;
  width: 1226px;
  height: 1px;
}
.sopd-guide-v {
  top: 0;
  width: 1px;
  height: 874px;
}
/* O nhap chu tren khi sua (nam ngoai #so-canvas nen khong anh huong in) */
.sopd-input {
  position: absolute;
  z-index: 12;
  font: 700 13px/1.2 "Times New Roman", Times, serif;
  text-transform: uppercase;
  text-align: center;
  border: 1px solid #2e7d32;
  background: #fffde8;
  padding: 2px 4px;
  width: 100px;
}