/* ================================================================
   Intrasistema Login — Modernized UX
   Theme: Topographic Vector Waves
   ================================================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Common geometry & motion tokens */
  --radius-card:   24px;
  --radius-pill:   100px;
  --radius-sm:     12px;

  --transition:    0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  color-scheme: light dark;
}

/* Light Theme (Default / Explicit) */
:root,
[data-theme="light"] {
  --bg-deep:       #0a0815;
  --bg-gradient:   radial-gradient(ellipse 100% 100% at 50% 20%, #120e28 0%, #0a0815 65%, #05040a 100%);
  --bg-card:       rgba(255, 255, 255, 0.94);
  --bg-card-hover: rgba(255, 255, 255, 0.98);
  --bg-input:      #f1f3f7;
  --bg-input-focus:#ffffff;

  --accent:        #0d2366;
  --accent-light:  #1e3a8a;
  --accent-glow:   rgba(13, 35, 102, 0.14);

  --text-primary:  #0f172a;
  --text-secondary:#475569;
  --text-muted:    #94a3b8;
  --text-on-accent:#ffffff;

  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-card:   rgba(255, 255, 255, 0.85);

  --shadow-card:   0 16px 40px rgba(0, 0, 0, 0.28),
                   0 4px 12px rgba(0, 0, 0, 0.16);
  --shadow-input:  0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-btn:    0 4px 14px rgba(13, 35, 102, 0.25);

  --dropdown-bg:     rgba(255, 255, 255, 0.96);
  --dropdown-border: rgba(0, 0, 0, 0.08);
  --dropdown-shadow: 0 10px 25px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.04);

  --skeleton-bg:     var(--bg-input);
  --skeleton-shimmer:rgba(255, 255, 255, 0.75);
  --skeleton-dark-el:rgba(0, 0, 0, 0.07);

  --alert-warn-bg:    #fef3c7;
  --alert-warn-text:  #92400e;
  --alert-warn-border:#fde68a;

  --alert-danger-bg:    #fee2e2;
  --alert-danger-text:  #991b1b;
  --alert-danger-border:#fecaca;

  --alert-info-bg:    #eef2ff;
  --alert-info-text:  #3730a3;
  --alert-info-border:#c7d2fe;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-deep:       #0a0815;
  --bg-gradient:   radial-gradient(ellipse 100% 100% at 50% 20%, #120e28 0%, #0a0815 65%, #05040a 100%);
  --bg-card:       rgba(18, 15, 30, 0.88);
  --bg-card-hover: rgba(24, 20, 40, 0.95);
  --bg-input:      rgba(255, 255, 255, 0.06);
  --bg-input-focus:rgba(255, 255, 255, 0.10);

  --accent:        #3b82f6;
  --accent-light:  #60a5fa;
  --accent-glow:   rgba(59, 130, 246, 0.25);

  --text-primary:  #f8fafc;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --text-on-accent:#ffffff;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-card:   rgba(255, 255, 255, 0.12);

  --shadow-card:   0 20px 50px rgba(0, 0, 0, 0.6),
                   0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-input:  0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-btn:    0 4px 14px rgba(59, 130, 246, 0.35);

  --dropdown-bg:     rgba(22, 18, 38, 0.96);
  --dropdown-border: rgba(255, 255, 255, 0.12);
  --dropdown-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);

  --skeleton-bg:     rgba(255, 255, 255, 0.05);
  --skeleton-shimmer:rgba(255, 255, 255, 0.12);
  --skeleton-dark-el:rgba(255, 255, 255, 0.08);

  --alert-warn-bg:    rgba(245, 158, 11, 0.15);
  --alert-warn-text:  #fcd34d;
  --alert-warn-border:rgba(245, 158, 11, 0.3);

  --alert-danger-bg:    rgba(239, 68, 68, 0.15);
  --alert-danger-text:  #fca5a5;
  --alert-danger-border:rgba(239, 68, 68, 0.3);

  --alert-info-bg:    rgba(99, 102, 241, 0.15);
  --alert-info-text:  #a5b4fc;
  --alert-info-border:rgba(99, 102, 241, 0.3);
}

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

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---------- Utility Classes (replace Bootstrap) ---------- */
.hidden    { display: none !important; }
.flex      { display: flex !important; }
.sr-only   {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Background Scene ---------- */
.background {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  overflow: hidden;
  padding: 24px;
  background: var(--bg-gradient);
  transition: background 0.4s ease;
}

/* Topographic Waves Canvas */
.topography-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* Ambient noise overlay for depth */
.background::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  opacity: 0.5;
  z-index: 0;
  pointer-events: none;
}

/* ---------- Login Card ---------- */
.login-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(40px) saturate(1.4);
  -webkit-backdrop-filter: blur(40px) saturate(1.4);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: cardEnter 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
  transition: max-width var(--transition), min-height var(--transition), box-shadow var(--transition), border-radius var(--transition);
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- Desktop Photo Panel (Unsplash) ---------- */
.login-photo-panel {
  display: none; /* hidden by default on mobile/small screens */
}

/* Base Photo Styles (Active when panel is shown) */
.photo-image-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.photo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  opacity: 0;
  transform: scale(1.02);
  transition: opacity 0.7s ease-in-out, transform 12s cubic-bezier(0.25, 1, 0.5, 1);
}

.photo-img.photo-loaded {
  opacity: 1;
  transform: scale(1.06);
}

.photo-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    110deg,
    #130f1e 8%,
    #24193a 18%,
    #130f1e 33%
  );
  background-size: 200% 100%;
  animation: photoShimmer 1.8s linear infinite;
  z-index: 0;
}

@keyframes photoShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Transparent Photo Attribution Overlay */
.photo-badge {
  position: absolute;
  bottom: 24px;
  left: 24px;
  right: 24px;
  z-index: 3;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: auto;
}

.photo-credit {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8), 0 2px 10px rgba(0, 0, 0, 0.9);
  user-select: none;
}

.photo-credit a {
  color: #ffffff;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(255, 255, 255, 0.5);
  font-weight: 500;
  transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
}

.photo-credit a:hover {
  color: #93c5fd;
  text-decoration-color: #93c5fd;
}

.photo-refresh-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.photo-refresh-btn svg {
  width: 16px;
  height: 16px;
}

.photo-refresh-btn:hover {
  background: rgba(0, 0, 0, 0.5);
  border-color: rgba(255, 255, 255, 0.4);
  transform: rotate(45deg);
}

.photo-refresh-btn:active {
  transform: scale(0.92) rotate(90deg);
}

.photo-refresh-btn.spinning svg {
  animation: spin 0.6s linear infinite;
}

/* ---------- Responsive Desktop Breakpoints ---------- */

/* Tablet & Compact Desktop (768px - 1023px) */
@media (min-width: 768px) {
  .background {
    padding: clamp(20px, 3vh, 40px);
  }

  .login-card {
    width: 95vw;
    max-width: 960px;
    min-height: 580px;
    flex-direction: row;
    align-items: stretch;
  }

  .login-photo-panel {
    display: flex;
    flex: 1.15 1 0;
    min-width: 340px;
    position: relative;
    overflow: hidden;
    background: #0f0c18;
    flex-direction: column;
    justify-content: flex-end;
    border-top-left-radius: calc(var(--radius-card) - 1px);
    border-bottom-left-radius: calc(var(--radius-card) - 1px);
  }

  .login-photo-panel::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
      180deg,
      rgba(15, 12, 24, 0.1) 0%,
      rgba(15, 12, 24, 0.35) 50%,
      rgba(15, 12, 24, 0.85) 100%
    );
    pointer-events: none;
    z-index: 1;
  }

  .card-body {
    flex: 1 1 0;
    min-width: 340px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 40px 32px 28px;
  }

  .card-body-inner {
    width: 100%;
    max-width: 380px;
    margin: auto 0;
    display: flex;
    flex-direction: column;
  }
}

/* Standard Desktop (1024px - 1439px) */
@media (min-width: 1024px) {
  .background {
    padding: clamp(24px, 4vh, 48px);
  }

  .login-card {
    width: 90vw;
    max-width: 1180px;
    min-height: clamp(620px, 80vh, 750px);
    border-radius: 28px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35),
                0 4px 16px rgba(0, 0, 0, 0.15);
  }

  .login-photo-panel {
    flex: 1.38 1 0;
    min-width: 460px;
    border-top-left-radius: 27px;
    border-bottom-left-radius: 27px;
  }

  .photo-badge {
    bottom: 28px;
    left: 28px;
    right: 28px;
  }

  .card-body {
    flex: 1 1 0;
    min-width: 380px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: clamp(48px, 4.5vw, 68px) clamp(36px, 3.5vw, 60px) clamp(24px, 2.5vw, 36px);
  }

  .card-body-inner {
    max-width: 400px;
    margin: auto 0;
    display: flex;
    flex-direction: column;
  }
}

/* Large & Ultra-wide Displays (1440px+) */
@media (min-width: 1440px) {
  .background {
    padding: 48px;
  }

  .login-card {
    width: 86vw;
    max-width: 1340px;
    min-height: clamp(680px, 82vh, 800px);
    border-radius: 32px;
  }

  .login-photo-panel {
    flex: 1.48 1 0;
    border-top-left-radius: 31px;
    border-bottom-left-radius: 31px;
  }

  .photo-badge {
    bottom: 32px;
    left: 32px;
    right: 32px;
  }

  .card-body {
    padding: 64px 60px 36px;
  }

  .card-body-inner {
    max-width: 420px;
    margin: auto 0;
    display: flex;
    flex-direction: column;
  }
}

/* ---------- Card Body (Mobile / Default) ---------- */
.card-body {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 48px 40px 28px;
  width: 100%;
}

.card-body-inner {
  width: 100%;
  margin: auto 0;
  display: flex;
  flex-direction: column;
}

@media (max-width: 480px) {
  .card-body {
    padding: 36px 24px 28px;
  }
}

/* ---------- Language Switcher ---------- */
/* ---------- Card Top Bar (Theme & Language Switchers) ---------- */
.card-top-bar {
  position: absolute;
  top: 18px;
  right: 20px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-selector-container,
.lang-selector-container {
  position: relative;
}

.theme-pill-btn,
.lang-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  background: var(--bg-input);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-input);
  transition: all var(--transition-fast);
  user-select: none;
}

.theme-pill-btn:hover,
.lang-pill-btn:hover {
  background: var(--bg-input-focus);
  color: var(--text-primary);
  border-color: var(--border-subtle);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.theme-mode-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.theme-pill-btn:hover .theme-mode-icon {
  color: var(--accent);
}

.theme-label-text {
  font-size: 0.75rem;
  line-height: 1;
}

.lang-globe-icon {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.lang-pill-btn:hover .lang-globe-icon {
  color: var(--accent);
}

.theme-chevron-icon,
.lang-chevron-icon {
  width: 11px;
  height: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}

.theme-pill-btn[aria-expanded="true"] .theme-chevron-icon,
.lang-pill-btn[aria-expanded="true"] .lang-chevron-icon {
  transform: rotate(180deg);
}

/* Dropdowns */
.theme-dropdown,
.lang-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 142px;
  background: var(--dropdown-bg);
  border: 1px solid var(--dropdown-border);
  border-radius: 14px;
  box-shadow: var(--dropdown-shadow);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 50;
  animation: dropdownFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.theme-option,
.lang-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 8px;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  text-align: left;
  width: 100%;
}

.theme-option-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-option-icon {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.theme-option:hover,
.lang-option:hover {
  background: var(--accent-glow);
  color: var(--accent);
}

.theme-option:hover .theme-option-icon {
  color: var(--accent);
}

.theme-option.active,
.lang-option.active {
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-glow);
}

.theme-option.active .theme-option-icon {
  color: var(--accent);
}

.theme-option .theme-check,
.lang-option .lang-check {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
}

.theme-option.active .theme-check,
.lang-option.active .lang-check {
  opacity: 1;
}

@keyframes dropdownFadeIn {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ---------- Card Content (fixed height zone) ---------- */
.card-content {
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

/* ---------- Brand ---------- */
.brand-wrapper {
  margin-bottom: 8px;
  text-align: center;
  height: 40px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-wrapper img {
  height: 40px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  display: block;
  transition: filter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Description / Title ---------- */
.login-card-description {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 28px;
  letter-spacing: -0.01em;
}

/* ---------- Section Labels ---------- */
.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

/* ---------- Tenant Input ---------- */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.form-control {
  display: block;
  width: 100%;
  height: 50px;
  padding: 0 52px 0 20px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1.5px solid transparent;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-input);
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-control:focus {
  background: var(--bg-input-focus);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow-input);
}

/* ---------- Next-Step / Arrow Button ---------- */
#next-step-btn {
  position: absolute;
  right: 5px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  color: var(--text-on-accent);
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: transform var(--transition-fast), box-shadow var(--transition), background var(--transition);
  z-index: 2;
}

#next-step-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#next-step-btn:hover {
  background: var(--accent-light);
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(13, 35, 102, 0.35);
}

#next-step-btn:active {
  transform: scale(0.94);
}

/* Spinner inside button */
#next-step-btn .spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ---------- Selected Tenant Display ---------- */
.selected-tenant-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 8px 12px 8px 8px;
  min-height: 50px;
  transition: background var(--transition), border-color var(--transition);
}

.selected-tenant-display:hover {
  background: var(--bg-input-focus);
  border-color: rgba(0, 0, 0, 0.1);
}

.tenant-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.tenant-icon-wrapper {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-accent);
}

.tenant-icon-wrapper svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

#selected-tenant-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#change-tenant-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

#change-tenant-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

#change-tenant-btn:hover {
  color: var(--accent);
  background: rgba(13, 35, 102, 0.06);
  transform: rotate(15deg);
}

/* ---------- Alert ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 16px;
  line-height: 1.4;
}

.alert-warning {
  background: var(--alert-warn-bg);
  color: var(--alert-warn-text);
  border: 1px solid var(--alert-warn-border);
}

.alert-danger {
  background: var(--alert-danger-bg);
  color: var(--alert-danger-text);
  border: 1px solid var(--alert-danger-border);
}

.alert-info {
  background: var(--alert-info-bg);
  color: var(--alert-info-text);
  border: 1px solid var(--alert-info-border);
}

.popup-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4f46e5;
  box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.7);
  animation: pulseDot 1.6s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  flex-shrink: 0;
  margin-top: 4px;
}

@keyframes pulseDot {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 7px rgba(79, 70, 229, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(79, 70, 229, 0);
  }
}

.popup-status-text-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.84rem;
  line-height: 1.35;
}

.popup-focus-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  text-align: left;
  font-size: 0.8rem;
  transition: color var(--transition-fast);
}

.popup-focus-link:hover {
  color: var(--accent-light);
}

.alert-content {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.alert-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-dismiss {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 50%;
  color: inherit;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity var(--transition-fast), background var(--transition-fast);
  padding: 0;
}

.alert-dismiss svg {
  width: 16px;
  height: 16px;
}

.alert-dismiss:hover {
  opacity: 1;
  background: rgba(0, 0, 0, 0.06);
}

/* Global error has flex layout with dismiss */
#global-error {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

#global-error.hidden {
  display: none;
}



/* ---------- Skeleton System ---------- */
.skeleton-shimmer {
  position: relative;
  overflow: hidden;
}

.skeleton-shimmer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--skeleton-shimmer) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  pointer-events: none;
}

/* Tenant Skeleton */
.skeleton-tenant-group {
  margin-bottom: 20px;
}

.skeleton-label {
  height: 12px;
  width: 120px;
  border-radius: 4px;
  background: var(--skeleton-bg);
  margin-bottom: 10px;
  position: relative;
  overflow: hidden;
}

.skeleton-label::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--skeleton-shimmer) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.skeleton-tenant-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 50px;
  background: var(--skeleton-bg);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 8px 14px 8px 8px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-input);
}

.skeleton-tenant-badge::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--skeleton-shimmer) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.skeleton-tenant-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-glow);
  flex-shrink: 0;
}

.skeleton-tenant-text {
  height: 15px;
  width: 130px;
  border-radius: 4px;
  background: var(--skeleton-dark-el);
}

.skeleton-tenant-action {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--skeleton-dark-el);
  margin-left: auto;
  flex-shrink: 0;
}

/* ---------- Auth Area & Skeletons ---------- */
.auth-area {
  position: relative;
  min-height: 108px;
  margin-top: 4px;
}

.skeleton-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.skeleton-btn {
  height: 48px;
  width: 100%;
  border-radius: var(--radius-sm);
  background: var(--skeleton-bg);
  border: 1.5px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-input);
}

.skeleton-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--skeleton-shimmer) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.skeleton-btn-icon {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: var(--skeleton-dark-el);
  flex-shrink: 0;
}

.skeleton-btn-text {
  height: 13px;
  border-radius: 4px;
  background: var(--skeleton-dark-el);
}

.skeleton-btn-text--email {
  width: 135px;
}

.skeleton-btn-text--google {
  width: 145px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Initial Load & Pre-render States for Instant Skeleton Display */
html.has-saved-tenant #tenant-selection-container {
  display: none !important;
}

html.has-saved-tenant #tenant-skeleton {
  display: block !important;
}

html.has-saved-tenant #auth-area {
  display: block !important;
}

html.has-saved-tenant #auth-skeleton {
  display: flex !important;
}

/* ---------- Firebase UI Overrides ---------- */
#firebaseui-auth-container {
  margin-top: 0;
}

/* Container reset */
.firebaseui-container {
  max-width: 100% !important;
  background: transparent !important;
  box-shadow: none !important;
  font-family: "Inter", system-ui, sans-serif !important;
}

.firebaseui-card-content {
  padding: 0 !important;
}

.firebaseui-card-header {
  display: none !important;
}

.firebaseui-card-actions {
  padding: 0 !important;
}

/* Provider buttons */
.firebaseui-idp-button,
.firebaseui-idp-button.mdl-button {
  max-width: 100% !important;
  border-radius: var(--radius-sm) !important;
  height: 48px !important;
  box-shadow: var(--shadow-input) !important;
  border: 1.5px solid var(--border-subtle) !important;
  transition: all var(--transition) !important;
  font-family: "Inter", system-ui, sans-serif !important;
}

.firebaseui-idp-button:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
  border-color: var(--border-subtle) !important;
}

/* Dark Mode IDP Buttons */
[data-theme="dark"] .firebaseui-idp-button {
  background-color: rgba(255, 255, 255, 0.07) !important;
  color: #f8fafc !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
}

[data-theme="dark"] .firebaseui-idp-button:hover {
  background-color: rgba(255, 255, 255, 0.12) !important;
  border-color: rgba(255, 255, 255, 0.22) !important;
}

[data-theme="dark"] .firebaseui-idp-google {
  background-color: #ffffff !important;
  color: #3c4043 !important;
}

[data-theme="dark"] .firebaseui-idp-google .firebaseui-idp-text {
  color: #3c4043 !important;
}

/* Override email button color to match brand */
.firebaseui-idp-password,
.firebaseui-idp-password.mdl-button {
  background-color: var(--accent) !important;
  color: var(--text-on-accent) !important;
}

.firebaseui-idp-password:hover {
  background-color: var(--accent-light) !important;
}

.firebaseui-idp-text {
  font-size: 0.9rem !important;
  font-weight: 500 !important;
}

/* Email/password form */
.firebaseui-textfield.mdl-textfield .firebaseui-input,
.firebaseui-textfield.mdl-textfield .firebaseui-id-country-selector {
  font-family: "Inter", system-ui, sans-serif !important;
  font-size: 0.95rem !important;
  border-color: var(--border-subtle) !important;
  color: var(--text-primary) !important;
}

.firebaseui-textfield.mdl-textfield .firebaseui-input:focus {
  border-color: var(--accent) !important;
}

.firebaseui-label {
  font-family: "Inter", system-ui, sans-serif !important;
  color: var(--text-secondary) !important;
}

.mdl-button--raised.mdl-button--colored,
.firebaseui-id-submit {
  background-color: var(--accent) !important;
  border-radius: var(--radius-sm) !important;
  font-family: "Inter", system-ui, sans-serif !important;
  font-weight: 600 !important;
  letter-spacing: 0.01em !important;
  height: 46px !important;
  transition: all var(--transition) !important;
}

.mdl-button--raised.mdl-button--colored:hover,
.firebaseui-id-submit:hover {
  background-color: var(--accent-light) !important;
  box-shadow: var(--shadow-btn) !important;
}

.mdl-button--primary,
.firebaseui-id-secondary-link {
  color: var(--accent) !important;
  font-family: "Inter", system-ui, sans-serif !important;
}

/* Progress bar */
.firebaseui-busy-indicator {
  background-color: var(--accent) !important;
}

.mdl-progress > .progressbar {
  background-color: var(--accent) !important;
}

.mdl-progress > .bufferbar {
  background: var(--bg-input) !important;
}

/* Terms of Service text */
.firebaseui-tos {
  font-family: "Inter", system-ui, sans-serif !important;
  color: var(--text-muted) !important;
}

.firebaseui-link {
  color: var(--accent) !important;
}

/* ---------- Footer ---------- */
.login-card-footer-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 20px;
  margin-bottom: 6px;
  line-height: 1.6;
}

.login-card-footer-text a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition-fast);
}

.login-card-footer-text a:hover {
  color: var(--accent-light);
  text-decoration: underline;
}

.login-card-footer-nav {
  text-align: center;
  padding-bottom: 2px;
}

.login-card-footer-nav a {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.login-card-footer-nav a:hover {
  color: var(--text-secondary);
  text-decoration: underline;
}

/* ---------- Cloudflare Edge & Telemetry (Bottom of Card Panel) ---------- */
.geo-footer-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: auto;
  padding-top: 16px;
}

.geo-footer-info {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-pill);
  background: var(--bg-input);
  font-family: inherit;
  font-size: 0.70rem;
  color: var(--text-muted);
  letter-spacing: 0.01em;
  line-height: 1.3;
  cursor: pointer;
  user-select: none;
  opacity: 0.9;
  transition: all var(--transition-fast);
  width: auto;
  max-width: 100%;
}

.geo-footer-info:hover,
.geo-footer-info[aria-expanded="true"] {
  opacity: 1;
  background: var(--bg-input-focus);
  color: var(--text-primary);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.geo-footer-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  white-space: nowrap;
}

#geo-item-location {
  flex-shrink: 1;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#geo-item-isp {
  flex-shrink: 1;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.geo-footer-item strong {
  font-weight: 600;
  color: var(--text-secondary);
}

.geo-footer-icon {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.geo-info-badge-icon {
  width: 13px;
  height: 13px;
  color: var(--text-muted);
  opacity: 0.75;
  flex-shrink: 0;
  margin-left: 2px;
  transition: color var(--transition-fast);
}

.geo-footer-info:hover .geo-info-badge-icon,
.geo-footer-info[aria-expanded="true"] .geo-info-badge-icon {
  color: var(--accent);
  opacity: 1;
}

.geo-divider {
  color: var(--text-muted);
  opacity: 0.4;
  font-size: 0.65rem;
  flex-shrink: 0;
}

/* ---------- Custom Glassmorphic Telemetry Tooltip / Popover ---------- */
.geo-tooltip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: min(360px, 92vw);
  background: rgba(18, 14, 28, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  padding: 14px 16px;
  z-index: 100;
  color: #fff;
  animation: geoTooltipFade 0.22s cubic-bezier(0.16, 1, 0.3, 1) both;
  pointer-events: auto;
}

.geo-tooltip.hidden {
  display: none !important;
}

.geo-tooltip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.geo-tooltip-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #f3f4f6;
  letter-spacing: 0.02em;
}

.geo-tooltip-title svg {
  width: 14px;
  height: 14px;
  color: #60a5fa;
}

.geo-tooltip-badge {
  font-size: 0.68rem;
  font-weight: 700;
  background: rgba(96, 165, 250, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(96, 165, 250, 0.3);
  padding: 2px 7px;
  border-radius: 100px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.geo-tooltip-grid {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.geo-tooltip-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.73rem;
  line-height: 1.35;
}

.geo-tooltip-label {
  color: #9ca3af;
  flex-shrink: 0;
}

.geo-tooltip-val {
  color: #e5e7eb;
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}

.geo-tooltip-arrow {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid rgba(18, 14, 28, 0.96);
}

@keyframes geoTooltipFade {
  from {
    opacity: 0;
    transform: translate(-50%, 6px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
  }
}

/* ---------- Handshake & Token Pipeline (Native to Card Content) ---------- */
#auth-handshake-container {
  display: flex;
  flex-direction: column;
  animation: viewSlideIn 0.35s cubic-bezier(0.16, 1, 0.3, 1) both;
}

#auth-handshake-container.hidden {
  display: none !important;
}

/* User meta inside selected-tenant-display */
.handshake-user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  text-align: left;
}

.handshake-user-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.handshake-user-sub {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
  margin-top: 2px;
}

#auth-user-avatar-wrap {
  position: relative;
  overflow: hidden;
}

#auth-user-avatar-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.handshake-status-badge {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 4px;
}

.handshake-pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(13, 35, 102, 0.6);
  animation: pulseDot 1.6s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.handshake-pulse-dot.success {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 35, 102, 0.18);
  animation: none;
}

/* Step Rows List */
.handshake-steps-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.handshake-step-row {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-input);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  transition: all var(--transition);
  opacity: 0.45;
}

.handshake-step-row.active {
  opacity: 1;
  background: var(--bg-input-focus);
  border-color: rgba(13, 35, 102, 0.25);
  box-shadow: var(--shadow-input);
}

.handshake-step-row.completed {
  opacity: 0.95;
  background: var(--bg-input);
  border-color: rgba(13, 35, 102, 0.12);
}

.handshake-step-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.handshake-step-bullet {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.handshake-step-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--transition-fast);
}

.handshake-step-spinner {
  display: none;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(13, 35, 102, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.handshake-step-check {
  display: none;
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.handshake-step-row.active .handshake-step-bullet {
  background: rgba(13, 35, 102, 0.08);
}

.handshake-step-row.active .handshake-step-dot {
  display: none;
}

.handshake-step-row.active .handshake-step-spinner {
  display: block;
}

.handshake-step-row.completed .handshake-step-bullet {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
}

.handshake-step-row.completed .handshake-step-dot,
.handshake-step-row.completed .handshake-step-spinner {
  display: none;
}

.handshake-step-row.completed .handshake-step-check {
  display: block;
}

.handshake-step-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.handshake-step-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.handshake-step-desc {
  font-size: 0.72rem;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.handshake-step-tag {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.04);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  letter-spacing: 0.02em;
  transition: all var(--transition-fast);
}

.handshake-step-row.active .handshake-step-tag {
  color: var(--accent-light);
  background: rgba(30, 58, 138, 0.08);
}

.handshake-step-row.completed .handshake-step-tag {
  color: var(--accent);
  background: rgba(13, 35, 102, 0.08);
}

/* Primary Action Button (Matches next-step-btn and Firebase UI primary buttons) */
.btn-primary-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--text-on-accent);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: all var(--transition-fast);
}

.btn-primary-action:hover {
  background: var(--accent-light);
  box-shadow: 0 6px 20px rgba(13, 35, 102, 0.35);
  transform: translateY(-1px);
  color: #fff;
}

.btn-primary-action:active {
  transform: scale(0.98);
}

.btn-primary-action svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Spinner inside action buttons */
.btn-spinner {
  width: 17px;
  height: 17px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

.btn-retry-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 44px;
  border-radius: var(--radius-sm);
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-retry-action:hover {
  background: #fecaca;
}

.btn-retry-action svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ---------- View Transitions ---------- */
#tenant-selection-container,
#selected-tenant-container,
#firebaseui-auth-container,
#tenant-alert {
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.view-enter {
  animation: viewSlideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .background {
    padding: 16px;
    align-items: flex-start;
    padding-top: 10vh;
  }

  .login-card {
    border-radius: 20px;
    max-width: 100%;
  }

  .brand-wrapper img {
    height: 28px;
  }

  .login-card-description {
    font-size: 1.15rem;
    margin-bottom: 20px;
  }
}

@media (max-width: 360px) {
  .card-body {
    padding: 28px 18px 22px;
  }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .login-card { animation: none !important; }
  .view-enter { animation: none !important; }
}