:root {
  --bg: #fafafa;
  --panel: #fff;
  --text: #222;
  --muted: #888;
  --border: #ddd;
  --border-soft: #eee;
  --row-border: #f2f2f2;
  --accent: #2c3e50;
  --accent-hover: #1a2530;
  --link: #2c3e50;
  --tag-bg: #eef;
  --tag-fg: #447;
  --code-bg: #f2f2f2;
  --status-bg: #fafafa;
  --input-bg: #fff;
  --input-border: #ccc;
}
body[data-theme="dark"] {
  --bg: #15181c;
  --panel: #1e2227;
  --text: #e6e8ea;
  --muted: #8a929b;
  --border: #2a2f36;
  --border-soft: #23272d;
  --row-border: #23272d;
  --accent: #4a90d9;
  --accent-hover: #6aa8e8;
  --link: #6aa8e8;
  --tag-bg: #2a3446;
  --tag-fg: #9bb7e0;
  --code-bg: #262b32;
  --status-bg: #181b1f;
  --input-bg: #262b32;
  --input-border: #3a4048;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 14px/1.4 -apple-system, system-ui, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
body { display: flex; flex-direction: column; }
header { position: relative; z-index: 1100; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.titlebar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
h1 { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 16px; font-weight: 600; }
.brand-icon { display: block; flex: 0 0 32px; }
h1 .sub { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; font-size: 13px; }
.controls input, .controls select, .controls button { font: inherit; padding: 4px 8px; border: 1px solid var(--input-border); border-radius: 3px; background: var(--input-bg); color: var(--text); }
.controls button#go,
.controls button#topic-go,
.controls button#country-go,
.controls button#professor-open,
.controls button#professor-add,
.controls button#professor-overview-refresh,
.controls button#professor-overview-add-country { cursor: pointer; background: var(--accent); color: #fff; border: 0; padding: 6px 16px; border-radius: 3px; }
.controls button#go:hover,
.controls button#topic-go:hover,
.controls button#country-go:hover,
.controls button#professor-open:hover,
.controls button#professor-add:hover,
.controls button#professor-overview-refresh:hover,
.controls button#professor-overview-add-country:hover { background: var(--accent-hover); }
.controls button#professor-save-md,
.controls button#professor-overview-save-md,
.controls button#professor-import-md,
.controls button#professor-overview-import-md {
  cursor: pointer;
  background: #1f8a70;
  color: #fff;
  border: 0;
  padding: 6px 16px;
  border-radius: 3px;
}
.controls button#professor-save-md:hover,
.controls button#professor-overview-save-md:hover,
.controls button#professor-import-md:hover,
.controls button#professor-overview-import-md:hover { background: #166b57; }
.controls button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.controls button#back { cursor: pointer; padding: 4px 10px; background: var(--input-bg); color: var(--text); border: 1px solid var(--input-border); }
.controls button#back:disabled { opacity: 0.4; cursor: not-allowed; }
.mode-tabs { display: flex; gap: 4px; margin-left: auto; }
.mode-tabs button,
.info-button,
#theme-toggle { cursor: pointer; font: inherit; padding: 4px 10px; border: 1px solid var(--input-border); border-radius: 3px; background: var(--input-bg); color: var(--text); }
.info-button { display: inline-flex; align-items: center; text-decoration: none; }
.info-button:hover { border-color: var(--link); }
.info-button:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.mode-tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
[hidden] { display: none !important; }
.seniority-badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px; margin-right: 5px; border-radius: 10px; font-size: 10px; font-weight: 600; vertical-align: middle; white-space: nowrap; }
.seniority-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; }
.seniority-badge.seniority-senior { color: #1d4ed8; background: #dbeafe; }
.seniority-badge.seniority-junior { color: #15803d; background: #dcfce7; }
.seniority-badge.seniority-basic { color: #a93226; background: #fde2df; }
.seniority-senior .seniority-dot, .seniority-dot.seniority-senior { background: #3b82f6; }
.seniority-junior .seniority-dot, .seniority-dot.seniority-junior { background: #22c55e; }
.seniority-basic .seniority-dot, .seniority-dot.seniority-basic { background: #e74c3c; }
.person-row { border-left: 3px solid #e74c3c; padding-left: 8px; }
.person-row.seniority-senior { border-left-color: #3b82f6; }
.person-row.seniority-junior { border-left-color: #22c55e; }
body[data-theme="dark"] .seniority-badge.seniority-senior { color: #93c5fd; background: #1e3a5f; }
body[data-theme="dark"] .seniority-badge.seniority-junior { color: #86efac; background: #173d2a; }
body[data-theme="dark"] .seniority-badge.seniority-basic { color: #fca5a5; background: #4a2323; }
.seniority-legend { display: flex; flex-direction: column; gap: 3px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; background: color-mix(in srgb, var(--panel) 92%, transparent); color: var(--text); box-shadow: 0 1px 4px rgb(0 0 0 / 18%); font: 11px/1.2 -apple-system, system-ui, "Segoe UI", sans-serif; }
.seniority-legend span { display: flex; align-items: center; gap: 5px; }
.topics label { margin-right: 6px; font-weight: normal; }
main { display: grid; grid-template-columns: 1fr 400px; flex: 1; min-height: 0; }
#map { height: 100%; background: var(--bg); }
#panel { border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; background: var(--panel); }
#profile { padding: 10px 16px; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
#profile h2 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
#profile .affil { color: var(--muted); font-size: 12px; }
.tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--border-soft); }
.tabs button { flex: 1; background: none; border: 0; padding: 8px; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--link); border-bottom-color: var(--link); }
.tab { display: none; flex: 1; overflow: auto; padding: 4px 16px; }
.tab.active { display: block; }
.row { padding: 8px 0; border-bottom: 1px solid var(--row-border); }
.row:last-child { border-bottom: 0; }
.title, .name { font-weight: 500; font-size: 13px; }
.title a, .name a { color: var(--link); text-decoration: none; }
.title a:hover, .name a:hover { text-decoration: underline; }
.meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.tag { display: inline-block; padding: 1px 5px; margin-right: 4px; background: var(--tag-bg); color: var(--tag-fg); border-radius: 2px; font-size: 10px; }
.w { font-size: 11px; color: var(--muted); font-weight: normal; margin-left: 6px; }
.ext { font-size: 11px; color: var(--muted); text-decoration: none; margin-left: 4px; }
.ext:hover { color: var(--link); }
.copy-inspire { margin-left: 6px; padding: 1px 6px; border: 1px solid var(--input-border); border-radius: 3px; background: var(--input-bg); color: var(--muted); font: inherit; font-size: 10px; line-height: 1.4; cursor: pointer; vertical-align: middle; }
.copy-inspire:hover { color: var(--link); border-color: var(--link); }
.copy-inspire.copied { color: #196f3d; border-color: #27ae60; background: #d4efdf; }
body[data-theme="dark"] .copy-inspire.copied { color: #82e0aa; border-color: #58d68d; background: #1e4d2f; }
#status { padding: 6px 16px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--border-soft); background: var(--status-bg); }
code { background: var(--code-bg); padding: 1px 4px; border-radius: 2px; font-size: 12px; }
.leaflet-popup-content { font: 12px system-ui; }
.leaflet-popup-content b { color: var(--accent); }
.leaflet-popup-content a.popup-author-link { color: var(--link); font-weight: 600; text-decoration: none; }
.leaflet-popup-content a.popup-author-link:hover { text-decoration: underline; }
body[data-theme="dark"] .leaflet-popup-content-wrapper,
body[data-theme="dark"] .leaflet-popup-tip { background: #262b32; color: #e6e8ea; }
body[data-theme="dark"] .leaflet-container { background: #15181c; }
body[data-theme="dark"] { color-scheme: dark; }
body[data-theme="dark"] .leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--border); }
body[data-theme="dark"] .leaflet-control-attribution { background: var(--panel); color: var(--muted); }
body[data-theme="dark"] .leaflet-control-attribution a { color: var(--link); }


footer { padding: 7px 14px; border-top: 1px solid var(--border); background: var(--panel); color: var(--muted); font-size: 12px; }
footer a { color: var(--link); }
#map, #panel { min-width: 0; }
.controls { row-gap: 10px; }
#profile, .title, .name { font-size: 14px; }
.meta, #profile .affil, #status { font-size: 12px; }
@media (max-width: 760px) {
  body { height: auto; min-height: 100dvh; overflow: auto; }
  .titlebar { flex-wrap: wrap; gap: 10px; }
  h1 .sub { display: block; margin: 4px 0 0; }
  .mode-tabs { margin-left: 0; }
  .controls { font-size: 14px; padding: 10px; }
  .controls input { max-width: 85vw; }
  main { display: flex; flex-direction: column; min-height: 75vh; }
  #map { height: 48vh; min-height: 300px; flex: none; }
  #panel { border-left: 0; min-height: 340px; }
  .tab { max-height: 65vh; }
}

/* Keep collaboration links clear against both basemap themes. */
.connection-line { stroke: #57758e; }
body[data-theme="dark"] .connection-line { stroke: #718496; }
.footer-credit { color: var(--text); font-weight: 600; margin-right: 8px; }
#retry-cites { cursor: pointer; color: var(--text); background: var(--input-bg); border: 1px solid var(--input-border); border-radius: 3px; padding: 5px 10px; }

/* Citation map tab shares the full map and preserves the collaboration view. */
.tabs button { min-width: 45%; }
.citation-map-view #map .seniority-legend { display: none; }
.citation-summary { font-size: 13px; padding: 4px 0; }
.citation-summary h3 { margin: 8px 0; font-size: 15px; }
.citation-note { color: var(--muted); font-size: 12px; }
.citation-focus { background: none; border: 0; color: var(--link); font: inherit; padding: 0; cursor: pointer; text-align: left; }
.citation-focus:hover { text-decoration: underline; }
.citation-papers { font-size: 12px; margin-top: 6px; }
.citation-papers summary { cursor: pointer; color: var(--muted); }

.author-lookup { display: inline-flex; align-items: center; gap: 6px; }
.author-input-wrap { position: relative; }
.author-suggestions { position: absolute; left: 0; top: calc(100% + 6px); width: 360px; border: 1px solid var(--input-border); border-radius: 8px; background: var(--panel); box-shadow: 0 10px 30px rgb(0 0 0 / 25%); overflow: hidden; }
#author-suggestion-list { list-style: none; margin: 0; padding: 4px; max-height: 340px; overflow-y: auto; overscroll-behavior: contain; }
#author-suggestion-list:empty { display: none; }
#author-suggestion-list li { display: flex; flex-direction: column; gap: 2px; padding: 9px 10px; border-radius: 5px; cursor: pointer; }
#author-suggestion-list li[aria-selected="true"], #author-suggestion-list li:hover { background: #eaf2fa; }
body[data-theme="dark"] #author-suggestion-list li[aria-selected="true"], body[data-theme="dark"] #author-suggestion-list li:hover { background: #293b4e; }
.suggestion-name { color: var(--text); font-weight: 600; }
.suggestion-bai { color: var(--link); font: 12px/1.4 ui-monospace, monospace; overflow-wrap: anywhere; }
.suggestion-institution { color: var(--muted); font-size: 12px; }
#author-suggestion-status { padding: 9px 12px; color: var(--muted); font-size: 11px; }
@media (max-width: 760px) {
  .author-lookup { position: relative; }
  .author-input-wrap { position: static; }
  .author-suggestions { width: min(360px, calc(100vw - 52px)); }
}
