:root {
  /* Theme đỏ: giữ tên biến cũ để không ảnh hưởng code đang dùng */
  --green: #a90019;
  --green-2: #c10c21;
  --green-dark: #7b0c14;
  --green-soft: #faf7f6;
  --orange: #e95d17;
  --orange-soft: #fff5ec;
  --line: #e2e0df;
  --line-strong: #d6d2d2;
  --text: #1d2732;
  --muted: #66717d;
  --bg: #ffffff;
  --shadow: 0 2px 10px rgba(89,19,20,.08);

  /* Hai vùng cuộn dọc có chiều cao rõ ràng, không bị ép xuống quá ngắn. */
  --employee-zone-h: 198px;
  --note-zone-h: 132px;
  --summary-card-h: 112px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
html { background: #f1f0f0; }
body {
  overflow: hidden;
  background: #fff;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  display: flex;
  justify-content: center;
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app-shell {
  width: min(100vw, 480px);
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.fixed-block { flex: 0 0 auto; min-width: 0; }

/* ===== Header ===== */
.topbar {
  min-height: 55px;
  padding: calc(6px + env(safe-area-inset-top)) 16px 6px;
  border-bottom: 1px solid #e8e6e6;
  display: grid;
  grid-template-columns: 38px minmax(0,1fr) 38px;
  align-items: center;
  background: #fff;
  z-index: 5;
}
.topbar h1 {
  margin: 0;
  text-align: center;
  color: #4a0f0f;
  font-size: clamp(18px, 5vw, 21px);
  font-weight: 700;
  line-height: 1.2;
}
.top-icon, .profile-button {
  width: 36px;
  height: 36px;
  padding: 5px;
  border: 0;
  background: transparent;
  color: var(--green);
}
.top-icon svg { width: 100%; height: 100%; stroke-width: 2.2; }
.profile-button {
  border: 1.8px solid var(--green);
  border-radius: 50%;
  padding: 6px;
}
.profile-button svg { width: 100%; height: 100%; stroke-width: 1.8; }

/* ===== Thông tin nhận suất ===== */
.receive-info {
  padding: 7px 15px 2px;
  background: #fff;
}
h2 {
  margin: 0;
  color: var(--green);
  font-size: clamp(16px, 4.5vw, 18px);
  line-height: 1.2;
  font-weight: 700;
}
.receive-info > h2 { margin-bottom: 6px; }
.info-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  background: #fff;
}
.info-row {
  min-height: 40px;
  border-top: 1px solid var(--line);
  padding: 0 11px;
  display: flex;
  align-items: center;
}
.info-row:first-child { border-top: 0; }
.split-row {
  display: grid;
  grid-template-columns: 1.08fr .92fr;
  gap: 7px;
}
.picker-field {
  min-width: 0;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 7px;
  position: relative;
  color: #24313d;
}
.picker-field > svg, .row-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  color: var(--green);
  stroke-width: 1.9;
}
.picker-field select,
.department-select-wrap select {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  color: #25313e;
  padding: 0 18px 0 0;
  font-size: 13px;
  cursor: pointer;
}
.chevron {
  position: absolute;
  right: 1px;
  top: 50%;
  transform: translateY(-54%);
  color: #1e2d39;
  pointer-events: none;
  font-size: 19px;
}
.date-field span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
}
.date-field input[type="date"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 10;

  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.department-row {
  display: grid;
  grid-template-columns: 24px 54px minmax(0,1fr);
  gap: 7px;
}
.department-copy {
  color: #4e5b66;
  font-size: 12px;
}
.department-select-wrap {
  min-width: 0;
  height: 40px;
  position: relative;
  display: flex;
  align-items: center;
}
.department-select-wrap select {
  font-size: 13px;
  font-weight: 600;
}
.status-row { justify-content: space-between; gap: 10px; }
.status-label { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.status-pill {
  border: 1px solid #f1c667;
  background: #fff8e8;
  color: #a96a12;
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}
.leader-line {
  margin: 6px 1px 1px;
  display: flex;
  align-items: center;
  gap: 7px;
  color: #3f4d59;
  font-size: 11.5px;
  line-height: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.info-circle {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--green);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--green);
  font-weight: 700;
  font-size: 10px;
  flex: 0 0 auto;
}

/* ===== Tổng hợp suất ăn ===== */
.summary-section {
  /* Tách hẳn khỏi section nhân viên; không dùng margin âm / không chồng lớp. */
  padding: 6px 15px 7px;
  background: #fff;
  overflow: visible;
  z-index: 3;
}
.summary-section h2 { margin-bottom: 6px; }
.summary-scroll {
  display: flex;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  height: calc(var(--summary-card-h) + 6px);
  padding: 0 1px 6px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
  touch-action: pan-x;
  scrollbar-width: none;
}
.summary-scroll::-webkit-scrollbar { display: none; }
.summary-card {
  flex: 0 0 128px;
  height: var(--summary-card-h);
  min-height: var(--summary-card-h);
  border: 1px solid #d5c2c0;
  border-radius: 9px;
  background: linear-gradient(180deg, #fffdfd 0%, #fbf9f8 100%);
  padding: 7px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  /* Bảo đảm góc dưới luôn nằm trong chính card, không bị section kế tiếp đè. */
  position: relative;
  z-index: 1;
}
.menu-two {
  border-color: #f2ba93;
  background: linear-gradient(180deg, #fffdfa 0%, #fff5ed 100%);
}
.summary-title {
  text-align: center;
  color: #821b1e;
  font-size: 12px;
  line-height: 1.28;
}
.summary-title strong { color: #172127; font-weight: 500; }
.menu-two .summary-title { color: #8f3b10; }
.summary-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 5px;
  align-items: end;
}
.summary-content img {
  width: 100%;
  height: 51px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid #dfdddd;
}
.meal-count {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  color: var(--green);
  line-height: 1;
}
.meal-count strong { font-size: 25px; font-weight: 700; }
.meal-count span { margin-top: 5px; font-size: 11px; }
.menu-two .meal-count strong { color: var(--orange); }
.menu-two .meal-count span { color: #111; }
.total-card { align-items: center; justify-content: center; gap: 2px; }
.people-summary-icon { width: 34px; height: 23px; color: var(--green); stroke-width: 2; }
.total-count strong { font-size: 27px; }
.extra-card { justify-content: center; gap: 9px; opacity: .85; }

/* ===== Danh sách nhân viên ===== */
.employees-section {
  height: var(--employee-zone-h);
  min-height: var(--employee-zone-h);
  max-height: var(--employee-zone-h);
  padding: 1px 15px 5px;
  display: grid;
  grid-template-rows: 31px minmax(0,1fr);
  background: #fff;
  overflow: hidden;
  z-index: 2;
}
.section-heading-row {
  min-height: 31px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.heading-actions { display: flex; align-items: center; gap: 3px; }
.round-action {
  width: 32px;
  height: 31px;
  padding: 5px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--green);
}
.round-action svg { width: 100%; height: 100%; stroke-width: 2; }
.filter-action { border: 1px solid #e3e1e0; }
.employees-card {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 1px 6px rgba(0,0,0,.04);
  background: #fff;
  overflow: hidden;
  display: grid;
  grid-template-rows: 27px minmax(0,1fr) 31px;
}
.employee-header {
  display: grid;
  grid-template-columns: 1.18fr .82fr;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  color: #3f4a55;
  font-size: 11.5px;
}
.employee-scroll {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: #d5cecd transparent;
}
.employee-row {
  min-height: 36px;
  padding: 3px 8px;
  display: grid;
  grid-template-columns: 1.18fr .82fr;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid #e9e8e8;
  font-size: 11.5px;
}
.employee-person { min-width: 0; display: flex; align-items: center; gap: 6px; }
.avatar {
  width: 27px;
  height: 27px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #f2ebea;
  color: var(--green);
  display: grid;
  place-items: center;
  font-size: 15px;
}
.employee-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-tag {
  justify-self: start;
  max-width: 100%;
  padding: 4px 6px;
  border: 1px solid #e3d8d7;
  border-radius: 6px;
  background: #f9f5f4;
  color: #a12125;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.05;
}
.menu-tag.orange { border-color: #ffd58c; background: #fff6df; color: #df5616; }
.view-all {
  border: 0;
  border-top: 1px solid #e8e6e6;
  background: #fff;
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
}

/* ===== Xác nhận ===== */
.confirm-panel {
  margin: 3px 15px 5px;
  border: 1px solid #ddd0cf;
  border-radius: 9px;
  background: linear-gradient(90deg, #fffcfc, #fff);
  padding: 6px 9px;
}
.confirm-main {
  display: grid;
  grid-template-columns: 25px minmax(0,1fr);
  gap: 8px;
  align-items: start;
  color: #8d191e;
  font-size: 11.5px;
  line-height: 1.25;
}
.confirm-main input { position: absolute; opacity: 0; pointer-events: none; }
.fake-check {
  width: 23px;
  height: 23px;
  border: 2px solid var(--green);
  border-radius: 4px;
  background: #fff;
  position: relative;
}
.confirm-main input:checked + .fake-check {
  background: var(--green);
}
.confirm-main input:checked + .fake-check::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
}
.confirm-copy { min-width: 0; }
.confirm-copy strong { display: block; font-weight: 700; }
.confirm-copy small { display: block; margin-top: 3px; color: #35434e; font-size: 10.5px; }

/* ===== Ghi chú + ảnh: vùng cuộn dọc riêng ===== */
.note-zone {
  height: var(--note-zone-h);
  min-height: var(--note-zone-h);
  max-height: var(--note-zone-h);
  margin: 0 15px 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  overflow: hidden;
}
.note-scroll {
  height: 100%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 6px 7px 9px;
  scrollbar-width: thin;
  scrollbar-color: #d5cecd transparent;
}
.note-label { display: block; margin: 0 0 4px; font-size: 11.5px; }
.textarea-wrap { position: relative; }
.textarea-wrap textarea {
  width: 100%;
  height: 62px;
  resize: none;
  border: 1px solid #d5d3d2;
  border-radius: 8px;
  outline: 0;
  padding: 8px 9px 20px;
  color: var(--text);
  font-size: 11.5px;
  line-height: 1.35;
}
.textarea-wrap textarea:focus { border-color: #d08e88; box-shadow: 0 0 0 2px rgba(169,0,25,.06); }
.textarea-wrap span {
  position: absolute;
  right: 8px;
  bottom: 6px;
  color: #727d86;
  font-size: 10px;
}
.attachment-title-row {
  margin: 9px 0 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
}
.attachment-title-row span { color: #747d84; }
.attachment-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.attach-btn {
  min-width: 0;
  height: 44px;
  border: 1px dashed #b3a9a8;
  border-radius: 8px;
  background: #fff;
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11.5px;
}
.attach-btn svg { width: 20px; height: 20px; stroke-width: 1.9; flex: 0 0 auto; }
.preview-strip { display: flex; flex-wrap: nowrap; gap: 7px; margin-top: 8px; min-height: 0; }
.preview-item {
  width: 58px;
  height: 58px;
  flex: 0 0 auto;
  border: 1px solid #dddada;
  border-radius: 7px;
  overflow: hidden;
  position: relative;
  background: #f6f5f5;
}
.preview-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 19px;
  height: 19px;
  border: 0;
  border-radius: 50%;
  background: rgba(0,0,0,.66);
  color: #fff;
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 1;
}

/* ===== Nút dưới ===== */
.bottom-actions {
  padding: 0 15px calc(6px + env(safe-area-inset-bottom));
  display: grid;
  gap: 5px;
  background: #fff;
}
.primary-btn, .secondary-btn {
  height: 40px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.primary-btn { border: 0; background: linear-gradient(90deg, #a50018, #c2001e); color: #fff; }
.secondary-btn { border: 1.4px solid var(--green); background: #fff; color: var(--green); }
.button-check, .button-info {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  line-height: 1;
}
.button-check { background: #fff; color: var(--green); }
.button-info { border: 1.5px solid currentColor; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ===== Modal ===== */
.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(42,9,8,.36);
  backdrop-filter: blur(2px);
}
.modal-layer.open { display: grid; }
.modal-card {
  width: min(100%, 360px);
  padding: 18px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 16px 50px rgba(0,0,0,.22);
}
.modal-card h3 { margin: 0 0 12px; color: var(--green-dark); font-size: 18px; }
.modal-input {
  width: 100%;
  height: 44px;
  border: 1px solid #d5d1d1;
  border-radius: 9px;
  outline: 0;
  padding: 0 11px;
  background: #fff;
  color: var(--text);
}
.modal-input:focus { border-color: #d08983; box-shadow: 0 0 0 3px rgba(169,0,25,.08); }
.modal-actions { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modal-actions button { height: 42px; border-radius: 8px; font-weight: 700; }
.modal-secondary { border: 1px solid #d5d1d1; background: #fff; color: #44505a; }
.modal-primary { border: 0; background: var(--green); color: #fff; }

/* ===== Màn hình rất hẹp ===== */
@media (max-width: 370px) {
  :root {
    --employee-zone-h: 186px;
    --note-zone-h: 120px;
    --summary-card-h: 106px;
  }
  .topbar, .receive-info, .summary-section, .employees-section { padding-left: 11px; padding-right: 11px; }
  .confirm-panel, .note-zone { margin-left: 11px; margin-right: 11px; }
  .bottom-actions { padding-left: 11px; padding-right: 11px; }
  .summary-card { flex-basis: 120px; }
  .split-row { grid-template-columns: 1fr 1fr; gap: 4px; }
  .picker-field select, .date-field span, .department-select-wrap select { font-size: 11.5px; }
  .employee-row, .employee-header { grid-template-columns: 1.12fr .88fr; }
}

/* ===== Màn hình thấp: co các vùng cố định nhưng vẫn giữ danh sách nhân viên ở mức sử dụng được ===== */
@media (max-height: 780px) {
  :root {
    --employee-zone-h: 180px;
    --note-zone-h: 112px;
    --summary-card-h: 102px;
  }
  .topbar { min-height: 49px; padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .receive-info { padding-top: 4px; }
  .receive-info > h2, .summary-section h2 { margin-bottom: 4px; }
  .info-row { min-height: 36px; }
  .picker-field, .department-select-wrap { height: 36px; }
  .leader-line { margin-top: 4px; line-height: 15px; }
  .summary-section { padding-top: 4px; padding-bottom: 5px; }
  .summary-content img { height: 45px; }
  .meal-count strong { font-size: 22px; }
  .employees-section { grid-template-rows: 28px minmax(0,1fr); padding-bottom: 4px; }
  .section-heading-row { min-height: 28px; }
  .confirm-panel { margin-top: 2px; margin-bottom: 4px; padding-top: 5px; padding-bottom: 5px; }
  .confirm-copy small { margin-top: 2px; }
  .primary-btn, .secondary-btn { height: 36px; }
}

@media (max-height: 700px) {
  :root {
    --employee-zone-h: 164px;
    --note-zone-h: 98px;
    --summary-card-h: 94px;
  }
  h2 { font-size: 14.5px; }
  .topbar h1 { font-size: 17px; }
  .info-row { min-height: 33px; }
  .picker-field, .department-select-wrap { height: 33px; }
  .picker-field > svg, .row-icon { width: 19px; height: 19px; }
  .leader-line { font-size: 10px; }
  .summary-card { padding: 5px; }
  .summary-title { font-size: 10.5px; }
  .summary-content img { height: 39px; }
  .meal-count strong { font-size: 20px; }
  .meal-count span { font-size: 9.5px; }
  .employee-row { min-height: 31px; font-size: 10.5px; }
  .avatar { width: 24px; height: 24px; }
  .confirm-panel { padding: 4px 7px; }
  .confirm-main { font-size: 10.5px; }
  .confirm-copy small { font-size: 9.5px; }
  .fake-check { width: 21px; height: 21px; }
  .note-scroll { padding-top: 4px; }
  .textarea-wrap textarea { height: 54px; }
  .bottom-actions { gap: 4px; }
  .primary-btn, .secondary-btn { height: 33px; font-size: 11.5px; }
}

/* Desktop chỉ dùng để xem trước; bản thiết kế vẫn là mobile */
@media (min-width: 481px) {
  .app-shell { box-shadow: 0 0 30px rgba(0,0,0,.12); }
}
