/* Quantum Circuit Studio - Professional Unsquished Layout & Interaction Styles */
:root {
  --bg-primary: #0e1117;
  --bg-secondary: #161922;
  --bg-tertiary: #1f2330;
  --border-color: #2b3145;
  --border-focus: #3b82f6;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-blue: #0f62fe;
  --accent-cyan: #0072c3;
  --accent-purple: #8a3ffc;
  --accent-amber: #f59e0b;
  --accent-green: #10b981;
  --accent-red: #ef4444;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --border-color: #cbd5e1;
  --border-focus: #2563eb;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent-blue: #0050d8;
  --accent-cyan: #0284c7;
  --accent-purple: #7c3aed;
  --accent-amber: #d97706;
  --accent-green: #059669;
  --accent-red: #dc2626;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

/* Chrome Header (46px) */
.app-header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
  gap: 8px;
  white-space: nowrap;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand-logo {
  width: 24px;
  height: 24px;
  background: linear-gradient(135deg, #0f62fe, #8a3ffc);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(15, 98, 254, 0.4);
}

.brand-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--text-main);
}

.circuit-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  width: 130px;
  transition: all 0.15s ease;
}

.circuit-title-input:hover,
.circuit-title-input:focus {
  border-color: var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-main);
}

.badge-aer-live {
  font-size: 10px;
  color: #10b981;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.12);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Header Action Groups */
.header-actions-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-run-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.param-stepper-box {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Buttons */
.btn-icon {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1.2;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: #282e42;
  border-color: #3e4763;
  color: #fff;
}

.btn-tiny {
  padding: 2px 6px;
  font-size: 10px;
}

.btn-primary-run {
  background: linear-gradient(135deg, #0f62fe, #0043ce);
  border: none;
  color: #ffffff;
  padding: 5px 12px;
  border-radius: 5px;
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 2px 8px rgba(15, 98, 254, 0.35);
  transition: all 0.15s ease;
}

.btn-primary-run:hover {
  background: linear-gradient(135deg, #1f6ffc, #0f52de);
  box-shadow: 0 4px 12px rgba(15, 98, 254, 0.5);
  transform: translateY(-1px);
}

/* Secondary Sub-toolbar (36px) */
.sub-toolbar {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 36px;
  gap: 8px;
  font-size: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.toolbar-divider {
  color: var(--border-color);
  margin: 0 2px;
  font-size: 11px;
}

.stepper-group {
  display: inline-flex;
  align-items: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 4px;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.btn-stepper {
  background: transparent;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  font-weight: bold;
  font-size: 12px;
  padding: 0 4px;
  line-height: 1;
}

.btn-stepper:hover {
  color: #38bdf8;
}

.status-badge {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

.badge-success {
  color: #10b981;
  border-color: rgba(16, 185, 129, 0.3);
}

/* Main Studio Workspace Grid */
.workspace-container {
  display: grid;
  grid-template-columns: 210px 1fr 280px;
  height: calc(100vh - 82px);
  overflow: hidden;
  transition: grid-template-columns 0.2s cubic-bezier(0.2, 0, 0.2, 1);
}

.workspace-container.right-collapsed {
  grid-template-columns: 210px 1fr 34px;
}

/* Left Palette */
.palette-container-wrapper {
  overflow: hidden;
  height: 100%;
}

.palette-pane {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 8px 10px;
  height: 100%;
}

.palette-category-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin: 10px 0 4px 0;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.gate-tile {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: #fff;
  border-radius: 6px;
  height: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  touch-action: none;
  font-size: 12px;
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  position: relative;
}

.gate-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  border-color: #ffffff;
}

.gate-tile.selected {
  outline: 2px solid var(--accent-amber);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}

.gate-tile:active,
.gate-tile.dragging {
  cursor: grabbing;
  opacity: 0.6;
}

/* Center Viewport & Canvas */
.center-viewport {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
  height: 100%;
}

.canvas-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: auto;
  position: relative;
  border-bottom: 1px solid var(--border-color);
  min-height: 240px;
}

#circuit-canvas {
  flex: 1;
  width: 100%;
  min-height: 240px;
}

/* Floating drop target highlight indicator on canvas */
.canvas-drop-indicator {
  position: fixed;
  display: none;
  pointer-events: none;
  border: 2px dashed #38bdf8;
  background: rgba(56, 189, 248, 0.22);
  border-radius: 6px;
  z-index: 9999;
  width: 44px;
  height: 42px;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.55);
  transition: left 0.05s ease-out, top 0.05s ease-out;
}

/* Bottom Visualizations Dock */
.bottom-viz-dock {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: height 0.2s cubic-bezier(0.2, 0, 0.2, 1);
}

.dock-normal {
  height: 220px;
}

.dock-minimized {
  height: 36px;
}

.dock-minimized .bottom-viz-content-box {
  display: none !important;
}

.dock-maximized {
  height: 400px;
}

.bottom-dock-header {
  height: 34px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
}

.bottom-tabs-strip {
  height: 34px !important;
  display: flex;
  align-items: center;
}

.dock-tab {
  padding: 4px 10px !important;
  font-size: 11px !important;
  color: var(--text-muted) !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer;
  border-radius: 4px;
}

.dock-tab-active {
  color: #fff !important;
  font-weight: 600 !important;
  background: rgba(15, 98, 254, 0.2) !important;
  border-bottom: 2px solid #0f62fe !important;
}

.dock-size-controls {
  display: flex;
  align-items: center;
  gap: 3px;
}

.btn-dock-tool {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  border-radius: 4px;
  cursor: pointer;
}

.btn-dock-tool:hover {
  background: var(--bg-secondary);
  color: var(--text-main);
  border-color: var(--border-color);
}

.bottom-viz-content-box {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Right Code and Inspector Pane */
.right-pane {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

.pane-collapsed .right-pane-body,
.pane-collapsed .right-tabs-strip {
  display: none !important;
}

.pane-collapsed .right-pane-header-strip {
  justify-content: center;
  padding: 0;
}

.right-pane-header-strip {
  height: 34px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
}

.right-tabs-strip {
  height: 34px !important;
}

.pane-tab {
  padding: 4px 8px !important;
  font-size: 11px !important;
  color: var(--text-muted) !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer;
}

.pane-tab-active {
  color: #fff !important;
  font-weight: 600 !important;
  border-bottom: 2px solid #0f62fe !important;
}

.btn-pane-toggle {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
}

.btn-pane-toggle:hover {
  color: var(--text-main);
}

.right-pane-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.code-textarea {
  width: 100%;
  flex: 1;
  background: #0d1017;
  color: #7dd3fc;
  font-family: "JetBrains Mono", Consolas, "Fira Code", monospace;
  font-size: 11px;
  line-height: 1.45;
  border: none;
  padding: 8px;
  resize: none;
  outline: none;
}

.code-toolbar {
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Floating Drag, Move, and Eager Placed Ghosts (Modeled from Chess board.js) */
.move-ghost,
.drag-ghost {
  position: fixed;
  transform: translate(-50%, -50%);
  z-index: 99999;
  pointer-events: none;
  width: 40px;
  height: 38px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.65), 0 0 0 2px rgba(255, 255, 255, 0.45);
  color: #ffffff;
  font-weight: 700;
  will-change: left, top, transform;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.4));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.placed-eager-ghost {
  position: fixed;
  transform: translate(-50%, -50%);
  z-index: 9998;
  pointer-events: none;
  width: 40px;
  height: 38px;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  color: #ffffff;
  font-weight: 700;
  will-change: left, top, transform;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.placed-eager-ghost .ghost-sym,
.move-ghost .ghost-sym,
.drag-ghost .ghost-sym {
  font-size: 14px;
  line-height: 1;
}

.placed-eager-ghost .ghost-id,
.move-ghost .ghost-id,
.drag-ghost .ghost-id {
  font-size: 8px;
  opacity: 0.85;
}

/* Responsive Breakpoints */
@media (max-width: 1280px) {
  .workspace-container {
    grid-template-columns: 190px 1fr 250px;
  }
  .palette-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 1024px) {
  .workspace-container {
    grid-template-columns: 180px 1fr 34px;
    position: relative;
  }
  .right-pane {
    width: 34px;
    transition: width 0.2s ease, box-shadow 0.2s ease;
  }
  .right-pane.pane-collapsed .right-pane-body {
    display: none !important;
  }
  .right-pane.pane-open {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 300px;
    z-index: 1000;
    box-shadow: -6px 0 20px rgba(0, 0, 0, 0.6);
    background: var(--bg-secondary);
  }
  .right-pane.pane-open .right-pane-body {
    display: flex !important;
  }
}

@media (max-width: 768px) {
  .app-header {
    height: auto;
    min-height: 44px;
    padding: 4px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: thin;
  }
  .secondary-toolbar {
    height: auto;
    min-height: 36px;
    padding: 4px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: thin;
  }
  .header-actions-group,
  .header-run-group {
    flex-shrink: 0;
  }
  .circuit-title-input {
    max-width: 110px;
    font-size: 11px;
  }
  .workspace-container {
    grid-template-columns: 1fr;
    position: relative;
  }
  .palette-container-wrapper {
    max-height: 140px;
  }
  .right-pane.pane-open {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 3px 6px;
    gap: 4px;
  }
  .brand-title {
    display: none;
  }
  .circuit-title-input {
    max-width: 85px;
    font-size: 11px;
    padding: 2px 4px;
  }
  .btn-header {
    padding: 4px 6px;
    font-size: 11px;
  }
  .secondary-toolbar {
    padding: 3px 6px;
    gap: 4px;
  }
  .toolbar-btn {
    padding: 3px 6px;
    font-size: 11px;
  }
}
