:root {
  --bg: #EEF2F0;
  --surface: #FFFFFF;
  --surface-2: #F5F8F6;
  --ink: #1E2B26;
  --ink-muted: #63756E;
  --ink-faint: #93A39C;
  --line: #DCE3DF;
  --pine: #2F6B52;
  --pine-dark: #24543F;
  --pine-light: #E4EEE8;
  --amber: #C97F2E;
  --amber-light: #FBEEDD;
  --red: #B24B44;
  --red-light: #F7E4E2;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 1px 2px rgba(30,43,38,0.04), 0 4px 16px rgba(30,43,38,0.06);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
body { padding: 20px 14px 60px; }
.app { max-width: 520px; margin: 0 auto; }

.topbar { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.wordmark { font-family: var(--mono); font-weight: 700; font-size: 15px; letter-spacing: 0.14em; color: var(--pine-dark); text-transform: uppercase; }
.wordmark span { color: var(--ink-faint); font-weight: 500; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.date-label { font-size: 13px; color: var(--ink-muted); font-family: var(--mono); }
.gear-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: var(--ink-muted); flex-shrink: 0;
}
.gear-btn:hover { background: var(--surface-2); color: var(--ink); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-title { font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); margin: 0 0 12px; }

.gauge-wrap { display: flex; flex-direction: column; align-items: center; }
.gauge-meta { display: flex; justify-content: space-between; width: 100%; margin-top: 4px; font-size: 12.5px; color: var(--ink-muted); }
.gauge-meta b { color: var(--ink); font-family: var(--mono); }
.zone-remaining { font-weight: 600; }
.zone-remaining.ok { color: var(--pine); }
.zone-remaining.warn { color: var(--amber); }
.zone-remaining.over { color: var(--red); }

.macro-row { display: flex; gap: 10px; margin-top: 14px; }
.macro-tile { flex: 1; background: var(--surface-2); border-radius: 10px; padding: 10px 8px; text-align: center; }
.macro-tile .val { font-family: var(--mono); font-weight: 700; font-size: 16px; }
.macro-tile .lbl { font-size: 10.5px; color: var(--ink-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.05em; }

textarea#foodInput {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-family: var(--sans); font-size: 14.5px; resize: vertical; min-height: 44px;
  background: var(--surface-2); color: var(--ink);
}
textarea#foodInput:focus { outline: none; border-color: var(--pine); background: var(--surface); }
.input-row { display: flex; justify-content: flex-end; margin-top: 6px; }
.mic-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--ink-muted); }
.mic-btn:hover { background: var(--surface-2); color: var(--ink); }
.mic-btn.recording { background: var(--red-light); border-color: var(--red); color: var(--red); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.btn { border: none; border-radius: 10px; padding: 10px 16px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: var(--sans); }
.btn-primary { background: var(--pine); color: white; flex: 1; }
.btn-primary:hover { background: var(--pine-dark); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-ghost { background: var(--surface-2); color: var(--ink-muted); border: 1px solid var(--line); }
.btn-ghost:hover { color: var(--ink); }
.btn-small { padding: 7px 12px; font-size: 13px; }

.status-line { font-size: 13px; color: var(--ink-muted); margin-top: 8px; display: flex; align-items: center; gap: 6px; }
.status-line.error { color: var(--red); }
.spinner { width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--pine); border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.preview-card { margin-top: 12px; border: 1px solid var(--pine-light); background: var(--pine-light); border-radius: 12px; padding: 12px 14px; }
.preview-desc { font-size: 13.5px; color: var(--ink); margin-bottom: 10px; line-height: 1.4; }
.preview-fields { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.preview-fields label { font-size: 12px; color: var(--ink-muted); white-space: nowrap; }
.preview-fields input { width: 72px; border: 1px solid var(--line); border-radius: 7px; padding: 5px 7px; font-family: var(--mono); font-size: 13.5px; text-align: right; }
.preview-confidence { font-size: 11.5px; color: var(--ink-muted); margin: 4px 0 10px; }
.plausibility-warning { font-size: 12px; color: var(--amber); margin: 4px 0 8px; line-height: 1.4; }
.preview-btns { display: flex; gap: 8px; }

details#manualFallback { margin-top: 10px; font-size: 13px; color: var(--ink-muted); }
details#manualFallback summary { cursor: pointer; }
.manual-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.manual-grid .full { grid-column: 1 / -1; }
.manual-grid label { font-size: 11.5px; color: var(--ink-muted); display: block; margin-bottom: 3px; }
.manual-grid input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; font-family: var(--sans); font-size: 13.5px; }

.entry-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry-item:last-child { border-bottom: none; }
.entry-time { font-family: var(--mono); font-size: 11.5px; color: var(--ink-faint); width: 38px; flex-shrink: 0; }
.entry-desc { flex: 1; font-size: 13.5px; color: var(--ink); line-height: 1.35; }
.entry-kcal { font-family: var(--mono); font-weight: 700; font-size: 14px; white-space: nowrap; }
.entry-del { border: none; background: none; color: var(--ink-faint); cursor: pointer; font-size: 16px; padding: 2px 4px; line-height: 1; }
.entry-del:hover { color: var(--red); }
.empty-hint { font-size: 13px; color: var(--ink-faint); padding: 6px 0; }

.entry-date-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.entry-date-row label { font-size: 12.5px; color: var(--ink-muted); }
.entry-date-row input[type="date"] { flex: 1; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; font-family: inherit; }

.weight-row { display: flex; align-items: center; gap: 10px; }
.weight-row input { width: 90px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-family: var(--mono); font-size: 14px; }
.weight-last { font-size: 12px; color: var(--ink-muted); margin-top: 8px; }

.hist-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; cursor: pointer; border-radius: 8px; }
.hist-row:hover, .hist-row:focus-visible { background: var(--surface-2); }
.hist-date { font-family: var(--mono); font-size: 11.5px; color: var(--ink-muted); width: 62px; flex-shrink: 0; }
.hist-bar-track { flex: 1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hist-bar-fill { height: 100%; border-radius: 4px; }
.hist-kcal { font-family: var(--mono); font-size: 12px; width: 52px; text-align: right; color: var(--ink-muted); flex-shrink: 0; }
.hist-row::after { content: '›'; color: var(--ink-faint); font-size: 15px; flex-shrink: 0; }
.hist-footer { font-size: 12px; color: var(--ink-faint); margin-top: 10px; }

.week-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.week-row:last-child { border-bottom: none; }
.week-date { font-family: var(--mono); font-size: 11.5px; color: var(--ink-muted); width: 62px; flex-shrink: 0; }
.week-kcal { font-family: var(--mono); font-size: 12.5px; width: 54px; text-align: right; flex-shrink: 0; }
.week-macros { flex: 1; text-align: right; font-size: 11.5px; color: var(--ink-muted); }
.week-row.no-data .week-kcal, .week-row.no-data .week-macros { color: var(--ink-faint); font-style: italic; }

.settings-panel { position: fixed; inset: 0; background: rgba(30,43,38,0.35); display: none; align-items: flex-end; justify-content: center; z-index: 50; }
.settings-panel.open { display: flex; }
.settings-sheet { background: var(--surface); border-radius: 18px 18px 0 0; padding: 22px 20px 28px; width: 100%; max-width: 520px; box-shadow: 0 -8px 30px rgba(0,0,0,0.15); }
.settings-sheet h3 { margin: 0 0 4px; font-size: 16px; }
.settings-hint { font-size: 12.5px; color: var(--ink-muted); line-height: 1.5; margin: 6px 0 16px; }
.settings-field { margin-bottom: 14px; }
.settings-field label { font-size: 12.5px; color: var(--ink-muted); display: block; margin-bottom: 5px; }
.settings-field input { width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font-family: var(--mono); font-size: 15px; }
.settings-btns { display: flex; gap: 8px; margin-top: 6px; }

.btn-danger { background: var(--surface-2); color: var(--red); border: 1px solid var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }
.settings-danger { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }

.footnote { text-align: center; font-size: 11.5px; color: var(--ink-faint); margin-top: 18px; line-height: 1.5; }

.daydetail-panel { position: fixed; inset: 0; background: rgba(30,43,38,0.35); display: none; align-items: flex-end; justify-content: center; z-index: 50; }
.daydetail-panel.open { display: flex; }
.daydetail-sheet { background: var(--surface); border-radius: 18px 18px 0 0; padding: 22px 20px 28px; width: 100%; max-width: 520px; max-height: 82vh; overflow-y: auto; box-shadow: 0 -8px 30px rgba(0,0,0,0.15); }
.daydetail-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.daydetail-header h3 { margin: 0; font-size: 16px; }
.daydetail-macro-row { display: flex; gap: 10px; margin: 12px 0; }
.daydetail-note { font-size: 12px; color: var(--ink-muted); margin: 8px 0 14px; line-height: 1.4; }
.daydetail-entry summary { cursor: pointer; font-size: 13.5px; padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; list-style: none; }
.daydetail-entry summary > span:first-child { flex: 1; }
.daydetail-entry summary::-webkit-details-marker { display: none; }
.daydetail-entry summary::after { content: '▾'; color: var(--ink-faint); font-size: 11px; margin-left: 4px; transition: transform 0.15s ease; }
.daydetail-entry[open] summary::after { transform: rotate(180deg); }
.daydetail-entry .macro-detail { font-size: 12.5px; color: var(--ink-muted); padding: 4px 0 10px; }
