/* Import FlyQ Fonts */
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;600;700&family=Inter:wght@300;400;600;700;800&display=swap');

/* FlyQ Theme Colors */
:root {
  --sky-blue: #0EA5E9;
  --light-blue: #38BDF8;
  --dark-blue: #0284C7;
  --midnight: #0F172A;
  --silver: #E5E7EB;
  --white: #FFFFFF;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-700: #374151;
  --gray-900: #111827;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  overflow: hidden;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Rajdhani', sans-serif;
  font-weight: 700;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
}

/* Header - FlyQ Theme */
.header {
  background: var(--white);
  color: var(--gray-900);
  padding: 1rem 2rem;
  box-shadow: 0 2px 10px rgba(14, 165, 233, 0.15);
  border-bottom: 2px solid rgba(14, 165, 233, 0.2);
}

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

.header h1 {
  font-family: 'Rajdhani', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, #38BDF8 0%, #0EA5E9 50%, #0284C7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.connection-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(255,255,255,0.1);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  flex-wrap: wrap;
}

.connection-panel label {
  font-size: 0.9rem;
  font-weight: 500;
}

.connection-panel input {
  padding: 0.5rem;
  border: none;
  border-radius: 4px;
  width: 150px;
  font-size: 0.9rem;
}

.connection-panel select {
  padding: 0.5rem;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: white;
  font-size: 0.9rem;
  cursor: pointer;
}

.connection-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.connection-mode-select {
  font-weight: 600;
  color: #374151;
  border: 2px solid #d1d5db;
}

.connection-status {
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 600;
}

.status-connected {
  background: #10b981;
  color: white;
}

.status-disconnected {
  background: #ef4444;
  color: white;
}

/* FlyQ Buttons */
.btn {
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: 'Rajdhani', sans-serif;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-primary {
  background: linear-gradient(135deg, #0EA5E9 0%, #38BDF8 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.btn-primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(14, 165, 233, 0.5);
}

.btn-success {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(16, 185, 129, 0.5);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(239, 68, 68, 0.5);
}

.btn-secondary {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: white;
  box-shadow: 0 4px 12px rgba(107, 114, 128, 0.3);
}

.btn-secondary:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(107, 114, 128, 0.5);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* Main Content */
/* 3-Column Resizable Layout: Blockly | Code | Controls */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
  padding-bottom: 200px; /* Space for fixed execution log */
  gap: 0; /* No gap between columns */
  position: relative;
}

/* Resizable Panels - Default Widths */
.resizable-panel {
  flex-shrink: 0;
  min-width: 200px; /* Minimum width for usability */
  max-width: 80%; /* Maximum width to prevent full collapse */
  transition: none; /* Disable transitions during resize */
}

/* Left Panel - Blockly Workspace (Default 35%) */
.blockly-panel {
  flex-basis: 35%;
  display: flex;
  flex-direction: column;
  background: var(--white);
  border-right: 2px solid rgba(14, 165, 233, 0.15);
}

/* Middle Panel - Generated Code (Default 30%) ⭐ - FlyQ Theme */
.code-panel {
  flex-basis: 30%;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, #F0F9FF 0%, #E0F2FE 100%);
  padding: 1rem;
  overflow-y: auto;
  max-height: calc(100vh - 80px);
  border-right: 2px solid rgba(14, 165, 233, 0.15);
}

/* Right Panel - Controls & Telemetry (Default 35%) - FlyQ Theme */
.control-panel {
  flex-basis: 35%;
  display: flex;
  flex-direction: column;
  background: var(--white);
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - 80px);
  position: relative;
}

/* Resize Handles Between Columns */
.resize-handle {
  width: 8px;
  background: linear-gradient(90deg, #e5e7eb 0%, #d1d5db 50%, #e5e7eb 100%);
  cursor: col-resize;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s ease;
  z-index: 10;
}

.resize-handle:hover {
  background: linear-gradient(90deg, #38BDF8 0%, #0EA5E9 50%, #38BDF8 100%);
}

.resize-handle:active {
  background: linear-gradient(90deg, #0284C7 0%, #0369A1 50%, #0284C7 100%);
  cursor: col-resize;
}

/* Visual Line in Resize Handle */
.resize-handle-line {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 2px;
  pointer-events: none;
}

.resize-handle:hover .resize-handle-line {
  background: rgba(255, 255, 255, 0.9);
  height: 60px;
}

/* Resizing State - Disable pointer events on iframes/canvas during resize */
.resizing .blockly-panel,
.resizing .code-panel,
.resizing .control-panel {
  pointer-events: none;
  user-select: none;
}

.panel-header {
  background: #f9fafb;
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: #374151;
}

.control-buttons {
  display: flex;
  gap: 0.5rem;
}

#blocklyDiv {
  flex: 1;
}

/* Telemetry Section */
.telemetry-section {
  padding: 1rem;
  border-bottom: 2px solid rgba(14, 165, 233, 0.2);
  background: linear-gradient(135deg, #E0F2FE 0%, #BAE6FD 100%);
}

.telemetry-section h3 {
  font-family: 'Rajdhani', sans-serif;
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
  color: var(--dark-blue);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.telemetry-item {
  display: flex;
  flex-direction: column;
  background: white;
  padding: 0.5rem;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.telemetry-label {
  font-size: 0.75rem;
  color: #6b7280;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.telemetry-value {
  font-size: 0.95rem;
  color: #1f2937;
  font-weight: 700;
  font-family: 'Courier New', monospace;
}

/* Battery Visualization */
.battery-item {
  grid-column: 1 / -1; /* Span full width */
}

.battery-display {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.battery-container {
  display: flex;
  align-items: center;
  gap: 2px;
}

.battery-body {
  width: 60px;
  height: 28px;
  border: 3px solid #374151;
  border-radius: 4px;
  padding: 2px;
  background: #f3f4f6;
  position: relative;
  overflow: hidden;
}

.battery-level {
  height: 100%;
  background: linear-gradient(180deg, #10b981 0%, #059669 100%);
  border-radius: 2px;
  transition: width 0.3s ease, background 0.3s ease;
  width: 100%;
  position: relative;
}

/* Battery level states */
.battery-level[data-level="100"],
.battery-level[data-level="90"],
.battery-level[data-level="80"],
.battery-level[data-level="70"] {
  background: linear-gradient(180deg, #10b981 0%, #059669 100%); /* Green */
}

.battery-level[data-level="60"],
.battery-level[data-level="50"],
.battery-level[data-level="40"] {
  background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%); /* Yellow */
}

.battery-level[data-level="30"],
.battery-level[data-level="20"],
.battery-level[data-level="10"] {
  background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%); /* Red */
  animation: batteryPulse 1s ease-in-out infinite;
}

@keyframes batteryPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.battery-tip {
  width: 6px;
  height: 16px;
  background: #374151;
  border-radius: 0 2px 2px 0;
}

.battery-text {
  font-size: 1.1rem !important;
  font-weight: 800 !important;
  min-width: 50px;
}

.examples-section {
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
  background: #fef3c7;
}

.examples-section h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: #92400e;
}

.example-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-example {
  background: #fbbf24;
  color: #78350f;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.btn-example:hover {
  background: #f59e0b;
}

/* Video Section */
.video-section {
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
  background: #fce7f3;
}

.video-section h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: #9f1239;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#video-container {
  margin-top: 0.5rem;
}

#drone-video {
  max-width: 100%;
  border: 2px solid #e11d48;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Fleet Section */
.fleet-section {
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
  background: #e0e7ff;
}

.fleet-section h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: #3730a3;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.fleet-grid {
  margin-bottom: 0.5rem;
}

#fleet-status {
  padding: 0.5rem;
  background: white;
  border-radius: 4px;
  text-align: center;
}

/* Code Display */
.code-section {
  padding: 1rem;
  border-bottom: 1px solid #e5e7eb;
  max-height: 250px;
  overflow-y: auto;
}

.code-section h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: #374151;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#code-output {
  background: #1f2937;
  color: #10b981;
  padding: 1rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  min-height: 150px;
  max-height: 180px;
  height: 150px;
  overflow-x: auto;
  overflow-y: auto;
  white-space: pre;
  display: block;
  width: 100%;
  box-sizing: border-box;
}

/* Log Display */
.log-section {
  flex: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.log-section h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: #374151;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#log-output {
  flex: 1;
  background: #1f2937;
  color: #9ca3af;
  padding: 1rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  min-height: 150px;
  max-height: 300px;
  height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  display: block;
  width: 100%;
  box-sizing: border-box;
}

/* Execution Controls */
.execution-controls {
  padding: 1rem;
  background: #f9fafb;
  border-top: 2px solid #e5e7eb;
  display: flex;
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  z-index: 100;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
  margin-top: auto;
}

.execution-controls .btn {
  flex: 1;
  padding: 0.75rem;
  font-size: 1rem;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Responsive Design - Stack on Tablets/Mobile */
@media (max-width: 1400px) {
  .main-content {
    flex-direction: column;
  }
  
  .blockly-panel {
    flex: 0 0 40% !important;
    border-right: none;
    border-bottom: 3px solid #e5e7eb;
  }
  
  .code-panel {
    flex: 0 0 30% !important;
    border-right: none;
    border-bottom: 3px solid #e5e7eb;
    max-height: 400px;
  }
  
  .control-panel {
    flex: 0 0 30% !important;
    max-height: 400px;
  }

  /* Hide resize handles on small screens */
  .resize-handle {
    display: none;
  }
}

/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.header {
  animation: slideIn 0.5s ease;
}

/* Tooltips */
.tooltip {
  position: relative;
  display: inline-block;
}

.tooltip .tooltiptext {
  visibility: hidden;
  width: 200px;
  background-color: #374151;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px;
  position: absolute;
  z-index: 1;
  bottom: 125%;
  left: 50%;
  margin-left: -100px;
  opacity: 0;
  transition: opacity 0.3s;
}

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
  .main-content {
    flex-direction: column;
  }
  
  .blockly-panel {
    width: 100%;
    height: 400px;
  }
  
  .control-panel {
    width: 100%;
    padding: 1rem;
  }
  
  .header-content {
    flex-direction: column;
    gap: 1rem;
  }
  
  .connection-panel {
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .header h1 {
    font-size: 1.5rem;
  }
  
  .blockly-panel {
    height: 300px;
  }
  
  .example-buttons {
    grid-template-columns: 1fr;
  }
  
  .telemetry-grid {
    grid-template-columns: 1fr 1fr;
  }
  
  .execution-controls {
    flex-direction: column;
  }
  
  .execution-controls button {
    width: 100%;
  }
  
  #gps-map {
    height: 250px !important;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0.5rem;
  }
  
  .header {
    padding: 0.75rem;
  }
  
  .telemetry-grid {
    grid-template-columns: 1fr;
  }
  
  #map-controls {
    flex-direction: column;
  }
  
  #map-controls button {
    width: 100%;
  }
}

/* Tutorial System Styles */
.tutorial-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.tutorial-overlay.active {
  display: flex;
}

.tutorial-card {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12px;
  padding: 2rem;
  max-width: 600px;
  width: 90%;
  color: white;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  position: relative;
  animation: slideUp 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(50px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.tutorial-card h2 {
  margin: 0 0 1rem 0;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tutorial-card p {
  font-size: 1.1rem;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.tutorial-card ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.tutorial-card ul li {
  padding: 0.5rem 0;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tutorial-card ul li:before {
  content: '✓';
  color: #4ade80;
  font-weight: bold;
  font-size: 1.2rem;
}

.tutorial-progress {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 1.5rem 0;
}

.tutorial-progress-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
}

.tutorial-progress-dot.active {
  background: white;
  width: 30px;
  border-radius: 5px;
}

.tutorial-buttons {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

.tutorial-buttons button {
  flex: 1;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tutorial-btn-primary {
  background: white;
  color: #667eea;
}

.tutorial-btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(255, 255, 255, 0.3);
}

.tutorial-btn-secondary {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid white;
}

.tutorial-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.3);
}

.tutorial-skip {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.tutorial-skip:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Tutorial Highlight */
.tutorial-highlight {
  position: relative;
  z-index: 9999;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.8);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.8), 0 0 20px 5px #667eea;
  }
  50% {
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.8), 0 0 30px 10px #764ba2;
  }
}

/* FLYQ Branding */
.flyq-brand {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 800;
}

.flyq-badge {
  display: inline-block;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 0.5rem;
}

/* Loading Spinner */
.flyq-spinner {
  border: 3px solid rgba(102, 126, 234, 0.2);
  border-top: 3px solid #667eea;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
  margin: 2rem auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
