/* ==========================================================================
   Kairos — Harmonized Dinia Top-Bar, App Switcher & Account Menu (Iris/Atlas)
   ========================================================================== */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 900;
  width: 100%;
  min-height: 62px;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border-subtle);
}

html.dark .top-bar {
  background: rgba(8, 12, 24, 0.86);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-width: 0;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  flex-shrink: 0;
}

.brand-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
}
.brand-logo.logo-dark { display: none; }
.brand-logo.logo-light { display: block; }
html.dark .brand-logo.logo-dark { display: block; }
html.dark .brand-logo.logo-light { display: none; }

.header-right-section {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

/* Sovereign & Organization & Tokens Badges */
.security-badge,
.tenant-badge,
.tokens-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 34px;
  padding: 0 0.7rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-muted);
}

.security-badge .status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.tenant-badge {
  color: var(--text-main);
}

.tokens-badge {
  cursor: pointer;
  color: var(--color-kairos);
  background: var(--color-kairos-tint);
  border-color: var(--color-kairos-border);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  transition: all var(--transition-fast);
}

.tokens-badge:hover {
  background: rgba(161, 89, 166, 0.2);
  transform: translateY(-1px);
}

.tokens-badge.low-tokens {
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.35);
}

/* Theme Toggle & App Switcher Buttons */
.btn-theme-toggle,
.btn-app-switcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.theme-icon-sun { color: #f59e0b; display: none; }
.theme-icon-moon { color: #64748b; display: inline-block; }
html.dark .theme-icon-sun { display: inline-block; }
html.dark .theme-icon-moon { display: none; }

/* 9-dot App Switcher Dropdown */
.app-switcher-container {
  position: relative;
}

.app-switcher-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 380px;
  max-width: calc(100vw - 24px);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-jira);
  padding: 14px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: dropdownFadeIn 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}

html.dark .app-switcher-dropdown {
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(20px);
  border-color: rgba(255, 255, 255, 0.12);
}

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

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

.app-switcher-title {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-main);
}

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

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

.app-switcher-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all 0.15s ease;
  min-width: 0;
}

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

.app-switcher-item.active {
  background: var(--color-kairos-tint);
  border-color: var(--color-kairos-border);
}

.app-switcher-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-switcher-icon {
  width: 21px;
  height: 21px;
  object-fit: contain;
}

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

.app-switcher-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.app-switcher-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
}

.app-switcher-active-tag {
  font-size: 0.58rem;
  font-weight: 700;
  color: #fff;
  background: var(--color-kairos);
  padding: 2px 5px;
  border-radius: 4px;
  text-transform: uppercase;
}

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

/* Google-style Dinia Account Menu */
.account-menu-container {
  position: relative;
}

.account-avatar-btn {
  background: none;
  border: 2px solid transparent;
  border-radius: 50%;
  padding: 2px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s ease;
}

.account-avatar-btn:hover {
  border-color: var(--color-kairos);
}

.account-avatar-btn .avatar-circle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-kairos) 0%, #002FA7 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(161, 89, 166, 0.3);
}

.account-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 345px;
  max-width: calc(100vw - 24px);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-jira);
  padding: 1.15rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: dropdownFadeIn 0.16s cubic-bezier(0.16, 1, 0.3, 1);
}

html.dark .account-dropdown {
  background: rgba(15, 23, 42, 0.96);
  backdrop-filter: blur(20px);
  border-color: rgba(255, 255, 255, 0.12);
}

.account-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border-subtle);
}

.account-large-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-kairos) 0%, #002FA7 100%);
  color: #fff;
  font-size: 1.35rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.15rem;
}

.account-user-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
}

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

.account-org-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  margin-top: 0.15rem;
}

/* Subscription & License Box */
.account-license-box {
  background: var(--color-kairos-tint);
  border: 1px solid var(--color-kairos-border);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}
.account-license-box.active {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.28);
}
.account-license-box.warning {
  background: rgba(245, 158, 11, 0.09);
  border-color: rgba(245, 158, 11, 0.3);
}

.license-info-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.license-label {
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--text-dim);
}

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

.license-sub-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.license-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.16);
  color: #10b981;
  flex-shrink: 0;
}
.license-status-badge.warning {
  background: rgba(245, 158, 11, 0.18);
  color: #f59e0b;
}
.license-status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* AI Tokens Box in Account Dropdown */
.account-tokens-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.account-tokens-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.account-tokens-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}
.account-tokens-label svg,
.account-tokens-label i {
  color: var(--color-kairos);
}

.account-tokens-value {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-main);
}

.account-tokens-progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--border-subtle);
  overflow: hidden;
}

.account-tokens-progress-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-kairos) 0%, #6366f1 100%);
  transition: width 0.3s ease;
}
.account-tokens-progress-bar.bar-warning {
  background: linear-gradient(90deg, #f59e0b 0%, #ef4444 100%);
}

.account-tokens-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
}

.btn-icon-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-icon-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.account-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.btn-dinia-manage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 0.9rem;
  border-radius: 9px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-dinia-manage:hover {
  border-color: var(--color-kairos);
  color: var(--color-kairos);
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 0.9rem;
  border-radius: 9px;
  border: 1px solid rgba(244, 63, 94, 0.28);
  background: rgba(244, 63, 94, 0.08);
  color: var(--accent-rose);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-logout:hover {
  background: var(--accent-rose);
  color: #fff;
  border-color: var(--accent-rose);
}

@media (max-width: 1060px) {
  .security-badge,
  .tenant-badge {
    display: none !important;
  }
}

@media (max-width: 920px) {
  .top-bar {
    padding: 0 1rem;
  }
}
