/* ============ SnakApp styles ============ */
:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f3eee6;
  --text: #2b2620;
  --text-muted: #7a7266;
  --border: #e5ddd0;
  --accent: #d96c2c;
  --accent-dark: #b95518;
  --accent-soft: #fbe8da;
  --green: #4a7c59;
  --star: #e8a33d;
  --danger: #b3452f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(43, 38, 32, 0.08), 0 4px 14px rgba(43, 38, 32, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Remove iOS double-tap zoom delay on interactive elements */
button, label, input, select, .tab-btn, .plan-day, .collection-chip {
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* ---- Header ---- */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: env(safe-area-inset-top);
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.app-header h1 { font-size: 1.25rem; margin: 0; }

.tabs { display: flex; gap: 0.25rem; flex: 1; }
.tab-btn {
  background: none;
  border: none;
  padding: 0.5rem 0.9rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  white-space: nowrap;
}
.tab-btn:hover { background: var(--surface-2); }
.tab-btn.active {
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-weight: 600;
}

.header-actions { display: flex; gap: 0.4rem; }

/* ---- Layout ---- */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Toolbar ---- */
.toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.toolbar-sub { margin-top: -0.25rem; }
.toolbar input[type="search"],
.toolbar input[type="url"],
.toolbar input[type="text"] {
  flex: 1;
  min-width: 160px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background: var(--surface);
}
.toolbar select {
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.9rem;
}
.check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---- Buttons ---- */
.btn {
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: none; border-color: transparent; color: var(--danger); }
.btn-danger:hover { text-decoration: underline; }
.btn-small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }

/* ---- Preference chips (Ideas tab) ---- */
.pref-chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}
.pref-chip {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
}
.pref-chip:hover { border-color: var(--accent); }
.pref-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---- Card grid ---- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.9rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card-img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: var(--surface-2);
  display: block;
}
.card-body { padding: 0.7rem 0.85rem; flex: 1; display: flex; flex-direction: column; gap: 0.3rem; }
.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.4rem; }
.card-title { font-weight: 600; font-size: 1rem; margin: 0; }
.fav-btn { background: none; border: none; cursor: pointer; font-size: 1.05rem; padding: 0; line-height: 1; }
.card-meta { font-size: 0.8rem; color: var(--text-muted); }
.stars { color: var(--star); font-size: 0.85rem; letter-spacing: 1px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.tag {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 0.1rem 0.5rem;
  border-radius: 99px;
}
.tag.homemade { background: #e4efe7; color: var(--green); font-weight: 600; }
.card-notes { font-size: 0.82rem; color: var(--text-muted); margin: 0; }
.card-actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.85rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

/* ---- Weekly plan ---- */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}
.plan-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.plan-day h3 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-dark);
}
.plan-day .plan-snack { font-weight: 600; font-size: 0.95rem; }
.plan-day img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-2);
}
.plan-day .card-meta { margin-top: auto; }

.plan-section-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.3rem 0 0.6rem;
}
.plan-section-head h2 { margin: 0; font-size: 1.1rem; }
.plan-day-clickable { cursor: pointer; transition: box-shadow 0.15s; }
.plan-day-clickable:hover { box-shadow: 0 3px 12px rgba(43, 38, 32, 0.18); }
.day-actions { float: right; display: inline-flex; gap: 2px; }
.day-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0 3px;
  line-height: 1;
}
.day-btn:hover { color: var(--accent-dark); }
.plan-empty-day { font-style: italic; }
.saved-row { margin: 0 0 0.8rem; }
.saved-row:empty { display: none; }
.chip-load {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  padding: 0;
}
.chip-load:hover { color: var(--accent-dark); }

/* ---- Daily plan ---- */
.daily-slots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.9rem;
}
.daily-slot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem;
}
.daily-slot h3 {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent-dark);
}
.toolbar input[type="date"] {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.9rem;
  font-family: inherit;
}

/* ---- Product search picker ---- */
.product-pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.6rem;
  margin-top: 0.8rem;
}
.product-pick {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: center;
  text-align: center;
  font-size: 0.85rem;
}
.product-pick img { width: 84px; height: 84px; object-fit: contain; }
.product-pick-noimg { font-size: 2.4rem; line-height: 84px; }
.product-pick:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---- Grocery ---- */
.section-title { font-size: 1.1rem; margin: 0 0 0.6rem; }
.grocery-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.grocery-pick {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.35rem 0.8rem;
  font-size: 0.88rem;
  cursor: pointer;
}
.grocery-pick:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
  font-weight: 600;
}
.grocery-list-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin: 1.4rem 0 0.5rem;
}
.grocery-list-head .section-title { margin: 0; }
.grocery-amt { color: var(--accent-dark); font-weight: 600; }
.grocery-from { font-size: 0.78rem; }
.grocery-detail { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.1rem; font-style: italic; }
#grocery-list { max-width: 640px; }

/* ---- Collections ---- */
.collection-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}
.collection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.collection-header h3 { margin: 0; font-size: 1.05rem; }
.collection-items { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.collection-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface-2);
  border-radius: 99px;
  padding: 0.25rem 0.7rem;
  font-size: 0.85rem;
}
.collection-chip button {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 0.8rem; padding: 0;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 32, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  z-index: 100;
  overflow-y: auto;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 620px;
  width: 100%;
  padding: 1.5rem;
  position: relative;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.modal-close {
  position: absolute;
  top: 0.7rem;
  right: 0.8rem;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
}
.modal-box h2 { margin-top: 0; font-size: 1.25rem; }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-field { display: flex; flex-direction: column; gap: 0.2rem; }
.form-field label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.form-field input, .form-field select, .form-field textarea {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--surface);
}
.form-field textarea { resize: vertical; min-height: 70px; }
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ---- Recipe detail ---- */
.recipe-detail img { max-width: 100%; border-radius: var(--radius); margin-bottom: 0.5rem; }
.recipe-detail .times { display: flex; gap: 1rem; font-size: 0.85rem; color: var(--text-muted); flex-wrap: wrap; }
.recipe-detail h3 { margin-bottom: 0.3rem; font-size: 1rem; }
.recipe-detail ul, .recipe-detail ol { margin: 0.2rem 0 0.8rem; padding-left: 1.3rem; }
.recipe-detail li { margin-bottom: 0.25rem; font-size: 0.92rem; }
.source-link { font-size: 0.82rem; }

/* ---- Database status / settings ---- */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b7b0a4;            /* disconnected */
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.connected { background: #3f9d5c; box-shadow: 0 0 0 3px rgba(63,157,92,0.2); }
.status-dot.needs-permission { background: var(--star); box-shadow: 0 0 0 3px rgba(232,163,61,0.2); }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px rgba(179,69,47,0.2); }

.db-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}
.db-indicator:hover { background: var(--surface-2); }

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem 1.4rem;
  max-width: 560px;
}
.settings-card h2 { margin-top: 0; font-size: 1.15rem; }
.db-status-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 1rem;
}
.db-status-text { font-weight: 600; }
.settings-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.settings-card + .settings-card { margin-top: 1.2rem; }
.cloud-form { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.9rem; }

/* ---- Image upload ---- */
.img-input-row { display: flex; gap: 0.4rem; align-items: center; }
.img-input-row input[type="url"] { flex: 1; }
.img-preview {
  max-width: 120px;
  max-height: 80px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  margin-top: 0.35rem;
  display: block;
}

/* ---- Cook mode checklist ---- */
.cook-mode h3 { margin: 0.8rem 0 0.2rem; font-size: 1rem; }
.checklist { list-style: none; padding-left: 0.2rem; margin: 0.3rem 0 0.8rem; }
.checklist li { margin-bottom: 0.5rem; font-size: 0.95rem; }
.checklist label { display: flex; gap: 0.55rem; align-items: flex-start; cursor: pointer; }
.checklist input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.12rem;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}
.checklist li.done span { text-decoration: line-through; color: var(--text-muted); }

/* ---- Misc ---- */
.empty-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 3rem 1rem;
  font-size: 0.95rem;
}
.import-status {
  font-size: 0.88rem;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-dark);
  margin: 0 0 1rem;
}
.import-status.error { background: #f7e3de; color: var(--danger); }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 99px;
  font-size: 0.9rem;
  z-index: 200;
  box-shadow: var(--shadow);
}

@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }

  /* iOS Safari auto-zooms into any input with font-size < 16px — prevent it */
  input, select, textarea { font-size: 16px !important; }

  /* Title + DB/Export buttons share the first row; tabs become their own
     full-width row that slides sideways instead of spilling off-screen */
  .app-header h1 { order: 1; }
  .header-actions { order: 2; margin-left: auto; }
  .tabs {
    order: 3;
    flex: 1 1 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.15rem;
  }
  .tabs::-webkit-scrollbar { display: none; }
}
