:root {
  --bg: #F6F5F1; --card: #FFFFFF; --line: #E4E2DB; --line2: #D9D6CE; --soft: #F1EFE9;
  --text: #1F2421; --muted: #5C635E; --accent: #2E7D57; --accent-dark: #1F5A3E; --accent-soft: #EAF4EE;
  --make: #1D5FB0; --red: #E03A2F; --gray-band: #A8A49A; --warm: #FFF6EC; --warm-line: #F1D9BD; --warm-text: #6B4A2B;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: Pretendard, 'Noto Sans KR', system-ui, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font-family: inherit; font-size: 15px; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.muted { color: var(--muted); font-size: 12px; }
.err { color: #B4362F; font-size: 13px; }

.app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.top { padding: calc(14px + env(safe-area-inset-top)) 18px 4px; display: flex; align-items: center; justify-content: space-between; }
.top h1 { margin: 0; font-size: 21px; }
.sync { font-size: 11px; color: var(--muted); }
.tabs { margin: 8px 10px 0; background: #ECEAE3; border-radius: 12px; padding: 4px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 3px; position: sticky; top: 0; z-index: 5; }
.tabs a { height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 9px; color: #4A504C; font-size: 13px; text-decoration: none; white-space: nowrap; }
.tabs a.on { background: #fff; color: var(--text); font-weight: 700; }
.view { flex: 1; padding: 10px 10px 200px; }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; }
.bottom-inner { max-width: 560px; margin: 0 auto; background: #fff; border-top: 1px solid var(--line); padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
.bottom-inner.row { display: flex; gap: 8px; }

.card { background: var(--card); border: 1px solid #E9E7E0; border-radius: 16px; padding: 12px; margin-bottom: 10px; }
.btn { height: 44px; border-radius: 12px; border: 1px solid #DAD7CF; background: #fff; padding: 0 14px; }
.primary { height: 52px; width: 100%; border: 0; border-radius: 14px; background: var(--accent); color: #fff; font-size: 16px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.primary:disabled { opacity: .5; }
.add-btn { width: 76px; height: 50px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; flex-shrink: 0; }
.input { height: 50px; width: 100%; min-width: 0; border: 1px solid #DAD7CF; border-radius: 12px; padding: 0 14px; background: var(--bg); }
.small-link { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 13px; padding: 10px; }
h2 { font-size: 17px; margin: 4px 4px 10px; }

/* 식단표 */
.person-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; padding: 0 2px; }
.person-head .name { font-size: 17px; font-weight: 700; }
.person-head .age { font-size: 12px; color: var(--muted); margin-left: 6px; }
.icon-btn { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: #4A504C; display: flex; align-items: center; justify-content: center; }
.icon-btn.on { width: auto; padding: 0 12px; background: var(--accent); color: #fff; border: 0; font-weight: 700; font-size: 13px; }
.edit-hint { font-size: 12px; color: var(--warm-text); background: var(--warm); border-radius: 8px; padding: 6px 8px; margin-bottom: 8px; }
.grid { display: grid; grid-template-columns: 16px repeat(4, minmax(0, 1fr)); column-gap: 4px; }
.dhead { height: 50px; min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--line2); border-bottom: 0; border-radius: 10px 10px 0 0; overflow: hidden; background: var(--soft); }
.dhead.today { background: var(--text); color: #fff; }
.band { height: 17px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: #fff; background: var(--gray-band); }
.band.prep { background: var(--red); }
.band.new { background: var(--accent); }
.dlabel { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; white-space: nowrap; }
.mlabel { display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: var(--muted); line-height: 1.2; text-align: center; word-break: break-all; }
.cell { min-width: 0; padding: 5px 3px; font-size: 11px; line-height: 1.4; word-break: keep-all; overflow-wrap: anywhere; border: 1px solid var(--line2); border-bottom: 0; background: #fff; text-align: left; }
.cell.last { border-bottom: 1px solid var(--line2); border-radius: 0 0 10px 10px; }
.cell.off { background: var(--soft); color: #8A8F8B; }
.cell.empty { color: #8A8F8B; }
.cell.editable { background: #FFFBF2; outline: 1px dashed #D9A066; outline-offset: -3px; cursor: pointer; }
.make { font-weight: 700; color: var(--make); }
.legend { font-size: 12px; color: var(--muted); margin: 2px 6px 8px; }
.cook { background: var(--warm); border: 1px solid var(--warm-line); }
.cook-row { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 10px; padding: 8px 10px; margin-top: 6px; font-size: 14px; }
.cook-row input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.pill { font-size: 12px; font-weight: 700; color: #fff; background: var(--red); border-radius: 999px; padding: 1px 8px; }
.toast { max-width: 536px; margin: 0 auto 8px; background: var(--text); color: #fff; border-radius: 14px; padding: 10px 6px 10px 14px; display: flex; align-items: center; gap: 8px; }
.toast a { height: 38px; padding: 0 12px; border-radius: 10px; background: #fff; color: var(--text); font-size: 13px; font-weight: 700; display: flex; align-items: center; text-decoration: none; white-space: nowrap; }
.toast button { width: 36px; height: 36px; border: 0; background: none; color: #C9CCC8; font-size: 18px; }

/* 칩 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; height: 36px; border-radius: 999px; border: 1px solid var(--line); background: #fff; padding: 0 13px; font-size: 14px; }
.chip.x { padding-right: 2px; }
.chip.x button { width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 16px; }
.chip.sel { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.chip.have { background: var(--soft); border-color: #ECEAE3; color: #8A8F8B; }
.chip.dark { background: var(--text); color: #fff; border-color: var(--text); font-weight: 700; }

/* 재고 */
.list { background: #fff; border: 1px solid #E9E7E0; border-radius: 16px; overflow: hidden; }
.item { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px; border-bottom: 1px solid #F0EEE8; }
.item:last-child { border-bottom: 0; }
.item .info { flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 0; }
.item .nm { font-size: 15px; font-weight: 500; }
.item .meta { font-size: 12px; color: var(--muted); }
.qbtn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid #DAD7CF; background: #fff; font-size: 20px; }
.qty { width: 30px; text-align: center; font-size: 18px; font-weight: 700; }
.qty.zero { color: #B4362F; }

/* 모달 */
.modal { position: fixed; inset: 0; background: rgba(31, 36, 33, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 560px; max-height: 88dvh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 4px 20px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.sheet-body { overflow-y: auto; padding: 8px 16px; display: flex; flex-direction: column; gap: 14px; }
.sheet-foot { padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid #F0EEE8; }
.field label, .field .lbl { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, .field select { width: 100%; border: 1px solid #DAD7CF; border-radius: 10px; padding: 10px 12px; min-height: 46px; background: #fff; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.seg button { height: 44px; border-radius: 10px; border: 1px solid #DAD7CF; background: #fff; }
.seg button.on { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }
.suggest { border: 1px solid #DAD7CF; border-top: 0; border-radius: 0 0 12px 12px; overflow: hidden; }
.suggest button { display: block; width: 100%; height: 44px; border: 0; border-top: 1px solid #F0EEE8; background: #fff; text-align: left; padding: 0 14px; }
.dish-row { display: flex; gap: 6px; align-items: center; }
.dish-row input[type=text] { flex: 1; }
.dish-row label { font-size: 12px; white-space: nowrap; display: flex; align-items: center; gap: 4px; color: var(--make); }

/* 구매 */
.buy-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: #FAF9F6; border-bottom: 1px solid #F0EEE8; }
.buy-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px; border-bottom: 1px solid #F0EEE8; }
.buy-row input { width: 22px; height: 22px; accent-color: var(--accent); margin: 0; flex-shrink: 0; }
.buy-row a { height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid #DAD7CF; color: var(--text); font-size: 12px; display: flex; align-items: center; text-decoration: none; white-space: nowrap; }

/* 설정 */
.meal-grid { display: grid; grid-template-columns: 92px repeat(3, minmax(0, 1fr)); gap: 6px; align-items: center; font-size: 13px; margin-top: 6px; }
.meal-grid button { height: 38px; border-radius: 8px; border: 1px solid #DAD7CF; background: #fff; color: var(--muted); }
.meal-grid button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.num { width: 28px; height: 28px; border-radius: 50%; background: var(--text); color: #fff; font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.busy { position: fixed; inset: 0; background: rgba(246, 245, 241, .92); z-index: 80; display: flex; align-items: center; justify-content: center; text-align: center; }
.busy-box p { margin: 6px 0; }
.spinner { width: 40px; height: 40px; border: 4px solid #D9D6CE; border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; }
.login h1 { font-size: 24px; }
.login label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.login input { width: 100%; height: 50px; border: 1px solid #DAD7CF; border-radius: 12px; padding: 0 14px; margin-bottom: 12px; }
[hidden] { display: none !important; }

.mic-btn { width: 50px; height: 50px; flex-shrink: 0; border-radius: 12px; border: 1px solid #DAD7CF; background: #fff; color: var(--accent); display: flex; align-items: center; justify-content: center; }
.mic-big { width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.mic-big svg { width: 36px; height: 36px; }
.mic-big.on { background: #C0392B; animation: micPulse 1.2s ease-in-out infinite; }
.mic-big:disabled { opacity: .4; }
@keyframes micPulse { 50% { box-shadow: 0 0 0 12px rgba(192, 57, 43, .18); } }
@media (prefers-reduced-motion: reduce) { .mic-big.on { animation: none; } }

.ai-fab { position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(20, 60, 40, .28); z-index: 20; }
.ai-fab:focus-visible { outline: 3px solid #1F2621; outline-offset: 2px; }

.ai-toast { position: fixed; left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); z-index: 21; background: #1F2621; color: #fff; border-radius: 14px; padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 560px; margin: 0 auto; }
.ai-toast button { background: none; border: 0; color: #fff; font-size: 22px; line-height: 1; padding: 0 4px; }
.spinner.small { width: 18px; height: 18px; border-width: 2px; flex: none; margin: 0; }
.ai-fab.working { background: #4E8F6C; }
.ai-fab.working svg { animation: aiPulse 1.2s ease-in-out infinite; }
@keyframes aiPulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .ai-fab.working svg { animation: none; } }
/* 누르는 즉시 눌린 느낌이 나게 */
button, a, [role="button"], input, label, select, textarea { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:not(:disabled):active, a.primary:active, [role="button"]:active, .chip:active { transform: scale(.96); filter: brightness(.92); transition: transform .05s; }
.cell .dish { display: flex; gap: 3px; align-items: flex-start; }
.cell .dish + .dish { margin-top: 3px; padding-top: 3px; border-top: 1px dotted var(--line2); }
.cell .dot { flex: none; width: 5px; height: 5px; border-radius: 50%; background: #B9BEB8; margin-top: 5px; }
.cell .make .dot { background: #2E7D56; width: 6px; height: 6px; margin-top: 4.5px; }
.cell .dn { flex: 1; min-width: 0; }
.cell .ln { display: block; white-space: nowrap; overflow: hidden; letter-spacing: -0.3px; }
