/* ============================================================================
   MANTIS · Login premium (SaaS) — solo UI
   Glassmorphism + gradientes + fondo espacial animado + dark/light.
   Colores corporativos: #061c6b (azul profundo) · #07ba86 (verde turquesa).
   Las variables de marca se pueden sobreescribir desde el <style> inline del
   index.php (logo, nombre e imagen se configuran ahí también).
   ============================================================================ */

:root {
  /* Marca (configurables) */
  --brand-deep: #061c6b;
  --brand-teal: #07ba86;

  /* Derivados */
  --deep-700: #04124a;
  --deep-900: #020a2e;
  --teal-300: #4fe3bd;

  /* Tema oscuro (por defecto) */
  --bg-0: #03061c;
  --bg-1: #061238;
  --text-strong: #f4f7ff;
  --text: #c8d2ee;
  --text-soft: #8d9bc4;
  --card-bg: rgba(16, 26, 64, 0.55);
  --card-border: rgba(140, 170, 255, 0.18);
  --card-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.75), 0 8px 30px rgba(2, 8, 40, 0.6);
  --field-bg: rgba(255, 255, 255, 0.04);
  --field-border: rgba(160, 180, 230, 0.18);
  --accent: var(--brand-teal);
  --field-border-focus: var(--accent);
  --glow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  --nebula-a: rgba(6, 28, 107, 0.55);
  --nebula-b: rgba(7, 186, 134, 0.35);
  --star: rgba(255, 255, 255, 0.9);

  --radius-card: 26px;
  --radius-field: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="light"] {
  --bg-0: #eef3ff;
  --bg-1: #dde9ff;
  --text-strong: #0a1b46;
  --text: #243766;
  --text-soft: #5b6e9c;
  --card-bg: rgba(255, 255, 255, 0.62);
  --card-border: rgba(6, 28, 107, 0.12);
  --card-shadow: 0 30px 70px -24px rgba(6, 28, 107, 0.35), 0 6px 22px rgba(6, 28, 107, 0.12);
  --field-bg: rgba(255, 255, 255, 0.7);
  --field-border: rgba(6, 28, 107, 0.16);
  --accent: var(--brand-deep);
  --field-border-focus: var(--accent);
  --glow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  --nebula-a: rgba(6, 28, 107, 0.22);
  --nebula-b: rgba(7, 186, 134, 0.28);
  --star: rgba(6, 28, 107, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg-0);
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-font-smoothing: antialiased;
  transition: background 0.6s var(--ease), color 0.6s var(--ease);
}

/* ============================ FONDO ESPACIAL ============================ */

.bg-stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--bg-1) 0%, var(--bg-0) 60%),
    radial-gradient(80% 60% at 85% 110%, rgba(7, 186, 134, 0.10), transparent 60%);
  transition: background 0.6s var(--ease);
}

/* Imagen de fondo opcional (cuando body tiene .has-bg-image) */
.bg-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transform: scale(1.06);
  transition: opacity 0.6s var(--ease);
}
.has-bg-image .bg-image { opacity: 1; }
.has-bg-image .bg-image::after {
  content: "";
  position: absolute;
  inset: 0;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: linear-gradient(160deg, var(--nebula-a), rgba(2, 6, 28, 0.6));
}

/* Nebulosas suaves */
.nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.7;
  will-change: transform;
}
.nebula.n1 {
  width: 46vw; height: 46vw; left: -8vw; top: -10vw;
  background: radial-gradient(circle, var(--nebula-a), transparent 70%);
  animation: drift 26s var(--ease) infinite alternate;
}
.nebula.n2 {
  width: 40vw; height: 40vw; right: -10vw; bottom: -12vw;
  background: radial-gradient(circle, var(--nebula-b), transparent 70%);
  animation: drift 32s var(--ease) infinite alternate-reverse;
}
.nebula.n3 {
  width: 28vw; height: 28vw; right: 18vw; top: 8vw;
  background: radial-gradient(circle, rgba(79, 227, 189, 0.18), transparent 70%);
  animation: drift 38s var(--ease) infinite alternate;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(4vw, 3vh, 0) scale(1.12); }
}

#particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ============================ LAYOUT ============================ */

.login-stage {
  position: relative;
  z-index: 2;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
}

/* Powered by */
.powered-by {
  margin: 22px 0 0;
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0.3px;
  color: var(--text-soft);
  text-align: center;
  animation: fadeUp 0.7s var(--ease) both;
  animation-delay: 0.3s;
}
.powered-by a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
  transition: opacity 0.2s var(--ease);
}
.powered-by a:hover { opacity: 0.78; text-decoration: underline; }

/* ============================ TARJETA GLASS ============================ */

.login-card {
  position: relative;
  width: min(440px, 100%);
  padding: 38px 34px 30px;
  border-radius: var(--radius-card);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow);
  backdrop-filter: blur(22px) saturate(140%);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  animation: cardIn 0.9s var(--ease) both;
  transition: background 0.6s var(--ease), border-color 0.6s var(--ease), box-shadow 0.6s var(--ease);
}

/* Borde con brillo sutil */
.login-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.35), transparent 40%, rgba(7, 186, 134, 0.35));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  opacity: 0.5;
  pointer-events: none;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(22px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================ MARCA ============================ */

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  animation: fadeUp 0.7s var(--ease) both;
  animation-delay: 0.08s;
}
.brand-logo {
  width: auto;
  max-width: 132px;
  height: auto;
  object-fit: contain;
  filter: brightness(0) invert(1);
  transition: transform 0.3s var(--ease), filter 0.4s var(--ease);
}
[data-theme="light"] .brand-logo { filter: none; }
.brand-logo:hover { transform: scale(1.04); }
.brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text-strong);
}
.brand-name b { color: var(--accent); }

/* ============================ PANELES ============================ */

.panels { position: relative; }
.panel { display: none; }
.panel.is-active { display: block; animation: panelIn 0.5s var(--ease) both; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel-title {
  margin: 0 0 4px;
  font-size: 23px;
  font-weight: 700;
  color: var(--text-strong);
  text-align: center;
  letter-spacing: -0.2px;
}
.panel-sub {
  margin: 0 0 22px;
  font-size: 14px;
  color: var(--text-soft);
  text-align: center;
  line-height: 1.5;
}

/* ============================ CAMPOS ============================ */

.field { margin-bottom: 16px; animation: fadeUp 0.6s var(--ease) both; }
.field:nth-of-type(1) { animation-delay: 0.12s; }
.field:nth-of-type(2) { animation-delay: 0.18s; }

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--text-soft);
  margin: 0 0 7px 4px;
}

.control {
  position: relative;
  display: flex;
  align-items: center;
}
.control .ico {
  position: absolute;
  left: 15px;
  font-size: 17px;
  color: var(--text-soft);
  pointer-events: none;
  transition: color 0.25s var(--ease);
}
.control input {
  width: 100%;
  height: 52px;
  padding: 0 46px 0 44px;
  font-size: 15px;
  color: var(--text-strong);
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-field);
  outline: none;
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s var(--ease);
}
.control input::placeholder { color: var(--text-soft); opacity: 0.7; }
.control input:hover { border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.control input:focus {
  border-color: var(--field-border-focus);
  box-shadow: var(--glow);
  background: color-mix(in srgb, var(--field-bg) 70%, transparent);
}
.control input:focus + .ico,
.control input:focus ~ .ico { color: var(--accent); }

.control.is-invalid input {
  border-color: #ff6b81;
  box-shadow: 0 0 0 4px rgba(255, 107, 129, 0.16);
}

/* Botón ojo */
.eye {
  position: absolute;
  right: 8px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: none;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
  border-radius: 10px;
  font-size: 17px;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.eye:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.eye:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* PIN de reset */
.control input.pin {
  text-align: center;
  letter-spacing: 12px;
  font-size: 22px;
  font-weight: 700;
  padding: 0 16px;
}

/* ============================ FILA OPCIONES ============================ */

.row-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 2px 2px 20px;
  gap: 10px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check .box {
  width: 20px;
  height: 20px;
  border-radius: 7px;
  border: 1px solid var(--field-border);
  background: var(--field-bg);
  display: grid;
  place-items: center;
  transition: all 0.2s var(--ease);
}
.check .box::after {
  content: "";
  width: 10px; height: 6px;
  border-left: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(-45deg) scale(0);
  margin-top: -2px;
  transition: transform 0.2s var(--ease);
}
.check input:checked + .box {
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 4px 12px -5px color-mix(in srgb, var(--accent) 55%, transparent);
}
.check input:checked + .box::after { transform: rotate(-45deg) scale(1); }
.check input:focus-visible + .box { box-shadow: var(--glow); }

.link {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  transition: opacity 0.2s var(--ease);
}
.link:hover { opacity: 0.78; text-decoration: underline; }

/* ============================ BOTÓN ============================ */

.btn-primary {
  position: relative;
  width: 100%;
  height: 52px;
  border: none;
  border-radius: var(--radius-field);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: #fff;
  cursor: pointer;
  overflow: hidden;
  background: var(--accent);
  box-shadow: 0 12px 28px -14px color-mix(in srgb, var(--accent) 60%, transparent);
  transition: transform 0.18s var(--ease), box-shadow 0.25s var(--ease), filter 0.2s var(--ease);
}
.btn-primary:hover { transform: translateY(-2px); filter: brightness(1.07); box-shadow: 0 18px 36px -14px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn-primary:active { transform: translateY(0) scale(0.99); filter: brightness(0.95); }
.btn-primary:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.btn-primary:disabled { cursor: not-allowed; filter: grayscale(0.2) brightness(0.92); transform: none; }

.btn-primary .label { transition: opacity 0.2s var(--ease); }
.btn-primary .spin {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
}
.btn-primary .spin i {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-primary.is-loading .label { opacity: 0; }
.btn-primary.is-loading .spin { opacity: 1; }

@keyframes spin { to { transform: rotate(360deg); } }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 14px;
  width: 100%;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-soft);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.btn-ghost:hover { color: var(--text-strong); background: rgba(127, 150, 210, 0.1); }
.btn-ghost:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============================ PIE ============================ */

.card-foot {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--card-border);
  text-align: center;
  font-size: 13.5px;
  color: var(--text-soft);
}
.card-foot a { color: var(--accent); font-weight: 700; text-decoration: none; }
.card-foot a:hover { text-decoration: underline; }

/* ============================ TOGGLE TEMA ============================ */

.theme-toggle {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 5;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  cursor: pointer;
  color: var(--text-strong);
  font-size: 19px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--card-shadow);
  transition: transform 0.2s var(--ease), color 0.3s var(--ease), background 0.4s var(--ease);
}
.theme-toggle:hover { transform: translateY(-2px) rotate(-8deg); color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle .bi-sun-fill { display: none; }
[data-theme="light"] .theme-toggle .bi-sun-fill { display: block; }
[data-theme="light"] .theme-toggle .bi-moon-stars-fill { display: none; }

/* ============================ ANIMACIONES BASE ============================ */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================ RESPONSIVE ============================ */

/* Tablet */
@media (max-width: 768px) {
  .login-stage { padding: 24px 16px; }
  .login-card { width: min(440px, 100%); }
}

/* Móvil */
@media (max-width: 520px) {
  .login-stage { padding: 18px 14px; }
  .login-card { padding: 28px 20px 22px; border-radius: 20px; }
  .brand { margin-bottom: 18px; }
  .brand-logo { max-width: 112px; }
  .brand-name { font-size: 18px; }
  .panel-title { font-size: 20px; }
  .panel-sub { font-size: 13px; margin-bottom: 18px; }
  .control input { height: 50px; font-size: 16px; } /* 16px evita zoom en iOS */
  .control input.pin { letter-spacing: 9px; font-size: 20px; }
  .btn-primary { height: 50px; }
  .row-options { flex-wrap: wrap; gap: 8px 12px; }
  .theme-toggle { top: 14px; right: 14px; width: 42px; height: 42px; font-size: 17px; }
}

/* Pantallas muy pequeñas */
@media (max-width: 360px) {
  .login-card { padding: 24px 16px 20px; }
  .control input { padding: 0 42px 0 40px; }
  .control .ico { left: 13px; font-size: 16px; }
  .control input.pin { letter-spacing: 6px; }
  .link, .check { font-size: 12.5px; }
}

/* Alturas reducidas (móvil en horizontal / ventanas bajas) */
@media (max-height: 660px) {
  .login-stage { align-items: start; padding-top: 16px; padding-bottom: 16px; }
  .brand { margin-bottom: 14px; }
  .panel-sub { margin-bottom: 14px; }
  .field { margin-bottom: 12px; }
}

/* ============================ ACCESIBILIDAD ============================ */

a:focus-visible,
input:focus-visible { outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .nebula { animation: none; }
}
