/* =========================================================
   Journal — dark, warm, typographic
   ========================================================= */
:root {
  --bg:           #14110f;
  --surface:      #1c1916;
  --surface-2:    #26211d;
  --surface-3:    #322b25;
  --text:         #f3ede4;
  --text-soft:    #cdc4b6;
  --text-muted:   #8b837a;
  --border:       #2e2823;
  --border-soft:  #221d19;
  --accent:       #d97f5c;
  --accent-soft:  #4a2a1e;
  --danger:       #b05757;
  --ok:           #7da26a;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body:    'Manrope', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

  --sat: env(safe-area-inset-top);
  --sab: env(safe-area-inset-bottom);
  --sal: env(safe-area-inset-left);
  --sar: env(safe-area-inset-right);

  --nav-h: 64px;
  --header-h: 88px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100svh;
  padding-top:    calc(var(--header-h) + var(--sat));
  padding-bottom: calc(var(--nav-h) + var(--sab) + 12px);
  padding-left:   var(--sal);
  padding-right:  var(--sar);
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------- Header ---------- */
.app-header {
  position: fixed; top: 0; left: 0; right: 0;
  padding: calc(var(--sat) + 14px) 20px 12px;
  background: linear-gradient(180deg, var(--bg) 75%, rgba(20,17,15,0));
  z-index: 10;
}
.header-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
}
.app-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 30px;
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.header-sub {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  min-height: 14px;
}
.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  color: var(--text-soft);
  border-radius: 10px;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- Bottom Nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--sab));
  padding-bottom: var(--sab);
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(20,17,15, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-soft);
  z-index: 9;
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  font-family: var(--font-body);
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent); }
.nav-item:active { background: var(--surface); }

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: calc(20px + var(--sar));
  bottom: calc(var(--nav-h) + var(--sab) + 18px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #1a0d06;
  box-shadow: 0 8px 24px -8px rgba(217, 127, 92, 0.6),
              0 2px 6px rgba(0,0,0,.3);
  display: grid; place-items: center;
  z-index: 8;
  transition: transform .12s ease;
}
.fab:active { transform: scale(0.94); }

/* ---------- Main view container ---------- */
#view-root {
  padding: 8px 18px 24px;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- Entry list / cards ---------- */
.entry-group + .entry-group { margin-top: 26px; }
.entry-group-label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 10px 4px;
  letter-spacing: 0.02em;
}

.entry {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  align-items: start;
  gap: 12px;
  padding: 14px 12px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
  background: var(--surface);
  margin-bottom: 10px;
  position: relative;
}
.entry-time {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  padding-top: 2px;
}
.entry-body { min-width: 0; }
.entry-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: -0.005em;
  word-break: break-word;
}
.entry-amount {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.02em;
}
.entry-nutri {
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-soft);
}
.entry-nutri span b { font-weight: 500; color: var(--text); }
.entry-notes {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
}
.entry-menu {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  color: var(--text-muted);
  border-radius: 8px;
  margin-top: -4px;
}
.entry-menu:active { background: var(--surface-2); }
.entry-menu svg { width: 18px; height: 18px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h2 {
  font-family: var(--font-display);
  font-weight: 400;
  font-style: italic;
  font-size: 22px;
  color: var(--text-soft);
  margin: 0 0 6px;
}
.empty-state p { margin: 0; font-size: 14px; }

/* ---------- Day navigator ---------- */
.day-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  margin: 0 0 16px;
  padding: 8px 10px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border-soft);
}
.day-nav button {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--text-soft);
}
.day-nav button:disabled { color: var(--surface-3); }
.day-nav button:active:not(:disabled) { background: var(--surface-2); }
.day-nav .day-label {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.04em;
}

/* ---------- Day totals (explicit show/hide) ---------- */
.totals-toggle {
  display: block; width: 100%;
  padding: 12px;
  margin-top: 16px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.totals-toggle:active { background: var(--surface); }
.totals-panel {
  margin-top: 12px;
  padding: 16px;
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border-soft);
}
.totals-panel h3 {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  margin: 0 0 10px;
  font-size: 16px;
  color: var(--text-soft);
}
.totals-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 10px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
}
.totals-grid div { display: flex; justify-content: space-between; }
.totals-grid b { font-weight: 500; }

/* ---------- Library cards (foods/recipes) ---------- */
.lib-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  margin-bottom: 8px;
}
.lib-item .lib-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
}
.lib-item .lib-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

.lib-search {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  margin-bottom: 14px;
}
.lib-search input {
  flex: 1; background: none; border: 0; outline: 0;
  color: var(--text);
  font-size: 15px;
  padding: 6px 0;
}
.lib-search input::placeholder { color: var(--text-muted); }

/* ---------- History ---------- */
.history-day {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  margin-bottom: 6px;
}
.history-day .h-date {
  font-family: var(--font-display);
  font-size: 16px;
}
.history-day .h-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Sheet (bottom modal) ---------- */
#sheet-root { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
#sheet-root.open { pointer-events: auto; }
.sheet-scrim {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity .2s ease;
}
#sheet-root.open .sheet-scrim { opacity: 1; }

.sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 92svh;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid var(--border);
  transform: translateY(100%);
  transition: transform .25s cubic-bezier(.2,.7,.2,1);
  display: flex; flex-direction: column;
  padding-bottom: var(--sab);
}
#sheet-root.open .sheet { transform: translateY(0); }
.sheet-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--surface-3);
  margin: 10px auto 4px;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px 8px;
}
.sheet-head h2 {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  margin: 0;
}
.sheet-head button {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  padding: 8px 10px;
}
.sheet-head button.cancel { color: var(--text-muted); font-weight: 500; }
.sheet-body {
  padding: 4px 18px 18px;
  overflow-y: auto;
  flex: 1;
}

/* ---------- Form fields ---------- */
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}
.field textarea { min-height: 64px; resize: vertical; }

.field-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.03em;
}

/* Combobox dropdown for food/recipe picker */
.combobox { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 5;
}
.combo-list.hidden { display: none; }
.combo-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 15px;
}
.combo-item:last-child { border-bottom: 0; }
.combo-item .tag {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 3px 6px;
  border-radius: 4px;
}
.combo-item:active, .combo-item.active { background: var(--surface-2); }
.combo-item.freeform { color: var(--text-soft); font-style: italic; }

/* Timestamp shifter */
.ts-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-top: 6px;
}
.ts-row input { padding: 11px; font-family: var(--font-mono); font-size: 15px; }
.ts-shift {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px;
  margin-top: 8px;
}
.ts-shift button {
  padding: 9px 0;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-soft);
}
.ts-shift button:active { background: var(--surface-2); }

/* Nutrition preview */
.nutri-preview {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 11px;
  padding: 12px 14px;
  margin: 8px 0 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-soft);
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 4px 14px;
}
.nutri-preview b { color: var(--text); font-weight: 500; }
.nutri-preview .full-row { grid-column: 1 / -1; color: var(--text-muted); font-style: italic; }

.primary-btn {
  display: block; width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #1a0d06;
  border-radius: 12px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
}
.primary-btn:active { transform: scale(0.99); }
.primary-btn:disabled { opacity: 0.4; }
.danger-btn {
  display: block; width: 100%;
  padding: 13px;
  background: transparent;
  color: var(--danger);
  border-radius: 12px;
  border: 1px solid var(--danger);
  font-weight: 600;
  font-size: 14px;
  margin-top: 10px;
}

/* Ingredient list (recipe editor) */
.ing-list { margin-top: 8px; }
.ing-row {
  display: grid; grid-template-columns: 1fr 70px 60px 28px; gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.ing-row input, .ing-row select {
  padding: 10px;
  font-size: 14px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.ing-row .remove {
  width: 28px; height: 36px;
  display: grid; place-items: center;
  color: var(--text-muted);
}
.ing-add {
  margin-top: 8px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-soft);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------- Settings ---------- */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}
.settings-section h3 {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  font-size: 17px;
  margin: 0 0 10px;
  color: var(--text-soft);
}
.settings-section p {
  font-size: 13px; color: var(--text-muted); margin: 0 0 10px;
}

/* ---------- Toast ---------- */
#toast-root {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--sab) + 80px);
  left: 50%; transform: translateX(-50%);
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  animation: toast-in .2s ease forwards, toast-out .2s ease 2.4s forwards;
}
.toast.error { color: var(--danger); border-color: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* ---------- Misc ---------- */
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 24px auto;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.divider {
  height: 1px; background: var(--border-soft);
  margin: 14px 0;
}
