/* ==========================================================================
   Janus - Dinia Suite SSO & Topbar Components
   Harmonisé avec Iris & compatible Mode Sombre / Mode Clair
   ========================================================================== */

/* Variables de thème avec fallbacks */
:root {
  --primary: var(--janus-profile, #6366f1);
  --accent: var(--janus-project, #0891b2);
  --border-color: var(--janus-border, #222b42);
  --bg-surface: var(--janus-surface, #121828);
  --bg-hover: var(--janus-surface-hover, #1a2235);
  --bg-active: rgba(8, 145, 178, 0.25);
  --text-main: var(--janus-text, #f1f5f9);
  --text-muted: var(--janus-muted, #94a3b8);
  --text-dim: #64748b;
  --danger: var(--janus-danger, #ef4444);
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;
  --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.7);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --font-display: 'Montserrat', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

:root[data-theme="light"],
html[data-theme="light"] {
  --primary: #7c3aed;
  --accent: #0891b2;
  --border-color: #e2e8f0;
  --bg-surface: #ffffff;
  --bg-hover: #f1f5f9;
  --bg-active: rgba(8, 145, 178, 0.12);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --shadow-xl: 0 12px 32px rgba(15, 23, 42, 0.12), 0 4px 6px rgba(15, 23, 42, 0.04);
}

/* Helper utilitaire */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Bouton Avatar Dinia Header
   ========================================================================== */
.account-menu-container {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.account-avatar-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.account-avatar-btn:hover,
.account-avatar-btn:focus-visible {
  border-color: var(--accent);
  transform: scale(1.05);
}

.account-avatar-btn .avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  padding: 4px;
}

:root[data-theme="light"] .account-avatar-btn .avatar-circle,
html[data-theme="light"] .account-avatar-btn .avatar-circle {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.avatar-picto-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ==========================================================================
   Dropdown Profil Dinia (Google Account Style)
   ========================================================================== */
.account-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 330px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 1.25rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transform-origin: top right;
  animation: accountMenuIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
}

:root[data-theme="dark"] .account-dropdown,
:root:not([data-theme="light"]) .account-dropdown {
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

:root[data-theme="light"] .account-dropdown,
html[data-theme="light"] .account-dropdown {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12), 0 4px 6px rgba(15, 23, 42, 0.04);
}

.account-dropdown.hidden {
  display: none !important;
}

@keyframes accountMenuIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* En-tête Identité Utilisateur */
.account-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

:root[data-theme="dark"] .account-header,
:root:not([data-theme="light"]) .account-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

:root[data-theme="light"] .account-header,
html[data-theme="light"] .account-header {
  border-bottom: 1px solid #e2e8f0;
}

.account-large-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0891b2 0%, #002fa7 100%);
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(8, 145, 178, 0.35);
}

.account-user-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.2;
}

:root[data-theme="light"] .account-user-name,
html[data-theme="light"] .account-user-name {
  color: #0f172a;
}

.account-user-email {
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-all;
}

:root[data-theme="light"] .account-user-email,
html[data-theme="light"] .account-user-email {
  color: #64748b;
}

.account-org-badge {
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
}

:root[data-theme="light"] .account-org-badge,
html[data-theme="light"] .account-org-badge {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #475569;
}

/* Boîte Statut Licence Dinia */
.account-license-box {
  background: rgba(8, 145, 178, 0.08);
  border: 1px solid rgba(8, 145, 178, 0.2);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.account-license-box.active {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
}

:root[data-theme="dark"] .account-license-box.active,
:root:not([data-theme="light"]) .account-license-box.active {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
}

:root[data-theme="light"] .account-license-box.active,
html[data-theme="light"] .account-license-box.active {
  background: #ecfdf5;
  border-color: #a7f3d0;
}

.license-info-left {
  display: flex;
  flex-direction: column;
}

.license-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

:root[data-theme="light"] .license-label,
html[data-theme="light"] .license-label {
  color: #64748b;
}

.license-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

:root[data-theme="light"] .license-name,
html[data-theme="light"] .license-name {
  color: #0f172a;
}

.license-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
}

:root[data-theme="light"] .license-status-badge,
html[data-theme="light"] .license-status-badge {
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

.license-status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* Actions dans le Dropdown */
.account-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn-dinia-manage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-hover);
  color: var(--text-main);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition-fast);
  box-sizing: border-box;
}

:root[data-theme="dark"] .btn-dinia-manage,
:root:not([data-theme="light"]) .btn-dinia-manage {
  background: #1a2235;
  border-color: rgba(255, 255, 255, 0.15);
  color: #f1f5f9;
}

:root[data-theme="dark"] .btn-dinia-manage:hover,
:root:not([data-theme="light"]) .btn-dinia-manage:hover {
  background: rgba(8, 145, 178, 0.25);
  border-color: var(--accent);
  color: #ffffff;
}

:root[data-theme="light"] .btn-dinia-manage,
html[data-theme="light"] .btn-dinia-manage {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #0f172a;
}

:root[data-theme="light"] .btn-dinia-manage:hover,
html[data-theme="light"] .btn-dinia-manage:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #0891b2;
}

.btn-dinia-manage svg,
.btn-dinia-manage i {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: none;
  background: none;
  color: var(--danger);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* ==========================================================================
   Bouton CTA Dinia SSO & Séparateur
   ========================================================================== */
.btn-dinia-sso-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(135deg, #1e3a8a 0%, #1e1b4b 100%);
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(30, 58, 138, 0.35);
  transition: all var(--transition-normal);
}

.btn-dinia-sso-cta:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #2563eb 0%, #1e3a8a 100%);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.45);
}

.btn-dinia-sso-cta:active {
  transform: translateY(0);
}

.sso-or-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin: 0.35rem 0;
}

.sso-or-divider::before,
.sso-or-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border-color);
}

:root[data-theme="light"] .sso-or-divider::before,
:root[data-theme="light"] .sso-or-divider::after,
html[data-theme="light"] .sso-or-divider::before,
html[data-theme="light"] .sso-or-divider::after {
  border-bottom-color: #e2e8f0;
}

.sso-or-divider span {
  padding: 0 0.75rem;
}

/* ==========================================================================
   Menu Gaufre / App Switcher 9 Points (Directives Dinia Suite)
   ========================================================================== */
.app-switcher-container {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.btn-app-switcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-app-switcher:hover,
.btn-app-switcher.active {
  color: var(--text-main);
  background: var(--bg-hover);
  border-color: var(--border-color);
}

:root[data-theme="dark"] .btn-app-switcher,
:root:not([data-theme="light"]) .btn-app-switcher {
  background: var(--janus-surface, #121828);
  border-color: var(--janus-border, #222b42);
  color: #94a3b8;
}

:root[data-theme="dark"] .btn-app-switcher:hover,
:root[data-theme="dark"] .btn-app-switcher.active,
:root:not([data-theme="light"]) .btn-app-switcher:hover,
:root:not([data-theme="light"]) .btn-app-switcher.active {
  background: #1a2235;
  border-color: rgba(255, 255, 255, 0.2);
  color: #f1f5f9;
}

:root[data-theme="light"] .btn-app-switcher,
html[data-theme="light"] .btn-app-switcher {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  color: #475569;
}

:root[data-theme="light"] .btn-app-switcher:hover,
:root[data-theme="light"] .btn-app-switcher.active,
html[data-theme="light"] .btn-app-switcher:hover,
html[data-theme="light"] .btn-app-switcher.active {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #0f172a;
}

.app-switcher-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 380px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 12px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: appSwitcherFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.app-switcher-dropdown.hidden {
  display: none !important;
}

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

:root[data-theme="dark"] .app-switcher-dropdown,
:root:not([data-theme="light"]) .app-switcher-dropdown {
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
}

:root[data-theme="light"] .app-switcher-dropdown,
html[data-theme="light"] .app-switcher-dropdown {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12), 0 4px 6px rgba(15, 23, 42, 0.04);
}

.app-switcher-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 6px 8px 6px;
  border-bottom: 1px solid var(--border-color);
}

:root[data-theme="dark"] .app-switcher-header,
:root:not([data-theme="light"]) .app-switcher-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

:root[data-theme="light"] .app-switcher-header,
html[data-theme="light"] .app-switcher-header {
  border-bottom: 1px solid #e2e8f0;
}

.app-switcher-title {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

:root[data-theme="light"] .app-switcher-title,
html[data-theme="light"] .app-switcher-title {
  color: #0f172a;
}

.app-switcher-subtitle {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
}

:root[data-theme="light"] .app-switcher-subtitle,
html[data-theme="light"] .app-switcher-subtitle {
  color: #64748b;
}

.app-switcher-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding-top: 4px;
}

.app-switcher-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  text-decoration: none;
  transition: all var(--transition-fast);
  background: transparent;
  min-width: 0;
  box-sizing: border-box;
  outline: none;
}

.app-switcher-item:hover,
.app-switcher-item:focus-visible {
  background: var(--bg-hover);
  border-color: var(--border-color);
  transform: translateY(-1px);
}

:root[data-theme="dark"] .app-switcher-item:hover,
:root[data-theme="dark"] .app-switcher-item:focus-visible,
:root:not([data-theme="light"]) .app-switcher-item:hover,
:root:not([data-theme="light"]) .app-switcher-item:focus-visible {
  background: #1a2235;
  border-color: rgba(255, 255, 255, 0.1);
}

:root[data-theme="light"] .app-switcher-item:hover,
:root[data-theme="light"] .app-switcher-item:focus-visible,
html[data-theme="light"] .app-switcher-item:hover,
html[data-theme="light"] .app-switcher-item:focus-visible {
  background: #f8fafc;
  border-color: #e2e8f0;
}

.app-switcher-item.active {
  background: rgba(8, 145, 178, 0.18);
  border-color: rgba(8, 145, 178, 0.4);
}

:root[data-theme="light"] .app-switcher-item.active,
html[data-theme="light"] .app-switcher-item.active {
  background: rgba(8, 145, 178, 0.08);
  border-color: rgba(8, 145, 178, 0.35);
}

.app-switcher-icon-box {
  width: 34px !important;
  height: 34px !important;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-switcher-icon {
  width: 20px !important;
  height: 20px !important;
  max-width: 20px !important;
  max-height: 20px !important;
  object-fit: contain;
  display: block;
}

.app-switcher-item-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  flex: 1;
}

.app-switcher-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.app-switcher-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:root[data-theme="light"] .app-switcher-name,
html[data-theme="light"] .app-switcher-name {
  color: #0f172a;
}

.app-switcher-active-tag {
  font-size: 0.6rem;
  font-weight: 700;
  color: #ffffff;
  background: #0891b2;
  padding: 1px 5px;
  border-radius: 4px;
  text-transform: uppercase;
  line-height: 1;
  flex-shrink: 0;
}

.app-switcher-desc {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:root[data-theme="light"] .app-switcher-desc,
html[data-theme="light"] .app-switcher-desc {
  color: #64748b;
}

.app-switcher-item-hub {
  grid-column: span 2;
  border-top: 1px solid var(--border-color);
  margin-top: 4px;
  padding-top: 10px;
}

:root[data-theme="dark"] .app-switcher-item-hub,
:root:not([data-theme="light"]) .app-switcher-item-hub {
  border-top-color: rgba(255, 255, 255, 0.08);
}

:root[data-theme="light"] .app-switcher-item-hub,
html[data-theme="light"] .app-switcher-item-hub {
  border-top-color: #e2e8f0;
}
