/* ===========================================================================
   AppsIstant — tokens de marca y componentes del rediseño (login + navbar).
   Se conecta al mecanismo de tema YA existente en el portal: el atributo
   data-bs-theme en <html> (ver layout.ejs), no se introduce un atributo
   nuevo. Todas las clases propias van prefijadas "aps-" para no chocar con
   clases de Bootstrap (ej. .card) ni con clases propias del portal que ya
   existían (.glass-card, .btn-neon-cyan, etc.).
   =========================================================================== */

:root {
  --brand-1: #22d3ee;
  --brand-2: #7c3aed;
  --brand-1-strong: #0891b2;
  --spark: #f59e0b;
  --grad: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  --grad-btn: linear-gradient(135deg, var(--brand-1-strong), var(--brand-2));
  --aps-radius: 12px;
  --aps-radius-lg: 18px;
}

html[data-bs-theme="light"] {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #f8fafc; --border: #e3e8f0;
  --text: #0f172a; --muted: #64748b; --input-bg: #ffffff; --hover: #f1f5f9;
  --focus: rgba(124, 58, 237, .18); --bolt-line: #0f172a;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 32px rgba(15, 23, 42, .08);

  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-border-color: var(--border);
  --bs-secondary-color: var(--muted);
  --bs-tertiary-bg: var(--hover);
  --bs-link-color: var(--brand-2);
  --bs-link-hover-color: var(--brand-1-strong);
}

html[data-bs-theme="dark"] {
  --bg: #0a0f1c; --surface: #111a2e; --surface-2: #0e1627; --border: #1f2a44;
  --text: #e6edf7; --muted: #94a3b8; --input-bg: #0e1627; --hover: #17223a;
  --focus: rgba(34, 211, 238, .22); --bolt-line: #e2e8f0;
  --shadow: 0 12px 32px rgba(0, 0, 0, .35);

  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-border-color: var(--border);
  --bs-secondary-color: var(--muted);
  --bs-tertiary-bg: var(--hover);
  --bs-link-color: #a78bfa;
  --bs-link-hover-color: var(--brand-1);
}

body { transition: background-color .2s, color .2s; }

.aps-brand-word { font-family: 'Poppins', sans-serif; font-weight: 700; letter-spacing: -.5px; color: var(--text); white-space: nowrap; }
.aps-brand-word .g { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.aps-bolt { display: block; }

/* ============ LOGIN ============ */
/* Altura FIJA de ventana (no "al menos"): así el login nunca empuja al
   documento entero a hacer scroll. Cada columna gestiona su propio overflow
   como respaldo (ver .aps-hero / .aps-pane-body) para pantallas realmente
   bajas, pero en la inmensa mayoría de los casos no hace falta: entre esto y
   los ajustes de @media (max-height) de más abajo, todo cabe sin scroll. */
.aps-login { height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.aps-hero {
  position: relative; overflow-y: auto; color: #e6edf7; padding: 40px 48px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(600px 400px at 15% 20%, rgba(34, 211, 238, .22), transparent 60%),
              radial-gradient(500px 420px at 85% 85%, rgba(124, 58, 237, .35), transparent 60%), #0b1220;
  --bolt-line: #e2e8f0;
}
.aps-hero::before {
  content: ""; position: absolute; inset: 0; opacity: .18;
  background-image: linear-gradient(rgba(255, 255, 255, .08) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .08) 1px, transparent 1px);
  background-size: 36px 36px; mask-image: radial-gradient(circle at 50% 50%, #000 30%, transparent 75%);
}
.aps-hero > * { position: relative; }
.aps-hero .aps-top { display: flex; align-items: center; gap: 12px; }
.aps-hero .aps-top .aps-brand-word { color: #fff; font-size: 22px; }
.aps-hero .aps-mid { max-width: 460px; }
.aps-hero .aps-mascot { width: 180px; margin-bottom: 28px; filter: drop-shadow(0 18px 40px rgba(124, 58, 237, .45)); }
.aps-hero h2 { font-family: 'Poppins', sans-serif; font-size: 34px; line-height: 1.2; margin: 0 0 12px; font-weight: 700; color: #fff; }
.aps-hero h2 .g { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.aps-hero p { color: #a8b3c7; margin: 0 0 24px; line-height: 1.6; }
.aps-feats { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.aps-feats li { display: flex; gap: 12px; align-items: center; color: #cbd5e1; }
.aps-feats i { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1); color: var(--brand-1); }
.aps-hero .aps-legal { font-size: 12.5px; color: #7c8aa3; }

.aps-pane { display: flex; flex-direction: column; background: var(--bg); min-height: 0; }
.aps-pane-top { flex: none; display: flex; justify-content: flex-end; gap: 10px; padding: 20px 28px; }
.aps-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
  font-variant-numeric: tabular-nums; cursor: pointer;
}
.aps-pill:hover { background: var(--hover); }
.aps-pill i { color: var(--muted); }
/* min-height:0 es lo que permite que un hijo flex con flex:1 SÍ pueda
   encogerse y mostrar su propio scroll en vez de forzar al padre a crecer
   (el comportamiento por defecto de flexbox no deja que un hijo sea más
   chico que su contenido, a menos que se lo indiques explícitamente). */
.aps-pane-body { flex: 1; min-height: 0; overflow-y: auto; display: grid; place-items: center; padding: 24px; }
.aps-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--aps-radius-lg); box-shadow: var(--shadow); padding: 36px 32px; }
.aps-card-head { text-align: center; margin-bottom: 28px; }
.aps-card-head .aps-bolt { width: 72px; margin: 0 auto 14px; }
.aps-card-head .aps-brand-word { font-size: 30px; }
.aps-card-head p { margin: 6px 0 0; color: var(--muted); font-size: 14.5px; }
.aps-field { margin-bottom: 18px; }
.aps-field label { display: block; font-weight: 600; font-size: 13.5px; margin-bottom: 7px; color: var(--text); }
.aps-input { position: relative; }
.aps-input > i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 17px; pointer-events: none; }
.aps-input input {
  width: 100%; height: 48px; border-radius: var(--aps-radius); border: 1px solid var(--border); background: var(--input-bg);
  color: var(--text); font: inherit; padding: 0 44px 0 44px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.aps-input input::placeholder { color: var(--muted); opacity: .8; }
.aps-input input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 4px var(--focus); }
.aps-input .aps-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; cursor: pointer; }
.aps-input .aps-eye:hover { background: var(--hover); color: var(--text); }
.aps-row-between { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 22px; font-size: 14px; }
.aps-link { color: var(--brand-2); text-decoration: none; font-weight: 500; }
html[data-bs-theme="dark"] .aps-link { color: #a78bfa; }
.aps-link:hover { text-decoration: underline; }
.aps-btn-primary {
  width: 100%; height: 50px; border: 0; border-radius: var(--aps-radius); background: var(--grad-btn); color: #fff;
  font: inherit; font-weight: 600; font-size: 15.5px; display: flex; align-items: center; justify-content: center;
  gap: 10px; cursor: pointer; box-shadow: 0 8px 20px rgba(124, 58, 237, .28); transition: transform .1s, filter .15s;
}
.aps-btn-primary:hover { filter: brightness(1.07); color: #fff; }
.aps-btn-primary:active { transform: translateY(1px); }
.aps-secure { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 22px; font-size: 12.5px; color: var(--muted); }
.aps-secure i { color: #10b981; }
.aps-pane-foot { flex: none; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 28px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.aps-pane-foot b { color: var(--text); font-weight: 600; }
.aps-mobile-brand { display: none; align-items: center; gap: 8px; }
.aps-mobile-brand .aps-brand-word { font-size: 19px; }

@media (max-width: 960px) {
  .aps-login { grid-template-columns: 1fr; }
  .aps-hero { display: none; }
  .aps-pane-top { justify-content: space-between; }
  .aps-pane-top .aps-mobile-brand { display: flex; }
}
@media (max-width: 520px) {
  .aps-pane-top .aps-theme-txt, .aps-pane-top .aps-pill:first-child { display: none; }
  .aps-card { padding: 28px 20px; }
  .aps-row-between { flex-wrap: wrap; gap: 10px; }
  .aps-pane-top { padding: 16px; }
}

/* Pantallas de poca altura (laptops con barra de marcadores/pestañas,
   ventanas no maximizadas, etc.): se achican los espacios/tamaños para que
   el login completo quepa sin que .aps-pane-body tenga que recurrir a su
   scroll de respaldo. */
@media (max-height: 760px) {
  .aps-hero { padding: 24px 40px; }
  .aps-hero .aps-mascot { width: 110px; margin-bottom: 14px; }
  .aps-hero h2 { font-size: 26px; margin-bottom: 8px; }
  .aps-hero p { margin-bottom: 14px; }
  .aps-pane-top { padding: 12px 24px; }
  .aps-pane-body { padding: 16px; }
  .aps-card { padding: 24px 28px; }
  .aps-card-head { margin-bottom: 16px; }
  .aps-card-head .aps-bolt { width: 52px; margin-bottom: 8px; }
  .aps-card-head .aps-brand-word { font-size: 24px; }
  .aps-field { margin-bottom: 12px; }
  .aps-row-between { margin: 2px 0 14px; }
  .aps-secure { margin-top: 14px; }
  .aps-pane-foot { padding: 10px 24px; }
}
@media (max-height: 560px) {
  .aps-hero .aps-mid { display: flex; flex-direction: column; }
  .aps-hero .aps-mascot { display: none; }
}

/* ============ NAVBAR / SIDEBAR (portal autenticado) ============ */
.aps-navbar {
  position: sticky; top: 0; z-index: 997; height: 68px; display: flex; align-items: center; gap: 14px; padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.aps-icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text); display: grid; place-items: center; font-size: 20px; cursor: pointer; }
.aps-icon-btn:hover { background: var(--hover); }
.aps-icon-btn.bordered { border-color: var(--border); background: var(--surface); font-size: 17px; }
.aps-nav-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.aps-nav-brand .aps-bolt { width: 40px; }
.aps-nav-brand .aps-brand-word { font-size: 22px; }
.aps-spacer { flex: 1; }
.aps-ai-btn {
  position: relative; display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 999px;
  border: 1.5px solid transparent; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--text);
  background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--grad) border-box;
}
.aps-ai-btn i { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; font-size: 16px; }
.aps-ai-btn:hover { box-shadow: 0 6px 18px rgba(124, 58, 237, .2); }
.aps-viewing { display: flex; flex-direction: column; gap: 2px; }
.aps-viewing small { font-size: 11px; color: var(--muted); font-weight: 500; padding-left: 4px; }
.aps-select {
  height: 38px; min-width: 200px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-size: 14px; padding: 0 12px;
}
.aps-divider { width: 1px; height: 28px; background: var(--border); }
.aps-user { display: flex; align-items: center; gap: 10px; padding: 4px 8px 4px 4px; border-radius: 999px; border: 1px solid transparent; background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.aps-user:hover { background: var(--hover); }
.aps-avatar { position: relative; width: 38px; height: 38px; border-radius: 50%; padding: 2px; background: var(--grad); flex: none; }
.aps-avatar span { width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center; background: var(--surface); font-weight: 700; color: var(--text); }
.aps-avatar::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; background: #10b981; border: 2px solid var(--surface); }
.aps-user .who { display: flex; flex-direction: column; line-height: 1.15; text-align: left; }
.aps-user .who b { font-size: 14px; }
.aps-user .who small { font-size: 12px; color: var(--muted); }
@media (max-width: 1100px) { .aps-viewing small, .aps-user .who, .aps-clock-pill { display: none; } .aps-select { min-width: 140px; } }
@media (max-width: 720px) { .aps-viewing, .aps-ai-btn span, .aps-divider { display: none; } .aps-ai-btn { padding: 0 12px; } }

.aps-side a.nav-link-custom.active {
  background: color-mix(in srgb, var(--brand-2) 10%, transparent);
  position: relative;
}
.aps-side a.nav-link-custom.active i {
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.aps-side a.nav-link-custom.active::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--grad);
}
