/* HomeMeal (สไตล์ร่วมกับ HomeShift) — mobile-first, ไฟล์เดียว, self-contained (ไม่มี font/asset ภายนอก) */
:root {
  --green: #059669;
  --green-2: #10b981;
  --green-dark: #047857;
  --red: #e11d48;
  --red-2: #f43f5e;
  --yellow: #f59e0b;
  --yellow-bg: #fef3c7;
  --yellow-ink: #92400e;
  --blue: #4f46e5;
  --blue-2: #6366f1;
  --ink: #0f172a;
  --muted: #64748b;
  --bg: #eef1f6;
  --card: #ffffff;
  --line: #e2e8f0;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 6px 18px rgba(15, 23, 42, .06);
  --shadow-lg: 0 4px 10px rgba(15, 23, 42, .08), 0 14px 34px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }
::selection { background: #c7d2fe; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", "Leelawadee UI", sans-serif;
  font-size: 17px;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 100% -50px, #e0e7ff66, transparent 60%),
    radial-gradient(900px 420px at -10% -80px, #d1fae566, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.55;
}

.container { max-width: 880px; margin: 0 auto; padding: 14px 16px 64px; }

h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.01em; margin: 16px 0 12px; }
h2 { font-size: 1.02rem; font-weight: 700; margin: 2px 0 12px; color: #334155; }
small, .hint { color: var(--muted); }
.hint { font-size: .88rem; margin: 6px 0; }
.muted { color: var(--muted); }
.center { text-align: center; }
code {
  background: #eef2f7; border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 6px; font-size: .88em;
}
a { color: var(--blue); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .86);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 8px;
}
.brand {
  font-weight: 800; font-size: 1.05rem; letter-spacing: -.01em;
  padding-bottom: 6px;
}
.mainnav {
  display: flex; align-items: center; gap: 2px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; margin: 0 -16px; padding: 0 12px 6px;
}
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
  color: #475569; text-decoration: none; white-space: nowrap;
  padding: 7px 13px; border-radius: 999px; font-size: .92rem; font-weight: 600;
}
.mainnav a:hover { background: #eef2f7; color: var(--ink); }
.mainnav a.active { background: var(--ink); color: #fff; }
.mainnav form { margin-left: auto; }
.linkbtn {
  background: none; border: none; padding: 7px 13px; cursor: pointer;
  font-family: inherit; font-size: .92rem; font-weight: 600;
  color: var(--muted); white-space: nowrap; border-radius: 999px;
}
.linkbtn:hover { background: #eef2f7; color: var(--ink); }
.linkbtn.danger { color: var(--red); }
.linkbtn.danger:hover { background: #ffe4e6; }

/* ---------- cards / layout ---------- */
.card {
  background: var(--card);
  border: 1px solid #eaeef4;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 14px 0;
}
.center-card { text-align: center; padding: 40px 18px; }
.bigicon { font-size: 3rem; line-height: 1; }
.bigicon.err { color: var(--red); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row-links { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.inline { display: inline; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; margin: 0; }
legend { font-weight: 700; font-size: .95rem; padding: 0 8px; color: #334155; }

/* ---------- forms ---------- */
label { display: block; font-size: .92rem; font-weight: 600; color: #334155; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"],
input[type="time"], input[type="datetime-local"], input[type="file"], select, textarea {
  width: 100%;
  padding: 12px 14px;
  margin-top: 6px;
  font-size: 1.02rem;
  font-weight: 400;
  font-family: inherit;
  color: var(--ink);
  border: 1.5px solid #dbe2ea;
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue-2);
  box-shadow: 0 0 0 3px #6366f126; background: #fff;
}
.form-row input, .form-row select { width: auto; min-width: 140px; }
.checkline {
  display: flex; align-items: center; gap: 12px; padding: 8px 0;
  font-weight: 500; color: var(--ink); cursor: pointer;
}
.checkline input {
  width: 22px; height: 22px; margin: 0; flex-shrink: 0; accent-color: var(--green);
}
.weekday-row { display: flex; flex-wrap: wrap; gap: 0 20px; }

/* ---------- buttons (ปุ่มหลักสูง ≥ 48px) ---------- */
.btn {
  display: inline-block;
  min-height: 48px;
  padding: 13px 22px;
  font-size: 1.02rem;
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  color: #fff;
  background: var(--blue);
  box-shadow: var(--shadow);
  transition: transform .06s, filter .15s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(180deg, var(--blue-2), var(--blue)); }
.btn-success { background: linear-gradient(180deg, var(--green-2), var(--green)); }
.btn-danger { background: linear-gradient(180deg, var(--red-2), var(--red)); }
.btn-secondary {
  background: #fff; color: var(--ink);
  border: 1.5px solid #dbe2ea; box-shadow: none; font-weight: 600;
}
.btn-secondary:hover { background: #f8fafc; filter: none; }
.btn-big { width: 100%; font-size: 1.12rem; }
.btn-huge {
  width: 100%; min-height: 84px; font-size: 1.65rem; margin-top: 14px;
  border-radius: 20px; box-shadow: var(--shadow-lg); letter-spacing: .02em;
}

/* ---------- flash ---------- */
.flash {
  padding: 13px 16px; border-radius: var(--radius-sm); margin: 12px 0;
  font-weight: 600; font-size: .96rem; border: 1px solid transparent;
}
.flash-ok { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.flash-warn { background: var(--yellow-bg); color: #78350f; border-color: #fde68a; }
.flash-error { background: #fff1f2; color: #9f1239; border-color: #fecdd3; }

/* ---------- badges (เหลือง = ป้ายกำกับ) ---------- */
.badge {
  display: inline-block; padding: 3px 11px; border-radius: 999px;
  font-size: .78rem; font-weight: 700; background: #eef2f7; color: #475569;
  vertical-align: middle;
}
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-warn { background: var(--yellow-bg); color: var(--yellow-ink); }

/* ---------- login ---------- */
.login-card { max-width: 430px; margin: 28px auto; padding: 24px 20px; }
.login-card h1 { text-align: center; margin: 4px 0 18px; }
.user-list { display: flex; flex-direction: column; gap: 10px; }
.user-pick {
  display: flex; align-items: center; gap: 14px;
  border: 1.5px solid #dbe2ea; border-radius: 14px; padding: 12px 14px;
  font-size: 1.08rem; font-weight: 600; cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.user-pick .avatar {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 999px; flex-shrink: 0;
  background: linear-gradient(135deg, #c7d2fe, #a5b4fc);
  color: #3730a3; font-weight: 800; font-size: 1.15rem;
}
.user-pick:has(input:checked) {
  border-color: var(--blue-2); background: #eef2ff;
  box-shadow: 0 0 0 3px #6366f11f;
}
.user-pick input { width: 20px; height: 20px; margin-left: auto; accent-color: var(--blue); }
.pin-input {
  text-align: center; font-size: 1.7rem !important; letter-spacing: .45em;
  border-radius: 14px !important;
}
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  justify-items: center; padding: 4px 6px;
}
.keypad button {
  width: 74px; height: 74px; border-radius: 999px;
  font-size: 1.5rem; font-weight: 600; font-family: inherit; color: var(--ink);
  border: none; background: #f1f5f9; cursor: pointer;
  transition: transform .06s, background .12s;
}
.keypad button:active { transform: scale(.93); background: #e2e8f0; }
.no-js-hide { display: none; }
.js .no-js-hide { display: grid; }

/* ---------- stats / tables ---------- */
.month-nav {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  margin: 14px 0;
}
.month-nav strong { font-size: 1.05rem; }
.month-nav .btn { min-height: 42px; padding: 9px 16px; font-size: .92rem; }
.stat-row { display: flex; flex-wrap: wrap; gap: 12px; }
.stat { flex: 1 1 190px; margin: 0; padding: 16px 18px; }
.stat-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.stat-value {
  font-size: 1.65rem; font-weight: 800; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; margin-top: 2px;
}
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .94rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
th {
  font-size: .76rem; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; white-space: nowrap;
}
tbody tr:hover td { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
tr.inactive td { opacity: .45; }
.row-actions { white-space: nowrap; }
.row-actions a { font-weight: 600; text-decoration: none; }
.dash-user { padding: 10px 0; border-bottom: 1px solid #f1f5f9; }
.dash-user:last-child { border-bottom: none; }
.dash-user strong { font-size: 1.05rem; margin-right: 6px; }
.flag-row { padding: 9px 0; border-bottom: 1px solid #f1f5f9; font-size: .94rem; }
.flag-row:last-child { border-bottom: none; }
.flag-row a { font-weight: 600; }

@media (max-width: 480px) {
  body { font-size: 16px; }
  .stat { flex-basis: 140px; }
  .form-row input, .form-row select { width: 100%; }
  .keypad button { width: 68px; height: 68px; }
}

/* ================= HomeMeal ================= */
.who { font-weight: 600; color: var(--muted); font-size: .85rem; }
.greet { margin-top: 20px; font-size: 1.35rem; }
.chip {
  display: inline-block; background: #eef2f7; border-radius: 999px;
  padding: 3px 11px; margin: 2px 2px; font-size: .84rem; font-weight: 500;
}
.btn-sm { min-height: 38px; padding: 8px 14px; font-size: .9rem; border-radius: 11px; }
ul.plain { margin: 0; padding-left: 20px; }
.w-sort { width: 74px !important; min-width: 0 !important; }

/* หน้าแรก: รายการวัน */
.day-list { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.day-row {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "date state" "meals meals";
  gap: 6px 10px; align-items: center;
  background: var(--card); border: 1px solid #eaeef4; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; text-decoration: none; color: var(--ink);
}
.day-row:hover { border-color: #c7d2fe; }
.day-row.locked { background: #f8fafc; }
.day-date { grid-area: date; }
.day-meals { grid-area: meals; display: flex; gap: 6px; flex-wrap: wrap; }
.day-state { grid-area: state; font-size: 1.1rem; }
.todo { font-size: .85rem; font-weight: 700; color: var(--yellow-ink); background: var(--yellow-bg); padding: 3px 10px; border-radius: 999px; }
.meal-pill { font-size: .82rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.pill-ok { background: #d1fae5; color: #065f46; }
.pill-skip { background: #eef2f7; color: #64748b; }
.pill-none { background: var(--yellow-bg); color: var(--yellow-ink); }

/* ฟอร์มเลือกอาหาร */
.meal-card { padding: 14px 16px; }
.meal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.meal-head h2 { margin: 0; font-size: 1.12rem; color: var(--ink); }
.skip-toggle { display: flex; align-items: center; gap: 6px; font-weight: 600; color: var(--muted); cursor: pointer; }
.skip-toggle input { width: 20px; height: 20px; accent-color: var(--red); }
.meal-card.is-skipped .meal-body { opacity: .35; pointer-events: none; }
.slot { padding: 12px 0; border-bottom: 1px dashed #e2e8f0; }
.slot:last-of-type { border-bottom: none; }
.slot-label { font-size: .85rem; color: var(--muted); }
.slot select { margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.chips-label { font-size: .8rem; color: var(--muted); font-weight: 700; min-width: 34px; }
.chip-opt { display: inline-block; cursor: pointer; font-weight: 500; }
.chip-opt input { position: absolute; opacity: 0; pointer-events: none; }
.chip-opt span {
  display: inline-block; padding: 7px 14px; border-radius: 999px;
  border: 1.5px solid #dbe2ea; background: #fff; font-size: .95rem;
}
.chip-opt input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 700; }
.chip-opt input:focus-visible + span { box-shadow: 0 0 0 3px #6366f140; }
.chip-opt.hidden, .chips.hidden, .custom-input.hidden { display: none; }
.js .custom-input.js-hide { display: none; }
.custom-input { border-style: dashed !important; }
.portion-row .chip-opt span { padding: 4px 11px; font-size: .84rem; }
.note-field { margin-top: 10px; }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 20; display: flex; gap: 8px;
  padding: 12px 0 14px; background: linear-gradient(transparent, var(--bg) 30%);
}
.sticky-actions .btn-big { flex: 1; width: auto; }
.sticky-actions .btn-secondary { flex: 0 1 auto; font-size: .9rem; padding: 10px 12px; }
.flash ul { margin: 6px 0 0; padding-left: 20px; font-weight: 500; }

/* admin */
.form-row.compact { margin: 6px 0; }
.form-row.compact .checkline { padding: 0; }
.dish-row {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid #f1f5f9;
}
.dish-row input[type="text"], .dish-row input[type="password"], .dish-row select { width: auto; min-width: 150px; margin-top: 0; padding: 8px 10px; font-size: .95rem; }
.dish-row input[type="number"] { margin-top: 0; padding: 8px 10px; }
.form-row.compact input, .form-row.compact select { margin-top: 0; padding: 8px 10px; }
.opt-group { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: .88rem; }
label.mini { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; font-size: .88rem; }
label.mini input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--blue); }
.add-row { background: #f8fafc; border-radius: 12px; padding: 10px; border: 1px dashed #cbd5e1; margin-top: 8px; }
.inactive { opacity: .5; }

/* ใบสรุปแม่ครัว */
.sheet-head h1 { margin: 6px 0 2px; }
.sheet-sub { font-weight: 600; color: #334155; }
.sheet-box {
  background: var(--card); border: 1px solid #e2e8f0; border-radius: var(--radius-sm);
  padding: 12px 14px; margin: 12px 0; break-inside: avoid;
}
.sheet-box h2 { margin: 0 0 8px; color: var(--ink); }
.sheet-box.is-done { opacity: .6; }
.sheet-box .count { color: var(--muted); font-weight: 600; }
.prep { border: 2px solid var(--ink); }
.prep-list { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 1.1rem; }
.meal-grid { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 760px) { .meal-grid { grid-template-columns: repeat(3, 1fr); } }
table.tally td { padding: 4px 6px; font-size: 1.02rem; border: none; }
table.tally td.num, table.week td.num { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
table.tally td.por { font-size: .82rem; color: var(--muted); }
.warn-line { color: var(--yellow-ink); font-weight: 600; font-size: .9rem; margin: 6px 0 0; }
table.people td { font-size: .9rem; }
table.people .who { min-width: 110px; }
.allergy { color: var(--red); font-weight: 700; font-size: .82rem; }
.pnote { color: #92400e; font-size: .82rem; }
.edit-link { font-size: .78rem; font-weight: 600; }
.toggle-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip-btn {
  border: 1.5px solid #dbe2ea; background: #fff; border-radius: 999px; padding: 6px 12px;
  font-family: inherit; font-size: .9rem; cursor: pointer;
}
.chip-btn.off { background: #fff1f2; border-color: #fecdd3; color: #9f1239; text-decoration: line-through; }

@media print {
  @page { size: A4; margin: 10mm; }
  .no-print, .topbar, .flash, .edit-link { display: none !important; }
  .sheet-head .flash { display: block !important; }
  body { background: #fff; font-size: 11pt; }
  .container { max-width: none; padding: 0; }
  .sheet-box { box-shadow: none; margin: 6px 0; padding: 8px 10px; }
  .meal-grid { grid-template-columns: repeat(3, 1fr); }
  .sheet-head h1 { font-size: 16pt; }
  table.people td, table.people th { padding: 4px 6px; }
  tbody tr:hover td { background: none; }
  a { color: inherit; text-decoration: none; }
}
