/* =============================================================================
 * Box Nutri Tracker — estilos v3. Mobile-first (PWA iPhone) + escritorio.
 * Timeline con rail + badges, color por tipo de bloque, fondo con profundidad.
 * ========================================================================== */
:root {
  --bg:        #0c0e12;
  --card:      #161a21;
  --card-2:    #1c212b;
  --card-hi:   #232a36;
  --line:      #28303c;
  --line-soft: #1f2530;
  --text:      #eaeef4;
  --muted:     #9098a6;
  --muted-2:   #5f6776;
  --accent:    #ef4444;
  --accent-2:  #ff6a6a;
  --gold:      #f5b942;
  --green:     #34d399;
  --blue:      #60a5fa;
  --radius:    18px;
  --radius-sm: 13px;
  --shadow:    0 18px 40px -12px rgba(0,0,0,.6);
  --shadow-sm: 0 6px 18px -6px rgba(0,0,0,.5);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(34px + var(--sab));
  background:
    radial-gradient(880px 520px at 100% -6%, rgba(239,68,68,.13), transparent 58%),
    radial-gradient(760px 600px at -12% 112%, rgba(96,165,250,.08), transparent 55%),
    radial-gradient(600px 400px at 50% 40%, rgba(245,185,66,.03), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

button { font-family: inherit; -webkit-tap-highlight-color: transparent; }
button:active { transform: scale(.97); }

/* ---------------- Header ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 14px;
  padding: calc(14px + var(--sat)) calc(22px + var(--sar)) 14px calc(22px + var(--sal));
  background: rgba(12, 14, 18, .72);
  backdrop-filter: saturate(160%) blur(20px);
  -webkit-backdrop-filter: saturate(160%) blur(20px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 13px; }
.logo {
  width: 46px; height: 46px; display: grid; place-items: center; font-size: 25px;
  background: linear-gradient(140deg, #ff6a6a, #c01f1f);
  border-radius: 14px; box-shadow: 0 8px 20px -6px rgba(239,68,68,.6);
}
.brand h1 { font-size: 19px; font-weight: 800; letter-spacing: -.2px; }
.clock { color: var(--muted); font-size: 12.5px; margin-top: 1px; }

.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  display: flex; align-items: center; gap: 9px;
  background: var(--card); border: 1px solid var(--line-soft);
  padding: 8px 14px; border-radius: 14px;
}
.stat-value { font-size: 19px; font-weight: 800; line-height: 1.1; letter-spacing: -.3px; }
.stat-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-top: 2px; }
.stat.streak { background: linear-gradient(140deg, rgba(245,185,66,.18), rgba(245,185,66,.04)); border-color: rgba(245,185,66,.32); }
.stat.streak .stat-icon { font-size: 24px; filter: drop-shadow(0 0 9px rgba(245,185,66,.45)); }
.stat.streak .stat-value { color: var(--gold); }

/* ---------------- Tabs ---------------- */
.tabs {
  display: flex; align-items: center; gap: 8px;
  padding: 12px calc(22px + var(--sar)) 12px calc(22px + var(--sal)); flex-wrap: wrap;
  border-bottom: 1px solid var(--line-soft);
}
.tab {
  background: transparent; color: var(--muted);
  border: 1px solid transparent; border-radius: 12px;
  padding: 9px 17px; font-size: 14px; font-weight: 700; cursor: pointer; transition: .15s; min-height: 40px;
}
.tab:hover { color: var(--text); }
.tab.active { background: linear-gradient(135deg, var(--accent), #b81d1d); color: #fff; box-shadow: 0 6px 16px -4px rgba(239,68,68,.5); }
.tab-spacer { flex: 1 1 30px; }
.ghost {
  background: var(--card); color: var(--muted); border: 1px solid var(--line);
  border-radius: 11px; padding: 8px 13px; font-size: 12.5px; cursor: pointer; transition: .15s; min-height: 38px;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }

/* ---------------- Paneles ---------------- */
.panel { padding: 22px calc(20px + var(--sar)) 0 calc(20px + var(--sal)); max-width: 820px; margin: 0 auto; }
.hidden { display: none !important; }

.view-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.view-label { font-weight: 800; font-size: 14px; padding: 8px 16px; border-radius: 22px; letter-spacing: -.1px; }
.view-label.training { background: rgba(239,68,68,.15); color: var(--accent-2); border: 1px solid rgba(239,68,68,.4); }
.view-label.rest { background: rgba(96,165,250,.15); color: var(--blue); border: 1px solid rgba(96,165,250,.4); }
.view-switch { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.seg { background: var(--card); color: var(--muted); border: 1px solid var(--line); padding: 8px 13px; border-radius: 10px; font-size: 12.5px; cursor: pointer; min-height: 36px; transition: .15s; }
.seg.active { background: var(--card-hi); color: var(--text); border-color: var(--accent); }

/* ---------------- Banner AHORA ---------------- */
.now-banner {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(100deg, rgba(239,68,68,.26), rgba(239,68,68,.05));
  border: 1px solid rgba(239,68,68,.55); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 18px; font-size: 15px;
  box-shadow: 0 10px 28px -10px rgba(239,68,68,.4);
}
.now-banner .pulse { color: var(--accent-2); animation: pulse 1.4s infinite; font-size: 12px; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1);} 50% { opacity: .25; transform: scale(.7);} }

/* ---------------- Resumen de macros ---------------- */
.macro-summary {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--line-soft); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 24px; box-shadow: var(--shadow-sm);
}
.macro-cell { text-align: center; padding: 16px 6px; background: var(--card); }
.m-label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.m-val { font-size: 23px; font-weight: 800; margin-top: 5px; letter-spacing: -.5px; }
.m-val .of, .of { font-size: 12px; color: var(--muted-2); font-weight: 600; margin-left: 2px; }
.macro-progress { grid-column: 1 / -1; padding: 15px 16px 17px; background: var(--card); }
.bar-track { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,.6); }
.bar-fill { height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width .45s ease; }
.bar-caption { font-size: 12px; color: var(--muted); margin-top: 9px; text-align: center; }

/* ---------------- Timeline (rail + badges) ---------------- */
.timeline { display: flex; flex-direction: column; gap: 12px; padding-bottom: 14px; }

/* color por tipo de bloque */
.type-meal     { --tc: #f5b942; }
.type-supp     { --tc: #60a5fa; }
.type-training { --tc: #ef4444; }
.type-free     { --tc: #2dd4bf; }
.type-info     { --tc: #a78bfa; }

.block {
  position: relative;
  display: grid; grid-template-columns: 52px 1fr; gap: 14px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.block-rail { position: relative; display: flex; flex-direction: column; align-items: center; gap: 7px; }
.block-rail::before {
  content: ''; position: absolute; top: 22px; left: 50%; transform: translateX(-50%);
  width: 2px; height: calc(100% + 12px); background: var(--line); z-index: 0;
}
.block:last-child .block-rail::before { display: none; }
.badge {
  position: relative; z-index: 1;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 20px;
  background: var(--card-2); border: 2px solid var(--tc);
  box-shadow: 0 0 0 4px rgba(0,0,0,.15), 0 4px 12px -4px var(--tc);
}
.block-time { font-size: 11px; font-weight: 700; color: var(--muted); text-align: center; line-height: 1.2; }
.now-tag { font-size: 9px; font-weight: 800; color: #fff; background: var(--accent); border-radius: 5px; padding: 2px 6px; letter-spacing: .5px; box-shadow: 0 2px 8px rgba(239,68,68,.6); }

.block-body { min-width: 0; }
.block-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.block-title { font-size: 16.5px; font-weight: 800; letter-spacing: -.2px; }
.macros { font-size: 11.5px; color: var(--gold); font-weight: 700; white-space: nowrap; }
.macros.free-macro { color: var(--green); }
.items { list-style: none; margin: 11px 0 0; display: flex; flex-wrap: wrap; gap: 7px; }
.items li { background: var(--card-2); border: 1px solid var(--line); border-radius: 9px; padding: 5px 11px; font-size: 12.5px; }
.note { font-size: 12.5px; color: var(--muted); margin-top: 11px; line-height: 1.6; }
.block-actions { margin-top: 14px; }

.check {
  background: transparent; color: var(--accent-2); border: 1.5px solid var(--accent);
  border-radius: 12px; padding: 11px 20px; font-size: 13.5px; font-weight: 700; cursor: pointer; transition: .15s; min-height: 44px;
}
.check:hover { background: rgba(239,68,68,.12); }
.check.checked { background: var(--green); border-color: var(--green); color: #052017; }
.check[disabled] { opacity: .4; cursor: not-allowed; }
.optional-tag { font-size: 12px; color: var(--muted-2); font-style: italic; }

/* estados */
.block.current { border-color: var(--tc); background: var(--card-hi); box-shadow: 0 0 0 1px var(--tc), var(--shadow); }
.block.current .badge { box-shadow: 0 0 0 4px rgba(0,0,0,.2), 0 0 18px -2px var(--tc); transform: scale(1.05); }
.block.done .badge { background: var(--green); border-color: var(--green); color: #052017; }
.block.done .block-title::after { content: ' ✓'; color: var(--green); }
.block.past { opacity: .55; }
.block.type-free { background: linear-gradient(180deg, rgba(45,212,191,.05), transparent); border-style: dashed; }
.block.type-info { background: linear-gradient(180deg, rgba(167,139,250,.08), transparent); border-color: rgba(167,139,250,.35); }
.block.type-info .note { color: #c4b5fd; }
.block.type-info .items li { border-color: rgba(167,139,250,.35); background: rgba(167,139,250,.08); }
@media (hover: hover) { .block:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); } }

/* ---------------- Cards (progreso) ---------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.card h2 { font-size: 16px; margin-bottom: 14px; font-weight: 800; letter-spacing: -.2px; }
.muted { color: var(--muted); font-size: 13px; }
.chart { width: 100%; height: auto; background: var(--bg); border-radius: 12px; }
.weekly { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.weekly th, .weekly td { text-align: left; padding: 10px 9px; border-bottom: 1px solid var(--line-soft); }
.weekly th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.weekly td.good { color: var(--green); font-weight: 700; }
.weekly td.bad { color: var(--accent-2); font-weight: 700; }
.weekly td.flat { color: var(--gold); font-weight: 700; }
.weekly td.empty, .empty { color: var(--muted); text-align: center; padding: 18px; }
.adjustments { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.adj { display: flex; gap: 12px; padding: 13px 15px; background: var(--card-2); border-radius: var(--radius-sm); border-left: 4px solid var(--line); }
.adj-icon { font-size: 20px; }
.adj-msg { font-size: 13.5px; line-height: 1.5; }
.adj-meta { font-size: 11px; color: var(--muted-2); margin-top: 5px; }
.adj-maintain { border-left-color: var(--green); }
.adj-rice_up { border-left-color: var(--blue); }
.adj-rice_down { border-left-color: var(--accent); }
.adj-watch { border-left-color: var(--gold); }
.adj-warn { border-left-color: var(--accent-2); }
.adj-empty { color: var(--muted); font-size: 13px; }

/* ---------------- Modal ---------------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.66);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: calc(20px + var(--sat)) 20px calc(20px + var(--sab)); animation: fadein .2s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal-box { background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 28px; max-width: 420px; width: 100%; box-shadow: var(--shadow); animation: pop .22s cubic-bezier(.2,.9,.3,1.2); }
@keyframes pop { from { transform: scale(.94); opacity: .5; } to { transform: scale(1); opacity: 1; } }
.modal-box h2 { font-size: 20px; margin-bottom: 8px; font-weight: 800; }
.input-row { display: flex; align-items: center; gap: 10px; margin: 20px 0 6px; }
.input-row input { flex: 1; background: var(--bg); border: 1.5px solid var(--line); border-radius: 14px; padding: 16px; font-size: 30px; color: var(--text); text-align: center; font-weight: 800; }
.input-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(239,68,68,.16); }
.unit { font-size: 18px; color: var(--muted); }
.error { color: var(--accent-2); font-size: 13px; min-height: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.primary { background: linear-gradient(135deg, var(--accent), #b81d1d); color: #fff; border: none; border-radius: 12px; padding: 12px 24px; font-size: 15px; font-weight: 700; cursor: pointer; min-height: 46px; box-shadow: 0 8px 20px -6px rgba(239,68,68,.5); }
.primary:hover { filter: brightness(1.08); }

.foot { text-align: center; color: var(--muted-2); font-size: 11.5px; padding: 28px 20px 0; max-width: 700px; margin: 0 auto; }

/* ---------------- Mobile ---------------- */
@media (max-width: 560px) {
  .topbar { align-items: center; gap: 10px 8px; padding-bottom: 12px; }
  .logo { width: 40px; height: 40px; font-size: 22px; }
  .brand { flex: 1 1 auto; }
  .brand h1 { font-size: 17px; }
  .stats { display: contents; }
  .topbar .stat { padding: 7px 10px; min-width: 0; }
  .topbar .stat.streak { flex: 0 0 auto; }
  .topbar .stat:not(.streak) { flex: 1 1 0; justify-content: center; }
  .stat-value { font-size: 17px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab, .ghost { flex: 0 0 auto; white-space: nowrap; }
  .tab-spacer { display: none; }
  .macro-summary { grid-template-columns: repeat(2, 1fr); }
  .macro-progress { grid-column: 1 / -1; }
  .block { grid-template-columns: 46px 1fr; gap: 12px; padding: 15px 16px; }
  .badge { width: 40px; height: 40px; font-size: 18px; }
  .block-rail::before { top: 20px; }
}
