/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: #f0f2f5;
  color: #222;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1a237e 0%, #283593 60%, #3949ab 100%);
  color: #fff;
  padding: 16px 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.header-inner { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.logo { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.02em; }
.subtitle { font-size: 0.85rem; opacity: 0.8; }

/* ===== Step Indicator ===== */
.step-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  gap: 0;
}
.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0.4;
  transition: opacity 0.3s;
}
.step-item.active  { opacity: 1; }
.step-item.done    { opacity: 0.7; }
.step-circle {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #ccc;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
  transition: background 0.3s;
}
.step-item.active .step-circle { background: #3949ab; }
.step-item.done   .step-circle { background: #43a047; }
.step-label { font-size: 0.75rem; color: #555; white-space: nowrap; }
.step-sep {
  width: 60px; height: 2px;
  background: #ddd;
  margin: 0 8px;
  margin-bottom: 16px;
}
@media (max-width: 600px) {
  .step-sep { width: 20px; }
  .step-label { display: none; }
}

/* ===== Main ===== */
main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ===== Card ===== */
.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  padding: 28px 32px;
  margin-bottom: 24px;
}
.card h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #1a237e;
}
.step-badge {
  background: #3949ab;
  color: #fff;
  border-radius: 50%;
  width: 28px; height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
  flex-shrink: 0;
}
.hint { color: #666; font-size: 0.88rem; margin-bottom: 16px; line-height: 1.6; }

/* ===== Drop Zone ===== */
.drop-zone {
  border: 2px dashed #90a4ae;
  border-radius: 10px;
  padding: 40px 24px;
  text-align: center;
  background: #f8f9ff;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}
.drop-zone.drag-over {
  border-color: #3949ab;
  background: #e8eaf6;
}
.drop-icon { font-size: 3rem; margin-bottom: 8px; }
.drop-zone p { color: #555; margin-bottom: 12px; line-height: 1.6; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: filter 0.15s, transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary   { background: #3949ab; color: #fff; }
.btn-secondary { background: #e0e0e0; color: #333; }
.btn-danger    { background: #e53935; color: #fff; }
.btn-sm        { padding: 5px 12px; font-size: 0.82rem; }
.btn-lg        { padding: 12px 28px; font-size: 1rem; }
.btn:hover     { filter: brightness(1.08); }

/* ===== Progress ===== */
.progress-wrap { margin-top: 16px; }
.progress-bar {
  height: 8px; background: #e0e0e0; border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; background: #3949ab;
  transition: width 0.3s ease;
}
#progress-label { font-size: 0.82rem; color: #555; margin-top: 4px; display: block; }

/* ===== Two-column layout ===== */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 24px;
  margin-bottom: 20px;
}
@media (max-width: 768px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ===== Preview Tabs ===== */
.preview-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  border-bottom: 2px solid #e8eaf6;
}
.preview-tab {
  padding: 7px 16px;
  border: none;
  background: #f5f5f5;
  color: #666;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  border: 1px solid #e0e0e0;
  border-bottom: none;
  transition: background 0.15s, color 0.15s;
  margin-right: 2px;
}
.preview-tab:hover {
  background: #e8eaf6;
  color: #3949ab;
}
.preview-tab.active {
  background: #fff;
  color: #1a237e;
  border-color: #e8eaf6;
  border-bottom: 2px solid #fff;
  margin-bottom: -2px;
  z-index: 1;
  position: relative;
}

/* ===== KiCad Footprint Preview Canvas ===== */
.fp-preview-wrap {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 0 6px 6px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 180px;
}
#fp-preview-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}
.fp-preview-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
  font-size: 0.75rem;
  color: #666;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ===== Preview ===== */
.preview-pane h3, .params-pane h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid #e8eaf6;
}
#preview-container {
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 0 6px 6px 6px;
  overflow: hidden;
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#preview-img {
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
  display: block;
}
.preview-thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.preview-thumb {
  width: 72px; height: 72px;
  object-fit: cover;
  border: 2px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.preview-thumb.selected { border-color: #3949ab; }
.preview-thumb:hover    { border-color: #7986cb; }

/* ===== Form ===== */
.form-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 8px 12px;
  align-items: center;
  margin-bottom: 20px;
}
.form-grid label { font-size: 0.85rem; color: #444; font-weight: 600; }
.form-grid input,
.form-grid select {
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  font-size: 0.9rem;
  width: 100%;
  transition: border-color 0.15s;
  background: #fff;
}
.form-grid input:focus,
.form-grid select:focus { outline: none; border-color: #3949ab; }

/* ===== Pad Table ===== */
.pad-toolbar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
.table-wrap { overflow-x: auto; }
#pad-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
#pad-table th {
  background: #e8eaf6;
  color: #1a237e;
  padding: 8px 10px;
  text-align: center;
  font-weight: 700;
  white-space: nowrap;
}
#pad-table td {
  padding: 5px 6px;
  border-bottom: 1px solid #eee;
  text-align: center;
}
#pad-table tr:hover td { background: #f5f5ff; }
#pad-table input, #pad-table select {
  width: 80px;
  padding: 4px 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.82rem;
  text-align: center;
}
#pad-table select { width: 90px; }
.btn-del-pad {
  background: none;
  border: none;
  color: #e53935;
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.btn-del-pad:hover { background: #ffebee; }

/* ===== Alert ===== */
.alert {
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 0.88rem;
  margin-bottom: 14px;
  line-height: 1.5;
}
.alert-warn    { background: #fff8e1; border: 1px solid #ffca28; color: #795548; }
.alert-success { background: #e8f5e9; border: 1px solid #a5d6a7; color: #2e7d32; }

/* ===== Action Bar ===== */
.action-bar {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid #eee;
  flex-wrap: wrap;
}

/* ===== Success / Download ===== */
.success-box {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #e8f5e9;
  border: 1px solid #a5d6a7;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.success-icon { font-size: 2rem; }
.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.file-chip {
  background: #e8eaf6;
  border: 1px solid #9fa8da;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: #1a237e;
  font-weight: 600;
}
.generated-params { margin-top: 24px; }
.generated-params h3 {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 8px;
}
.generated-params pre {
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 12px;
  font-size: 0.78rem;
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ===== Loading Overlay ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 16px;
}
.loading-overlay p { color: #fff; font-size: 1rem; font-weight: 600; }
.spinner {
  width: 52px; height: 52px;
  border: 5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Utility ===== */
.hidden { display: none !important; }
.active { display: block; }

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 14px;
  font-size: 0.78rem;
  color: #888;
  background: #fff;
  border-top: 1px solid #eee;
}
