/* AcaTel — "annotated journal" theme
   Ink-blue structure, cool paper surface, one highlighter accent used only for
   things a researcher would mark: interests, open deadlines, AI summaries. */

:root {
  --ink: #1b2a4a;
  --ink-2: #33456b;
  --muted: #5d6a82;
  --paper: #f7f8fa;
  --surface: #ffffff;
  --rule: #d9dee7;
  --rule-soft: #eaedf2;
  --link: #0f6e6e;
  --mark: #ffe066;
  --mark-soft: rgba(255, 224, 102, .45);
  --danger: #b4413c;
  --ok: #2f7d4f;
  --nav-bg: #1b2a4a;
  --nav-text: #c9d3e6;
  --nav-active: #ffffff;
  --shadow: 0 1px 2px rgba(27, 42, 74, .06), 0 4px 16px rgba(27, 42, 74, .05);
  --radius-s: 4px;
  --radius-m: 8px;
  --font-body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Literata", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e6eaf2; --ink-2: #c3cbdb; --muted: #95a1b8; --paper: #0f1626; --surface: #17213a;
    --rule: #2a3653; --rule-soft: #212c46; --link: #6cc7c0; --mark: #e8c547; --mark-soft: rgba(232, 197, 71, .25);
    --danger: #e07a73; --ok: #6fc391; --nav-bg: #0b1120; --nav-text: #9aa7c2;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #e6eaf2; --ink-2: #c3cbdb; --muted: #95a1b8; --paper: #0f1626; --surface: #17213a;
  --rule: #2a3653; --rule-soft: #212c46; --link: #6cc7c0; --mark: #e8c547; --mark-soft: rgba(232, 197, 71, .25);
  --danger: #e07a73; --ok: #6fc391; --nav-bg: #0b1120; --nav-text: #9aa7c2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 15px/1.55 var(--font-body);
}
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 2px; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; line-height: 1.2; margin: 0; }
h1 { font-size: 1.9rem; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Highlighter mark — the one bold element */
.mark {
  background: linear-gradient(transparent 38%, var(--mark-soft) 38%, var(--mark-soft) 92%, transparent 92%);
  padding: 0 .15em; border-radius: 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone;
}

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--nav-bg); color: var(--nav-text); padding: 22px 14px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; padding: 0 8px; }
.brand svg { flex: none; }
.brand b { font-family: var(--font-head); font-size: 1.35rem; font-weight: 600; letter-spacing: .01em; }
.brand small { display: block; font-size: .72rem; color: var(--nav-text); font-weight: 400; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: .75rem; color: var(--nav-text); opacity: .7; padding: 12px 10px 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-s);
  color: var(--nav-text); text-decoration: none; font-size: .93rem;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a[aria-current="page"] { background: rgba(255, 255, 255, .1); color: var(--nav-active); box-shadow: inset 3px 0 0 var(--mark); }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.sidebar-foot { margin-top: auto; font-size: .8rem; padding: 0 8px; display: grid; gap: 6px; }
.sidebar-foot a { color: var(--nav-text); }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 32px; border-bottom: 1px solid var(--rule); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: .9rem; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: var(--paper); font-weight: 600; font-size: .85rem;
}
.topbar .menu-btn { display: none; }
.content { padding: 28px 32px 64px; max-width: 1180px; }
.page-head { margin-bottom: 22px; display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; color: var(--muted); max-width: 62ch; }
.badge-demo {
  display: inline-block; font-size: .78rem; padding: 3px 10px; border-radius: 999px;
  border: 1px dashed var(--muted); color: var(--muted);
}

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: .9rem; font-weight: 500;
  padding: 8px 14px; border-radius: var(--radius-s); border: 1px solid var(--rule); background: var(--surface);
  color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { background: var(--ink-2); }
.btn-ghost { border-color: transparent; background: transparent; padding: 6px 8px; color: var(--link); }
.btn-ghost:hover { border-color: transparent; text-decoration: underline; }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn.is-saved { color: var(--ok); }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-s); padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--link); outline-offset: -1px; border-color: transparent; }
label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); }
label > span { font-weight: 500; }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end; padding: 16px; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius-m); margin-bottom: 20px;
}
.filters > label { flex: 1 1 130px; }
.filters > label:first-child { flex: 2.4 1 240px; }
.filters .btn { height: 39px; flex: 0 0 auto; }

/* ---------- Panels / sections ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); padding: 20px; }
.panel + .panel { margin-top: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }

/* Dashboard briefing — sentences, not stat tiles */
.briefing { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--rule); border-radius: var(--radius-m); background: var(--surface); overflow: hidden; margin-bottom: 20px; }
.briefing a { padding: 16px 18px; text-decoration: none; color: var(--ink); border-right: 1px solid var(--rule); display: grid; gap: 2px; }
.briefing a:last-child { border-right: 0; }
.briefing a:hover { background: var(--rule-soft); }
.briefing strong { font-family: var(--font-head); font-size: 1.6rem; font-weight: 600; }
.briefing span { color: var(--muted); font-size: .88rem; }

.chips { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.chip { font-size: .9rem; }
.chip.mark { font-weight: 500; }

/* ---------- Result lists ---------- */
.results { display: grid; gap: 0; }
.results-empty, .results-loading, .results-error {
  padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--rule); border-radius: var(--radius-m);
}
.results-error { color: var(--danger); border-color: var(--danger); }
.skeleton { height: 76px; border-radius: var(--radius-s); background: linear-gradient(90deg, var(--rule-soft), var(--surface), var(--rule-soft)); background-size: 200% 100%; animation: shimmer 1.3s infinite linear; margin-bottom: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Bibliography-style paper entry with hanging indent */
.entry {
  padding: 16px 0 16px 0; border-bottom: 1px solid var(--rule-soft);
  display: grid; grid-template-columns: 1fr auto; gap: 4px 20px;
}
.entry:first-child { padding-top: 4px; }
.entry-title { font-family: var(--font-head); font-size: 1.08rem; font-weight: 600; line-height: 1.3; }
.entry-title a { color: var(--ink); text-decoration: none; }
.entry-title a:hover { color: var(--link); text-decoration: underline; }
.entry-meta { color: var(--muted); font-size: .88rem; padding-left: 1.4em; text-indent: -1.4em; }
.entry-meta em { font-style: italic; color: var(--ink-2); }
.entry-summary { grid-column: 1 / -1; font-size: .93rem; max-width: 78ch; }
.entry-summary .label { color: var(--muted); font-size: .82rem; margin-right: 4px; }
.entry-side { text-align: right; font-size: .85rem; color: var(--muted); grid-row: span 2; }
.entry-side b { display: block; font-family: var(--font-head); font-size: 1.3rem; color: var(--ink); }
.entry-actions { grid-column: 1 / -1; display: flex; gap: 4px; flex-wrap: wrap; margin-left: -8px; }
.tag { font-size: .78rem; border: 1px solid var(--rule); border-radius: 999px; padding: 1px 8px; color: var(--ink-2); white-space: nowrap; }
.tag-tier { border-color: var(--ink-2); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius-m); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .82rem; background: var(--paper); }
tr:last-child td { border-bottom: 0; }
td.when { white-space: nowrap; }
.closed { color: var(--muted); text-decoration: line-through; }
.countdown { display: block; font-size: .8rem; color: var(--muted); }

/* Programme / funding rows */
.row-item { display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; padding: 14px 0; border-bottom: 1px solid var(--rule-soft); }
.row-item h3 a { color: var(--ink); text-decoration: none; }
.row-item h3 a:hover { color: var(--link); text-decoration: underline; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .88rem; color: var(--muted); }
.facts b { color: var(--ink); font-weight: 500; }

/* News */
.news-item { display: grid; grid-template-columns: 1fr 96px; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--rule-soft); }
.news-item img { width: 96px; height: 72px; object-fit: cover; border-radius: var(--radius-s); background: var(--rule-soft); }
.news-item h3 a { color: var(--ink); text-decoration: none; }
.news-item h3 a:hover { text-decoration: underline; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { font: inherit; font-size: .9rem; border: 0; background: none; padding: 6px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tabs button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* Rankings */
.rank-table td:first-child { font-weight: 500; }
.rank-val { display: block; }
.rank-src { font-size: .78rem; }
.na { color: var(--muted); font-style: italic; }

/* Interest strength bars */
.strength { display: grid; gap: 12px; }
.strength-row { display: grid; grid-template-columns: 160px 1fr 44px; gap: 12px; align-items: center; font-size: .92rem; }
.bar { height: 8px; background: var(--rule-soft); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ink-2); border-radius: 999px; }
.interest-edit { display: grid; grid-template-columns: 1fr 120px 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
.interest-edit input[type=range] { padding: 0; border: 0; background: none; }

/* Graph */
#graph { width: 100%; height: 560px; display: block; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-m); touch-action: none; }
.graph-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: 10px; }
.graph-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

/* Copilot */
.copilot { display: grid; grid-template-columns: 1fr 300px; gap: 18px; align-items: start; }
.mode-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.mode-pick input { position: absolute; opacity: 0; width: 1px; }
.mode-pick label { display: inline-block; cursor: pointer; font-size: .9rem; color: var(--ink); border: 1px solid var(--rule); border-radius: 999px; padding: 5px 12px; }
.mode-pick input:checked + label { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.mode-pick input:focus-visible + label { outline: 2px solid var(--link); outline-offset: 2px; }
.answer { font-size: .97rem; line-height: 1.65; }
.answer h2 { font-size: 1.15rem; margin: 1.2em 0 .4em; }
.answer h2:first-child { margin-top: 0; }
.answer ul, .answer ol { padding-left: 1.3em; }
.answer li { margin-bottom: .3em; }
.answer blockquote { margin: 1em 0; padding: 6px 12px; border-left: 3px solid var(--mark); color: var(--muted); }
.answer sup a { text-decoration: none; font-size: .78em; padding: 0 1px; }
.sources ol { padding-left: 1.3em; font-size: .88rem; }
.sources li { margin-bottom: 6px; }
.history-item { display: block; width: 100%; text-align: left; font: inherit; border: 0; border-bottom: 1px solid var(--rule-soft); background: none; padding: 10px 0; cursor: pointer; color: var(--ink); }
.history-item small { display: block; color: var(--muted); }

/* Roadmap */
.roadmap { list-style: none; margin: 0; padding: 0; position: relative; }
.roadmap::before { content: ""; position: absolute; left: 13px; top: 8px; bottom: 8px; width: 2px; background: var(--rule); }
.step { position: relative; display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; align-items: center; padding: 8px 0; }
.step button.tick {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--ink-2); background: var(--surface);
  cursor: pointer; display: grid; place-items: center; z-index: 1; padding: 0; color: var(--paper);
}
.step.done button.tick { background: var(--ok); border-color: var(--ok); }
.step.done .step-title { color: var(--muted); }
.step.next .step-title { font-weight: 600; }
.step.next .step-title span { background: linear-gradient(transparent 40%, var(--mark-soft) 40%); }
.step-tools { display: flex; gap: 2px; }
.progress-line { font-size: .92rem; color: var(--muted); margin-bottom: 12px; }
.suggestion { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--rule-soft); }

/* Saved */
.status-select { width: auto; padding: 4px 8px; font-size: .85rem; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: var(--radius-s); font-size: .9rem; box-shadow: var(--shadow); z-index: 50;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* Auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-art { background: var(--nav-bg); color: #e6eaf2; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-art h1 { font-size: 2.6rem; max-width: 14ch; color: #fff; }
.auth-art p { max-width: 44ch; color: #c9d3e6; font-size: 1.05rem; }
.auth-art .ref { font-size: .88rem; color: #9aa7c2; border-left: 3px solid #ffe066; padding-left: 12px; max-width: 46ch; }
.auth-form { display: grid; place-items: center; padding: 32px; }
.auth-form form { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.alert { padding: 10px 12px; border-radius: var(--radius-s); background: rgba(180, 65, 60, .1); color: var(--danger); font-size: .9rem; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid-3, .copilot { grid-template-columns: 1fr; }
  .briefing { grid-template-columns: repeat(2, 1fr); }
  .briefing a:nth-child(2) { border-right: 0; }
  .briefing a:nth-child(-n+2) { border-bottom: 1px solid var(--rule); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 272px; transform: translateX(-100%); transition: transform .2s; z-index: 30; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .topbar .who > .muted { display: none; }
  .badge-demo { white-space: nowrap; font-size: .72rem; padding: 2px 8px; }
  .content { padding: 20px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .filters > label { flex-basis: 40%; }
  .filters > label:first-child { flex-basis: 100%; }
  .filters .btn { flex: 1 1 100%; justify-content: center; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 32px 24px; gap: 20px; }
  .auth-art h1 { font-size: 1.9rem; }
  .entry { grid-template-columns: 1fr; }
  .entry-side { text-align: left; grid-row: auto; }
  .entry-side b { display: inline; font-size: 1rem; margin-right: 4px; }
  .strength-row { grid-template-columns: 110px 1fr 40px; }
  h1 { font-size: 1.5rem; }
  #graph { height: 420px; }
}
@media (max-width: 480px) {
  .briefing { grid-template-columns: 1fr 1fr; }
  .briefing strong { font-size: 1.3rem; }
  .news-item { grid-template-columns: 1fr; }
  .news-item img { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Prevent long titles from forcing horizontal scroll on narrow screens */
.grid-2 > *, .grid-3 > *, .copilot > * { min-width: 0; }
.entry-title, .entry-meta, .row-item h3, .news-item h3 { overflow-wrap: anywhere; }
