:root {
  /* Theme chuyển từ xanh lá sang đỏ; giữ tên biến cũ để không ảnh hưởng HTML/JS. */
  --green: #d60015;
  --green-dark: #9e0c1b;
  --green-soft: #fbf5f5;
  --orange: #f2a51f;
  --text: #20242a;
  --muted: #6c737d;
  --line: #e1e5e8;
  --panel: #fff;
  --shadow: 0 4px 14px rgba(50, 31, 33, .09);
  --radius: 14px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  background: #f4f0f1;
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app {
  width: min(100%, 480px);
  height: 100dvh;
  margin: 0 auto;
  background: #fff;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  box-shadow: 0 0 30px rgba(0,0,0,.06);
}

.fixed-zone { flex: none; }

.topbar {
  min-height: calc(58px + env(safe-area-inset-top));
  padding: max(10px, env(safe-area-inset-top)) 18px 10px;
  background: linear-gradient(105deg, #ca0a1e, #fd0922);
  color: #fff;
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 6px;
  z-index: 5;
}
.topbar h1 { margin: 0; text-align: center; font-size: 24px; line-height: 1.1; font-weight: 800; }
.icon-btn {
  width: 42px; height: 42px; border: 0; padding: 7px; background: transparent; color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.employee-wrap { padding: 10px 16px 7px; background: #fff; }
.employee-card {
  min-height: 98px;
  padding: 12px 14px;
  border: 1px solid #f1efef;
  border-radius: 15px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
}
.avatar { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.employee-info { min-width: 0; display: grid; gap: 3px; }
.employee-info strong { font-size: 21px; line-height: 1.05; }
.employee-info span { font-size: 16px; color: #42474d; }

.scroll-zone {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding: 5px 16px 10px;
  background: #fff;
}
.scroll-zone::-webkit-scrollbar { display: none; }
.scan-heading { margin: 2px 0 9px; color: #7f252e; font-size: 21px; line-height: 1.2; }

.qr-panel {
  border-radius: 13px;
  min-height: 246px;
  padding: 18px 16px 16px;
  background:
    radial-gradient(circle at 50% 28%, rgba(223, 143, 151, .12), transparent 35%),
    linear-gradient(180deg, #fdf8f9, #f8f0f1);
  border: 1px solid #f4e6e7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
}
.qr-decoration { position: relative; width: 180px; height: 160px; display: grid; place-items: center; }
.qr-symbol { width: 118px; height: 118px; fill: #501e23; }
.qr-symbol .cut { fill: #fdf8f8; }
.corner { position: absolute; width: 34px; height: 34px; border-color: #e9858f; border-style: solid; }
.c1 { left: 0; top: 0; border-width: 5px 0 0 5px; border-radius: 12px 0 0 0; }
.c2 { right: 0; top: 0; border-width: 5px 5px 0 0; border-radius: 0 12px 0 0; }
.c3 { left: 0; bottom: 0; border-width: 0 0 5px 5px; border-radius: 0 0 0 12px; }
.c4 { right: 0; bottom: 0; border-width: 0 5px 5px 0; border-radius: 0 0 12px 0; }
.scan-btn {
  border: 0;
  border-radius: 999px;
  min-height: 44px;
  padding: 9px 22px;
  background: var(--green);
  color: #fff;
  font-size: 17px;
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  box-shadow: 0 5px 12px rgba(214,0,21,.2);
  cursor: pointer;
}
.scan-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.valid-card {
  margin-top: 9px;
  border: 1.5px solid #e1bec1;
  border-radius: 13px;
  background: linear-gradient(100deg, #fffbfc, #fffdfd);
  padding: 12px 13px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.check-badge {
  width: 48px; height: 48px; flex: 0 0 auto; border-radius: 50%;
  background: #f95162; color: #fff; display: grid; place-items: center; margin-top: 4px;
}
.check-badge svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.valid-content { min-width: 0; flex: 1; }
.valid-content > strong { display: block; color: #c20e20; font-size: 18px; margin-bottom: 8px; }
.info-grid { display: grid; grid-template-columns: 1fr 1.2fr; gap: 8px 13px; font-size: 14px; }
.info-grid span { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.info-grid b { color: var(--green); font-size: 18px; width: 20px; text-align: center; }

.meal-card {
  margin-top: 9px;
  border: 1px solid #eae8e8;
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
  background: #fff;
}
.meal-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.meal-title-row h3 { margin: 0; color: #7f252e; font-size: 20px; }
.status-pill { border: 1px solid #efb548; background: #fffaf0; color: #b66f00; border-radius: 8px; padding: 6px 9px; font-size: 13px; white-space: nowrap; }
.meal-layout { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 11px; align-items: stretch; }
.meal-image-wrap { min-width: 0; border-radius: 10px; overflow: hidden; background: #f4f4f4; display: grid; place-items: center; }
.meal-image-wrap img { width: 100%; height: 100%; max-height: 210px; object-fit: contain; display: block; }
.meal-list { margin: 0; min-width: 0; display: grid; align-content: center; }
.meal-list > div { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px; padding: 6px 0; border-bottom: 1px solid #eee; font-size: 13px; }
.meal-list > div:last-child { border-bottom: 0; }
.meal-list dt { font-weight: 700; white-space: nowrap; }
.meal-list dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.warning-card {
  margin: 9px 0 3px;
  border: 1.5px solid #efb54a;
  border-radius: 12px;
  background: #fffaf0;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.warning-icon {
  width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%; border: 3px solid #e8a22b;
  color: #e8a22b; display: grid; place-items: center; font-weight: 850; font-family: Georgia, serif; font-size: 22px;
}
.warning-card p { margin: 0; font-size: 14px; line-height: 1.4; }

.action-dock {
  padding: 7px 16px 8px;
  background: #fff;
  border-top: 1px solid #f0f1f1;
  display: grid;
  gap: 7px;
}
.primary-action, .secondary-action {
  width: 100%; min-height: 46px; border-radius: 8px; font-size: 18px; font-weight: 800;
  display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer;
}
.primary-action { border: 1px solid var(--green); background: linear-gradient(95deg,#d30e22,#f30018); color: #fff; }
.secondary-action { border: 1.5px solid var(--green); background: #fff; color: var(--green); }
.round-check { width: 25px; height: 25px; border-radius: 50%; background: #fff; color: var(--green); display: grid; place-items: center; font-weight: 900; }
.rescan-icon { font-size: 28px; line-height: 1; }
.manual-link { border: 0; background: transparent; color: var(--green); font-weight: 700; font-size: 14px; padding: 1px 0; cursor: pointer; }
.last-receipt {
  border: 0; border-radius: 10px; background: #f4f5f6; min-height: 44px; padding: 8px 10px;
  display: grid; grid-template-columns: 26px 1fr 20px; align-items: center; gap: 5px; color: #394048; text-align: left; cursor: pointer;
}
.last-receipt > span:first-child { color: #6f7781; font-size: 22px; }
.last-receipt > span:nth-child(2) { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.last-receipt b { font-size: 24px; font-weight: 500; color: #111; }

.bottom-nav {
  min-height: calc(64px + env(safe-area-inset-bottom));
  padding: 5px 10px max(5px, env(safe-area-inset-bottom));
  border-top: 1px solid #e7e9e9;
  background: #fff;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
}
.bottom-nav button { border: 0; background: transparent; color: #555d67; display: grid; place-items: center; gap: 1px; cursor: pointer; }
.bottom-nav button span { font-size: 28px; line-height: 1; }
.bottom-nav button small { font-size: 11px; font-weight: 700; }
.bottom-nav button.active { color: var(--green); }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(38,15,18,.48); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.manual-modal {
  width: min(100%, 390px); background: #fff; border-radius: 20px; padding: 24px 20px 20px; box-shadow: 0 22px 60px rgba(0,0,0,.22);
  position: relative; animation: modalIn .18s ease-out;
}
@keyframes modalIn { from { transform: translateY(10px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-x { position: absolute; right: 12px; top: 10px; width: 34px; height: 34px; border: 0; background: #f4f2f2; border-radius: 50%; font-size: 23px; cursor: pointer; }
.modal-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-size: 28px; font-weight: 900; margin-bottom: 12px; }
.manual-modal h2 { margin: 0 0 7px; color: #821e28; font-size: 24px; }
.manual-modal p { margin: 0 0 17px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.manual-modal label { display: block; font-weight: 750; margin-bottom: 7px; }
.manual-modal input { width: 100%; height: 48px; border: 1.5px solid #d9d0d1; border-radius: 10px; padding: 0 13px; outline: none; font-size: 16px; }
.manual-modal input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(214,0,21,.1); }
.modal-actions { margin-top: 18px; display: grid; grid-template-columns: 1fr 1.25fr; gap: 10px; }
.modal-actions button { min-height: 46px; border-radius: 10px; font-weight: 800; cursor: pointer; }
.modal-cancel { border: 1px solid #d8d0d1; background: #fff; color: #4c4344; }
.modal-confirm { border: 1px solid var(--green); background: var(--green); color: #fff; }

.toast {
  position: fixed; z-index: 80; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 16px);
  max-width: calc(100vw - 40px); background: #5c242a; color: #fff; border-radius: 999px; padding: 10px 16px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .18s ease; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 390px) {
  .employee-wrap, .scroll-zone, .action-dock { padding-left: 12px; padding-right: 12px; }
  .topbar h1 { font-size: 22px; }
  .avatar { width: 64px; height: 64px; }
  .employee-card { min-height: 88px; padding: 10px 12px; }
  .employee-info strong { font-size: 19px; }
  .employee-info span { font-size: 14px; }
  .scan-heading { font-size: 19px; }
  .info-grid { font-size: 12px; gap: 7px; }
  .meal-title-row h3 { font-size: 18px; }
  .meal-list > div { font-size: 12px; }
}

@media (max-height: 760px) {
  .topbar { min-height: calc(52px + env(safe-area-inset-top)); padding-bottom: 7px; }
  .topbar h1 { font-size: 21px; }
  .employee-wrap { padding-top: 7px; padding-bottom: 5px; }
  .employee-card { min-height: 80px; padding: 8px 11px; }
  .avatar { width: 58px; height: 58px; }
  .employee-info strong { font-size: 18px; }
  .employee-info span { font-size: 13px; }
  .action-dock { gap: 5px; padding-top: 5px; padding-bottom: 6px; }
  .primary-action, .secondary-action { min-height: 40px; font-size: 16px; }
  .last-receipt { min-height: 38px; padding-top: 5px; padding-bottom: 5px; }
  .bottom-nav { min-height: calc(56px + env(safe-area-inset-bottom)); }
  .bottom-nav button span { font-size: 24px; }
  .bottom-nav button small { font-size: 10px; }
}

@media (max-height: 650px) {
  .employee-wrap { padding-top: 5px; padding-bottom: 4px; }
  .employee-card { min-height: 70px; }
  .avatar { width: 50px; height: 50px; }
  .employee-info { gap: 1px; }
  .employee-info strong { font-size: 16px; }
  .employee-info span { font-size: 12px; }
  .manual-link { font-size: 12px; }
  .last-receipt { display: none; }
  .action-dock { padding-bottom: 5px; }
}
