/* CSS Reset & Base Styles */
* { 
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

:root {
  /* Light Theme (Default) */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent-primary: #3b82f6;
  --accent-primary-dark: #2563eb;
  --accent-secondary: #8b5cf6;
  --border-color: #e2e8f0;
  --border-color-light: #f1f5f9;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 8px 28px rgba(2, 6, 23, 0.08);
  --shadow-lg: 0 20px 40px rgba(2, 6, 23, 0.1);
  --status-ok: #10b981;
  --status-ok-bg: rgba(16, 185, 129, 0.1);
  --status-warn: #ef4444;
  --status-warn-bg: rgba(239, 68, 68, 0.1);
  --status-idle: #6b7280;
  --status-idle-bg: rgba(107, 114, 128, 0.1);
  --gradient-primary: linear-gradient(135deg, #3b82f6, #8b5cf6);
  --gradient-secondary: linear-gradient(135deg, #f8fafc, #e2e8f0);
}

[data-theme="dark"] {
  /* Dark Theme */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent-primary: #60a5fa;
  --accent-primary-dark: #3b82f6;
  --accent-secondary: #a78bfa;
  --border-color: #334155;
  --border-color-light: #1e293b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.3);
  --status-ok: #34d399;
  --status-ok-bg: rgba(52, 211, 153, 0.15);
  --status-warn: #f87171;
  --status-warn-bg: rgba(248, 113, 113, 0.15);
  --status-idle: #9ca3af;
  --status-idle-bg: rgba(156, 163, 175, 0.15);
  --gradient-primary: linear-gradient(135deg, #60a5fa, #a78bfa);
  --gradient-secondary: linear-gradient(135deg, #1e293b, #0f172a);
}

/* Base Styles */
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* Header Styles */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}

.header-left {
  flex: 1;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.logo i {
  font-size: 2.5rem;
  color: var(--accent-primary);
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-title {
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 500;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Switch Toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 30px;
}

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

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

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

input:checked + .slider {
  background: var(--gradient-primary);
}

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

/* Control Section */
.controls-section {
  margin-bottom: 32px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* Button Styles */
.btn {
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn.primary {
  background: var(--gradient-primary);
  color: white;
}

.btn.secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

.btn.warning {
  background: transparent;
  color: var(--status-warn);
  border: 1px solid var(--status-warn);
}

.btn.small {
  padding: 8px 16px;
  font-size: 0.85rem;
}

/* Main Grid Layout */
.main-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 24px;
  margin-bottom: 32px;
}

@media (max-width: 1100px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

/* Card Styles */
.card {
  background: var(--bg-card);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

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

.panel-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
}

/* Video Panel Styles */
.video-wrapper {
  position: relative;
  width: 100%;
  background: #000;
  aspect-ratio: 4/3;
  overflow: hidden;
}

.video, .canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-overlay {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.overlay-stats {
  display: flex;
  gap: 16px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
}

.stat-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
}

.video-controls {
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-color);
}

.video-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* Status Indicators */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-indicator::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-indicator.active::before {
  background-color: var(--status-ok);
}

.status-indicator.idle::before {
  background-color: var(--status-idle);
}

.status-indicator.warning::before {
  background-color: var(--status-warn);
}

/* Status Panel Styles */
.status-container {
  padding: 24px;
}

.status-badge {
  padding: 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1.2rem;
  text-align: center;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 2px solid transparent;
}

.badge-green {
  background: var(--status-ok-bg);
  color: var(--status-ok);
  border-color: var(--status-ok);
}

.badge-red {
  background: var(--status-warn-bg);
  color: var(--status-warn);
  border-color: var(--status-warn);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.8; }
  100% { opacity: 1; }
}

/* Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.metric-card {
  display: flex;
  gap: 16px;
  padding: 20px;
  border-radius: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
}

.metric-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
}

.metric-content {
  flex: 1;
}

.metric-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.metric-value {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  margin-bottom: 12px;
}

.metric-progress {
  margin-top: 12px;
}

.progress-bar {
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: var(--status-ok);
  width: 0%;
  transition: width 0.3s ease;
}

.progress-fill.warning {
  background: var(--status-warn);
}

.progress-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Parameters Card */
.params-card {
  padding: 20px;
  border-radius: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.params-card h4 {
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.params-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.param-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.param-item label {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.param-item input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  background: var(--border-color);
  border-radius: 3px;
  outline: none;
}

.param-item input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
}

.param-item input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  border: none;
}

.param-item span {
  align-self: flex-end;
  font-weight: 600;
  color: var(--accent-primary);
}

/* Alarm Status */
.alarm-status {
  padding: 20px;
  border-radius: 12px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  margin-bottom: 24px;
}

.alarm-status h4 {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.alarm-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
}

.indicator-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--status-idle);
}

.alarm-active .indicator-dot {
  background: var(--status-warn);
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Note Section */
.note {
  padding: 16px;
  border-radius: 10px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  display: flex;
  gap: 12px;
}

.note i {
  color: var(--status-warn);
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.note p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Footer */
.app-footer {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}

.footer-content p {
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.footer-copyright {
  font-size: 0.85rem;
  color: var(--text-muted) !important;
  margin-top: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 16px;
  }
  
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  
  .controls-grid {
    grid-template-columns: 1fr;
  }
  
  .overlay-stats {
    flex-direction: column;
    gap: 8px;
  }
  
  .metric-card {
    flex-direction: column;
  }
  
  .metric-icon {
    align-self: flex-start;
  }
}
