:root {
  --paper: #faf8f2;
  --card: #fffefb;
  --ink: #263d34;
  --muted: #7d877d;
  --green: #3f7465;
  --green-dark: #2d5c4e;
  --green-light: #e9f0e7;
  --orange: #d48248;
  --orange-light: #fbecdd;
  --line: #e8e9df;
  --red: #ad4f45;
  --shadow: 0 8px 32px #344b3510;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .46; }
button, input, select, textarea { touch-action: manipulation; }
button, .button { -webkit-user-select: none; user-select: none; }
a { color: var(--green); text-underline-offset: 3px; }
svg { width: 22px; height: 22px; flex-shrink: 0; vertical-align: middle; }
img { max-width: 100%; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; overflow-wrap: anywhere; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #82a78b; outline-offset: 4px;
}
[hidden] { display: none !important; }
noscript { display: block; padding: 32px; text-align: center; }

.app-shell { max-width: 1040px; min-height: 100dvh; margin: 0 auto; padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: calc(20px + env(safe-area-inset-top)) 22px 18px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 21px; font-weight: 750; letter-spacing: 1px; }
.topbar .brand { flex: 1; min-width: 0; }
.topbar .brand > div { min-width: 0; }
.topbar .page-title { font-size: 22px; letter-spacing: .5px; }
.topbar .subtitle { display: block; margin-top: 4px; font-size: 12px; line-height: 1.5; font-weight: 400; letter-spacing: 0; overflow-wrap: anywhere; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; color: var(--orange); border-radius: 12px; background: var(--orange-light); }
.brand-mark img { width: 38px; height: 38px; border-radius: 12px; }
.brand small { color: var(--muted); font-size: 10px; letter-spacing: 2px; font-weight: 550; }
.brand-text { display: grid; gap: 2px; }
.eyebrow { font-size: 11px; font-weight: 650; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }
.page-title { font-size: clamp(26px, 5vw, 34px); line-height: 1.3; font-weight: 700; letter-spacing: -.7px; }
.subtitle { margin-top: 9px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.page { padding: 12px 22px 30px; }
.page > .section-heading:first-child { margin-bottom: 24px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 8px 0 24px; }
.status { display: inline-flex; align-items: center; gap: 6px; min-width: 0; min-height: 44px; padding: 5px 0; border: 0; background: transparent; font-size: 11px; color: var(--muted); line-height: 1.5; text-align: left; overflow-wrap: anywhere; }
.status-dot { width: 6px; height: 6px; background: #8cae83; border-radius: 50%; flex-shrink: 0; }
.status.is-pending .status-dot, .status.is-offline .status-dot, .status-dot.is-pending { background: var(--orange); }
.status.is-error .status-dot { background: var(--red); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.section-title { font-size: 17px; font-weight: 650; letter-spacing: -.2px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin: 24px 0 14px; }
.section-heading > div { min-width: 0; }
.section-heading > h3 { flex: 1; min-width: 0; font-size: 16px; font-weight: 650; }
.section-heading small { font-size: 12px; color: var(--muted); }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 14px; }
.stack > .field { margin-bottom: 0; }
.muted, .hint { color: var(--muted); font-size: 12px; line-height: 1.7; }
.full-width { width: 100%; }
.list { display: grid; gap: 12px; }
.spacer { margin-top: 24px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 17px; border: 1px solid transparent; border-radius: 13px; background: var(--green-light); font-size: 14px; font-weight: 600; line-height: 1.4; text-decoration: none; transition: background .16s, transform .16s; }
.button:hover { background: #dde8d9; }
.button:active, .icon-button:active { transform: translateY(1px); }
.button.primary { background: var(--green); color: #fff; }
.button.primary:hover { background: var(--green-dark); }
.button.secondary { background: var(--card); border-color: var(--line); }
.button.secondary:hover { background: #f4f4ed; }
.button.ghost { background: transparent; color: var(--green); }
.button.ghost:hover { background: var(--green-light); }
.button.danger { background: #faeae5; color: var(--red); }
.button.small { font-size: 12px; min-height: 36px; padding: 7px 12px; border-radius: 10px; }
.icon-button { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 10px; border: 1px solid var(--line); background: var(--card); border-radius: 14px; flex-shrink: 0; }
.icon-button:hover { background: var(--green-light); }
.icon-button svg { width: 20px; height: 20px; }
.text-button { background: none; border: 0; min-height: 44px; padding: 8px 3px; color: var(--green); font-size: 13px; }
.text-button.danger { color: var(--red); }
.bottom-nav { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 7px; padding: 9px 16px calc(9px + env(safe-area-inset-bottom)); background: #fffefbf5; border-top: 1px solid var(--line); backdrop-filter: blur(18px); }
.nav-button { min-height: 53px; flex: 1; max-width: 180px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; border: 0; border-radius: 13px; color: var(--muted); background: transparent; font-size: 11px; font-weight: 550; }
.nav-button svg { width: 21px; height: 21px; }
.nav-button.is-active { color: var(--green-dark); background: var(--green-light); }

.summary-bar { display: flex; align-items: center; gap: 14px; padding: 18px 20px; border-radius: 18px; background: #edf2e9; }
.summary-bar strong { font-size: 24px; color: var(--green); font-variant-numeric: tabular-nums; }
.summary-bar p { color: #667d69; font-size: 12px; line-height: 1.7; }
.app-shell > .summary-bar { margin: 0 22px; padding: 2px 14px; justify-content: space-between; gap: 12px; }
.app-shell > .summary-bar > .muted { flex-shrink: 0; font-size: 10px; }
.app-shell > .notice { margin-left: 22px; margin-right: 22px; }
.calendar-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.calendar-title { font-size: 16px; font-weight: 650; white-space: nowrap; }
.calendar-toolbar .icon-button { width: 44px; height: 44px; padding: 10px; border-radius: 11px; }
.calendar-toolbar [data-direction="previous"] svg { transform: rotate(180deg); }
.week-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; margin: 16px 0 25px; }
.day-chip { position: relative; min-width: 0; min-height: 76px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; padding: 10px 0; border: 1px solid transparent; border-radius: 16px; background: transparent; }
.day-chip small { color: var(--muted); font-size: 11px; }
.day-chip strong { font-size: 18px; font-weight: 550; font-variant-numeric: tabular-nums; }
.day-chip.is-today { border-color: #c6d4bd; }
.day-chip.is-selected { color: #fff; background: var(--green); box-shadow: 0 5px 12px #3f746525; }
.day-chip.is-selected small { color: #e1eade; }
.day-chip .day-dot { position: absolute; bottom: 6px; width: 4px; height: 4px; border-radius: 50%; background: var(--orange); }
.day-chip.is-selected .day-dot { background: #f3d3a9; }
.day-chip .day-indicator { display: none; position: absolute; bottom: 6px; width: 4px; height: 4px; border-radius: 50%; background: var(--orange); font-size: 0; }
.day-chip.has-meals .day-indicator { display: block; }
.day-chip.is-selected .day-indicator { background: #f3d3a9; }
.weekdays { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); text-align: center; font-size: 11px; color: var(--muted); padding: 12px 0; }
.month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; margin-bottom: 24px; }
.month-day { position: relative; min-height: 45px; padding: 9px 0 14px; border: 1px solid transparent; border-radius: 12px; background: transparent; font-size: 14px; font-variant-numeric: tabular-nums; }
.month-day.is-selected { color: #fff; background: var(--green); }
.month-day.is-today { border-color: #a7bea1; }
.month-day.is-outside { color: #bec3b8; }
.month-day.has-meals::after { content: ""; position: absolute; bottom: 7px; left: calc(50% - 2px); width: 4px; height: 4px; border-radius: 50%; background: var(--orange); }
.month-day.is-selected::after { background: #f5d6ae; }
.month-day .day-indicator { display: none; }
.segmented { display: inline-flex; gap: 3px; padding: 4px; border-radius: 12px; background: #eeeee5; }
.segment { min-height: 34px; padding: 6px 14px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 550; }
.segment.is-active { background: #fffefb; color: var(--green-dark); box-shadow: 0 1px 6px #344b3510; }
.empty-state { padding: 35px 22px; text-align: center; border: 1px dashed #d9dece; border-radius: 20px; color: var(--muted); }
.empty-state svg { width: 34px; height: 34px; color: #9cab8b; margin-bottom: 13px; }
.empty-state h3 { margin-bottom: 8px; color: #657661; font-size: 16px; font-weight: 600; }
.empty-state p { font-size: 13px; line-height: 1.8; }
.empty-state .button { margin-top: 18px; }
.empty-state .brand-mark { margin: 0 auto 14px; }
.empty-state .brand-mark svg { width: 24px; height: 24px; margin: 0; }
.empty-state .actions { justify-content: center; }
.meal-card { margin-bottom: 12px; padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.meal-card > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 13px; }
.meal-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; font-size: 13px; color: var(--green); }
.meal-meta > div:first-child { flex: 1; min-width: 0; }
.meal-meta .actions { flex-shrink: 0; }
.meal-meta svg { width: 17px; height: 17px; color: var(--orange); }
.meal-items { display: grid; gap: 12px; }
.meal-items .row { align-items: flex-start; }
.meal-items strong { display: block; font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.meal-items .chip { max-width: 45%; flex-shrink: 0; }
.meal-card > .muted { margin-top: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.meal-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.meal-item-name { font-size: 15px; line-height: 1.6; font-weight: 600; overflow-wrap: anywhere; }
.meal-item-amount { font-size: 12px; color: var(--orange); line-height: 1.7; text-align: right; flex-shrink: 0; }
.meal-note { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.dish-grid { display: grid; gap: 12px; }
.dish-card { position: relative; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); text-align: left; }
.dish-card h3 { font-size: 16px; font-weight: 650; margin-bottom: 9px; overflow-wrap: anywhere; }
.dish-card .actions { margin-top: 16px; }
.dish-card .section-heading { flex-wrap: nowrap; align-items: flex-start; margin: 0 0 12px; }
.dish-card .section-heading h3 { margin: 0; }
.dish-card .section-heading .actions { margin: 0; flex-shrink: 0; }
.chip-list { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-block; padding: 4px 8px; border-radius: 7px; background: #f0f3e9; color: #748566; font-size: 11px; line-height: 1.5; overflow-wrap: anywhere; }
.chip.orange { background: var(--orange-light); color: #b27b48; }
.chip.muted { background: #f2f1eb; color: #8c9186; }

.field { display: grid; gap: 8px; margin-bottom: 18px; }
.field > label, label.field > span, .field-label { display: block; color: #556b59; font-size: 13px; line-height: 1.6; font-weight: 600; }
.field-row { display: flex; align-items: flex-start; gap: 12px; }
.field-row > .field { flex: 1; min-width: 0; }
.input, .textarea, .select { width: 100%; min-height: 46px; padding: 12px 13px; color: var(--ink); border: 1px solid #dfe4d6; border-radius: 12px; background: #fffefb; outline-offset: 2px; font-size: 16px; line-height: 1.5; }
.input, .textarea, .select { min-width: 0; max-width: 100%; }
.input[type="date"] { display: block; min-inline-size: 0; }
.field-row:has(> .field:nth-child(3)) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-row:has(> .field:nth-child(3)) > .field:first-child { grid-column: 1 / -1; }
.input::placeholder, .textarea::placeholder { color: #abb2a3; }
.input:focus, .textarea:focus, .select:focus { border-color: #6d967b; }
.textarea { resize: vertical; min-height: 90px; }
.select { -webkit-appearance: auto; appearance: auto; }
.field small { color: var(--muted); font-size: 11px; line-height: 1.6; }
.item-editor { border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: #fffefa; }
.item-editor + .item-editor { margin-top: 12px; }
.item-editor > header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.item-editor h3 { font-size: 15px; }
.item-editor .field:last-child { margin-bottom: 0; }
.item-editor > .section-heading { margin: 0 0 14px; }
.quantity-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.portion-options { display: flex; flex-wrap: wrap; gap: 7px; }
.portion-options button { min-height: 38px; border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; background: #fffefb; color: var(--muted); font-size: 12px; }
.portion-options button.is-selected, .portion-options button[aria-pressed="true"] { color: var(--green); border-color: #8faa8c; background: var(--green-light); }
.form-error { color: var(--red); font-size: 13px; line-height: 1.7; padding: 12px 14px; border-radius: 12px; background: #fcefe9; margin: 12px 0; overflow-wrap: anywhere; }
.form-error:empty { display: none; }
.notice { padding: 14px 16px; border-radius: 14px; border: 1px solid #eadbbf; background: #fcf3df; color: #8a744e; font-size: 12px; line-height: 1.8; margin: 12px 0; }
.notice.success { color: var(--green-dark); background: var(--green-light); border-color: #d9e4d3; }
.notice .button { margin-top: 10px; }
.notice strong { font-weight: 650; }
.notice code { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }

.sheet { position: fixed; inset: auto 0 0; width: min(100%, 680px); max-height: 92dvh; padding: 0; margin: 0 auto; border: 0; border-radius: 24px 24px 0 0; color: var(--ink); background: var(--paper); box-shadow: 0 -8px 50px #233a3320; overscroll-behavior: contain; }
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop { background: #203e3459; backdrop-filter: blur(3px); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px 16px; border-bottom: 1px solid var(--line); background: var(--paper); }
.sheet-header h2 { font-size: 20px; font-weight: 650; }
.sheet-header .icon-button { border: 0; background: #ecefe4; width: 36px; height: 36px; }
.sheet-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 22px calc(24px + env(safe-area-inset-bottom)); }
.sheet-footer { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 15px 22px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.sheet form { min-width: 0; }
.sheet form.stack { display: grid; gap: 16px; }
.sheet .stack > .card { margin-top: 0; }
.sheet .stack > .section-heading { margin-top: 0; }
.sheet-footer .button.primary { flex: 1; }
.sheet .empty-state { padding: 24px 16px; }
.picker-list { display: grid; gap: 8px; margin: 12px 0; }
.picker-option { width: 100%; justify-content: flex-start; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-align: left; }
.picker-option.is-selected { border-color: #8faa8c; background: var(--green-light); }
.picker-option strong { display: block; font-size: 14px; margin-bottom: 6px; }

.auth-shell { max-width: 520px; min-height: 100dvh; padding: calc(34px + env(safe-area-inset-top)) 24px calc(30px + env(safe-area-inset-bottom)); margin: 0 auto; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 390px; }
.auth-card .brand { margin-bottom: 42px; }
.auth-card .page-title { font-size: 31px; }
.auth-card .subtitle { margin-bottom: 28px; }
.auth-card > .eyebrow { margin-bottom: 10px; }
.auth-card > .subtitle + .subtitle { margin-top: -14px; font-size: 13px; }
.auth-card .field { margin-bottom: 18px; }
.auth-card .stack > .field { margin-bottom: 0; }
.auth-card .button.primary { width: 100%; min-height: 49px; margin-top: 5px; }
.auth-card .auth-links { display: flex; justify-content: space-between; gap: 12px; margin: 14px 0 24px; }
.auth-art { display: grid; place-items: center; width: 60px; height: 60px; margin-bottom: 28px; border-radius: 19px; background: var(--orange-light); color: var(--orange); }
.auth-art svg { width: 38px; height: 38px; transform: rotate(-10deg); }
.auth-divider { margin: 22px 0; height: 1px; background: var(--line); }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 20px 0; }
.stat-card { padding: 18px 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.stat-grid:has(> :last-child:nth-child(2)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-card { min-width: 0; }
.stat-card h3 { font-size: 14px; margin-bottom: 8px; }
.stat-card p { font-size: 12px; line-height: 1.8; overflow-wrap: anywhere; }
.stat-card strong { display: block; margin-bottom: 7px; color: var(--green); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-card span, .stat-card small { color: var(--muted); font-size: 11px; }
.ingredient-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 17px 0; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; }
.ingredient-row:last-child { border-bottom: 0; }
.ingredient-row h3, .ingredient-row strong { display: block; font-size: 15px; font-weight: 600; margin-bottom: 5px; }
.ingredient-row small { font-size: 11px; color: var(--muted); }
.ingredient-count { padding: 6px 11px; border-radius: 9px; background: var(--green-light); color: var(--green); font-size: 12px; white-space: nowrap; }
.settings-section { margin-top: 26px; }
.settings-section h2 { margin-bottom: 14px; font-size: 16px; }
.settings-section .button { width: 100%; justify-content: flex-start; margin-bottom: 10px; }
.settings-section p { overflow-wrap: anywhere; }
.settings-section .actions { margin-top: 14px; }
.settings-section .actions .button { flex: 1; width: auto; }
.install-steps { padding-left: 20px; margin: 10px 0 0; line-height: 2; }
.toast { position: fixed; z-index: 30; bottom: calc(95px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); max-width: calc(100% - 40px); width: max-content; padding: 13px 19px; border-radius: 13px; background: #2c5147; color: white; box-shadow: var(--shadow); font-size: 13px; line-height: 1.6; }

@media (min-width: 640px) {
  .page { padding: 24px 40px 42px; }
  .topbar { padding: 27px 40px 21px; }
  .app-shell > .summary-bar { margin-left: 40px; margin-right: 40px; }
  .app-shell > .notice { margin-left: 40px; margin-right: 40px; }
  .week-strip { gap: 10px; }
  .day-chip { min-height: 86px; }
  .dish-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .month-day { min-height: 62px; }
  .sheet { inset: 0; margin: auto; border-radius: 24px; max-height: min(86dvh, 900px); height: fit-content; }
  .sheet-footer { padding-bottom: 20px; }
  .stat-card { padding: 23px 21px; }
}

@media (min-width: 860px) {
  .app-shell { border-left: 1px solid #eeede5; border-right: 1px solid #eeede5; }
  .auth-shell { padding: 50px 36px; }
  .bottom-nav { left: max(0px, calc((100vw - 1040px) / 2)); right: max(0px, calc((100vw - 1040px) / 2)); padding-top: 12px; padding-bottom: 12px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
