/*
 * Stylesheet for Josef Ullrich's personal academic portfolio.
 *
 * Design goals:
 *  - Clean, academic look: white cards on a soft gray background.
 *  - Fixed left sidebar with photo, name, and navigation.
 *  - Consistent spacing and image sizing so nothing overflows.
 *
 * All colors and key sizes live in the CSS variables below,
 * so the whole theme can be tweaked in one place.
 */

:root {
  color-scheme: light;
  --bg-color: #f4f4f5;          /* soft gray page background */
  --card-bg: #ffffff;           /* white cards and sidebar */
  --border-color: #e4e4e7;      /* subtle borders */
  --text-color: #3f3f46;        /* main body text */
  --text-muted: #71717a;        /* secondary text (dates, subtitles) */
  --heading-color: #18181b;     /* near-black headings */
  --accent-color: #1d4ed8;      /* deep blue accent for links */
  --tag-bg: #eef2ff;            /* light blue tag background */
  --tag-color: #3730a3;         /* tag text */
  --sidebar-width: 250px;
  --card-radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  --button-bg: #18181b;
  --button-text: #ffffff;
  --image-bg: #ffffff;
}

/* Night mode swaps the shared variables so every part of the site changes. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg-color: #0f1115;
  --card-bg: #181b21;
  --border-color: #30343d;
  --text-color: #d4d7dd;
  --text-muted: #9ca3af;
  --heading-color: #f4f4f5;
  --accent-color: #7da2ff;
  --tag-bg: #252d49;
  --tag-color: #b8c8ff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --button-bg: #f4f4f5;
  --button-text: #18181b;
  --image-bg: #ffffff;
}

/* ---------- Reset and base styles ---------- */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-color);
  background-color: var(--bg-color);
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Images should never be wider than their container */
img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--accent-color);
}

/* ---------- Layout: sidebar + main content ---------- */

.layout {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;

  background-color: var(--card-bg);
  border-right: 1px solid var(--border-color);
  padding: 2.5rem 1.5rem 1.5rem;

  /* Push the social links / copyright to the bottom */
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: center;
}

.sidebar-photo {
  /* Fixed square size so the photo is always a perfect circle */
  width: 130px;
  height: 130px;

  /* Crop the tall portrait photo to fill the square...          */
  object-fit: cover;
  /* ...positioned so the crop skips the hedge above the head    */
  /* and keeps the face centered with the shirt and tie visible. */
  object-position: 50% 60%;

  display: block;
  margin: 0 auto 1rem;
  border-radius: 50%;
  border: 3px solid var(--border-color);
}

.sidebar-name {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--heading-color);
  letter-spacing: -0.01em;
}

.sidebar-tagline {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  margin-bottom: 1.75rem;
}

/* Day/night control */
.theme-toggle {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background-color: var(--card-bg);
  color: var(--text-color);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.theme-toggle:hover {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.theme-toggle-icon {
  font-size: 1.05rem;
  line-height: 1;
}

/* Vertical navigation links */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-link {
  display: block;
  padding: 0.45rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-color);
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  background-color: var(--bg-color);
  color: var(--heading-color);
}

/* Highlight for the section currently in view (set by script.js) */
.nav-link.active {
  background-color: var(--tag-bg);
  color: var(--accent-color);
  font-weight: 600;
}

/* Bottom of sidebar: contact, CV button, copyright */
.sidebar-bottom {
  margin-top: 2rem;
}

.sidebar-social {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.social-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-color);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.social-icon:hover {
  color: var(--accent-color);
  border-color: var(--accent-color);
}

.social-icon:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.social-icon svg {
  width: 17px;
  height: 17px;
}

.resume-button {
  display: block;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  background-color: var(--button-bg);
  color: var(--button-text);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

.resume-button:hover {
  opacity: 0.85;
}

.sidebar-copyright {
  margin-top: 1rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ---------- Main content ---------- */

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 2rem 2.5rem 3rem;
}

/* Each section is a white card */
.section-card {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: var(--card-radius);
  box-shadow: var(--shadow);
  padding: 2rem 2.25rem;
  margin-bottom: 1.5rem;
  /* Offset so anchor links don't hide the heading behind the top edge */
  scroll-margin-top: 1.5rem;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.section-card h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--heading-color);
  letter-spacing: -0.01em;
  margin-bottom: 1.25rem;
}

.section-card p {
  margin-bottom: 0.9rem;
}

.section-card p:last-child {
  margin-bottom: 0;
}

/* ---------- About section ---------- */

.about-lead {
  font-weight: 600;
  color: var(--heading-color);
}

/* ============================================================
   Collapsible entries (research / experience / projects / education)

   Each entry is one clickable row (a real <button>) followed by a
   details panel that smoothly expands and collapses. The open/close
   state is a single class, "is-open", toggled by script.js.
   ============================================================ */

/* Thin divider line between entries in the same section */
.entry + .entry {
  border-top: 1px solid var(--border-color);
}

/* The <h3> wrapper only exists for document semantics; the button
   inside it does all the visual work. */
.entry-row {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

/* The whole row is one big button so the entire row is clickable. */
.entry-toggle {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 0.9rem 0.5rem;

  /* Strip default button styling so it blends into the card */
  background: none;
  border: none;
  border-radius: 8px;
  font: inherit;
  text-align: left;
  color: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.entry-toggle:hover {
  background-color: var(--bg-color);
}

/* Visible focus ring for keyboard users */
.entry-toggle:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* ---------- Project PDF buttons ---------- */

/* Each project keeps its PDF action in the upper-right corner. */
.project-entry {
  position: relative;
}

/* Leave a compact gap between the chevron and PDF action. */
.project-entry.has-pdf .entry-chevron {
  margin-right: 2.25rem;
}

/* Compact icon button inspired by a document/download control. */
.project-pdf-button {
  position: absolute;
  top: 0.8rem;
  right: 0.5rem;
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  z-index: 1;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.project-pdf-button svg {
  display: block;
  width: 1.125rem;
  height: 1.125rem;
}

.project-pdf-button:hover {
  background-color: var(--bg-color);
  border-color: var(--border-color);
  color: var(--accent-color);
}

.project-pdf-button:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* Small, consistent logo size for all organizations */
.entry-logo {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 8px;
  background-color: var(--image-bg);
}

/* Left column: organization / project title (bold) + subtitle */
.entry-left {
  flex: 1;
  min-width: 0; /* allows long titles to wrap instead of overflowing */
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.entry-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--heading-color);
  line-height: 1.4;
}

.entry-subtitle {
  font-size: 0.83rem;
  color: var(--text-muted);
}

/* Right column: role + date, right-aligned next to the chevron */
.entry-right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.1rem;
  text-align: right;
}

.entry-role {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--heading-color);
  line-height: 1.4;
}

.entry-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Chevron arrow: points right when collapsed, rotates down when open */
.entry-chevron {
  flex-shrink: 0;
  box-sizing: border-box;
  width: 28px;
  height: 28px;
  padding: 5px;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background-color: var(--bg-color);
  color: var(--heading-color);
  transition: transform 0.3s ease, border-color 0.15s ease, color 0.15s ease;
}

.entry-toggle:hover .entry-chevron {
  border-color: var(--accent-color);
  color: var(--accent-color);
}

.entry.is-open .entry-chevron {
  transform: rotate(90deg);
  border-color: var(--accent-color);
  color: var(--accent-color);
}

/* --- Expand/collapse animation ---
   The details panel is a CSS grid whose single row animates between
   0fr (fully collapsed) and 1fr (natural height). This gives a smooth
   height transition without any JavaScript measurements. */
.entry-details {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s ease;
}

.entry.is-open .entry-details {
  grid-template-rows: 1fr;
}

/* The inner wrapper must hide its overflow for the trick to work */
.entry-details-inner {
  overflow: hidden;
  min-width: 0;
}

/* Indent the details so they line up under the title, past the logo,
   and give them breathing room when open */
.entry.is-open .entry-details-inner {
  padding: 0.25rem 0.5rem 1.1rem calc(44px + 1.5rem);
}

/* Projects have no logo, so details align with the row padding only */
.entry.no-logo.is-open .entry-details-inner {
  padding-left: 0.5rem;
}

/* Fade the details in/out along with the height animation */
.entry-details-inner > * {
  opacity: 0;
  transition: opacity 0.25s ease;
}

.entry.is-open .entry-details-inner > * {
  opacity: 1;
  transition-delay: 0.1s;
}

.entry ul {
  padding-left: 1.25rem;
  margin-bottom: 1rem;
}

.entry ul li {
  margin-bottom: 0.35rem;
}

.entry-details-inner > :last-child {
  margin-bottom: 0;
}

/* ---------- Research figure ---------- */

.entry-figure-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 1rem;
  margin: 1.25rem 0;
}

.entry-figure {
  margin: 1.25rem auto;
  max-width: 560px; /* keeps the figure from dominating the page */
}

.entry-figure-grid .entry-figure {
  width: 100%;
  max-width: none;
  margin: 0;
}

.entry-figure img {
  display: block;
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 8px;
}

.entry-figure figcaption {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
  text-align: center;
}

/* ---------- Tags ---------- */

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  background-color: var(--tag-bg);
  color: var(--tag-color);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
}

/* ---------- Education coursework ---------- */

.coursework-title {
  margin-bottom: 0.6rem;
  color: var(--heading-color);
  font-size: 0.95rem;
  font-weight: 700;
}

.coursework-group + .coursework-group {
  margin-top: 0.25rem;
}

.coursework-group summary {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: fit-content;
  padding: 0.3rem 0.4rem;
  border-radius: 6px;
  color: var(--heading-color);
  font-size: 0.88rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.coursework-group summary::-webkit-details-marker {
  display: none;
}

.coursework-group summary::before {
  content: "›";
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  transition: transform 0.2s ease;
}

.coursework-group[open] summary::before {
  transform: rotate(90deg);
}

.coursework-group summary:hover {
  background-color: var(--bg-color);
  color: var(--accent-color);
}

.coursework-group summary:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.coursework-group ul {
  margin: 0.35rem 0 0.65rem 0.75rem;
  padding-left: 1.25rem;
}

.coursework-group li {
  margin-bottom: 0.25rem;
  color: var(--text-color);
  font-size: 0.87rem;
}

/* ---------- Publications placeholder ---------- */

.placeholder-note {
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- Responsive: stack sidebar on top for small screens ---------- */

@media (max-width: 820px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    position: static;       /* sidebar becomes a normal header block */
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 2rem 1.25rem 1.5rem;
  }

  /* Navigation becomes a horizontal, wrapping row of pills */
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem;
    margin-top: 0.5rem;
  }

  .sidebar-bottom {
    margin-top: 1.25rem;
  }

  .resume-button {
    display: inline-block;
  }

  .main-content {
    margin-left: 0;
    padding: 1.25rem 1rem 2rem;
  }

  .section-card {
    padding: 1.5rem 1.25rem;
  }

  .entry-figure-grid {
    grid-template-columns: 1fr;
  }

  /* On narrow screens the row wraps: logo + titles stay on the first
     line, and the role/date column drops underneath, aligned left. */
  .entry-toggle {
    flex-wrap: wrap;
    gap: 0.35rem 0.85rem;
    padding: 0.85rem 0.35rem;
  }

  .entry-left {
    /* Leave room for the chevron on the first line */
    flex: 1 1 calc(100% - 44px - 28px - 2rem);
  }

  .entry-right {
    /* Full-width second line under the logo/title.
       "order" moves it after the chevron so the chevron
       stays up on the first line next to the title. */
    order: 10;
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
    align-items: baseline;
    padding-left: calc(44px + 0.85rem); /* aligns under the title, past the logo */
    text-align: left;
  }

  .entry.no-logo .entry-right {
    padding-left: 0;
  }

  .entry.no-logo .entry-left {
    flex: 1 1 calc(100% - 28px - 1rem);
  }

  /* Details indent shrinks on mobile so text isn't squeezed */
  .entry.is-open .entry-details-inner {
    padding-left: 0.35rem;
    padding-right: 0.35rem;
  }
}
