/* ============================================================================
   Portal LBS — Estilos específicos del portal SSO
   Depende de lbs-tokens.css (custom properties) y lbs-glass.css (primitivas).
   ========================================================================= */

/* ── Body / layout ─────────────────────────────────────────────────── */
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Topbar ────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-12) var(--sp-24);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-10);
  font-size: var(--fs-md);
  letter-spacing: .02em;
  color: var(--text);
  text-decoration: none;
}
.brand strong { font-weight: 600; }

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--ink-950);
  border: 1px solid rgba(255,255,255,.1);
}
html[data-theme="light"] .brand-logo {
  background: var(--ink-100);
  border-color: rgba(0,0,0,.08);
}
.brand-logo svg { display: block; }

.brand-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: var(--sp-8);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-10);
}

.user-chip {
  font-size: 13px;
  color: var(--text-muted);
  padding: var(--sp-4) var(--sp-10);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-pill);
}

/* ── Layout containers ─────────────────────────────────────────────── */
.main-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-24);
  position: relative;
  z-index: 1;
}
.main-wide {
  flex: 1;
  width: min(960px, 100%);
  margin: 0 auto;
  padding: var(--sp-24);
  position: relative;
  z-index: 1;
}

/* ── Card (extends .glass) ─────────────────────────────────────────── */
.card {
  padding: var(--sp-32);
  position: relative;
}
.auth-card { width: min(400px, 100%); }
.auth-card-wide { width: min(560px, 100%); }
.card h1 {
  margin: 0 0 var(--sp-4);
  font-size: var(--fs-xl);
  line-height: 28px;
  font-weight: 600;
}

/* ── Text utilities ────────────────────────────────────────────────── */
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }

/* ── Form fields ───────────────────────────────────────────────────── */
.field {
  display: block;
  margin: var(--sp-16) 0;
}
.field span {
  display: block;
  margin-bottom: var(--sp-6);
  font-size: 13px;
  color: var(--text-muted);
}
.field input {
  width: 100%;
  padding: 9px var(--sp-12);
  font: inherit;
  color: var(--text);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
html[data-theme="light"] .field input {
  background: rgba(0,0,0,.02);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
.input-code {
  font-family: var(--mono);
  font-size: var(--fs-lg);
  letter-spacing: .35em;
  text-align: center;
}

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-6);
  padding: 9px var(--sp-16);
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}
.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  background: var(--accent-solid);
  border-color: var(--accent-solid);
  color: var(--accent-contrast);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 48, 255, .3);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-block {
  width: 100%;
  margin-top: var(--sp-8);
}
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-danger { color: var(--red-500); }
.btn-danger:hover { border-color: var(--red-500); }
.btn-icon {
  font: inherit;
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  width: 34px;
  height: 34px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}
.btn-icon:hover {
  border-color: var(--accent);
}

.inline-form { display: inline; }

/* ── Alerts ────────────────────────────────────────────────────────── */
.alert {
  padding: var(--sp-10) var(--sp-12);
  border-radius: var(--radius-md);
  margin: var(--sp-12) 0;
  font-size: 13px;
  line-height: var(--lh-loose);
}
.alert-error {
  background: var(--red-bg);
  color: var(--red-500);
  border: 1px solid rgba(194, 71, 71, .3);
}
.alert-ok {
  background: var(--green-bg);
  color: var(--green-500);
  border: 1px solid rgba(57, 134, 106, .3);
}

/* ── Flash messages ────────────────────────────────────────────────── */
.flashes {
  width: min(400px, 100%);
  margin-bottom: var(--sp-12);
  position: relative;
  z-index: 2;
}
.flash {
  padding: var(--sp-10) var(--sp-12);
  border-radius: var(--radius-md);
  font-size: 13px;
  background: var(--surface-solid);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
}

/* ── MFA enroll ────────────────────────────────────────────────────── */
.enroll-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-24);
  margin-top: var(--sp-16);
}
@media (max-width: 560px) {
  .enroll-grid { grid-template-columns: 1fr; }
}
.qr-box {
  background: #ffffff;
  border-radius: var(--radius-md);
  padding: var(--sp-10);
  width: fit-content;
  height: fit-content;
}
.reenroll {
  margin-top: var(--sp-16);
  border-top: 1px solid var(--surface-border);
  padding-top: var(--sp-12);
}
.reenroll summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
}
.secret {
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
  background: rgba(127, 127, 127, .12);
  padding: var(--sp-8) var(--sp-10);
  border-radius: var(--radius-md);
  margin-bottom: var(--sp-8);
  user-select: all;
}

/* ── Launcher ──────────────────────────────────────────────────────── */
.launcher-head h1 {
  margin: var(--sp-24) 0 var(--sp-2);
  font-size: var(--fs-2xl);
  line-height: 32px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--sp-16);
  margin-top: var(--sp-24);
}

.tile {
  display: flex;
  flex-direction: column;
  gap: var(--sp-10);
  padding: var(--sp-20);
  min-height: 96px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  color: var(--text);
  text-decoration: none;
  position: relative;
  overflow: hidden;
  transition: border-color var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}

/* Gradient border overlay on tiles */
.tile::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(
    168deg,
    var(--glass-border-top) 0%,
    var(--glass-border-side) 40%,
    var(--glass-border-bottom) 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  pointer-events: none;
}

/* Sheen on tiles */
.tile::after {
  content: '';
  position: absolute;
  inset: -100%;
  background: linear-gradient(
    115deg,
    transparent 40%,
    rgba(255,255,255,.06) 45%,
    rgba(255,255,255,.12) 50%,
    rgba(255,255,255,.06) 55%,
    transparent 60%
  );
  transform: translateX(-100%);
  transition: transform 500ms var(--ease-glass);
  pointer-events: none;
  z-index: 1;
}
a.tile:hover::after {
  transform: translateX(100%);
}

a.tile:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: var(--shadow-3), 0 0 24px rgba(0, 48, 255, .08);
}
a.tile:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.tile-disabled {
  opacity: .5;
  cursor: default;
}
.tile-header {
  display: flex;
  align-items: center;
  gap: var(--sp-10);
}
.tile-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-lg);
  flex-shrink: 0;
}
.tile-nombre {
  font-size: var(--fs-md);
  font-weight: 600;
}
.rol-badge {
  align-self: flex-start;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: capitalize;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: var(--radius-pill);
  padding: var(--sp-2) var(--sp-10);
}

/* Tile color identities derived from LBS blue */
.tile-icon--sgo      { background: rgba(47,107,255,.15); color: var(--blue-400); }
.tile-icon--gestion  { background: rgba(57,134,106,.15); color: var(--green-500); }
.tile-icon--sengi    { background: rgba(163,139,250,.15); color: #a38bfa; }
.tile-icon--scada    { background: rgba(0,180,255,.15); color: #00b4ff; }
.tile-icon--mt       { background: rgba(245,182,64,.15); color: #f5b640; }
.tile-icon--dispatch { background: rgba(255,140,50,.15); color: #ff8c32; }

.launcher-foot {
  display: flex;
  gap: var(--sp-10);
  flex-wrap: wrap;
  margin-top: var(--sp-40);
  padding-top: var(--sp-16);
  border-top: 1px solid var(--surface-border);
}

/* ── Auth card entrance animation ──────────────────────────────────── */
@keyframes card-enter {
  from {
    opacity: 0;
    transform: translateY(20px) scale(.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
.auth-card,
.auth-card-wide {
  animation: card-enter var(--dur-enter) var(--ease-out);
}

/* ── Login step transition ─────────────────────────────────────────── */
@keyframes step-slide {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
.step-enter {
  animation: step-slide var(--dur-enter) var(--ease-out);
}

/* ── aria-live for errors ──────────────────────────────────────────── */
.alert[role="alert"] { /* specificity for aria-live announced alerts */ }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .topbar { padding: var(--sp-10) var(--sp-16); }
  .main-center,
  .main-wide { padding: var(--sp-16); }
  .card { padding: var(--sp-24); }
  .tiles { grid-template-columns: 1fr; }
  .launcher-head h1 { font-size: var(--fs-xl); }
}

@media (min-width: 2000px) {
  .main-wide { width: min(1200px, 100%); }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

/* ── Reduced motion for portal-specific ────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .auth-card,
  .auth-card-wide {
    animation: none;
  }
  .step-enter { animation: none; }
  .tile::after { display: none; }
  a.tile:hover { transform: none; }
  .btn-primary:hover { transform: none; }
}

@supports not (backdrop-filter: blur(1px)) {
  .tile {
    background: var(--surface-solid);
  }
  .flash {
    background: var(--surface-solid);
  }
}
