/* ============================================================
   Interaktiver Code-Editor Styles
   Split-Pane mit Live-Preview
   ============================================================ */

/* --- Editor Container --- */
.code-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: var(--spacing-lg) 0;
  background: var(--editor-bg);
}

/* --- Editor Header --- */
.code-editor__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-sm) var(--spacing-md);
  background: #2d2d2d;
  border-bottom: 1px solid #444;
}

.code-editor__filename {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #aaa;
}

.code-editor__actions {
  display: flex;
  gap: var(--spacing-sm);
}

.code-editor__btn {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  padding: 0.3em 0.8em;
  border: 1px solid #555;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #ccc;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.code-editor__btn:hover {
  background: #444;
  color: white;
}

.code-editor__btn--run {
  border-color: var(--unit-project);
  color: var(--unit-project);
}

.code-editor__btn--run:hover {
  background: var(--unit-project);
  color: white;
}

.code-editor__btn--reset {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.code-editor__btn--reset:hover {
  background: var(--color-danger);
  color: white;
}

/* --- Split Pane --- */
.code-editor__panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 300px;
}

.code-editor__panes--full {
  grid-template-columns: 1fr;
}

/* --- Code Input Area --- */
.code-editor__input {
  position: relative;
  background: var(--editor-bg);
}

.code-editor__textarea {
  width: 100%;
  height: 100%;
  min-height: 300px;
  padding: var(--spacing-md);
  background: transparent;
  color: var(--editor-text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  border: none;
  outline: none;
  resize: vertical;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.code-editor__textarea::placeholder {
  color: #555;
}

/* Line numbers overlay */
.code-editor__lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 3rem;
  padding: var(--spacing-md) 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  color: #555;
  pointer-events: none;
  user-select: none;
}

.code-editor__textarea--with-lines {
  padding-left: 3.5rem;
}

/* --- Preview Area --- */
.code-editor__preview {
  background: var(--bg);
  border-left: 1px solid #444;
  position: relative;
}

.code-editor__preview-label {
  position: absolute;
  top: var(--spacing-sm);
  right: var(--spacing-sm);
  font-size: 0.7rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
  background: rgba(255,255,255,0.9);
  padding: 0.1em 0.5em;
  border-radius: var(--radius-sm);
}

.code-editor__iframe {
  width: 100%;
  height: 100%;
  min-height: 300px;
  border: none;
  background: var(--bg);
}

/* --- Console Output --- */
.code-editor__console {
  background: #0d0d0d;
  border-top: 1px solid #333;
  padding: var(--spacing-sm) var(--spacing-md);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #aaa;
  max-height: 150px;
  overflow-y: auto;
  display: none;
}

.code-editor__console.active {
  display: block;
}

.code-editor__console-line {
  padding: 0.1em 0;
  border-bottom: 1px solid #1a1a1a;
}

.code-editor__console-line--error {
  color: var(--color-danger);
}

.code-editor__console-line--log {
  color: #d4d4d4;
}

/* --- Tabbed Editor (HTML + CSS + JS tabs) --- */
.code-editor__tabs {
  display: flex;
  background: #252525;
  border-bottom: 1px solid #444;
}

.code-editor__tab {
  padding: var(--spacing-sm) var(--spacing-md);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #888;
  border: none;
  background: transparent;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.code-editor__tab:hover {
  color: #ccc;
}

.code-editor__tab.active {
  color: #fff;
  border-bottom-color: var(--slide-accent);
  background: var(--editor-bg);
}

/* --- Standalone Preview (for exercises) --- */
.preview-only {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: var(--spacing-lg) 0;
}

.preview-only__header {
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.preview-only iframe {
  width: 100%;
  min-height: 200px;
  border: none;
}

/* --- Responsive Editor --- */
@media (max-width: 768px) {
  .code-editor__panes {
    grid-template-columns: 1fr;
  }

  .code-editor__preview {
    border-left: none;
    border-top: 1px solid #444;
  }

  .code-editor__textarea {
    min-height: 200px;
  }

  .code-editor__iframe {
    min-height: 200px;
  }
}
