/**
 * Article Content Styles
 * Styles pour le contenu des articles de blog MineStrator
 * Applique la charte graphique au HTML généré par le WYSIWYG
 *
 * SYNCHRONISÉ avec le backend TipTap Editor (Stargate)
 * Dernière mise à jour : 09/12/2024
 */

/* ==========================================================================
   ARTICLE CONTENT - Espacements synchronisés avec TipTap Editor
   ========================================================================== */

/* --- VARIABLES --- */
.article-content-styled {
  --msr-primary: #009b72;
  --msr-primary-hover: #007a5a;
  --msr-primary-light: #f0fdf9;
  --msr-text: #2C3038;
  --msr-text-strong: #1a1d21;
  --msr-code-bg: #ecfdf5;
  --msr-code-text: #059669;
  --msr-code-block-bg: #282c34;
  --msr-code-block-text: #abb2bf;
}

/* --- BASE --- */
.article-content-styled {
  font-family: 'DM Sans', 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1.05rem;           /* ~16.8px */
  line-height: 1.8;
  font-weight: 400;             /* IMPORTANT: pas de gras par défaut */
  color: var(--msr-text);
}

/* --- MÉDIAS --- */
/* Images, vidéos, code et tableaux en pleine largeur */
.article-content-styled img,
.article-content-styled video,
.article-content-styled pre,
.article-content-styled table {
  max-width: 100%;
}

/* --- TITRES H2 --- */
.article-content-styled h2 {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.75rem;           /* 28px */
  font-weight: 700;
  color: var(--msr-text);
  margin-top: 2em;              /* ~56px - ESPACE AVANT (CRITIQUE) */
  margin-bottom: 0.75em;        /* ~21px - ESPACE APRÈS */
  padding-bottom: 0.5em;        /* ~14px */
  border-bottom: 3px solid var(--msr-primary);
  line-height: 1.3;
}

/* Premier H2 sans marge haute */
.article-content-styled > h2:first-child {
  margin-top: 0;
}

/* --- TITRES H3 --- */
.article-content-styled h3 {
  font-family: 'DM Sans', sans-serif;
  font-size: 1.4rem;            /* ~22px */
  font-weight: 600;
  color: var(--msr-text);
  margin-top: 1.5em;            /* ~33px */
  margin-bottom: 0.5em;         /* ~11px */
  line-height: 1.4;
}

.article-content-styled > h3:first-child {
  margin-top: 0;
}

/* --- PARAGRAPHES --- */
.article-content-styled p {
  margin-bottom: 1.2em;         /* ~20px */
  font-weight: 400;
}

.article-content-styled p:last-child {
  margin-bottom: 0;
}

/* --- LISTES --- */
.article-content-styled ul,
.article-content-styled ol {
  padding-left: 1.5em;
  margin-bottom: 1.2em;         /* ~20px */
}

.article-content-styled li {
  margin-bottom: 0.5em;         /* ~8px entre items */
  line-height: 1.8;
  font-weight: 400;
}

.article-content-styled li:last-child {
  margin-bottom: 0;
}

.article-content-styled ul li {
  list-style-type: disc;
}

.article-content-styled ul li::marker {
  color: var(--msr-primary);
}

.article-content-styled ol li {
  list-style-type: decimal;
}

.article-content-styled ol li::marker {
  color: var(--msr-primary);
  font-weight: 600;
}

/* Listes imbriquées */
.article-content-styled li ul,
.article-content-styled li ol {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

.article-content-styled li p {
  margin-bottom: 0.25em;
}

/* --- BLOCKQUOTES (Callouts) --- */
.article-content-styled blockquote {
  border-left: 4px solid var(--msr-primary);
  background-color: var(--msr-primary-light);
  padding: 16px 20px;
  margin: 1.5em 0;              /* ~25px avant et après */
  border-radius: 0 8px 8px 0;
  color: var(--msr-text);
  font-style: normal;
}

.article-content-styled blockquote p {
  margin-bottom: 0;
}

.article-content-styled blockquote p:not(:last-child) {
  margin-bottom: 0.5em;
}

/* --- LIENS --- */
.article-content-styled a {
  color: var(--msr-primary);
  text-decoration: underline;
  transition: color 0.2s ease;
}

.article-content-styled a:hover {
  color: var(--msr-primary-hover);
}

/* --- GRAS ET ITALIQUE --- */
.article-content-styled strong,
.article-content-styled b {
  font-weight: 700;
  color: var(--msr-text-strong);
}

.article-content-styled em,
.article-content-styled i {
  font-style: italic;
}

/* --- CODE INLINE --- */
.article-content-styled code {
  background-color: var(--msr-code-bg);
  color: var(--msr-code-text);
  padding: 3px 7px;
  border-radius: 6px;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 0.875em;
  font-weight: 500;
  border: 1px solid rgba(5, 150, 105, 0.15);
}

/* ==========================================================================
   BLOCS DE CODE - Design moderne avec Highlight.js
   ========================================================================== */

.article-content-styled pre {
  position: relative;
  background: linear-gradient(135deg, #1e2028 0%, #252830 100%);
  border-radius: 12px;
  margin: 1.75em 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Bouton copier en haut à droite */
.article-content-styled pre .code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.4);
  padding: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
}

.article-content-styled pre:hover .code-copy-btn {
  opacity: 1;
}

.article-content-styled pre .code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
}

.article-content-styled pre .code-copy-btn.copied {
  background: var(--msr-primary);
  color: #fff;
  opacity: 1;
}

.article-content-styled pre .code-copy-btn svg {
  width: 16px;
  height: 16px;
}

/* Code content */
.article-content-styled pre code {
  display: block;
  padding: 16px 20px;
  padding-right: 45px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Monaco', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.7;
  color: #e4e7eb;
  background: transparent;
  border-radius: 0;
  border: none;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Scrollbar personnalisée pour les blocs de code */
.article-content-styled pre code::-webkit-scrollbar {
  height: 8px;
}

.article-content-styled pre code::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 4px;
}

.article-content-styled pre code::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.article-content-styled pre code::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Override Highlight.js default */
.article-content-styled pre code.hljs {
  background: transparent;
  padding: 20px;
}

/* ==========================================================================
   HIGHLIGHT.JS - Thème personnalisé MineStrator (inspiré One Dark Pro)
   ========================================================================== */

.article-content-styled .hljs-comment,
.article-content-styled .hljs-quote {
  color: #5c6370;
  font-style: italic;
}

.article-content-styled .hljs-keyword,
.article-content-styled .hljs-selector-tag {
  color: #c678dd;
}

.article-content-styled .hljs-string,
.article-content-styled .hljs-addition {
  color: #98c379;
}

.article-content-styled .hljs-number,
.article-content-styled .hljs-literal {
  color: #d19a66;
}

.article-content-styled .hljs-built_in,
.article-content-styled .hljs-type {
  color: #e5c07b;
}

.article-content-styled .hljs-function,
.article-content-styled .hljs-title {
  color: #61afef;
}

.article-content-styled .hljs-attr,
.article-content-styled .hljs-attribute {
  color: #d19a66;
}

.article-content-styled .hljs-variable,
.article-content-styled .hljs-template-variable {
  color: #e06c75;
}

.article-content-styled .hljs-tag {
  color: #e06c75;
}

.article-content-styled .hljs-name {
  color: #e06c75;
}

.article-content-styled .hljs-selector-class,
.article-content-styled .hljs-selector-id {
  color: #61afef;
}

.article-content-styled .hljs-deletion {
  color: #e06c75;
}

.article-content-styled .hljs-meta {
  color: #56b6c2;
}

.article-content-styled .hljs-emphasis {
  font-style: italic;
}

.article-content-styled .hljs-strong {
  font-weight: bold;
}

/* --- IMAGES --- */
.article-content-styled img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.5em auto;           /* ~25px avant et après, centré */
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Petites images inline (icônes) */
.article-content-styled img[width] {
  border-radius: 4px;
  box-shadow: none;
  margin: 0;
  display: inline;
  vertical-align: middle;
}

/* --- VIDÉOS --- */
.article-content-styled video {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.5em auto;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  background-color: #1e1e1e;
}

/* Masquer les contrôles natifs (comportement GIF) */
.article-content-styled video::-webkit-media-controls {
  display: none !important;
}

.article-content-styled video::-webkit-media-controls-enclosure {
  display: none !important;
}

.article-content-styled video::-webkit-media-controls-panel {
  display: none !important;
}

/* Firefox */
.article-content-styled video::-moz-media-controls {
  display: none !important;
}

/* --- SÉPARATEURS (HR) --- */
.article-content-styled hr {
  border: none;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--msr-primary) 20%, var(--msr-primary) 80%, transparent);
  margin: 2.5em 0;              /* ~42px avant et après */
  border-radius: 2px;
}

/* --- TABLEAUX --- */
.article-content-styled table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.95rem;
}

.article-content-styled th,
.article-content-styled td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #e1e5ea;
}

.article-content-styled th {
  background-color: var(--msr-primary-light);
  color: var(--msr-text);
  font-weight: 600;
}

.article-content-styled tr:hover {
  background-color: rgba(0, 155, 114, 0.03);
}

/* --- DIVS (blocs de code legacy) --- */
/* Exclure les embeds YouTube et autres composants spéciaux */
.article-content-styled > div:not(.youtube-embed):not([data-youtube-video]) {
  background-color: var(--msr-code-block-bg);
  color: var(--msr-code-block-text);
  margin: 1.5em 0;
  padding: 16px 20px;
  border-radius: 8px;
  font-family: 'Fira Code', 'Monaco', monospace;
  font-size: 0.9rem;
  overflow-x: auto;
}

.article-content-styled > div:not(.youtube-embed):not([data-youtube-video]) > div {
  background-color: transparent;
  margin: 0;
  padding: 0;
}

/* ==========================================================================
   LITE YOUTUBE EMBED
   ========================================================================== */

.article-content-styled .youtube-embed {
  position: relative;
  display: block;
  width: 100%;
  max-width: 720px;
  margin: 1.5em auto;
  aspect-ratio: 16 / 9;
  background-color: #000;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  contain: content;
  background-size: cover;
  background-position: center;
}

/* Play button (rouge YouTube) */
.article-content-styled .youtube-embed::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 68px;
  height: 48px;
  background-color: #ff0000;
  border-radius: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: all 0.2s ease;
}

.article-content-styled .youtube-embed:hover::after {
  background-color: #cc0000;
  transform: translate(-50%, -50%) scale(1.1);
}

/* Triangle play (blanc) */
.article-content-styled .youtube-embed .youtube-play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-40%, -50%);
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 10px 0 10px 18px;
  border-color: transparent transparent transparent #fff;
  z-index: 1;
  pointer-events: none;
}

/* Quand iframe chargée, cacher le play button */
.article-content-styled .youtube-embed.youtube-activated::after,
.article-content-styled .youtube-embed.youtube-activated .youtube-play-icon {
  display: none;
}

.article-content-styled .youtube-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 768px) {
  .article-content-styled {
    font-size: 1rem;
    padding: 0 16px;
  }

  .article-content-styled h2 {
    font-size: 1.5rem;
  }

  .article-content-styled h3 {
    font-size: 1.25rem;
  }

  .article-content-styled blockquote {
    padding: 12px 16px;
    margin: 1.25em 0;
  }

  .article-content-styled ul,
  .article-content-styled ol {
    padding-left: 1.25em;
  }

  /* Blocs de code responsive */
  .article-content-styled pre {
    margin: 1.25em -16px;
    border-left: none;
    border-right: none;
    border-radius: 0;
  }

  .article-content-styled pre .code-copy-btn {
    top: 6px;
    right: 6px;
    padding: 5px;
    opacity: 0.7;
  }

  .article-content-styled pre .code-copy-btn svg {
    width: 14px;
    height: 14px;
  }

  .article-content-styled pre code {
    padding: 14px 16px;
    padding-right: 40px;
    font-size: 12px;
    line-height: 1.6;
  }

  .article-content-styled img,
  .article-content-styled video {
    margin: 1em 0;
  }

  /* YouTube embed responsive */
  .article-content-styled .youtube-embed {
    max-width: 100%;
    border-radius: 8px;
  }
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
  .article-content-styled {
    font-size: 11pt;
    line-height: 1.6;
    color: #000;
  }

  .article-content-styled a {
    color: #000;
    text-decoration: underline;
  }

  .article-content-styled h2 {
    color: #000;
    border-bottom-color: #ccc;
  }

  .article-content-styled blockquote {
    border-left-color: #666;
    background: #f5f5f5;
  }

  .article-content-styled pre {
    background: #f5f5f5;
    color: #000;
  }

  .article-content-styled img,
  .article-content-styled video {
    box-shadow: none;
    max-width: 80%;
  }

  /* Masquer les vidéos et embeds YouTube à l'impression */
  .article-content-styled video,
  .article-content-styled .youtube-embed {
    display: none;
  }
}

/* === TABLE OF CONTENTS (Sommaire) === */
.article-content-styled .article-toc {
  background: linear-gradient(135deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.06) 100%);
  border: 1px solid rgba(255,255,255,0.1);
  border-left: 4px solid var(--msr-primary, #00b894);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  margin: 2rem 0;
  backdrop-filter: blur(10px);
}

.article-content-styled .article-toc .toc-title {
  margin: 0 0 1rem 0;
  padding: 0;
  font-size: 1.15rem;
  color: #fff;
}

.article-content-styled .article-toc .toc-title strong {
  font-weight: 600;
}

.article-content-styled .article-toc .toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.article-content-styled .article-toc .toc-list li {
  margin: 0.5rem 0;
  padding: 0;
}

.article-content-styled .article-toc .toc-list li a {
  color: var(--msr-primary, #00b894);
  text-decoration: none;
  font-size: 1rem;
  transition: color 0.2s ease, padding-left 0.2s ease;
  display: inline-block;
}

.article-content-styled .article-toc .toc-list li a:hover {
  color: #fff;
  padding-left: 6px;
}

.article-content-styled .article-toc .toc-list li.toc-subitem {
  padding-left: 1.5rem;
  position: relative;
}

.article-content-styled .article-toc .toc-list li.toc-subitem::before {
  content: '└';
  position: absolute;
  left: 0.5rem;
  color: rgba(255,255,255,0.3);
}

.article-content-styled .article-toc .toc-list li.toc-subitem a {
  font-size: 0.95rem;
  color: rgba(255,255,255,0.7);
}

.article-content-styled .article-toc .toc-list li.toc-subitem a:hover {
  color: var(--msr-primary, #00b894);
}

/* Headings with anchors - scroll offset for fixed header */
.article-content-styled h2[id],
.article-content-styled h3[id] {
  scroll-margin-top: 100px;
  position: relative;
}

/* Anchor link indicator on hover */
.article-content-styled h2[id]:hover::after,
.article-content-styled h3[id]:hover::after {
  content: ' #';
  color: var(--msr-primary, #00b894);
  opacity: 0.5;
  font-weight: 400;
  font-size: 0.8em;
}

/* Print styles for TOC */
@media print {
  .article-content-styled .article-toc {
    background: #f5f5f5;
    border: 1px solid #ccc;
    border-left: 4px solid #333;
    page-break-inside: avoid;
  }

  .article-content-styled .article-toc .toc-title {
    color: #000;
  }

  .article-content-styled .article-toc .toc-list li a {
    color: #333;
  }
}

/* TOC highlight effect when navigating to heading */
.article-content-styled h2.toc-highlight,
.article-content-styled h3.toc-highlight {
  animation: toc-flash 2s ease-out;
}

@keyframes toc-flash {
  0% {
    background: rgba(0, 184, 148, 0.3);
    border-radius: 4px;
    padding-left: 8px;
    margin-left: -8px;
  }
  100% {
    background: transparent;
    padding-left: 0;
    margin-left: 0;
  }
}
