*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366f1;
  --primary-light: #a5b4fc;
  --primary-dark: #4f46e5;
  --food: #22c55e;
  --food-bg: #f0fdf4;
  --symptom: #f97316;
  --symptom-bg: #fff7ed;
  --danger: #ef4444;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --shadow: 0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.10), 0 4px 6px rgba(0,0,0,.05);
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
#root { height: 100%; display: flex; flex-direction: column; }

/* ── Layout ── */
.screen { flex: 1; overflow-y: auto; padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px); }
.screen-full { flex: 1; overflow-y: auto; }

/* ── Top bar ── */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 8px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.topbar-sub { font-size: 13px; color: var(--text-secondary); margin-top: 1px; }

/* ── Bottom nav ── */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + var(--safe-bottom)); background: var(--card); border-top: 1px solid var(--border); display: flex; align-items: flex-start; padding-top: 8px; z-index: 20; box-shadow: 0 -2px 10px rgba(0,0,0,.06); }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; padding: 6px 4px; border: none; background: none; color: var(--text-muted); transition: color .15s; }
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 24px; height: 24px; }
.nav-item span { font-size: 10px; font-weight: 600; letter-spacing: .3px; }

/* ── Cards ── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 12px 16px; }
.card-flat { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); padding: 16px; margin: 8px 16px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: 12px; font-weight: 600; font-size: 15px; cursor: pointer; transition: all .15s; padding: 12px 20px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); transform: scale(.97); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-full { width: 100%; }
.btn-sm { font-size: 13px; padding: 8px 14px; border-radius: 8px; }

/* ── Mic button ── */
.mic-wrap { display: flex; flex-direction: column; align-items: center; padding: 24px 16px 16px; gap: 16px; }
.mic-btn { width: 96px; height: 96px; border-radius: 50%; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-lg); transition: all .15s; background: var(--primary); color: #fff; }
.mic-btn:active { transform: scale(.93); }
.mic-btn.listening { background: var(--danger); animation: pulse 1.2s ease-in-out infinite; }
.mic-btn svg { width: 40px; height: 40px; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,.4); } 50% { box-shadow: 0 0 0 18px rgba(239,68,68,0); } }

.mic-label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }

/* ── Entry textarea ── */
.entry-area { padding: 0 16px; }
.entry-textarea { width: 100%; border: 1.5px solid var(--border); border-radius: 14px; padding: 14px 16px; font-size: 15px; font-family: inherit; resize: none; outline: none; color: var(--text); background: var(--card); transition: border-color .15s; min-height: 90px; line-height: 1.5; }
.entry-textarea:focus { border-color: var(--primary); }
.entry-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ── Type toggle ── */
.type-toggle { display: flex; gap: 8px; padding: 12px 16px 0; }
.type-btn { flex: 1; padding: 10px; border-radius: 10px; border: 1.5px solid var(--border); background: var(--card); font-size: 14px; font-weight: 600; cursor: pointer; transition: all .15s; color: var(--text-secondary); display: flex; align-items: center; justify-content: center; gap: 6px; }
.type-btn.active-food { border-color: var(--food); background: var(--food-bg); color: var(--food); }
.type-btn.active-symptom { border-color: var(--symptom); background: var(--symptom-bg); color: var(--symptom); }

/* ── Log entries ── */
.log-item { display: flex; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; }
.log-item:active { background: var(--bg); }
.log-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 18px; }
.log-icon.food { background: var(--food-bg); }
.log-icon.symptom { background: var(--symptom-bg); }
.log-content { flex: 1; min-width: 0; }
.log-summary { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.log-time { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }

.section-header { padding: 12px 16px 6px; font-size: 12px; font-weight: 700; color: var(--text-muted); letter-spacing: .5px; text-transform: uppercase; }

/* ── Profile selector ── */
.profile-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 32px 24px; gap: 16px; background: var(--bg); }
.profile-screen h1 { font-size: 28px; font-weight: 800; color: var(--text); }
.profile-screen p { font-size: 15px; color: var(--text-secondary); text-align: center; }
.profile-cards { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.profile-card { width: 140px; padding: 24px 16px; border-radius: 20px; border: 2px solid var(--border); background: var(--card); display: flex; flex-direction: column; align-items: center; gap: 12px; cursor: pointer; box-shadow: var(--shadow); transition: all .15s; }
.profile-card:active { transform: scale(.96); box-shadow: var(--shadow-sm); }
.avatar { width: 64px; height: 64px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 800; color: #fff; }
.profile-card .name { font-size: 16px; font-weight: 700; color: var(--text); }

/* ── Login screen ── */
.login-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 100vh; padding: 32px 24px; gap: 20px; }
.login-screen .avatar-lg { width: 80px; height: 80px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 36px; font-weight: 800; color: #fff; margin-bottom: 8px; }
.login-screen h2 { font-size: 22px; font-weight: 700; }
.login-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 14px; }
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.input-field { border: 1.5px solid var(--border); border-radius: 12px; padding: 13px 16px; font-size: 16px; font-family: inherit; outline: none; color: var(--text); background: var(--card); transition: border-color .15s; width: 100%; }
.input-field:focus { border-color: var(--primary); }
.remember-row { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-secondary); }
.back-btn { background: none; border: none; color: var(--text-secondary); font-size: 14px; cursor: pointer; display: flex; align-items: center; gap: 4px; }

/* ── Insights ── */
.insights-content { padding: 16px; white-space: pre-wrap; font-size: 14px; line-height: 1.7; color: var(--text); }
.insights-content h2, .insights-content strong { color: var(--text); }
.digest-card { background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%); color: #fff; border-radius: var(--radius); margin: 16px; padding: 20px; }
.digest-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 8px; opacity: .85; }
.digest-card p { font-size: 14px; line-height: 1.6; }
.analyze-btn-wrap { padding: 16px; }

/* ── Settings ── */
.settings-section { margin: 16px; }
.settings-section h3 { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; background: var(--card); border-bottom: 1px solid var(--border); font-size: 15px; }
.settings-row:first-of-type { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.settings-row:last-of-type { border-bottom: none; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.settings-row:only-of-type { border-radius: var(--radius-sm); border-bottom: none; }
.settings-block { background: var(--card); border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow); }
.toggle { position: relative; width: 48px; height: 28px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 14px; transition: .3s; cursor: pointer; }
.toggle-slider::before { content: ''; position: absolute; height: 22px; width: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .3s; }
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── Follow-up toast ── */
.followup-toast { position: fixed; bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px); left: 16px; right: 16px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 16px; z-index: 100; border-left: 4px solid var(--primary); animation: slideUp .3s ease; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.followup-toast h4 { font-size: 13px; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.followup-toast p { font-size: 14px; color: var(--text); margin-bottom: 12px; }
.followup-input { width: 100%; border: 1.5px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: inherit; outline: none; }
.followup-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }

/* ── Success/error feedback ── */
.toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); background: #1e293b; color: #fff; padding: 10px 20px; border-radius: 40px; font-size: 14px; font-weight: 600; z-index: 200; animation: fadeInOut 2.5s ease forwards; white-space: nowrap; }
@keyframes fadeInOut { 0%,100%{opacity:0;transform:translateX(-50%) translateY(-6px)} 15%,85%{opacity:1;transform:translateX(-50%) translateY(0)} }

/* ── Empty state ── */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 24px; color: var(--text-muted); text-align: center; }
.empty-state svg { width: 48px; height: 48px; opacity: .4; }
.empty-state p { font-size: 15px; }
.empty-state small { font-size: 13px; }

/* ── Loading ── */
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-wrap { display: flex; justify-content: center; padding: 32px; }

/* ── Edit modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 300; display: flex; align-items: flex-end; }
.modal-sheet { background: var(--card); border-radius: 24px 24px 0 0; padding: 24px; width: 100%; max-height: 80vh; overflow-y: auto; animation: slideUp .25s ease; }
.modal-sheet h3 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

/* ── Stat chips ── */
.stats-row { display: flex; gap: 10px; padding: 12px 16px; overflow-x: auto; }
.stat-chip { background: var(--card); border-radius: 12px; padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 90px; box-shadow: var(--shadow); flex-shrink: 0; }
.stat-chip .num { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat-chip .lbl { font-size: 11px; color: var(--text-muted); font-weight: 600; }

/* ── Desktop view ── */
@media (min-width: 640px) {
  .screen, .screen-full { max-width: 480px; margin: 0 auto; }
  .bottom-nav { max-width: 480px; left: 50%; transform: translateX(-50%); }
  .followup-toast { max-width: 448px; left: 50%; transform: translateX(-50%); }
  .profile-screen { background: linear-gradient(135deg, #f0f4ff 0%, #f8fafc 100%); }
}

/* ── Rich log cards ── */
.log-item-rich { padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s; }
.log-item-rich:active { background: var(--bg); }
.log-item-rich:last-child { border-bottom: none; }
.log-item-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.log-item-icon { font-size: 16px; }
.log-item-time { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.log-item-occurred { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.log-item-summary { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; line-height: 1.3; }
.chips-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.chip { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.chip-item { background: #e0e7ff; color: #4338ca; }
.chip-ingredient { background: #fef3c7; color: #92400e; }
.chip-symptom { background: var(--symptom-bg); color: var(--symptom); }
.chip-safe { background: var(--food-bg); color: #15803d; }
.severity-dots { display: flex; gap: 3px; align-items: center; }
.severity-dot { width: 8px; height: 8px; border-radius: 50%; }
.severity-dot.filled { background: var(--symptom); }
.severity-dot.empty { background: var(--border); }
