:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #8a90a0;
  --accent: #3ddc84;
  --accent-soft: rgba(61, 220, 132, 0.12);
  --danger: #ff5c5c;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo { color: var(--accent); font-size: 1.1rem; }

.mes-nav {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.mes-nav h1 {
  font-size: 1rem;
  margin: 0;
  min-width: 130px;
  text-align: center;
  text-transform: capitalize;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px; 
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  display: grid; 
  place-items: center;
  transition: background .15s;
}

.icon-btn:hover { background: var(--surface-2); }

.pill {
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--accent);
  padding: 0.4rem 0.8rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.dias-semana {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 0.4rem;
}

.calendario {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.dia {
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  position: relative;
  transition: transform .1s, background .15s, border-color .15s;
  font-size: 0.9rem;
  color: var(--text);
}

.dia:hover { background: var(--surface-2); transform: translateY(-1px); }
.dia.vacio { visibility: hidden; }
.dia.hoy {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.dia.activo {
  background: var(--accent);
  color: #0b0d10;
  border-color: var(--accent);
  font-weight: 700;
}

.dia .punto {
  width: 5px; 
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.dia.activo .punto { background: #0b0d10; }
.dia .punto.kcal { background: #f5a623; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
  z-index: 10;
}

.overlay.show { opacity: 1; pointer-events: auto; }

.panel {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: min(420px, 100%);
  background: var(--bg);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 11;
  display: flex;
  flex-direction: column;
}

.panel.show { transform: translateX(0); }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.2rem 1.2rem 0.6rem;
}

.panel-fecha {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0 0 0.2rem;
  text-transform: capitalize;
}

.panel-sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem 1.2rem 2rem;
}

.bloque { margin-bottom: 1.4rem; }

.bloque-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.bloque-head h2 { font-size: 0.95rem; margin: 0; }

.add-btn {
  width: 30px; 
  height: 30px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  display: grid; 
  place-items: center;
}

.add-btn:hover { background: var(--accent); color: #0b0d10; }

.rutina-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
}

.rutina-header .del-rutina {
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
}

.rutina-header .del-rutina:hover {
  color: var(--danger);
}

.lista { display: flex; flex-direction: column; gap: 0.5rem; }

.item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  animation: fadeIn .2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.item-info { display: flex; flex-direction: column; gap: 2px; }
.item-info strong { font-size: 0.9rem; }
.item-info small { color: var(--muted); font-size: 0.75rem; }

.item img {
  width: 46px; 
  height: 46px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
}

.item-acciones { display: flex; gap: 0.3rem; }

.item-acciones button {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  font-size: 0.9rem;
}

.item-acciones button:hover { color: var(--text); }
.item-acciones .del:hover { color: var(--danger); }

.vacio {
  color: var(--muted);
  font-size: 0.8rem;
  font-style: italic;
  padding: 0.4rem 0;
}

.total-kcal {
  margin-top: 0.6rem;
  text-align: right;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: none;
  place-items: center;
  z-index: 20;
  padding: 1rem;
}

.modal.show { display: grid; }

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  width: min(380px, 100%);
  animation: pop .18s ease;
}

@keyframes pop {
  from { opacity: 0; transform: scale(.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-card h3 { margin: 0 0 0.8rem; font-size: 1rem; }
#modalCampos { display: grid; gap: 0.8rem; }

#modalCampos input[type="text"],
#modalCampos input[type="number"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem;
  border-radius: 8px;
  font-size: 0.9rem;
  width: 100%;
}

#modalCampos textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem;
  border-radius: 8px;
  font-size: 0.9rem;
  width: 100%;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}

#modalCampos input[type="file"] {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.4rem 0;
}

#modalCampos input[type="file"]::file-selector-button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  margin-right: 0.5rem;
  font-family: inherit;
  transition: background 0.15s;
}

#modalCampos input[type="file"]::file-selector-button:hover {
  background: var(--border);
}

#modalCampos .preview {
  width: 100%;
  max-height: 140px;
  object-fit: cover;
  border-radius: 8px;
  margin-top: 0.4rem;
}

#btnCalcular {
  background: var(--accent-soft) !important;
  color: var(--accent) !important;
  border: 1px solid var(--border) !important;
  padding: 0.7rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0.2rem 0;
}

#btnCalcular:hover:not(:disabled) {
  background: var(--accent) !important;
  color: #0b0d10 !important;
}

#btnCalcular:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.modal-acciones {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-acciones button {
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}

.ghost { background: transparent; color: var(--muted); }
.ghost:hover { color: var(--text); }
.primary { background: var(--accent); color: #0b0d10; }

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1.1rem;
  border-radius: 99px;
  font-size: 0.8rem;
  opacity: 0;
  transition: all .25s;
  z-index: 30;
  pointer-events: none;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 420px) {
  .app { padding: 0.8rem 0.8rem 2rem; }
  .mes-nav h1 { font-size: 0.9rem; min-width: 110px; }
  .brand span:last-child { display: none; }
}