:root {
  --bg: #0f1419;
  --surface: #1a2330;
  --surface-2: #1e2530;
  --border: #2a3441;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #4ade80;
  --accent-2: #3b82f6;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.brand { font-weight: 700; color: var(--text); font-size: 18px; }
.user { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.btn-link {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.btn-link:hover { color: var(--text); }

/* Container */
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}
.center { display: flex; align-items: center; justify-content: center; min-height: 60vh; }
.back-link { color: var(--muted); display: inline-block; margin-bottom: 8px; }
.page-title { margin: 0 0 20px; text-transform: capitalize; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-header h2 { margin: 0; }

/* Grid */
.grid { display: grid; gap: 14px; }
.cards-resumo { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 18px; }

/* Metric */
.muted { color: var(--muted); font-size: 13px; }
.metric { margin: 6px 0; }
.metric-value { font-size: 32px; font-weight: 700; line-height: 1.1; }
.metric-label { font-size: 14px; color: var(--muted); margin-left: 4px; }

/* Progress bar */
.bar {
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  height: 6px;
  margin-top: 8px;
}
.bar-fill {
  background: var(--accent);
  height: 100%;
  transition: width 240ms ease;
}
.bar-fill.protein { background: var(--accent-2); }

/* Period switcher */
.period-switcher { display: flex; gap: 4px; }
.period-switcher a {
  padding: 4px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
}
.period-switcher a:hover { background: var(--surface-2); text-decoration: none; }
.period-switcher a.active { background: var(--accent-2); color: white; }

/* Chart card */
.chart-wrap {
  position: relative;
  height: 240px;
  width: 100%;
}
.chart-wrap canvas { display: block; max-width: 100%; }
@media (max-width: 480px) {
  .chart-wrap { height: 200px; }
}

/* Refeições */
.refs { list-style: none; padding: 0; margin: 0; }
.ref {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.ref:last-child { border-bottom: 0; }
.ref-hora { color: var(--muted); font-variant-numeric: tabular-nums; }
.ref-tipo { text-transform: capitalize; }
.ref-itens { font-size: 13px; margin-top: 2px; }
.ref-macros { text-align: right; font-size: 14px; }

/* Detail page */
.itens-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.itens-table th, .itens-table td {
  padding: 6px 8px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.itens-table th { color: var(--muted); font-weight: 500; }
.itens-table td:first-child, .itens-table th:first-child { text-align: left; }
.obs { margin-top: 12px; }

/* Forms / Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card { width: 100%; max-width: 380px; padding: 28px; }
.brand-big { margin: 0; font-size: 28px; text-align: center; }
.login-card p { text-align: center; margin: 6px 0 20px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; }
.form label span { color: var(--muted); font-size: 13px; }
.form input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
.form input:focus { outline: 2px solid var(--accent-2); border-color: transparent; }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  border: 0;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--accent-2); color: white; }
.btn-primary:hover { background: #2563eb; text-decoration: none; }

.alert { padding: 10px 12px; border-radius: 6px; font-size: 14px; margin-bottom: 12px; }
.alert-error { background: rgba(239, 68, 68, 0.12); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }

.link-small { font-size: 13px; }

@media (max-width: 480px) {
  .topbar-inner { height: 52px; }
  .container { padding: 16px 12px 40px; }
  .card { padding: 14px; }
  .metric-value { font-size: 26px; }
  .ref { grid-template-columns: 48px 1fr auto; gap: 8px; }
  .ref-itens { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
