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

:root {
  --bg: #f4f1fa;
  --accent: #7c3aed;
  --accent-dark: #6d28d9;
  --accent-soft: #ede9fe;
  --ink: #2a2233;
  --muted: #8b8494;
  --bubble-coach: #ffffff;
  --danger: #dc2626;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- LOGIN ---------- */
.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, #7c3aed 0%, #a855f7 55%, #f0abfc 100%);
}
.login-card {
  background: #fff;
  border-radius: 28px;
  padding: 40px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(60, 20, 120, .35);
}
.login-logo { font-size: 56px; margin-bottom: 12px; }
.login-card h1 { font-size: 26px; line-height: 1.2; margin-bottom: 8px; }
.login-sub { color: var(--muted); font-size: 15px; margin-bottom: 28px; }
#pin {
  width: 100%;
  font-size: 22px;
  letter-spacing: 12px;
  text-align: center;
  padding: 14px;
  border: 2px solid #e5e0f0;
  border-radius: 16px;
  outline: none;
  margin-bottom: 14px;
}
#pin:focus { border-color: var(--accent); }
#login-btn {
  width: 100%;
  padding: 15px;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 16px;
  cursor: pointer;
}
#login-btn:active { background: var(--accent-dark); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 16px; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(120deg, var(--accent), #a855f7);
  color: #fff;
  box-shadow: 0 2px 14px rgba(124, 58, 237, .3);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-info { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 40px; height: 40px;
  background: rgba(255,255,255,.25);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.coach-name { font-weight: 700; font-size: 15px; }
.coach-status { font-size: 12px; opacity: .85; }
.session-badge {
  background: rgba(255,255,255,.2);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  white-space: nowrap;
}
.session-badge:empty { display: none; }

/* ---------- CHAT ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.bubble {
  padding: 12px 15px;
  border-radius: 20px;
  font-size: 15.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.coach .bubble {
  background: var(--bubble-coach);
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 4px rgba(80, 50, 130, .08);
}
.msg.user .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble b, .bubble strong { color: var(--accent-dark); }
.msg.user .bubble b { color: #fff; }
.bubble a { color: var(--accent-dark); font-weight: 600; }

/* video embeds */
.video-embed {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 325px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid #e8e2f5;
  background: #000;
}
.embed-tiktok {
  width: 100%;
  height: min(60vh, 580px);
  border: none;
  display: block;
}
.embed-yt {
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  border: none;
  display: block;
}
.embed-link {
  font-size: 11.5px;
  color: #efe8ff;
  background: #1c1230;
  text-align: center;
  padding: 6px;
  text-decoration: none;
}

/* video card */
.video-card {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 320px;
  background: #fff;
  border: 1px solid #e8e2f5;
  border-radius: 16px;
  padding: 10px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(80, 50, 130, .1);
}
.video-thumb {
  width: 72px; height: 96px;
  flex-shrink: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #1c1230, #3b2a63);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 24px;
  background-size: cover;
  background-position: center;
}
.video-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; justify-content: center; }
.video-tag {
  font-size: 10px; font-weight: 700; letter-spacing: .5px;
  color: var(--accent); text-transform: uppercase;
}
.video-title {
  font-size: 13px; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.video-author { font-size: 11.5px; color: var(--muted); }

/* typing */
.typing { display: flex; gap: 5px; padding: 14px 16px; background: var(--bubble-coach); border-radius: 20px; border-bottom-left-radius: 6px; align-self: flex-start; box-shadow: 0 1px 4px rgba(80,50,130,.08); }
.typing span {
  width: 8px; height: 8px; border-radius: 50%;
  background: #c4b5fd;
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }

/* ---------- COMPOSER ---------- */
.composer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #ece7f5;
}
.composer-form { display: flex; gap: 8px; }
#msg {
  flex: 1;
  padding: 13px 16px;
  font-size: 15.5px;
  border: 1.5px solid #e5e0f0;
  border-radius: 22px;
  outline: none;
  background: var(--bg);
}
#msg:focus { border-color: var(--accent); }
#send-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
#send-btn:disabled { background: #c4b5fd; }
#send-btn:active { background: var(--accent-dark); }

.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: 90px;
  background: rgba(40, 20, 60, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 13.5px;
  z-index: 50;
  animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- TOPBAR ACTIONS ---------- */
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px;
  border: none;
  background: rgba(255,255,255,.18);
  border-radius: 12px;
  font-size: 17px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(255,255,255,.32); }
.icon-btn.dark { background: #ece7f5; }

/* ---------- DIVIDER ---------- */
.divider {
  align-self: center;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 6px 14px;
  max-width: 90%;
}

/* ---------- OVERLAYS ---------- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(30, 15, 50, .45);
  z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.panel {
  background: #fff;
  width: 100%;
  max-width: 520px;
  max-height: 86dvh;
  border-radius: 24px 24px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  animation: slideup .22s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.panel-head h2 { font-size: 19px; color: var(--ink); }

.new-chat {
  width: 100%;
  padding: 13px;
  border: 1.5px dashed var(--accent);
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
}
.chats-list { display: flex; flex-direction: column; gap: 8px; }
.chat-item {
  border: 1.5px solid #ece7f5;
  border-radius: 14px;
  padding: 11px 13px;
  cursor: pointer;
  background: #fff;
  text-align: left;
}
.chat-item.activa { border-color: var(--accent); background: var(--accent-soft); }
.chat-item-title { font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.chat-item-preview { font-size: 12.5px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- PLAN ---------- */
.plan-progress {
  font-size: 14px; font-weight: 600; color: var(--accent-dark);
  background: var(--accent-soft); border-radius: 12px;
  padding: 10px 14px; margin-bottom: 12px; text-align: center;
}
.plan-list { display: flex; flex-direction: column; gap: 10px; }
.plan-session { border: 1.5px solid #ece7f5; border-radius: 16px; padding: 13px 14px; }
.plan-session.hecha { border-color: #bbf7d0; background: #f0fdf4; }
.plan-session-head { display: flex; align-items: center; gap: 10px; }
.plan-check {
  width: 28px; height: 28px; flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  background: #ece7f5; color: var(--muted);
}
.plan-session.hecha .plan-check { background: #22c55e; color: #fff; }
.plan-session-title { font-size: 14.5px; font-weight: 700; line-height: 1.25; }
.plan-session-meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
.plan-ejercicios { margin: 10px 0 0 6px; padding-left: 14px; color: #55505e; font-size: 13px; line-height: 1.7; }
.plan-next-hint { margin-top: 10px; font-size: 13px; color: var(--accent-dark); font-weight: 600; }
.plan-adaptable { margin-top: 10px; font-size: 13px; color: var(--muted); font-style: italic; background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; }
