/* ===== Variables ===== */
:root {
  --bg: #050505;
  --surface: #0f0f0f;
  --surface-2: #161616;
  --border: #222222;
  --text: #ffffff;
  --text-muted: #888888;
  --accent: #00b4d8;
  --accent-hover: #0096c7;
  --success: #22c55e;
  --error: #ef4444;
  --sidebar-w: 300px;
  --header-h: 60px;
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html {
  overscroll-behavior: none;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ===== Logo ===== */
.logo { text-align: center; margin-bottom: 32px; }
.logo-metodo {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 4px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.logo-brand { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.logo-nirvana {
  font-size: 28px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.logo-financiero {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
}
.logo-sm .logo-nirvana { font-size: 17px; }
.logo-sm .logo-financiero { font-size: 17px; }

/* ===== LOGIN PAGE ===== */
.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background: radial-gradient(ellipse at top, #0d1a1f 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
}

.login-subtitle {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 32px;
}

.field { margin-bottom: 20px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.field input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  padding: 12px 16px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: #444; }

.error-msg {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

.btn-login {
  width: 100%;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 13px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.btn-login:hover { background: var(--accent-hover); }
.btn-login:active { transform: scale(0.98); }
.btn-login:disabled { opacity: 0.6; cursor: not-allowed; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(0,0,0,0.3);
  border-top-color: #000;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== APP PAGE ===== */
.app-page {
  min-height: 100vh;
  min-height: 100dvh;
}

/* Header */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding-left: calc(20px + var(--safe-left));
  padding-right: calc(20px + var(--safe-right));
  z-index: 100;
  gap: 16px;
}

.header-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.header-center { display: flex; justify-content: center; }
.header-right { display: flex; align-items: center; gap: 14px; justify-content: flex-end; }

.sidebar-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
  z-index: 1;
}
.sidebar-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}


.user-name {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  min-height: 36px;
  -webkit-tap-highlight-color: transparent;
}
.btn-logout:hover { border-color: var(--error); color: var(--error); }

/* Layout */
.app-layout {
  display: flex;
  margin-top: calc(var(--header-h) + var(--safe-top));
  min-height: calc(100vh - var(--header-h) - var(--safe-top));
  min-height: calc(100dvh - var(--header-h) - var(--safe-top));
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  top: calc(var(--header-h) + var(--safe-top));
  bottom: 0;
  left: 0;
  overflow-y: auto;
  z-index: 50;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  padding-bottom: var(--safe-bottom);
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-inner { padding: 20px 0; }

.sidebar-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 0 20px 16px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 49;
}

/* Modules in sidebar */
.module-item { border-bottom: 1px solid var(--border); }

.module-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.module-header:hover { background: var(--surface-2); }

.module-info { flex: 1; min-width: 0; }
.module-num {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--accent);
  text-transform: uppercase;
  display: block;
  margin-bottom: 3px;
}
.module-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.module-progress-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}
.module-progress-badge.done { color: var(--success); border-color: rgba(34,197,94,0.3); }

.module-lessons {
  display: none;
  padding: 4px 0 8px;
}
.module-lessons.open { display: block; }

.lesson-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 20px 10px 24px;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 2px solid transparent;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.lesson-item:hover { background: var(--surface-2); }
.lesson-item.active {
  background: rgba(0, 180, 216, 0.08);
  border-left-color: var(--accent);
}

.lesson-check {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
}
.lesson-item.completed .lesson-check {
  background: rgba(34,197,94,0.15);
  border-color: rgba(34,197,94,0.4);
  color: var(--success);
}
.lesson-item.active .lesson-check {
  background: rgba(0,180,216,0.15);
  border-color: rgba(0,180,216,0.4);
  color: var(--accent);
}

.lesson-name {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  padding-top: 3px;
  flex: 1;
}
.lesson-item.active .lesson-name,
.lesson-item:hover .lesson-name { color: var(--text); }
.lesson-item.completed .lesson-name { color: #555; }

/* Main content */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 32px 40px calc(32px + var(--safe-bottom)) calc(40px + var(--safe-left));
  min-width: 0;
  overflow-x: hidden;
}

.content-wrap {
  width: 100%;
  max-width: 860px;
}

/* Video placeholder */
.video-placeholder {
  aspect-ratio: 16/9;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.placeholder-content { text-align: center; }
.placeholder-icon {
  font-size: 48px;
  color: var(--border);
  margin-bottom: 16px;
}
.placeholder-content p { color: var(--text-muted); font-size: 15px; }

/* Video wrapper */
.video-wrapper {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* fallback 16:9 para iOS antiguo */
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
@supports (aspect-ratio: 16/9) {
  .video-wrapper {
    padding-top: 0;
    aspect-ratio: 16/9;
  }
}
.video-wrapper iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}


.video-active { display: block; width: 100%; }

.video-loading {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.video-unavailable {
  width: 100%;
  aspect-ratio: 16/9;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--text-muted);
}

/* Video meta */
.video-meta {
  margin: 20px 0 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.video-breadcrumb {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.video-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

/* Video footer — 2 columnas: anterior | siguiente */
.video-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: stretch;
}

.btn-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  width: 100%;
  min-height: 54px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  white-space: nowrap;
}
.btn-nav:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(0,180,216,0.06);
}
.btn-nav:disabled { opacity: 0.3; cursor: not-allowed; }


/* ===== Tablet ===== */
@media (max-width: 1024px) {
  :root { --sidebar-w: 260px; }
  .app-main { padding: 24px 28px calc(24px + var(--safe-bottom)); }
  .nav-sublabel { max-width: 130px; }
}

/* ===== Móvil ===== */
@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }
  .user-name { display: none; }
  .header-center { display: none; }

  .app-layout {
    margin-top: calc(var(--header-h) + var(--safe-top));
  }
  .sidebar {
    top: calc(var(--header-h) + var(--safe-top));
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }

  .app-main {
    margin-left: 0;
    padding: 0 0 calc(24px + var(--safe-bottom));
  }

  /* Video de borde a borde en móvil */
  .content-wrap {
    max-width: 100%;
  }
  .video-wrapper {
    border-radius: 0;
  }
  .video-meta,
  .video-footer,
  .video-placeholder {
    margin: 0 16px;
  }
  .video-meta {
    margin-top: 14px;
    margin-bottom: 12px;
  }
  .video-footer {
    margin-bottom: 16px;
  }

  .login-card { padding: 32px 24px; }
  .logo-nirvana, .logo-financiero { font-size: 22px; }

  .video-title { font-size: 17px; }

  /* Footer móvil */
  .video-footer { gap: 8px; }
  .btn-nav { min-height: 52px; font-size: 13px; }
}

/* ===== Muy pequeño (< 380px) ===== */
@media (max-width: 380px) {
  .logo-nirvana, .logo-financiero { font-size: 18px; }
  .app-main { padding: 0 0 calc(20px + var(--safe-bottom)); }
  .video-title { font-size: 15px; }
}
