/* ============================================================
   AvenHealth AI — Design System
   Signature: chunky hand-scored "vital" cards — thick ink borders,
   hard offset shadows, mono-numeral stat type. Light, high-energy,
   never clinical-white / never dark-mode-default.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  /* --- palette --- */
  --ink:        #14171F;
  --paper:      #FCFBF7;
  --paper-2:    #F3F1E9;
  --line:       #14171F;

  --lime:       #C6F135;
  --lime-ink:   #2B3300;
  --coral:      #FF5C72;
  --coral-ink:  #4A0A12;
  --violet:     #7B5CFA;
  --violet-ink: #211447;
  --mint:       #14E6A6;
  --mint-ink:   #003323;
  --sun:        #FFC53D;
  --sun-ink:    #402C00;

  --muted:      #6B6A63;

  /* --- geometry --- */
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --border: 2.5px;
  --shadow: 5px 5px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --shadow-press: 2px 2px 0 var(--ink);

  /* --- type --- */
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --nav-h: 72px;
  --sidebar-w: 264px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
a { color: inherit; }
::selection { background: var(--lime); color: var(--lime-ink); }

.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============================================================
   Layout shell
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---- Desktop sidebar ---- */
.sidebar {
  display: none;
  flex-direction: column;
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: var(--border) solid var(--ink);
  background: var(--paper);
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 20px;
  margin-bottom: 30px; padding: 0 6px;
}
.sidebar .brand .dot {
  width: 14px; height: 14px; background: var(--lime); border: var(--border) solid var(--ink); border-radius: 4px;
  transform: rotate(15deg);
}
.sidebar nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.side-link {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-sm);
  border: var(--border) solid transparent;
  font-weight: 600; font-size: 14.5px; color: var(--ink);
  text-decoration: none; cursor: pointer; background: none;
  text-align: left; width: 100%;
}
.side-link svg { width: 20px; height: 20px; flex-shrink: 0; }
.side-link:hover { background: var(--paper-2); }
.side-link.active {
  background: var(--lime); border-color: var(--ink); box-shadow: var(--shadow-sm);
}
.sidebar .fab-desktop {
  margin-top: 8px; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ink); color: var(--paper); border: var(--border) solid var(--ink);
  border-radius: var(--radius-sm); padding: 13px; font-weight: 700; cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.sidebar .fab-desktop:active { box-shadow: none; transform: translate(3px,3px); }
.sidebar .plan-card {
  margin-top: auto; border: var(--border) solid var(--ink); border-radius: var(--radius-md);
  padding: 14px; background: var(--paper-2); font-size: 12.5px;
}
.sidebar .plan-card .upgrade-btn {
  margin-top: 10px; width: 100%; padding: 9px; background: var(--violet); color: #fff;
  border: var(--border) solid var(--ink); border-radius: 8px; font-weight: 700; font-size: 12.5px; cursor: pointer;
}

/* ---- Topbar (all breakpoints) ---- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  height: var(--topbar-h); padding: 0 16px;
  background: var(--paper); border-bottom: var(--border) solid var(--ink);
}
.topbar .brand-mobile {
  display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 18px;
}
.topbar .brand-mobile .dot { width: 12px; height: 12px; background: var(--lime); border: 2px solid var(--ink); border-radius: 4px; transform: rotate(15deg); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border: var(--border) solid var(--ink); border-radius: 10px; background: var(--paper); cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.icon-btn:active { box-shadow: none; transform: translate(2px,2px); }
.icon-btn svg { width: 18px; height: 18px; }
.streak-chip {
  display: flex; align-items: center; gap: 5px; padding: 6px 10px;
  background: var(--sun); border: var(--border) solid var(--ink); border-radius: 999px;
  font-weight: 700; font-size: 13px;
}

/* ---- Main content ---- */
.main-content {
  flex: 1; min-width: 0;
  padding: 18px 16px calc(var(--nav-h) + 28px);
}
@media (min-width: 900px) {
  .main-content { padding: 30px 36px 40px; }
}

.view { display: none; animation: fadeUp .28s ease both; }
.view.active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: translateY(0);} }

.page-head { margin-bottom: 20px; }
.page-head .eyebrow { font-family: var(--font-mono); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.page-head h1 { font-size: 26px; margin-top: 4px; }
@media (min-width: 900px) { .page-head h1 { font-size: 32px; } }

/* ============================================================
   Bottom nav — mobile & tablet
   ============================================================ */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: var(--nav-h);
  background: var(--paper);
  border-top: var(--border) solid var(--ink);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .nav-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: none; cursor: pointer; color: var(--muted); font-size: 10.5px; font-weight: 700;
  padding: 8px 0 6px;
}
.bottom-nav .nav-btn svg { width: 22px; height: 22px; }
.bottom-nav .nav-btn.active { color: var(--ink); }
.bottom-nav .nav-btn.active .icon-wrap { background: var(--lime); border: 2px solid var(--ink); }
.bottom-nav .icon-wrap {
  width: 34px; height: 26px; display: flex; align-items: center; justify-content: center;
  border-radius: 9px; border: 2px solid transparent;
}
.bottom-nav .nav-btn.fab-slot { position: relative; }
.bottom-nav .fab {
  position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
  width: 54px; height: 54px; border-radius: 16px; background: var(--coral);
  border: var(--border) solid var(--ink); box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.bottom-nav .fab svg { width: 24px; height: 24px; }

@media (min-width: 720px) {
  .bottom-nav { grid-template-columns: repeat(5, 88px); justify-content: center; gap: 6px; }
}

@media (min-width: 980px) {
  .bottom-nav { display: none; }
  .sidebar { display: flex; }
  .app-shell { min-height: 100vh; }
}

/* ============================================================
   Cards & components
   ============================================================ */
.card {
  background: var(--paper); border: var(--border) solid var(--ink); border-radius: var(--radius-md);
  box-shadow: var(--shadow); padding: 18px;
}
.card.flat { box-shadow: none; }
.card.tight { padding: 14px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1180px) { .grid-3 { grid-template-columns: repeat(4, 1fr); } }

/* Health score ring card (signature element) */
.score-card {
  display: flex; align-items: center; gap: 20px; background: var(--ink); color: var(--paper);
  border: var(--border) solid var(--ink); box-shadow: var(--shadow); border-radius: var(--radius-lg);
  padding: 20px;
}
.score-ring-wrap { position: relative; width: 116px; height: 116px; flex-shrink: 0; }
.score-ring-wrap svg { transform: rotate(-90deg); }
.score-ring-bg { fill: none; stroke: #2A2E38; stroke-width: 11; }
.score-ring-fg { fill: none; stroke: var(--lime); stroke-width: 11; stroke-linecap: round; transition: stroke-dashoffset .6s ease; }
.score-ring-label {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.score-ring-label .num { font-size: 30px; font-weight: 700; line-height: 1; }
.score-ring-label .lbl { font-size: 10px; color: #A6A8B0; text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }
.score-card .copy h3 { font-size: 15px; color: #A6A8B0; font-weight: 500; font-family: var(--font-body); }
.score-card .copy p { margin-top: 6px; font-size: 14px; line-height: 1.5; color: #E7E7EA; }

.stat-card { display: flex; flex-direction: column; gap: 8px; }
.stat-card .stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-card .stat-icon {
  width: 34px; height: 34px; border-radius: 9px; border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center;
}
.stat-card .stat-icon svg { width: 18px; height: 18px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; font-family: var(--font-mono); }
.stat-card .stat-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat-card .bar-track { height: 8px; border-radius: 5px; background: var(--paper-2); border: 2px solid var(--ink); overflow: hidden; }
.stat-card .bar-fill { height: 100%; }

.bg-lime { background: var(--lime); } .bg-coral { background: var(--coral); color: #fff; }
.bg-violet { background: var(--violet); color: #fff; } .bg-mint { background: var(--mint); }
.bg-sun { background: var(--sun); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 2px solid var(--ink); font-size: 12px; font-weight: 700; background: var(--paper);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: var(--border) solid var(--ink); border-radius: 12px; padding: 12px 18px;
  font-weight: 700; font-size: 14px; cursor: pointer; background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.btn:active { box-shadow: none; transform: translate(3px,3px); }
.btn.primary { background: var(--lime); }
.btn.dark { background: var(--ink); color: var(--paper); }
.btn.violet { background: var(--violet); color: #fff; }
.btn.coral { background: var(--coral); color: #fff; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.input, textarea.input, select.input {
  width: 100%; border: var(--border) solid var(--ink); border-radius: 12px; padding: 12px 14px;
  font-family: inherit; font-size: 14.5px; background: var(--paper); color: var(--ink);
}
.input:focus, textarea.input:focus, select.input:focus { outline: 3px solid var(--lime); outline-offset: 1px; }
label.field-label { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); display: block; margin-bottom: 6px; }
.field { margin-bottom: 14px; }

.section-title { display: flex; align-items: center; justify-content: space-between; margin: 26px 0 12px; }
.section-title h2 { font-size: 18px; }
.section-title .see-all { font-size: 12.5px; font-weight: 700; color: var(--violet); cursor: pointer; }

.empty-state {
  border: var(--border) dashed var(--ink); border-radius: var(--radius-md); padding: 26px 18px; text-align: center;
}
.empty-state .glyph { font-size: 30px; }
.empty-state p { margin-top: 8px; color: var(--muted); font-size: 13.5px; }

/* Meal list item */
.meal-row {
  display: flex; gap: 12px; align-items: flex-start; border: var(--border) solid var(--ink);
  border-radius: var(--radius-md); padding: 12px; background: var(--paper); box-shadow: var(--shadow-sm);
}
.meal-row .grade {
  width: 38px; height: 38px; flex-shrink: 0; border: 2px solid var(--ink); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-family: var(--font-mono); font-weight: 700;
}
.meal-row .meal-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.meal-row .macros { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.meal-row .macros span { font-size: 11.5px; font-family: var(--font-mono); background: var(--paper-2); border: 2px solid var(--ink); border-radius: 6px; padding: 2px 6px; }

/* Chat */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - var(--nav-h) - 20px); }
@media (min-width: 980px) { .chat-wrap { height: calc(100vh - 60px); } }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px 16px; }
.bubble { max-width: 82%; padding: 12px 14px; border: var(--border) solid var(--ink); border-radius: var(--radius-md); font-size: 14px; line-height: 1.5; }
.bubble.user { align-self: flex-end; background: var(--lime); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--paper); box-shadow: var(--shadow-sm); border-bottom-left-radius: 4px; }
.chat-input-row { display: flex; gap: 8px; padding-top: 10px; border-top: var(--border) solid var(--ink); }
.chat-input-row textarea { resize: none; }

/* Log meal modal / capture */
.capture-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.capture-tabs button {
  flex: 1; padding: 10px; border: var(--border) solid var(--ink); border-radius: 10px; background: var(--paper);
  font-weight: 700; font-size: 13px; cursor: pointer;
}
.capture-tabs button.active { background: var(--lime); box-shadow: var(--shadow-sm); }
.photo-drop {
  border: var(--border) dashed var(--ink); border-radius: var(--radius-md); padding: 26px; text-align: center;
  cursor: pointer; background: var(--paper-2);
}
.photo-drop img { max-height: 180px; border-radius: 10px; border: 2px solid var(--ink); }
.mic-btn {
  width: 84px; height: 84px; border-radius: 50%; border: var(--border) solid var(--ink); background: var(--coral);
  color: #fff; display: flex; align-items: center; justify-content: center; margin: 8px auto; cursor: pointer;
  box-shadow: var(--shadow);
}
.mic-btn.recording { animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: var(--shadow);} 50% { box-shadow: 0 0 0 10px rgba(255,92,114,.25);} }

/* Modal (quick logs) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,23,31,.5); z-index: 60;
  display: none; align-items: flex-end; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal-sheet {
  width: 100%; max-width: 480px; background: var(--paper); border: var(--border) solid var(--ink);
  border-radius: 22px 22px 0 0; padding: 20px; max-height: 88vh; overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal-sheet { border-radius: var(--radius-lg); margin-bottom: 40px; }
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { font-size: 18px; }

/* Auth screen */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(198,241,53,.35), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(123,92,250,.25), transparent 40%),
    var(--paper);
}
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 22px; }
.auth-logo .dot { width: 18px; height: 18px; background: var(--lime); border: var(--border) solid var(--ink); border-radius: 5px; transform: rotate(15deg); }
.auth-logo span { font-family: var(--font-display); font-weight: 700; font-size: 22px; }
.auth-tagline { text-align: center; font-size: 13px; color: var(--muted); margin-bottom: 22px; }
.auth-toggle { display: flex; gap: 8px; margin-top: 16px; justify-content: center; font-size: 13.5px; }
.auth-toggle a { font-weight: 700; color: var(--violet); cursor: pointer; }
.error-text { color: var(--coral-ink); background: #FFE3E7; border: 2px solid var(--coral); border-radius: 10px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; display: none; }
.error-text.show { display: block; }

/* Toast */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper); padding: 11px 18px; border-radius: 12px; font-size: 13.5px;
  font-weight: 600; z-index: 90; opacity: 0; pointer-events: none; transition: all .25s ease;
  border: 2px solid var(--ink); box-shadow: var(--shadow-sm);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 980px) { #toast { bottom: 24px; } }

/* Disease risk pills */
.risk-row { display: flex; align-items: center; justify-content: space-between; padding: 11px 4px; border-bottom: 1.5px dashed #D8D6C9; }
.risk-row:last-child { border-bottom: none; }
.risk-level { font-size: 11.5px; font-weight: 700; padding: 4px 9px; border-radius: 999px; border: 2px solid var(--ink); }
.risk-level.low { background: var(--mint); }
.risk-level.moderate { background: var(--sun); }
.risk-level.elevated { background: var(--coral); color: #fff; }

.skeleton { background: linear-gradient(90deg, var(--paper-2) 25%, #ECE9DC 37%, var(--paper-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { 0% { background-position: 100% 0;} 100% { background-position: 0 0; } }

.hide { display: none !important; }
