/* ============================================================================
   PyData-inspired theme for thesis HTML export
   ============================================================================ */

/* ---------------------------------------------------------------------------
   CSS Variables — Light theme (default)
   --------------------------------------------------------------------------- */

:root {
  --color-bg: #fff;
  --color-text: #333;
  --color-text-muted: #6c757d;
  --color-link: #0366d6;
  --color-link-hover: #024ea4;
  --color-border: #e1e4e8;
  --color-sidebar-bg: #f7f8fa;
  --color-sidebar-active: #0366d6;
  --color-sidebar-active-bg: #e8f0fe;
  --color-nav-part: #555;
  --color-code-bg: #f6f8fa;
  --color-topbar-bg: #f7f8fa;
  --color-search-bg: #fff;
  --color-backdrop: rgba(0, 0, 0, 0.4);
  --sidebar-width: 280px;
  --toc-width: 220px;
  --content-max-width: 820px;
  --topbar-height: 3.5rem;
  --font-body: "New Computer Modern", "Computer Modern", Georgia, serif;
  --font-heading: system-ui, -apple-system, sans-serif;
  --font-mono: "Fira Code", "Consolas", monospace;
}

/* ---------------------------------------------------------------------------
   CSS Variables — Dark theme
   --------------------------------------------------------------------------- */

[data-theme="dark"] {
  --color-bg: #15171a;
  --color-text: #d4d4d8;
  --color-text-muted: #9ca3af;
  --color-link: #60a5fa;
  --color-link-hover: #93c5fd;
  --color-border: #2d3139;
  --color-sidebar-bg: #1a1d23;
  --color-sidebar-active: #60a5fa;
  --color-sidebar-active-bg: #1e293b;
  --color-nav-part: #a0a0a0;
  --color-code-bg: #1e1e2e;
  --color-topbar-bg: #1a1d23;
  --color-search-bg: #1e2028;
  --color-backdrop: rgba(0, 0, 0, 0.6);
}

/* ---------------------------------------------------------------------------
   Reset & Base
   --------------------------------------------------------------------------- */

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-height) + 1rem);
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--color-text);
  background: var(--color-bg);
}

a {
  color: var(--color-link);
  text-decoration: none;
}
a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

img, svg {
  max-width: 100%;
  height: auto;
}

/* ---------------------------------------------------------------------------
   Topbar
   --------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 1rem;
  background: var(--color-topbar-bg);
  border-bottom: 1px solid var(--color-border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.topbar-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-title:hover {
  color: var(--color-link);
  text-decoration: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* Topbar buttons — shared style */
.topbar .sidebar-toggle-btn,
.topbar .theme-toggle,
.topbar .github-link,
.topbar .lang-switch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 6px;
  padding: 0.35rem;
  transition: background 0.15s, color 0.15s;
}
.topbar .sidebar-toggle-btn:hover,
.topbar .theme-toggle:hover,
.topbar .github-link:hover,
.topbar .lang-switch:hover {
  background: var(--color-sidebar-active-bg);
  color: var(--color-text);
  text-decoration: none;
}

/* Search trigger */
.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.search-trigger:hover {
  border-color: var(--color-link);
  background: var(--color-sidebar-active-bg);
}
.search-trigger kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  background: var(--color-sidebar-bg);
}

/* Language switch badge */
.lang-switch {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.5rem !important;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

/* Hide sidebar toggles on desktop */
#sidebar-toggle-left,
#sidebar-toggle-right {
  display: none;
}

/* ---------------------------------------------------------------------------
   3-Column Layout
   --------------------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--toc-width);
  min-height: calc(100vh - var(--topbar-height));
}

/* ---------------------------------------------------------------------------
   Sidebar Left (Global Navigation)
   --------------------------------------------------------------------------- */

.sidebar-left {
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-border);
  padding: 1rem 0;
  font-size: 0.9rem;
}

.sidebar-header {
  padding: 0.5rem 1rem 1rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 0.5rem;
}

.site-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.3;
  display: block;
}
.site-title:hover {
  color: var(--color-link);
  text-decoration: none;
}

.global-nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.global-nav li a {
  display: block;
  padding: 0.35rem 1rem;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}
.global-nav li a:hover {
  background: var(--color-sidebar-active-bg);
  color: var(--color-text);
  text-decoration: none;
}
.global-nav li.active a {
  color: var(--color-sidebar-active);
  font-weight: 600;
  border-left-color: var(--color-sidebar-active);
  background: var(--color-sidebar-active-bg);
}

.nav-part {
  padding: 0.8rem 1rem 0.3rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-nav-part);
}

/* ---------------------------------------------------------------------------
   Main Content
   --------------------------------------------------------------------------- */

.content {
  max-width: var(--content-max-width);
  padding: 2rem 3rem;
  width: 100%;
  justify-self: center;
}

/* ---------------------------------------------------------------------------
   Sidebar Right (Local TOC)
   --------------------------------------------------------------------------- */

.sidebar-right {
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  border-left: 1px solid var(--color-border);
}

.local-toc h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 0 0 0.5rem;
}

.local-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.local-toc li a {
  display: block;
  padding: 0.2rem 0;
  color: var(--color-text-muted);
  border-left: 2px solid transparent;
  padding-left: 0.75rem;
  transition: color 0.15s, border-color 0.15s;
}
.local-toc li a:hover {
  color: var(--color-text);
  text-decoration: none;
}
.local-toc li a.active {
  color: var(--color-sidebar-active);
  border-left-color: var(--color-sidebar-active);
}

.local-toc .toc-l3 a {
  padding-left: 1.5rem;
  font-size: 0.82rem;
}

/* ---------------------------------------------------------------------------
   Typography
   --------------------------------------------------------------------------- */

h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  margin: 2rem 0 1rem;
  line-height: 1.3;
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 0.5rem;
}

h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  margin: 2rem 0 0.75rem;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.3rem;
}

h3 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  margin: 1.5rem 0 0.5rem;
}

h4 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 1rem 0 0.5rem;
}

p {
  margin: 0 0 1em;
  text-align: justify;
  hyphens: auto;
}

dt {
  font-weight: bold;
}

dd {
  margin-bottom: 0.5em;
}

blockquote {
  margin: 1em 0;
  padding: 0.5em 1em;
  border-left: 4px solid var(--color-border);
  color: var(--color-text-muted);
  font-style: italic;
}

blockquote.epigraph {
  width: 55%;
  margin-left: auto;
  margin-right: 0;
  border-left: none;
  font-style: italic;
  font-size: 0.95em;
  padding: 0;
}

blockquote.epigraph footer {
  text-align: right;
  font-style: normal;
  margin-top: 0.3em;
}

blockquote.epigraph footer::before {
  content: "— ";
}

.lettrine::first-letter {
  font-size: 2.5em;
  float: left;
  line-height: 1;
  margin-right: 2px;
  font-variant: small-caps;
}

/* ---------------------------------------------------------------------------
   Footnotes
   --------------------------------------------------------------------------- */

.footnotes {
  margin-top: 2em;
  font-size: 0.9em;
  color: var(--color-text-muted);
}

.footnotes hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin-bottom: 1em;
}

.footnotes ol {
  padding-left: 0;
}

.footnotes li {
  margin-bottom: 0.5em;
}

.footnotes a[role="doc-backlink"] {
  text-decoration: none;
  margin-right: 0.3em;
}

sup {
  font-size: 0.75em;
}

/* ---------------------------------------------------------------------------
   Cover / Index Page
   --------------------------------------------------------------------------- */

.thesis-header {
  text-align: center;
  padding: 3rem 1rem;
}

.thesis-header .institution {
  font-variant: small-caps;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.thesis-header .thesis-title {
  font-size: 2rem;
  border: none;
  margin: 1rem 0;
}

.thesis-header .author {
  font-size: 1.2rem;
  margin: 0.5rem 0;
}

.thesis-header .date {
  color: var(--color-text-muted);
}

.thesis-header .abstract {
  text-align: justify;
  max-width: 600px;
  margin: 2rem auto 0;
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

/* PDF download button */
.pdf-download {
  margin-top: 1.5rem;
}

.btn-pdf {
  display: inline-block;
  padding: 0.6rem 1.5rem;
  border: 2px solid var(--color-link);
  border-radius: 8px;
  color: var(--color-link);
  font-weight: 600;
  font-size: 1rem;
  transition: background 0.2s, color 0.2s;
}
.btn-pdf:hover {
  background: var(--color-link);
  color: #fff;
  text-decoration: none;
}

[data-theme="dark"] .btn-pdf:hover {
  color: var(--color-bg);
}

/* ---------------------------------------------------------------------------
   Figures & Images
   --------------------------------------------------------------------------- */

figure {
  margin: 1.5em 0;
  text-align: center;
}

figcaption {
  font-size: 0.9em;
  color: var(--color-text-muted);
  margin-top: 0.5em;
  text-align: left;
}

/* SVG frames from Typst html.frame */
.typst-frame {
  display: inline;
  vertical-align: baseline;
}

svg.typst-frame {
  max-width: 100%;
  height: auto;
}

/* Dark mode: invert SVGs and rotate hue to preserve colors */
[data-theme="dark"] svg.typst-frame {
  filter: invert(1) hue-rotate(180deg);
}

/* Dark mode: invert inline SVG images (PDFs rendered as base64 SVG by Typst) */
/* These are black-on-transparent diagrams that need the same treatment */
[data-theme="dark"] figure img[src^="data:image/svg+xml"] {
  filter: invert(1) hue-rotate(180deg);
}

/* ---------------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------------- */

table {
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.9em;
  width: 100%;
}

th, td {
  padding: 0.5em 0.75em;
  border: 1px solid var(--color-border);
  text-align: left;
}

th {
  background: var(--color-sidebar-bg);
  font-weight: 600;
}

/* ---------------------------------------------------------------------------
   Theorem Boxes — Light theme
   --------------------------------------------------------------------------- */

.thm-box {
  padding: 1em;
  margin: 1em 0;
  border-left: 4px solid;
  border-radius: 4pt;
  text-align: left;
}

.thm-head {
  margin: 0 0 0.5em;
}

.thm-theoreme  { background: #e8f4f8; border-color: #2196F3; }
.thm-lemme     { background: #f0f8e8; border-color: #4CAF50; }
.thm-proposition { background: #fff8e8; border-color: #FF9800; }
.thm-corollaire { background: #f8f0f8; border-color: #9C27B0; }
.thm-definition { background: #f5f5f5; border-color: #607D8B; }
.thm-thdef     { background: #f0f0ff; border-color: #3F51B5; }
.thm-conjecture { background: #fff0f0; border-color: #f44336; }
.thm-invariant { background: #e8f8f8; border-color: #00BCD4; }
.thm-remarque  { background: #f8f7e8; border-color: #d4b400; }
.thm-qo        { background: #fffde8; border-color: #FFC107; }

/* Theorem Boxes — Dark theme */
[data-theme="dark"] .thm-theoreme  { background: #1a2733; }
[data-theme="dark"] .thm-lemme     { background: #1a2a1a; }
[data-theme="dark"] .thm-proposition { background: #2a2418; }
[data-theme="dark"] .thm-corollaire { background: #271a2a; }
[data-theme="dark"] .thm-definition { background: #1e2124; }
[data-theme="dark"] .thm-thdef     { background: #1a1a2e; }
[data-theme="dark"] .thm-conjecture { background: #2a1a1a; }
[data-theme="dark"] .thm-invariant { background: #1a2a2a; }
[data-theme="dark"] .thm-remarque  { background: #2a2918; }
[data-theme="dark"] .thm-qo        { background: #2a2a18; }

/* Proofs */
.thm-proof {
  margin: 1em 0;
}

.proof-head {
  margin: 0 0 0.5em;
}

.qed {
  display: block;
  text-align: right;
}

/* ---------------------------------------------------------------------------
   Code & Algorithms
   --------------------------------------------------------------------------- */

code, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

pre {
  background: var(--color-code-bg);
  padding: 1em;
  border-radius: 4px;
  overflow-x: auto;
}

/* ---------------------------------------------------------------------------
   Page Navigation (prev/next)
   --------------------------------------------------------------------------- */

.page-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.page-nav a {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.15s;
}
.page-nav a:hover {
  background: var(--color-sidebar-bg);
  border-color: var(--color-link);
  text-decoration: none;
}

/* ---------------------------------------------------------------------------
   Bibliography
   --------------------------------------------------------------------------- */

.bibliography {
  font-size: 0.9em;
}

/* ---------------------------------------------------------------------------
   Sidebar Backdrop (mobile overlays)
   --------------------------------------------------------------------------- */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 149;
  background: var(--color-backdrop);
}

.sidebar-backdrop.visible {
  display: block;
}

/* ---------------------------------------------------------------------------
   Search Modal
   --------------------------------------------------------------------------- */

.search-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--color-backdrop);
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
}

.search-overlay.visible {
  display: flex;
}

.search-dialog {
  width: 90%;
  max-width: 600px;
  background: var(--color-search-bg);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.search-header {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  gap: 0.5rem;
}

.search-input {
  flex: 1;
  border: none;
  background: none;
  font-size: 1.1rem;
  font-family: var(--font-body);
  color: var(--color-text);
  outline: none;
}
.search-input::placeholder {
  color: var(--color-text-muted);
}

.search-close {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  background: var(--color-sidebar-bg);
  color: var(--color-text-muted);
  cursor: pointer;
}

.search-results {
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.5rem;
}

.search-results:empty::after {
  content: "";
  display: none;
}

.search-result {
  display: block;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  color: var(--color-text);
  transition: background 0.1s;
}
.search-result:hover {
  background: var(--color-sidebar-active-bg);
  text-decoration: none;
}

.search-result-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.search-result-excerpt {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 0.2rem;
}

.search-result-page {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-bottom: 0.1rem;
}

.search-result-excerpt mark {
  background: rgba(255, 213, 79, 0.3);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

.search-no-results {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

/* ---------------------------------------------------------------------------
   Responsive Design
   --------------------------------------------------------------------------- */

/* Medium screens: hide right sidebar */
@media (max-width: 1200px) {
  .sidebar-right {
    display: none;
  }
  .layout {
    grid-template-columns: var(--sidebar-width) 1fr;
  }
  #sidebar-toggle-right {
    display: inline-flex;
  }
  /* Right sidebar as overlay when toggled */
  .sidebar-right.open {
    display: block;
    position: fixed;
    top: var(--topbar-height);
    right: 0;
    width: var(--toc-width);
    height: calc(100vh - var(--topbar-height));
    z-index: 150;
    background: var(--color-bg);
    border-left: 1px solid var(--color-border);
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
  }
}

/* Small screens: hide both sidebars */
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar-left {
    display: none;
  }

  #sidebar-toggle-left {
    display: inline-flex;
  }

  /* Left sidebar as overlay */
  .sidebar-left.open {
    display: block;
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    z-index: 150;
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-border);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  }

  .content {
    padding: 2rem 1.5rem;
  }

  /* Hide Ctrl+K label on small screens */
  .search-trigger kbd {
    display: none;
  }
}

/* Very small screens */
@media (max-width: 600px) {
  .topbar-title {
    font-size: 0.8rem;
    max-width: 40vw;
  }

  .content {
    padding: 1.5rem 1rem;
  }
}

/* ---------------------------------------------------------------------------
   Print
   --------------------------------------------------------------------------- */

@media print {
  .topbar,
  .sidebar-left,
  .sidebar-right,
  .page-nav,
  .sidebar-backdrop,
  .search-overlay {
    display: none !important;
  }
  .layout {
    grid-template-columns: 1fr;
  }
  .content {
    max-width: 100%;
  }
}
