:root {
  --bg: #fafafa;
  --card: #ffffff;
  --border: #e2e2e2;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --accent: #2f6f4f;
  --danger: #b3261e;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over component rules like `.overlay`
   that set an explicit `display` (otherwise `display:flex` keeps it shown). */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  /* Respect the iPhone safe areas. */
  padding-bottom: env(safe-area-inset-bottom);
}

/* Mobile-first: single column, comfortable tap targets. */
.main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

a { color: var(--accent); text-decoration: none; }

button,
.btn,
.btn-secondary,
.btn-danger {
  font: inherit;
  min-height: 44px;
  padding: 0 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
button:active, .btn:active { opacity: 0.85; }

/* Nav */
.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem max(0.75rem, env(safe-area-inset-left));
  padding-top: max(0.5rem, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.nav a {
  padding: 0.5rem 0.75rem;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
}
.nav a.active { color: var(--text); background: var(--bg); }
.nav-logout { margin-left: auto; }
.nav-logout button { min-height: 40px; border: none; background: transparent; color: var(--muted); }

h1 { font-size: 1.5rem; margin: 0.25rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 0; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.page-head h1 { margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.form { display: flex; flex-direction: column; gap: 0.85rem; }
.form label { display: flex; flex-direction: column; gap: 0.35rem; font-weight: 600; font-size: 0.95rem; }
.form input,
.form textarea {
  font: inherit;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  width: 100%;
}
.form textarea { resize: vertical; }
.form .checkbox { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 400; }
.form .checkbox input { width: auto; }
.form-actions { display: flex; gap: 0.5rem; }
.error { color: var(--danger); margin: 0; font-weight: 600; }

/* Search */
.search { position: relative; margin-bottom: 1rem; }
.search input { width: 100%; font: inherit; padding: 0.7rem; border: 1px solid var(--border); border-radius: var(--radius); }
.search-results {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}
.search-results li { border-bottom: 1px solid var(--border); }
.search-results li:last-child { border-bottom: none; }
.search-results a, .search-results button {
  display: flex;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 0.75rem;
  min-height: 48px;
  color: var(--text);
}
.search-results .none { padding: 0.75rem; color: var(--muted); }

/* Thumbnails */
.thumb {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex: 0 0 auto;
  background: #eee;
}
.thumb-empty { display: inline-block; }

/* Recipe list */
.recipe-list { list-style: none; margin: 0; padding: 0; }
.recipe-row { border-bottom: 1px solid var(--border); }
.recipe-row a { display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 0.25rem; min-height: 48px; color: var(--text); }
.empty { color: var(--muted); padding: 0.5rem 0.25rem; }

.recipe-photo { width: 100%; max-height: 60vh; object-fit: cover; border-radius: var(--radius); margin-bottom: 1rem; }
.markdown { margin-bottom: 1.5rem; }
.markdown h1, .markdown h2, .markdown h3 { margin: 1rem 0 0.5rem; }
.markdown p { margin: 0.5rem 0; }
.markdown ul { padding-left: 1.25rem; }
.markdown code { background: #f0f0f0; padding: 0.1rem 0.3rem; border-radius: 4px; }
.danger-form { margin-top: 1rem; }

/* Agenda */
.agenda { display: flex; flex-direction: column; gap: 1rem; }
.day {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.badge { font-size: 0.7rem; background: var(--accent); color: #fff; padding: 0.1rem 0.4rem; border-radius: 999px; vertical-align: middle; }
.add-btn { min-height: 36px; padding: 0 0.7rem; }

.plan-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.plan-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
.plan-item-link { display: flex; align-items: center; gap: 0.6rem; flex: 1; min-width: 0; color: var(--text); }
.plan-item-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-item-actions { display: flex; gap: 0.25rem; flex: 0 0 auto; }
.icon-btn {
  min-height: 40px;
  min-width: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

/* "maybe" entries: dimmed with a dashed border. */
.plan-item.maybe {
  opacity: 0.55;
  border-style: dashed;
  border-width: 1.5px;
}

.load-more { display: flex; justify-content: center; margin-top: 1rem; }

/* Add-to-day overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.overlay-card {
  background: var(--card);
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.overlay-head { display: flex; align-items: center; justify-content: space-between; }
.overlay-card input { font: inherit; padding: 0.7rem; border: 1px solid var(--border); border-radius: var(--radius); }
.overlay-card .search-results { overflow-y: auto; }

/* Wider screens: the same column, just a bit more breathing room. */
@media (min-width: 700px) {
  .main { padding-top: 1.5rem; }
  .overlay { align-items: center; }
  .overlay-card { border-radius: var(--radius); }
}
