/* Health & Habits */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --rust: #C15F33; --bg: #1B1C18; --surface: #26271F; --border: #3A3B30;
  --text: #E8E6DC; --text-muted: #8A8B7A; --mono: ui-monospace, "SF Mono", monospace;
}
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; }

/* Login */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 32px 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login-mark { font-family: var(--mono); font-size: 18px; letter-spacing: 0.12em; color: var(--rust); text-align: center; }
.login-sub { font-size: 13px; color: var(--text-muted); text-align: center; }
.login-error { font-size: 13px; color: #9C4438; min-height: 18px; }

/* Buttons */
button { cursor: pointer; font: inherit; }
.btn { background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); border-radius: 3px; padding: 10px 16px; font-size: 14px; white-space: nowrap; }
.btn:focus-visible { outline: 2px solid var(--rust); }
.btn-primary { background: var(--rust); border-color: var(--rust); color: var(--bg); font-weight: 600; }
.btn-accent  { background: var(--rust); border-color: var(--rust); color: var(--bg); font-weight: 600; }
.btn-block   { width: 100%; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text-muted); border-radius: 3px; width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }

/* Inputs */
input[type="text"], input[type="number"], input[type="password"] { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 3px; padding: 10px 12px; font-size: 15px; width: 100%; font-family: inherit; }
input::placeholder { color: var(--text-muted); }
input:focus { outline: 2px solid var(--rust); outline-offset: -1px; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { display: none; }

/* Shell */
.app { max-width: 560px; margin: 0 auto; padding: 0 16px 64px; }
.hidden { display: none !important; }

/* Topbar */
.topbar { display: flex; flex-direction: column; gap: 8px; padding: 18px 0 10px; padding-top: max(18px, env(safe-area-inset-top) + 10px); position: sticky; top: 0; background: var(--bg); z-index: 10; }
.topbar-row1 { display: flex; align-items: center; justify-content: space-between; }
.brand { font-family: var(--mono); font-size: 13px; letter-spacing: 0.12em; color: var(--rust); }
.date-display { font-family: var(--mono); letter-spacing: 0.08em; font-size: 12px; color: var(--text-muted); padding: 2px 0; }

/* Cards */
.view { padding-top: 16px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.card-head-right { display: flex; align-items: center; gap: 8px; }
.tag { font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; color: var(--rust); }
.card-head-meta { font-family: var(--mono); font-size: 13px; color: var(--text-muted); }
.card-head-meta.over { color: #9C4438; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; min-width: 0; }

/* Section reorder */
.section-handle { cursor: grab; color: var(--border); font-size: 16px; user-select: none; flex-shrink: 0; padding: 4px; }
.card.is-dragging { position: fixed; z-index: 200; opacity: 0.95; pointer-events: none; border-color: var(--rust); }
.section-placeholder { background: var(--border); border-radius: 6px; opacity: 0.3; }

/* Calories */
.food-search-wrap { margin-bottom: 12px; }
.food-search-row { display: flex; gap: 8px; align-items: center; }
.food-search-row input { flex: 1; min-width: 0; }
.cal-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.cal-row:last-of-type { border-bottom: none; }
.cal-label { font-size: 13px; color: var(--text-muted); width: 72px; flex-shrink: 0; }
.cal-row input { text-align: right; }

/* Habits */
.habit-list { list-style: none; }
.habit-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.habit-row:last-child { border-bottom: none; }
.habit-check-btn { background: none; border: 2px solid var(--border); border-radius: 4px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--bg); font-size: 16px; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
.habit-row.checked .habit-check-btn, .steps-check-row.checked .habit-check-btn { background: var(--rust); border-color: var(--rust); }
.habit-name { font-size: 15px; }
.habit-row.checked .habit-name { color: var(--text-muted); text-decoration: line-through; }
.empty-row { color: var(--text-muted); font-size: 13px; padding: 10px 0; font-style: italic; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 10px; font-style: italic; }

/* Steps */
.steps-check-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.steps-check-label { font-size: 15px; }

/* Weight */
.weight-last-note { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; justify-content: center; z-index: 100; padding: 0 12px max(12px, env(safe-area-inset-bottom)); }
.modal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; width: 100%; max-width: 540px; display: flex; flex-direction: column; }
.modal-card-tall { max-height: 80vh; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

/* Library list */
.lib-list { list-style: none; overflow-y: auto; flex: 1; min-height: 0; }
.lib-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.lib-row:last-child { border-bottom: none; }
.lib-name { flex: 1; font-size: 15px; }
.lib-actions { display: flex; gap: 6px; }
.lib-actions button { background: none; border: none; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 4px 6px; }
.drag-handle { cursor: grab; color: var(--border); font-size: 16px; user-select: none; flex-shrink: 0; }
.lib-row.is-dragging { position: fixed; z-index: 200; background: var(--surface); border: 1px solid var(--rust); border-radius: 4px; padding: 8px 12px; pointer-events: none; opacity: 0.95; }
.drag-placeholder { background: var(--border); border-radius: 4px; opacity: 0.4; }

/* Toast */
.toast { position: fixed; bottom: max(24px, env(safe-area-inset-bottom) + 12px); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 20px; border-radius: 20px; font-size: 14px; font-weight: 500; white-space: nowrap; z-index: 300; pointer-events: none; }
.toast.error { background: #9C4438; color: #fff; }
