:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --line: #d6deea;
  --text: #1c2733;
  --muted: #5f6f82;
  --brand: #2f6feb;
  --danger: #c52f2f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
}

.topbar {
  display: grid;
  gap: 12px;
  padding: 16px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.topbar-note {
  margin: 0;
  text-align: center;
  color: #2a3d55;
  font-size: 0.88rem;
  background: #fff6e5;
  border: 1px solid #f0d7a8;
  padding: 8px 12px;
  border-radius: 10px;
}

.palette-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  min-width: 220px;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}


.content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.panel {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.palette {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.actions-bar {
  display: flex;
  gap: 10px;
  align-items: center;
}

.palette-btn,
.action {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  font-size: 0.9rem;
  cursor: pointer;
}

.palette-btn {
  width: 92px;
  height: 72px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  text-align: center;
}

.palette-title {
  font-size: 0.85rem;
  font-weight: 600;
}

.palette-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.palette-btn:hover,
.action:hover {
  border-color: var(--brand);
}

.palette-btn.active {
  border-color: var(--brand);
  background: #e8f1ff;
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.actions {
  display: grid;
  gap: 8px;
}

.action.danger {
  border-color: #e8b7b7;
  color: var(--danger);
}

.action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.help ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.9rem;
  display: grid;
  gap: 4px;
}

.workspace {
  flex: 1;
  width: 100%;
  min-height: 0;
  padding: 28px;
  overflow: auto;
}

.workspace-row {
  position: relative;
  display: inline-block;
  width: fit-content;
}

.board-shell {
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #eef2f8;
  padding: 20px;
  position: relative;
}

.board {
  position: relative;
  width: 980px;
  height: 520px;
  border: 1px solid #c9d3e3;
  border-radius: 10px;
  background: linear-gradient(to bottom, #ffffff 0%, #f8fbff 100%);
  overflow: hidden;
}

.resize-handle {
  position: absolute;
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  opacity: 0.85;
  z-index: 5;
}

.resize-right {
  width: 14px;
  height: 60px;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.resize-bottom {
  width: 60px;
  height: 14px;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.resize-corner {
  width: 18px;
  height: 18px;
  right: 6px;
  bottom: 6px;
  cursor: se-resize;
}

.holes-layer,
.components-layer {
  position: absolute;
  inset: 0;
}

.hole {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #95a4bb;
  transform: translate(-50%, -50%);
}

.power-rail-bg {
  position: absolute;
  height: 18px;
  border-radius: 6px;
  pointer-events: none;
  background: transparent;
  border: 2px solid;
}

.power-rail-bg.positive {
  border-color: #ff4444;
}

.power-rail-bg.negative {
  border-color: #333333;
}

.component {
  position: absolute;
  border-radius: 8px;
  border: 1px solid #6e7f95;
  cursor: grab;
  user-select: none;
}

.component:active {
  cursor: grabbing;
}

.component.preview {
  opacity: 0.55;
  pointer-events: none;
  cursor: crosshair;
}

.component.selected {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.component .terminal {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f8fbff;
  border: 1px solid #2a3d55;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.component-label {
  position: absolute;
  left: 50%;
  top: -6px;
  transform: translate(-50%, -100%);
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.85);
  color: #ffffff;
  pointer-events: none;
  white-space: nowrap;
}

.component.resistor {
  width: 48px;
  height: 26px;
  background: #e9c593;
  position: relative;
  overflow: visible;
}

.component.resistor .resistor-stripes {
  position: absolute;
  inset: 3px 4px;
  display: flex;
  gap: 3px;
  justify-content: space-between;
  align-items: stretch;
  pointer-events: none;
}

.component.resistor .resistor-stripe {
  flex: 0 0 auto;
  width: 5px;
  height: 100%;
  border-radius: 2px;
  opacity: 0.9;
}

.component.led {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #d83c3c;
}

.component.capacitor {
  width: 48px;
  height: 26px;
  /* border-radius: 6px;
  background: #a7c7e7;
  border-color: #7aa7d1; 
  */
  background-image: url('img/capacitor_ceramico.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border: none;
}

.component.electrolytic {
  width: 48px;
  height: 32px;
  /* border-radius: 6px;
  background: #5aa179;
  border-color: #3e7a58; */

  background-image: url('img/capacitor_eletrolitico.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border: none;
}

.component.diode {
  width: 48px;
  height: 24px;
  border-radius: 6px;
  /* background: #c97b63;
  border-color: #a45a44; */
  position: relative;
  background-image: url('img/diodo.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  border: none;
}

/* 
era a faixa que aparecia no diodo quando ele era desenhao via css
.component.diode::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  right: 8px;
  border-radius: 0;
  background: #3b2c25;
  opacity: 0.85;
} */

.component.button {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #7a7a7a;
  border-color: #5a5a5a;
}

.component.trimpot {
  width: 48px;
  height: 26px;
  border-radius: 6px;
  background: #b08b53;
  border-color: #8b6a3d;
}

.component.crystal {
  width: 48px;
  height: 20px;
  border-radius: 6px;
  background: #b6b8c3;
  border-color: #8e91a0;
}

.component.sensor {
  width: 48px;
  height: 26px;
  border-radius: 8px 8px 5px 5px;
  background: #2f5b8a;
  border-color: #244768;
}

.component.ic {
  min-width: 26px;
  min-height: 26px;
  border-radius: 6px;
  background: #2a3140;
  border-color: #202633;
}

.component.sip {
  width: 120px;
  height: 26px;
  border-radius: 6px;
  background: #4b5563;
  border-color: #3f4754;
}

.component.to92 {
  width: 48px;
  height: 26px;
  border-radius: 8px 8px 5px 5px;
  background: #2f333a;
  border-color: #252a31;
}

.component.to126 {
  width: 48px;
  height: 40px;
  border-radius: 7px;
  background: #3b414d;
  border-color: #2f3540;
}

.component.jumper {
  height: 8px;
  background: #3ea05e;
  border-radius: 999px;
  border: 1px solid #111111;
  transform-origin: center;
}

.component.jumper.preview {
  opacity: 0.6;
  pointer-events: none;
}

.settings-toggle {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.settings-toggle:hover {
  border-color: var(--brand);
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 320px;
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 16px;
  transform: translateX(100%);
  transition: transform 180ms ease;
  z-index: 30;
}

.settings-drawer.open {
  transform: translateX(0);
}

.components-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 0;
  width: 260px;
  background: var(--panel);
  border-left: 0;
  padding: 16px;
  transform: translateX(100%);
  transition: transform 180ms ease, opacity 180ms ease;
  z-index: 20;
  box-shadow: none;
  opacity: 0;
  pointer-events: none;
}

.components-drawer.open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 24px rgba(0, 0, 0, 0.08);
}

.components-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.components-header h2 {
  margin: 0;
  font-size: 1rem;
}

.components-close {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.components-list {
  display: grid;
  gap: 8px;
  max-height: calc(100% - 52px);
  overflow: auto;
  padding-right: 6px;
}

.components-item {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 2px;
}

.components-item.is-selected {
  border-color: var(--brand);
  background: rgba(47, 111, 235, 0.12);
}

.components-item-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.components-item-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.components-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 25;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.jumper-drawer {
  position: fixed;
  left: 0;
  top: 0;
  transform: none;
  width: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  border-radius: 12px;
  background: var(--panel);
  transition: width 180ms ease, opacity 180ms ease;
  z-index: 15;
}

.jumper-drawer.open {
  width: 68px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  opacity: 1;
  pointer-events: auto;
}

.jumper-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.jumper-header h2 {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.jumper-section {
  display: grid;
  gap: 8px;
}

.led-drawer {
  position: fixed;
  left: 0;
  top: 0;
  transform: none;
  width: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  border-radius: 12px;
  background: var(--panel);
  transition: width 180ms ease, opacity 180ms ease;
  z-index: 15;
}

.led-drawer.open {
  width: 68px;
  padding: 10px 8px;
  border: 1px solid var(--line);
  opacity: 1;
  pointer-events: auto;
}

.led-header {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.led-header h2 {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.led-section {
  display: grid;
  gap: 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2a3d55;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 50;
  pointer-events: none;
  max-width: 80vw;
  text-align: center;
  white-space: pre-line;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.settings-header h2 {
  margin: 0;
  font-size: 1rem;
}

.settings-close {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.settings-section {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.settings-section label {
  font-size: 0.9rem;
}

.settings-section input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.settings-warning {
  margin: 8px 0 0;
  color: #d32f2f;
  font-size: 0.85rem;
  min-height: 18px;
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.modal.open {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 20, 0.4);
}

.modal-content {
  position: relative;
  width: min(420px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  z-index: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
}

.modal-close {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.stripe-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  display: none;
  gap: 8px;
}

.stripe-section.is-active {
  display: grid;
}

.stripe-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.stripe-actions {
  display: flex;
  gap: 6px;
}

.stripe-list {
  display: grid;
  gap: 6px;
}

.stripe-row {
  display: grid;
  grid-template-columns: 1fr 24px;
  align-items: center;
  gap: 8px;
}

.stripe-select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.85rem;
  background: #fff;
}

.stripe-preview {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.modal-body input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

.modal-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 18px;
}

.modal-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.color-picker {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.color-option {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 0.85rem;
  background: #fff;
  text-align: left;
}

.color-option--picker {
  justify-content: flex-start;
}

.color-option.is-selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(47, 111, 235, 0.12);
}

.color-option--custom {
  position: relative;
  background: #f4f6fa;
  border: 1px solid var(--line);
}

.color-option--custom::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 8px;
  padding: 2px;
  background: conic-gradient(
    #ff3b3b,
    #ff9f0a,
    #ffd60a,
    #34c759,
    #0a84ff,
    #5e5ce6,
    #ff2d55,
    #ff3b3b
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid #c9d3e3;
}

.jumper-drawer .color-grid {
  grid-template-columns: 1fr;
  gap: 8px;
}

.jumper-drawer .color-option {
  justify-content: center;
  padding: 8px 6px;
}

.jumper-drawer .color-option--custom {
  margin-top: 12px;
}

.jumper-drawer .color-label {
  display: none;
}

.jumper-drawer .color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 8px;
}

.jumper-drawer .color-picker {
  width: 24px;
  height: 24px;
  border-radius: 8px;
}

.led-drawer .color-grid {
  grid-template-columns: 1fr;
  gap: 8px;
}

.led-drawer .color-option {
  justify-content: center;
  padding: 8px 6px;
}

.led-drawer .color-option--custom {
  margin-top: 12px;
}

.led-drawer .color-label {
  display: none;
}

.led-drawer .color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 8px;
}

.led-drawer .color-picker {
  width: 24px;
  height: 24px;
  border-radius: 8px;
}

@media (max-width: 1200px) {
  .content {
    grid-template-columns: 260px 1fr;
  }

  .board {
    width: 860px;
    height: 500px;
  }
}

/* Mobile Warning */
.mobile-warning {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.mobile-warning-content {
  background: var(--panel);
  border-radius: 12px;
  padding: 32px 24px;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.mobile-warning-content h2 {
  margin: 0 0 16px 0;
  color: var(--brand);
  font-size: 1.5rem;
}

.mobile-warning-content p {
  margin: 0 0 12px 0;
  color: var(--muted);
  line-height: 1.6;
}

.mobile-warning-content p:last-of-type {
  margin-bottom: 24px;
}

.mobile-warning-content .action {
  width: 100%;
  padding: 12px 24px;
  font-size: 1rem;
}
