/* ============================================================
   Industrial Machine Configurator — Stylesheet
   Light, professional, industry-standard UI
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ---------- Custom Properties ---------- */
:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-border-active: #2563eb;
  --color-text: #1e293b;
  --color-text-secondary: #64748b;
  --color-text-muted: #94a3b8;
  --color-success: #16a34a;
  --color-shadow: rgba(0, 0, 0, 0.06);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.2s ease;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- Top Bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__icon {
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.topbar__icon svg {
  width: 20px;
  height: 20px;
}

.topbar__title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.02em;
}

.topbar__subtitle {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  font-weight: 400;
}

/* ---------- Button ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}

.btn:active {
  transform: scale(0.97);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn--ghost {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  box-shadow: none;
}

.btn--ghost:hover {
  background: rgba(2, 6, 23, 0.04);
}

.btn--icon {
  padding: 10px;
  width: 42px;
  justify-content: center;
}

.btn--icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn--primary:hover {
  background: var(--color-primary-hover);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.btn--primary svg {
  width: 16px;
  height: 16px;
  fill: #fff;
}

/* ---------- Main Layout ---------- */
.app {
  display: flex;
  height: calc(100vh - 65px);
}

body.sidebar-collapsed .panel {
  display: none;
}

/* ---------- Config Panel ---------- */
.panel {
  width: 400px;
  min-width: 400px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.panel::-webkit-scrollbar {
  width: 5px;
}

.panel::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 10px;
}

/* ---------- Section ---------- */
.section__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.section__icon {
  width: 32px;
  height: 32px;
  background: var(--color-primary-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-primary);
}

.section__icon svg {
  width: 16px;
  height: 16px;
}

.section__title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text);
  line-height: 1.2;
}

.section__desc {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  font-weight: 400;
  margin-top: 1px;
}

/* Section Badge (numbered) */
.section__badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff;
}

.section__badge--red {
  background: #e53e3e;
}

.section__badge--blue {
  background: #2563eb;
}

/* Flow Indicator */
.flow-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: #f0fdf4;
  border: 1px dashed #86efac;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  color: #166534;
  font-weight: 500;
  margin-top: 12px;
}

/* Gate Panel */
.gate-panel {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--color-border);
}

.section__badge--amber {
  background: #f59e0b;
}

.section__icon--amber {
  background: #fef3c7;
  color: #f59e0b;
}

.gate-info {
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  padding: 4px 0;
}

.gate-info__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  font-size: 0.8rem;
}

.gate-info__row+.gate-info__row {
  border-top: 1px solid var(--color-border);
}

.gate-info__label {
  color: var(--color-text-secondary);
  font-weight: 500;
}

.gate-info__value {
  color: var(--color-text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Gate Status Badge */
.gate-status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.gate-status--closed {
  background: #fee2e2;
  color: #dc2626;
}

.gate-status--open {
  background: #dcfce7;
  color: #16a34a;
}

.gate-status--moving {
  background: #fef3c7;
  color: #d97706;
}

/* ---------- Physics Panel ---------- */
.physics-panel {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px;
}

.physics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.physics-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.physics-card__title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 6px;
}

.physics-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.72rem;
  color: var(--color-text-secondary);
  padding: 4px 0;
}

.physics-row strong {
  color: var(--color-text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------- Dimension Row ---------- */
.dim-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
}

.dim-row__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text);
  width: 60px;
  flex-shrink: 0;
}

.dim-row__label--wide {
  width: 128px;
  font-size: 0.76rem;
}

.dim-row__input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.dim-input {
  width: 80px;
  padding: 6px 10px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  background: var(--color-surface);
  text-align: right;
  transition: border-color var(--transition);
}

.dim-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.dim-input--error {
  border-color: #dc2626;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.1);
}

.dim-input--warn {
  border-color: #d97706;
  box-shadow: 0 0 0 2px rgba(217, 119, 6, 0.1);
}

.layout-feedback {
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.78rem;
  line-height: 1.45;
  border: 1px solid var(--color-border);
}

.layout-feedback ul {
  margin: 6px 0 0 18px;
}

.layout-feedback--ok {
  background: #f0fdf4;
  border-color: #86efac;
  color: #166534;
}

.layout-feedback--warn {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #92400e;
}

.layout-feedback--error {
  background: #fef2f2;
  border-color: #fca5a5;
  color: #991b1b;
}

.layout-mode-note {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 0.76rem;
  line-height: 1.45;
}

.is-hidden {
  display: none !important;
}

/* Remove number input arrows */
.dim-input::-webkit-outer-spin-button,
.dim-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.dim-input {
  -moz-appearance: textfield;
}

.dim-row__unit {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-left: 2px;
}

.dim-row__metric {
  font-size: 0.72rem;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  padding: 3px 8px;
  border-radius: 20px;
  white-space: nowrap;
  border: 1px solid var(--color-border);
}

/* ---------- Feed Source ---------- */
.feed-source-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.feed-source-options--triple {
  grid-template-columns: repeat(3, 1fr);
}

#arrangementModeOptions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.feed-source-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 8px;
  background: var(--color-surface);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.feed-source-card input {
  accent-color: var(--color-primary);
}

.feed-source-card.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ---------- Material Cards ---------- */
.materials {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.material-card {
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  background: var(--color-surface);
}

.material-card:hover {
  border-color: var(--color-primary);
  box-shadow: 0 2px 12px var(--color-shadow);
  transform: translateY(-2px);
}

.material-card.active {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.material-card__preview {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  margin: 0 auto 10px;
  border: 1px solid var(--color-border);
}

.material-card__preview--steel {
  background: linear-gradient(135deg, #6b7b8d 0%, #8d99a8 25%, #5a6a7c 50%, #8d99a8 75%, #6b7b8d 100%);
}

.material-card__preview--aluminum {
  background: linear-gradient(135deg, #c0c8d0 0%, #dde2e8 30%, #a8b4c0 55%, #dde2e8 80%, #c0c8d0 100%);
}

.material-card__name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
}

.material-card__desc {
  font-size: 0.7rem;
  color: var(--color-text-muted);
}

.physics-grid--neutralizer {
  margin-top: 6px;
}

/* ---------- Spec Summary ---------- */
.spec-summary {
  background: var(--color-bg);
  border-radius: var(--radius-md);
  padding: 16px;
  border: 1px solid var(--color-border);
}

.spec-summary__row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.8rem;
}

.spec-summary__row+.spec-summary__row {
  border-top: 1px solid var(--color-border);
}

.spec-summary__label {
  color: var(--color-text-secondary);
  font-weight: 500;
}

.spec-summary__value {
  color: var(--color-text);
  font-weight: 600;
  text-align: right;
}

/* ---------- 3D Preview ---------- */
.preview {
  flex: 1;
  position: relative;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.preview canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.preview__hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.72rem;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
}

.preview__hint svg {
  width: 14px;
  height: 14px;
  fill: var(--color-text-muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app {
    flex-direction: column;
    height: auto;
  }

  .panel {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }

  .preview {
    height: 50vh;
    min-height: 350px;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 12px 16px;
  }

  .topbar__title {
    font-size: 1rem;
  }

  .topbar__subtitle {
    display: none;
  }

  .panel {
    padding: 18px;
  }

  .btn {
    padding: 10px 16px;
    font-size: 0.8rem;
  }

  .dim-row {
    flex-wrap: wrap;
  }
}
