/*
SPDX-License-Identifier: GPL-3.0-or-later
Copyright (C) 2025 Manuel Regamey
This file is part of SluInk. See the LICENSE file or <https://www.gnu.org/licenses/>.
*/

/* ==========================================================================
   Hypatie · style.css (cleaned & consolidated)
   --------------------------------------------------------------------------
   - Trois thèmes via html[data-theme="..."]: light / dark / academic
   - Light : bleu doux renforcé (légère teinte bleutée sur cartes/stripes)
   - Dark  : palette sombre lisible
   - Academic : ambiance papier ivoire + bleu "bibliothèque"
   - Normalisation des boutons de thème + focus/hover/active
   - Icônes de thème : inversion universelle en dark (img + svg)
   - Évite color-mix(); tints via rgba(var(--accent-rgb), α)
   ========================================================================== */

/* ========== 0) Variables de base (fallback si data-theme absent) ======== */
:root{
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell,
               "Noto Sans", "Helvetica Neue", Arial, "Apple Color Emoji",
               "Segoe UI Emoji", "Segoe UI Symbol";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
               "Liberation Mono", "Courier New", monospace;

  /* Fallback proche LIGHT */
  --bg: #ffffff;
  --fg: #1b1b1b;
  --muted: #6b7280;
  --card: #f6f8fa;
  --border: #e5e7eb;
  --shadow: 0 2px 12px rgba(0,0,0,.06);

  --accent: #4f7dbf;               /* Bleu doux (fallback) */
  --accent-rgb: 79,125,191;
  --accent-contrast: #ffffff;
  --link: #2563eb;
  --link-visited: #7c3aed;
  --mark: #fff2a8;

  --code-bg: #f5f7fb;
  --code-fg: #0f172a;
  --code-border: #e2e8f0;
  --line-num: #9aa5b1;
  --inline-bg: #eef4ff;

  --kbd-bg: #f3f4f6;
  --kbd-fg: #111827;

  --table-stripe: #f3f7ff;

  /* Tints (dérivées d'accent) */
  --hover-bg:        rgba(var(--accent-rgb), 0.12);
  --blockquote-bg:   rgba(var(--accent-rgb), 0.10);
  --row-hover-bg:    rgba(var(--accent-rgb), 0.08);
  --button-border:   rgba(var(--accent-rgb), 0.35);
  --ring:            rgba(var(--accent-rgb), 0.32);
}

/* ========== 1) Thèmes =================================================== */

/* 1.1 Light  bleu doux renforcé */
html[data-theme="light"]{
  color-scheme: light;

  --bg: #ffffff;
  --fg: #1b1b1b;
  --muted: #667085;

  --card: #f7faff;                  /* léger voile bleu */
  --border: #e4e9f3;

  --accent: #4f7dbf;
  --accent-rgb: 79,125,191;
  --accent-contrast: #ffffff;

  --link: #2563eb;
  --link-visited: #7c3aed;

  --code-bg: #f4f7ff;
  --code-fg: #0f172a;
  --code-border: #e1e6f0;
  --inline-bg: #eef4ff;

  --table-stripe: #f3f7ff;

  --hover-bg:        rgba(var(--accent-rgb), 0.12);
  --blockquote-bg:   rgba(var(--accent-rgb), 0.10);
  --row-hover-bg:    rgba(var(--accent-rgb), 0.08);
  --button-border:   rgba(var(--accent-rgb), 0.35);
  --ring:            rgba(var(--accent-rgb), 0.32);
}

/* 1.2 Dark */
html[data-theme="dark"]{
  color-scheme: dark;

  --bg: #0f1521;
  --fg: #a4b4d4;
  --muted: #a1a1aa;
  --card: #191f2c;
  --border: #1f2937;
  --shadow: 0 2px 12px rgba(0,0,0,.35);

  --accent: #5877b9;
  --accent-rgb: 88,119,185;
  --accent-contrast: #0b1020;
  --link: #93c5fd;
  --link-visited: #c4b5fd;
  --mark: #49410a;

  --code-bg: #1e1e1f;
  --code-fg: #a4b4d4;
  --code-border: #1f2937;
  --line-num: #6b7280;
  --inline-bg: #1c263b;

  --kbd-bg: #111827;
  --kbd-fg: #a4b4d4;

  --table-stripe: #0e1726;

  --hover-bg:        rgba(var(--accent-rgb), 0.15);
  --blockquote-bg:   rgba(var(--accent-rgb), 0.12);
  --row-hover-bg:    rgba(var(--accent-rgb), 0.10);
  --button-border:   rgba(var(--accent-rgb), 0.45);
  --ring:            rgba(var(--accent-rgb), 0.33);
}

/* 1.3 Academic  ivoire renforcé */
html[data-theme="academic"]{
  color-scheme: light;

  --bg: #f9f5e7;                    /* ivoire chaud */
  --fg: #1c1915;
  --muted: #5e5a4f;

  --card: #f2eadb;                  /* carte papier */
  --border: #e6dbc3;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.06);

  --accent: #2b4c7e;                /* bleu bibliothèque */
  --accent-rgb: 43,76,126;
  --accent-contrast: #ffffff;

  --link: var(--accent);
  --link-visited: #5a32a3;

  --code-bg: #f6edd9;               /* parchemin */
  --code-fg: #1a1816;
  --code-border: #e6dbc3;

  --table-stripe: #f3ead4;

  --hover-bg:        rgba(var(--accent-rgb), 0.12);
  --blockquote-bg:   rgba(var(--accent-rgb), 0.08);
  --row-hover-bg:    rgba(var(--accent-rgb), 0.07);
  --button-border:   rgba(var(--accent-rgb), 0.35);
  --ring:            rgba(var(--accent-rgb), 0.28);
}

/* ========== 2) Application globale ===================================== */
html{ background: var(--bg); }
body{
  color: var(--fg);
  margin: 0;
  max-width: none;
  padding: 3rem 1.25rem 6rem;
  font: 16px/1.65 var(--font-sans);
  text-rendering: optimizeLegibility;
}

/* 2.1 Layout principal (sidebar + contenu) */
.layout{
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(0, 4fr);
  gap: 1.25rem;
  align-items: start;
  max-width: min(1200px, 95vw);
  margin: 0 auto;
}

/* 2.2 En-tête / barre de nav */
header.site{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: .9rem 1.2rem;
  margin-bottom: 1rem;
  display:flex; justify-content:space-between; gap:.75rem; align-items:center;
}
header.site .brand{ font-weight:700; letter-spacing:.2px; }
header.site .brand a{ text-decoration:none; color:inherit; }

/* 2.3 Sidebar (TOC) */
.sidebar{
  position: sticky; top: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}
.sidebar nav ul{ list-style:none; padding-left:.25rem; }
.sidebar nav li{ margin:.2rem 0; }
.sidebar nav a{ text-decoration:none; }
.sidebar nav a:hover{ text-decoration:underline; }
.sidebar a.is-active{ font-weight:600; }

/* 2.4 Contenu principal */
.content{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

/* 2.5 Top navigation */
.topnav{ display:flex; gap:.75rem; align-items:center; flex-wrap:wrap; }
.topnav a{
  text-decoration:none;
  padding:.3rem .6rem;
  border-radius:8px;
  border:1px solid var(--border);
  background: var(--card);
}
.topnav a:hover{ background: var(--hover-bg); }

/* ========== 3) Thème switcher ========================================== */
.theme-buttons{ display:flex; gap:.4rem; align-items:center; }

.theme-buttons [data-theme-set],
.theme-buttons [data-theme-cycle]{
  display:inline-flex; align-items:center; justify-content:center;
  gap:.4rem;
  padding:.4rem .6rem;
  background: var(--card);
  color: inherit;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: none;
  cursor: pointer;
  line-height: 1;
  min-width: 2.2rem;
  min-height: 2.2rem;
  transition: background .15s ease, border-color .15s ease,
              box-shadow .15s ease, transform .05s ease;
}
.theme-buttons [data-theme-set]:hover,
.theme-buttons [data-theme-cycle]:hover{ background: var(--hover-bg); }
.theme-buttons [data-theme-set]:active,
.theme-buttons [data-theme-cycle]:active{ transform: translateY(1px); }
.theme-buttons [data-theme-set]:focus-visible,
.theme-buttons [data-theme-cycle]:focus-visible{
  outline: none; box-shadow: 0 0 0 3px var(--ring); border-color: var(--accent);
}

/* État ACTIF (thème courant) */
html[data-theme="light"] .theme-buttons [data-theme-set="light"],
html[data-theme="dark"] .theme-buttons [data-theme-set="dark"],
html[data-theme="academic"] .theme-buttons [data-theme-set="academic"]{
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

/* Icônes  inversion universelle en dark */
html[data-theme="light"] .theme-buttons [data-theme-set] img,
html[data-theme="academic"] .theme-buttons [data-theme-set] img,
html[data-theme="light"] .theme-buttons [data-theme-set] svg,
html[data-theme="academic"] .theme-buttons [data-theme-set] svg{
  filter: none;
}
html[data-theme="dark"] .theme-buttons [data-theme-set] img,
html[data-theme="dark"] .theme-buttons [data-theme-set] svg{
  filter: invert(1) brightness(1.1) contrast(1.05);
}

/* ========== 4) Typographie & éléments ================================== */
h1,h2,h3,h4,h5,h6{ line-height: 1.25; margin-top: 2.2rem; margin-bottom: .8rem; }
h1{ font-size: 2rem; letter-spacing: .2px; }
h2{ font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: .25rem;}
h3{ font-size: 1.25rem; }
h4{ font-size: 1.1rem; }
h5,h6{ font-size: 1rem; color: var(--muted); font-style: italic; }

/* Ambient serif pour Academic (option forte d'ambiance) */
:root[data-theme="academic"] h1,
:root[data-theme="academic"] h2,
:root[data-theme="academic"] h3{
  font-family: Georgia, "Noto Serif", "Liberation Serif", serif;
  letter-spacing: .2px;
}

p, ul, ol, dl, blockquote, pre, table{ margin: 1rem 0; }
ul,ol{ padding-inline-start: 1.25rem; }
li + li{ margin-top: .25rem; }

a{ color: var(--link); text-decoration: underline; text-decoration-thickness: .08em; }
a:visited{ color: var(--link-visited); }
a:hover{ text-underline-offset: 2px; }
hr{ border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
mark{ background: var(--mark); padding: .1em .2em; border-radius: .2em; }

blockquote{
  padding: .75rem 1rem;
  border-left: 5px solid var(--accent);
  background: var(--blockquote-bg);
  border-radius: 8px;
  margin-left: 0; margin-right: 0;
  color: inherit;
}

/* Boutons génériques */
.button{
  display:inline-block;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: .5rem .85rem;
  border-radius: 10px;
  border: 1px solid var(--button-border);
  text-decoration: none;
  font-weight: 600;
}

/* ========== 5) Tables =================================================== */
table{
  width: 100%;
  border-collapse: collapse;
  overflow-x: auto;
  display: block;
  border: 1px solid var(--border);
  border-radius: 10px;
}
thead th{
  text-align: left;
  font-weight: 600;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: .6rem .7rem;
}
tbody td, tbody th{ padding: .55rem .7rem; }
tbody tr:nth-child(odd){ background: var(--table-stripe); }
tbody tr:hover{ background: var(--row-hover-bg); }

/* ========== 6) Code & source =========================================== */
code{ font-family: var(--font-mono); font-size: .95em; }
p > code, li > code, td > code, th > code{
  background: var(--inline-bg);
  border: 1px solid var(--code-border);
  padding: .1rem .35rem;
  border-radius: 6px;
}
pre{
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 12px;
  padding: 1rem 1rem;
  overflow: auto;
  box-shadow: var(--shadow);
}
pre code{ color: var(--code-fg); background: transparent; }

/* Pandoc .sourceCode specifics */
div.sourceCode{ position: relative; }
pre.numberSource{ border-left: 3px solid var(--border); }
pre.numberSource code > span > a:first-child::before{ color: var(--line-num) !important; }

/* Teinte minimale pour Pandoc */
code span.kw { font-weight: 600; }
code span.kw, code span.cf, code span.ot { color: #2563eb; }
code span.st, code span.ss, code span.vs { color: #047857; }
code span.co, code span.do, code span.an { color: #6b7280; font-style: italic; }
code span.fu { color: #7c3aed; }
code span.va, code span.vb, code span.dt { color: #dc2626; }
code span.bn, code span.dv, code span.fl { color: #b45309; }

/* ========== 7) KBD & médias ============================================ */
kbd{
  background: var(--kbd-bg);
  color: var(--kbd-fg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: .15rem .35rem;
  font-family: var(--font-mono);
  font-size: .85em;
}
img{ max-width: 100%; height: auto; border-radius: 8px; }
figure{ margin: 1.2rem 0; }
figcaption{ color: var(--muted); font-size: .95em; text-align: center; }

/* ========== 8) TOC / Footer / Responsive / Print ======================= */
#TOC{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  margin: 1.5rem 0;
}
#TOC > ul{ padding-left: 1rem; }
#TOC a{ text-decoration: none; }
#TOC a:hover{ text-decoration: underline; }

footer.site{
  margin-top: 1rem;
  color: var(--muted);
  font-size: .9em;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

@media (max-width: 1000px){
  .layout{
    grid-template-columns: 1fr;
  }
  .sidebar{ display: none !important; }
  .topnav{ order:3; width:100%; padding-top:.5rem; }
}

@media print{
  html{ background: white; }
  body{ color: black; box-shadow: none; }
  header.site, .content, .sidebar, #TOC{ box-shadow: none; }
  a[href^="http"]::after{ content: " (" attr(href) ")"; font-size: .9em; }
}
