/**
 * LARC Playground - Unified Styles
 * Supports Gallery, Builder, and Editor modes
 */

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

:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --secondary: #667eea;
  --secondary-dark: #764ba2;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;

  /* Light mode colors (default) */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  --color-bg: #f9fafb;
  --color-bg-alt: #ffffff;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-surface: #ffffff;
  --color-code-bg: #1f2937;
  --color-code-text: #e5e7eb;
}

/* Dark mode - System preference */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --gray-50: #111827;
    --gray-100: #1f2937;
    --gray-200: #374151;
    --gray-300: #4b5563;
    --gray-400: #6b7280;
    --gray-500: #9ca3af;
    --gray-600: #d1d5db;
    --gray-700: #e5e7eb;
    --gray-800: #f3f4f6;
    --gray-900: #f9fafb;

    --color-bg: #0f172a;
    --color-bg-alt: #1e293b;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-border: #334155;
    --color-surface: #1e293b;
    --color-code-bg: #020617;
    --color-code-text: #e2e8f0;

    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --secondary: #818cf8;
    --secondary-dark: #6366f1;
  }
}

/* Dark mode - Manual override */
[data-theme="dark"] {
  --gray-50: #111827;
  --gray-100: #1f2937;
  --gray-200: #374151;
  --gray-300: #4b5563;
  --gray-400: #6b7280;
  --gray-500: #9ca3af;
  --gray-600: #d1d5db;
  --gray-700: #e5e7eb;
  --gray-800: #f3f4f6;
  --gray-900: #f9fafb;

  --color-bg: #0f172a;
  --color-bg-alt: #1e293b;
  --color-text: #f1f5f9;
  --color-text-muted: #94a3b8;
  --color-border: #334155;
  --color-surface: #1e293b;
  --color-code-bg: #020617;
  --color-code-text: #e2e8f0;

  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --secondary: #818cf8;
  --secondary-dark: #6366f1;
}

/* Light mode - Manual override */
[data-theme="light"] {
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  --color-bg: #f9fafb;
  --color-bg-alt: #ffffff;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-surface: #ffffff;
  --color-code-bg: #1f2937;
  --color-code-text: #e5e7eb;

  --primary: #2563eb;
  --primary-dark: #1e40af;
  --secondary: #667eea;
  --secondary-dark: #764ba2;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  overflow: hidden;
}

.playground-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ==================== HEADER ==================== */

.pg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 100;
}

/* Dark mode header - make it darker and more subtle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pg-header {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    border-bottom: 1px solid var(--color-border);
  }
}

[data-theme="dark"] .pg-header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  border-bottom: 1px solid var(--color-border);
}

.pg-logo h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.pg-logo p {
  font-size: 0.875rem;
  opacity: 0.9;
}

.pg-mode-tabs {
  display: flex;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.25rem;
  border-radius: 8px;
}

/* Dark mode tabs */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pg-mode-tabs {
    background: rgba(0, 0, 0, 0.4);
  }
}

[data-theme="dark"] .pg-mode-tabs {
  background: rgba(0, 0, 0, 0.4);
}

.mode-tab {
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-tab:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.mode-tab.active {
  background: white;
  color: var(--primary);
}

/* Dark mode active tab */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mode-tab.active {
    background: rgba(255, 255, 255, 0.15);
    color: #60a5fa;
  }
}

[data-theme="dark"] .mode-tab.active {
  background: rgba(255, 255, 255, 0.15);
  color: #60a5fa;
}

.pg-actions {
  display: flex;
  gap: 0.75rem;
}

.btn-monitor {
  padding: 0.75rem 1.25rem;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
}

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

/* Dark mode monitor button */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-monitor {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
  }

  :root:not([data-theme="light"]) .btn-monitor:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
  }
}

[data-theme="dark"] .btn-monitor {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .btn-monitor:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

/* ==================== MAIN CONTENT ==================== */

.pg-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.pg-mode {
  display: none;
  height: 100%;
  overflow: auto;
}

.pg-mode.active {
  display: block;
}

/* ==================== GALLERY MODE ==================== */

#gallery-mode {
  padding: 2rem;
  background: var(--color-bg);
}

.gallery-header {
  max-width: 1400px;
  margin: 0 auto 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.gallery-header h2 {
  font-size: 2rem;
  color: var(--color-text);
  font-weight: 700;
}

.gallery-controls {
  display: flex;
  gap: 1rem;
}

.search-input,
.filter-select {
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 0.875rem;
  background: var(--color-surface);
  color: var(--color-text);
  transition: all 0.2s;
}

.search-input {
  width: 300px;
}

.search-input:focus,
.filter-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.example-card {
  background: var(--color-surface);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.3s;
  display: flex;
  flex-direction: column;
}

.example-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.example-preview {
  height: 200px;
  background: linear-gradient(135deg, var(--gray-100) 0%, var(--gray-200) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: hidden;
  position: relative;
}

.example-preview-content {
  transform: scale(0.8);
  transform-origin: center;
  width: 100%;
  max-height: 180px;
  overflow: hidden;
}

.example-preview::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 0%, var(--color-surface) 100%);
  pointer-events: none;
}

.example-info {
  padding: 1.25rem;
  flex: 1;
}

.example-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}

.example-description {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  line-height: 1.6;
  margin-bottom: 1rem;
}

.example-components {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.components-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.components-list {
  font-size: 0.75rem;
  background: var(--color-bg);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  color: var(--color-text);
  font-family: 'Monaco', 'Courier New', monospace;
}

.example-actions {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
}

.btn-example-action {
  flex: 1;
  padding: 0.75rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  background: var(--primary-dark);
}

/* Dark mode primary button */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary {
    background: var(--primary);
  }

  :root:not([data-theme="light"]) .btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(96, 165, 250, 0.4);
  }
}

[data-theme="dark"] .btn-primary {
  background: var(--primary);
}

[data-theme="dark"] .btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(96, 165, 250, 0.4);
}

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

.btn-secondary:hover {
  background: var(--color-bg-alt);
}

/* ==================== BUILDER MODE ==================== */

#builder-mode.active {
  display: flex;
  flex-direction: column;
}

.builder-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.builder-sidebar {
  width: 280px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
}

.builder-canvas-area {
  flex: 1;
  background: var(--color-bg);
  overflow-y: auto;
}

.builder-properties {
  width: 320px;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
}

.builder-code-panel {
  height: 300px;
  border-top: 2px solid var(--secondary);
  background: var(--color-code-bg);
  overflow-y: auto;
  color: var(--color-code-text);
}

/* ==================== EDITOR MODE ==================== */

.editor-layout {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.editor-panes {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.editor-code-pane {
  width: 50%;
  display: flex;
  flex-direction: column;
  background: var(--color-code-bg);
  border-right: 1px solid #374151;
}

.editor-tabs {
  display: flex;
  background: #1f2937;
  border-bottom: 1px solid #374151;
}

.editor-tab {
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
}

.editor-tab:hover {
  color: white;
  background: rgba(255, 255, 255, 0.05);
}

.editor-tab.active {
  color: white;
  border-bottom-color: var(--primary);
  background: rgba(96, 165, 250, 0.15);
}

.editor-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.editor-area {
  display: none;
  height: 100%;
}

.editor-area.active {
  display: block;
}

.code-editor {
  width: 100%;
  height: 100%;
  padding: 1.5rem;
  background: var(--color-code-bg);
  color: var(--color-code-text);
  border: none;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  tab-size: 2;
}

.code-editor:focus {
  outline: none;
}

.editor-toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  background: #1f2937;
  border-top: 1px solid #374151;
}

.editor-toolbar button {
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

#run-code {
  background: var(--success);
  color: white;
}

#run-code:hover {
  background: #059669;
}

.editor-preview-pane {
  width: 50%;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.preview-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.preview-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
}

.btn-icon:hover {
  background: var(--color-bg);
}

.preview-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--color-surface);
}

/* ==================== BUS MONITOR OVERLAY ==================== */

.monitor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.monitor-panel {
  background: var(--color-surface);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 900px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.monitor-header h3 {
  font-size: 1.25rem;
  color: var(--color-text);
  font-weight: 600;
}

.btn-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--color-text-muted);
  transition: all 0.2s;
}

.btn-close:hover {
  background: var(--color-bg-alt);
  color: var(--color-text);
}

/* ==================== UTILITIES ==================== */

[hidden] {
  display: none !important;
}

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

::-webkit-scrollbar-track {
  background: var(--color-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--color-text-muted);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-text);
}

/* Dark scrollbars for editor */
.code-editor::-webkit-scrollbar-track {
  background: #1f2937;
}

.code-editor::-webkit-scrollbar-thumb {
  background: #4b5563;
}

.code-editor::-webkit-scrollbar-thumb:hover {
  background: #6b7280;
}

/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* Responsive */
@media (max-width: 1200px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }

  .editor-panes {
    flex-direction: column;
  }

  .editor-code-pane,
  .editor-preview-pane {
    width: 100%;
  }

  .editor-preview-pane {
    height: 400px;
  }
}

@media (max-width: 768px) {
  .pg-header {
    flex-direction: column;
    gap: 1rem;
  }

  .gallery-controls {
    flex-direction: column;
    width: 100%;
  }

  .search-input {
    width: 100%;
  }

  .builder-layout {
    flex-direction: column;
  }

  .builder-sidebar,
  .builder-properties {
    width: 100%;
    height: 200px;
  }
}
