/* =============================================================================
   App Sidebar Navigation
   ============================================================================= */

/* --- App shell: sidebar + content side-by-side --- */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- Sidebar --- */
.app-sidebar {
  width: 240px;
  min-width: 240px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f8f9fa;
  border-right: 1px solid #e1dfdd;
  transition: width 0.2s ease, min-width 0.2s ease;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  z-index: 100;
}

.app-sidebar.collapsed {
  width: 56px;
  min-width: 56px;
}

/* --- Logo (top) --- */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  border-bottom: 1px solid #e1dfdd;
  flex-shrink: 0;
  min-height: 56px;
  box-sizing: border-box;
}

.sidebar-logo-icon {
  width: 32px;
  height: 18px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #66D4FF, #a78bfa, #ff6eb4, #a78bfa, #66D4FF);
  background-size: 300% 300%;
  animation: sidebar-logo-gradient 8s ease infinite;
  -webkit-mask-image: url('../img/logo_lad_freigestellt.png');
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-image: url('../img/logo_lad_freigestellt.png');
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
}

@keyframes sidebar-logo-gradient {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.sidebar-logo-note {
  font-size: 0.55rem;
  color: #8a8886;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.7;
}

.app-sidebar.collapsed .sidebar-logo-note {
  display: none;
}


.app-sidebar.collapsed .sidebar-toggle {
  display: none;
}

/* --- Collapse toggle (top-right) --- */
.sidebar-toggle,
.platform-page .sidebar-toggle {
  position: absolute;
  top: 16px;
  right: 10px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none !important;
  border: none !important;
  border-radius: 0;
  box-shadow: none;
  cursor: pointer;
  color: #605e5c;
  z-index: 2;
  padding: 0;
  transition: color 0.15s;
}

.sidebar-toggle:hover,
.platform-page .sidebar-toggle:hover {
  color: #3F8CFF;
  background: none !important;
  border: none !important;
}

.sidebar-toggle svg {
  width: 20px;
  height: 20px;
}

/* --- Navigation (middle, scrollable) --- */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  margin: 1px 8px;
  border-radius: 6px;
  color: #323130;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
}

.sidebar-nav-item:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #3F8CFF;
}

.sidebar-nav-item.active {
  background: rgba(63, 140, 255, 0.1);
  color: #3F8CFF;
}

.sidebar-nav-item .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-nav-item .nav-icon-fai {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: currentColor;
}

/* Inline action button inside a nav item (e.g. "+" for new file) */
.sidebar-nav-action,
.platform-page .sidebar-nav-action {
  margin-left: auto;
  background: none !important;
  border: none !important;
  box-shadow: none;
  color: #8a8886;
  font-size: 1.1rem;
  font-weight: 400;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.sidebar-nav-item:hover .sidebar-nav-action,
.sidebar-nav-item.active .sidebar-nav-action {
  opacity: 0.6;
}

.sidebar-nav-action:hover,
.platform-page .sidebar-nav-action:hover {
  opacity: 1 !important;
  color: #3F8CFF;
  background: none !important;
  border: none !important;
}

.sidebar-nav-item .nav-label {
  overflow: hidden;
  transition: opacity 0.15s ease;
}

.app-sidebar.collapsed .sidebar-nav-item {
  justify-content: center;
  padding: 9px 0;
  margin: 1px 4px;
}

.app-sidebar.collapsed .sidebar-nav-item .nav-label {
  opacity: 0;
  width: 0;
}

.app-sidebar.collapsed .sidebar-nav-action {
  display: none;
}

/* Tooltip on hover when collapsed */
.app-sidebar.collapsed .sidebar-nav-item {
  position: relative;
}

.app-sidebar.collapsed .sidebar-nav-item::after {
  content: attr(data-label);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 8px;
  background: #323130;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 200;
}

.app-sidebar.collapsed .sidebar-nav-item:hover::after {
  opacity: 1;
}

/* Separator */
.sidebar-nav-separator {
  height: 1px;
  background: #e1dfdd;
  margin: 6px 14px;
}

/* --- Submenu (e.g. client list under Chat) --- */
.sidebar-submenu {
  padding: 2px 0 4px 0;
}

.sidebar-submenu-loading,
.sidebar-submenu-empty {
  padding: 4px 14px 4px 24px;
  font-size: 0.75rem;
  color: #8a8886;
}

.sidebar-submenu-empty a {
  color: #3F8CFF;
  text-decoration: none;
}

.sidebar-client-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px 5px 24px;
  font-size: 0.8rem;
  color: #323130;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-radius: 4px;
  margin: 0 8px;
}

.sidebar-client-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sidebar-client-item.selected {
  background: rgba(63, 140, 255, 0.1);
  color: #3F8CFF;
}

.sidebar-client-item.offline {
  opacity: 0.55;
}

.sidebar-client-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #8a8886;
}

.sidebar-client-item.selected .sidebar-client-icon {
  color: #3F8CFF;
}

.sidebar-client-item.virtual {
  border-bottom: 1px solid #e1dfdd;
  margin-bottom: 4px;
  padding-bottom: 7px;
}

.sidebar-client-item .client-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-client-item .client-status-dot.online {
  background: #4caf50;
}

.sidebar-client-item .client-status-dot.offline {
  background: #bdbdbd;
}

.sidebar-client-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-client-item .client-clear-btn {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.7rem;
  padding: 2px 4px;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.platform-page .sidebar-client-item .client-clear-btn {
  background: none !important;
  border: none !important;
  padding: 2px 4px;
  border-radius: 0;
}

.sidebar-client-item:hover .client-clear-btn {
  opacity: 0.6;
}

.sidebar-client-item .client-clear-btn:hover {
  opacity: 1;
}

/* --- File list items (editor submenu) --- */
.sidebar-submenu-header {
  display: flex;
  justify-content: flex-end;
  padding: 0 14px 2px 14px;
}

.sidebar-submenu-add,
.platform-page .sidebar-submenu-add {
  background: none !important;
  border: none !important;
  box-shadow: none;
  color: #605e5c;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s;
}

.sidebar-submenu-add:hover,
.platform-page .sidebar-submenu-add:hover {
  color: #3F8CFF;
  background: none !important;
  border: none !important;
}

.sidebar-file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px 5px 24px;
  font-size: 0.8rem;
  color: #323130;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-radius: 4px;
  margin: 0 8px;
}

.sidebar-file-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sidebar-file-item.selected {
  background: rgba(63, 140, 255, 0.1);
  color: #3F8CFF;
}

.sidebar-file-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #8a8886;
}

.sidebar-file-item.selected .sidebar-file-icon {
  color: #3F8CFF;
}

.sidebar-file-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-file-item .file-item-delete {
  display: inline-flex !important;
  opacity: 0;
  background: none !important;
  border: none !important;
  box-shadow: none;
  cursor: pointer;
  font-size: 0.7rem;
  padding: 2px 4px;
  flex-shrink: 0;
  transition: opacity 0.15s;
  width: auto;
  height: auto;
}

.sidebar-file-item:hover .file-item-delete {
  opacity: 0.6;
}

.sidebar-file-item .file-item-delete:hover {
  opacity: 1;
}

/* --- Keys submenu items (keys page sections) --- */
.sidebar-keys-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px 5px 24px;
  font-size: 0.8rem;
  color: #323130;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-radius: 4px;
  margin: 0 8px;
}

.sidebar-keys-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.sidebar-keys-item.selected {
  background: rgba(63, 140, 255, 0.1);
  color: #3F8CFF;
}

.sidebar-keys-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #8a8886;
}

.sidebar-keys-item.selected .sidebar-keys-icon {
  color: #3F8CFF;
}

.sidebar-keys-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hide submenu when sidebar is collapsed */
.app-sidebar.collapsed .sidebar-submenu {
  display: none;
}

/* --- User info (bottom) --- */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid #e1dfdd;
  flex-shrink: 0;
  min-height: 56px;
  box-sizing: border-box;
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5A9FFF, #3F8CFF);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  font-weight: 600;
  font-size: 0.8rem;
}

.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  transition: opacity 0.15s ease;
}

.sidebar-user-email {
  font-size: 0.8rem;
  font-weight: 600;
  color: #323130;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s;
}

.sidebar-user:hover .sidebar-user-email {
  color: #3F8CFF;
}

.sidebar-logout-btn,
.platform-page .sidebar-logout-btn {
  margin-left: auto;
  background: none !important;
  border: none !important;
  box-shadow: none;
  border-radius: 0;
  cursor: pointer;
  padding: 6px;
  color: #605e5c;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
}

.sidebar-logout-btn:hover,
.platform-page .sidebar-logout-btn:hover {
  color: #c83232;
  background: none !important;
  border: none !important;
}

/* Override global .platform-page button styles for sidebar buttons */
.platform-page .mobile-nav-toggle {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
}

.sidebar-logout-btn svg {
  width: 18px;
  height: 18px;
}

.app-sidebar.collapsed .sidebar-user-info {
  opacity: 0;
  width: 0;
}

.app-sidebar.collapsed .sidebar-logout-btn {
  display: none;
}

.sidebar-copyright {
  display: block;
  text-align: center;
  font-size: 0.6rem;
  color: #a19f9d;
  text-decoration: none;
  padding: 4px 0 8px;
  flex-shrink: 0;
  transition: color 0.15s;
}

.sidebar-copyright:hover {
  color: #3F8CFF;
}

.app-sidebar.collapsed .sidebar-copyright {
  font-size: 0;
  padding: 0;
  overflow: hidden;
}

/* --- Impersonation floating widget (top-right) --- */
.impersonation-widget {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 50;
  display: none; /* shown by JS for admins */
  align-items: center;
  gap: 8px;
}

.impersonation-widget .imp-trigger,
.platform-page .impersonation-widget .imp-trigger {
  background: none !important;
  border: none !important;
  box-shadow: none;
  padding: 4px;
  cursor: pointer;
  color: #8a8886;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.15s;
}

.impersonation-widget .imp-trigger:hover,
.platform-page .impersonation-widget .imp-trigger:hover {
  color: #3F8CFF;
  background: none !important;
  border: none !important;
}

.impersonation-widget .imp-trigger svg {
  width: 20px;
  height: 20px;
}

.impersonation-widget .imp-active-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #3F8CFF;
  white-space: nowrap;
}

.impersonation-widget .imp-exit,
.platform-page .impersonation-widget .imp-exit {
  background: none !important;
  border: none !important;
  box-shadow: none;
  padding: 4px;
  cursor: pointer;
  color: #c83232;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: color 0.15s;
}

.impersonation-widget .imp-exit:hover,
.platform-page .impersonation-widget .imp-exit:hover {
  color: #a02020;
  background: none !important;
  border: none !important;
}

.impersonation-widget .imp-exit svg {
  width: 18px;
  height: 18px;
}

/* Popover for user search */
.imp-popover {
  display: none;
  position: absolute;
  top: 50%;
  right: 100%;
  transform: translateY(-50%);
  margin-right: 6px;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  z-index: 60;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.imp-popover.open {
  display: flex;
}

.imp-popover input {
  width: 200px;
  box-sizing: border-box;
  font-size: 0.85rem;
  padding: 5px 8px;
}

.imp-popover .imp-change-btn,
.platform-page .imp-popover .imp-change-btn {
  background: none !important;
  border: 1px solid #d6d4d2 !important;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 500;
  color: #323130;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s;
}

.imp-popover .imp-change-btn:hover,
.platform-page .imp-popover .imp-change-btn:hover {
  border-color: #3F8CFF !important;
  color: #3F8CFF;
  background: none !important;
}

/* --- Content area --- */
.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
  min-width: 0;
  position: relative;
}

/* --- Mobile hamburger toggle (inside app-content) --- */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 99;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid #d6d4d2;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #323130;
}

/* --- Mobile sidebar overlay --- */
.sidebar-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
}

.sidebar-mobile-overlay.active {
  display: block;
}

/* --- Mobile responsive --- */
@media (max-width: 768px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 1000;
    box-shadow: none;
  }

  .app-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  /* Always show expanded on mobile (not icon-only) */
  .app-sidebar.collapsed.mobile-open {
    width: 240px;
    min-width: 240px;
  }

  .app-sidebar.collapsed.mobile-open .nav-label,
  .app-sidebar.collapsed.mobile-open .sidebar-user-info {
    opacity: 1;
    width: auto;
  }

  .app-sidebar.collapsed.mobile-open .sidebar-nav-item {
    justify-content: flex-start;
    padding: 9px 14px;
    margin: 1px 8px;
  }

  .app-sidebar.collapsed.mobile-open .sidebar-logout-btn {
    display: flex;
  }

  .app-sidebar.collapsed.mobile-open .sidebar-submenu {
    display: block;
  }

  .mobile-nav-toggle {
    display: flex;
  }

  .sidebar-toggle {
    display: none;
  }

  .app-content {
    width: 100%;
  }
}
