/* ============================================================
   Health Tracker Plus v3 — Global Stylesheet
   ============================================================ */

:root {
  --accent:        #1D9E75;
  --accent-dark:   #0F6E56;
  --accent-light:  #E1F5EE;
  --accent-border: #5DCAA5;

  --text:   #1A1A1A;
  --text-2: #444;
  --text-3: #888;
  --text-4: #BBB;

  --bg:      #F2F4F6;
  --surface: #FFFFFF;
  --border:  #E5E7EB;
  --border-2:#D1D5DB;

  --radius:    12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --header-h: 54px;
  --tab-h:    58px;

  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'DM Mono', 'SF Mono', monospace;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing:border-box; margin:0; padding:0; }
html { -webkit-text-size-adjust:100%; }
body {
  font-family:var(--font);
  font-size:15px;
  color:var(--text);
  background:var(--bg);
  -webkit-font-smoothing:antialiased;
  min-height:100dvh;
  overscroll-behavior:none;
}
a { color:var(--accent); text-decoration:none; }
input,select,textarea,button { font-family:inherit; font-size:inherit; }
button { cursor:pointer; background:none; border:none; }
textarea { resize:vertical; }
img { max-width:100%; }

/* ── App shell ──────────────────────────────────────────────── */
.app {
  max-width:480px;
  margin:0 auto;
  min-height:100dvh;
  display:flex;
  flex-direction:column;
  position:relative;
  background:var(--bg);
}

/* ── Header ─────────────────────────────────────────────────── */
.header {
  height:var(--header-h);
  background:var(--accent);
  display:flex;
  align-items:center;
  gap:10px;
  padding:0 16px;
  position:sticky;
  top:0;
  z-index:100;
  flex-shrink:0;
}
.header-logo {
  width:30px; height:30px;
  border-radius:8px;
  background:rgba(255,255,255,.2);
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
}
.header-title { flex:1; font-size:15px; font-weight:600; color:white; }
.header-sub   { font-size:11px; color:rgba(255,255,255,.75); margin-top:1px; }
.header-btn {
  width:34px; height:34px; border-radius:50%;
  background:rgba(255,255,255,.15);
  display:flex; align-items:center; justify-content:center;
  color:white; flex-shrink:0; transition:background .15s;
}
.header-btn:hover { background:rgba(255,255,255,.25); }
.header-back { color:white; display:flex; align-items:center; border-radius:6px; padding:3px; }

/* ── Bottom tabs ─────────────────────────────────────────────── */
.tabs {
  display:flex;
  position:fixed;
  bottom:0; left:50%; transform:translateX(-50%);
  width:100%; max-width:480px;
  height:var(--tab-h);
  background:var(--surface);
  border-top:.5px solid var(--border);
  z-index:100;
  padding-bottom:env(safe-area-inset-bottom, 0);
}
.tab {
  flex:1;
  display:flex; flex-direction:column;
  align-items:center; justify-content:center;
  gap:3px;
  font-size:10px; font-weight:500;
  color:var(--text-3);
  border:none; background:none;
  transition:color .15s;
  padding:0 4px;
}
.tab.active { color:var(--accent); }

/* ── Content ─────────────────────────────────────────────────── */
.content {
  flex:1;
  padding:12px 16px calc(var(--tab-h) + 16px);
  overflow-y:auto;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background:var(--surface);
  border:.5px solid var(--border);
  border-radius:var(--radius);
  padding:14px 16px;
  margin-bottom:10px;
}
.card-title {
  font-size:10px; font-weight:600;
  color:var(--text-3);
  text-transform:uppercase; letter-spacing:.05em;
  margin-bottom:10px;
}
.card-hint { font-size:12px; color:var(--text-3); line-height:1.5; margin-bottom:10px; }

/* ── Forms ───────────────────────────────────────────────────── */
.field { margin-bottom:12px; }
.field:last-child { margin-bottom:0; }
.field label {
  display:block;
  font-size:11px; font-weight:500;
  color:var(--text-3);
  text-transform:uppercase; letter-spacing:.04em;
  margin-bottom:5px;
}
.field input,
.field select,
.field textarea {
  width:100%;
  padding:11px 14px;
  border:1px solid var(--border-2);
  border-radius:var(--radius-sm);
  font-size:14px; color:var(--text);
  background:var(--surface);
  outline:none;
  transition:border-color .15s;
}
.field input:focus,
.field select:focus,
.field textarea:focus { border-color:var(--accent); }
.field-row { display:grid; grid-template-columns:1fr 1fr; gap:10px; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  padding:11px 20px;
  border-radius:var(--radius-sm);
  font-size:14px; font-weight:500;
  border:none; cursor:pointer;
  transition:opacity .15s, transform .1s;
  text-decoration:none;
}
.btn:active { transform:scale(.97); }
.btn-primary  { background:var(--accent); color:white; }
.btn-outline  { background:transparent; color:var(--text-2); border:.5px solid var(--border-2); }
.btn-danger   { background:#FCEBEB; color:#A32D2D; border:.5px solid #F09595; }
.btn-full     { width:100%; }
.btn-sm       { padding:7px 14px; font-size:12px; }
.btn:disabled { opacity:.5; pointer-events:none; }
.btn.saving   { opacity:.7; pointer-events:none; }
.btn.saved    { background:var(--accent-dark); }

/* ── Toggle ──────────────────────────────────────────────────── */
.toggle { position:relative; width:44px; height:26px; flex-shrink:0; }
.toggle input { display:none; }
.toggle-track {
  position:absolute; inset:0; border-radius:13px;
  background:var(--border-2); cursor:pointer; transition:background .2s;
}
.toggle input:checked + .toggle-track { background:var(--accent); }
.toggle-thumb {
  position:absolute; top:3px; left:3px;
  width:20px; height:20px; border-radius:50%;
  background:white; box-shadow:0 1px 3px rgba(0,0,0,.2);
  transition:transform .2s; pointer-events:none;
}
.toggle input:checked ~ .toggle-thumb { transform:translateX(18px); }
.toggle-row {
  display:flex; align-items:center; justify-content:space-between;
  padding:9px 0; border-bottom:.5px solid var(--border);
}
.toggle-row:last-child { border-bottom:none; }
.toggle-label { font-size:14px; color:var(--text); }
.toggle-sub   { font-size:11px; color:var(--text-3); margin-top:2px; }

/* ── Check ───────────────────────────────────────────────────── */
.check-label {
  display:flex; align-items:center; gap:10px;
  cursor:pointer; padding:4px 0;
  font-size:14px; color:var(--text);
}
.check-label input[type=checkbox] { display:none; }
.check-box {
  width:22px; height:22px; border-radius:6px;
  border:1.5px solid var(--border-2);
  background:white; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  transition:all .15s;
}
.check-label input:checked + .check-box {
  background:var(--accent); border-color:var(--accent);
}
.check-label input:checked + .check-box::after {
  content:''; width:5px; height:9px;
  border-right:2px solid white; border-bottom:2px solid white;
  transform:rotate(45deg) translateY(-1px); display:block;
}

/* ── Mood buttons ────────────────────────────────────────────── */
.mood-row { display:flex; gap:6px; }
.mood-btn {
  flex:1; height:42px; border-radius:var(--radius-sm);
  border:.5px solid var(--border-2); background:var(--surface);
  font-size:13px; font-weight:500; color:var(--text-2);
  cursor:pointer; transition:all .15s;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px;
}
.mood-btn.active { background:var(--accent); border-color:var(--accent); color:white; }

/* ── Number control ──────────────────────────────────────────── */
.num-ctrl {
  display:flex; align-items:center; gap:8px;
  background:var(--bg); border-radius:var(--radius-xs);
  padding:8px 12px; margin-bottom:8px;
}
.num-label { font-size:13px; color:var(--text-2); flex:1; }
.num-input {
  width:80px; padding:8px 10px;
  border:1px solid var(--border-2); border-radius:var(--radius-xs);
  font-size:16px; font-weight:500; font-family:var(--mono);
  text-align:center; outline:none;
}
.num-input:focus { border-color:var(--accent); }
.num-unit { font-size:12px; color:var(--text-3); width:32px; }

/* ── Alert ───────────────────────────────────────────────────── */
.alert { padding:10px 14px; border-radius:var(--radius-sm); font-size:13px; margin-bottom:12px; line-height:1.4; }
.alert-error   { background:#FCEBEB; color:#A32D2D; border:.5px solid #F09595; }
.alert-success { background:var(--accent-light); color:var(--accent-dark); border:.5px solid var(--accent-border); }
.alert-info    { background:#E6F1FB; color:#185FA5; border:.5px solid #B5D4F4; }
.alert-warn    { background:#FAEEDA; color:#854F0B; border:.5px solid #EF9F27; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position:fixed;
  bottom:calc(var(--tab-h) + 10px);
  left:50%; transform:translateX(-50%) translateY(6px);
  background:#1A1A1A; color:white;
  padding:10px 18px; border-radius:20px;
  font-size:13px; font-weight:500;
  opacity:0; pointer-events:none;
  transition:opacity .2s, transform .2s;
  z-index:500; white-space:nowrap;
  max-width:calc(100% - 32px);
}
.toast.show { opacity:1; transform:translateX(-50%) translateY(0); }
.toast.err  { background:#A32D2D; }

/* ── Modal ───────────────────────────────────────────────────── */
.overlay {
  display:none; position:fixed; inset:0;
  background:rgba(0,0,0,.45); z-index:200;
}
.overlay.on { display:block; }
.modal {
  display:none; position:fixed;
  bottom:0; left:50%; transform:translateX(-50%);
  width:100%; max-width:480px;
  background:var(--surface);
  border-radius:var(--radius) var(--radius) 0 0;
  padding:20px 20px calc(24px + env(safe-area-inset-bottom, 0));
  z-index:201;
  max-height:92dvh; overflow-y:auto;
}
.modal.on { display:block; animation:slideup .22s ease; }
@keyframes slideup {
  from { transform:translateX(-50%) translateY(20px); opacity:0; }
  to   { transform:translateX(-50%) translateY(0);    opacity:1; }
}
.modal-handle { width:36px; height:4px; border-radius:2px; background:var(--border-2); margin:-8px auto 16px; }
.modal-title  { font-size:16px; font-weight:600; color:var(--text); margin-bottom:16px; }

/* ── Shortcut rows ───────────────────────────────────────────── */
.shortcut {
  display:flex; align-items:center; gap:12px;
  padding:11px 0; border-bottom:.5px solid var(--border);
  cursor:pointer; text-decoration:none;
}
.shortcut:last-child { border-bottom:none; }
.sc-icon {
  width:38px; height:38px; border-radius:10px;
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.sc-title { font-size:14px; font-weight:500; color:var(--text); }
.sc-sub   { font-size:11px; color:var(--text-3); margin-top:2px; }
.sc-arrow { margin-left:auto; color:var(--text-4); }

/* ── Nutrition pills ─────────────────────────────────────────── */
.nutr-pill {
  display:inline-flex; align-items:center; gap:2px;
  font-size:11px; padding:2px 7px; border-radius:10px;
  background:var(--bg); color:var(--text-3);
  font-family:var(--mono);
}
.nutr-pill.fat { background:var(--accent-light); color:var(--accent-dark); }

/* ── Divider ─────────────────────────────────────────────────── */
.divider { height:.5px; background:var(--border); margin:10px 0; }

/* ── Section label ───────────────────────────────────────────── */
.sec-label {
  font-size:10px; font-weight:600; color:var(--text-3);
  text-transform:uppercase; letter-spacing:.05em;
  margin-bottom:8px; padding:0 2px;
}

/* ── Sub tabs ────────────────────────────────────────────────── */
.sub-tabs {
  display:flex; background:var(--surface);
  border-bottom:.5px solid var(--border);
  overflow-x:auto;
  position:sticky; top:var(--header-h); z-index:90;
}
.sub-tab {
  padding:10px 14px; font-size:12px; font-weight:500;
  color:var(--text-3); border:none; background:none;
  border-bottom:2px solid transparent;
  white-space:nowrap; cursor:pointer; transition:all .15s;
  flex-shrink:0;
}
.sub-tab.active { color:var(--accent); border-bottom-color:var(--accent); }

/* ── Category grid (chat) ────────────────────────────────────── */
.cat-grid {
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  gap:8px;
  margin-bottom:12px;
}
.cat-btn {
  background:var(--surface);
  border:.5px solid var(--border);
  border-radius:var(--radius-sm);
  padding:10px 6px;
  text-align:center;
  cursor:pointer;
  transition:all .15s;
  border:none;
}
.cat-btn:hover,
.cat-btn.active { background:var(--accent-light); border-color:var(--accent-border); }
.cat-btn.active .cat-label { color:var(--accent-dark); }
.cat-icon  { font-size:22px; margin-bottom:4px; }
.cat-label { font-size:11px; font-weight:500; color:var(--text-2); }
.cat-cost  { font-size:9px; color:var(--text-4); margin-top:2px; }

/* ── Chat bubbles ────────────────────────────────────────────── */
.bubble-wrap { display:flex; flex-direction:column; gap:8px; }
.bubble {
  max-width:86%; padding:10px 14px;
  border-radius:16px; font-size:14px; line-height:1.5; word-wrap:break-word;
}
.bubble.user {
  background:var(--accent); color:white;
  border-radius:16px 16px 4px 16px;
  align-self:flex-end;
}
.bubble.ai {
  background:var(--surface); border:.5px solid var(--border);
  border-radius:16px 16px 16px 4px;
  align-self:flex-start;
}
.bubble.system {
  background:var(--bg); color:var(--text-3);
  font-size:12px; text-align:center;
  align-self:center; border-radius:10px; max-width:100%;
}
.bubble-actions { display:flex; flex-wrap:wrap; gap:4px; margin-top:6px; }
.bubble-pill {
  font-size:11px; padding:3px 8px; border-radius:10px;
  background:var(--accent-light); color:var(--accent-dark);
}

/* ── Typing indicator ────────────────────────────────────────── */
.typing { display:flex; gap:4px; align-items:center; padding:6px 2px; }
.typing span {
  width:7px; height:7px; border-radius:50%;
  background:var(--text-3);
  animation:typing 1.2s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay:.2s; }
.typing span:nth-child(3) { animation-delay:.4s; }
@keyframes typing { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-5px)} }

/* ── Day summary strip ───────────────────────────────────────── */
.day-summary {
  background:var(--bg); border-radius:var(--radius-sm);
  padding:10px 12px; margin-bottom:12px;
}
.day-summary-row {
  display:flex; align-items:center; gap:8px;
  padding:4px 0; font-size:12px;
}
.day-summary-icon { width:20px; text-align:center; flex-shrink:0; }
.day-summary-text { flex:1; color:var(--text-2); }
.day-summary-val  { color:var(--text-3); font-size:11px; font-family:var(--mono); }

/* ── Year tracker grid ───────────────────────────────────────── */
.tracker-wrap { margin-bottom:14px; }
.tracker-months { display:flex; flex-direction:column; gap:6px; }
.tracker-month { }
.tracker-month-label {
  font-size:9px; font-weight:600; color:var(--text-3);
  text-transform:uppercase; letter-spacing:.04em;
  margin-bottom:3px;
}
.tracker-weeks { display:flex; flex-direction:column; gap:1.5px; }
.tracker-week  { display:flex; gap:1.5px; }
.tracker-day   {
  width:11px; height:11px; border-radius:2px;
  background:var(--border); flex-shrink:0;
  cursor:pointer; transition:transform .1s;
}
.tracker-day:hover { transform:scale(1.3); z-index:1; }
.tracker-weekdays {
  display:flex; gap:1.5px; margin-bottom:3px;
}
.tracker-weekday {
  width:11px; text-align:center;
  font-size:7px; color:var(--text-4); flex-shrink:0;
}
/* Mood colors */
.m1{background:#E24B4A;} .m2{background:#EF9F27;} .m3{background:#FFE066;}
.m4{background:#5DCAA5;} .m5{background:#1D9E75;}
/* Stool colors */
.b1{background:#6B3A2A;} .b2{background:#A0522D;} .b3{background:#CD853F;}
.b4{background:#1D9E75;} .b5{background:#5DCAA5;} .b6{background:#185FA5;} .b7{background:#E24B4A;}
/* Activity */
.a0{background:var(--border);}
.a1{background:#C6F0DF;} .a2{background:#5DCAA5;} .a3{background:#1D9E75;} .a4{background:#0F6E56;}
/* Cycle */
.cy-mens{background:#E24B4A;} .cy-fert{background:#E1F5EE;} .cy-sym{background:#FAEEDA;} .cy-none{background:var(--border);}
/* Sleep */
.sl1{background:#E6F1FB;} .sl2{background:#B5D4F4;} .sl3{background:#5DCAA5;} .sl4{background:#1D9E75;} .sl5{background:#0F6E56;}

/* ── Legend ──────────────────────────────────────────────────── */
.legend { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:10px; }
.legend-item { display:flex; align-items:center; gap:4px; font-size:10px; color:var(--text-3); }
.legend-dot   { width:10px; height:10px; border-radius:2px; flex-shrink:0; }

/* ── Sparkline ───────────────────────────────────────────────── */
.sparkline { width:100%; height:56px; margin-bottom:6px; }

/* ── Chip grid ───────────────────────────────────────────────── */
.chips { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:10px; }
.chip {
  font-size:12px; padding:6px 12px; border-radius:20px;
  border:.5px solid var(--border-2); background:var(--surface);
  color:var(--text-2); cursor:pointer; transition:all .15s;
  white-space:nowrap;
}
.chip.active { background:var(--accent); border-color:var(--accent); color:white; }

/* ── Auth ────────────────────────────────────────────────────── */
.auth-body {
  background:var(--bg); min-height:100dvh;
  display:flex; align-items:center; justify-content:center;
  padding:24px 16px;
}
.auth-wrap { width:100%; max-width:380px; }
.auth-logo { text-align:center; margin-bottom:24px; }
.auth-logo-icon {
  width:54px; height:54px; border-radius:16px;
  background:var(--accent); margin:0 auto 10px;
  display:flex; align-items:center; justify-content:center;
}
.auth-logo-name { font-size:18px; font-weight:600; color:var(--text); }
.auth-card {
  background:var(--surface); border:.5px solid var(--border);
  border-radius:var(--radius); padding:24px;
  box-shadow:0 2px 8px rgba(0,0,0,.06);
}
.auth-title { font-size:20px; font-weight:600; color:var(--text); margin-bottom:6px; }
.auth-sub   { font-size:13px; color:var(--text-3); margin-bottom:18px; line-height:1.5; }
.auth-footer { text-align:center; margin-top:14px; font-size:12px; color:var(--text-3); line-height:1.8; }
.success-icon {
  width:48px; height:48px; border-radius:50%;
  background:var(--accent-light); color:var(--accent-dark);
  font-size:22px; font-weight:600;
  display:flex; align-items:center; justify-content:center;
  margin:0 auto 14px;
}

/* ── Avatar ──────────────────────────────────────────────────── */
.avatar {
  border-radius:50%; overflow:hidden;
  display:flex; align-items:center; justify-content:center;
  font-weight:600; flex-shrink:0;
}
.avatar img { width:100%; height:100%; object-fit:cover; }

/* ── Privacy note ────────────────────────────────────────────── */
.privacy-note {
  display:flex; align-items:flex-start; gap:8px;
  font-size:11px; color:#185FA5; line-height:1.4;
  background:#E6F1FB; border:.5px solid #B5D4F4;
  border-radius:var(--radius-sm); padding:10px 12px;
  margin-bottom:12px;
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width:4px; height:4px; }
::-webkit-scrollbar-track { background:transparent; }
::-webkit-scrollbar-thumb { background:var(--border-2); border-radius:2px; }
