@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,400&display=swap');

/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  --bg:          #07090f;
  --surface:     #0d1119;
  --card:        #111827;
  --raised:      #171e2e;
  --border:      #1e2535;
  --border2:     #2a3450;
  --accent:      #22c55e;
  --accent2:     #38bdf8;
  --warn:        #f59e0b;
  --danger:      #ef4444;
  --text:        #e5e7eb;
  --muted:       #5c6478;
  --muted2:      #8b93a8;
  --good:        #22c55e;
  --mid:         #f59e0b;
  --bad:         #ef4444;
  --radius:      12px;
  --radius-sm:   8px;
  --sidebar-icon-w: 60px;
  --sidebar-full-w: 220px;
  --tab-bar-h:   60px;
  --header-h:    52px;
  --safe-top:    env(safe-area-inset-top,   0px);
  --safe-bot:    env(safe-area-inset-bottom, 0px);
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'DM Sans', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100svh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
h1, h2, h3, .heading { font-family: 'Rajdhani', sans-serif; letter-spacing: 0.03em; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; color: var(--accent2); margin-bottom: 14px; }
h3 { font-size: 1rem; color: var(--muted2); margin-bottom: 10px; }

/* ══════════════════════════════════════════════════════════════════════════
   APP SHELL
   ══════════════════════════════════════════════════════════════════════════ */

#app { display: flex; flex-direction: column; min-height: 100svh; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h);
  padding: 0 16px;
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(7,9,15,0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
  flex-shrink: 0;
}
.app-header h1 {
  font-size: 1.25rem;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.06em;
}
.header-meta { color: var(--muted); font-size: 0.72rem; }
.mode-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mode-bar select { width: auto; min-width: 110px; }

/* ── Body row ───────────────────────────────────────────────────────────── */
.app-body { display: flex; flex: 1; min-height: 0; }

/* ── Sidebar (hidden phone, shown tablet+) ──────────────────────────────── */
.app-sidebar { display: none; }

/* ── Main content ───────────────────────────────────────────────────────── */
.app-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tab-bar-h) + var(--safe-bot) + 8px);
}

/* ══════════════════════════════════════════════════════════════════════════
   BOTTOM TAB BAR  (phone < 640px)
   ══════════════════════════════════════════════════════════════════════════ */
.app-tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tab-bar-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  background: rgba(9,11,18,0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  padding-top: 7px;
  z-index: 190;
}

.tab-bar-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.15s;
  padding: 0 2px;
}
.tab-bar-btn.active { color: var(--accent); }

.tab-bar-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 9px;
  font-size: 1.1rem;
  transition: all 0.22s cubic-bezier(0.34,1.56,0.64,1);
  position: relative;
}
.tab-bar-btn.active .tab-bar-icon {
  background: rgba(34,197,94,0.12);
  transform: translateY(-2px);
}
.tab-bar-label {
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1;
}

/* ══════════════════════════════════════════════════════════════════════════
   TABLET  640px+  —  Icon sidebar
   ══════════════════════════════════════════════════════════════════════════ */
@media (min-width: 640px) {
  .app-tab-bar { display: none; }

  .app-sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-icon-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 6px 0 16px;
    position: sticky;
    top: var(--header-h);
    height: calc(100svh - var(--header-h));
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    transition: width 0.25s cubic-bezier(0.4,0,0.2,1);
    z-index: 100;
  }
  .app-sidebar::-webkit-scrollbar { display: none; }
  .app-sidebar.expanded { width: var(--sidebar-full-w); }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 36px;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    margin-bottom: 4px;
    flex-shrink: 0;
    transition: color 0.15s;
  }
  .sidebar-toggle:hover { color: var(--text); }

  .app-main { padding: 20px 24px 32px; }

  .sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted2);
    transition: all 0.15s;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    padding: 0;
  }
  .sidebar-nav-item:hover { color: var(--text); }
  .sidebar-nav-item.active { color: var(--accent); }
  .sidebar-nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 55%;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px var(--accent);
  }

  .sidebar-nav-icon {
    width: var(--sidebar-icon-w);
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
  }

  .sidebar-nav-label {
    font-family: 'Rajdhani', sans-serif;
    font-weight: 600;
    font-size: 0.92rem;
    letter-spacing: 0.04em;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
  }
  .app-sidebar.expanded .sidebar-nav-label { opacity: 1; }

  .sidebar-divider { height: 1px; background: var(--border); margin: 4px 10px; flex-shrink: 0; }
  .sidebar-spacer  { flex: 1; }
}

/* ══════════════════════════════════════════════════════════════════════════
   DESKTOP  1024px+  —  Always-expanded sidebar
   ══════════════════════════════════════════════════════════════════════════ */
@media (min-width: 1024px) {
  .app-sidebar { width: var(--sidebar-full-w); }
  .sidebar-toggle { display: none; }
  .sidebar-nav-label { opacity: 1 !important; }
  .app-main { padding: 24px 32px 40px; max-width: 880px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   TAB PANELS
   ══════════════════════════════════════════════════════════════════════════ */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ══════════════════════════════════════════════════════════════════════════
   SUB-TABS
   ══════════════════════════════════════════════════════════════════════════ */
.sub-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted2);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: 'Rajdhani', sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  transition: all 0.15s;
  white-space: nowrap;
}
.sub-btn:hover  { color: var(--text); border-color: var(--border2); }
.sub-btn.active { color: var(--accent2); border-color: var(--accent2); background: rgba(56,189,248,0.07); }

/* ══════════════════════════════════════════════════════════════════════════
   GRID
   ══════════════════════════════════════════════════════════════════════════ */
.grid   { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════════════════════════════════════
   CARD
   ══════════════════════════════════════════════════════════════════════════ */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card, .card-mt { margin-top: 16px; }

/* ══════════════════════════════════════════════════════════════════════════
   KPI TILES
   ══════════════════════════════════════════════════════════════════════════ */
.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; }
@media (max-width: 480px) { .kpi-grid { grid-template-columns: repeat(2,1fr); } }
.kpi-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 10px; text-align: center; }
.kpi-tile strong { display: block; font-family: 'Rajdhani', sans-serif; font-size: 1.4rem; font-weight: 700; color: var(--accent); }
.kpi-tile span { font-size: 0.72rem; color: var(--muted); }

/* ══════════════════════════════════════════════════════════════════════════
   PROGRESS BARS
   ══════════════════════════════════════════════════════════════════════════ */
.progress-wrap  { margin-bottom: 8px; }
.progress-label { font-size: 0.72rem; color: var(--muted2); margin-bottom: 3px; display: flex; justify-content: space-between; }
.progress-bar   { height: 8px; background: var(--surface); border-radius: 4px; overflow: hidden; border: 1px solid var(--border); }
.progress-fill  { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 4px; transition: width 0.3s ease; }
.progress-fill.warn   { background: linear-gradient(90deg, var(--warn),   #d97706); }
.progress-fill.danger { background: linear-gradient(90deg, var(--danger),  #b91c1c); }

/* ══════════════════════════════════════════════════════════════════════════
   FORMS
   ══════════════════════════════════════════════════════════════════════════ */
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 0.72rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--border2);
  background: var(--surface); color: var(--text);
  font-size: 0.85rem; font-family: 'DM Sans', 'Inter', sans-serif;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent2); }
textarea { min-height: 80px; resize: vertical; }

/* ══════════════════════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: none;
  cursor: pointer; font-family: 'Rajdhani', sans-serif; font-weight: 700;
  font-size: 0.88rem; letter-spacing: 0.04em; transition: all 0.15s; white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary   { background: linear-gradient(90deg,var(--accent),#16a34a); color: #042f2e; }
.btn-secondary { background: linear-gradient(90deg,var(--accent2),#0284c7); color: #041b2c; }
.btn-warn      { background: linear-gradient(90deg,var(--warn),#d97706); color: #2a1600; }
.btn-danger    { background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.4); color: var(--danger); }
.btn-ghost     { background: transparent; border: 1px solid var(--border2); color: var(--muted2); }
.btn-primary:hover, .btn-secondary:hover, .btn-warn:hover { opacity: 0.9; }
.btn-ghost:hover  { border-color: var(--text); color: var(--text); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }

/* ══════════════════════════════════════════════════════════════════════════
   TABLE
   ══════════════════════════════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th, td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--accent2); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

/* ══════════════════════════════════════════════════════════════════════════
   TAGS / PILLS
   ══════════════════════════════════════════════════════════════════════════ */
.tag        { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.68rem; font-weight: 600; }
.tag-green  { background: rgba(34,197,94,0.12);  color: #86efac; border: 1px solid rgba(34,197,94,0.3);  }
.tag-blue   { background: rgba(56,189,248,0.12); color: #7dd3fc; border: 1px solid rgba(56,189,248,0.3); }
.tag-yellow { background: rgba(245,158,11,0.12); color: #fde68a; border: 1px solid rgba(245,158,11,0.3); }
.tag-red    { background: rgba(239,68,68,0.12);  color: #fca5a5; border: 1px solid rgba(239,68,68,0.3);  }
.tag-gray   { background: rgba(107,114,128,0.15);color: var(--muted2); border: 1px solid var(--border); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 0.72rem; border: 1px solid var(--border); color: var(--muted2); background: var(--surface); }

/* ══════════════════════════════════════════════════════════════════════════
   SCORE / STATUS / MISC
   ══════════════════════════════════════════════════════════════════════════ */
.score-block { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--surface); }
.score-num   { font-family: 'Rajdhani', sans-serif; font-size: 2.4rem; font-weight: 700; line-height: 1; }
.score-num.good { color: var(--good); }
.score-num.mid  { color: var(--mid);  }
.score-num.bad  { color: var(--bad);  }
.status      { font-size: 0.8rem; padding: 6px 0; min-height: 24px; transition: color 0.2s; }
.status.ok   { color: var(--good);   }
.status.err  { color: var(--danger); }
.status.info { color: var(--muted2); }
hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
.app-footer { padding: 10px 16px; text-align: center; font-size: 0.7rem; color: var(--muted); border-top: 1px solid var(--border); }
.text-muted  { color: var(--muted);  }
.text-muted2 { color: var(--muted2); }
.text-good   { color: var(--good);   }
.text-warn   { color: var(--warn);   }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.text-sm  { font-size: 0.78rem; }
.text-xs  { font-size: 0.7rem;  }
.mt-1 { margin-top: 6px;  }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.flex         { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.w-full { width: 100%; }

/* ══════════════════════════════════════════════════════════════════════════
   FOOD TAG FILTERS
   ══════════════════════════════════════════════════════════════════════════ */
.tag-filter-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 10px; min-height: 26px; padding: 4px 0; }
.tag-filter-btn { cursor: pointer; user-select: none; transition: transform 0.06s ease, filter 0.12s ease, opacity 0.12s ease; }
.tag-filter-btn:hover  { filter: brightness(1.15); }
.tag-filter-btn:active { transform: scale(0.98); }
.tag-filter-btn.active { box-shadow: 0 0 0 2px rgba(56,189,248,0.35); }
.tag-filter-meta  { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tag-filter-clear { cursor: pointer; font-size: 0.72rem; opacity: 0.9; }
.tag-filter-clear:hover { opacity: 1; text-decoration: underline; }
.tag-filter-mode     { display: inline-flex; gap: 6px; align-items: center; }
.tag-filter-mode-btn { cursor: pointer; user-select: none; opacity: 0.85; }
.tag-filter-mode-btn:hover  { opacity: 1; }
.tag-filter-mode-btn.active { box-shadow: 0 0 0 2px rgba(107,114,128,0.35); opacity: 1; }
.tag-more { cursor: help; }

/* ══════════════════════════════════════════════════════════════════════════
   AI SPINNER
   ══════════════════════════════════════════════════════════════════════════ */
.ai-spinner { width: 18px; height: 18px; border: 2px solid var(--border2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════════════════
   ONBOARDING WIZARD
   ══════════════════════════════════════════════════════════════════════════ */
#onboarding-overlay {
  position: fixed; inset: 0; background: rgba(6,9,16,0.92); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  backdrop-filter: blur(4px);
}
#onboarding-modal {
  background: var(--card); border: 1px solid var(--border2); border-radius: 16px;
  padding: 28px 24px; width: 100%; max-width: 420px; max-height: 90svh;
  overflow-y: auto; box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.ob-step        { display: none;  }
.ob-step.active { display: block; }
.ob-dot        { width: 8px; height: 8px; border-radius: 50%; background: var(--border2); transition: background 0.2s, transform 0.2s; }
.ob-dot.active { background: var(--accent); transform: scale(1.3); }
.ob-dot.done   { background: var(--accent2); }

/* ── Dashboard tappable summary cards ──────────────────────────────────── */
.card[onclick] {
  transition: background 0.12s, border-color 0.12s;
}
.card[onclick]:active {
  background: var(--raised);
  border-color: var(--border2);
}

/* ── Dashboard collapsed accordions — low visual weight ────────────────── */
details.card > summary {
  list-style: none;
  user-select: none;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary {
  margin-bottom: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── Utility ────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Sleep time inputs — prevent native clock wheel on mobile ─────────── */
input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
}
/* Keep time input readable and tappable but not full-screen clock */
input[type="time"]::-webkit-calendar-picker-indicator {
  opacity: 0.6;
  cursor: pointer;
}


/* Utility (added v3.7.0 patch) */
.row{display:flex;align-items:center;}
.between{justify-content:space-between;gap:10px;}
