/* ============================================
   Sidebar Layout Theme — Charles Cui
   ============================================ */

/* --- Variables & Theming --- */
:root,
[data-theme="light"] {
  --bg: #fafafa;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-muted: #555;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.1);
  --tag-bg: #e0e7ff;
  --tag-text: #3730a3;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-card: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #60a5fa;
  --accent-hover: #93bbfc;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.4);
  --tag-bg: #1e3a5f;
  --tag-text: #93c5fd;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
  transition: background 0.3s, color 0.3s;
}

a { color: var(--accent); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-hover); }

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

/* --- Site Wrapper: Sidebar + Main --- */
.site-wrapper {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 380px;
  min-width: 380px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  transition: background 0.3s;
}

.sidebar-inner {
  padding: 2.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Sidebar Profile */
.sidebar-profile {
  text-align: center;
  margin-bottom: 2rem;
}

.sidebar-photo {
  width: 200px;
  height: 200px;
  border-radius: 14px;
  object-fit: cover;
  margin-bottom: 1rem;
}

.sidebar-name {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.sidebar-title {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.2rem;
}

.sidebar-affil {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Sidebar Navigation */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 1.5rem;
}

.sidebar-nav a {
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  transition: all 0.2s;
}

.sidebar-nav a:hover {
  color: var(--text);
  background: var(--bg);
}

.sidebar-nav a.active {
  color: var(--accent);
  background: var(--tag-bg);
  font-weight: 600;
}

/* Sidebar Social */
.sidebar-social {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1.5rem;
}

.sidebar-social a {
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.2s;
}
.sidebar-social a:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* Theme toggle in sidebar */
.sidebar .theme-toggle {
  margin-top: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  font-family: inherit;
  transition: all 0.2s;
}
.sidebar .theme-toggle:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

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

/* --- Mobile Header --- */
.mobile-header {
  display: none;
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mobile-brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}
.mobile-brand:hover { color: var(--accent); }

.mobile-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-toggle-mobile {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  display: flex;
  align-items: center;
}
.theme-toggle-mobile:hover { color: var(--text); }

.mobile-menu-btn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
}
.mobile-menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform 0.3s, opacity 0.3s;
}
.mobile-menu-btn.open span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.mobile-menu-btn.open span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.open span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

/* Mobile Nav Drawer */
.mobile-nav {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 150;
  background: var(--bg-sidebar);
  padding: 4.5rem 0 2rem;
  overflow-y: auto;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}
.mobile-nav.open {
  transform: translateY(0);
}

.mobile-nav-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.mobile-nav-photo {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: cover;
}

.mobile-nav-links {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 1rem;
}

.mobile-nav-links a {
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 500;
  padding: 0.75rem 0.75rem;
  border-radius: 8px;
  transition: all 0.2s;
}
.mobile-nav-links a:hover,
.mobile-nav-links a.active {
  color: var(--accent);
  background: var(--tag-bg);
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 2.5rem 3rem 3rem 3.5rem;
  max-width: 1100px;
}

/* --- Bio intro (About page) --- */
.bio {
  margin-bottom: 2.5rem;
}

.bio p {
  font-size: 0.95rem;
  line-height: 1.75;
  margin-bottom: 1rem;
}

.bio a { font-weight: 500; }

/* --- Section --- */
.section {
  margin-bottom: 2.5rem;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
}

/* --- Experience --- */
.exp-list {
  list-style: none;
}

.exp-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.exp-item:last-child { border-bottom: none; }

.exp-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.exp-role {
  font-weight: 600;
  font-size: 0.95rem;
}

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

.exp-org {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}

.exp-desc {
  font-size: 0.88rem;
  line-height: 1.6;
  margin-bottom: 0.3rem;
}

.exp-links {
  display: inline-flex;
  gap: 0.5rem;
}

.exp-links a {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.2s;
}
.exp-links a:hover {
  border-color: var(--accent);
}

/* Secondary affiliations */
.exp-secondary-orgs {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 0.25rem;
}

.exp-secondary-orgs a {
  color: var(--text-muted);
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
}
.exp-secondary-orgs a:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}

/* Expand/collapse toggle */
.exp-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
  padding: 0.3rem 0.6rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.exp-toggle:hover {
  border-color: var(--accent);
  background: var(--tag-bg);
}

.exp-toggle-icon {
  display: inline-block;
  transition: transform 0.2s;
  font-size: 0.7rem;
}
.exp-toggle[aria-expanded="true"] .exp-toggle-icon {
  transform: rotate(90deg);
}

/* Nested experience list */
.exp-nested {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease;
}
.exp-nested.open {
  max-height: 2000px;
}

.exp-list--nested {
  margin-top: 0.75rem;
  padding: 0.5rem 0 0 1rem;
  border-left: 2px solid var(--border);
  list-style: none;
}

.exp-list--nested .exp-item {
  padding: 0.6rem 0;
}

/* --- News --- */
.news-list {
  list-style: none;
}

.news-item {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  gap: 0.75rem;
}

.news-item:last-child { border-bottom: none; }

.news-date {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  min-width: 5.5rem;
  font-weight: 500;
}

/* --- Publications --- */
.pub-list {
  list-style: none;
}

.pub-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}
.pub-item:hover { box-shadow: var(--shadow-hover); }

.pub-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

.pub-authors {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.pub-venue {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.pub-tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  margin-right: 0.5rem;
}

.pub-links {
  display: inline-flex;
  gap: 0.5rem;
}

.pub-links a {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: all 0.2s;
}
.pub-links a:hover {
  border-color: var(--accent);
}

/* Year headers in publications page */
.pub-year-heading {
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  font-size: 1.1rem;
  color: var(--text-muted);
}

/* --- Bio / Page content --- */
.page-content h1 { font-size: 1.75rem; margin-bottom: 1rem; }
.page-content h2 { font-size: 1.4rem; margin: 2rem 0 0.75rem; }
.page-content h3 { font-size: 1.15rem; margin: 1.75rem 0 0.6rem; }
.page-content p { margin-bottom: 1rem; }
.page-content ul, .page-content ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.page-content li { margin-bottom: 0.4rem; }
.page-content strong { font-weight: 600; }

/* --- Tables (food recs) --- */
.page-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.page-content th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.page-content td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.page-content tr:last-child td { border-bottom: none; }

/* --- Footer --- */
.footer {
  margin-top: 3rem;
  padding: 1.5rem 0;
  border-top: 1px solid var(--border);
}

.footer p {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* --- Responsive --- */
@media (max-width: 860px) {
  .sidebar {
    display: none;
  }

  .mobile-header {
    display: flex;
  }

  .mobile-nav {
    display: block;
  }

  .site-wrapper {
    flex-direction: column;
  }

  .main-content {
    padding: 1.5rem 1.25rem 2rem;
  }

  .exp-header {
    flex-direction: column;
    gap: 0.15rem;
  }

  .page-content table { font-size: 0.8rem; }
  .page-content th, .page-content td { padding: 0.4rem 0.5rem; }
}
