/* 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);
  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);
}

.dock {
  grid-area: dock;
}

/* 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 */
[data-focus] #app {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "main";
}

[data-focus] .sidebar,
[data-focus] .right-panel,
[data-focus] .dock {
  display: none;
}

/* 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;
  }
}
