/* QUANTUM LABS — Layout (IDE-style grid) */

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--results-width);
  grid-template-rows: var(--toolbar-height) 1fr;
  width: 100vw;
  height: 100vh;
  grid-template-areas:
    "toolbar toolbar toolbar"
    "sidebar canvas results";
  overflow: hidden;
}

/* Cb Controls Wrapper */
.cb-controls-wrapper {
  display: contents;
}

/* Toolbar */
.toolbar {
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0 var(--sp-4);
  background: var(--carbon);
  grid-area: toolbar;
  border-bottom: 1px solid var(--wire);
  height: var(--toolbar-height);
  flex-shrink: 0;
}

/* Toolbar Left */
.toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}

/* Toolbar Center */
.toolbar-center {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* Toolbar Right */
.toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* Toolbar Divider */
.toolbar-divider {
  width: 1px;
  height: 20px;
  margin: 0 var(--sp-1);
  background: var(--wire);
}

/* Form Inputs (Toolbar) */
.toolbar-select,
.toolbar-input {
  height: 30px;
  padding: 0 var(--sp-2);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--bone);
  background: var(--carbon);
  border: 1px solid var(--wire);
  border-radius: var(--radius-sm);
  transition: all var(--duration-fast) var(--ease-out);
  outline: none;
}

/* Toolbar Select */
.toolbar-select:hover,
.toolbar-input:hover,
.toolbar-select:focus,
.toolbar-input:focus {
  background: var(--graphite);
  border-color: var(--ember-40);
}
.toolbar-select {
  padding-right: 24px;
  cursor: pointer;
  appearance: none;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%2394A3B8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6 6-6"/></svg>');
  background-repeat: no-repeat;
  background-position: right 8px center;
}
[data-theme="light"] .toolbar-select,
[data-theme="light"] .toolbar-input {
  color: var(--bone);
  background: var(--carbon);
  border-color: var(--wire);
}
[data-theme="light"] .toolbar-select:hover,
[data-theme="light"] .toolbar-input:hover,
[data-theme="light"] .toolbar-select:focus,
[data-theme="light"] .toolbar-input:focus {
  border-color: var(--ember);
}

/* Sidebar (Gate Palette) */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--carbon);
  grid-area: sidebar;
  border-right: 1px solid var(--wire);
  overflow-y: auto;
  min-height: 0;
}

/* Circuit Canvas Area */
.canvas-area {
  position: relative;
  display: block;
  /* Switched to block so children stretch naturally */
  background: var(--obsidian);
  grid-area: canvas;
  overflow: auto;
}

/* Results Panel */
.results-panel {
  display: flex;
  flex-direction: column;
  background: var(--carbon);
  grid-area: results;
  border-left: 1px solid var(--wire);
  overflow: hidden;
}

/* Responsive: collapse results panel on small screens */

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--toolbar-height) 1fr 1fr;
    grid-template-areas:
      "toolbar toolbar"
      "sidebar canvas"
      "sidebar results";
  }

  /* Results Panel */
  .results-panel {
    border-left: none;
    border-top: 1px solid var(--wire);
  }
}

@media (max-width: 768px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow-y: auto;
  }

  /* Canvas Area */
  .canvas-area {
    min-height: 60vh;
    flex-shrink: 0;
  }

  /* Results Panel */
  .results-panel {
    min-height: 60vh;
    padding-bottom: 80px;
    /* space for FAB */
    flex-shrink: 0;
    border-left: none;
    border-top: 1px solid var(--wire);
  }

  /* Cb Controls Wrapper */
  .cb-controls-wrapper {
    position: fixed;
    /* Fixed instead of absolute */
    bottom: 0;
    left: 0;
    z-index: var(--z-modal);
    /* Ensure above scrolling content */
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 75%;
    max-height: 550px;
    background: var(--carbon);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-bottom-sheet);
    transform: translateY(100%);
    transition: transform 0.35s var(--ease-out);
    border-top: 1px solid var(--wire);
  }

  /* Cb Controls Wrapper */
  .cb-controls-wrapper.show {
    transform: translateY(0);
  }

  /* Toolbar */
  .toolbar {
    justify-content: flex-start;
    /* Pack to left */
    gap: var(--sp-2);
    height: auto;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow: visible;
    z-index: 10;
  }

  .toolbar-center::-webkit-scrollbar {
    display: none;
    /* Hide scrollbar for a cleaner look */
  }

  /* Toolbar Divider */
  .toolbar-divider {
    display: none;
  }

  /* Toolbar Center */
  .toolbar-center {
    justify-content: flex-start;
    /* Reset from space-between */
    width: auto;
    /* Reset from 100% */
    flex-wrap: nowrap;
    overflow-x: auto;
    flex: 1;
    min-width: 0;
  }

  .toolbar-center > * {
    flex-shrink: 0;
  }

  /* Toolbar Right */
  .toolbar-right {
    flex-wrap: nowrap;
  }

  /* Sidebar */
  .sidebar {
    flex: 1;
    overflow-y: auto;
  }

}