/* ===================================================================
   SOA Rich Text Editor — soa-rich-editor.css v1.0.0
   =================================================================== */

/* ── Variables SOA ──────────────────────────────────────────────── */
.soa-rich {
  --soa-purple:  #6c63ff;
  --soa-blue:    #4a90d9;
  --soa-green:   #27ae60;
  --soa-grad:    radial-gradient(ellipse at top left, #1a1a2e 0%, #16213e 40%, #0f3460 100%);
  --soa-text:    #e8e8f0;
  --soa-muted:   #9999bb;

  /* Thème sombre éditeur de code */
  --ed-bg:     #1e2433;
  --ed-bar:    #161b27;
  --ed-border: #2a3050;
  --ed-nums:   #4a5570;
  --ed-code:   #cdd6f4;

  /* Couleurs d'onglets */
  --col-html: #e44d26;
  --col-css:  #2196d3;
  --col-js:   #f0db4f;

  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--soa-text);
  max-width: 1260px;
  margin: 0 auto;
  padding: 0.5rem;
  box-sizing: border-box;
}

.soa-rich *,
.soa-rich *::before,
.soa-rich *::after { box-sizing: border-box; }

/* ── Carte / Hero ───────────────────────────────────────────────── */
.soa-rich__card {
  background: var(--soa-grad);
  border-radius: 16px;
  padding: 2rem 2.5rem 1.8rem;
  margin-bottom: 1.2rem;
}

.soa-rich__eyebrow {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--soa-purple);
  margin-bottom: 0.5rem;
}

.soa-rich__title {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 800;
  margin: 0 0 0.4rem;
  line-height: 1.2;
  background: linear-gradient(135deg, #fff 30%, #a89dff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.soa-rich__subtitle {
  font-size: 0.88rem;
  color: var(--soa-muted);
  margin: 0;
  line-height: 1.5;
}

/* ── Plan de travail ────────────────────────────────────────────── */
.soa-rich__workbench {
  background: var(--ed-bg);
  border: 1px solid var(--ed-border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Barre haute ────────────────────────────────────────────────── */
.soa-rich__topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--ed-bar);
  border-bottom: 1px solid var(--ed-border);
  padding: 0.4rem 0.7rem;
  flex-wrap: wrap;
}

/* Onglets */
.soa-rich__tabs {
  display: flex;
  gap: 0.2rem;
}

.soa-rich__tab {
  background: transparent;
  border: none;
  color: var(--soa-muted);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.3rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.soa-rich__tab:hover { background: rgba(255,255,255,0.06); color: #fff; }
.soa-rich__tab--html.soa-rich__tab--active { color: var(--col-html); background: rgba(228, 77, 38, 0.12); }
.soa-rich__tab--css.soa-rich__tab--active  { color: var(--col-css);  background: rgba( 33,150,211, 0.12); }
.soa-rich__tab--js.soa-rich__tab--active   { color: var(--col-js);   background: rgba(240,219, 79, 0.12); }

/* Contrôles */
.soa-rich__controls {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.soa-rich__sep {
  width: 1px;
  height: 18px;
  background: var(--ed-border);
  margin: 0 0.15rem;
  flex-shrink: 0;
}

/* Boutons de la barre haute */
.soa-rich__btn-run,
.soa-rich__btn-auto,
.soa-rich__layout-btn,
.soa-rich__btn-fs {
  background: transparent;
  border: 1px solid var(--ed-border);
  color: var(--soa-muted);
  font-size: 0.74rem;
  padding: 0.22rem 0.55rem;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}
.soa-rich__btn-run:hover,
.soa-rich__btn-auto:hover,
.soa-rich__layout-btn:hover,
.soa-rich__btn-fs:hover {
  background: rgba(255,255,255,0.07);
  color: #fff;
  border-color: #4a5070;
}

.soa-rich__btn-run { color: #6effa0; border-color: rgba(110,255,160,0.3); }
.soa-rich__btn-run:hover { background: rgba(110,255,160,0.08); border-color: #6effa0; }

.soa-rich__layout-btn--active {
  background: rgba(108,99,255,0.18);
  border-color: var(--soa-purple);
  color: var(--soa-purple);
}

.soa-rich__auto-state { font-weight: 700; color: #6effa0; }
.soa-rich__btn-auto--off .soa-rich__auto-state { color: #ff7070; }

/* ── Zone divisée ───────────────────────────────────────────────── */
.soa-rich__split {
  display: flex;
  flex: 1;
  min-height: 520px;
  overflow: hidden;
}

/* ── Volet éditeur de code ──────────────────────────────────────── */
.soa-rich__editor-pane {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  background: var(--ed-bg);
  border-right: 1px solid var(--ed-border);
  min-width: 0;
  overflow: hidden;
}

.soa-rich__editor-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.soa-rich__editor-wrap--hidden { display: none !important; }

/* Numéros de ligne */
.soa-rich__line-nums {
  flex-shrink: 0;
  width: 42px;
  background: var(--ed-bar);
  border-right: 1px solid var(--ed-border);
  font: 13px/22px 'Consolas', 'Courier New', monospace;
  color: var(--ed-nums);
  text-align: right;
  padding: 0.5rem 6px 0.5rem 0;
  overflow: hidden;
  user-select: none;
  white-space: pre;
}

/* Zone de code */
.soa-rich__code {
  flex: 1;
  background: var(--ed-bg);
  color: var(--ed-code);
  border: none;
  outline: none;
  resize: none;
  font: 13px/22px 'Consolas', 'Courier New', monospace;
  padding: 0.5rem 0.7rem;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}
.soa-rich__code::selection { background: rgba(108,99,255,0.35); }

/* ── Poignée de redimensionnement ───────────────────────────────── */
.soa-rich__resize-handle {
  flex-shrink: 0;
  width: 4px;
  background: var(--ed-border);
  cursor: col-resize;
  transition: background 0.15s;
  z-index: 5;
}
.soa-rich__resize-handle:hover,
.soa-rich__resize-handle:active { background: var(--soa-purple); }

/* ── Volet WYSIWYG ──────────────────────────────────────────────── */
.soa-rich__canvas-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f5f5fa;
  min-width: 0;
  overflow: hidden;
}

/* ── Barre de mise en forme ─────────────────────────────────────── */
.soa-rich__fmt-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.12rem;
  background: #ffffff;
  border-bottom: 1px solid #dcdee8;
  padding: 0.35rem 0.6rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  flex-shrink: 0;
}

.soa-rich__fmt-sep {
  width: 1px;
  height: 20px;
  background: #dcdee8;
  margin: 0 0.18rem;
  flex-shrink: 0;
}

/* Sélecteur de bloc */
.soa-rich__fmt-select {
  height: 26px;
  font-size: 0.75rem;
  border: 1px solid #dcdee8;
  border-radius: 4px;
  background: #fff;
  color: #2a2a3e;
  padding: 0 0.5rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}
.soa-rich__fmt-select:focus { border-color: var(--soa-purple); }

/* Boutons de mise en forme */
.soa-rich__fmt-btn {
  background: transparent;
  border: 1px solid transparent;
  color: #2a2a3e;
  font-size: 0.82rem;
  min-width: 27px;
  height: 27px;
  padding: 0 0.28rem;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
  line-height: 1;
  font-family: inherit;
}
.soa-rich__fmt-btn:hover    { background: #edf0ff; border-color: #dcdee8; }
.soa-rich__fmt-btn--active  { background: #e0e4ff; border-color: var(--soa-purple); color: var(--soa-purple); }

.soa-rich__fmt-btn strong { font-weight: 900; }
.soa-rich__fmt-btn em     { font-style: italic; }
.soa-rich__fmt-btn u      { text-decoration: underline; }
.soa-rich__fmt-btn s      { text-decoration: line-through; }

/* Sélecteurs de couleur */
.soa-rich__color-wrap {
  display: inline-flex;
  align-items: center;
  flex-direction: column;
  gap: 1px;
  cursor: pointer;
  position: relative;
  width: 27px;
  height: 27px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 3px 4px 2px;
  transition: background 0.12s, border-color 0.12s;
  justify-content: center;
}
.soa-rich__color-wrap:hover { background: #edf0ff; border-color: #dcdee8; }

.soa-rich__color-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #2a2a3e;
  line-height: 1;
  display: block;
}
.soa-rich__color-label--bg { text-decoration: underline; text-decoration-style: double; }

.soa-rich__color-swatch {
  display: block;
  width: 16px;
  height: 4px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.15);
}

.soa-rich__color-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: none;
  padding: 0;
}

/* ── Zone de saisie WYSIWYG (canvas) ───────────────────────────── */
.soa-rich__canvas {
  flex: 1;
  background: #ffffff;
  color: #1a1a2e;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1rem;
  line-height: 1.75;
  padding: 2rem 2.8rem;
  overflow-y: auto;
  outline: none;
  border: none;
  min-height: 180px;
}

/* Placeholder */
.soa-rich__canvas:empty::before {
  content: attr(data-placeholder);
  color: #b0b0c8;
  pointer-events: none;
  font-style: italic;
}

/* Contenu par défaut du canvas */
.soa-rich__canvas h1 { font-size: 1.9rem; font-weight: 700; margin: 0.4em 0 0.3em; line-height: 1.2; }
.soa-rich__canvas h2 { font-size: 1.45rem; font-weight: 700; margin: 0.6em 0 0.25em; line-height: 1.25; }
.soa-rich__canvas h3 { font-size: 1.18rem; font-weight: 700; margin: 0.7em 0 0.2em; }
.soa-rich__canvas h4 { font-size: 1.05rem; font-weight: 700; margin: 0.75em 0 0.2em; }
.soa-rich__canvas p  { margin: 0 0 0.75em; }
.soa-rich__canvas ul,
.soa-rich__canvas ol { padding-left: 1.6em; margin: 0 0 0.75em; }
.soa-rich__canvas li { margin-bottom: 0.25em; }
.soa-rich__canvas blockquote {
  margin: 1em 0;
  padding: 0.75em 1.2em;
  border-left: 4px solid var(--soa-purple);
  background: #f5f4ff;
  color: #555;
  font-style: italic;
  border-radius: 0 6px 6px 0;
}
.soa-rich__canvas pre {
  background: #1e2433;
  color: #cdd6f4;
  padding: 1em 1.2em;
  border-radius: 6px;
  font: 0.84rem/1.5 'Consolas', 'Courier New', monospace;
  overflow-x: auto;
  margin: 0.8em 0;
  white-space: pre;
}
.soa-rich__canvas a           { color: var(--soa-purple); text-decoration: underline; }
.soa-rich__canvas a:hover     { color: var(--soa-blue); }
.soa-rich__canvas img         { max-width: 100%; height: auto; border-radius: 4px; }
.soa-rich__canvas hr          { border: none; border-top: 2px solid #e0e0ee; margin: 1.5em 0; }
.soa-rich__canvas table       { border-collapse: collapse; width: 100%; margin: 1em 0; }
.soa-rich__canvas th,
.soa-rich__canvas td          { border: 1px solid #dcdee8; padding: 0.45em 0.75em; }
.soa-rich__canvas th          { background: #f0f0f8; font-weight: 700; text-align: left; }

/* ── Barre du bas ───────────────────────────────────────────────── */
.soa-rich__bottombar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--ed-bar);
  border-top: 1px solid var(--ed-border);
  padding: 0.42rem 0.7rem;
  flex-wrap: wrap;
}

.soa-rich__btn-copy,
.soa-rich__btn-download,
.soa-rich__btn-format,
.soa-rich__btn-clear {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--ed-border);
  color: var(--soa-text);
  font-size: 0.76rem;
  padding: 0.28rem 0.7rem;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.15s;
}
.soa-rich__btn-copy:hover,
.soa-rich__btn-download:hover,
.soa-rich__btn-format:hover {
  background: rgba(255,255,255,0.1);
  border-color: #4a5070;
}
.soa-rich__btn-clear            { color: #ff8a8a; border-color: rgba(255,138,138,0.3); }
.soa-rich__btn-clear:hover      { background: rgba(255,138,138,0.1); border-color: #ff8a8a; }

.soa-rich__status {
  margin-left: auto;
  font: 0.7rem/1 'Consolas', 'Courier New', monospace;
  color: var(--soa-muted);
  white-space: nowrap;
}

/* ── Dispositions ───────────────────────────────────────────────── */

/* ↔ Côte à côte (défaut) */
.soa-rich__workbench--lr .soa-rich__split       { flex-direction: row; }
.soa-rich__workbench--lr .soa-rich__resize-handle { width: 4px; height: auto; cursor: col-resize; }

/* ↕ Haut / bas */
.soa-rich__workbench--tb .soa-rich__split         { flex-direction: column; }
.soa-rich__workbench--tb .soa-rich__editor-pane   { flex: 0 0 50%; border-right: none; border-bottom: 1px solid var(--ed-border); }
.soa-rich__workbench--tb .soa-rich__resize-handle { width: auto; height: 4px; cursor: row-resize; }

/* ▤ Éditeur seul */
.soa-rich__workbench--editor .soa-rich__canvas-pane  { display: none; }
.soa-rich__workbench--editor .soa-rich__resize-handle { display: none; }
.soa-rich__workbench--editor .soa-rich__editor-pane  { flex: 1; border-right: none; }

/* ▶ Canvas seul */
.soa-rich__workbench--canvas .soa-rich__editor-pane   { display: none; }
.soa-rich__workbench--canvas .soa-rich__resize-handle { display: none; }

/* ── Plein écran ────────────────────────────────────────────────── */
.soa-rich__workbench--fullscreen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  border-radius: 0;
  border: none;
}
.soa-rich__workbench--fullscreen .soa-rich__split { min-height: 0; flex: 1; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .soa-rich__card { padding: 1.5rem 1.2rem; }

  /* Côte à côte → Haut/bas sur mobile */
  .soa-rich__workbench--lr .soa-rich__split       { flex-direction: column; }
  .soa-rich__workbench--lr .soa-rich__editor-pane { flex: 0 0 50%; border-right: none; border-bottom: 1px solid var(--ed-border); }
  .soa-rich__workbench--lr .soa-rich__resize-handle { width: auto; height: 4px; cursor: row-resize; }

  .soa-rich__split    { min-height: 420px; }
  .soa-rich__canvas   { padding: 1.2rem 1.5rem; }
  .soa-rich__fmt-bar  { gap: 0.08rem; padding: 0.3rem 0.4rem; }
  .soa-rich__controls { gap: 0.2rem; }
}

@media (max-width: 480px) {
  .soa-rich__split  { min-height: 360px; }
  .soa-rich__canvas { padding: 1rem 1rem; font-size: 0.92rem; }
  .soa-rich__fmt-select { font-size: 0.7rem; }
}
