/* =====================================================================
   Check Cơm — CSS dùng chung cho trang check món và trang quản trị.
   Chép nguyên từ Styles.html của bản Apps Script, không đổi một dòng nào:
   giao diện phải giống hệt bản cũ.
   ===================================================================== */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e6e8ec;
  --brand: #f97316;
  --brand-dark: #ea580c;
  --brand-soft: #fff2e7;
  --green: #16a34a;
  --red: #dc2626;
  --blue: #2563eb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}

/* Giao diện sáng cố định — không đổi theo cài đặt tối của máy */
:root { color-scheme: light; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
a { color: var(--brand-dark); }

.wrap { max-width: 760px; margin: 0 auto; padding: 16px 16px 120px; }
.wrap.wide { max-width: 1120px; padding-bottom: 48px; }

/* ---------- Header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0 18px;
}
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }

/* ---------- Card ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }
.label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }

/* ---------- Form ---------- */
input, select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input.inline, select.inline { padding: 6px 8px; border-radius: 8px; font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; min-width: 0; }
.row.tight > * { flex: 0 0 auto; }

/* ---------- Button ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; font: inherit; font-weight: 600; line-height: 1.2;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink);
  cursor: pointer; white-space: nowrap; transition: filter .15s, background .15s;
}
.btn:hover:not(:disabled) { filter: brightness(.97); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-danger { color: var(--red); border-color: var(--line); background: transparent; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-link { background: none; border: none; color: var(--brand-dark); padding: 4px 6px; cursor: pointer; font: inherit; font-weight: 600; }

/* ---------- Danh sách món ---------- */
.dish-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.dish {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--panel); cursor: pointer; transition: all .15s; width: 100%; font: inherit; color: var(--ink);
}
.dish:hover { border-color: var(--brand); }
.dish[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); }
.dish .tick {
  flex: 0 0 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 12px; color: #fff;
}
.dish[aria-pressed="true"] .tick { background: var(--brand); border-color: var(--brand); }
.dish .dname { font-weight: 600; display: block; }
.dish .dprice { color: var(--muted); font-size: 13px; }
.dish .dinfo { min-width: 0; flex: 1 1 auto; }

/* Bộ đếm số lượng cho đồ uống */
.dish .qty { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.dish .qnum { min-width: 16px; text-align: center; font-variant-numeric: tabular-nums; }
.qbtn {
  width: 28px; height: 28px; flex: 0 0 28px; padding: 0; font: inherit; font-size: 17px; line-height: 1;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); cursor: pointer;
}
.qbtn:hover { border-color: var(--brand); }

/* ---------- Thanh xác nhận ---------- */
.submitbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 20px rgba(16, 24, 40, .07);
}
.submitbar .sb-info { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); }
.submitbar .btn { flex: 0 0 auto; }
.submitbar .inner { max-width: 760px; margin: 0 auto; width: 100%; display: flex; align-items: center; gap: 12px; }

/* ---------- Bảng ---------- */
.table-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: rgba(127, 127, 127, .05); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }

/* ---------- Linh tinh ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* white-space: nowrap — chip là viên bo tròn, chữ tràn xuống 3 dòng thì viên
   méo hẳn. Thà để cột rộng ra rồi cuộn ngang còn hơn. */
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--brand-soft); color: var(--brand-dark); white-space: nowrap; }
.chip.gray { background: rgba(127, 127, 127, .14); color: var(--muted); }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab {
  padding: 10px 14px; border: none; background: none; font: inherit; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab.active { color: var(--brand-dark); border-bottom-color: var(--brand); }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(12px);
  background: #16181d; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); opacity: 0; pointer-events: none; transition: all .2s; z-index: 100;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

.center-box { max-width: 380px; margin: 8vh auto; }
.muted { color: var(--muted); }
.sp { height: 10px; }
.nowrap { white-space: nowrap; }
.skeleton { color: var(--muted); padding: 24px 0; text-align: center; }

/* ---------- Trạng thái thanh toán ---------- */
.chip.green { background: rgba(22, 163, 74, .13); color: var(--green); }
.chip.red { background: rgba(220, 38, 38, .12); color: var(--red); }

/* ---------- Hộp thoại ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60; padding: 16px;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .55);
}
.modal.open { display: flex; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.modal-close { background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.amount-big { font-size: 30px; font-weight: 700; text-align: center; color: var(--brand-dark); font-variant-numeric: tabular-nums; margin: 6px 0 2px; }
.qr-wrap { text-align: center; margin: 12px 0 4px; }
.qr-wrap img { width: 100%; max-width: 250px; border-radius: 12px; background: #fff; padding: 8px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); flex: 0 0 auto; }
.kv .v { font-weight: 600; text-align: right; word-break: break-word; }
.warn { background: var(--brand-soft); color: var(--brand-dark); border-radius: 10px; padding: 10px 12px; font-size: 13px; }

/* Tab lịch sử không có thanh xác nhận cố định */
body.tab-history .submitbar { display: none; }
body.tab-history .wrap { padding-bottom: 32px; }

details.day > summary { cursor: pointer; list-style: none; padding: 10px 0; }
details.day > summary::-webkit-details-marker { display: none; }
details.day .day-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
details.day .day-line .d { font-weight: 700; }

/* =====================================================================
   Phần thêm cho bản PHP — tab "Dữ liệu" (nhập/xuất Excel).
   Bản Apps Script không có tab này nên Styles.html cũ không có gì tương ứng.
   ===================================================================== */

/* Ô chọn file cao bằng các ô nhập khác cho thẳng hàng */
input[type="file"] { padding: 8px 12px; cursor: pointer; }
input[type="file"]::file-selector-button {
  margin-right: 10px; padding: 5px 12px; font: inherit; font-weight: 600;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--brand-soft); color: var(--brand-dark); cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--brand); }

/* Danh sách dòng bị bỏ qua — gấp lại cho khỏi chiếm chỗ */
#impResult details > summary { padding: 6px 0; }
#impResult details[open] > summary { margin-bottom: 4px; }
#impResult .warn ul { max-height: 260px; overflow-y: auto; }
#impResult .warn li + li { margin-top: 4px; }

/* Thanh chuyển trang của bảng "Chi tiết từng bữa" (tab Lịch sử) */
.pager {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; flex-wrap: wrap; padding: 14px 0 2px;
}
.pager .hint { font-variant-numeric: tabular-nums; }

/* =====================================================================
   iOS Safari — chặn cú TỰ PHÓNG TO khi chạm vào ô nhập
   ---------------------------------------------------------------------
   Safari trên iPhone tự phóng trang lên khi người dùng chạm vào một ô
   form có font-size DƯỚI 16px, và KHÔNG bao giờ tự thu lại. Trang đang
   ở 428px bỗng bị nhìn qua một khung hẹp hơn, nên thanh "Xác nhận"
   (position: fixed) và các bảng bị cắt mất bên phải — đúng triệu chứng
   "chọn món xong là vỡ giao diện".

   Cả 7 ô của trang đều đang thừa hưởng font-size 15px của body.

   Chỉ nâng lên 16px trên THIẾT BỊ CẢM ỨNG, không đụng tới bản desktop:
   dùng (hover: none) and (pointer: coarse) thay cho max-width vì iPhone
   xoay ngang vẫn rộng 926px mà vẫn dính lỗi này.

   KHÔNG dùng cách "maximum-scale=1, user-scalable=no" trong thẻ viewport:
   nó chặn luôn thao tác chụm tay phóng to của người mắt kém, mà iOS từ
   bản 10 cũng đã bỏ qua không đọc nữa.
   ===================================================================== */
@media (hover: none) and (pointer: coarse) {
  input, select, textarea,
  input.inline, select.inline { font-size: 16px; }
}

/* =====================================================================
   Bảng -> thẻ xếp dọc trên màn hình hẹp  (table.cards)
   ---------------------------------------------------------------------
   Bảng "Tổng nợ theo người" có 5 cột, trên điện thoại phải vuốt ngang mới
   thấy nút Thanh toán — mà đó lại là thứ người dùng cần bấm nhất.

   Dưới 600px mỗi hàng biến thành một thẻ: tên làm tiêu đề, các số xếp
   thành từng dòng "nhãn — giá trị", nút Thanh toán kéo rộng hết thẻ.
   Nhãn lấy từ thuộc tính data-label của từng ô nên không phải dựng markup
   riêng cho mobile: xoay ngang máy là tự trở về dạng bảng.

   Ô KHÔNG có data-label thì không hiện nhãn — dùng cho ô tên (.c-head)
   và ô nút (.c-act).

   600px: mọi điện thoại dựng đứng đều vào dạng thẻ; iPhone xoay ngang
   (926px) vẫn xem dạng bảng vì lúc đó bảng thừa chỗ.
   ===================================================================== */
@media (max-width: 600px) {
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards thead { display: none; }          /* nhãn đã nằm ở data-label */

  table.cards tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    background: var(--panel);
  }
  table.cards tr:last-child { margin-bottom: 0; }
  table.cards tbody tr:hover { background: var(--panel); }   /* bỏ hiệu ứng hover của bảng */

  table.cards td {
    border: none;
    padding: 5px 0;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    text-align: right;
    white-space: normal;
  }
  table.cards td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 auto;
    text-align: left;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
  }

  /* Đầu thẻ: tên người, tách khỏi phần số bằng một đường kẻ */
  table.cards td.c-head {
    display: block;
    text-align: left;
    font-size: 16px;
    padding: 0 0 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
  }

  /* Chân thẻ: nút Thanh toán kéo rộng hết thẻ cho dễ bấm bằng ngón cái */
  table.cards td.c-act { display: block; padding: 10px 0 0; text-align: left; }
  table.cards td.c-act .btn { width: 100%; padding: 10px 16px; font-size: 15px; }

  /* Bảng dạng thẻ không cần vuốt ngang nữa, bỏ luôn phần lề âm.
     Đánh dấu bằng class trên thẻ bao chứ không dùng :has() — Safari chỉ
     hiểu :has() từ bản 15.4, mà máy cũ hơn thì thẻ sẽ tràn ra 16px mỗi bên. */
  .table-scroll.table-cards { overflow-x: visible; margin: 0; padding: 0; }
}

/* =====================================================================
   Ô chọn ngày trên điện thoại  (.f-date)
   ---------------------------------------------------------------------
   <input type="date"> là điều khiển gốc của hệ điều hành, và Safari trên
   iPhone hiển thị nó theo NGÔN NGỮ CỦA MÁY. Máy đặt tiếng Việt thì ra
   "ngày 31 thg 8, 2026" — dài gần gấp đôi "31/08/2026" của Chrome.

   Tệ hơn: ô ngày có chiều rộng tối thiểu bằng đúng đoạn chữ đó và KHÔNG
   co lại được, nên flex-basis 160px của .row không ép nổi. Ô bị đẩy tràn
   ra ngoài thẻ, đúng triệu chứng "Đến ngày" bị cắt mất bên phải.

   Không sửa được cách iOS định dạng (thuộc tính lang của trang không ăn
   thua, iOS lấy theo locale của máy), nên chỉ còn cách cho nó đủ chỗ:
   dưới 600px mỗi ô ngày chiếm trọn một dòng — thừa sức chứa 200px mà
   chuỗi tiếng Việt cần.

   Cũng KHÔNG hạ font-size cho chữ ngắn lại: dưới 16px là iOS lại tự
   phóng to trang, quay về đúng lỗi đã sửa ở phần trên.
   ===================================================================== */
@media (max-width: 600px) {
  .row > .f-date { flex-basis: 100%; }
}
