/* Global Styles */
body {
  margin: 0;
  font-family: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #fafbfc;
  color: #1a202c;
  font-weight: 400;
  letter-spacing: -0.01em;
}

.hidden {
  display: none !important;
}

/* Header */
header {
  background: #333;
  color: #fff;
  padding: 8px 10px;
  text-align: center;
  font-size: 1em;
}

/* Container for Sidebar and Main Content */
.container {
  display: flex;
  flex: 1;
}

/* Sidebar */
.sidebar {
  width: 160px;
  background: #ffffff;
  padding: 16px 12px;
  border-right: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.sidebar h3 {
  margin: 0 0 16px 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.sidebar button, .gate-btn {
  width: 100%;
  margin: 6px 0;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #e2e8f0;
  background-color: #ffffff;
  text-align: center;
  user-select: none;
  border-radius: 6px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  color: #374151;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.sidebar button:hover, .gate-btn:hover {
  background-color: #f8fafc;
  border-color: #cbd5e1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.gate-btn {
  cursor: grab;
  font-family: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-weight: 500;
  background-color: #f8fafc;
  color: #475569;
  border: 1.5px solid #e2e8f0;
  position: relative;
  width: auto;
  min-width: 40px;
  max-width: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.gate-btn.two-qubit-gate {
  border-color: #f472b6;
  color: #be185d;
  max-width: 60px;
  min-width: 50px;
}

.gate-btn.two-qubit-gate:hover {
  background-color: #fef7ff;
  border-color: #ec4899;
  color: #be185d;
}

.gate-btn.parametric-gate {
  border-color: #34d399;
  color: #047857;
  max-width: 60px;
  min-width: 50px;
  position: relative;
}

.gate-btn.parametric-gate:hover {
  background-color: #f0fdf4;
  border-color: #10b981;
  color: #047857;
}

.gate-btn.parametric-gate::after {
  content: 'θ';
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 9px;
  opacity: 0.6;
}

.param-launch-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
}

.param-launch-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.param-pill {
  background-color: #10b981;
  color: #ffffff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.param-pill.hidden {
  display: none;
}

.node.has-parametric-gate {
  stroke: #10b981 !important;
  stroke-width: 2px !important;
}

.angle-tooltip {
  position: absolute;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
}

/* Operation History Visualization */
.operation-list {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(4px);
  pointer-events: all;
  z-index: 100;
}

.operation-list:empty {
  display: none;
}

.operation-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 20px;
  padding: 2px 6px;
  font-family: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
  font-size: 10px;
  font-weight: 500;
  color: #475569;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  cursor: grab;
  transition: all 0.15s ease;
  user-select: none;
  white-space: nowrap;
}

.operation-chip:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
  transform: translateX(2px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.operation-chip:active {
  cursor: grabbing;
}

.operation-chip.dragging {
  opacity: 0.7;
  transform: rotate(2deg) scale(0.98);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
}

/* Different styles for different gate types */
.operation-chip.single-qubit {
  border-color: #cbd5e1;
  color: #475569;
}

.operation-chip.two-qubit {
  border-color: #f472b6;
  color: #be185d;
  background-color: #fef7ff;
}

.operation-chip.parametric {
  border-color: #34d399;
  color: #047857;
  background-color: #f0fdf4;
}

.operation-chip.control {
  border-left: 4px solid #3b82f6;
  position: relative;
}

.operation-chip.control::before {
  content: '● ';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  color: #3b82f6;
  font-size: 8px;
}

.operation-chip.target {
  border-left: 4px solid #ef4444;
  position: relative;
}

.operation-chip.target::before {
  content: '▶ ';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  color: #ef4444;
  font-size: 6px;
}

/* Drop zone styling for operation reordering */
.operation-list.drag-over {
  border-color: #f59e0b;
  background-color: rgba(251, 191, 36, 0.1);
}

.operation-drop-indicator {
  height: 2px;
  background-color: #f59e0b;
  border-radius: 1px;
  margin: 2px 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.operation-drop-indicator.active {
  opacity: 1;
}

/* Per-node toggle button - always visible but subtle */
.node-toggle-btn {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(203, 213, 225, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  color: rgba(107, 114, 128, 0.7);
  z-index: 200;
  pointer-events: all;
  opacity: 0.6;
}

.node-toggle-btn:hover {
  opacity: 1;
  background-color: #f8fafc;
  border-color: #94a3b8;
  color: #6b7280;
}

.node-toggle-btn.operations-visible {
  background-color: rgba(59, 130, 246, 0.9);
  color: #ffffff;
  border-color: rgba(37, 99, 235, 0.8);
  opacity: 0.8;
}

.node-toggle-btn.operations-visible:hover {
  opacity: 1;
  background-color: #3b82f6;
  border-color: #2563eb;
}

/* Operation count badge */
.operation-count-badge {
  position: absolute;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  /* background-color: #ef4444; */
  color: #ef4444;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  pointer-events: none;
}

.operation-count-badge.hidden {
  display: none;
}

/* Hidden operation lists */
.operation-list.hidden {
  display: none;
}

/* Node with hidden operations indicator */
.node.has-hidden-operations {
  stroke: #f59e0b !important;
  stroke-width: 2px !important;
  stroke-dasharray: 3,2;
}

.gate-btn:hover {
  background-color: #f1f5f9;
  border-color: #cbd5e1;
  color: #334155;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.gate-btn:active {
  cursor: grabbing;
  transform: translateY(0px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.gate-btn.dragging {
  opacity: 0.7;
  transform: rotate(3deg) scale(0.98);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.node.drag-over {
  stroke: #f59e0b !important;
  stroke-width: 3px !important;
  filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.4));
}

/* Main Content */
.main {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background-color: #fafbfc;
}

.main h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: #1a202c;
  letter-spacing: -0.01em;
}

/* Panels for Graph and Dot Grid */
.side-by-side {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.panel {
  flex: 1 1 380px;
  padding: 20px;
  border: 1px solid #e2e8f0;
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 0 rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.2s ease;
}

.panel:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.04), 0 2px 0 rgba(0, 0, 0, 0.06);
}

.panel h3 {
  margin: 0 0 16px 0;
  font-size: 15px;
  font-weight: 600;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  font-size: 13px;
}

.import-panel {
  margin-bottom: 16px;
}

.import-panel textarea {
  width: 100%;
  min-height: 150px;
  padding: 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  font-family: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
  font-size: 13px;
  color: #0f172a;
  line-height: 1.5;
  resize: vertical;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}

.import-panel textarea:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.2);
}

.import-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 10px 0;
  flex-wrap: wrap;
}

.import-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.import-toggle input {
  transform: scale(1.1);
}

.readonly-qasm {
  background-color: #f8fafc;
  color: #475569;
}

.import-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.import-helper {
  font-size: 12px;
  color: #6b7280;
}

.import-feedback {
  font-size: 12px;
  font-weight: 600;
  color: #0ea5e9;
}

.import-feedback.error {
  color: #dc2626;
}

.qubit-count-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.qubit-count-row label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
}

.qubit-count-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.qubit-count-controls input {
  width: 80px;
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
}

.secondary-btn {
  padding: 9px 12px;
  background: #f8fafc;
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  transition: all 0.15s ease;
}

.secondary-btn:hover {
  background: #e2e8f0;
  border-color: #cbd5e1;
}

.primary-btn {
  padding: 10px 16px;
  background: linear-gradient(135deg, #0ea5e9, #22d3ee);
  border: 1px solid #7dd3fc;
  color: #ffffff;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(14, 165, 233, 0.25);
  transition: all 0.15s ease;
}

.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(14, 165, 233, 0.3);
}

.primary-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Graph and Dot Grid Containers */
#viz, #dot-grid {
  width: 100%;
  height: 500px;
  border: 1px solid #f1f5f9;
  border-radius: 8px;
  background-color: #fefefe;
  overflow: hidden;
}

.dot-grid-axis-label {
  font-size: 12px;
  color: #64748b;
  font-family: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
  margin-bottom: 4px;
}

/* Kaleidoscope panel */
#kaleidoscope-panel {
  margin-bottom: 20px;
}

.kaleido-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kaleido-tags {
  display: inline-flex;
  gap: 8px;
  align-items: center;
}

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: #0ea5e9;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.pill.light {
  background: #e2e8f0;
  color: #334155;
}

.kaleido-body {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

#kaleido-canvas {
  width: 220px;
  height: 220px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: radial-gradient(circle at 50% 45%, #f8fafc 0%, #e2e8f0 60%, #d9e2ec 100%);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(15, 23, 42, 0.08);
}

.kaleido-readout {
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
}

.kaleido-line {
  display: flex;
  justify-content: space-between;
  font-family: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
  font-size: 13px;
  color: #0f172a;
}

.kaleido-line .label {
  color: #6b7280;
}

.kaleido-controls {
  margin-top: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.kaleido-speed {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #475569;
}

#kaleido-speed-input {
  width: 160px;
}

.kaleido-hint {
  font-size: 12px;
  color: #64748b;
}

/* Circuit and Statevector Containers */
#circuit-container, #statevector-container {
  margin-top: 16px;
  padding: 16px 20px;
  border: 1px solid #e2e8f0;
  background-color: #ffffff;
  border-radius: 8px;
  overflow-x: auto;
  white-space: nowrap;
  font-family: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.6;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.dot-highlight-0 {
  stroke: #22c55e;
  stroke-width: 2px;
}

.dot-highlight-1 {
  stroke: #ef4444;
  stroke-width: 2px;
}

.dot-dim {
  opacity: 0.25;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(15, 23, 42, 0.7);
}

.modal-content {
  background-color: #ffffff;
  margin: 15% auto;
  padding: 20px;
  border: 1px solid #e2e8f0;
  width: 320px;
  border-radius: 8px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.modal-content h3 {
  margin: 0 0 20px 0;
  font-size: 18px;
  font-weight: 600;
  color: #1a202c;
  text-align: center;
}

/* Qubit Button Groups in Modal */
.qubit-group {
  margin: 16px 0;
}

.qubit-group span {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: #4a5568;
  font-size: 14px;
}

.qubit-btn {
  margin: 4px;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  background-color: #ffffff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  transition: all 0.15s ease;
  min-width: 32px;
}

.qubit-btn:hover {
  background-color: #f7fafc;
  border-color: #cbd5e1;
}

.qubit-btn.selected {
  background-color: #3b82f6;
  color: #ffffff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Modal Buttons */
.modal-content button {
  margin: 8px 4px 0 0;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.modal-content button#confirmGate {
  background-color: #10b981;
  color: white;
}

.modal-content button#confirmGate:hover {
  background-color: #059669;
  transform: translateY(-1px);
}

.modal-content button#cancelGate {
  background-color: #e5e7eb;
  color: #374151;
}

.modal-content button#cancelGate:hover {
  background-color: #d1d5db;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: #94a3b8;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  transition: color 0.15s ease;
}

.modal-close-btn:hover {
  color: #334155;
}

.param-modal-content {
  width: 520px;
  max-width: calc(100% - 32px);
  max-height: 80vh;
  overflow: hidden;
  padding: 18px 18px 12px;
  display: flex;
  flex-direction: column;
}

.param-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}

.param-modal-subtitle {
  margin: 4px 0 0;
  color: #64748b;
  font-size: 13px;
}

.param-list {
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.param-row {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 12px;
  background: linear-gradient(145deg, #f8fafc, #ffffff);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.param-row.dirty {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
}

.param-row.focus-pulse {
  animation: focusPulse 0.9s ease;
}

@keyframes focusPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.25);
  }
  100% {
    box-shadow: 0 0 0 14px rgba(59, 130, 246, 0);
  }
}

.param-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.param-name {
  font-weight: 700;
  color: #0f172a;
}

.param-detail {
  font-size: 12px;
  color: #64748b;
}

.param-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.param-control {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.param-control label {
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}

.param-input-row {
  display: grid;
  grid-template-columns: 1fr 96px auto;
  gap: 8px;
  align-items: center;
}

.param-slider {
  width: 100%;
  accent-color: #10b981;
}

.param-number {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d9e2ec;
  border-radius: 8px;
  font-size: 13px;
  color: #0f172a;
}

.param-number:focus {
  outline: 2px solid #bae6fd;
  border-color: #38bdf8;
}

.pi-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  background: #ecfeff;
  color: #0f172a;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.01em;
  min-width: 68px;
}

.param-empty-state {
  padding: 12px;
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  color: #64748b;
  font-size: 13px;
  margin: 6px 0 10px 0;
}

.param-modal-footer {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.param-modal-message {
  font-size: 12px;
  color: #047857;
  min-height: 16px;
}

.param-modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 720px) {
  .param-input-row {
    grid-template-columns: 1fr;
  }
}

/* Specialized Button Styles */
.remove-btn, .clear-btn, .demo-btn, .teleport-btn {
  background-color: #f3f4f6 !important;
  color: #4b5563 !important;
  border: 1px solid #d1d5db !important;
}

.remove-btn:hover, .clear-btn:hover {
  background-color: #ef4444 !important;
  color: #ffffff !important;
  border-color: #dc2626 !important;
}

.demo-btn:hover {
  background-color: #8b5cf6 !important;
  color: #ffffff !important;
  border-color: #7c3aed !important;
}

.teleport-btn:hover {
  background-color: #06b6d4 !important;
  color: #ffffff !important;
  border-color: #0891b2 !important;
}

/* Two-qubit gate visual feedback */
.two-qubit-control {
  stroke: #f472b6 !important;
  stroke-width: 4px !important;
  filter: drop-shadow(0 0 6px rgba(244, 114, 182, 0.6));
}
