/* ============ TOKENS ============ */
:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --surface-2: #F1F5F2;
  --text: #22302A;
  --text-muted: #6B7A72;
  --border: rgba(34,48,42,0.08);
  --primary: #2E8B6F;
  --primary-dark: #1F6B54;
  --accent: #F4A261;
  --coral: #E76F51;
  --blue: #5AA9E6;
  --ring-track: rgba(34,48,42,0.08);
  --shadow: 0 2px 10px rgba(20,30,25,0.06), 0 1px 2px rgba(20,30,25,0.04);
  --radius: 18px;
  --radius-sm: 12px;
  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}
html.dark {
  --bg: #10160F;
  --surface: #182620;
  --surface-2: #1E2E27;
  --text: #E7F1EB;
  --text-muted: #8FA79C;
  --border: rgba(231,241,235,0.08);
  --primary: #45B08B;
  --primary-dark: #2E8B6F;
  --ring-track: rgba(231,241,235,0.09);
  --shadow: 0 2px 14px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 88px;
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0 0 4px; }
h1 { font-size: 1.6rem; }
h3 { font-size: 1.05rem; color: var(--text); }
.muted { color: var(--text-muted); font-size: 0.88rem; }
button { font-family: var(--font-body); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ============ TOPBAR ============ */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  max-width: 720px; margin: 0 auto; position: sticky; top: 0; z-index: 15;
  background: var(--bg);
}
.greeting { flex: 1; min-width: 0; }
.greeting-line { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.greeting-date { font-size: 0.78rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center; font-family: var(--font-body);
}
.bell-dot {
  position: absolute; top: 2px; right: 2px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--coral); display: inline-block;
}
#bell-btn { position: relative; font-size: 1.15rem; }

/* ============ DRAWER ============ */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(10,15,12,0.5); z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.drawer-backdrop.show { opacity: 1; pointer-events: all; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 250px; background: var(--surface);
  z-index: 95; padding: 20px 12px; transform: translateX(-100%); transition: transform 0.25s ease;
  display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
}
.drawer.open { transform: translateX(0); }
.drawer-brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-size: 1.15rem; padding: 6px 10px 16px; }
.drawer-logo { width: 32px; height: 32px; border-radius: 8px; object-fit: cover; }
.drawer-brand .brand-name b { color: var(--primary); }
.drawer-item {
  display: flex; align-items: center; gap: 10px; border: none; background: transparent; color: var(--text);
  padding: 12px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 0.92rem; text-align: left;
}
.drawer-item:hover { background: var(--surface-2); }
.drawer-item.active { background: rgba(46,139,111,0.14); color: var(--primary); font-weight: 600; }

/* ============ NOTIFICATION PANEL ============ */
.notif-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: 300px; max-width: 88vw; background: var(--surface);
  z-index: 95; padding: 16px; transform: translateX(100%); transition: transform 0.25s ease; box-shadow: var(--shadow);
  overflow-y: auto;
}
.notif-panel.open { transform: translateX(0); }
.notif-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.notif-item { border-bottom: 1px solid var(--border); padding: 10px 0; }
.notif-item b { font-size: 0.88rem; }
.notif-item span { float: right; font-size: 0.72rem; }
.notif-item p { margin: 4px 0 0; font-size: 0.82rem; color: var(--text-muted); }

/* ============ LAYOUT ============ */
.view { max-width: 720px; margin: 0 auto; padding: 0 16px 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 16px; gap: 10px; }
.page-head--back { justify-content: flex-start; }
.eyebrow { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--primary); font-weight: 600; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-head-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

.grid { display: grid; gap: 12px; }
.grid--2 { grid-template-columns: 1fr 1fr; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 420px) { .grid--3 { grid-template-columns: repeat(3, 1fr); gap: 8px; } }

/* ============ HERO / RINGS ============ */
.card--hero { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.card--hero-sm .ring-wrap svg { width: 92px; height: 92px; }
.ring-wrap svg { display: block; }
.ring-anim { transition: stroke-dashoffset 0.8s cubic-bezier(.4,0,.2,1); }
.hero-kcal { display: flex; flex-direction: column; }
.hero-kcal span { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 500; }
.hero-kcal label { font-size: 0.72rem; color: var(--text-muted); }
.dot-list { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: 8px; }
.dot-item { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dot-label { flex: 1; color: var(--text-muted); }
.dot-value { font-family: var(--font-mono); font-size: 0.8rem; }

/* ============ MINI CARDS (agua/sal/comidas) ============ */
.card--mini { padding: 12px; text-align: center; }
.mini-icon {
  width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 1rem; margin: 0 auto 6px;
}
.mini-label { font-size: 0.72rem; }
.mini-value { font-family: var(--font-mono); font-size: 0.86rem; font-weight: 500; }

/* ============ LAST MEAL / MEAL ROWS ============ */
.last-meal { display: flex; align-items: center; gap: 12px; }
.thumb { width: 44px; height: 44px; border-radius: 12px; object-fit: cover; flex-shrink: 0; }
.thumb--lg { width: 64px; height: 64px; border-radius: 14px; }
.thumb--sm { width: 38px; height: 38px; border-radius: 10px; }
.thumb--emoji { display: flex; align-items: center; justify-content: center; background: var(--surface-2); font-size: 1.3rem; }

.meal-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.meal-row:last-child { border-bottom: none; }
.meal-row-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.meal-row-body b { font-size: 0.88rem; }
.meal-row-body span { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meal-row-kcal { font-family: var(--font-mono); font-size: 0.85rem; color: var(--primary); white-space: nowrap; }

.day-summary { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-muted); }

/* ============ BUTTONS ============ */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 10px 16px; border-radius: 999px; font-size: 0.88rem; cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--primary); color: white; border-color: transparent; }
.btn--ghost { background: transparent; }
.btn--danger { background: transparent; color: var(--coral); border-color: var(--coral); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.file-btn { display: inline-flex; align-items: center; }
.icon-btn {
  border: none; background: transparent; color: var(--text-muted); font-size: 1.05rem;
  cursor: pointer; width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }

/* ============ NAV ============ */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
  border-top: 1px solid var(--border); display: flex; align-items: center; z-index: 20;
  padding-bottom: env(safe-area-inset-bottom); max-width: 720px; margin: 0 auto;
}
.navitem {
  flex: 1; border: none; background: transparent; color: var(--text-muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px; font-size: 0.66rem; cursor: pointer;
}
.navitem.active { color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 1.1rem; }
.fab-inline {
  width: 50px; height: 50px; border-radius: 50%; background: var(--primary); color: #fff;
  border: none; font-size: 1.6rem; cursor: pointer; margin: 0 6px; transform: translateY(-10px);
  box-shadow: 0 6px 16px rgba(46,139,111,0.4); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; line-height: 0;
}

/* ============ FORMS ============ */
.input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 0.92rem; margin-bottom: 4px;
}
.input--sm { width: auto; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: 12px; }
@media (min-width: 480px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.form-grid label { font-size: 0.78rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.segmented { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; }
.seg-btn { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 999px; cursor: pointer; color: var(--text-muted); font-size: 0.82rem; }
.seg-btn.active { background: var(--primary); color: white; }

/* ============ SETTINGS LIST ROWS ============ */
.list-row {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
}
.list-row--flat {
  padding: 12px 0; border-bottom: 1px solid var(--border); margin: 0 -18px; padding-left: 18px; padding-right: 18px;
}
.list-row--flat.no-border { border-bottom: none; }
.row-icon { font-size: 1.1rem; width: 26px; text-align: center; }
.list-row-body { flex: 1; display: flex; flex-direction: column; }
.list-row-body b { font-size: 0.9rem; }
.row-value { font-size: 0.82rem; white-space: nowrap; }
.chevron { color: var(--text-muted); font-size: 1.1rem; }

/* ============ TABS ============ */
.tabs { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }
.tabs--sub { margin-bottom: 16px; }
.tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
  padding: 8px 16px; border-radius: 999px; cursor: pointer; white-space: nowrap; font-size: 0.85rem;
}
.tab.active { background: var(--primary); color: white; border-color: transparent; }
.tab--ghost { background: transparent; border-color: transparent; padding: 6px 12px; }
.tab--ghost.active { background: rgba(46,139,111,0.14); color: var(--primary); }

/* ============ MODAL ============ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10,15,12,0.55);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
  opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.modal-backdrop.show { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border-radius: 22px 22px 0 0; padding: 20px; animation: slideUp 0.25s ease;
}
@media (min-width: 620px) { .modal-backdrop { align-items: center; } .modal { border-radius: var(--radius); } }
.modal--small { max-width: 420px; }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 8px; }
.modal-head--back { justify-content: flex-start; }
.modal-head--back h3 { flex: 1; }

/* ============ NUEVA COMIDA — LISTA DE MÉTODOS ============ */
.method-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.method-row {
  display: flex; align-items: center; gap: 14px; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--radius-sm); padding: 14px; cursor: pointer; text-align: left; width: 100%;
}
.method-icon {
  width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0;
}
.method-text { display: flex; flex-direction: column; gap: 2px; }
.method-text b { font-size: 0.92rem; }
.method-row--add { margin-top: 6px; justify-content: flex-start; }

/* ============ IA DETECTADO ============ */
.ia-detected { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-top: 12px; }
.ia-detected-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.badge { background: rgba(46,139,111,0.14); color: var(--primary); font-size: 0.72rem; padding: 3px 10px; border-radius: 999px; }
.ia-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.ia-item:last-child { border-bottom: none; }

/* ============ MEAL CAPTURE / DRAFT ITEMS ============ */
.photo-capture video, .draft-photo, #photo-preview { width: 100%; border-radius: var(--radius-sm); background: #000; max-height: 240px; object-fit: cover; }
.search-results { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.search-item {
  text-align: left; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; display: flex; justify-content: space-between;
}
.selected-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.selected-item span:first-child { flex: 1; }

.draft-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; }
.draft-item-info { flex: 1; min-width: 0; }
.draft-item-head { display: flex; align-items: center; gap: 8px; }
.draft-item-head b { flex: 1; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-item-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.confidence { font-size: 0.66rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.confidence--high { background: rgba(46,139,111,0.15); color: var(--primary); }
.confidence--mid { background: rgba(244,162,97,0.2); color: #B5651D; }
.confidence--low { background: rgba(231,111,81,0.18); color: var(--coral); }

.macro-summary {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin-top: 14px;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 6px;
}
.macro-summary div { display: flex; flex-direction: column; gap: 2px; }
.macro-summary b { font-family: var(--font-mono); font-size: 0.95rem; }
.macro-summary span { font-size: 0.66rem; color: var(--text-muted); }

/* ============ CALENDAR ============ */
.cal-nav { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-grid--labels { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 4px; }
.cal-cell {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 50%; cursor: pointer; font-size: 0.8rem; background: transparent;
}
.cal-cell--empty { background: transparent; cursor: default; }
.cal-cell.has-data { background: rgba(46,139,111,0.14); }
.cal-cell.is-today { background: var(--primary); color: #fff; font-weight: 600; }

/* ============ STAT BOXES (estadísticas) ============ */
.stat-box { display: flex; align-items: center; gap: 12px; }
.stat-box-icon { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0; }
.stat-box b { font-size: 1.05rem; font-family: var(--font-mono); display: block; }
.stat-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.stat-line:last-child { border-bottom: none; }
.stat-line .accent { color: var(--primary); }
.legend-row { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 0.8rem; }
.legend-row i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }

/* ============ IMPORT/EXPORT ============ */
.format-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
@media (max-width: 460px) { .format-grid { grid-template-columns: repeat(3, 1fr); } }
.format-tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 4px;
  border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.72rem; color: var(--text);
}
.format-tile span { font-size: 1.3rem; }
.format-tile.active { border-color: var(--primary); background: rgba(46,139,111,0.14); color: var(--primary); }

/* ============ CHARTS ============ */
.chart-box { position: relative; height: 220px; }
.chart-box--sm { height: 200px; max-width: 260px; margin: 0 auto; }

/* ============ TOASTS ============ */
#toast-host { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow);
  padding: 10px 18px; border-radius: 999px; font-size: 0.85rem; opacity: 0; transform: translateY(-10px);
  transition: all 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast--error { border-color: var(--coral); color: var(--coral); }
.toast--success { border-color: var(--primary); color: var(--primary); }

.lock-screen { display: flex; align-items: center; justify-content: center; height: 100vh; font-family: var(--font-display); font-size: 1.3rem; }

/* ============ INSTALL BANNER ============ */
.install-banner {
  position: fixed; left: 12px; right: 12px; bottom: 76px; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; display: flex; align-items: center; gap: 12px;
  max-width: 700px; margin: 0 auto; animation: slideUp 0.3s ease;
}
.install-banner img { width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0; }
.install-banner-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.install-banner-text b { font-size: 0.9rem; }
.install-banner-text span { font-size: 0.78rem; color: var(--text-muted); }
.install-banner-actions { display: flex; gap: 6px; flex-shrink: 0; }
@media (max-width: 420px) {
  .install-banner { flex-wrap: wrap; }
  .install-banner-actions { width: 100%; justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  .ring-anim, .modal, .toast { transition: none !important; animation: none !important; }
}
