/* ============================================================
   🌿 My Health Tracker — style.css
   Mobile-first, green & natural palette
   ============================================================ */

/* ── Reset & Variables ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-900: #1a4d2e;
  --green-700: #2d7a4f;
  --green-500: #4caf78;
  --green-200: #b7dfc8;
  --green-50:  #f0f7f2;
  --teal:      #2a9d8f;
  --amber:     #f4a261;
  --red:       #e76f51;
  --blue:      #457b9d;
  --gray-800:  #2d2d2d;
  --gray-600:  #555;
  --gray-400:  #999;
  --gray-100:  #f5f5f5;
  --white:     #fff;
  --shadow:    0 2px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 6px 24px rgba(0,0,0,.15);
  --radius:    12px;
  --radius-sm: 8px;
  --nav-h:     64px;
  --header-h:  56px;
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--green-50);
  color: var(--gray-800);
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}

/* ── App Header ─────────────────────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--green-700);
  color: var(--white);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  box-shadow: var(--shadow);
}
.app-header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: .3px; }
.app-header .subtitle { font-size: .75rem; opacity: .8; }

/* ── Bottom Nav ─────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--white);
  border-top: 1px solid var(--green-200);
  display: flex;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: none; background: none; cursor: pointer;
  color: var(--gray-400); font-size: .6rem; font-weight: 600;
  padding: 6px 2px; transition: color .2s;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn .tab-icon { font-size: 1.3rem; line-height: 1; }
.tab-btn.active { color: var(--green-700); }
.tab-btn.active .tab-icon { transform: translateY(-2px); }

/* ── Pages ──────────────────────────────────────────────────── */
.page { display: none; padding: 16px; max-width: 900px; margin: 0 auto; }
.page.active { display: block; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-header h2 { font-size: 1.25rem; color: var(--green-900); }

/* ── FAB ────────────────────────────────────────────────────── */
#fab {
  position: fixed; right: 20px; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  z-index: 150;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--green-700); color: var(--white);
  border: none; font-size: 1.6rem; cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
#fab:active { transform: scale(.93); background: var(--green-900); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--white); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-actions { display: flex; gap: 4px; }

.entry-time { font-size: .8rem; color: var(--gray-400); font-weight: 600; }

/* ── Chips ──────────────────────────────────────────────────── */
.entry-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 600;
  background: var(--green-50); color: var(--green-900);
  border: 1px solid var(--green-200);
}
.chip.red    { background: #fde8e4; border-color: #f5b8ae; color: #c0392b; }
.chip.orange { background: #fef0e6; border-color: #f9c8a0; color: #c55a11; }
.chip.yellow { background: #fefbe6; border-color: #f9e6a0; color: #8a6500; }
.chip.green  { background: #e8f5ee; border-color: #a0d4b4; color: #1a6b37; }
.chip.great  { background: #d4f0e1; border-color: #7dc5a0; color: #0d5228; }

.symptoms { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.tag {
  background: var(--green-200); color: var(--green-900);
  padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 600;
}

.entry-notes { font-size: .85rem; color: var(--gray-600); line-height: 1.5; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 600; border: none; cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:active { opacity: .85; transform: scale(.97); }
.btn-primary { background: var(--green-700); color: var(--white); }
.btn-ghost { background: none; border: 1.5px solid var(--gray-400); color: var(--gray-600); }
.btn-danger { background: var(--red); color: var(--white); }
.icon-btn {
  background: none; border: none; cursor: pointer; font-size: 1rem;
  padding: 4px; border-radius: 6px; opacity: .7;
  transition: opacity .15s; -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { opacity: 1; }

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--white); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 640px;
  max-height: 92vh; overflow-y: auto;
  padding: 0 0 env(safe-area-inset-bottom);
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(40px); } to { transform: translateY(0); } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--green-200);
  position: sticky; top: 0; background: var(--white); z-index: 1;
}
.modal-header h3 { font-size: 1.05rem; color: var(--green-900); }
.close-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--gray-400); padding: 4px; }

.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 14px 20px; border-top: 1px solid var(--green-200);
  position: sticky; bottom: 0; background: var(--white);
}

/* ── Forms ──────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 20px; }
.form-grid label { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; font-weight: 600; color: var(--gray-600); }
.form-grid .full-width { grid-column: 1 / -1; }

input[type="text"], input[type="number"], input[type="date"],
input[type="time"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--green-200); border-radius: var(--radius-sm);
  font-size: .9rem; font-family: inherit;
  background: var(--white); color: var(--gray-800);
  appearance: none; -webkit-appearance: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--green-700);
  box-shadow: 0 0 0 3px rgba(45,122,79,.15);
}
textarea { resize: vertical; min-height: 70px; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23555' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.data-table {
  width: 100%; border-collapse: collapse; font-size: .82rem;
  min-width: 480px;
}
.data-table th {
  background: var(--green-50); color: var(--green-900);
  padding: 10px 10px; text-align: left; font-weight: 700; font-size: .75rem;
  border-bottom: 2px solid var(--green-200); white-space: nowrap;
}
.data-table td { padding: 10px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--green-50); }
.data-table .num { text-align: center; }
.notes-cell { max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Score colors in table ───────────────────────────────────── */
.score-green { color: #1a6b37; font-weight: 700; }
.score-yellow { color: #8a6500; font-weight: 700; }
.score-red { color: #c0392b; font-weight: 700; }

/* ── Stats row ──────────────────────────────────────────────── */
.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--white); border-radius: var(--radius);
  padding: 14px 10px; text-align: center;
  box-shadow: var(--shadow); border: 1px solid var(--green-200);
}
.stat-num { font-size: 1.6rem; font-weight: 800; color: var(--green-700); line-height: 1; }
.stat-num small { font-size: .7rem; font-weight: 600; margin-left: 1px; }
.stat-label { font-size: .7rem; color: var(--gray-600); margin-top: 4px; }

/* ── Supplements ─────────────────────────────────────────────── */
.supp-grid { display: flex; flex-direction: column; gap: 12px; }
.supp-card { background: var(--white); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.supp-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.supp-name { font-weight: 700; font-size: .95rem; color: var(--green-900); }
.supp-meta { font-size: .78rem; color: var(--gray-400); margin-top: 2px; }
.supp-dots { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.dot-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid var(--green-200); background: var(--white);
  font-size: .75rem; font-weight: 700; cursor: pointer;
  color: var(--gray-400); transition: all .15s;
  -webkit-tap-highlight-color: transparent;
  display: flex; align-items: center; justify-content: center;
}
.dot-btn.today { border-color: var(--green-700); }
.dot-btn.taken { background: var(--green-700); border-color: var(--green-700); color: var(--white); }
.adherence-bar { height: 5px; background: var(--green-100, #e0f0e8); border-radius: 3px; overflow: hidden; }
.adherence-fill { height: 100%; background: var(--green-500); border-radius: 3px; transition: width .3s; }
.adherence-pct { font-size: .72rem; color: var(--gray-400); margin-top: 4px; text-align: right; }

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 700;
}
.badge.green { background: #d4f0e1; color: #0d5228; }
.badge.red { background: #fde8e4; color: #c0392b; }
.badge.blue { background: #dceef8; color: #1a4a6b; }
.badge.gray { background: var(--gray-100); color: var(--gray-600); }

/* ── Appointments ────────────────────────────────────────────── */
.appt-card { margin-bottom: 10px; }
.appt-header { display: flex; justify-content: space-between; align-items: flex-start; }
.appt-date { font-size: .8rem; color: var(--gray-400); }
.appt-title { font-weight: 700; font-size: .95rem; color: var(--green-900); }
.appt-reason, .appt-notes, .appt-cost { font-size: .82rem; color: var(--gray-600); margin-top: 6px; }
.active-tag { color: var(--green-700); font-weight: 700; font-size: .78rem; }

/* ── Phase tags ──────────────────────────────────────────────── */
.phase-tag { padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; }
.phase-menstrual { background: #fde8e4; color: #c0392b; }
.phase-follicular { background: #fef9e6; color: #8a6500; }
.phase-ovulation { background: #e8f5ee; color: #1a6b37; }
.phase-luteal { background: #e8e4fd; color: #4a2090; }

/* ── Type tags ───────────────────────────────────────────────── */
.type-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

/* ── Section title ───────────────────────────────────────────── */
.section-title { font-size: .85rem; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: .5px; margin: 16px 0 10px; }

/* ── Loading / Empty / Error ─────────────────────────────────── */
.loading { color: var(--gray-400); text-align: center; padding: 40px; font-size: .9rem; }
.empty { color: var(--gray-400); text-align: center; padding: 40px 20px; font-size: .9rem; line-height: 1.6; }
.error { color: var(--red); text-align: center; padding: 20px; font-size: .9rem; background: #fde8e4; border-radius: var(--radius); }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed; top: calc(var(--header-h) + 10px); left: 50%; transform: translateX(-50%);
  z-index: 900; padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 600; white-space: nowrap;
  animation: slideDown .25s ease, fadeOut .3s ease 2.7s forwards;
  box-shadow: var(--shadow-lg);
}
.toast-success { background: var(--green-700); color: var(--white); }
.toast-error { background: var(--red); color: var(--white); }
@keyframes slideDown { from { transform: translateX(-50%) translateY(-20px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; } }

/* ── Home (Welcome) Screen ──────────────────────────────────── */
.page-home { padding: 0 0 16px; max-width: none; }

.home-greeting { padding: 18px 20px 12px; }
.greeting-text { font-size: 1.5rem; font-weight: 800; color: var(--green-900); line-height: 1.1; }
.greeting-date { font-size: .85rem; color: var(--gray-600); margin-top: 4px; font-weight: 500; }

.swiper {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
  scrollbar-width: none; -ms-overflow-style: none;
  scroll-behavior: smooth;
}
.swiper::-webkit-scrollbar { display: none; }
.swiper-panel {
  flex: 0 0 100%; width: 100%;
  scroll-snap-align: start; scroll-snap-stop: always;
  padding: 8px 16px 24px;
}
.panel-title {
  font-size: .8rem; font-weight: 700; color: var(--gray-600);
  text-transform: uppercase; letter-spacing: .8px;
  margin-bottom: 14px; padding-left: 4px;
}

.swiper-dots {
  display: flex; justify-content: center; gap: 8px;
  padding: 4px 0 12px;
}
.swiper-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green-200); border: none; cursor: pointer;
  transition: all .2s; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.swiper-dot.active { background: var(--green-700); width: 24px; border-radius: 4px; }

/* ── Today panel ────────────────────────────────────────────── */
.today-hero {
  background: linear-gradient(135deg, var(--green-700), var(--green-500));
  color: var(--white); border-radius: 18px;
  padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-lg);
}
.today-hero-label { font-size: .72rem; font-weight: 700; opacity: .85; text-transform: uppercase; letter-spacing: .8px; }
.today-hero-stat { font-size: 2rem; font-weight: 800; margin: 4px 0; }
.today-hero-meta { font-size: .85rem; opacity: .9; }

.today-stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px;
  margin-bottom: 14px;
}
.today-stat {
  background: var(--white); border-radius: 14px;
  padding: 14px; box-shadow: var(--shadow);
  border: 1px solid var(--green-200);
}
.today-stat-icon { font-size: 1.4rem; line-height: 1; }
.today-stat-label { font-size: .72rem; color: var(--gray-600); margin-top: 6px; font-weight: 600; }
.today-stat-value { font-size: 1.1rem; font-weight: 800; color: var(--green-900); margin-top: 2px; }
.today-stat-empty { color: var(--gray-400); font-weight: 600; font-size: .9rem; }

.today-section {
  background: var(--white); border-radius: 14px;
  padding: 14px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.today-section-title {
  font-size: .78rem; font-weight: 700; color: var(--gray-600);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px;
}
.today-supps { display: flex; flex-wrap: wrap; gap: 6px; }
.today-supp-pill {
  padding: 5px 10px; border-radius: 999px;
  font-size: .78rem; font-weight: 600;
  background: var(--green-50); color: var(--gray-600);
  border: 1px solid var(--green-200);
}
.today-supp-pill.taken { background: var(--green-700); color: var(--white); border-color: var(--green-700); }

/* Make any "tap to edit" card behave like a real button */
.today-clickable {
  width: 100%; text-align: left; font-family: inherit;
  border: 1px solid var(--green-200); cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  -webkit-tap-highlight-color: transparent;
  display: block;
}
.today-clickable:active { transform: scale(.985); box-shadow: var(--shadow-lg); }
.today-hero.today-clickable { border: none; }

/* Tappable supplement pills */
.today-supp-pill[data-sid] {
  cursor: pointer; font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: transform .1s;
}
.today-supp-pill[data-sid]:active { transform: scale(.92); }

.today-empty {
  background: var(--white); border-radius: 14px;
  padding: 32px 20px; text-align: center;
  box-shadow: var(--shadow);
}
.today-empty-icon { font-size: 3rem; margin-bottom: 8px; }
.today-empty-title { font-size: 1.05rem; font-weight: 700; color: var(--green-900); margin-bottom: 6px; }
.today-empty-text { color: var(--gray-600); font-size: .88rem; line-height: 1.5; margin-bottom: 16px; }
.swipe-hint {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--green-700); font-weight: 700; font-size: .85rem;
  background: var(--green-50); padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--green-200);
}

/* ── Quick Add grid ─────────────────────────────────────────── */
.quickadd-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
}
.quickadd-tile {
  background: var(--white); border-radius: 16px;
  padding: 18px 14px; text-align: left;
  box-shadow: var(--shadow); border: 1px solid var(--green-200);
  cursor: pointer; transition: transform .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column; gap: 4px;
  font-family: inherit;
}
.quickadd-tile:active { transform: scale(.96); box-shadow: var(--shadow-lg); }
.quickadd-tile-icon {
  width: 44px; height: 44px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; margin-bottom: 6px;
  background: var(--green-50);
}
.quickadd-tile-title { font-size: .95rem; font-weight: 700; color: var(--green-900); }
.quickadd-tile-desc { font-size: .75rem; color: var(--gray-600); line-height: 1.3; }

@media (min-width: 600px) {
  .quickadd-grid { grid-template-columns: repeat(3, 1fr); }
  .today-stats { grid-template-columns: repeat(4, 1fr); }
}

/* ── Auth Screen ─────────────────────────────────────────────── */
.auth-screen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--green-50) 0%, var(--green-200) 100%);
  padding: 20px;
}
.auth-card {
  background: var(--white); border-radius: 20px;
  padding: 36px 28px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: slideUp .35s ease;
}
.auth-logo { font-size: 3rem; margin-bottom: 8px; }
.auth-title { font-size: 1.4rem; color: var(--green-900); margin-bottom: 6px; }
.auth-subtitle { color: var(--gray-600); font-size: .9rem; margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; font-weight: 600; color: var(--gray-600); }
.auth-error { color: var(--red); font-size: .82rem; min-height: 1em; margin: -4px 0 0; text-align: left; }
.auth-submit { margin-top: 4px; padding: 12px; font-size: 1rem; }
.auth-submit:disabled { opacity: .6; cursor: wait; }
.auth-forgot { margin-top: 12px; font-size: .82rem; text-align: right; }
.auth-forgot a { color: var(--green-700); font-weight: 600; text-decoration: none; }
.auth-forgot a:hover { text-decoration: underline; }
.auth-toggle { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--green-200); font-size: .85rem; color: var(--gray-600); }
.auth-toggle a { color: var(--green-700); font-weight: 700; text-decoration: none; margin-left: 4px; }
.auth-toggle a:hover { text-decoration: underline; }

/* ── Header sign-out button ─────────────────────────────────── */
.header-btn {
  background: rgba(255,255,255,.15); border: none; color: var(--white);
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 1.1rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s; -webkit-tap-highlight-color: transparent;
}
.header-btn:active { background: rgba(255,255,255,.3); }

/* ── Responsive desktop ──────────────────────────────────────── */
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: var(--radius); max-height: 88vh; }
  .bottom-nav { max-width: 900px; left: 50%; transform: translateX(-50%); border-radius: var(--radius) var(--radius) 0 0; border-left: 1px solid var(--green-200); border-right: 1px solid var(--green-200); }
  .tab-btn { font-size: .7rem; }
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(3, 1fr); }
  .stat-num { font-size: 1.3rem; }
}
