:root {
  --teal: #0f4c46;
  --teal-dark: #0a3532;
  --gold: #c9a227;
  --gold-light: #e6c757;
  --papyrus: #f7f2e4;
  --paper: #fffdf7;
  --ink: #2a2620;
  --muted: #7a7263;
  --line: #e7ddc4;
  --terracotta: #b5502f;
  --danger: #b3261e;
  --radius: 14px;
  --nav-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--papyrus);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

h1, h2, h3 { margin: 0; }

button {
  font: inherit;
  cursor: pointer;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--teal);
  color: white;
  padding-top: max(12px, env(safe-area-inset-top, 0px));
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 40px; height: 40px; border-radius: 50%; }
.brand-text h1 { font-size: 1.25rem; letter-spacing: 0.03em; color: var(--gold-light); font-family: Georgia, "Times New Roman", serif; }
.brand-text p { font-size: 0.72rem; margin: 0; opacity: 0.85; }

.icon-btn {
  background: rgba(255,255,255,0.12);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: rgba(255,255,255,0.22); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  background: var(--paper);
  border-top: 1px solid var(--line);
  height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}
.nav-btn.active { color: var(--teal); font-weight: 600; }

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--terracotta);
  color: white;
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: 0 6px 16px rgba(0,0,0,0.25);
  z-index: 15;
}
.fab:active { transform: scale(0.95); }
.fab[hidden] { display: none; }

/* View */
.view {
  padding: 14px 14px 24px;
  max-width: 720px;
  margin: 0 auto;
}

/* Search / filters */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.search-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 1rem;
}
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-size: 0.85rem;
}
.chip.active { background: var(--teal); border-color: var(--teal); color: white; }

/* Recipe cards */
.card-grid { display: flex; flex-direction: column; gap: 12px; }
.recipe-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.recipe-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.recipe-card h3 { font-size: 1.05rem; }
.badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--gold-light);
  color: var(--teal-dark);
  font-weight: 700;
  white-space: nowrap;
}
.badge.repas { background: #d9e6d0; color: #33512a; }
.recipe-card .ingredients-preview {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}
.empty-state svg { opacity: 0.5; margin-bottom: 10px; }
.empty-state p { margin: 4px 0; }
.empty-state .btn { margin-top: 14px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
}
.btn-primary { background: var(--teal); color: white; }
.btn-primary:active { background: var(--teal-dark); }
.btn-gold { background: var(--gold); color: var(--teal-dark); }
.btn-outline { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid #e8bdb8; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* Detail view */
.detail-header { margin-bottom: 12px; }
.back-link {
  background: none;
  border: none;
  color: var(--teal);
  font-weight: 600;
  padding: 8px 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.detail-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-top: 6px; }
.detail-title-row h2 { font-family: Georgia, serif; }
.ingredient-list { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.ingredient-list li {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
}
.section-title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 18px 0 8px; }
.notes-block { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; font-size: 0.92rem; }
.action-row { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

/* Journal */
.batch-item {
  display: flex;
  gap: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  align-items: center;
}
.batch-thumb {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--line);
  flex-shrink: 0;
}
.batch-thumb-placeholder {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  background: var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
}
.batch-info { flex: 1; min-width: 0; }
.batch-info h4 { font-size: 0.95rem; margin: 0 0 3px; }
.batch-meta { font-size: 0.78rem; color: var(--muted); margin: 0; }
.batch-lot { font-size: 0.8rem; color: var(--teal-dark); font-weight: 600; margin-top: 2px; }
.batch-del {
  background: none;
  border: none;
  color: var(--muted);
  padding: 8px;
  flex-shrink: 0;
}

/* Settings */
.settings-list { display: flex; flex-direction: column; gap: 10px; }
.settings-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.settings-card h3 { font-size: 1rem; margin-bottom: 4px; }
.settings-card p { font-size: 0.85rem; color: var(--muted); margin: 4px 0 12px; }
.stat-row { display: flex; gap: 18px; margin: 8px 0 16px; }
.stat { text-align: center; }
.stat strong { display: block; font-size: 1.4rem; color: var(--teal); font-family: Georgia, serif; }
.stat span { font-size: 0.75rem; color: var(--muted); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 15, 0.5);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  background: var(--papyrus);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 18px 18px calc(24px + env(safe-area-inset-bottom, 0px));
  animation: sheet-up 0.18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(16px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-header h2 { font-size: 1.1rem; font-family: Georgia, serif; }
.modal-close { background: none; border: none; font-size: 1.4rem; color: var(--muted); padding: 4px 8px; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 6px; color: var(--teal-dark); }
.field input[type=text],
.field input[type=date],
.field input[type=number],
.field textarea,
.field select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 1rem;
  font-family: inherit;
}
.field textarea { min-height: 70px; resize: vertical; }
.field-hint { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }

.ingredient-row { display: flex; gap: 8px; margin-bottom: 8px; }
.ingredient-row input { flex: 1; }
.ingredient-row .row-del {
  background: none; border: 1px solid var(--line); border-radius: 10px;
  width: 42px; color: var(--danger); flex-shrink: 0;
}
.add-ingredient-btn { margin-top: 2px; }

.category-toggle { display: flex; gap: 8px; }
.category-toggle button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-weight: 600;
}
.category-toggle button.active { background: var(--teal); border-color: var(--teal); color: white; }

/* Photo capture */
.photo-capture {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.photo-preview-wrap {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: var(--paper);
  border: 1px dashed var(--line);
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-preview-wrap img { width: 100%; display: block; max-height: 320px; object-fit: contain; }
.photo-placeholder { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 0.88rem; }
.photo-btn-row { display: flex; gap: 10px; }
.photo-btn-row .btn { flex: 1; }
input[type=file].hidden-input { display: none; }

/* Photo viewer */
.photo-viewer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}
.photo-viewer img { max-width: 94%; max-height: 78vh; border-radius: 8px; }
.photo-viewer .pv-close {
  position: absolute; top: max(16px, env(safe-area-inset-top,0px)); right: 16px;
  background: rgba(255,255,255,0.15); border: none; color: white;
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.3rem;
}
.photo-viewer .pv-caption { color: white; margin-top: 14px; text-align: center; padding: 0 20px; font-size: 0.9rem; opacity: 0.9; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--teal-dark);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 70;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  animation: toast-in 0.15s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.import-input { display: none; }

@media (min-width: 720px) {
  .bottom-nav { display: none; }
  body { padding-bottom: 0; }
  .fab { bottom: 24px; }
  .view { padding-top: 20px; }
}
