/* Plate — phone-first responsive styles */

/* ⛔ PITFALL GUARD: a "hidden" element must NEVER intercept clicks. The .modal class below
   sets display:flex to center its contents — without this rule, that display:flex would
   silently override the [hidden] attribute the moment .modal is also present in markup,
   leaving an invisible full-page overlay eating every click. This rule wins over any class. */
[hidden] { display: none !important; }

:root {
  --bg: #f7f7f5;
  --card-bg: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e3e3e0;
  --accent: #2f7a4f;
  --accent-dark: #1f5c39;
  --danger: #b3261e;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 40px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--accent);
  color: white;
  padding: 12px 16px;
}
.app-header h1 { margin: 0 0 8px; font-size: 1.3rem; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab-btn {
  flex: 1;
  min-width: 70px;
  padding: 10px 8px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.18);
  color: white;
  font-size: 0.95rem;
  cursor: pointer;
}
.tab-btn.is-active { background: white; color: var(--accent-dark); font-weight: 600; }

main#app { max-width: 640px; margin: 0 auto; padding: 12px; }

.view { display: none; }
.view.is-active { display: block; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card h2 { margin-top: 0; font-size: 1.05rem; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }
input, select {
  display: block;
  width: 100%;
  font-size: 1rem;
  padding: 10px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

.row { display: flex; gap: 8px; align-items: flex-end; }
.row label { flex: 1; }
.row.nav-row { align-items: center; justify-content: space-between; margin: 10px 0; }
.period-label { font-weight: 600; }

.grid5 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }

button {
  font-size: 0.95rem;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  margin-top: 6px;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: #eceae4; color: var(--text); }
button.secondary:hover { background: #ddd9d0; }

.result-list { list-style: none; padding: 0; margin: 8px 0 0; max-height: 320px; overflow-y: auto; }
.result-list li {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.result-list li:hover { background: #f0f4f1; }
.result-list .food-meta { font-size: 0.8rem; color: var(--muted); }

.status-text { font-size: 0.85rem; color: var(--muted); }
.error-text { font-size: 0.85rem; color: var(--danger); }

.amount-toggle { display: flex; gap: 8px; margin: 10px 0; }
.toggle-btn {
  flex: 1;
  background: #eceae4;
  color: var(--text);
  border-radius: 8px;
}
.toggle-btn.is-active { background: var(--accent); color: white; }

.totals-box { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.totals-box .stat { background: #f0f4f1; border-radius: 8px; padding: 8px 10px; }
.totals-box .stat .label { font-size: 0.75rem; color: var(--muted); }
.totals-box .stat .value { font-size: 1.15rem; font-weight: 600; }

.meal-block { margin-bottom: 14px; }
.meal-block h3 { margin-bottom: 6px; text-transform: capitalize; }
.entry-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.entry-row .entry-amt { color: var(--muted); font-size: 0.8rem; }

.breakdown-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.breakdown-table th, .breakdown-table td { text-align: right; padding: 6px 4px; border-bottom: 1px solid var(--border); }
.breakdown-table th:first-child, .breakdown-table td:first-child { text-align: left; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
.modal-inner {
  background: white;
  width: 100%;
  max-width: 480px;
  border-radius: 16px 16px 0 0;
  padding: 18px;
  max-height: 90vh;
  overflow-y: auto;
}

@media (min-width: 480px) {
  .modal { align-items: center; }
  .modal-inner { border-radius: 16px; }
}

/* Header settings (gear) button — sits in the tab row but isn't a view tab */
.tab-btn.settings-btn { flex: 0 0 auto; min-width: 44px; font-size: 1.1rem; }

/* ===================== Home — meal flags ===================== */
.home-header-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.home-header-card h2 { margin: 0; font-size: 1rem; }

.meal-flags { display: flex; flex-direction: column; gap: 12px; }
.meal-flag { margin-bottom: 0; cursor: default; }
.meal-flag-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.meal-flag-header h3 { margin: 0; text-transform: capitalize; }
.flag-count { font-size: 0.8rem; color: var(--muted); }
.flag-stats { grid-template-columns: repeat(3, 1fr); margin-top: 10px; }
.meal-flag-breakdown { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 8px; }

.entry-row .remove-entry-btn, .entry-row.remove-entry-btn {
  margin-top: 0;
  padding: 6px 10px;
  font-size: 0.8rem;
}
.entry-row { align-items: center; }

/* ===================== Settings modal ===================== */
.macro-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 12px; margin: 8px 0; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--text); }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; }

/* ===================== Water tab ===================== */
.water-progress {
  height: 14px;
  background: #eceae4;
  border-radius: 7px;
  overflow: hidden;
  margin: 12px 0;
}
.water-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}
#water-quick-add button { flex: 1; }
#water-entries li { display: flex; justify-content: space-between; align-items: center; }
#water-entries .remove-water-btn { padding: 6px 10px; font-size: 0.8rem; margin-top: 0; }
