/* ==========================================================================
   Mach3 Web - Cloud CNC Motion Controller Design System
   Aesthetic: Cyber-Industrial Dark Glassmorphism with High-Contrast Telemetry
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700;800&family=Orbitron:wght@500;700;900&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --bg-deep: #07090e;
  --bg-primary: #0b0f17;
  --bg-surface: rgba(16, 23, 36, 0.7);
  --bg-surface-solid: #101724;
  --bg-elevated: rgba(22, 32, 50, 0.6);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(0, 240, 255, 0.25);
  --border-active: #00f0ff;

  --accent-cyan: #00f0ff;
  --accent-cyan-glow: rgba(0, 240, 255, 0.35);
  --accent-blue: #0066ff;
  --accent-emerald: #00ff88;
  --accent-emerald-glow: rgba(0, 255, 136, 0.35);
  --accent-amber: #ffb700;
  --accent-amber-glow: rgba(255, 183, 0, 0.35);
  --accent-crimson: #ff2a55;
  --accent-crimson-glow: rgba(255, 42, 85, 0.45);

  --dro-bg: #04060a;
  --dro-text: #00f0ff;
  --dro-sub: #4b6382;

  --font-ui: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Courier New', monospace;
  --font-display: 'Orbitron', 'JetBrains Mono', monospace;

  --shadow-panel: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(0, 240, 255, 0.15);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-deep);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(0, 102, 255, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(0, 240, 255, 0.05) 0%, transparent 45%),
    linear-gradient(to bottom, #07090e 0%, #0b0f17 100%);
  color: #e2e8f0;
  font-family: var(--font-ui);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(10, 14, 22, 0.6);
}
::-webkit-scrollbar-thumb {
  background: rgba(0, 240, 255, 0.2);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent-cyan);
}

/* ==========================================================================
   Header Bar
   ========================================================================== */
.app-header {
  height: 56px;
  background: rgba(11, 15, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  flex-shrink: 0;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-badge {
  background: linear-gradient(135deg, #00f0ff 0%, #0066ff 100%);
  color: #07090e;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  letter-spacing: 1.5px;
  box-shadow: 0 0 16px var(--accent-cyan-glow);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #ffffff;
}

.brand-sub {
  font-size: 12px;
  font-weight: 400;
  color: #64748b;
  margin-left: 6px;
  letter-spacing: 0.5px;
}

.telemetry-summary {
  display: flex;
  align-items: center;
  gap: 20px;
}

.status-badge {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 20px;
  letter-spacing: 1px;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s ease;
}

.status-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.state-idle {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}
.state-idle::before { background: #38bdf8; }

.state-running {
  background: rgba(0, 255, 136, 0.15);
  color: var(--accent-emerald);
  border: 1px solid var(--accent-emerald);
  box-shadow: 0 0 12px var(--accent-emerald-glow);
}
.state-running::before {
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
  animation: pulse 1s infinite alternate;
}

.state-hold {
  background: rgba(255, 183, 0, 0.15);
  color: var(--accent-amber);
  border: 1px solid var(--accent-amber);
}
.state-hold::before { background: var(--accent-amber); }

.state-estop {
  background: rgba(255, 42, 85, 0.2);
  color: var(--accent-crimson);
  border: 1px solid var(--accent-crimson);
  box-shadow: 0 0 16px var(--accent-crimson-glow);
  animation: pulse 0.7s infinite alternate;
}
.state-estop::before { background: var(--accent-crimson); }

.state-sim {
  background: rgba(148, 163, 184, 0.12);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.2);
}
.state-sim::before { background: #94a3b8; }

.state-online {
  background: rgba(0, 240, 255, 0.15);
  color: var(--accent-cyan);
  border: 1px solid var(--accent-cyan);
}
.state-online::before { background: var(--accent-cyan); }

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  100% { transform: scale(1.2); opacity: 1; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-header {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: #cbd5e1;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-accent);
  color: #ffffff;
}

.btn-header.primary {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.15) 0%, rgba(0, 102, 255, 0.25) 100%);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}
.btn-header.primary:hover {
  background: var(--accent-cyan);
  color: #07090e;
  box-shadow: 0 0 16px var(--accent-cyan-glow);
}

/* ==========================================================================
   Main Grid Workspace
   ========================================================================== */
.workspace-grid {
  display: grid;
  grid-template-columns: 360px 1fr 380px;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* Glass Panels */
.panel {
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.02);
}

.panel-title {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: #94a3b8;
  text-transform: uppercase;
}

.panel-body {
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ==========================================================================
   Column 1: DROs & Jogging
   ========================================================================== */
.dro-bank {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dro-card {
  background: var(--dro-bg);
  border: 1px solid rgba(0, 240, 255, 0.15);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.8);
  transition: border-color 0.2s ease;
}

.dro-card:hover {
  border-color: var(--accent-cyan);
}

.dro-axis-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.axis-label {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 900;
  color: #64748b;
  width: 22px;
}
.axis-label.axis-x { color: #ff4d4f; }
.axis-label.axis-y { color: #52c41a; }
.axis-label.axis-z { color: #1890ff; }
.axis-label.axis-a { color: #faad14; }

.btn-zero {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: #94a3b8;
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-zero:hover {
  background: var(--accent-cyan);
  color: #07090e;
  border-color: var(--accent-cyan);
}

.dro-value-wrapper {
  text-align: right;
}

.dro-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--dro-text);
  letter-spacing: -0.5px;
  text-shadow: 0 0 10px var(--accent-cyan-glow);
}

.dro-dtg {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--dro-sub);
}

/* Jogging Controls */
.jog-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.jog-mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.btn-toggle {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-toggle.active {
  background: rgba(0, 240, 255, 0.15);
  color: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan-glow);
}

.jog-step-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.select-dark {
  background: #0f172a;
  border: 1px solid var(--border-subtle);
  color: #e2e8f0;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  outline: none;
  flex: 1;
}

.jog-dpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 50px);
  gap: 6px;
}

.btn-jog {
  background: linear-gradient(180deg, #182234 0%, #101724 100%);
  border: 1px solid var(--border-subtle);
  color: #cbd5e1;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  transition: all 0.12s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-jog:hover {
  border-color: var(--accent-cyan);
  color: #ffffff;
  box-shadow: 0 0 12px var(--accent-cyan-glow);
  transform: translateY(-1px);
}

.btn-jog:active {
  transform: translateY(1px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}

/* MPG Wheel Simulator */
.mpg-wheel-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.mpg-wheel {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle, #2a374a 0%, #101622 70%);
  border: 3px solid #3e4f68;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7), inset 0 0 10px rgba(0, 0, 0, 0.9);
  cursor: grab;
  position: relative;
  transition: border-color 0.2s ease;
}

.mpg-wheel:hover {
  border-color: var(--accent-cyan);
}

.mpg-wheel:active {
  cursor: grabbing;
}

.mpg-indicator-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan);
  position: absolute;
  top: 10px;
  left: 38px;
}

/* Overrides Panel */
.slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #94a3b8;
}

.slider-dark {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #182234;
  outline: none;
}

.slider-dark::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan);
  cursor: pointer;
  transition: transform 0.1s ease;
}

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

/* ==========================================================================
   Column 2: 3D Viewport & Master Controls
   ========================================================================== */
.center-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.viewport-panel {
  flex: 1;
  position: relative;
  background: #06090e;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

#viewport-3d-canvas {
  width: 100%;
  height: 100%;
}

.viewport-overlay-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 6px;
  z-index: 10;
}

.btn-view-chip {
  background: rgba(11, 15, 23, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  color: #94a3b8;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-view-chip:hover {
  background: var(--accent-cyan);
  color: #07090e;
  border-color: var(--accent-cyan);
}

.viewport-stats-overlay {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(11, 15, 23, 0.85);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #94a3b8;
  display: flex;
  gap: 16px;
  z-index: 10;
}

.viewport-stats-overlay span strong {
  color: var(--accent-cyan);
}

/* Master Cycle Controls Bar */
.master-controls-bar {
  background: var(--bg-surface);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 2fr 1.5fr 1.5fr 2fr;
  gap: 12px;
}

.btn-industrial {
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1px;
  padding: 16px 12px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-industrial:active {
  transform: translateY(2px);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}

.btn-cycle-start {
  background: linear-gradient(135deg, #00ff88 0%, #009944 100%);
  color: #051a0e;
  box-shadow: 0 0 20px var(--accent-emerald-glow);
}
.btn-cycle-start:hover {
  background: #00ff88;
  box-shadow: 0 0 30px var(--accent-emerald-glow);
}

.btn-feed-hold {
  background: linear-gradient(135deg, #ffb700 0%, #b38000 100%);
  color: #1a1200;
  box-shadow: 0 0 16px var(--accent-amber-glow);
}
.btn-feed-hold:hover {
  background: #ffb700;
}

.btn-stop {
  background: linear-gradient(135deg, #475569 0%, #1e293b 100%);
  color: #f1f5f9;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.btn-stop:hover {
  background: #64748b;
}

.btn-estop {
  background: linear-gradient(135deg, #ff2a55 0%, #99001f 100%);
  color: #ffffff;
  border: 2px solid #ff4d6d;
  box-shadow: 0 0 24px var(--accent-crimson-glow);
  position: relative;
  overflow: hidden;
}

.btn-estop.active-alarm {
  animation: estopStrobe 0.6s infinite alternate;
}

@keyframes estopStrobe {
  0% { box-shadow: 0 0 10px #ff2a55; border-color: #ff2a55; }
  100% { box-shadow: 0 0 36px #ff2a55; border-color: #ffffff; }
}

/* Program Execution Progress Bar */
.progress-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: #94a3b8;
  font-family: var(--font-mono);
}

.progress-track {
  width: 100%;
  height: 6px;
  background: #0f172a;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #0077ff 0%, #00f0ff 100%);
  box-shadow: 0 0 10px var(--accent-cyan);
  transition: width 0.1s linear;
}

/* ==========================================================================
   Column 3: G-Code Program, MDI & Diagnostics
   ========================================================================== */
.gcode-controls-row {
  display: flex;
  gap: 8px;
}

.gcode-viewer-panel {
  flex: 1;
  background: var(--dro-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 20px;
}

.gcode-line {
  display: flex;
  padding: 0 8px;
  cursor: pointer;
  transition: background 0.1s ease;
}

.gcode-line:hover {
  background: rgba(255, 255, 255, 0.05);
}

.gcode-line.active-executing {
  background: rgba(0, 240, 255, 0.2);
  border-left: 3px solid var(--accent-cyan);
  color: #ffffff;
  font-weight: 700;
}

.line-num {
  width: 44px;
  color: #475569;
  user-select: none;
}

.line-code {
  color: #cbd5e1;
}

/* MDI Console */
.mdi-row {
  display: flex;
  gap: 6px;
}

.mdi-input {
  flex: 1;
  background: #070a10;
  border: 1px solid var(--border-subtle);
  color: #00f0ff;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  outline: none;
}

.mdi-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan-glow);
}

.btn-mdi {
  background: var(--accent-blue);
  border: none;
  color: #ffffff;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.mdi-history-list {
  list-style: none;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #64748b;
  max-height: 80px;
  overflow-y: auto;
}

.mdi-history-list li {
  padding: 2px 4px;
  cursor: pointer;
}

.mdi-history-list li:hover {
  color: var(--accent-cyan);
}

/* Diagnostics & Indicators */
.led-indicators-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.led-card {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 4px;
  text-align: center;
  font-size: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  color: #64748b;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.led-card.active {
  border-color: var(--accent-emerald);
  color: var(--accent-emerald);
}

.led-indicator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #334155;
}

.led-card.active .led-indicator-dot {
  background: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}
