/* SPRTCalc — giao diện iPhone. Luôn nền sáng: nhãn của phần mềm gốc ghi màu chữ cố định và ảnh
   công thức là chữ đen trên nền trong suốt, chế độ tối sẽ làm mất chữ. */
:root {
  --chinh: #1f4e8c; --nen: #f2f3f7; --the: #ffffff; --chu: #1c1c1e; --mo: #6c6c70;
  --vien: #d9dae0; --tren: env(safe-area-inset-top, 0px); --duoi: env(safe-area-inset-bottom, 0px);
  --trai: env(safe-area-inset-left, 0px); --phai: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--nen); color: var(--chu); }
body {
  font: 15px/1.42 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; overflow-x: hidden;
}
#dau {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: calc(var(--tren) + 8px) calc(var(--phai) + 12px) 8px calc(var(--trai) + 14px);
  background: var(--chinh); color: #fff;
}
#ten { font-weight: 600; font-size: 17px; }
#trang-thai { flex: 1; font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#nut-menu { background: none; border: 0; color: #fff; font-size: 24px; line-height: 1; min-width: 44px; min-height: 36px; padding: 0; }
#noi-dung {
  padding: calc(var(--tren) + 58px) calc(var(--phai) + 10px) calc(var(--duoi) + 76px) calc(var(--trai) + 10px);
  max-width: 900px; margin: 0 auto;
}
#thanh-tab {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: rgba(250,250,252,.97);
  border-top: 1px solid var(--vien); padding: 4px calc(var(--phai) + 2px) calc(var(--duoi) + 4px) calc(var(--trai) + 2px);
}
#thanh-tab[hidden], #phu-ban-phim[hidden], #lop-phu[hidden], #thong-bao[hidden] { display: none; }
#thanh-tab button {
  flex: 1; background: none; border: 0; color: var(--mo); font-size: 11px; padding: 3px 1px;
  min-height: 48px; display: flex; flex-direction: column; align-items: center; gap: 1px;
}
#thanh-tab button .bt { font-size: 21px; line-height: 1.15; }
#thanh-tab button.chon { color: var(--chinh); font-weight: 600; }

/* --- thẻ · khung --- */
.the { background: var(--the); border-radius: 12px; margin: 0 0 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); overflow: hidden; }
.the > .dau-the {
  display: flex; align-items: center; gap: 6px; padding: 11px 12px; font-weight: 600; font-size: 15px;
  min-height: 44px; color: var(--chinh); user-select: none; -webkit-user-select: none;
}
.the > .dau-the .ten-the { flex: 1; }
.the > .dau-the .mui { color: var(--mo); transition: transform .15s; font-size: 13px; }
.the.thu > .dau-the .mui { transform: rotate(-90deg); }
.the.thu > .ruot { display: none; }
.the > .ruot { padding: 0 12px 12px; }
.w, .dung, .ngang, .luoi { min-width: 0; }
.dung { display: flex; flex-direction: column; gap: 8px; }
.ngang { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ngang > .nhan { flex: 0 1 auto; }
.luoi { display: flex; flex-direction: column; gap: 8px; }
.hang-luoi { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.hang-luoi > .o-nhap { flex: 1 1 120px; }
.cap-o { flex: 1 1 100%; display: flex; align-items: center; gap: 8px; }
.cap-o > .nhan { flex: 0 0 38%; }
.cap-o > .o-nhap { flex: 1 1 auto; width: auto; }
.nhan { min-width: 0; overflow-wrap: anywhere; }
.nhan img { max-width: 100%; height: auto; vertical-align: middle; }
.nhan table { border-collapse: collapse; max-width: 100%; font-size: 13px; }
.nhan th, .nhan td { padding: 4px 5px; border: 1px solid #ccd0d8; vertical-align: top; }
/* ⚠ `.nhan` cho ngắt giữa từ (`anywhere`) để câu dài không tràn. Trong bảng quy tắc đó làm bề rộng tối
   thiểu của cột co về một chữ cái, nên cột đầu bị bẻ thành «Dù / ng / ở». Bảng đã có cuộn ngang
   nên ở đây không ngắt giữa từ, cột tự rộng theo từ dài nhất. */
.nhan table, .nhan th, .nhan td { overflow-wrap: normal; word-break: normal; }
.nhan th:first-child, .nhan td:first-child { min-width: 92px; }
/* cột số canh phải (kết quả từng bước): «-1,29e-04» có dấu trừ nên trình duyệt dám xuống dòng giữa số */
.nhan td[align="right"] { white-space: nowrap; }
.nhan .cuon-bang { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.nhan .cuon-bang table { min-width: 560px; }
.anh-cong-thuc { overflow-x: auto; }
.an { display: none !important; }

/* --- ô nhập · nút: mọi vùng chạm tối thiểu 44 pt, cỡ chữ ≥ 16 px để iOS không tự phóng to --- */
input, select, textarea { font: inherit; font-size: 16px; color: var(--chu); }
.o-nhap, select.chon {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--vien); border-radius: 9px;
  background: #fff; -webkit-appearance: none; appearance: none; min-width: 0;
}
select.chon {
  padding-right: 28px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%236c6c70' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 10px center;
}
.ngang > .o-nhap, .ngang > select.chon { flex: 1 1 130px; width: auto; }
textarea.o-nhap { min-height: 110px; }
.o-nhap:focus, select.chon:focus { outline: 2px solid var(--chinh); outline-offset: -1px; }
button.nut {
  min-height: 44px; padding: 8px 13px; border-radius: 9px; border: 1px solid var(--vien); background: #f7f8fa;
  color: var(--chinh); font: inherit; font-weight: 500; touch-action: manipulation;
}
button.nut:active { background: #e6ecf5; }
button.nut:disabled { opacity: .45; }
button.nut.chu-nho { padding: 8px 6px; min-width: 46px; }
label.tick { display: flex; align-items: center; gap: 9px; min-height: 44px; }
label.tick input { width: 22px; height: 22px; }
.tab-long { display: flex; background: #e4e5ea; border-radius: 9px; padding: 2px; margin-bottom: 10px; }
.tab-long button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 7px; font: inherit; font-size: 14px; min-height: 40px; color: var(--chu); }
.tab-long button.chon { background: #fff; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.14); }

/* --- bảng: cuộn ngang trong khung, cột đầu dính lại để luôn biết đang xem hàng nào --- */
.cuon-bang { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--vien); border-radius: 9px; background: #fff; }
table.bang { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: 14px; }
table.bang th { background: #eef1f6; font-weight: 600; font-size: 12.5px; padding: 6px 7px; text-align: left; border-bottom: 1px solid var(--vien); position: sticky; top: 0; min-width: 78px; }
table.bang td { border-bottom: 1px solid #eceef2; padding: 0; min-width: 78px; vertical-align: middle; }
table.bang td .chi-doc { display: block; padding: 8px 7px; white-space: pre-wrap; }
table.bang td input { width: 100%; min-width: 92px; border: 0; background: transparent; padding: 9px 7px; min-height: 42px; border-radius: 0; }
table.bang td input:focus { outline: 2px solid var(--chinh); outline-offset: -2px; background: #fff; }
table.bang td select.chon { border: 0; border-radius: 0; min-width: 190px; font-size: 14px; }
table.bang tr.dang-chon td { box-shadow: inset 0 0 0 100px rgba(31,78,140,.09); }
table.bang th:first-child, table.bang td:first-child { position: sticky; left: 0; z-index: 1; background: inherit; box-shadow: 1px 0 0 var(--vien); }
table.bang tr { background: #fff; }
table.bang tr.dau { background: #eef1f6; }
.dau-go { color: var(--chinh); border: 1px solid var(--vien); background: #fff; border-radius: 50%; width: 24px; height: 24px; font-size: 13px; line-height: 1; padding: 0; flex: none; }

/* --- thanh phụ phía trên bàn phím: bàn phím số iPhone không có dấu trừ --- */
#phu-ban-phim {
  position: fixed; left: 0; right: 0; z-index: 30; display: flex; gap: 6px; padding: 6px 8px;
  background: #d5d8de; border-top: 1px solid #b4b7bd;
}
#phu-ban-phim button { flex: 1; min-height: 40px; background: #fff; border: 0; border-radius: 7px; font-size: 18px; box-shadow: 0 1px 0 #8e9096; color: var(--chu); }
#phu-ban-phim button.xong { flex: 1.5; color: var(--chinh); font-weight: 600; font-size: 15px; }

/* --- màn hình chờ · lớp phủ · thông báo --- */
#man-cho { position: fixed; inset: 0; z-index: 50; background: var(--nen); display: flex; align-items: center; justify-content: center; padding: 24px; overflow: auto; }
.cho-the { text-align: center; width: 100%; max-width: 420px; }
.cho-the img { border-radius: 16px; }
.cho-the h1 { margin: 10px 0 4px; font-size: 22px; }
#cho-chu { color: var(--mo); }
progress { width: 80%; height: 6px; }
#lop-phu { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.tam {
  background: #fff; width: 100%; max-width: 620px; max-height: 88%; overflow-y: auto; border-radius: 16px 16px 0 0;
  padding: 16px 14px calc(var(--duoi) + 16px);
}
.tam h2 { margin: 0 0 10px; font-size: 18px; }
.tam .ds-nut { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.tam p { margin: 6px 0; }
.ma-may { font: 600 20px/1.3 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 1px; text-align: center; padding: 10px; background: #eef1f6; border-radius: 9px; user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; }
.nguy { color: #b3261e; }
.dat { color: #1a7f37; }
#thong-bao {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--duoi) + 76px); z-index: 45; background: rgba(28,28,30,.93);
  color: #fff; padding: 10px 13px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; max-height: 40%; overflow: auto;
}
.bo-in { position: fixed; inset: 0; z-index: 60; background: #fff; display: flex; flex-direction: column; }
.bo-in iframe { flex: 1; border: 0; width: 100%; }
.bo-in .hang-nut { display: flex; gap: 8px; padding: calc(var(--tren) + 8px) 10px 8px; background: var(--nen); }
.hang-cap-nhat { display: flex; gap: 8px; align-items: center; background: #fff8e1; border: 1px solid #e0b000; border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; }
.hang-cap-nhat span { flex: 1; font-size: 14px; }
