/* ====================================================================
   WEBAPP SAÚDE & EMAGRECIMENTO — Design tokens
   ==================================================================== */

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

:root {
  /* Brand */
  --brand: oklch(0.68 0.16 152);          /* health-green accent */
  --brand-strong: oklch(0.58 0.17 152);
  --brand-soft: oklch(0.94 0.04 152);
  --brand-ink: oklch(0.22 0.05 152);

  /* Light theme */
  --bg: oklch(0.985 0.003 95);
  --surface: #ffffff;
  --surface-2: oklch(0.97 0.004 95);
  --surface-3: oklch(0.94 0.005 95);
  --line: oklch(0.91 0.005 95);
  --line-strong: oklch(0.85 0.005 95);
  --ink: oklch(0.18 0.01 95);
  --ink-2: oklch(0.38 0.01 95);
  --ink-3: oklch(0.58 0.01 95);

  --pos: oklch(0.68 0.16 152);
  --neg: oklch(0.62 0.20 25);
  --warn: oklch(0.78 0.15 75);
  --info: oklch(0.65 0.13 240);

  /* Geometry */
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04), 0 1px 1px rgb(0 0 0 / 0.02);
  --shadow: 0 4px 12px rgb(0 0 0 / 0.04), 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.08), 0 2px 6px rgb(0 0 0 / 0.04);

  /* Density */
  --density: 1;
  --pad-card: calc(20px * var(--density));
  --pad-tight: calc(12px * var(--density));
  --row-h: calc(56px * var(--density));
  --gap: calc(16px * var(--density));
  --gap-sm: calc(10px * var(--density));

  /* Type */
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
}

[data-theme="dark"] {
  --bg: oklch(0.16 0.01 240);
  --surface: oklch(0.21 0.012 240);
  --surface-2: oklch(0.24 0.014 240);
  --surface-3: oklch(0.28 0.016 240);
  --line: oklch(0.30 0.015 240);
  --line-strong: oklch(0.38 0.02 240);
  --ink: oklch(0.97 0.005 240);
  --ink-2: oklch(0.78 0.01 240);
  --ink-3: oklch(0.58 0.01 240);
  --brand-soft: oklch(0.32 0.06 152);
  --brand-ink: oklch(0.92 0.08 152);

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow: 0 4px 14px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 18px 40px rgb(0 0 0 / 0.5);
}

[data-density="compact"] { --density: 0.82; }
[data-density="comfortable"] { --density: 1; }
[data-density="spacious"] { --density: 1.18; }

/* ── reset ── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; }

/* ── frame container (the inner app, both desktop & mobile) ── */
.app {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: -0.005em;
}
.app * { box-sizing: border-box; }

/* ── primitives ── */
.num {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--pad-card);
}
.card-tight { padding: var(--pad-tight); }
.card-flat { box-shadow: none; }

.divider { height: 1px; background: var(--line); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.pos { color: var(--pos); background: color-mix(in oklab, var(--pos) 12%, transparent); border-color: color-mix(in oklab, var(--pos) 25%, transparent); }
.chip.neg { color: var(--neg); background: color-mix(in oklab, var(--neg) 12%, transparent); border-color: color-mix(in oklab, var(--neg) 25%, transparent); }
.chip.brand { color: var(--brand-strong); background: var(--brand-soft); border-color: color-mix(in oklab, var(--brand) 25%, transparent); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}
.btn-primary:hover { background: oklch(from var(--ink) calc(l + 0.08) c h); }
.btn-brand {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}
.btn-brand:hover { background: var(--brand-strong); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { padding: 8px; aspect-ratio: 1; }

.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.input:focus { border-color: var(--brand); background: color-mix(in oklab, var(--brand-soft) 50%, var(--surface)); }
.input::placeholder { color: var(--ink-3); }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 500; color: var(--ink-2); }

/* ── KPI tile ── */
.kpi {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--pad-card);
  position: relative;
  overflow: hidden;
}
.kpi-label { font-size: 12px; font-weight: 500; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-family: var(--font-display); font-size: clamp(22px, 2.5vw, 32px); font-weight: 600; letter-spacing: -0.025em; }
.kpi-sub { font-size: 12px; color: var(--ink-3); }

.kpi-accent::after {
  content: '';
  position: absolute;
  inset: -1px;
  border: 1px solid var(--brand);
  border-radius: inherit;
  pointer-events: none;
  opacity: 0.5;
}

/* ── nav ── */
.sidebar {
  width: 240px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 4px;
  flex-shrink: 0;
  height: 100%;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.sidebar-brand .badge { width: 32px; height: 32px; border-radius: 9px; background: var(--ink); color: var(--surface); display: grid; place-items: center; }
.sidebar-brand .badge svg { width: 18px; height: 18px; }
.sidebar-brand h1 { font-size: 13px; font-weight: 600; margin: 0; line-height: 1.1; }
.sidebar-brand p { font-size: 11px; color: var(--ink-3); margin: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.nav-item .ico { width: 18px; height: 18px; opacity: 0.85; }
.nav-item.active .ico { color: var(--brand-strong); opacity: 1; }

/* mobile bottom tabs */
.tabs {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border-radius: var(--radius);
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 500;
}
.tab.active { color: var(--brand-strong); }
.tab .ico { width: 22px; height: 22px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-title { font-size: 18px; font-weight: 600; margin: 0; }
.topbar-sub { font-size: 12px; color: var(--ink-3); margin: 0; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
}

/* layout */
.content {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.content-mobile { padding: 16px 16px 24px; }
.row { display: flex; gap: var(--gap); }
.row.stretch > * { flex: 1; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }

@media (max-width: 720px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* table */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-3);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: var(--surface-2); }

/* mobile list */
.list-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}
.list-card:last-child { border-bottom: 0; }

/* modal */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 14, 0.4);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
  animation: fadeIn 0.18s ease;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  width: 100%;
  max-width: 460px;
  max-height: 90%;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  animation: pop 0.22s cubic-bezier(.2,.9,.3,1.1);
}
.modal-head { padding: 20px 24px 0; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 16px 24px 24px; display: flex; flex-direction: column; gap: 14px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

/* count-up animation utility */
.fade-in { animation: fadeIn 0.3s ease both; }
.slide-up { animation: slideUp 0.35s cubic-bezier(.2,.7,.2,1) both; }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.stagger > * { animation: slideUp 0.4s cubic-bezier(.2,.7,.2,1) both; }
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.06s; }
.stagger > *:nth-child(3) { animation-delay: 0.10s; }
.stagger > *:nth-child(4) { animation-delay: 0.14s; }
.stagger > *:nth-child(5) { animation-delay: 0.18s; }
.stagger > *:nth-child(6) { animation-delay: 0.22s; }
.stagger > *:nth-child(7) { animation-delay: 0.26s; }
.stagger > *:nth-child(8) { animation-delay: 0.30s; }

/* segmented control */
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}
.seg button {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-3);
  border-radius: calc(var(--radius) - 4px);
  white-space: nowrap;
}
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* bar */
.bar {
  height: 8px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: inherit;
  transition: width 0.6s cubic-bezier(.2,.7,.2,1);
}

/* mobile header */
.m-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
  flex-shrink: 0;
}
.m-header h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.m-header p { font-size: 12px; color: var(--ink-3); margin: 0; }

/* toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 60;
  animation: pop 0.25s cubic-bezier(.2,.9,.3,1.1);
}

/* dot indicator */
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); display: inline-block; }
