/**
 * UI Components, Forms, Modals & Catalog Styles
 */

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background-color: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover {
  background-color: var(--bg-surface-hover);
  border-color: var(--text-dim);
}

.btn:active {
  background-color: var(--bg-surface-active);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary-hover);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--accent-primary-hover);
  box-shadow: 0 0 12px var(--accent-primary-glow);
}

.btn-danger {
  background-color: var(--accent-danger);
  border-color: var(--accent-danger-hover);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: var(--accent-danger-hover);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
}

.btn-icon-sm {
  width: 24px;
  height: 24px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.btn-icon-sm:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.btn-group {
  display: flex;
  gap: 2px;
}

.btn-group .btn {
  flex: 1;
}

.btn.active {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

/* Tool Buttons in Floating Toolbar */
.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

.tool-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
}

/* ==================== COMPONENT CATALOG ==================== */
/* Unified Top Action Bar for Left Panel */
.sidebar-top-actions {
  padding: 8px 10px;
  background: var(--bg-surface-alt, #f8fafc);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 5px;
}

.btn-action-top {
  padding: 6px 4px;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.btn-admin {
  background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);
  color: #ffffff;
  border: none;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-admin:hover {
  opacity: 0.9;
}

.catalog-section {
  margin-bottom: 16px;
}

.catalog-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  padding-left: 2px;
}

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

/* Enlarge buttons for geometric shapes (Item 3 & 4) */
.shape-catalog-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.shape-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  min-height: 64px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  box-sizing: border-box;
  width: 100%;
  overflow: hidden;
}

.shape-item:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.shape-item.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
}

.shape-item.active .shape-item-name,
.shape-item.active .shape-item-sub,
.shape-item.active .shape-item-icon {
  color: #ffffff;
}

.shape-item.active .shape-item-icon svg {
  stroke: #ffffff;
}

.shape-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  line-height: 1;
  color: var(--text-main);
}

.shape-item-icon svg {
  display: block;
}

.shape-item-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
}

.shape-item-sub {
  font-size: 9.5px;
  color: var(--text-muted);
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
}

/* Fixed component items so labels never spill out */
.component-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  min-height: 64px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: center;
  overflow: hidden;
}

.component-item:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.component-item-icon {
  font-size: 17px;
  line-height: 1;
}

.component-item-name {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-main);
  white-space: normal;
  line-height: 1.25;
  text-align: center;
  word-break: break-word;
  max-width: 100%;
}

.component-item-sub {
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1.1;
}

/* Wire Color Palette in Toolbar / Breadboard */
.color-palette-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.color-palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 4px;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.active {
  border-color: #ffffff;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

/* ==================== INSPECTOR & FORMS ==================== */
.inspector-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  border-bottom: 1px solid var(--border-default);
  padding-bottom: 6px;
  margin-bottom: 4px;
}

.prop-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.prop-row label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.prop-badge {
  font-size: 10.5px;
  padding: 3px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--accent-primary);
  font-weight: 600;
}

.form-input, .form-select {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent-primary);
}

.coord-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.coord-inputs span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
}

.num-input {
  width: 72px;
}

.slider-val-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-val-wrap input[type="range"] {
  flex: 1;
  accent-color: var(--accent-primary);
}

.slider-val-wrap span {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  min-width: 40px;
}

.color-picker-input {
  width: 36px;
  height: 28px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
}

/* Empty State */
.empty-inspector {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 8px;
  color: var(--text-dim);
}

.empty-icon {
  font-size: 32px;
  margin-bottom: 10px;
  opacity: 0.5;
}

.empty-inspector h4 {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.empty-inspector p {
  font-size: 11.5px;
  line-height: 1.45;
  margin-bottom: 14px;
}

.stats-card {
  display: flex;
  gap: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}

.stat-item {
  font-size: 10.5px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  font-family: var(--font-mono);
}

/* ==================== ELEMENTS LIST HIERARCHY ==================== */
.elements-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}

.elements-search-wrap {
  flex: 1;
}

.elements-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
  max-height: calc(100vh - 160px);
}

.elements-group {
  margin-bottom: 6px;
}

.elements-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  cursor: pointer;
  user-select: none;
  margin-bottom: 3px;
  transition: background-color 0.12s ease;
}

.elements-group-header:hover {
  background: var(--bg-surface-hover);
}

.group-arrow {
  font-size: 9px;
  color: var(--text-dim);
  width: 10px;
}

.group-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  flex: 1;
}

.group-count {
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
}

.element-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.12s ease;
}

.element-row:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-default);
}

.element-row.selected {
  background: rgba(59, 130, 246, 0.15);
  border-color: var(--accent-primary);
}

.element-icon {
  font-size: 13px;
}

.element-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.element-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.element-sub {
  font-size: 9.5px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.element-row-actions {
  display: flex;
  align-items: center;
}

/* Waypoint draggable handles */
.wire-waypoint-handle {
  cursor: crosshair;
  pointer-events: all;
  transition: fill 0.15s ease, stroke-width 0.15s ease;
}

.wire-waypoint-handle:hover {
  fill: #1d4ed8;
  stroke: #ffffff;
  stroke-width: 2.2;
}

/* ==================== MODALS ==================== */
.modal-overlay,
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.active,
.modal-backdrop.active {
  display: flex !important;
}

.modal-dialog {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalEnter 0.2s ease-out;
}

@keyframes modalEnter {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg-surface);
}

.export-preview-box {
  background: #1e293b;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
}

.preview-dims-label {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--accent-primary);
  text-align: center;
  margin-top: 4px;
}

.presets-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preset-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px;
  transition: all 0.15s ease;
}

.preset-card:hover {
  border-color: var(--accent-primary);
}

.preset-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.preset-header h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.preset-badge {
  font-size: 9.5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
  font-weight: 600;
}

.preset-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 10px;
}

.preset-actions {
  display: flex;
  justify-content: flex-end;
}

.ml-2 { margin-left: 8px; }
.mt-3 { margin-top: 12px; }

/* Breadboard Hardware Placement & Selection Styles */
.component-item.bb-place-board {
  border-style: dashed;
  background: rgba(59, 130, 246, 0.05);
}

.component-item.bb-place-board:hover {
  border-style: solid;
  background: rgba(59, 130, 246, 0.12);
}

.bb-board-instance {
  cursor: move;
}

.bb-board-instance.selected > rect:nth-child(2) {
  stroke: #3b82f6 !important;
  stroke-width: 2.5px !important;
}

.bb-component {
  cursor: pointer;
}

.bb-component.selected {
  filter: drop-shadow(0 0 6px rgba(59, 130, 246, 0.8));
}

/* ==================== CIRCUIT CONVERTER & TRANSPILER STYLES ==================== */
.btn-convert {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(16, 185, 129, 0.12));
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: var(--text-main);
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-convert:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(16, 185, 129, 0.22));
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.25);
  transform: translateY(-1px);
}

.conversion-quick-card {
  margin: 8px 12px 14px 12px;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.04), rgba(59, 130, 246, 0.08));
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: var(--radius-md, 8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.conversion-quick-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.conversion-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(16, 185, 129, 0.15);
  color: #059669;
}

.conversion-sub {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

.btn-convert-full {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid rgba(59, 130, 246, 0.4);
  background: linear-gradient(135deg, #2563eb, #0d9488);
  color: #ffffff;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.btn-convert-full:hover {
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  transform: translateY(-1px);
}

.btn-convert-full:active {
  transform: translateY(0);
}

/* ==================== TOAST NOTIFICATIONS ==================== */
#app-toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10000;
  pointer-events: none;
}

.app-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid #334155;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  font-size: 12.5px;
  font-weight: 500;
  animation: toastFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: all 0.25s ease;
}

.app-toast.toast-success {
  border-left: 4px solid #10b981;
}

.app-toast.toast-info {
  border-left: 4px solid #3b82f6;
}

.app-toast.toast-error {
  border-left: 4px solid #ef4444;
}

.app-toast.toast-exit {
  opacity: 0;
  transform: translateY(8px);
}

@keyframes toastFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Admin Modal Styles */
.admin-nav-bar {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-default);
  padding: 8px 16px;
  background: var(--bg-surface-alt, #f8fafc);
}

.admin-nav-tab {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-muted);
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.admin-nav-tab:hover {
  background: var(--bg-surface-hover);
  color: var(--text-main);
}

.admin-nav-tab.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

.admin-tab-pane {
  display: none;
}

.admin-tab-pane.active {
  display: block;
}

.pin-edit-row td {
  padding: 3px 4px;
}

/* Toolbar Nudge Group (Item 0) */
.toolbar-nudge-group {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
}

.nudge-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-right: 2px;
}

.btn-nudge {
  padding: 3px 6px;
  font-size: 11px;
  line-height: 1;
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-default);
  border-radius: 3px;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.1s ease;
}

.btn-nudge:hover {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

/* Floating On-Canvas D-pad Arrow Widget (Item 0) */
.canvas-floating-arrows {
  position: absolute;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  user-select: none;
}

.arrow-pad-middle {
  display: flex;
  align-items: center;
  gap: 2px;
}

.arrow-pad-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: #f8fafc;
  cursor: pointer;
  transition: all 0.12s ease;
}

.arrow-pad-btn:hover {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
  transform: scale(1.08);
}

.arrow-pad-btn.arrow-center {
  font-size: 9px;
  font-weight: 700;
  cursor: default;
  background: transparent;
  border: none;
  color: var(--text-muted);
}

