:root {
  --bg: #f5f7fa;
  --panel-bg: #ffffff;
  --border: #d8dee6;
  --text: #1f2933;
  --muted: #5f6b7a;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --highlight-bg: #fff7e6;
  --highlight-border: #f5b942;
  --badge-bg: #eef2ff;
  --badge-text: #3730a3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  padding: 2rem 1.5rem 1rem;
  text-align: center;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.8rem;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 3fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 1rem;
  /* offsets the #status line above .results so the controls box and the
     first result card line up visually */
  margin-top: 2.5rem;
}

.results-panel {
  min-width: 0;
}

.right-column {
  position: sticky;
  top: 1rem;
  margin-top: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.summary-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  max-height: calc(100vh - 2rem - 2.5rem);
  overflow-y: auto;
}

.summary-panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
}

.summary-panel ul {
  margin: 0;
  padding-left: 1.1rem;
}

.summary-panel .institution-match {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.summary-panel .institution-match h4 {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--highlight-border);
}

.summary-panel .institution-match ul {
  padding-left: 1.1rem;
}

.summary-panel .institution-match li {
  margin-bottom: 0.25rem;
}

.summary-panel .summary-loading {
  font-style: italic;
}

.summary-panel .summary-error {
  color: #b91c1c;
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    margin-top: 0;
  }

  .right-column {
    display: none;
  }
}

.controls {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.control-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.control-group .hint {
  font-size: 0.75rem;
  color: var(--muted);
}

select,
input[type="text"] {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--panel-bg);
  color: var(--text);
}

select:focus,
input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.toggle-btn {
  padding: 0.5rem 0.4rem;
  border: none;
  background: var(--panel-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s, color 0.15s;
}

.toggle-btn:nth-child(3) {
  grid-column: 1 / -1;
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.primary-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.primary-btn:hover:not(:disabled) {
  background: var(--accent-dark);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.secondary-btn {
  width: 100%;
  padding: 0.65rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.secondary-btn:hover:not(:disabled) {
  background: var(--badge-bg);
}

.secondary-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.link-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  margin-bottom: 1rem;
}

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

.status {
  min-height: 1.5rem;
  margin-bottom: 1rem;
  padding: 0 0.25rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.status.error {
  color: #b91c1c;
}

.status.empty {
  color: var(--muted);
}

.results {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.results[hidden] {
  display: none;
}

.card {
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.card:hover {
  background: #e8f0fe;
  border-color: var(--accent);
}

.card.highlighted {
  background: var(--highlight-bg);
  border-color: var(--highlight-border);
}

.card.highlighted:hover {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.card-title {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  line-height: 1.35;
}

.card-title a {
  color: var(--text);
  text-decoration: none;
}

.card-title a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.journal {
  font-style: italic;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.if-badge {
  background: var(--badge-bg);
  color: var(--badge-text);
}

.if-badge.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.github-badge {
  background: #24292f;
  color: #fff;
  text-decoration: none;
  transition: background 0.15s;
}

.github-badge:hover {
  background: #000;
}

.institution-badge {
  position: absolute;
  top: -0.6rem;
  right: 1rem;
  background: var(--highlight-border);
  color: #4a3300;
}

.authors {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.author-match {
  font-weight: 700;
  color: var(--accent-dark);
  background: var(--badge-bg);
  border-radius: 4px;
  padding: 0 0.2rem;
}

.abstract {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}

.abstract summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

.abstract p {
  margin: 0.5rem 0 0;
  color: var(--text);
}

.digest-panel {
  /* matches .sidebar/.summary-panel margin-top, since #status/#results
     (which the sidebar's offset accounts for) are hidden in this view */
  margin-top: 2.5rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

.digest-panel h2 {
  margin: 0 0 0.5rem;
}

.digest-meta {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.digest-content p {
  margin: 0 0 1rem;
  line-height: 1.6;
}

.digest-content a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.digest-content a:hover {
  text-decoration: underline;
}

.digest-content .digest-sources {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.digest-content .digest-sources h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.digest-content .digest-sources ol {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.9rem;
}

.digest-content .digest-sources li {
  margin-bottom: 0.35rem;
}

.digest-loading,
.digest-error {
  font-style: italic;
  color: var(--muted);
}

.digest-error {
  color: #b91c1c;
  font-style: normal;
}

.digest-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.digest-actions .secondary-btn {
  width: auto;
}

.digest-email {
  display: flex;
  gap: 0.5rem;
}

.digest-email input[type="email"] {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.digest-history {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem;
}

.digest-history h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.digest-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.digest-history-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.digest-history-item:hover {
  background: var(--badge-bg);
  border-color: var(--accent);
}

.digest-history-meta {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.digest-history-time {
  font-size: 0.7rem;
  color: var(--muted);
}

footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

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

footer code {
  background: var(--badge-bg);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}
