/* --- Design System Variables --- */
:root {
  --bg-color: hsl(222, 28%, 7%);
  --sidebar-bg: hsla(222, 28%, 11%, 0.7);
  --glass-bg: hsla(222, 28%, 14%, 0.6);
  --glass-border: hsla(217, 30%, 20%, 0.5);
  --glass-border-focus: hsla(250, 80%, 65%, 0.4);
  
  --text-primary: hsl(210, 40%, 98%);
  --text-secondary: hsl(215, 20%, 65%);
  --text-muted: hsl(215, 12%, 45%);
  
  --accent-color: hsl(250, 80%, 65%);
  --accent-hover: hsl(250, 85%, 70%);
  --accent-glow: hsla(250, 80%, 65%, 0.25);
  
  --color-danger: hsl(350, 80%, 55%);
  --color-success: hsl(145, 80%, 45%);
  --color-warning: hsl(40, 80%, 55%);
  
  --font-family-sans: 'Outfit', sans-serif;
  --font-family-mono: 'Space Grotesk', sans-serif;
  
  --border-radius-lg: 16px;
  --border-radius-md: 8px;
  --border-radius-sm: 4px;
}

/* --- Base Layout --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family-sans);
  background-color: var(--bg-color);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* --- Glassmorphic Panels --- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

/* --- Sidebar Style --- */
.sidebar {
  width: 420px;
  min-width: 420px;
  height: 100%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--glass-border);
  background: var(--sidebar-bg);
  z-index: 10;
}

.sidebar-header {
  padding: 24px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h1 {
  font-family: var(--font-family-mono);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 30%, var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge {
  font-size: 0.7rem;
  background: var(--accent-glow);
  color: var(--accent-hover);
  border: 1px solid hsla(250, 80%, 65%, 0.3);
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 500;
  text-transform: uppercase;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Clean, visible scrollbars */
.sidebar-content::-webkit-scrollbar {
  width: 8px;
}
.sidebar-content::-webkit-scrollbar-track {
  background: hsla(222, 28%, 5%, 0.2);
  border-radius: 4px;
}
.sidebar-content::-webkit-scrollbar-thumb {
  background: hsl(215, 20%, 45%);
  border-radius: 4px;
  border: 1px solid var(--sidebar-bg);
}
.sidebar-content::-webkit-scrollbar-thumb:hover {
  background: hsl(215, 25%, 55%);
}

/* --- Config Sections --- */
.config-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.config-section h2 {
  font-size: 0.92rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 4px;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 6px;
}

.section-title-row h2 {
  border-bottom: none;
  padding-bottom: 0;
}

/* --- Form Controls --- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.row-align {
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.select-input {
  background: var(--bg-color);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  padding: 8px 12px;
  border-radius: var(--border-radius-md);
  font-family: var(--font-family-sans);
  font-size: 0.85rem;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
}

.select-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.select-sm {
  padding: 4px 8px;
  font-size: 0.8rem;
}

/* --- DH Parameters Table --- */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius-md);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.8rem;
  table-layout: fixed;
}

#dh-table th:nth-child(1) { width: 9%; }   /* Joint index */
#dh-table th:nth-child(2) { width: 19%; }  /* Joint Type dropdown */
#dh-table th:nth-child(3) { width: 16%; }  /* d input */
#dh-table th:nth-child(4) { width: 16%; }  /* theta input */
#dh-table th:nth-child(5) { width: 16%; }  /* a input */
#dh-table th:nth-child(6) { width: 16%; }  /* alpha input */
#dh-table th:nth-child(7) { width: 8%; }   /* delete button */

th {
  background: hsla(222, 28%, 5%, 0.5);
  color: var(--text-secondary);
  font-weight: 600;
  padding: 8px 4px;
  border-bottom: 1px solid var(--glass-border);
  text-align: center;
}

td {
  padding: 6px 2px;
  border-bottom: 1px solid var(--glass-border);
  vertical-align: middle;
  text-align: center;
}

tr:last-child td {
  border-bottom: none;
}

/* Inputs within table */
.cell-input {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-primary);
  padding: 4px 2px;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-family-mono);
  font-size: 0.76rem;
  text-align: center;
  outline: none;
  transition: all 0.15s ease;
}

.cell-input:hover {
  background: hsla(220, 20%, 20%, 0.3);
  border-color: var(--glass-border);
}

.cell-input:focus {
  background: var(--bg-color);
  border-color: var(--accent-color);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.cell-select {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-primary);
  padding: 4px;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-family-sans);
  font-size: 0.8rem;
  outline: none;
  cursor: pointer;
}

.cell-select:hover {
  background: hsla(220, 20%, 20%, 0.3);
  border-color: var(--glass-border);
}

.cell-select:focus {
  background: var(--bg-color);
  border-color: var(--accent-color);
}

.dh-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-family-sans);
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--border-radius-md);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  outline: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-primary {
  background: var(--accent-color);
  border: 1px solid transparent;
  color: var(--text-primary);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
  background: hsla(220, 20%, 20%, 0.2);
}

.btn-danger-sm {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--border-radius-sm);
}

.btn-danger-sm:hover {
  color: var(--color-danger);
  background: hsla(350, 80%, 55%, 0.1);
  border-color: hsla(350, 80%, 55%, 0.2);
}

.btn-group {
  display: flex;
  gap: 6px;
}

/* --- File Upload UI --- */
.file-uploader {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.border-top {
  border-top: 1px solid var(--glass-border);
  padding-top: 12px;
}

.file-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.file-label-row label {
  font-weight: 600;
}

.file-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-input {
  display: none;
}

.file-input-btn {
  background: var(--bg-color);
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.file-input-btn:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
}

.file-name-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-family-mono);
}

.status-indicator {
  font-size: 0.7rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
}

.status-indicator.default {
  background: hsla(215, 12%, 45%, 0.15);
  color: var(--text-secondary);
}

.status-indicator.uploaded {
  background: hsla(145, 80%, 45%, 0.15);
  color: var(--color-success);
}

.help-text {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--glass-border);
  transition: .2s;
  border-radius: 20px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--accent-color);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--accent-color);
}

input:checked + .slider:before {
  transform: translateX(16px);
}

.hidden {
  display: none !important;
}

/* --- 3D Viewport Area --- */
.visualizer-container {
  flex: 1;
  position: relative;
  height: 100%;
}

#canvas-container {
  width: 100%;
  height: 100%;
  outline: none;
}

/* --- Controls Overlay --- */
.controls-overlay {
  position: absolute;
  bottom: 24px;
  left: 24px;
  right: 24px;
  border-radius: var(--border-radius-lg);
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 100;
}

/* Toggles Row */
.render-toggles {
  display: flex;
  gap: 20px;
  align-items: center;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 10px;
  flex-wrap: wrap;
}

/* Custom Checkbox */
.checkbox-container {
  display: flex;
  align-items: center;
  position: relative;
  padding-left: 22px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-secondary);
  user-select: none;
  font-weight: 500;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  height: 14px;
  width: 14px;
  background-color: transparent;
  border: 1.5px solid var(--text-muted);
  border-radius: 3px;
  transition: all 0.15s ease;
}

.checkbox-container:hover input ~ .checkmark {
  border-color: var(--text-secondary);
}

.checkbox-container input:checked ~ .checkmark {
  background-color: var(--accent-color);
  border-color: var(--accent-color);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
  display: block;
}

.checkbox-container .checkmark:after {
  left: 4px;
  top: 1px;
  width: 4px;
  height: 7px;
  border: solid white;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

/* Playback Slider Row */
.playback-slider-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.playback-slider-row span {
  font-family: var(--font-family-mono);
  font-size: 0.85rem;
  color: var(--text-secondary);
  width: 50px;
}

#time-total {
  text-align: right;
}

.slider-input {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--glass-border);
  outline: none;
  cursor: pointer;
}

.slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  border: 2.5px solid var(--accent-color);
  transition: transform 0.1s ease;
  box-shadow: 0 0 6px var(--accent-glow);
}

.slider-input::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Control Bar Row */
.control-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.btn-action {
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 8px;
  border-radius: var(--border-radius-md);
  width: 38px;
  height: 38px;
}

.btn-action:hover {
  border-color: var(--text-primary);
  background: hsla(220, 20%, 20%, 0.2);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Record WebM Button */
.btn-record-webm {
  background: hsla(350, 80%, 55%, 0.15);
  border: 1px solid hsla(350, 80%, 55%, 0.3);
  color: var(--color-danger);
  padding: 8px 16px;
  font-family: var(--font-family-sans);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--border-radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-record-webm:hover {
  background: hsla(350, 80%, 55%, 0.25);
  border-color: var(--color-danger);
  box-shadow: 0 0 10px rgba(230, 40, 40, 0.2);
}

.record-dot {
  width: 8px;
  height: 8px;
  background: var(--color-danger);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 1.5s infinite;
}

.recording-badge {
  background: var(--color-danger);
  color: #fff;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 8px 16px;
  border-radius: var(--border-radius-md);
  box-shadow: 0 0 12px rgba(230, 40, 40, 0.4);
  animation: pulse 1.5s infinite;
}

/* Animations */
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(230, 40, 40, 0.4);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(230, 40, 40, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(230, 40, 40, 0);
  }
}

/* --- Header Branding --- */
.header-brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.header-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-help-trigger {
  padding: 2px 8px;
  font-size: 0.7rem;
  font-weight: 500;
  border-radius: 20px;
  background: transparent;
  border: 1px solid var(--glass-border);
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.btn-help-trigger:hover {
  border-color: var(--text-primary);
  color: var(--text-primary);
  background: hsla(220, 20%, 20%, 0.3);
}

/* --- Help Modal Overlay --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
  display: none !important;
  opacity: 0;
}

.modal-content {
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  border-radius: var(--border-radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modal-enter 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modal-enter {
  from {
    transform: scale(0.9) translateY(20px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

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

.modal-header h2 {
  font-family: var(--font-family-mono);
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 30%, var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.75rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
  transition: color 0.2s ease;
}

.btn-close-modal:hover {
  color: var(--color-danger);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  line-height: 1.6;
}

.modal-body h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent-hover);
  margin-bottom: 8px;
}

.modal-body p {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.modal-body ul {
  padding-left: 20px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-body code {
  font-family: var(--font-family-mono);
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: var(--border-radius-sm);
  color: var(--text-primary);
  font-size: 0.85em;
}

/* Animations */
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(230, 40, 40, 0.4);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(230, 40, 40, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(230, 40, 40, 0);
  }
}
