/* =============================================================================
   Layout & Structure
   ============================================================================= */

/* Layout */
.app-container {
  display: flex;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 260px;
  /* Layered background: solid surface color first (no transparency), then
   * the brand gradient on top. The gradient echoes the login screen so the
   * app feels continuous from auth to dashboard. */
  background-color: var(--janus-surface);
  background-image: var(--janus-brand-gradient);
  background-repeat: no-repeat;
  border-right: 1px solid var(--janus-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 20;
}

.sidebar-header {
  padding: 16px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--janus-border);
  min-width: 0;
  overflow: hidden;
  transition: background var(--transition);
}

.sidebar-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.logo-img {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  padding: 4px;
  background: rgba(8, 145, 178, 0.12);
  border: 1px solid rgba(8, 145, 178, 0.30);
  box-shadow: 0 2px 8px rgba(8, 145, 178, 0.20);
  transition: transform var(--transition), box-shadow var(--transition);
  flex-shrink: 0;
}

.logo-img:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 14px rgba(8, 145, 178, 0.35);
}

.sidebar-brand-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
}

.sidebar-brand-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  min-width: 0;
}

.logo-text {
  font-size: 14px;
  font-weight: 700;
  /* Theme-aware so the logo stays readable on light backgrounds:
   * dark → near-white gradient, light → deep slate gradient.
   * Uses background-clip: text to render the gradient through the glyphs. */
  background: linear-gradient(135deg, var(--janus-text), var(--janus-muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
  line-height: 1.2;
}

#sidebar-org-plan {
  font-size: 9px;
  padding: 1px 5px;
  flex-shrink: 0;
  font-weight: 700;
}

.logo-sub {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--janus-muted);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  overflow-y: auto;
}

.nav-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--janus-subtle);
  padding: 12px 10px 4px 10px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  color: var(--janus-muted);
  background: transparent;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  width: 100%;
}

.nav-btn:hover {
  background-color: var(--janus-surface-hover);
  color: var(--janus-text);
}

.nav-btn.active {
  background-color: var(--janus-surface-hover);
  color: var(--janus-text);
  border-color: var(--janus-border);
  font-weight: 600;
}

.nav-btn.layer-profile.active {
  border-left: 3px solid var(--janus-profile);
  background: linear-gradient(90deg, var(--janus-profile-bg), transparent);
  color: #F8FAFC;
}

.nav-btn.layer-project.active {
  border-left: 3px solid var(--janus-project);
  background: linear-gradient(90deg, var(--janus-project-bg), transparent);
  color: #F8FAFC;
}

.nav-btn.layer-friendship.active {
  border-left: 3px solid var(--janus-friendship);
  background: linear-gradient(90deg, var(--janus-friendship-bg), transparent);
  color: #F8FAFC;
}

.nav-btn .icon {
  font-size: 16px;
  width: 20px;
  display: flex;
  justify-content: center;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--janus-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--janus-surface);
  border: 1px solid var(--janus-border);
  font-size: 12px;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.sidebar-user-avatar {
  font-size: 15px;
  flex-shrink: 0;
}

.sidebar-user-texts {
  text-align: left;
  line-height: 1.25;
  min-width: 0;
  overflow: hidden;
}

.sidebar-user-name {
  font-weight: 600;
  color: var(--janus-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
}

.sidebar-user-role {
  font-size: 10px;
  color: var(--janus-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: capitalize;
}

.btn-sidebar-logout {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #f87171;
  cursor: pointer;
  padding: 4px 7px;
  font-size: 11px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  transition: all 0.15s ease;
  flex-shrink: 0;
  line-height: 1.2;
}

.btn-sidebar-logout:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
  color: #ef4444;
}

.ollama-status-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background-color: var(--janus-bg);
  border: 1px solid var(--janus-border);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--janus-success);
  box-shadow: 0 0 8px var(--janus-success);
}

.status-dot.offline {
  background-color: var(--janus-danger);
  box-shadow: 0 0 8px var(--janus-danger);
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--janus-bg);
}

/* Topbar Header */
.topbar {
  height: 64px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--janus-border);
  /* Solid surface first, then the brand gradient on top — mirrors the
   * sidebar so the sticky header feels like one continuous chrome with the
   * login screen and the nav rail. */
  background-color: var(--janus-surface);
  background-image: var(--janus-brand-gradient);
  background-repeat: no-repeat;
  flex-shrink: 0;
}

.page-title-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--janus-text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Content Views */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.view-section {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes janusSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.spin-icon {
  display: inline-block;
  animation: janusSpin 0.75s linear infinite !important;
}

@keyframes janusAiPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(167, 118, 228, 0.4);
    border-color: rgba(167, 118, 228, 0.6);
  }
  50% {
    box-shadow: 0 0 16px 2px rgba(167, 118, 228, 0.25);
    border-color: rgba(167, 118, 228, 1);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(167, 118, 228, 0.4);
    border-color: rgba(167, 118, 228, 0.6);
  }
}

@keyframes janusAiGlow {
  0%, 100% { opacity: 0.6; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1.04); }
}

.ai-reasoning-card {
  animation: janusAiPulse 2.4s ease-in-out infinite;
}

.ai-pulse-icon {
  animation: janusAiGlow 1.8s ease-in-out infinite;
  display: inline-block;
}

/* =============================================================================
   Client Portal B2B Mode (role=client)
   ============================================================================= */

body.client-role-active .internal-nav {
  display: none !important;
}

body.client-role-active .client-portal-nav {
  display: flex !important;
  flex-direction: column;
  gap: 4px;
}

body.client-role-active .sidebar-header {
  cursor: default !important;
}

body.client-role-active #sidebar-org-caret,
body.client-role-active #workspace-dropdown-menu {
  display: none !important;
}

body.client-role-active .sidebar-footer .ollama-status-badge,
body.client-role-active .sidebar-footer #btn-pwa-install-sidebar {
  display: none !important;
}

/* Consistent Active & Hover Styling for Client Portal Nav Buttons */
.client-portal-nav .nav-btn.active {
  background-color: var(--janus-surface-hover);
  color: var(--janus-text);
  border-color: var(--janus-border);
  border-left: 3px solid var(--janus-profile, var(--janus-primary));
  background: linear-gradient(90deg, color-mix(in srgb, var(--janus-profile, var(--janus-primary)) 12%, transparent), transparent);
  font-weight: 600;
}