/* ── AICWISE Portal Auth ── */

/* Login overlay — light, portal-aligned */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #f0f4f6 0%, #e8f0ef 45%, #f5f7f9 100%);
  overflow: hidden;
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.auth-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-overlay__bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 85% 15%, rgba(26, 147, 111, 0.12) 0%, transparent 55%),
    radial-gradient(ellipse 55% 45% at 10% 85%, rgba(15, 76, 92, 0.1) 0%, transparent 50%);
  pointer-events: none;
}

.auth-overlay__orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  pointer-events: none;
  opacity: 0.55;
}

.auth-overlay__orb--1 {
  width: 320px;
  height: 320px;
  top: -80px;
  right: -60px;
  background: rgba(26, 147, 111, 0.22);
}

.auth-overlay__orb--2 {
  width: 280px;
  height: 280px;
  bottom: -70px;
  left: -50px;
  background: rgba(15, 76, 92, 0.18);
}

.auth-card {
  position: relative;
  width: min(420px, calc(100vw - 2rem));
  padding: 2rem 2rem 1.6rem;
  background: #fff;
  border: 1px solid rgba(15, 76, 92, 0.1);
  border-radius: 1.25rem;
  box-shadow:
    0 4px 6px rgba(15, 76, 92, 0.04),
    0 24px 56px rgba(15, 76, 92, 0.1);
  animation: auth-card-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  overflow: hidden;
}

.auth-card__accent {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary) 0%, #157a5e 50%, var(--accent) 100%);
}

@keyframes auth-card-in {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-card__logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1.1rem;
}

.auth-card__logo-ring {
  padding: 2px;
  border-radius: 1rem;
  background: linear-gradient(145deg, var(--primary) 0%, #157a5e 55%, var(--accent) 100%);
  box-shadow: 0 6px 22px rgba(15, 76, 92, 0.18);
  overflow: hidden;
  line-height: 0;
}

.auth-card__logo {
  display: block;
  width: 6.25rem;
  height: 6.25rem;
  border-radius: 0.85rem;
  object-fit: cover;
  object-position: center;
  background: #0a0a0f;
  padding: 0;
  transform: scale(1.72);
  transform-origin: center center;
}

.auth-card__brand {
  text-align: center;
  margin-bottom: 1.6rem;
}

.auth-card__badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(26, 147, 111, 0.1);
  border: 1px solid rgba(26, 147, 111, 0.2);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  margin-bottom: 0.55rem;
}

.auth-card__brand h1 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.auth-card__brand p {
  font-size: 0.82rem;
  color: #6b7280;
  line-height: 1.5;
}

.auth-card__brand a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s;
}

.auth-card__brand a:hover { color: var(--primary); }

.auth-form { display: flex; flex-direction: column; gap: 0.95rem; }

.auth-field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: #4b5563;
  margin-bottom: 0.38rem;
}

.auth-field input {
  width: 100%;
  padding: 0.68rem 0.9rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  color: var(--dark);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  direction: ltr;
  text-align: right;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.auth-field input::placeholder { color: #bbb; }

.auth-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26, 147, 111, 0.14);
}

.auth-error {
  font-size: 0.78rem;
  color: var(--danger);
  text-align: center;
  min-height: 1.2em;
  opacity: 0;
  transition: opacity 0.25s;
}

.auth-error.visible { opacity: 1; }

.auth-form.shake {
  animation: auth-shake 0.45s ease;
}

@keyframes auth-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.auth-submit {
  margin-top: 0.2rem;
  padding: 0.72rem 1rem;
  background: linear-gradient(135deg, var(--primary) 0%, #157a5e 50%, var(--accent) 100%);
  color: #fff;
  border: none;
  border-radius: 0.65rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 4px 18px rgba(15, 76, 92, 0.25);
}

.auth-submit svg {
  transform: scaleX(-1);
  opacity: 0.9;
}

.auth-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(15, 76, 92, 0.3);
}

.auth-submit:active { transform: translateY(0); }

.auth-submit:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

.auth-footer {
  margin-top: 1.35rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.72rem;
  color: #9ca3af;
}

.auth-footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.auth-footer a:hover { color: var(--accent); }

/* Portal hidden until auth */
body:not(.is-authenticated) .app-shell,
body:not(.is-authenticated) .sidebar-toggle,
body:not(.is-authenticated) .user-profile {
  display: none !important;
}

/* ── Profile in toolbar ── */
.user-profile {
  position: relative;
  flex-shrink: 0;
}

.user-profile__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem 0.35rem 0.45rem;
  background: var(--glass-bg, #fff);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--primary);
}

.user-profile__trigger:hover {
  background: var(--setting-primary-soft, rgba(15, 76, 92, 0.08));
  border-color: var(--primary);
}

.user-profile__trigger[aria-expanded="true"] {
  background: var(--setting-primary-soft, rgba(15, 76, 92, 0.1));
  border-color: var(--primary);
}

.user-profile__avatar {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.user-profile__name {
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.user-profile__chevron {
  font-size: 0.55rem;
  opacity: 0.45;
  transition: transform 0.2s;
}

.user-profile__trigger[aria-expanded="true"] .user-profile__chevron {
  transform: rotate(180deg);
}

/* Dropdown */
.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  inset-inline-end: 0;
  inset-inline-start: auto;
  width: min(260px, calc(100vw - 1.5rem));
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  z-index: 500;
  overflow: hidden;
}

.user-dropdown.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-dropdown__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: #f8f9fa;
}

.user-dropdown__header img {
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 2px solid var(--border);
}

.user-dropdown__header-info strong {
  display: block;
  font-size: 0.85rem;
  color: var(--dark);
  margin-bottom: 0.15rem;
}

.user-dropdown__header-info span {
  font-size: 0.72rem;
  color: #888;
  direction: ltr;
  display: block;
}

.user-dropdown__section {
  padding: 0.45rem 0;
}

.user-dropdown__label {
  padding: 0.35rem 1rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.user-dropdown__item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 1rem;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--dark);
  text-decoration: none;
  cursor: pointer;
  text-align: right;
  transition: background 0.15s, color 0.15s;
}

.user-dropdown__item:hover {
  background: #f0f4f5;
  color: var(--primary);
}

.user-dropdown__item svg {
  width: 1rem;
  height: 1rem;
  opacity: 0.5;
  flex-shrink: 0;
}

.user-dropdown__divider {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0;
}

.user-dropdown__item--danger {
  color: var(--danger);
}

.user-dropdown__item--danger:hover {
  background: rgba(174, 32, 18, 0.08);
  color: var(--danger);
}

@media (max-width: 768px) {
  .user-profile__name { display: none; }
}
