/* ITC 2026 - Course Website Styles */
/* UPF Aula Global inspired design */

:root {
  --upf-red: #c8102e;
  --upf-red-hover: rgba(200, 16, 46, 0.9);
  --upf-red-light: rgba(200, 16, 46, 0.08);
  --text: #1d2125;
  --text-secondary: #6a737b;
  --bg: #fff;
  --bg-light: #f8f9fa;
  --bg-card: #f5f5f5;
  --border: #dee2e6;
  --border-light: #ecebeb;
  --link: #0f6cbf;
  --success: #357a32;
  --max-width: 960px;
  --nav-height: 56px;
}

/* Reset & base */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 14px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 1rem);
}

body {
  margin: 0;
  font-family: Roboto, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-weight: 400;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 500;
  line-height: 1.3;
  margin: 1.5em 0 0.5em;
}

h1 { font-size: 1.6rem; color: var(--upf-red); margin-top: 0; }
h2 { font-size: 1.3rem; color: var(--text); border-bottom: 2px solid var(--upf-red); padding-bottom: 0.3em; }
h3 { font-size: 1.1rem; }

p { margin: 0 0 1em; }

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

/* Top navbar */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1rem;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.navbar-brand img {
  height: 42px;
}

.navbar-brand-text {
  flex: 1;
  text-align: center;
}

.navbar-brand:hover { color: var(--upf-red); text-decoration: none; }

.navbar-nav {
  display: flex;
  gap: 0.25rem;
  list-style: none;
  margin: 0 0 0 auto;
  padding: 0;
  align-items: center;
}

.navbar-nav a {
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  white-space: nowrap;
}

.navbar-nav a:hover,
.navbar-nav a.active {
  background: var(--upf-red-light);
  color: var(--upf-red);
  text-decoration: none;
}

/* Language switcher */
.lang-switcher {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.lang-switcher a {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-secondary);
}

.lang-switcher a:hover { border-color: var(--upf-red); color: var(--upf-red); text-decoration: none; }
.lang-switcher a.active { background: var(--upf-red); color: #fff; border-color: var(--upf-red); }

/* Hamburger menu - visible on all screen sizes */
.menu-toggle {
  display: block;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  color: var(--text);
  margin-right: 0.5rem;
}

/* Layout */
.page {
  display: flex;
  margin-top: var(--nav-height);
  min-height: calc(100vh - var(--nav-height));
}

/* Sidebar - open by default, collapsible */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-light);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0;
  position: sticky;
  top: var(--nav-height);
  height: calc(100vh - var(--nav-height));
  overflow-y: auto;
  transition: margin-left 0.25s ease, opacity 0.25s ease;
}

.sidebar.hidden {
  margin-left: -240px;
  opacity: 0;
  pointer-events: none;
}

.sidebar-section {
  padding: 0 1rem;
  margin-bottom: 0.5rem;
  border: none;
  outline: none;
}

.sidebar-section > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem 0;
}

.sidebar-section > summary::-webkit-details-marker { display: none; }

.sidebar-section > summary::before {
  content: '\203A';
  font-size: 1rem;
  line-height: 1;
  color: var(--text-secondary);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  width: 0.6rem;
  text-align: center;
}

.sidebar-section[open] > summary::before {
  transform: rotate(90deg);
}

.sidebar-section > summary:hover::before {
  color: var(--upf-red);
}

.sidebar-section > summary h4 {
  margin: 0;
}

.sidebar-section h4 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin: 0 0 0.5rem;
  font-weight: 500;
}

.sidebar a {
  display: block;
  padding: 0.3rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text);
  border-radius: 4px;
  border-left: 3px solid transparent;
}

.sidebar a:hover {
  background: var(--upf-red-light);
  color: var(--upf-red);
  text-decoration: none;
}

.sidebar a.active {
  border-left-color: var(--upf-red);
  color: var(--upf-red);
  font-weight: 500;
  background: var(--upf-red-light);
}

/* Main content */
.content {
  flex: 1;
  max-width: var(--max-width);
  padding: 1.5rem 2rem 3rem;
  margin: 0 auto;
  overflow-x: hidden;
  min-width: 0;
}

/* Lecture header */
.lecture-header {
  border-bottom: 2px solid var(--upf-red);
  padding-bottom: 0.75rem;
  margin-bottom: 1.5rem;
}

.lecture-header .course-name {
  color: var(--upf-red);
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.lecture-header h1 {
  margin: 0.25rem 0 0.5rem;
  border: none;
  padding: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.lecture-header .pdf-link {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--upf-red);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-decoration: none;
  border: 1.5px solid var(--upf-red);
  border-radius: 3px;
  padding: 0.1rem 0.4rem;
  position: relative;
  top: -2px;
  transition: background 0.15s, color 0.15s;
}

.lecture-header .pdf-link:hover {
  background: var(--upf-red);
  color: #fff;
  text-decoration: none;
}

/* Hero image */
.hero-image {
  margin: 0 0 1.5rem;
  border-radius: 6px;
  overflow: hidden;
}

.hero-image img {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  object-position: center 30%;
  display: block;
  filter: grayscale(20%);
}

.hero-image figcaption {
  background: var(--bg-light);
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 0;
  border-bottom: 2px solid var(--upf-red);
}

/* Video embed */
.video-container {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  overflow: hidden;
  margin: 1rem 0 1.5rem;
  border-radius: 6px;
}

.video-container iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* Theorem-like environments */
.env-block {
  margin: 1.25em 0;
  padding: 0.75em 1em;
  border-radius: 4px;
}

.env-block .env-label {
  font-weight: 700;
  font-family: Roboto, sans-serif;
}

.env-problem {
  background: var(--upf-red-light);
  border-left: 4px solid var(--upf-red);
}

.env-example {
  background: #f5f5f5;
  border-left: 4px solid #999;
}

.env-definition {
  background: #f0fff4;
  border-left: 4px solid var(--success);
}

.env-theorem {
  background: var(--upf-red-light);
  border-left: 4px solid var(--upf-red);
}

.env-worked {
  background: #eef5ff;
  border-left: 4px solid #2b6cb0;
}

/* Solution toggle */
details.solution {
  margin: 0.75em 0 0.5em 1em;
  border-left: 3px solid #bbb;
  padding-left: 1em;
  color: var(--text-secondary);
}

details.solution[open] {
  color: var(--text);
}

details.solution summary {
  cursor: pointer;
  font-style: italic;
  color: var(--text-secondary);
  user-select: none;
  font-size: 0.9rem;
}

details.solution summary:hover {
  color: var(--upf-red);
}

/* Equations */
.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25em 0;
  max-width: 100%;
}

.katex { max-width: 100%; }

/* Prevent any child from overflowing content */
.content p, .content div, .content figure {
  max-width: 100%;
  overflow-wrap: break-word;
}

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

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

figcaption {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  text-align: center;
}

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

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

th {
  background: var(--bg-light);
  font-weight: 500;
}

/* Cards for index page */
.card-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0.75rem 0 1.5rem;
}

.card {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}

.card:first-child { border-top: 1px solid var(--border-light); }

.card:hover {
  background: var(--upf-red-light);
}

.card h3 {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 400;
  flex: 1;
}

.card h3 a { color: var(--text); }
.card h3 a:hover { color: var(--upf-red); text-decoration: none; }

.card .card-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: none; /* hidden in compact mode */
}

.card .pdf-link {
  font-size: 0.55rem;
  font-weight: 700;
  color: var(--upf-red);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-decoration: none;
  border: 1.5px solid var(--upf-red);
  border-radius: 2px;
  padding: 0.05rem 0.3rem;
  transition: background 0.15s, color 0.15s;
}

.card .pdf-link:hover {
  background: var(--upf-red);
  color: #fff;
  text-decoration: none;
}

/* Footer */
.footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-light);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    z-index: 90;
    box-shadow: 4px 0 12px rgba(0,0,0,0.1);
  }

  .sidebar.hidden {
    margin-left: 0;
    left: -260px;
    position: fixed;
  }

  .content {
    padding: 1rem;
  }

  h1 { font-size: 1.3rem; }
  h2 { font-size: 1.15rem; }
}

@media (max-width: 480px) {
  .card-grid {
    grid-template-columns: 1fr;
  }

  .katex-display {
    font-size: 0.85em;
  }
}

/* Print */
@media print {
  .navbar, .sidebar, .menu-toggle, .lang-switcher, .footer,
  .search-overlay, .sidebar-backdrop, .navbar-actions { display: none; }
  .page { display: block; }
  .content { max-width: 100%; padding: 0; }
  details.solution { display: block; }
  details.solution[open] summary { display: none; }
}

/* ============ Dark mode ============ */
[data-theme="dark"] {
  --upf-red: #e8354f;
  --upf-red-hover: rgba(232, 53, 79, 0.85);
  --upf-red-light: rgba(232, 53, 79, 0.12);
  --text: #dce1e6;
  --text-secondary: #8b929a;
  --bg: #181a1b;
  --bg-light: #1e2021;
  --bg-card: #242628;
  --border: #353739;
  --border-light: #2c2e30;
  --link: #6db3f8;
  --success: #5cb85c;
}

[data-theme="dark"] .navbar {
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

[data-theme="dark"] .navbar-brand img {
  filter: brightness(0) invert(1);
}

[data-theme="dark"] .hero-image img {
  filter: brightness(0.75) grayscale(20%);
}

[data-theme="dark"] figure img[src*="tikz"],
[data-theme="dark"] figure img[src*="fig"] {
  filter: invert(0.88) hue-rotate(180deg);
}

[data-theme="dark"] .env-example {
  background: rgba(255,255,255,0.05);
  border-left-color: #666;
}

[data-theme="dark"] .env-definition {
  background: rgba(92, 184, 92, 0.08);
}

[data-theme="dark"] .env-worked {
  background: rgba(43, 108, 176, 0.10);
  border-left-color: #5b8fd1;
}

[data-theme="dark"] details.solution {
  border-left-color: #555;
}

/* ============ Navbar actions ============ */
.navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin-left: auto;
  margin-right: 0.5rem;
}

.navbar-actions + .lang-switcher {
  margin-left: 0;
}

.theme-toggle,
.search-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 4px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover,
.search-toggle:hover {
  background: var(--upf-red-light);
  color: var(--upf-red);
}

.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

.search-hint {
  font-size: 0.6rem;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  margin-left: 0.25rem;
  font-family: system-ui, sans-serif;
  pointer-events: none;
}

/* ============ Search overlay ============ */
.search-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  justify-content: center;
  align-items: flex-start;
  padding-top: 12vh;
}

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

.search-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 92%;
  max-width: 540px;
  max-height: 65vh;
  overflow: hidden;
  box-shadow: 0 16px 48px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  gap: 0.6rem;
}

.search-input-wrap svg {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1.05rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
}

.search-input::placeholder {
  color: var(--text-secondary);
}

.search-results {
  overflow-y: auto;
  flex: 1;
  padding: 0.4rem;
}

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

.search-result:hover,
.search-result.selected {
  background: var(--upf-red-light);
  color: var(--upf-red);
  text-decoration: none;
}

.search-result-title {
  font-weight: 500;
  font-size: 0.9rem;
}

.search-result-section {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: 0.5rem;
}

.search-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.search-footer {
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

.search-footer kbd {
  background: var(--bg-light);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  font-family: inherit;
  font-size: 0.65rem;
}

/* ============ Sidebar backdrop ============ */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: var(--nav-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.35);
  z-index: 85;
}

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

/* ============ Mobile improvements ============ */
@media (max-width: 768px) {
  .navbar-brand-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
  }

  .search-hint { display: none; }

  .sidebar a {
    padding: 0.45rem 0.75rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

@media (max-width: 480px) {
  .navbar-brand-text {
    display: none;
  }

  .search-overlay {
    padding-top: 5vh;
  }

  .search-box {
    max-height: 80vh;
  }
}

/* --- Public site: upcoming-topic styles --- */
.sidebar-disabled {
  display: block;
  padding: 0.4rem 0.75rem;
  font-size: 0.93rem;
  color: var(--text-secondary);
  opacity: 0.45;
}
.card-disabled {
  opacity: 0.35;
  pointer-events: none;
}
.card-disabled .pdf-link {
  display: none;
}
