/* ==========================================================================
   ASA MADAR ELECTRONIC - Interactive Gerber & Multi-Layer PCB Viewer Styles
   ========================================================================== */

#gerber-viewer-modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, 0.90) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 99999 !important;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.2rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

#gerber-viewer-modal.active,
#gerber-viewer-modal[style*="display: flex"] {
  display: flex !important;
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

.gerber-modal-dialog {
  width: 94vw;
  max-width: 1260px;
  height: 88vh;
  max-height: 840px;
  background: #080c14;
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius-lg, 16px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(16, 185, 129, 0.12);
  color: #e2e8f0;
}

.gerber-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: rgba(15, 23, 42, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}

.gerber-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.gerber-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.gerber-badge {
  font-size: 0.74rem;
  background: rgba(16, 185, 129, 0.18);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
}

.gerber-body-layout {
  display: grid;
  grid-template-columns: 330px 1fr;
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* Sidebar: Layer Manager & DFM Rules */
.gerber-sidebar {
  background: #0b101a;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.gerber-sidebar::-webkit-scrollbar {
  width: 5px;
}
.gerber-sidebar::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.6);
}
.gerber-sidebar::-webkit-scrollbar-thumb {
  background: rgba(16, 185, 129, 0.3);
  border-radius: 4px;
}

.g-section-title {
  font-size: 0.84rem;
  font-weight: 800;
  color: #10b981;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.layer-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.layer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 11px;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  transition: all 0.2s ease;
  cursor: pointer;
  user-select: none;
}

.layer-item:hover {
  background: rgba(30, 41, 59, 0.85);
  border-color: rgba(16, 185, 129, 0.35);
}

.layer-item.active {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.45);
}

.layer-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.80rem;
}

.layer-info input[type="checkbox"] {
  cursor: pointer;
  width: 15px;
  height: 15px;
  accent-color: #10b981;
}

.layer-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
}

.layer-name {
  font-weight: 700;
  color: #f1f5f9;
  font-size: 0.80rem;
}

.layer-ext {
  font-size: 0.69rem;
  color: #64748b;
  font-family: monospace;
}

.layer-status-pill {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  color: #94a3b8;
  font-weight: 600;
}

.layer-status-pill.detected {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  font-weight: 700;
}

/* Color Presets Picker */
.color-presets-wrap {
  display: flex;
  gap: 8px;
  margin-top: 5px;
}

.color-chip {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.color-chip:hover {
  transform: scale(1.15);
  border-color: rgba(255, 255, 255, 0.6);
}

.color-chip.selected {
  border-color: #fff;
  transform: scale(1.12);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
}

/* DFM Technical Specs Box */
.dfm-stats-box {
  background: rgba(15, 23, 42, 0.65);
  border: 1px dashed rgba(56, 189, 248, 0.25);
  border-radius: 8px;
  padding: 11px 13px;
  font-size: 0.77rem;
  color: #94a3b8;
  line-height: 1.6;
}

.dfm-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.dfm-row strong {
  color: #e2e8f0;
}

/* Canvas Viewport */
.gerber-canvas-viewport {
  position: relative;
  background-color: #070b14;
  background-image: 
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(16, 185, 129, 0.06) 0%, transparent 75%);
  background-size: 24px 24px, 24px 24px, 100% 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.gerber-canvas-viewport:active {
  cursor: grabbing;
}

#gerber-main-canvas {
  display: block;
  box-shadow: 0 12px 45px rgba(0, 0, 0, 0.85);
  border-radius: 6px;
  image-rendering: auto;
}

/* Floating Toolbar */
.gerber-canvas-controls {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  padding: 6px 14px;
  border-radius: 30px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6);
  z-index: 10;
}

.ctrl-btn {
  background: transparent;
  border: none;
  color: #cbd5e1;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.zoom-level-text {
  font-size: 0.8rem;
  font-family: monospace;
  color: #10b981;
  padding: 0 6px;
  user-select: none;
  font-weight: 700;
}

.ctrl-separator {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.15);
}

/* Loading Overlay */
.gerber-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 20, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  gap: 12px;
}

.g-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(16, 185, 129, 0.2);
  border-top-color: #10b981;
  border-radius: 50%;
  animation: gSpin 0.8s linear infinite;
}

@keyframes gSpin {
  to { transform: rotate(360deg); }
}

/* Responsive Tablet & Mobile Layout: Canvas top (compact), Options below (full visibility) */
@media (max-width: 900px) {
  .gerber-modal-dialog {
    width: 96vw;
    height: 92vh;
    max-height: 92vh;
  }
  .gerber-body-layout {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .gerber-canvas-viewport {
    height: 250px;
    min-height: 200px;
    max-height: 270px;
    flex-shrink: 0;
    order: 1;
  }
  .gerber-sidebar {
    flex: 1;
    min-height: 0;
    max-height: none !important;
    overflow-y: auto;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 13px 15px;
    order: 2;
    gap: 12px;
  }
  .layer-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 6px;
  }
  .layer-item {
    padding: 8px 10px;
  }
  .gerber-canvas-controls {
    bottom: 10px;
    padding: 4px 10px;
    transform: translateX(-50%) scale(0.9);
    gap: 6px;
  }
}

@media (max-width: 600px) {
  #gerber-viewer-modal {
    padding: 0.4rem;
  }
  .gerber-modal-dialog {
    width: 98vw;
    height: 96vh;
    border-radius: 12px;
  }
  .gerber-header {
    padding: 9px 12px;
  }
  .gerber-title {
    font-size: 0.84rem;
    gap: 6px;
  }
  .gerber-badge {
    display: none;
  }
  .gerber-canvas-viewport {
    height: 210px;
    min-height: 180px;
    max-height: 220px;
  }
  .gerber-sidebar {
    padding: 10px 12px;
    gap: 10px;
  }
  .layer-list {
    grid-template-columns: 1fr;
    gap: 5px;
  }
  .layer-item {
    padding: 7px 9px;
  }
  .layer-info {
    gap: 6px;
    font-size: 0.76rem;
  }
  .layer-name {
    font-size: 0.77rem;
  }
  .layer-ext {
    font-size: 0.65rem;
  }
  .layer-status-pill {
    font-size: 0.65rem;
    padding: 2px 5px;
  }
  .color-presets-wrap {
    gap: 6px;
  }
  .color-chip {
    width: 26px;
    height: 26px;
    border-radius: 6px;
  }
  .dfm-stats-box {
    padding: 9px 11px;
    font-size: 0.72rem;
  }
}
