:root {
  --primary: #2a9d8f;
  --primary-dark: #1f7a70;
  --primary-light: #e7f5f3;
  --danger: #e76f51;
  --danger-light: #fde8e0;
  --warning: #f4a261;
  --warning-light: #fcefdc;
  --success: #52b788;
  --success-light: #e2f3e9;
  --text: #1d3557;
  --text-muted: #6c757d;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --border: #e1e7ed;
  --shadow: 0 2px 8px rgba(20, 40, 60, 0.06);
  --radius: 12px;
  --tabbar-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }

.app {
  max-width: 720px; margin: 0 auto; min-height: 100vh;
  display: flex; flex-direction: column;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

header.app-header {
  padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top));
  background: var(--primary); color: white;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
header .title { font-weight: 600; font-size: 17px; display: flex; align-items: center; gap: 8px; }
header .subtitle { font-size: 12px; opacity: 0.85; }
header .header-actions { display: flex; gap: 6px; align-items: center; }
header .header-actions button { color: white; font-size: 20px; padding: 4px 8px; }
header .user-badge {
  font-size: 12px; padding: 4px 10px; border-radius: 12px;
  background: rgba(255,255,255,0.18); color: white;
}

main.content { flex: 1; padding: 12px; }

.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border-radius: var(--radius); padding: 14px;
  margin-bottom: 10px; box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 8px; font-size: 15px; color: var(--text); }
.card .meta { font-size: 12px; color: var(--text-muted); }

.section-title {
  font-size: 13px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 600; margin: 16px 4px 8px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; border-radius: 10px; font-weight: 500;
  background: var(--primary); color: white; transition: transform 0.06s, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn.danger { background: var(--danger); color: white; }
.btn.ghost { background: transparent; color: var(--primary-dark); }
.btn.full { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; }

.fab {
  position: fixed; right: 20px;
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: white; font-size: 28px; font-weight: 300;
  box-shadow: 0 6px 16px rgba(42, 157, 143, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}

nav.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; z-index: 15;
}
nav.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 6px 2px; color: var(--text-muted); font-size: 11px;
}
nav.tabbar button.active { color: var(--primary); }
nav.tabbar button .icon { font-size: 22px; line-height: 1; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { min-height: 70px; resize: vertical; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 30, 0.5);
  display: none; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal-backdrop.active { display: flex; animation: fadeIn 0.15s; }
.modal {
  background: var(--surface); width: 100%; max-width: 720px;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 4px 10px; border-radius: 16px; font-size: 12px; font-weight: 500;
  background: var(--primary-light); color: var(--primary-dark);
  border: 1px solid transparent;
}
.chip.allowed { background: var(--success-light); color: #1d7848; }
.chip.forbidden { background: var(--danger-light); color: #a83a1f; }
.chip.testing { background: var(--warning-light); color: #a05a1e; }
.chip.selectable { cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.chip.selectable.selected { background: var(--primary); color: white; border-color: var(--primary); }

.intensity-selector { display: flex; gap: 6px; }
.intensity-selector button {
  flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  font-weight: 500;
}
.intensity-selector button.selected { background: var(--warning); color: white; border-color: var(--warning); }

.entry {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  margin-bottom: 8px; box-shadow: var(--shadow);
  display: flex; gap: 10px; align-items: flex-start;
}
.entry .entry-icon {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  flex-shrink: 0;
}
.entry .entry-icon.meal { background: var(--primary-light); }
.entry .entry-icon.symptom { background: var(--danger-light); }
.entry .entry-body { flex: 1; min-width: 0; }
.entry .entry-title { font-weight: 600; font-size: 14px; }
.entry .entry-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.entry .entry-details { font-size: 13px; margin-top: 4px; color: var(--text); }
.entry-actions { display: flex; gap: 4px; }
.entry-actions button { padding: 4px 6px; font-size: 14px; color: var(--text-muted); border-radius: 6px; }

.day-header {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 4px 6px; font-weight: 600; font-size: 13px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.day-header .day-date { color: var(--text); }

.empty {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty .emoji { font-size: 48px; display: block; margin-bottom: 8px; opacity: 0.6; }

.phase-banner {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white; padding: 14px 16px; border-radius: var(--radius);
  margin-bottom: 12px;
}
.phase-banner .label { font-size: 12px; opacity: 0.85; }
.phase-banner .name { font-size: 17px; font-weight: 600; margin-top: 2px; }
.phase-banner .dates { font-size: 12px; opacity: 0.85; margin-top: 4px; }

.risk-item {
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px;
  margin-bottom: 8px; box-shadow: var(--shadow);
}
.risk-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.risk-name { font-weight: 600; font-size: 14px; }
.risk-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.risk-bar {
  height: 8px; background: var(--border); border-radius: 4px; overflow: hidden;
  margin-top: 8px;
}
.risk-bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s ease; }
.risk-badge {
  padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; white-space: nowrap;
}
.risk-badge.low { background: var(--success-light); color: #1d7848; }
.risk-badge.med { background: var(--warning-light); color: #a05a1e; }
.risk-badge.high { background: var(--danger-light); color: #a83a1f; }

.scroll-tail { height: 30px; }
.info-text { font-size: 12px; color: var(--text-muted); padding: 6px 4px; line-height: 1.5; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@media (min-width: 600px) {
  .fab { right: calc((100% - 720px) / 2 + 20px); }
}

.cat-tabs {
  display: flex; background: var(--surface); border-radius: 10px; padding: 4px;
  margin-bottom: 10px; gap: 4px; box-shadow: var(--shadow);
}
.cat-tabs button {
  flex: 1; padding: 8px; font-size: 13px; font-weight: 500; border-radius: 8px;
  color: var(--text-muted);
}
.cat-tabs button.active { background: var(--primary); color: white; }

.food-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; background: var(--surface); border-radius: 10px;
  margin-bottom: 6px; box-shadow: var(--shadow);
}
.food-row .food-name { font-weight: 500; font-size: 14px; }
.food-row .food-notes { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* --- Login page --- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #e7f5f3 0%, #cde9e3 100%);
}
.auth-card {
  background: var(--surface); padding: 32px 24px; border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.1); max-width: 400px; width: 100%;
}
.auth-card .logo {
  font-size: 40px; text-align: center; margin-bottom: 8px;
}
.auth-card h1 {
  font-size: 22px; text-align: center; margin: 0 0 4px; color: var(--primary-dark);
}
.auth-card .tagline {
  text-align: center; font-size: 13px; color: var(--text-muted); margin-bottom: 24px;
}
.auth-card .notice {
  background: var(--warning-light); color: #a05a1e; padding: 10px 12px;
  border-radius: 8px; font-size: 13px; margin-bottom: 16px; text-align: center;
}
.auth-card a { color: var(--primary); text-decoration: none; }
.auth-tabs {
  display: flex; gap: 4px; background: var(--bg); padding: 4px;
  border-radius: 10px; margin-bottom: 16px;
}
.auth-tabs button {
  flex: 1; padding: 8px; border-radius: 8px; font-weight: 500;
  color: var(--text-muted); font-size: 14px;
}
.auth-tabs button.active { background: var(--primary); color: white; }
.auth-link-row { text-align: center; margin-top: 12px; font-size: 13px; color: var(--text-muted); }

.sync-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 3px 8px; border-radius: 10px;
  background: rgba(255,255,255,0.2); color: white;
}
.sync-badge.online { background: rgba(82, 183, 136, 0.3); }
.sync-badge.offline { background: rgba(231, 111, 81, 0.3); }
