/* ============================================================
   DIETA — Estilos  (mobile-first, sin dependencias externas)
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-bg:       #f0f4f8;
  --c-surface:  #ffffff;
  --c-surface2: #f8fafc;
  --c-border:   #e2e8f0;
  --c-accent:   #16a34a;   /* verde salud */
  --c-accent2:  #0284c7;
  --c-orange:   #ea580c;
  --c-red:      #dc2626;
  --c-yellow:   #ca8a04;
  --c-text:     #1e293b;
  --c-muted:    #64748b;
  --c-muted2:   #94a3b8;
  --r:          12px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg:  0 4px 24px rgba(0,0,0,.12);
}

html { font-size: 16px; }
body {
  background: var(--c-bg);
  color: var(--c-text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  line-height: 1.55;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--c-bg); }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }

/* ---- Layout ---- */
.app       { max-width: 640px;  margin: 0 auto; padding: 16px; }
.admin-app { max-width: 1060px; margin: 0 auto; padding: 16px; }

/* ---- Header ---- */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.header-brand { display: flex; align-items: center; gap: 9px; }
.header-icon  { font-size: 1.4rem; }
.header-title { font-size: 1rem; font-weight: 700; color: var(--c-accent); }
.header-sub   { font-size: .75rem; color: var(--c-muted); }

/* ---- Cards ---- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title { font-size: .92rem; font-weight: 700; margin-bottom: 12px; color: var(--c-text); display: flex; align-items: center; gap: 7px; }

/* ---- Botones ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px;
  font-size: .88rem; font-weight: 600; cursor: pointer;
  border: none; transition: all .15s; text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--c-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #15803d; }
.btn-blue    { background: var(--c-accent2); color: #fff; }
.btn-blue:hover:not(:disabled) { background: #0369a1; }
.btn-danger  { background: var(--c-red); color: #fff; }
.btn-warning { background: var(--c-orange); color: #fff; }
.btn-ghost   { background: transparent; color: var(--c-muted); border: 1px solid var(--c-border); }
.btn-ghost:hover:not(:disabled) { border-color: var(--c-accent); color: var(--c-accent); background: rgba(22,163,74,.05); }
.btn-sm  { padding: 6px 11px; font-size: .8rem; border-radius: 6px; }
.btn-xs  { padding: 4px 8px;  font-size: .75rem; border-radius: 5px; }
.btn-block { width: 100%; }

/* ---- Inputs ---- */
.field { margin-bottom: 13px; }
.field label { display: block; font-size: .82rem; color: var(--c-muted); margin-bottom: 4px; font-weight: 500; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 12px;
  background: var(--c-surface2); border: 1px solid var(--c-border);
  border-radius: 8px; color: var(--c-text); font-size: .9rem;
  transition: border-color .15s; font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--c-accent); background: #fff;
}
.field textarea { min-height: 72px; resize: vertical; }
.field-row { display: grid; gap: 10px; }
.field-row.cols-2 { grid-template-columns: 1fr 1fr; }
.field-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ---- Login ---- */
.login-page {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(135deg, #f0fdf4 0%, #e0f2fe 100%);
}
.login-logo  { font-size: 3.5rem; margin-bottom: 6px; }
.login-title { font-size: 1.9rem; font-weight: 800; color: var(--c-text); }
.login-sub   { color: var(--c-muted); margin-bottom: 28px; font-size: .95rem; text-align: center; }
.login-box {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 16px; padding: 28px; width: 100%; max-width: 360px;
  box-shadow: var(--shadow-lg);
}
.login-box input { font-size: 1rem; }

/* ---- Meal type pills ---- */
.meal-type-grid { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.mt-pill {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 20px; border: 1.5px solid var(--c-border);
  font-size: .82rem; font-weight: 600; cursor: pointer; background: var(--c-surface2);
  color: var(--c-muted); transition: all .12s;
}
.mt-pill:hover  { border-color: var(--c-accent); color: var(--c-accent); }
.mt-pill.active { border-color: var(--c-accent); background: rgba(22,163,74,.1); color: var(--c-accent); }

/* ---- Meal entries list ---- */
.meal-list { list-style: none; }
.meal-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 10px; margin-bottom: 8px;
  transition: box-shadow .15s;
}
.meal-item:hover { box-shadow: var(--shadow); }
.meal-icon {
  font-size: 1.4rem; min-width: 34px; text-align: center;
  padding-top: 2px;
}
.meal-content { flex: 1; min-width: 0; }
.meal-food  { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-meta  { font-size: .78rem; color: var(--c-muted); margin-top: 2px; }
.meal-notes { font-size: .78rem; color: var(--c-muted2); margin-top: 3px; font-style: italic; }
.meal-cals  { font-size: .8rem; font-weight: 700; color: var(--c-orange); white-space: nowrap; margin-top: 2px; }
.meal-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

/* ---- Day separator ---- */
.day-header {
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--c-muted);
  padding: 10px 0 5px;
  display: flex; align-items: center; gap: 8px;
}
.day-header::after { content: ''; flex: 1; height: 1px; background: var(--c-border); }

/* ---- Stats / summary ---- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 10px; padding: 12px 14px; text-align: center;
}
.stat-val  { font-size: 1.5rem; font-weight: 800; color: var(--c-accent); }
.stat-lbl  { font-size: .75rem; color: var(--c-muted); margin-top: 2px; }

/* ---- Mini bar chart ---- */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 80px; margin: 8px 0; }
.bar-col   { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.bar       { width: 100%; background: var(--c-accent); border-radius: 4px 4px 0 0; min-height: 3px; transition: height .4s; }
.bar.zero  { background: var(--c-border); }
.bar-lbl   { font-size: .65rem; color: var(--c-muted); text-align: center; white-space: nowrap; }
.bar-val   { font-size: .65rem; font-weight: 600; color: var(--c-accent); }

/* ---- Weekly plan ---- */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.plan-day  {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 10px; overflow: hidden;
}
.plan-day-header {
  padding: 9px 14px; background: var(--c-accent);
  color: #fff; font-weight: 700; font-size: .9rem; text-transform: capitalize;
}
.plan-day-body { padding: 10px 12px; }
.plan-slot { margin-bottom: 10px; }
.plan-slot-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--c-muted); margin-bottom: 3px;
  display: flex; align-items: center; gap: 4px;
}
.plan-slot-food { font-size: .88rem; font-weight: 500; color: var(--c-text); }
.plan-slot-detail { font-size: .78rem; color: var(--c-muted); }
.plan-slot-cals { font-size: .75rem; color: var(--c-orange); font-weight: 600; }
.plan-empty { color: var(--c-muted2); font-size: .82rem; font-style: italic; }

/* ---- Plan editor ---- */
.plan-editor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 14px; }
.plan-editor-day  {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 10px; overflow: hidden;
}
.plan-editor-day-header {
  padding: 9px 14px; background: #f1f5f9;
  font-weight: 700; font-size: .9rem; text-transform: capitalize;
  border-bottom: 1px solid var(--c-border); color: var(--c-text);
}
.plan-slot-editor { padding: 8px 12px; border-bottom: 1px solid var(--c-border); }
.plan-slot-editor:last-child { border-bottom: none; }
.plan-slot-editor label { font-size: .72rem; font-weight: 700; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; display: block; margin-bottom: 4px; }
.plan-slot-editor input, .plan-slot-editor textarea {
  width: 100%; padding: 5px 8px; font-size: .82rem;
  border: 1px solid var(--c-border); border-radius: 6px;
  background: var(--c-surface2); color: var(--c-text); font-family: inherit;
  margin-bottom: 4px;
}
.plan-slot-editor input:focus, .plan-slot-editor textarea:focus {
  outline: none; border-color: var(--c-accent);
}
.plan-slot-editor textarea { min-height: 50px; resize: vertical; }

/* ---- Admin sidebar / nav ---- */
.admin-layout { display: grid; grid-template-columns: 230px 1fr; gap: 16px; margin-top: 14px; }
.admin-nav { display: flex; flex-direction: column; gap: 3px; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 13px; border-radius: 8px;
  cursor: pointer; font-size: .88rem; font-weight: 500;
  color: var(--c-muted); transition: all .12s; white-space: nowrap;
}
.nav-item:hover  { background: var(--c-surface2); color: var(--c-text); }
.nav-item.active { background: rgba(22,163,74,.1); color: var(--c-accent); font-weight: 600; }
.nav-icon { font-size: 1rem; flex-shrink: 0; }
.admin-panel { display: none; }
.admin-panel.active { display: block; }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th { text-align: left; padding: 8px 11px; color: var(--c-muted); font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--c-border); }
td { padding: 9px 11px; border-bottom: 1px solid var(--c-border); vertical-align: top; }
tr:hover td { background: var(--c-surface2); }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px; backdrop-filter: blur(3px);
}
.modal {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 16px; padding: 22px; width: 100%; max-width: 480px;
  max-height: 92vh; overflow-y: auto;
  box-shadow: var(--shadow-lg); animation: slideUp .2s;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-title  { font-size: 1rem; font-weight: 700; }
.modal-close  { background: none; border: none; color: var(--c-muted); cursor: pointer; font-size: 1.2rem; padding: 2px 6px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ---- Toast ---- */
.toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 7px; align-items: center; pointer-events: none; }
.toast {
  background: var(--c-text); color: #fff; padding: 9px 16px; border-radius: 9px;
  font-size: .86rem; font-weight: 500; box-shadow: var(--shadow-lg);
  animation: fadeIn .25s, fadeOut .3s 2.7s forwards;
  max-width: 320px; text-align: center;
}
.toast.success { background: var(--c-accent); }
.toast.error   { background: var(--c-red); }
.toast.info    { background: var(--c-accent2); }

/* ---- Chips ---- */
.chip { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .72rem; font-weight: 600; }
.chip-green  { background: rgba(22,163,74,.12); color: var(--c-accent); }
.chip-orange { background: rgba(234,88,12,.1); color: var(--c-orange); }
.chip-blue   { background: rgba(2,132,199,.1); color: var(--c-accent2); }
.chip-gray   { background: var(--c-surface2); color: var(--c-muted); border: 1px solid var(--c-border); }

/* ---- Misc ---- */
.divider { border: none; border-top: 1px solid var(--c-border); margin: 14px 0; }
.text-muted  { color: var(--c-muted); }
.text-sm     { font-size: .82rem; }
.text-center { text-align: center; }
.flex  { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.hidden { display: none !important; }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c-accent); display: inline-block; animation: pulse 2s infinite; }

/* ---- Calories ring (mini) ---- */
.cal-badge { font-size: .75rem; color: var(--c-orange); font-weight: 700; white-space: nowrap; }

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 32px 16px; color: var(--c-muted); }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 8px; }
.empty-state p { font-size: .9rem; }

/* ---- Tab bar (usuario) ---- */
.tab-bar {
  display: flex; gap: 0;
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 10px; padding: 3px; margin-bottom: 16px;
}
.tab-btn {
  flex: 1; padding: 8px; border-radius: 8px; border: none;
  background: transparent; font-size: .84rem; font-weight: 600;
  color: var(--c-muted); cursor: pointer; transition: all .12s;
}
.tab-btn.active { background: var(--c-accent); color: #fff; }

/* ---- Animations ---- */
@keyframes fadeIn  { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeOut { from { opacity:1; } to { opacity:0; } }
@keyframes slideUp { from { opacity:0; transform:translateY(18px); } to { opacity:1; transform:translateY(0); } }
@keyframes pulse   { 0%,100%{box-shadow:0 0 0 0 rgba(22,163,74,.4)} 50%{box-shadow:0 0 0 5px rgba(22,163,74,0)} }
.anim-in { animation: fadeIn .25s both; }

/* ============================================================
   RESPONSIVE — Tablet y móvil
   ============================================================ */

/* ---- Tablet (≤ 900px) ---- */
@media (max-width: 900px) {
  .admin-app { padding: 10px; }
  .plan-editor-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

/* ---- Móvil (≤ 680px): layout admin sidebar → nav horizontal ---- */
@media (max-width: 680px) {
  /* Layout: una sola columna */
  .admin-layout { grid-template-columns: 1fr; gap: 10px; margin-top: 8px; }
  .admin-app { padding: 8px; }

  /* Sidebar nav → barra horizontal scrollable */
  .admin-sidebar-nav {
    display: flex !important;
    flex-direction: row !important;
    overflow-x: auto;
    gap: 2px;
    padding: 4px !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .admin-sidebar-nav::-webkit-scrollbar { display: none; }
  .admin-sidebar-nav .nav-item {
    flex-direction: column;
    align-items: center;
    gap: 3px;
    font-size: .68rem;
    padding: 7px 10px;
    min-width: 58px;
    text-align: center;
    border-radius: 8px;
    flex-shrink: 0;
  }
  .admin-sidebar-nav .nav-icon { font-size: 1.1rem; }
  .admin-sidebar-nav .divider { display: none; }

  /* User selector: compacto y pegado al nav */
  #user-selector-box { margin-top: 6px !important; }
  #user-selector-box .card-title { margin-bottom: 5px; }

  /* Header: compacto */
  .header { padding: 9px 12px; }
  .header-icon { font-size: 1.2rem; }
  .header-title { font-size: .9rem; }
  .header-sub { display: none; }
  .header .btn-sm { padding: 5px 9px; font-size: .75rem; }

  /* Botones en fila: wrap */
  .flex.gap-8  { flex-wrap: wrap; }
  .flex.gap-12 { flex-wrap: wrap; }

  /* Fields: cols-2 y cols-3 apilan */
  .field-row.cols-2,
  .field-row.cols-3 { grid-template-columns: 1fr !important; }

  /* Modal: slide-up desde abajo (sheet) */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: 20px 20px 0 0;
    max-height: 93vh;
    max-width: 100%;
    padding: 20px 18px 28px;
  }

  /* Tabla: compactar texto */
  table  { font-size: .78rem; min-width: 500px; }
  th     { padding: 7px 9px; }
  td     { padding: 7px 9px; }
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* indicador visual de scroll */
    background:
      linear-gradient(to right, white 30%, rgba(255,255,255,0)) center left,
      linear-gradient(to left,  white 30%, rgba(255,255,255,0)) center right,
      radial-gradient(farthest-side at 0%   50%, rgba(0,0,0,.08), transparent) center left,
      radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,.08), transparent) center right;
    background-repeat: no-repeat;
    background-size: 40px 100%, 40px 100%, 8px 100%, 8px 100%;
    background-attachment: local, local, scroll, scroll;
  }

  /* Plan editor: una columna; días como horizontal scroll */
  .plan-editor-grid {
    display: flex;
    overflow-x: auto;
    gap: 10px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }
  .plan-editor-day {
    min-width: 280px;
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  /* Plan vista usuario: scroll horizontal */
  .plan-grid {
    display: flex;
    overflow-x: auto;
    gap: 10px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }
  .plan-day {
    min-width: 260px;
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  /* Stat grid */
  .stat-grid { gap: 7px; }
  .stat-val   { font-size: 1.25rem; }

  /* Login box: full width */
  .login-box { padding: 20px 16px; }
  .login-title { font-size: 1.5rem; }

  /* Meal pills: más compactos */
  .mt-pill { padding: 5px 10px; font-size: .78rem; }

  /* Botones de acción en tabla: apilar */
  td .flex { gap: 4px; }

  /* Ocultar columnas menos importantes en tablas admin */
  .hide-mobile { display: none !important; }

  /* Toast más abajo en móvil */
  .toast-container { bottom: 16px; width: calc(100% - 32px); left: 16px; transform: none; }
  .toast { width: 100%; }
}

/* ---- Muy pequeño (≤ 380px) ---- */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-grid > :nth-child(3) { grid-column: 1 / -1; }
  .header-title { font-size: .84rem; }
  .btn-sm { padding: 5px 8px; font-size: .72rem; }
  .meal-food { font-size: .88rem; }
}

/* ---- Indicador de scroll horizontal para plan ---- */
.scroll-hint {
  font-size: .72rem; color: var(--c-muted2); text-align: center;
  margin-top: 4px; display: none;
}
@media (max-width: 680px) { .scroll-hint { display: block; } }

