/* ==========================================================================
   CodeEditor Pro - Modern Dark UI Stylesheet (v2.1.0)
   ========================================================================== */

:root {
  --bg-dark: #0d1117;
  --bg-darker: #090d13;
  --bg-card: #161b22;
  --bg-card-hover: #1f242c;
  --bg-input: #0b0f14;
  --border-color: #30363d;
  --border-light: rgba(255, 255, 255, 0.08);

  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --text-dim: #484f58;

  --accent-cyan: #38bdf8;
  --accent-blue: #2563eb;
  --accent-purple: #a855f7;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;

  --html-color: #f97316;
  --css-color: #06b6d4;
  --js-color: #eab308;

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Navigation Bar
   ========================================================================== */
.navbar {
  height: 56px;
  background-color: rgba(13, 17, 23, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 100;
  flex-shrink: 0;
}

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

.brand-logo {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #2563eb 0%, #a855f7 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 0 16px rgba(168, 85, 247, 0.35);
}

.brand-title {
  font-weight: 800;
  font-size: 1.12rem;
  letter-spacing: -0.02em;
}

.gradient-text {
  background: linear-gradient(135deg, #38bdf8, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  letter-spacing: 0.05em;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.header-center {
  flex: 1;
  max-width: 320px;
}

.template-selector-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: border-color 0.2s;
}

.template-selector-wrap:focus-within {
  border-color: var(--accent-cyan);
}

.template-selector-wrap select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  outline: none;
  width: 100%;
  cursor: pointer;
}

.template-selector-wrap select option {
  background-color: var(--bg-card);
  color: var(--text-main);
}

/* Actions */
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: var(--font-sans);
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.45);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.icon-btn.active {
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
}

.icon-btn.danger:hover {
  color: var(--accent-red);
  border-color: var(--accent-red);
  background: rgba(239, 68, 68, 0.12);
}

.view-toggles {
  display: flex;
  background: var(--bg-card);
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  gap: 2px;
}

.view-toggles .icon-btn {
  border: none;
  background: transparent;
  width: 30px;
  height: 30px;
}

.view-toggles .icon-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

/* Auto Run Switch */
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.toggle-switch input {
  display: none;
}

.toggle-slider {
  width: 34px;
  height: 18px;
  background-color: var(--border-color);
  border-radius: 20px;
  position: relative;
  transition: background-color 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background-color: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent-green);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

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

/* ==========================================================================
   Tab Navigation (for Single-Tab Mode or Small Screens)
   ========================================================================== */
.editor-tabs-bar {
  display: flex;
  background: var(--bg-darker);
  border-bottom: 1px solid var(--border-color);
  padding: 0 8px;
  gap: 4px;
  flex-shrink: 0;
}

.editor-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.editor-tab:hover {
  color: var(--text-main);
}

.editor-tab.active {
  color: var(--text-main);
  border-bottom-color: var(--accent-cyan);
  background: rgba(255, 255, 255, 0.04);
}

.tab-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.html-ind { background-color: var(--html-color); }
.css-ind { background-color: var(--css-color); }
.js-ind { background-color: var(--js-color); }

/* ==========================================================================
   Main Workspace Layouts
   ========================================================================== */
.workspace {
  flex: 1;
  display: flex;
  overflow: hidden;
  height: calc(100vh - 56px - 28px);
  position: relative;
}

/* --- Layout 1: Side-by-Side (Desktop Default) --- */
body.layout-side .workspace {
  flex-direction: row;
}

body.layout-side .editors-container:not(.tabbed-mode) {
  width: 50%;
  height: 100%;
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: 1fr;
  border-right: 2px solid var(--border-color);
  border-bottom: none;
}

body.layout-side .editors-container:not(.tabbed-mode) .pane {
  border-right: none;
  border-bottom: 1px solid var(--border-color);
}

body.layout-side .editors-container:not(.tabbed-mode) .pane:last-child {
  border-bottom: none;
}

body.layout-side .output-container {
  width: 50%;
  height: 100%;
}

/* --- Layout 2: Top-Bottom Stack --- */
body.layout-stack .workspace {
  flex-direction: column;
}

body.layout-stack .editors-container:not(.tabbed-mode) {
  width: 100%;
  height: 52%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 1fr;
  border-bottom: 2px solid var(--border-color);
  border-right: none;
}

body.layout-stack .editors-container:not(.tabbed-mode) .pane {
  border-right: 1px solid var(--border-color);
  border-bottom: none;
}

body.layout-stack .editors-container:not(.tabbed-mode) .pane:last-child {
  border-right: none;
}

body.layout-stack .output-container {
  width: 100%;
  height: 48%;
}

/* --- Layout 3: Tabbed Mode (Single Active Pane) --- */
.editors-container.tabbed-mode {
  display: block !important;
  width: 50% !important;
  height: 100% !important;
}

body.layout-stack .editors-container.tabbed-mode {
  width: 100% !important;
  height: 52% !important;
}

.editors-container.tabbed-mode .pane {
  width: 100% !important;
  height: 100% !important;
  border: none !important;
}

/* Base Pane Elements */
.pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-input);
  overflow: hidden;
  position: relative;
  min-height: 0;
  min-width: 0;
}

.pane-header {
  height: 32px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.pane-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
}

.lang-icon {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
}

.html-tag { background: rgba(249, 115, 22, 0.15); color: var(--html-color); }
.css-tag { background: rgba(6, 182, 212, 0.15); color: var(--css-color); }
.js-tag { background: rgba(234, 179, 8, 0.15); color: var(--js-color); }

.mini-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.mini-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--border-color);
}

/* Editor Wrapper & Line Numbers */
.editor-wrapper {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  background-color: #0b0f14;
  min-height: 0;
}

.line-numbers {
  width: 44px;
  background-color: #080c10;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 10px 6px;
  text-align: right;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid rgba(255, 255, 255, 0.04);
  box-sizing: border-box;
}

.code-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #e6edf3;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 10px 14px;
  resize: none;
  white-space: pre;
  tab-size: 2;
  overflow-y: auto;
  overflow-x: auto;
  box-sizing: border-box;
}

.code-input::placeholder {
  color: #3b434d;
}

/* ==========================================================================
   Output & Live Preview
   ========================================================================== */
.output-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  position: relative;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

.output-header {
  height: 34px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-main);
  flex-shrink: 0;
}

.output-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
}

.live-pulse {
  width: 8px;
  height: 8px;
  background-color: var(--accent-green);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulseAnim 2s infinite;
}

@keyframes pulseAnim {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.error-pill {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.2);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.4);
  cursor: pointer;
  font-weight: 600;
  animation: pulseAnim 1.5s infinite;
}

.output-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--accent-red);
  color: #fff;
  font-weight: 700;
}

.preview-stage {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  position: relative;
  background: #ffffff;
}

.preview {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
  display: block;
}

/* ==========================================================================
   Fullscreen Mode
   ========================================================================== */
body.preview-fullscreen .navbar,
body.preview-fullscreen .editors-container,
body.preview-fullscreen .statusbar,
body.preview-fullscreen .editor-tabs-bar {
  display: none !important;
}

body.preview-fullscreen .workspace,
body.preview-fullscreen .output-container {
  width: 100vw !important;
  height: 100vh !important;
}

.exit-fullscreen-btn {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  background: rgba(13, 17, 23, 0.85);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: all 0.2s;
}

.exit-fullscreen-btn:hover {
  background: #ef4444;
  border-color: #ef4444;
}

body.preview-fullscreen .exit-fullscreen-btn {
  display: block;
}

/* ==========================================================================
   Virtual Console Drawer
   ========================================================================== */
.console-drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 190px;
  background: rgba(13, 17, 23, 0.98);
  border-top: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  z-index: 50;
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.console-drawer.open {
  transform: translateY(0);
}

.console-header {
  height: 32px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.console-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--text-main);
}

.console-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.console-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
}

.console-log-msg {
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  display: flex;
  gap: 8px;
  word-break: break-all;
}

.console-system { color: var(--text-muted); font-style: italic; }
.console-log { color: #d1d5db; }
.console-warn { color: var(--accent-amber); background: rgba(245, 158, 11, 0.05); }
.console-error { color: var(--accent-red); background: rgba(239, 68, 68, 0.1); font-weight: 600; }
.console-info { color: var(--accent-cyan); }

/* ==========================================================================
   Status Bar
   ========================================================================== */
.statusbar {
  height: 28px;
  background: var(--bg-darker);
  border-top: 1px solid var(--border-color);
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.73rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-green);
}

.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
}

.status-pill.status-compiling {
  background: rgba(234, 179, 8, 0.12);
  color: var(--accent-amber);
}

.status-pill.status-compiling .dot {
  background: var(--accent-amber);
}

.shortcut-hint {
  color: var(--text-dim);
}

/* ==========================================================================
   Scrollbar & Responsive Media Queries
   ========================================================================== */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

@media (max-width: 900px) {
  body.layout-side .workspace {
    flex-direction: column !important;
  }

  body.layout-side .editors-container:not(.tabbed-mode) {
    width: 100% !important;
    height: 52% !important;
    grid-template-rows: 1fr !important;
    grid-template-columns: repeat(3, 1fr) !important;
    border-right: none !important;
    border-bottom: 2px solid var(--border-color) !important;
  }

  body.layout-side .output-container {
    width: 100% !important;
    height: 48% !important;
  }

  .header-center {
    display: none;
  }
}
