:root {
  --bg-dark: #1a1510;
  --bg-panel: #25201a;
  --border: #4a3f35;
  --accent: #b88d5e;
  --accent-hover: #d4a76a;
  --text: #e8dcc8;
  --text-dim: #a89885;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  padding: 12px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
}

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

.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn.primary {
  background: var(--accent);
  color: #1a1510;
}
.btn.primary:hover { background: var(--accent-hover); }

.btn.secondary {
  background: var(--border);
  color: var(--text);
}
.btn.secondary:hover { background: #5a4f45; }

.status {
  font-size: 0.85rem;
  color: var(--text-dim);
  padding: 4px 10px;
  background: rgba(184, 141, 94, 0.15);
  border-radius: 4px;
}

/* Split view */
.split-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}
.panel:last-child { border-right: none; }

.panel-header {
  padding: 10px 16px;
  background: rgba(184, 141, 94, 0.1);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}
.panel-header h2 { font-size: 1rem; color: var(--accent); }
.panel-header .hint { font-size: 0.75rem; color: var(--text-dim); }

/* Éditeur */
.editor-panel #markdownEditor {
  flex: 1;
  width: 100%;
  border: none;
  resize: none;
  padding: 16px;
  background: var(--bg-panel);
  color: var(--text);
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
}

/* CodeMirror override */
.CodeMirror {
  flex: 1;
  font-size: 14px;
  background: var(--bg-panel) !important;
  color: var(--text) !important;
}
.CodeMirror-gutters { background: #1e1812 !important; border-right: 1px solid var(--border); }

/* Aperçu */
.preview-panel { background: #0f0d0b; }
.preview-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#previewFrame {
  width: 100%;
  height: 100%;
  border: none;
  background: #f8ebd0;
}
#previewLoading {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(26, 21, 16, 0.95);
  color: var(--accent);
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 500;
  display: none;
  z-index: 10;
}
#previewLoading.active { display: block; }

/* Responsive */
@media (max-width: 900px) {
  .split-view { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .panel { border-right: none; border-bottom: 1px solid var(--border); }
  .panel:last-child { border-bottom: none; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-panel); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* === APERÇU IFRAME === */
.preview-container {
  flex: 1;
  position: relative;
  overflow: auto; /* Permet le scroll si besoin */
  background: #1a1510; /* Fond sombre pour mettre en valeur la page */
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
}

#previewFrame {
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-height: 100%;
  border: none;
  background: transparent;
  flex-shrink: 0;
}

/* Supprime les marges par défaut de l'iframe */
#previewFrame {
  display: block;
}
