:root {
  --bg: #f6f1e8;
  --surface: #fffdf9;
  --surface-2: #efe8dd;
  --ink: #1f2a22;
  --muted: #6d776f;
  --line: #dcd3c6;
  --accent: #2f6f4e;
  --accent-dark: #24583e;
  --accent-soft: #dce9df;
  --danger: #a84235;
  --shadow: 0 16px 40px rgba(49, 52, 45, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgba(255,255,255,.8), transparent 35%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.app-shell { max-width: 1200px; margin: 0 auto; padding: 0 28px 70px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 0; border-bottom: 1px solid rgba(93,87,77,.14);
}
.brand { display: flex; gap: 12px; align-items: center; border: 0; background: transparent; color: inherit; text-align: left; padding: 0; }
.brand-mark { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; background: var(--accent); color: white; font-weight: 900; font-size: 21px; box-shadow: 0 8px 20px rgba(47,111,78,.18); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: -.02em; }
.brand small { color: var(--muted); margin-top: 2px; }
.top-actions { display: flex; gap: 8px; }

.view { display: none; animation: rise .2s ease; }
.view.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.hero { display: grid; grid-template-columns: 1fr auto; gap: 48px; align-items: end; padding: 76px 0 56px; }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: 12px; font-weight: 800; color: var(--accent); margin: 0 0 12px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-family: Georgia, "Times New Roman", serif; font-size: clamp(46px, 7vw, 84px); line-height: .95; letter-spacing: -.055em; margin-bottom: 22px; max-width: 820px; }
.hero-copy { max-width: 720px; color: var(--muted); font-size: 18px; line-height: 1.7; margin-bottom: 30px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.database-stat { min-width: 170px; aspect-ratio: 1; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid rgba(90,82,73,.08); }
.database-stat span { font-size: 48px; font-family: Georgia, serif; line-height: 1; }
.database-stat small { margin-top: 8px; max-width: 90px; text-align: center; color: var(--muted); line-height: 1.3; }

.btn { border: 1px solid transparent; border-radius: 999px; padding: 11px 18px; font-weight: 750; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: white; box-shadow: 0 8px 20px rgba(47,111,78,.14); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-danger { background: var(--danger); color: white; }
.btn-large { padding: 15px 22px; }
.text-button, .back-button { border: 0; background: transparent; color: var(--accent); font-weight: 750; padding: 4px; }

.day-section { padding-top: 18px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 20px; }
.section-heading h2 { font-family: Georgia, serif; font-size: 36px; letter-spacing: -.03em; margin: 0; }
.day-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.meal-card { position: relative; min-height: 235px; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; overflow: hidden; }
.meal-card::after { content: attr(data-index); position: absolute; right: 12px; bottom: -24px; font-family: Georgia, serif; font-size: 92px; color: rgba(47,111,78,.055); }
.meal-time { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: 10px; font-weight: 850; margin-bottom: 18px; }
.meal-card h3 { font-size: 20px; line-height: 1.15; letter-spacing: -.025em; margin-bottom: 10px; }
.meal-card p { color: var(--muted); font-size: 13px; line-height: 1.45; margin-bottom: 14px; }
.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; position: relative; z-index: 1; }
.tag { display: inline-flex; padding: 5px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-dark); font-size: 11px; font-weight: 750; }
.card-link { margin-top: 14px; align-self: flex-start; border: 0; padding: 0; background: transparent; color: var(--accent); font-weight: 800; position: relative; z-index: 1; }
.missing-card { border-style: dashed; background: rgba(255,255,255,.35); justify-content: center; }
.missing-card h3 { color: var(--muted); }

.empty-state { text-align: center; padding: 64px 22px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); background: rgba(255,255,255,.22); }
.empty-state[hidden], .day-grid:empty { display: none; }
.empty-state h3 { color: var(--ink); margin-bottom: 8px; }
.empty-icon { font-size: 40px; margin-bottom: 12px; }

.page-heading { padding: 58px 0 28px; }
.page-heading h1 { font-size: clamp(42px, 6vw, 68px); margin: 14px 0 14px; }
.page-heading > p:not(.eyebrow) { color: var(--muted); font-size: 17px; }
.back-button { margin-bottom: 30px; }
.browse-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.browse-heading .back-button { margin-bottom: 30px; }

.food-form { max-width: 900px; }
.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.field { display: grid; gap: 9px; }
.field-wide { grid-column: 1 / -1; }
.field > span, legend { font-weight: 800; font-size: 14px; }
fieldset.field { border: 0; padding: 0; margin: 0; }
.field-help, .field small { color: var(--muted); font-size: 12px; margin: -3px 0 0; }
input, textarea, select { width: 100%; border: 1px solid var(--line); background: #fffefa; color: var(--ink); border-radius: 14px; padding: 12px 14px; outline: none; transition: box-shadow .15s ease, border-color .15s ease; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(47,111,78,.09); }
.checkbox-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.check-pill { position: relative; }
.check-pill input { position: absolute; opacity: 0; pointer-events: none; }
.check-pill span { min-height: 64px; display: grid; place-items: center; text-align: center; border: 1px solid var(--line); border-radius: 15px; padding: 10px; color: var(--muted); font-size: 12px; font-weight: 750; cursor: pointer; background: #fffefa; }
.check-pill input:checked + span { background: var(--accent-soft); color: var(--accent-dark); border-color: #a9c5b2; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline-fields label { display: grid; gap: 7px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 0 60px; }

.filters { display: grid; grid-template-columns: minmax(260px, 1fr) 220px 220px; gap: 10px; margin: 6px 0 24px; }
.recipe-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.recipe-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-height: 245px; display: flex; flex-direction: column; box-shadow: 0 9px 26px rgba(49,52,45,.045); }
.recipe-card h3 { font-size: 22px; line-height: 1.15; margin: 8px 0 10px; }
.recipe-card .category-line { color: var(--accent); font-size: 12px; font-weight: 800; }
.recipe-card .recipe-excerpt { color: var(--muted); font-size: 14px; line-height: 1.55; }
.recipe-card-actions { display: flex; gap: 12px; margin-top: 16px; align-items: center; }
.recipe-card-actions button { border: 0; padding: 0; background: transparent; color: var(--accent); font-weight: 800; }
.recipe-card-actions .delete-link { color: var(--danger); margin-left: auto; }

.detail-card { background: var(--surface); border: 1px solid var(--line); border-radius: 28px; padding: clamp(24px, 5vw, 54px); box-shadow: var(--shadow); max-width: 950px; }
.detail-card h1 { font-size: clamp(44px, 7vw, 72px); margin: 10px 0 18px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); margin-bottom: 30px; }
.detail-section { border-top: 1px solid var(--line); padding-top: 24px; margin-top: 24px; }
.detail-section h2 { font-family: Georgia, serif; font-size: 28px; }
.detail-section pre { white-space: pre-wrap; font: inherit; line-height: 1.7; color: #3e473f; margin: 0; }
.detail-actions { display: flex; gap: 10px; margin-top: 30px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: #1f2a22; color: white; padding: 11px 16px; border-radius: 999px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.confirm-dialog { border: 0; border-radius: 22px; padding: 0; max-width: 420px; box-shadow: var(--shadow); background: var(--surface); color: var(--ink); }
.confirm-dialog::backdrop { background: rgba(28,34,29,.35); backdrop-filter: blur(3px); }
.confirm-dialog form { padding: 26px; }
.confirm-dialog p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 980px) {
  .day-grid { grid-template-columns: repeat(2, 1fr); }
  .meal-card:last-child { grid-column: 1 / -1; }
  .recipe-grid { grid-template-columns: repeat(2, 1fr); }
  .checkbox-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 720px) {
  .app-shell { padding: 0 16px 48px; }
  .topbar { align-items: flex-start; gap: 12px; }
  .top-actions { flex-direction: column; align-items: stretch; }
  .top-actions .btn { padding: 8px 12px; font-size: 12px; }
  .hero { grid-template-columns: 1fr; padding-top: 52px; gap: 20px; }
  .database-stat { min-width: 0; width: 130px; justify-self: start; }
  .hero-actions { flex-direction: column; align-items: stretch; }
  .day-grid, .recipe-grid { grid-template-columns: 1fr; }
  .meal-card:last-child { grid-column: auto; }
  .browse-heading { align-items: flex-start; flex-direction: column; }
  .filters { grid-template-columns: 1fr; }
  .form-card { grid-template-columns: 1fr; padding: 20px; }
  .checkbox-grid { grid-template-columns: 1fr 1fr; }
  .inline-fields { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
}

/* Supabase + image additions */
.status-pill { align-self: center; display:inline-flex; align-items:center; padding:8px 11px; border-radius:999px; border:1px solid var(--line); font-size:11px; font-weight:800; color:var(--muted); background:var(--surface); }
.status-pill.ok { color:var(--accent-dark); background:var(--accent-soft); border-color:#b9cfbf; }
.status-pill.error { color:var(--danger); background:#f7e4e0; border-color:#e5b9b1; }
.btn:disabled { opacity:.55; cursor:wait; transform:none; }
.image-picker { display:grid; grid-template-columns:minmax(0,1fr) minmax(180px,280px); gap:16px; align-items:stretch; }
.image-upload-zone { min-height:170px; border:1.5px dashed var(--line); border-radius:18px; display:flex; flex-direction:column; align-items:center; justify-content:center; text-align:center; padding:22px; background:#fffefa; cursor:pointer; }
.image-upload-zone:hover { border-color:var(--accent); background:var(--accent-soft); }
.image-upload-zone strong { color:var(--accent); }
.image-upload-zone small { margin-top:7px; color:var(--muted); }
.image-upload-zone input { position:absolute; width:1px; height:1px; opacity:0; pointer-events:none; }
.image-preview-wrap { position:relative; min-height:170px; }
.image-preview-wrap img { width:100%; height:170px; object-fit:cover; border-radius:18px; border:1px solid var(--line); display:block; }
.image-preview-wrap .btn { position:absolute; right:8px; bottom:8px; background:rgba(255,253,249,.92); }
.meal-image { width:calc(100% + 36px); height:105px; object-fit:cover; margin:-18px -18px 16px; }
.recipe-image { width:calc(100% + 40px); height:165px; object-fit:cover; margin:-20px -20px 16px; border-radius:var(--radius) var(--radius) 0 0; }
.detail-image { width:100%; max-height:500px; object-fit:cover; border-radius:20px; margin-bottom:28px; }
@media (max-width:720px){ .image-picker{grid-template-columns:1fr;} .status-pill{display:none;} }

/* Multi-user auth, recipebook switching, sharing */
[hidden] { display: none !important; }
.auth-shell { min-height:100vh; display:grid; place-items:center; padding:28px; }
.auth-card { width:min(100%, 520px); background:var(--surface); border:1px solid var(--line); border-radius:30px; padding:clamp(26px,5vw,48px); box-shadow:var(--shadow); }
.auth-brand { display:flex; align-items:center; gap:12px; margin-bottom:42px; }
.auth-brand strong, .auth-brand small { display:block; }
.auth-brand small { color:var(--muted); margin-top:2px; }
.auth-card h1 { font-size:clamp(46px,9vw,66px); margin-bottom:16px; }
.auth-copy { color:var(--muted); line-height:1.65; margin-bottom:24px; }
.auth-tabs { display:grid; grid-template-columns:1fr 1fr; gap:6px; padding:5px; border-radius:999px; background:var(--surface-2); margin-bottom:22px; }
.auth-tab { border:0; background:transparent; padding:10px 14px; border-radius:999px; color:var(--muted); font-weight:800; }
.auth-tab.active { background:var(--surface); color:var(--ink); box-shadow:0 4px 12px rgba(49,52,45,.08); }
.auth-form { display:grid; gap:15px; }
.auth-form .btn { margin-top:4px; }
.auth-message { min-height:24px; margin:16px 0 0; font-size:13px; color:var(--accent); }
.auth-message.error { color:var(--danger); }
.auth-footnote { margin:24px 0 0; padding-top:20px; border-top:1px solid var(--line); color:var(--muted); font-size:12px; line-height:1.55; }

.book-switcher { min-width:210px; }
.book-switcher select { padding:9px 34px 9px 12px; border-radius:999px; font-size:12px; font-weight:750; background:var(--surface); }
.view-only-label { margin-left:auto; color:var(--muted); font-size:12px; font-weight:750; }

.manage-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; padding-bottom:60px; }
.manage-card { background:var(--surface); border:1px solid var(--line); border-radius:var(--radius); padding:24px; box-shadow:0 10px 30px rgba(49,52,45,.045); }
.manage-card-wide { grid-column:1 / -1; }
.manage-card h2 { font-family:Georgia,"Times New Roman",serif; font-size:30px; letter-spacing:-.03em; margin-bottom:16px; }
.muted { color:var(--muted); }
.share-code-box { display:flex; align-items:center; justify-content:space-between; gap:14px; padding:16px; border:1px solid var(--line); border-radius:16px; background:#fffefa; margin:18px 0 10px; }
.share-code-box small, .share-code-box strong { display:block; }
.share-code-box small { color:var(--muted); margin-bottom:4px; }
.share-code-box strong { font-family:ui-monospace,SFMono-Regular,Menlo,monospace; letter-spacing:.08em; font-size:19px; }
.compact-form { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:8px; margin-bottom:18px; }
.share-form { display:grid; grid-template-columns:minmax(0,1fr) 120px auto; gap:8px; margin-top:14px; }
.manage-list { display:grid; gap:12px; }
.manage-item, .household-card { border:1px solid var(--line); border-radius:18px; padding:16px; background:#fffefa; }
.manage-item.compact { padding:14px 16px; }
.manage-item-heading { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.manage-item-heading strong, .manage-item-heading small { display:block; }
.manage-item-heading small { color:var(--muted); margin-top:4px; }
.role-badge { white-space:nowrap; padding:5px 8px; border-radius:999px; background:var(--accent-soft); color:var(--accent-dark); font-size:10px; font-weight:850; text-transform:uppercase; letter-spacing:.06em; }
.member-list { display:grid; gap:7px; margin-top:14px; padding-top:12px; border-top:1px solid var(--line); font-size:13px; }
.member-row { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.member-row small { color:var(--muted); margin-left:5px; }
.danger-text { color:var(--danger); }
.household-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
.household-card { padding:18px; }
.household-book-form { margin:10px 0 0; }
.mini-book-list { display:flex; flex-wrap:wrap; gap:7px; margin-top:14px; }
.mini-book-list button { border:1px solid var(--line); border-radius:999px; background:var(--surface); color:var(--accent); padding:7px 10px; font-size:12px; font-weight:750; }
.empty-inline { grid-column:1 / -1; padding:28px; border:1px dashed var(--line); border-radius:18px; color:var(--muted); text-align:center; }

@media (max-width: 1040px) {
  .topbar { align-items:flex-start; }
  .top-actions { flex-wrap:wrap; justify-content:flex-end; }
  .book-switcher { flex-basis:100%; }
  .book-switcher select { width:100%; }
}
@media (max-width: 820px) {
  .manage-grid, .household-grid { grid-template-columns:1fr; }
  .manage-card-wide { grid-column:auto; }
  .share-form { grid-template-columns:1fr; }
  .compact-form { grid-template-columns:1fr; }
}
@media (max-width: 720px) {
  .auth-shell { padding:16px; }
  .auth-card { border-radius:22px; padding:24px 20px; }
  .auth-brand { margin-bottom:30px; }
  .topbar { flex-direction:column; }
  .top-actions { width:100%; display:grid; grid-template-columns:1fr 1fr; }
  .top-actions .book-switcher { grid-column:1 / -1; }
  .top-actions .status-pill { display:none; }
}
