:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #1e1e35;
  --bg-input: #252545;
  --border: #2a2a4a;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --accent-dim: rgba(233, 69, 96, 0.15);
  --success: #2ed573;
  --warning: #ffa502;
  --danger: #ff4757;
  --info: #70a1ff;
  --text-primary: #eaeaea;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --sidebar-width: 240px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

#loading-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--bg-primary);
}

#app { display: flex; height: 100vh; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  transition: transform var(--transition);
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.3rem;
  background: linear-gradient(135deg, var(--accent), #ff6b81);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.nav-links { list-style: none; padding: 10px 0; flex: 1; }

.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition);
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--accent-dim); color: var(--text-primary); }
.nav-link.active { background: var(--accent-dim); color: var(--accent); border-left-color: var(--accent); }
.nav-link .icon { font-size: 1.2rem; width: 24px; text-align: center; }

.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--border);
}

#user-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  display: block; text-align: center; padding: 8px;
  background: var(--bg-input); color: var(--text-secondary);
  text-decoration: none; border-radius: var(--radius-sm);
  font-size: 0.85rem; transition: all var(--transition);
}
.logout-btn:hover { background: var(--danger); color: white; }

/* ── Main Content ── */
#content { flex: 1; overflow-y: auto; padding: 24px; }
#page-container { max-width: 1400px; margin: 0 auto; }

.mobile-header {
  display: none; align-items: center; gap: 12px; padding: 0 0 16px;
}
.mobile-header button {
  background: none; border: none; color: var(--text-primary);
  font-size: 1.5rem; cursor: pointer;
}
.mobile-header h2 { font-size: 1.1rem; }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 16px;
}
.card-title { font-size: 1rem; font-weight: 600; }

/* ── Grid ── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Status ── */
.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block; margin-right: 8px;
}
.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.busy { background: var(--warning); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Temperature ── */
.temp-display { display: flex; align-items: baseline; gap: 4px; }
.temp-value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.temp-unit { font-size: 1rem; color: var(--text-secondary); }
.temp-target { font-size: 0.85rem; color: var(--text-muted); }

/* ── Progress ── */
.progress-bar {
  width: 100%; height: 8px;
  background: var(--bg-input); border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ff6b81);
  border-radius: 4px; transition: width 0.5s ease;
}

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 20px; border: none; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 500; cursor: pointer;
  transition: all var(--transition); text-decoration: none; color: white;
}
.btn-primary { background: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success { background: var(--success); color: #000; }
.btn-warning { background: var(--warning); color: #000; }
.btn-danger { background: var(--danger); }
.btn-ghost {
  background: var(--bg-input); color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--accent); }
.btn-ghost.active { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Jog Controls ── */
.jog-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; max-width: 200px;
}
.jog-btn {
  padding: 12px; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 1.2rem; cursor: pointer;
  transition: all var(--transition);
}
.jog-btn:hover { background: var(--accent-dim); border-color: var(--accent); }
.jog-btn:active { transform: scale(0.95); }

/* ── Camera ── */
.camera-feed {
  width: 100%; border-radius: var(--radius);
  background: #000; aspect-ratio: 16/9; object-fit: contain;
}

/* ── File List ── */
.file-list { list-style: none; }
.file-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.file-item:hover { background: var(--accent-dim); }
.file-name { font-weight: 500; }
.file-meta { font-size: 0.8rem; color: var(--text-secondary); }

/* ── Forms ── */
input[type="number"], input[type="text"], textarea, select {
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); padding: 10px 14px;
  border-radius: var(--radius-sm); font-size: 0.9rem;
  outline: none; transition: border-color var(--transition);
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

/* ── Console ── */
.console {
  background: #0a0a14; border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Fira Code', 'Cascadia Code', monospace; font-size: 0.85rem;
}
.console-output { padding: 12px; height: 300px; overflow-y: auto; color: var(--text-secondary); }
.console-input { display: flex; border-top: 1px solid var(--border); }
.console-input input {
  flex: 1; border: none; border-radius: 0;
  background: transparent; padding: 10px 14px;
  font-family: inherit; color: var(--text-primary);
  outline: none;
}
.console-input button {
  padding: 10px 16px; background: var(--accent);
  border: none; color: white; cursor: pointer;
}

/* ── Toast ── */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 1000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 20px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border);
  box-shadow: var(--shadow); animation: slideIn 0.3s ease;
  max-width: 400px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }
.toast.warning { border-left: 4px solid var(--warning); }
@keyframes slideIn { from { transform: translateX(100px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Spinner ── */
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { display: flex; align-items: center; justify-content: center; padding: 60px; }

/* ── Slider ── */
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  background: var(--bg-input); border-radius: 3px; outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px;
  background: var(--accent); border-radius: 50%; cursor: pointer;
}

/* ── Stat ── */
.stat { text-align: center; padding: 16px; }
.stat-value { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

/* ── Print Info ── */
.print-info { display: flex; flex-direction: column; gap: 8px; }
.print-filename { font-weight: 600; font-size: 1.1rem; }
.print-stats { display: flex; gap: 20px; color: var(--text-secondary); font-size: 0.85rem; }

/* ── Section ── */
.section-header {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 20px;
  flex-wrap: wrap; gap: 12px;
}
.section-title { font-size: 1.4rem; font-weight: 700; }

/* ── Overlay (sidebar backdrop) ── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 99;
  background: rgba(0,0,0,0.5);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed; left: 0; top: 0; height: 100%;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .mobile-header { display: flex; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  #content { padding: 16px; }
}

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
