/* ================================================================
   SKYPEC — CSS RIÊNG CHO ĐIỆN THOẠI  (chỉ nạp khi màn hình ≤ 767px)
   • Điều hướng nằm ở ĐÁY màn hình (thanh tab).
   • Mọi danh sách xếp 1 cột, dạng thẻ — tránh cuộn ngang.
   • Nhật ký nhập-xuất & lưới nhập nhiều món: bảng → thẻ xếp dọc.
   ================================================================ */

@media (max-width: 350px) { html { font-size: 14px; } }

body { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + .5rem); }

main {
  max-width: 640px;
  padding: .75rem var(--gutter) 1rem;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

.topbar {
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}
@media (max-width: 420px) { .user-name { display: none; } }

/* ---------- Thanh tab cố định đáy ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(16, 24, 40, .05);
}
.tab {
  flex: 1 1 0; flex-direction: column; gap: 3px;
  padding: .3rem .1rem;
  font-size: clamp(.6rem, 2.6vw, .72rem);
}
.tab .ic { width: 22px; height: 22px; }
.tab.active::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%;
  height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
}

/* ---------- Lưới KPI ---------- */
.kpi-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* ---------- Bố cục nhỏ: dồn 1 cột ---------- */
@media (max-width: 380px) {
  .filter-panel, .filters-inline, .field-row { grid-template-columns: 1fr; }
}
@media (max-width: 340px) { .detail-grid { grid-template-columns: 1fr; } }

/* ---------- Kho: thẻ thu gọn 2 dòng, bấm để mở ---------- */
#khoCards { gap: .45rem; }
.kho-card { padding: .6rem .7rem; cursor: pointer; }
.kho-card .kho-head { align-items: center; gap: .55rem; margin-bottom: 0; }
.kho-card .kho-name { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kho-card .kho-code { display: none; }
.kho-chips { display: flex; gap: .6rem; margin-top: .15rem; font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; }
.kchip { display: inline-flex; align-items: center; gap: .25rem; }
.kchip .dot { width: 7px; height: 7px; }
.kchip b { color: var(--text); font-variant-numeric: tabular-nums; }
.kchip.zero b { color: var(--fail); }
.kho-card .kho-total { min-width: 42px; padding: .18rem .4rem; }
.kho-card .kho-total strong { font-size: 1.1rem; }
.kho-card .kho-total span { display: none; }
.kho-chev { display: inline-flex; color: var(--muted); transition: transform .15s; }
.kho-card.open .kho-chev { transform: rotate(180deg); }
.kho-card .kho-more { display: none; margin-top: .6rem; cursor: default; }
.kho-card.open .kho-more { display: block; }
.kho-card.open .kho-name { white-space: normal; }
.kho-card.open .kho-code { display: inline-flex; }

/* ================================================================
   NHẬT KÝ NHẬP - XUẤT: bảng → thẻ xếp dọc (không cuộn ngang)
   ================================================================ */
#logTableWrap { background: none; border: 0; box-shadow: none; overflow: visible; }
#logTable, #logTable tbody { display: block; }
#logTable thead { display: none; }

#logTable tr {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .65rem .85rem .7rem;
  margin-bottom: .55rem;
}
#logTable tr.in  { border-left-color: var(--ok); }
#logTable tr.out { border-left-color: var(--fail); }

#logTable td {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .26rem 0; border: 0;
  font-size: .88rem;
}
#logTable td::before {
  content: attr(data-label);
  color: var(--muted); font-weight: 600; font-size: .76rem;
  flex: 0 0 auto;
}
/* STT: ẩn cho gọn */
#logTable td.col-stt { display: none; }
/* Tên thiết bị: làm tiêu đề thẻ */
#logTable td.cell-name {
  display: block; order: -1;
  font-size: 1rem; font-weight: 700; line-height: 1.3;
  padding: 0 0 .5rem; margin-bottom: .4rem;
  border-bottom: 1px solid var(--line);
}
#logTable td.cell-name::before { display: none; }
/* Ghi chú trống: ẩn dòng */
#logTable td.cell-note:empty { display: none; }
#logTable td.col-qty strong { font-size: 1.05rem; }
/* Nút xoá: xuống cuối, full dòng */
#logTable td.col-act {
  justify-content: flex-end;
  padding-top: .55rem; margin-top: .35rem;
  border-top: 1px solid var(--line);
}
#logTable td.col-act::before { display: none; }
.row-del .row-del-txt { display: inline; }

/* ================================================================
   MODAL NHẬP NHIỀU MÓN: lưới → thẻ mini-form mỗi món
   ================================================================ */
.entry-wrap { max-height: none; overflow: visible; }
.table-wrap.entry-wrap { background: none; border: 0; box-shadow: none; }
#entryTable, #entryTable tbody { display: block; }
#entryTable thead { display: none; }

#entryTable tr.entry-row {
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr; gap: .55rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem .7rem .7rem;
  margin-bottom: .6rem;
}
#entryTable td { display: block; padding: 0; border: 0; grid-column: span 2; }
#entryTable td::before {
  content: attr(data-label);
  display: block; font-size: .72rem; color: var(--muted);
  font-weight: 600; margin-bottom: .25rem;
}
/* Số lượng + Khu vực: nằm cạnh nhau */
#entryTable td.col-qty    { grid-column: span 1; }
#entryTable td.col-region { grid-column: span 1; }
/* Số thứ tự: huy hiệu nhỏ góc trên */
#entryTable td.idx {
  position: absolute; top: .5rem; right: .6rem;
  min-width: 1.4rem; text-align: center;
  padding: .05rem .45rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: .72rem; color: var(--muted);
}
#entryTable td.idx::before { display: none; }
/* Nút xoá dòng: full width ở cuối */
#entryTable td.col-act::before { display: none; }
#entryTable td.col-act .row-del {
  width: 100%; height: 40px; justify-content: center;
}
#entryTable .row-del .row-del-txt { display: inline; }

/* ---------- Modal: bottom-sheet ---------- */
.modal { align-items: flex-end; }
.modal-box {
  max-height: 92vh; max-height: 92dvh;
  border-radius: 18px 18px 0 0;
  padding: 1.1rem var(--gutter) calc(1rem + env(safe-area-inset-bottom));
  animation: sheet .22s ease;
}
.modal-box::before {
  content: ""; display: block;
  width: 40px; height: 4px; border-radius: 4px;
  background: var(--line-2); margin: -.3rem auto .85rem;
}
@keyframes sheet { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ---------- Toast nằm trên thanh tab ---------- */
.toast { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + .75rem); }

/* ---------- Bảng xem trước Nhập sự cố → thẻ ---------- */
#previewTable thead { display: none; }
#previewTable, #previewTable tbody { display: block; }
#previewTable tr {
  display: grid; grid-template-columns: 1fr auto; gap: .4rem;
  padding: .7rem; margin-bottom: .55rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2);
}
#previewTable td { display: block; padding: 0; border: 0; min-width: 0; }
#previewTable td:nth-child(1) { grid-column: 1; }
#previewTable td:nth-child(5) { grid-column: 2; grid-row: 1; align-self: center; }
#previewTable td:nth-child(2),
#previewTable td:nth-child(3),
#previewTable td:nth-child(4) { grid-column: 1 / -1; }
#previewTable td:nth-child(1) input { font-weight: 700; }
#previewTable td[colspan] { grid-column: 1 / -1; }
