/* Modern CSS Reset & Variable System */
:root {
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-card-hover: #334155;
  --bg-input: #0f172a;
  --border-color: #334155;
  --border-accent: #3b82f6;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-glow: rgba(59, 130, 246, 0.25);
  
  --accent: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.2);
  
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  
  --sidebar-width: 380px;
  --details-width: 360px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Header Navbar */
.app-header {
  height: 64px;
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 20px;
  box-shadow: 0 0 15px var(--primary-glow);
}

.logo-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-title span {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.unit-selector {
  display: flex;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 3px;
  border-radius: var(--radius-md);
}

.unit-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.unit-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.header-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.header-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
}

.header-btn.primary-btn {
  background: linear-gradient(135deg, var(--primary), #2563eb);
  border: none;
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.header-btn.primary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px var(--primary-glow);
}

/* App Main Layout */
.app-container {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--details-width);
  height: calc(100vh - 64px);
  overflow: hidden;
}

@media (max-width: 1280px) {
  .app-container {
    grid-template-columns: 340px 1fr 320px;
  }
}

@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
}

/* Sidebar Inputs Panel */
.sidebar-panel {
  background: rgba(30, 41, 59, 0.6);
  border-right: 1px solid var(--border-color);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.section-icon {
  color: var(--primary);
  font-size: 1.1rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Stair Type Selection Cards */
.stair-types-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stair-type-card {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.stair-type-card:hover {
  border-color: var(--text-muted);
  background: rgba(51, 65, 85, 0.5);
}

.stair-type-card.active {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.12);
  box-shadow: 0 0 12px var(--primary-glow);
}

.stair-type-icon {
  width: 42px;
  height: 42px;
  background: rgba(15, 23, 42, 0.8);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 20px;
}

.stair-type-card span {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Form Controls & Range Sliders */
.input-group {
  margin-bottom: 16px;
}

.input-group:last-child {
  margin-bottom: 0;
}

.input-label-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.input-label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-main);
}

.input-val-badge {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  background: rgba(59, 130, 246, 0.15);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.range-slider-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg-dark);
  border-radius: 3px;
  outline: none;
  border: 1px solid var(--border-color);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 10px var(--primary-glow);
  transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.number-input {
  width: 80px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  text-align: right;
  outline: none;
  transition: border-color 0.2s ease;
}

.number-input:focus {
  border-color: var(--primary);
}

.select-input {
  width: 100%;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.85rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
}

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

.toggle-group {
  display: flex;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 2px;
  border-radius: var(--radius-sm);
}

.toggle-opt {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  text-align: center;
  transition: all 0.2s ease;
}

.toggle-opt.active {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

/* Presets Container */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.preset-chip {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.preset-chip:hover {
  border-color: var(--primary);
  color: var(--text-main);
}

/* Central Viewport Area */
.viewport-panel {
  display: flex;
  flex-direction: column;
  background: #090d16;
  position: relative;
  overflow: hidden;
}

.viewport-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(15, 23, 42, 0.9);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.tabs-group {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.camera-controls-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  padding: 3px;
  border-radius: var(--radius-md);
}

.cam-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.cam-btn:hover, .cam-btn.active {
  background: var(--primary);
  color: #fff;
}

/* Viewport Content Containers */
.viewport-content {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
}

.view-pane {
  position: absolute;
  inset: 0;
  display: none;
}

.view-pane.active {
  display: block;
}

/* 3D Canvas Canvas */
#canvas-3d {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

/* 3D Overlay Controls & HUD */
.hud-overlay {
  position: absolute;
  top: 16px;
  left: 16px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hud-badge {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-main);
  pointer-events: auto;
  box-shadow: var(--shadow-md);
}

.hud-badge span {
  color: var(--primary);
  font-weight: 700;
}

.view-tools-overlay {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
  z-index: 5;
}

.tool-fab {
  width: 42px;
  height: 42px;
  background: rgba(30, 41, 59, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: all 0.2s ease;
}

.tool-fab:hover {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.08);
}

/* 2D Blueprint Pane */
#blueprint-pane {
  background: #0b1120;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.blueprint-svg {
  width: 100%;
  height: 100%;
  max-width: 900px;
  max-height: 650px;
}

/* Reference Gallery Pane */
#gallery-pane {
  padding: 24px;
  overflow-y: auto;
  background: var(--bg-dark);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.gallery-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.gallery-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-accent);
}

.gallery-card img {
  width: 100%;
  height: 240px;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid var(--border-color);
}

.gallery-card-body {
  padding: 16px;
}

.gallery-card-body h3 {
  font-size: 0.98rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.gallery-card-body p {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Right Details Sidebar */
.details-panel {
  background: rgba(30, 41, 59, 0.6);
  border-left: 1px solid var(--border-color);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Output Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.metric-card {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.metric-card.full-width {
  grid-column: span 2;
}

.metric-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-val {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-main);
}

.metric-sub {
  font-size: 0.74rem;
  color: var(--text-dim);
}

/* Ergonomic Comfort Diagnostic Card */
.comfort-card {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.comfort-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.comfort-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.comfort-status-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: uppercase;
}

.comfort-status-badge.ideal {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.comfort-status-badge.good {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.comfort-status-badge.warning {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.comfort-status-badge.danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.comfort-formula {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(30, 41, 59, 0.5);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.comfort-formula .formula-expr {
  color: var(--text-muted);
}

.comfort-formula .formula-res {
  font-weight: 700;
  color: var(--primary);
}

.comfort-bar-bg {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.comfort-bar-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  border-radius: 4px;
  transition: width 0.3s ease, background 0.3s ease;
}

.code-check-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.code-check-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.code-check-item .check-icon {
  font-size: 0.9rem;
}

.code-check-item.pass .check-icon {
  color: var(--accent);
}

.code-check-item.fail .check-icon {
  color: var(--danger);
}

/* Print Specification Sheet Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.active {
  display: flex;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 28px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 16px;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.close-btn:hover {
  color: var(--text-main);
}
