:root {
  --bg: #f6f4f1;
  --accent: #c2410c;
  --accent-dark: #9a3412;
  --accent-soft: #ffedd5;
  --ink: #1c1917;
  --muted: #79716b;
  --bubble-coach: #ffffff;
  --bubble-user: #c2410c;
  --danger: #dc2626;
  --ok: #15803d;
  --line: #e7e2dc;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ---------- LOGIN ---------- */
.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #1c1917 0%, #44403c 55%, #c2410c 140%);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 22px;
  padding: 32px 24px 26px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}

.login-logo { font-size: 44px; line-height: 1; }
.login-card h1 { font-size: 25px; margin: 14px 0 6px; line-height: 1.2; letter-spacing: -.3px; }
.login-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }

#login-form { display: flex; flex-direction: column; gap: 10px; }

#pin {
  width: 100%;
  padding: 15px 16px;
  font-size: 20px;
  text-align: center;
  letter-spacing: 7px;
  border: 1.5px solid var(--line);
  border-radius: 13px;
  outline: none;
  background: #faf9f7;
}
#pin:focus { border-color: var(--accent); background: #fff; }

#login-btn {
  padding: 15px;
  font-size: 16px;
  font-weight: 650;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 13px;
  cursor: pointer;
}
#login-btn:active { background: var(--accent-dark); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 0; }

/* ---------- APP ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-info { display: flex; align-items: center; gap: 10px; min-width: 0; }

.avatar {
  width: 38px; height: 38px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: grid; place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

.coach-name { font-weight: 680; font-size: 15px; letter-spacing: -.2px; }
.coach-status { font-size: 11.5px; color: var(--ok); }

.topbar-actions { display: flex; align-items: center; gap: 6px; }

.session-badge {
  font-size: 11px;
  font-weight: 650;
  color: var(--accent-dark);
  background: var(--accent-soft);
  padding: 5px 9px;
  border-radius: 9px;
  white-space: nowrap;
}

.icon-btn {
  width: 36px; height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 11px;
  font-size: 16px;
  cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { background: #f2efec; }
.icon-btn.dark { border-color: transparent; background: #f2efec; }

/* ---------- CHAT ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.msg { display: flex; flex-direction: column; max-width: 88%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.coach { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.coach .bubble {
  background: var(--bubble-coach);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.msg.user .bubble {
  background: var(--bubble-user);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.bubble a { color: var(--accent-dark); }
.msg.user .bubble a { color: #ffe9d6; }
.bubble b { font-weight: 680; }

.divider {
  align-self: center;
  font-size: 11.5px;
  color: var(--muted);
  background: #efece8;
  padding: 5px 12px;
  border-radius: 20px;
  text-align: center;
  max-width: 92%;
}

.typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bubble-coach);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-bottom-left-radius: 5px;
}
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.3s infinite both;
}
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .28; } 40% { opacity: 1; } }

/* ---------- VIDEOS ---------- */
.video-embed {
  margin-top: 8px;
  width: 100%;
  max-width: 320px;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
}
.video-embed iframe { width: 100%; border: 0; display: block; }
.embed-tiktok { height: 520px; }
.embed-yt { height: 180px; }

.embed-link, .video-card {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--accent-dark);
  text-decoration: none;
  padding: 8px 11px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
}
.embed-link:active, .video-card:active { background: #f6f2ee; }
.video-card { display: flex; gap: 10px; color: var(--ink); }
.video-thumb {
  width: 54px; height: 54px;
  border-radius: 9px;
  background: #e7e2dc center/cover no-repeat;
  display: grid; place-items: center;
  font-size: 18px;
  flex-shrink: 0;
}
.video-tag { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.video-title { font-size: 13px; font-weight: 600; }
.video-author { font-size: 11.5px; color: var(--muted); }

/* ---------- COMPOSER ---------- */
.composer {
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid var(--line);
}
.composer-form { display: flex; gap: 8px; align-items: center; }
#msg {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  border: 1.5px solid var(--line);
  border-radius: 22px;
  outline: none;
  background: #faf9f7;
}
#msg:focus { border-color: var(--accent); background: #fff; }
#send-btn {
  width: 46px; height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  flex-shrink: 0;
}
#send-btn:disabled { opacity: .5; }

/* ---------- OVERLAYS ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 23, .5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.panel {
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 16px 14px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel-head h2 { font-size: 18px; margin: 0; letter-spacing: -.2px; }

.new-chat {
  width: 100%;
  padding: 13px;
  font-size: 14.5px;
  font-weight: 620;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  margin-bottom: 12px;
}

.chats-list { display: flex; flex-direction: column; gap: 8px; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 11px 11px 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 13px;
}
.chat-item.activa { border-color: var(--accent); background: #fffaf5; }
.chat-item-main { flex: 1; min-width: 0; text-align: left; cursor: pointer; }
.chat-item-title { font-size: 14px; font-weight: 620; margin-bottom: 2px; }
.chat-item-preview { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.chat-item-fecha { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.chat-del {
  width: 30px; height: 30px;
  border: 1px solid var(--line);
  background: #faf9f7;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  display: grid; place-items: center;
  opacity: .75;
}
.chat-del:active { background: #fee2e2; border-color: #fca5a5; opacity: 1; }
.chat-chip {
  font-size: 10px;
  font-weight: 650;
  color: var(--ok);
  background: #dcfce7;
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: 5px;
  vertical-align: middle;
}

/* ---------- PLAN ---------- */
.plan-body { display: flex; flex-direction: column; gap: 14px; }

.plan-block { background: #fff; border: 1px solid var(--line); border-radius: 15px; padding: 13px; }
.plan-block h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 680;
}

.plan-progress { font-size: 14.5px; font-weight: 620; }
.plan-metrics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.metric {
  flex: 1 1 45%;
  background: #faf9f7;
  border-radius: 10px;
  padding: 8px 10px;
}
.metric-label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.metric-value { font-size: 15px; font-weight: 650; }

.ej-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.ej-row:last-child { border-bottom: 0; padding-bottom: 0; }
.ej-row:first-child { padding-top: 0; }
.ej-name { font-size: 14px; font-weight: 620; }
.ej-meta { font-size: 12px; color: var(--muted); }
.ej-clave { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.ej-peso { text-align: right; flex-shrink: 0; }
.peso-actual { font-size: 15px; font-weight: 700; }
.peso-sug { font-size: 12px; font-weight: 620; }
.accion-subir .peso-sug { color: var(--ok); }
.accion-mantener .peso-sug { color: var(--muted); }
.accion-consolidar .peso-sug { color: #b45309; }
.accion-tope .peso-sug { color: var(--accent-dark); }
.peso-motivo { font-size: 11px; color: var(--muted); margin-top: 2px; max-width: 190px; }

.pr-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.pr-row:last-child { border-bottom: 0; }
.pr-peso { font-weight: 700; color: var(--accent-dark); }
.pr-meta { font-size: 11.5px; color: var(--muted); }

.sesion-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--line);
}
.sesion-row:last-child { border-bottom: 0; }
.sesion-check {
  width: 22px; height: 22px;
  border-radius: 7px;
  display: grid; place-items: center;
  background: #f2efec;
  font-size: 12px;
  flex-shrink: 0;
}
.sesion-row.hecha .sesion-check { background: #dcfce7; color: var(--ok); }
.sesion-row.proxima { font-weight: 650; }
.sesion-row.proxima .sesion-check { background: var(--accent-soft); }
.sesion-meta { font-size: 11.5px; color: var(--muted); }

/* ---------- TOAST ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  background: #1c1917;
  color: #fff;
  font-size: 13.5px;
  padding: 11px 18px;
  border-radius: 22px;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
  animation: subir .22s ease-out;
}
@keyframes subir { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- PLANIFICACIÓN ---------- */
.sem-item { border-bottom: 1px solid var(--line); }
.sem-item:last-child { border-bottom: 0; }
.sem-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  cursor: pointer;
}
.sem-title { font-size: 14px; font-weight: 640; }
.sem-meta { font-size: 11.5px; color: var(--muted); }
.sem-chevron { font-size: 12px; color: var(--muted); transition: transform .18s ease; }
.sem-chevron.abierto { transform: rotate(180deg); }
.sem-detalle { padding: 2px 0 12px; }
.sem-tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-bottom: 8px;
}
.sem-tabla th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  font-weight: 650;
  padding: 4px 6px 4px 0;
  border-bottom: 1px solid var(--line);
}
.sem-tabla td { padding: 5px 6px 5px 0; border-bottom: 1px solid #f4f1ee; }
.sem-tabla tr:last-child td { border-bottom: 0; }
.sem-sesion {
  font-size: 12px;
  color: var(--ink);
  padding: 6px 0 0;
}
.sem-obs {
  font-size: 11.5px;
  color: var(--muted);
  padding-left: 16px;
  margin-top: 2px;
  line-height: 1.4;
}

/* ---------- BOTONES PEQUEÑOS ---------- */
.mini-btn {
  width: 28px; height: 28px;
  border: 1px solid var(--line);
  background: #faf9f7;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  display: grid; place-items: center;
  padding: 0;
  opacity: .8;
}
.mini-btn:active { opacity: 1; background: #f2efec; }
.mini-btn.borrar-sesion:active { background: #fee2e2; border-color: #fca5a5; }
.graf-toggle { margin-top: 4px; }

/* ---------- GRÁFICO DE EVOLUCIÓN ---------- */
.graf-slot { padding: 4px 0 10px; }
.graf { width: 100%; max-width: 340px; height: auto; display: block; margin: 0 auto; }
.graf-linea { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.graf-pt { fill: #fff; stroke: var(--accent); stroke-width: 1.6; }
.graf-pr { fill: var(--accent); stroke: #fff; stroke-width: 1.6; }
.graf-eje { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; }
.graf-lbl { font-size: 9.5px; fill: var(--muted); font-family: inherit; }
.graf-meta { font-size: 11.5px; color: var(--muted); text-align: center; margin-top: 4px; }
.graf-vacio { font-size: 12px; color: var(--muted); padding: 10px 0; text-align: center; }

/* ---------- SESIONES DEL HISTORIAL ---------- */
.sem-sesion { padding: 7px 0 0; }
.sem-sesion-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}
.sem-sesion-botones { display: flex; gap: 5px; flex-shrink: 0; }

/* ---------- FORMULARIO DE EDICIÓN ---------- */
.editor-slot { padding: 8px 0 4px; }
.ed-form {
  background: #faf9f7;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ed-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ed-form label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  font-weight: 620;
}
.ed-form input, .ed-form select, .ed-form textarea {
  font-size: 13.5px;
  font-family: inherit;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  width: 100%;
}
.ed-tabla { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ed-tabla th {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  text-align: left;
  padding: 2px 4px 4px 0;
  font-weight: 650;
}
.ed-tabla td { padding: 3px 4px 3px 0; }
.ed-tabla select, .ed-tabla input { width: 100%; padding: 5px 6px; font-size: 12.5px; }
.ed-tabla td:first-child { width: 44%; }
.ed-acciones { display: flex; gap: 7px; margin-top: 2px; }
.ed-btn {
  flex: 1;
  padding: 10px;
  font-size: 13.5px;
  font-weight: 620;
  border-radius: 9px;
  border: 1px solid var(--line);
  cursor: pointer;
  font-family: inherit;
}
.ed-guardar { background: var(--accent); color: #fff; border-color: var(--accent); }
.ed-guardar:active { background: var(--accent-dark); }
.ed-cancelar { background: #fff; color: var(--ink); }
.ed-error { color: var(--danger); font-size: 12px; min-height: 15px; }
