:root {
  --bg: #0b0d10;
  --card: #14181d;
  --card-2: #1c2129;
  --text: #e8ecf1;
  --muted: #8a93a0;
  --accent: #ff7a45;
  --burn: #4dd0a8;
  --intake: #6ea8ff;
  --protein: #4dd0a8;
  --error: #ff5e5e;
  --green: #4dd0a8;
  --yellow: #ffc857;
  --red: #ff5e5e;
  --gray: #2a313b;
  --border: #232a33;
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-top: env(safe-area-inset-top, 0);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { padding-top: var(--safe-top); min-height: 100vh; }

.screen {
  max-width: 560px; margin: 0 auto;
  padding: 16px 16px calc(90px + var(--safe-bottom));
}

h1, h2, h3 { margin: 16px 0 12px; font-weight: 600; }
h1 { font-size: 28px; }
h2 { font-size: 22px; margin-top: 8px; }
h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--error); font-size: 14px; min-height: 18px; }
.positive { color: var(--green); }
.negative { color: var(--accent); }

.topbar { display: flex; justify-content: space-between; align-items: center; }

input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 6px 0;
  outline: none;
  min-height: 44px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

label { display: block; font-size: 13px; color: var(--muted); margin-top: 8px; }
label input, label select { margin-top: 4px; }

button {
  width: 100%;
  background: var(--accent); color: #fff;
  border: none; border-radius: 10px;
  padding: 14px;
  margin: 8px 0;
  font-weight: 600; cursor: pointer;
  -webkit-appearance: none;
  min-height: 44px;
}
button:disabled { opacity: 0.5; }
button.secondary {
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--border);
}
button.secondary.danger { color: var(--error); border-color: var(--error); }
button.link-btn {
  width: auto; background: transparent;
  padding: 8px 12px; margin: 0; font-size: 22px;
  min-height: 0;
}

.card {
  background: var(--card);
  border-radius: 14px; padding: 16px;
  margin: 8px 0;
}

/* HOME — DOS COLUMNAS */
.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin: 12px 0;
}
.col {
  background: var(--card);
  border-radius: 16px;
  padding: 18px 14px 14px;
  position: relative;
}
.col.gasto::before, .col.ingesta::before {
  content: ''; position: absolute; left: 14px; top: 14px;
  width: 4px; height: 18px; border-radius: 2px;
}
.col.gasto::before { background: var(--burn); }
.col.ingesta::before { background: var(--intake); }

.col-label {
  text-transform: uppercase; font-size: 11px;
  letter-spacing: 1px; color: var(--muted);
  font-weight: 600;
  margin-left: 12px;
  margin-bottom: 4px;
}
.col-big {
  font-size: 36px; font-weight: 700; line-height: 1;
  margin: 6px 0 4px;
}
.col-big .col-unit {
  font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 4px;
}
.col-sub {
  font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
  min-height: 18px;
}
.real-dot, .inferred-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
}
.real-dot { background: var(--green); }
.inferred-dot { background: var(--yellow); border: 1px dashed var(--yellow); }

.col-mini {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 6px; margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.col-mini > div {
  display: flex; flex-direction: column; gap: 2px;
  text-align: center;
}
.col-mini .metric-label { font-size: 10px; }
.col-mini strong { font-size: 14px; font-weight: 600; }

.balance { text-align: center; }
.balance .metric-big { font-size: 32px; font-weight: 700; line-height: 1.1; margin: 4px 0; }

.metric-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.metric { font-size: 22px; font-weight: 600; margin-top: 4px; }
.metric-big { font-size: 32px; font-weight: 700; margin-top: 4px; line-height: 1.1; }
.metric-big .small { font-size: 14px; font-weight: 400; }

.bar {
  height: 6px;
  background: var(--card-2); border-radius: 3px; overflow: hidden;
}
.bar-fill { height: 100%; background: var(--accent); transition: width 0.3s; }
.bar-fill.protein { background: var(--protein); }
.bar-fill.burn { background: var(--burn); }

/* PENDING */
.card.pending {
  background: linear-gradient(135deg, rgba(255,122,69,0.12), rgba(255,94,138,0.12));
  border: 1px solid rgba(255,122,69,0.3);
  display: flex; align-items: center; gap: 14px;
}
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--card-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}
.spinner.big { width: 56px; height: 56px; border-width: 5px; margin: 16px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* SUB-TABS dentro de Comer */
.subtabs {
  display: flex; gap: 4px;
  background: var(--card-2);
  border-radius: 10px;
  padding: 4px;
  margin: 8px 0 14px;
}
.subtabs button {
  flex: 1; margin: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px; font-weight: 600;
  padding: 10px;
  min-height: 0;
  border-radius: 7px;
  transition: all 0.15s;
}
.subtabs button.active {
  background: var(--accent);
  color: #fff;
}

/* CÁMARA trigger */
.camera-trigger {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: 18px;
  padding: 40px 20px;
  margin: 0;
  cursor: pointer;
  min-height: 160px;
  text-align: center;
  font-size: 16px;
  color: var(--muted);
}
.camera-trigger:active { border-color: var(--accent); background: var(--card-2); }
.camera-icon { font-size: 56px; margin-bottom: 8px; }

.preview-block {
  text-align: center;
  padding: 12px;
}
.preview-img {
  width: 100%; max-height: 220px; object-fit: cover;
  border-radius: 12px; margin-bottom: 8px;
  display: block;
}
.remove-photo { margin: 0; padding: 8px 14px; width: auto; min-height: 0; font-size: 13px; }

.analyzing-card { text-align: center; padding: 16px; }
.result-card { padding: 14px; }
.result-card .title { margin: 8px 0 4px; font-size: 17px; }
.result-totals {
  display: flex; justify-content: space-around;
  padding: 10px 0; gap: 6px;
  margin: 8px 0;
  background: var(--card-2);
  border-radius: 10px;
}
.result-totals > div { text-align: center; }
.result-totals strong { font-size: 17px; }
.result-totals .small { display: block; line-height: 1; }

/* Texto + mic */
.text-input-block { margin-top: 8px; }
.text-input-block textarea { margin: 0 0 8px; }
.text-input-actions { display: flex; gap: 8px; align-items: stretch; }
.text-input-actions > button:not(.mic-btn) { flex: 1; margin: 0; }
.mic-btn {
  width: 56px; flex: 0 0 auto;
  margin: 0;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 22px;
  padding: 0;
}
.mic-btn.recording {
  background: var(--error);
  border-color: var(--error);
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 4px rgba(255,94,94,0.25); }
}

/* HISTÓRICO de comidas — expandible */
.meals-list { list-style: none; padding: 0; margin: 0; }
.meal-card {
  background: var(--card);
  border-radius: 12px;
  margin-bottom: 6px;
  overflow: hidden;
}
.meal-row {
  display: grid;
  grid-template-columns: 50px 1fr 70px;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.meal-row:active { background: var(--card-2); }
.meal-time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
}
.meal-body { min-width: 0; }
.meal-desc {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 14px;
}
.meal-bar {
  margin-top: 4px; height: 3px;
  background: var(--card-2); border-radius: 2px; overflow: hidden;
}
.meal-bar-fill { height: 100%; }
.meal-bar-fill.green { background: var(--green); }
.meal-bar-fill.yellow { background: var(--yellow); }
.meal-bar-fill.red { background: var(--red); }
.meal-kcal { text-align: right; }
.meal-kcal strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.meal-kcal .small { display: block; line-height: 1; }

.meal-detail {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
}
.meal-detail ul { padding-left: 16px; margin: 8px 0; }
.meal-detail .secondary.danger { margin-top: 8px; padding: 10px; }

/* PESO */
.weight-input { padding: 14px; }
.weight-meta {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}
.weight-row {
  display: flex; gap: 8px; align-items: stretch;
}
.weight-row input { flex: 1; margin: 0; }
.weight-row .weight-btn {
  width: auto; margin: 0;
  padding: 0 18px;
  flex: 0 0 auto;
  min-width: 110px;
}

.chart-card { padding: 16px 12px; }
.chart-head { display: flex; justify-content: space-between; padding: 0 4px 8px; }
.chart { margin-bottom: 8px; }

.traffic { display: flex; gap: 2px; padding: 4px 0; height: 16px; }
.traffic .day { flex: 1; border-radius: 2px; background: var(--gray); }
.traffic .day.green { background: var(--green); }
.traffic .day.yellow { background: var(--yellow); }
.traffic .day.red { background: var(--red); }

.legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 8px 4px 0; font-size: 11px;
}
.legend .dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 2px; margin-right: 4px; vertical-align: middle;
}
.legend .dot.green { background: var(--green); }
.legend .dot.yellow { background: var(--yellow); }
.legend .dot.red { background: var(--red); }
.legend .dot.gray { background: var(--gray); }

/* Settings */
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; margin: 0; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* TABS */
.tabs {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: rgba(11,13,16,0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + var(--safe-bottom));
  z-index: 100;
}
.tabs button {
  flex: 1; background: transparent; border: none;
  padding: 8px 0 4px; margin: 0;
  opacity: 0.5;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: 0;
}
.tabs button.active { opacity: 1; }
.tabs .tab-ico { font-size: 22px; line-height: 1; }
.tabs .tab-lbl { font-size: 11px; font-weight: 500; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 200;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

textarea { min-height: 60px; resize: vertical; }

details { margin: 8px 0; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 4px 0; }
details ul { padding-left: 16px; }
