:root{
  --sidebar-w: 360px;

  --bg: #0b0f19;
  --panel: #121a2a;
  --text: #e8eefc;
  --muted: #9fb0d0;
  --accent: #4da3ff;
  --border: rgba(255,255,255,.12);

  --node-default: rgba(77,163,255,.95);
  --node-research: rgba(255,80,80,.95);
  --node-strong: rgba(140,255,170,.95);

  --link-color: rgba(255,255,255,.18);
  --weight-color: rgba(232,238,252,.92);
  --label-color: rgba(232,238,252,.92);
  --label-stroke: rgba(0,0,0,.65);

  --type-publication: #3b82f6;
  --type-dataset: #22c55e;
  --type-software: #facc15;
  --type-other: #ef4444;

  --graph-bg: radial-gradient(
    1200px 800px at 50% 40%,
    rgba(255,255,255,.06),
    transparent 60%
  );

  --overlay-bg: rgba(0,0,0,.35);
  --overlay-bg-soft: rgba(0,0,0,.28);
}

body.light-theme{
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --border: rgba(0,0,0,.12);

  --node-default: #2563eb;
  --node-research: #dc2626;
  --node-strong: #16a34a;

  --link-color: rgba(0,0,0,.18);
  --weight-color: rgba(17,24,39,.95);
  --label-color: rgba(17,24,39,.92);
  --label-stroke: rgba(255,255,255,.85);

  --type-publication: #2563eb;
  --type-dataset: #16a34a;
  --type-software: #eab308;
  --type-other: #dc2626;

  --graph-bg: radial-gradient(
    1200px 800px at 50% 40%,
    rgba(0,0,0,.05),
    transparent 60%
  );

  --overlay-bg: rgba(255,255,255,.86);
  --overlay-bg-soft: rgba(255,255,255,.74);
}

*{ box-sizing:border-box; }

.flex-between{
  display:flex;
  align-items:center;
  justify-content:space-between;
}

body{
  margin:0;
  height:100vh;
  overflow:hidden;
  font-family: system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  background:var(--bg);
  color:var(--text);
}

.app{
  display:grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height:100vh;
  width:100vw;
}

.sidebar{
  background:var(--panel);
  border-right:1px solid var(--border);
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:12px;
  overflow:auto;
}

h1{
  margin:0 0 6px 0;
  font-size:16px;
}

.btn{
  appearance:none;
  border:1px solid var(--border);
  background:rgba(255,255,255,.06);
  color:var(--text);
  padding:10px 12px;
  border-radius:10px;
  cursor:pointer;
  font-weight:600;
}

body.light-theme .btn{
  background:rgba(0,0,0,.03);
}

.btn:hover{
  border-color:rgba(255,255,255,.22);
}

body.light-theme .btn:hover{
  border-color:rgba(0,0,0,.22);
}

.btn:disabled{
  opacity:.5;
  cursor:not-allowed;
}

.theme-switch{
  appearance:none;
  position:relative;
  display:grid;
  grid-template-columns:1fr 1fr;
  align-items:center;
  width:72px;
  height:38px;
  padding:0;
  border:1px solid var(--border);
  border-radius:999px;
  background:rgba(255,255,255,.06);
  color:var(--text);
  cursor:pointer;
}

body.light-theme .theme-switch{
  background:rgba(0,0,0,.03);
}

.theme-switch:hover{
  border-color:rgba(255,255,255,.22);
}

body.light-theme .theme-switch:hover{
  border-color:rgba(0,0,0,.22);
}

.theme-switch:focus-visible{
  outline:2px solid rgba(77,163,255,.75);
  outline-offset:2px;
}

.theme-switch-icon{
  position:relative;
  z-index:1;
  display:grid;
  place-items:center;
  width:36px;
  height:36px;
  color:var(--muted);
  pointer-events:none;
  transition:color .18s ease;
}

.theme-switch-icon svg{
  width:18px;
  height:18px;
  fill:none;
  stroke:currentColor;
  stroke-width:2;
  stroke-linecap:round;
  stroke-linejoin:round;
}

.theme-switch-thumb{
  position:absolute;
  z-index:0;
  top:3px;
  left:3px;
  width:30px;
  height:30px;
  border-radius:50%;
  background:var(--accent);
  box-shadow:0 4px 12px rgba(0,0,0,.28);
  transition:transform .18s ease;
}

.theme-switch-moon{
  color:#ffffff;
}

body.light-theme .theme-switch-thumb{
  transform:translateX(36px);
}

body.light-theme .theme-switch-moon{
  color:var(--muted);
}

body.light-theme .theme-switch-sun{
  color:#ffffff;
}

.dropzone{
  border:1px dashed rgba(255,255,255,.25);
  border-radius:12px;
  padding:14px;
  color:var(--muted);
  background:rgba(255,255,255,.03);
  line-height:1.35;
  user-select:none;
}

body.light-theme .dropzone{
  border:1px dashed rgba(0,0,0,.22);
  background:rgba(0,0,0,.02);
}

.dropzone.dragover{
  border-color:var(--accent);
  color:var(--text);
  background:rgba(77,163,255,.10);
}

.viz{
  position:relative;
  height:100%;
  width:100%;
}

svg{
  width:100%;
  height:100%;
  display:block;
  background:var(--graph-bg);
}

.viz-top{
  position:absolute;
  top:12px;
  left:12px;
  right:12px;
  display:flex;
  justify-content:center;
  pointer-events:none;
}

.year-chip{
  border:1px solid var(--border);
  background:var(--overlay-bg);
  padding:10px 14px;
  border-radius:999px;
  font-size:18px;
  font-weight:700;
  color:var(--text);
  backdrop-filter: blur(6px);
}

.viz-right{
  position:absolute;
  top:12px;
  right:12px;
  bottom:56px; /* leave room for bottom buttons */
  width:340px;
  pointer-events:none;
  display:flex;
  align-items:flex-start;
  justify-content:flex-end;
  overflow:hidden;
}

.info-stack{
  width:100%;
  height:100%;
  display:flex;
  flex-direction:column;
  gap:12px;
  /* Stack distributes available height among cards; overflow scrolls the whole column */
  overflow-y:auto;
  overflow-x:hidden;
  scrollbar-width:thin;
  scrollbar-color:var(--border) transparent;
  padding-right:2px; /* avoid scrollbar overlap */
}

.info-card{
  pointer-events:auto;
  width:100%;
  /* flex-shrink + min-height:0 lets each card yield space to siblings
     and scroll its own content if it is still too tall after distribution */
  flex: 1 1 auto;
  min-height: 0;
  max-height: fit-content;
  overflow-y:auto;
  overflow-x:hidden;
  background:var(--overlay-bg);
  border:1px solid var(--border);
  border-radius:14px;
  padding:12px 12px 10px 12px;
  backdrop-filter: blur(6px);
}

.legend {
  height: fit-content !important;
  max-height: fit-content !important;
  min-height: fit-content !important;
}

.info-title{
  font-size:13px;
  font-weight:800;
  letter-spacing:.02em;
  margin-bottom:10px;
}

.info-row{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
}

.info-label{
  font-size:12px;
  color:var(--muted);
}

.info-value{
  font-size:14px;
  font-weight:800;
  color:var(--text);
}

.info-section{
  margin-top:10px;
}

.info-list{
  margin:8px 0 0 18px;
  padding:0;
  color:var(--text);
  font-size:12px;
  line-height:1.35;
}

.legend-list{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin-top:8px;
}

.legend-item{
  display:flex;
  align-items:center;
  gap:8px;
  font-size:12px;
  color:var(--text);
}

.legend-swatch{
  width:16px;
  height:10px;
  border-radius:3px;
  display:inline-block;
  border:1px solid rgba(0,0,0,.15);
}

.legend-publication{ background:var(--type-publication); }
.legend-dataset{ background:var(--type-dataset); }
.legend-software{ background:var(--type-software); }
.legend-other{ background:var(--type-other); }

.rg-overview-container{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.rg-overview-item{
  border:1px solid var(--border);
  border-radius:10px;
  overflow:hidden;
  background:rgba(255,255,255,.03);
}

body.light-theme .rg-overview-item{
  background:rgba(0,0,0,.02);
}

.rg-overview-item summary{
  cursor:pointer;
  list-style:none;
  padding:10px 12px;
  font-size:13px;
  font-weight:700;
}

.rg-overview-item summary::-webkit-details-marker{
  display:none;
}

.rg-overview-body{
  padding:0 12px 10px 12px;
}

.rg-overview-body ul{
  margin:6px 0 0 18px;
  padding:0;
  font-size:12px;
  line-height:1.35;
}

.viz-bottom{
  position:absolute;
  left:12px;
  right:12px;
  bottom:12px;
  display:flex;
  gap:10px;
  justify-content:center;
}

.hint{
  position:absolute;
  left:12px;
  bottom:60px;
  font-size:12px;
  color:var(--muted);
  background:var(--overlay-bg-soft);
  padding:8px 10px;
  border:1px solid var(--border);
  border-radius:10px;
  backdrop-filter: blur(6px);
  pointer-events:none;
}

.hidden{ display:none; }

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

.row-tight{
  align-items:center;
}

.name-search-row{
  align-items:stretch;
}

.name-search-input{
  flex:1 1 180px;
  min-width:0;
  width:auto;
}

.name-search-btn{
  flex:0 0 auto;
  min-width:88px;
}

.divider{
  height:1px;
  background:var(--border);
  opacity:.8;
  margin:4px 0;
}

.section-title{
  font-size:12px;
  color:var(--muted);
  text-transform:uppercase;
  letter-spacing:.08em;
}

.field{
  display:flex;
  flex-direction:column;
  gap:6px;
}

.label{
  font-size:12px;
  color:var(--muted);
}

.label-inline{
  font-size:12px;
  color:var(--muted);
}

.input{
  border:1px solid var(--border);
  background:rgba(0,0,0,.18);
  color:var(--text);
  padding:9px 10px;
  border-radius:10px;
  outline:none;
  width:100%;
}

body.light-theme .input{
  background:rgba(0,0,0,.03);
}

.input:focus{
  border-color:rgba(77,163,255,.55);
}

.author-combobox{
  position:relative;
}

.author-suggestions{
  position:absolute;
  z-index:30;
  top:calc(100% + 4px);
  left:0;
  right:0;
  max-height:220px;
  overflow-y:auto;
  overscroll-behavior:contain;
  padding:4px;
  border:1px solid var(--border);
  border-radius:10px;
  background:var(--panel);
  box-shadow:0 12px 28px rgba(0,0,0,.28);
}

.author-suggestions[hidden]{
  display:none;
}

.author-suggestion{
  appearance:none;
  display:block;
  width:100%;
  border:0;
  border-radius:7px;
  background:transparent;
  color:var(--text);
  padding:8px 10px;
  text-align:left;
  cursor:pointer;
}

.author-suggestion:hover,
.author-suggestion:focus{
  background:rgba(77,163,255,.14);
  outline:none;
}

.author-suggestion-name{
  display:block;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  font-size:13px;
  font-weight:700;
}

.author-suggestion-id{
  display:block;
  margin-top:2px;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  color:var(--muted);
  font-size:11px;
}

.author-suggestion-empty{
  padding:8px 10px;
  color:var(--muted);
  font-size:12px;
}

.small{
  font-size:12px;
  color:var(--muted);
}

.results-modal{
  position:fixed;
  inset:0;
  z-index:9999;
  display:grid;
  place-items:center;
  padding:24px;
  background:rgba(0,0,0,.58);
  backdrop-filter:blur(5px);
}

.results-modal[hidden]{
  display:none;
}

.results-modal-card{
  width:min(min-content, calc(100vw - 32px));
  max-height:min(78vh, 640px);
  display:flex;
  flex-direction:column;
  overflow:hidden;
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:14px;
  color:var(--text);
  box-shadow:0 24px 80px rgba(0,0,0,.42);
}

.results-modal-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  padding:18px;
  border-bottom:1px solid var(--border);
}

.results-modal-title{
  font-size:16px;
  font-weight:800;
  margin-bottom:4px;
}

.results-modal-subtitle{
  color:var(--muted);
  font-size:13px;
  line-height:1.35;
}

.results-modal-close{
  flex:0 0 auto;
}

.results-table-wrap{
  overflow:auto;
}

.results-table{
  width:100%;
  min-width:720px;
  border-collapse:collapse;
  font-size:13px;
  table-layout:auto;
}

.results-table th,
.results-table td{
  padding:12px 14px;
  border-bottom:1px solid var(--border);
  text-align:left;
  vertical-align:top;
}

.results-table th{
  position:sticky;
  top:0;
  z-index:1;
  background:var(--panel);
  color:var(--muted);
  font-size:12px;
  font-weight:800;
}

.results-table tbody tr:hover{
  background:rgba(77,163,255,.10);
}

.results-table td{
  overflow:hidden;
  text-overflow:ellipsis;
}

.results-table-name,
.results-table-orcid,
.results-table-institution,
.results-table-action{
  white-space:nowrap;
}

.results-table-name{
  width:26%;
  max-width:260px;
}

.results-table-orcid{
  width:170px;
}

.results-table-institution{
  width:auto;
  max-width:42ch;
}

td.results-table-institution[title]{
  cursor:help;
}

.results-table-action{
  width:96px;
  min-width:96px;
  text-align:right;
}

.results-empty{
  padding:18px;
  color:var(--muted);
  font-size:13px;
}

.result-select-btn{
  padding:8px 10px;
  border-radius:8px;
  min-width:72px;
  white-space:nowrap;
}

body.light-theme .results-modal{
  background:rgba(17,24,39,.34);
}

body.light-theme .results-modal-card{
  box-shadow:0 24px 80px rgba(17,24,39,.24);
}

.color{
  width:44px;
  height:32px;
  padding:0;
  border:1px solid var(--border);
  border-radius:10px;
  background:rgba(0,0,0,.18);
  cursor:pointer;
}

body.light-theme .color{
  background:rgba(0,0,0,.03);
}

.color::-webkit-color-swatch-wrapper{ padding:0; }
.color::-webkit-color-swatch{
  border:none;
  border-radius:8px;
}

.dialog{
  border:none;
  padding:0;
  background:transparent;
}

.dialog::backdrop{
  background: rgba(0,0,0,.55);
}

.dialog-card{
  width:min(420px, calc(100vw - 24px));
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:14px;
  padding:16px;
  color:var(--text);
}

.dialog-title{
  font-size:15px;
  font-weight:700;
  margin-bottom:4px;
}

.dialog-subtitle{
  font-size:12px;
  color:var(--muted);
  margin-bottom:12px;
}

.dialog-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  margin-top:14px;
}

.edge-dialog-card{
  width:min(560px, calc(100vw - 24px));
  max-height:80vh;
  overflow:auto;
}

.edge-link{
  color:var(--accent);
  text-decoration:none;
  font-size:13px;
  font-weight:600;
}

.edge-link:hover{
  text-decoration:underline;
}

.error-modal{
  position:fixed;
  inset:0;
  z-index:10000;
  display:grid;
  place-items:center;
  padding:24px;
  background:rgba(0,0,0,.58);
  backdrop-filter:blur(5px);
}

.error-modal[hidden]{
  display:none;
}

.error-modal-card{
  width:min(480px, calc(100vw - 32px));
  max-height:min(70vh, 520px);
  overflow:auto;
  background:var(--panel);
  border:1px solid var(--border);
  border-top:4px solid #ff6b6b;
  border-radius:14px;
  padding:18px;
  color:var(--text);
  box-shadow:0 24px 80px rgba(0,0,0,.42);
}

.error-modal-title{
  font-size:16px;
  font-weight:800;
  margin-bottom:10px;
}

.error-modal-details{
  color:var(--muted);
  font-size:13px;
  line-height:1.45;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
}

.error-modal-actions{
  display:flex;
  justify-content:flex-end;
  margin-top:18px;
}

body.light-theme .error-modal{
  background:rgba(17,24,39,.34);
}

body.light-theme .error-modal-card{
  border-top-color:#dc2626;
  box-shadow:0 24px 80px rgba(17,24,39,.24);
}
/* ═══════════════════════════════════════════════════════════════════════════
   NUOVO: Timeline + graph layout
   ═══════════════════════════════════════════════════════════════════════════ */

.viz { /* NUOVO */
  display: flex; /* NUOVO */
  flex-direction: column; /* NUOVO */
  height: 100vh; /* NUOVO */
  width: 100%; /* NUOVO */
  overflow: hidden; /* NUOVO */
  position: relative; /* NUOVO */
} /* NUOVO */

/* NUOVO: scrollable timeline strip at the top */
.timeline-panel { /* NUOVO */
  flex: 0 0 auto; /* NUOVO */
  height: 160px; /* NUOVO */
  background: var(--panel); /* NUOVO */
  border-bottom: 2px solid var(--border); /* NUOVO */
  overflow-x: scroll; /* NUOVO */
  overflow-y: hidden; /* NUOVO */
  position: relative; /* NUOVO */
  z-index: 2; /* NUOVO */
  scrollbar-width: thin; /* NUOVO */
  scrollbar-color: var(--border) transparent; /* NUOVO */
} /* NUOVO */

.timeline-panel > svg{
  width: max-content;
  height: 100%;
  display: block;
}

/* NUOVO: graph takes all remaining height */
.graph-panel { /* NUOVO */
  flex: 1 1 0; /* NUOVO */
  position: relative; /* NUOVO */
  overflow: hidden; /* NUOVO */
  min-height: 0; /* NUOVO */
} /* NUOVO */
/*
.graph-panel > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--graph-bg);
}

.graph-panel .viz-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
}

.graph-panel .viz-right {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: 56px;
}

.graph-panel .viz-bottom {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
}

.graph-panel .hint {
  position: absolute;
  left: 12px;
  bottom: 60px;
} */

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE: tablet and mobile
   ═══════════════════════════════════════════════════════════════════════════ */

/* Tablet: narrow sidebar */
@media (max-width: 900px) {
  :root {
    --sidebar-w: 260px;
  }

  .viz-right {
    width: 260px;
  }

  .info-card {
    font-size: 11px;
  }

  .timeline-panel {
    height: 120px;
  }
}

/* Mobile: stack sidebar below the viz, full-width layout */
@media (max-width: 640px) {
  :root {
    --sidebar-w: 100vw;
  }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    height: 100dvh;
  }

  .sidebar {
    border-right: none;
    border-top: 1px solid var(--border);
    max-height: 40vh;
    overflow-y: auto;
    order: 2; /* sidebar goes below viz on mobile */
  }

  .viz {
    order: 1;
    height: 60dvh;
  }

  .timeline-panel {
    height: 100px;
  }

  /* Right panel becomes a bottom sheet on mobile */
  .viz-right {
    position: absolute;
    top: auto;
    bottom: 56px;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: 40%;
  }

  .info-stack {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 8px;
  }

  .info-card {
    min-width: 240px;
    max-height: 100%;
    flex-shrink: 0;
  }

  .hint {
    display: none; /* hide hint on small screens */
  }

  .year-chip {
    font-size: 14px;
    padding: 6px 10px;
  }
}
