/* ==========================================================================
   Pietro Dardano - Modernist Scientific Grid
   YAGNI, minimal, clean, squared-ish aesthetic for science/robotics.
   ========================================================================== */

:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --surface-subtle: #f4f5f8;
  --border: #e2e4ea;
  --border-strong: #111111;
  --text: #1a1c20;
  --text-muted: #5f6672;
  --accent: #1155cc;
  --accent-soft: rgba(17, 85, 204, 0.08);
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sidebar-width: 320px;
  --content-max: 860px;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-subtle: #1c2129;
  --border: #30363d;
  --border-strong: #f0f6fc;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, 0.12);
  --code-bg: #1f242c;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

a:hover {
  text-decoration: underline;
}

/* Page Container */
.page-container {
  display: flex;
  max-width: 1220px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  gap: 48px;
}

/* ==========================================================================
   Left Sticky Sidebar
   ========================================================================== */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: 40px;
  align-self: flex-start;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 24px;
}

.avatar-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
  background: var(--surface-subtle);
}

.avatar-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.profile-name {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 6px;
}

.profile-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.35;
  margin-bottom: 12px;
}

.profile-affiliations {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.profile-affiliations a {
  color: var(--text);
  font-weight: 500;
}

.profile-affiliations a:hover {
  color: var(--accent);
}

.profile-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  font-size: 0.88rem;
  font-family: var(--font-mono);
  color: var(--text);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s, background-color 0.15s;
}

.link-btn:hover {
  text-decoration: none;
  border-color: var(--text-muted);
  background: var(--accent-soft);
  color: var(--accent);
}

.cv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--bg);
  background: var(--text);
  border: 1px solid var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.15s;
}

.cv-btn:hover {
  text-decoration: none;
  opacity: 0.88;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 16px;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-mono);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.theme-toggle-btn:hover {
  border-color: var(--text);
  background: var(--surface);
}

/* ==========================================================================
   Main Content Area
   ========================================================================== */
.main-content {
  flex: 1;
  min-width: 0;
  max-width: var(--content-max);
}

.section {
  margin-bottom: 52px;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 2px solid var(--text);
  padding-bottom: 8px;
  margin-bottom: 20px;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
}

.section-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Bio Text */
.bio-paragraph {
  margin-bottom: 14px;
  font-size: 1.02rem;
  color: var(--text);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 3px 8px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

/* News Feed */
.news-container {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  max-height: 380px;
  overflow-y: auto;
}

.news-item {
  display: grid;
  grid-template-columns: 85px max-content 1fr;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

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

.news-date {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.news-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 9px;
  text-align: center;
  white-space: nowrap;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.4;
}

.news-text {
  color: var(--text);
}

/* Publications */
.pub-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  transition: border-color 0.15s ease;
}

.pub-card:hover {
  border-color: var(--text-muted);
}

.pub-title {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 8px;
  color: var(--text);
}

.pub-authors {
  font-size: 0.93rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.pub-authors .author-me {
  color: var(--text);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.pub-venue {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 12px;
}

.pub-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.action-btn:hover {
  border-color: var(--text);
  color: var(--text);
  text-decoration: none;
}

.action-btn.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.pub-collapsible {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  display: none;
}

.pub-collapsible.open {
  display: block;
}

.pub-abstract-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
  background: var(--surface-subtle);
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.pub-bibtex-box {
  position: relative;
  background: var(--code-bg);
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.pub-bibtex-box pre {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.copy-bibtex-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  cursor: pointer;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
}

/* Projects */
.project-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.project-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}

.project-title {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text);
}

.project-period {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.project-summary {
  font-size: 0.92rem;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 8px;
}

.project-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 12px;
}

.project-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.project-links {
  display: flex;
  gap: 8px;
}

/* Experience & Education Timelines */
.timeline {
  border-left: 2px solid var(--border);
  padding-left: 20px;
  margin-left: 6px;
}

.timeline-item {
  position: relative;
  margin-bottom: 22px;
}

.timeline-item:last-child {
  margin-bottom: 0;
}

.timeline-marker {
  position: absolute;
  left: -27px;
  top: 4px;
  width: 12px;
  height: 12px;
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
}

.timeline-role {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text);
}

.timeline-org {
  font-size: 0.88rem;
  color: var(--accent);
  font-weight: 600;
}

.timeline-period {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.timeline-details {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Footer */
footer {
  margin-top: 60px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 900px) {
  .page-container {
    flex-direction: column;
    padding: 24px 16px 60px;
    gap: 32px;
  }
  
  .sidebar {
    width: 100%;
    position: static;
  }
  
  .avatar-wrapper {
    max-width: 180px;
    margin: 0 auto 16px;
  }
  
  .profile-name, .profile-title, .profile-affiliations {
    text-align: center;
  }
  
  .profile-links {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .news-item {
    grid-template-columns: 75px max-content 1fr;
    gap: 10px;
  }
  
  .news-badge {
    display: inline-flex;
  }
}

@media (max-width: 540px) {
  .news-item {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    align-items: center;
  }
  
  .news-text {
    width: 100%;
    margin-top: 2px;
  }
}

/* ==========================================================================
   Research Chat Assistant (Sidebar Trigger & Centered Modal Dialog)
   ========================================================================== */
.chat-assistant-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.chat-assistant-btn:hover {
  background: var(--surface-subtle);
  border-color: var(--accent);
}

.chat-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: chatFadeIn 0.18s ease;
}

.chat-modal-overlay.open {
  display: flex;
}

.chat-drawer {
  width: 520px;
  max-width: 100%;
  height: 580px;
  max-height: 85vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes chatFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes chatSlideUp {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
}

.chat-header-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.2;
}

.chat-header-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--accent);
  margin-top: 2px;
}

.chat-header-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

.chat-header-links a {
  color: var(--text-muted);
}

.chat-header-links a:hover {
  color: var(--accent);
}

.chat-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
}

.chat-close-btn:hover {
  color: var(--text);
}

.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  word-break: break-word;
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text);
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #ffffff;
}

.chat-msg.loading {
  font-style: italic;
  color: var(--text-muted);
}

.chat-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px 12px;
  border-top: 1px dashed var(--border);
  background: var(--surface);
  max-height: 110px;
  overflow-y: auto;
}

.prompt-chip {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text);
  padding: 4px 8px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.prompt-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface-subtle);
  border-top: 1px solid var(--border);
}

.chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.88rem;
  font-family: var(--font-sans);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.chat-input:focus {
  border-color: var(--accent);
}

.chat-send-btn {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.15s;
}

.chat-send-btn:hover {
  opacity: 0.9;
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 540px) {
  .chat-drawer {
    bottom: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    height: 85vh;
  }
}

