/* Update Banner */
.update-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.85), rgba(139, 92, 246, 0.85));
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.4);
}

.update-banner span {
  flex: 1;
}

.update-banner a {
  color: #fff;
  text-decoration: underline;
  white-space: nowrap;
}

.update-banner-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  opacity: 0.8;
  padding: 0 4px;
}

.update-banner-close:hover {
  opacity: 1;
}

/* Ambient Background */
.ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.15;
}

.ambient-orb:nth-child(1) {
  width: 600px;
  height: 600px;
  background: var(--accent-primary);
  top: -10%;
  left: -5%;
  animation: orbFloat1 20s ease-in-out infinite;
}

.ambient-orb:nth-child(2) {
  width: 500px;
  height: 500px;
  background: var(--accent-secondary);
  bottom: -10%;
  right: -5%;
  animation: orbFloat2 25s ease-in-out infinite;
}

.ambient-orb:nth-child(3) {
  width: 400px;
  height: 400px;
  background: var(--voice-idle);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: orbFloat3 30s ease-in-out infinite;
  opacity: 0.08;
}

/* App Grid */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--right-panel-width);
  grid-template-rows: 1fr var(--dock-height);
  grid-template-areas:
    "sidebar main right"
    "dock    dock dock";
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* Panel Areas */
.sidebar {
  grid-area: sidebar;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition-normal), transform 0.3s ease, opacity 0.3s ease;
  z-index: var(--z-sidebar);
}

.main-canvas {
  grid-area: main;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.right-panel {
  grid-area: right;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width var(--transition-normal), transform 0.3s ease, opacity 0.3s ease;
}

.dock {
  grid-area: dock;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

/* View Panels (for router) */
.view-panel {
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.main-canvas > .view-panel {
  display: none;
}

.main-canvas > .view-panel.active {
  display: flex;
}

/* View panel content defaults */
.knowledge-explorer,
.workspace-panel {
  gap: var(--space-md);
  padding: var(--space-lg);
  overflow-y: auto;
}

/* Sidebar Collapsed State */
#app.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) 1fr var(--right-panel-width);
}

/* Right Panel Collapsed State */
#app.right-panel-collapsed {
  grid-template-columns: var(--sidebar-width) 1fr var(--right-panel-collapsed-width);
}

#app.sidebar-collapsed.right-panel-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) 1fr var(--right-panel-collapsed-width);
}

/* Focus Mode */
#app.focus-mode .sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

#app.focus-mode .right-panel {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}

#app.focus-mode .dock {
  transform: translateY(100%);
  opacity: 0;
}

#app.focus-mode .main-canvas {
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  z-index: 1;
}

/* Focus mode avatar in chat header */
.focus-mode-avatar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
}

#app.focus-mode .focus-mode-avatar {
  display: flex;
}

/* Focus toggle button */
.chat-focus-btn {
  opacity: 0.6;
  transition: opacity var(--transition-fast);
}

.chat-focus-btn:hover {
  opacity: 1;
}

#app.focus-mode .chat-focus-btn {
  opacity: 1;
  color: var(--accent-primary);
}

/* Tablet (<=1200px) */
@media (max-width: 1200px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr var(--dock-height);
    grid-template-areas:
      "main"
      "dock";
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: var(--dock-height);
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    z-index: var(--z-modal);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .right-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: var(--dock-height);
    width: var(--right-panel-width);
    background: var(--bg-secondary);
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    z-index: var(--z-modal);
  }

  .right-panel.open {
    transform: translateX(0);
  }

  /* Overlay backdrop for mobile panels */
  .panel-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-modal) - 1);
  }

  .panel-backdrop.active {
    display: block;
  }
}

/* Mobile (<=768px) */
@media (max-width: 768px) {
  :root {
    --dock-height: 56px;
  }

  .sidebar {
    width: 100%;
  }

  .right-panel {
    width: 100%;
  }

  /* Main canvas needs padding for fixed dock and must allow scroll */
  .main-canvas {
    padding-bottom: var(--dock-height);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* View panels must be able to scroll on mobile */
  .view-panel {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
  }
}
