/* Research Desk. One accent (deep teal), one radius (6px), cool neutrals, light and dark.
   The serif is reserved for the paper itself: it is a manuscript, so it reads like one. */

:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #1a2028;
  --muted: #556170;
  --line: #dde2e8;
  --line-strong: #c4ccd6;
  --accent: #0e6a62;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ef;
  --ok: #1d6b43;
  --ok-soft: #e5f2ea;
  --warn: #8a5300;
  --warn-soft: #fbf1df;
  --danger: #a8261d;
  --danger-soft: #fbe9e7;
  --radius: 6px;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --rail: 300px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1216;
    --surface: #151a20;
    --ink: #e4e8ed;
    --muted: #98a3af;
    --line: #252d36;
    --line-strong: #354050;
    --accent: #5cc4b8;
    --accent-ink: #05201d;
    --accent-soft: #12302d;
    --ok: #67c48f;
    --ok-soft: #132a1d;
    --warn: #e0a955;
    --warn-soft: #2c2213;
    --danger: #f0857c;
    --danger-soft: #2f1917;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--ui);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip {
  position: absolute; left: -999px; top: 8px; z-index: 10;
  background: var(--surface); padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--line-strong);
}
.skip:focus { left: 8px; }

/* Buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px; white-space: nowrap;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: transparent; cursor: pointer; font-weight: 550; text-decoration: none; color: inherit;
  transition: background-color 120ms, border-color 120ms, transform 80ms;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.quiet { border-color: transparent; color: var(--muted); padding: 0 8px; min-height: 32px; }
.btn.quiet:hover { color: var(--ink); background: transparent; border-color: var(--line); }

label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { color: var(--muted); font-size: 14px; }
.field { display: grid; gap: 6px; }
.field .hint { margin: 0; }
textarea, input[type="password"], input[type="text"] {
  width: 100%; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
textarea { resize: vertical; line-height: 1.5; }
textarea:focus, input:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
.field-error { color: var(--danger); font-size: 14px; }
.counter { color: var(--muted); font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; }

/* Shell */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100dvh; }
.rail {
  position: sticky; top: 0; align-self: start; height: 100dvh;
  display: flex; flex-direction: column; gap: 16px; padding: 20px 16px;
  border-right: 1px solid var(--line); background: var(--surface);
}
.brand { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; padding: 0 4px; }
.brand small { display: block; font-size: 13px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.papers { min-height: 0; display: flex; flex-direction: column; flex: 1; }
.papers > summary { display: none; }
.papers-list { overflow-y: auto; margin: 0 -8px; padding: 0 8px; flex: 1; }
.papers-list li + li { margin-top: 2px; }
.paper-link {
  display: block; padding: 10px 10px 10px 12px; text-decoration: none; color: inherit;
  border-left: 3px solid transparent; border-radius: 0 var(--radius) var(--radius) 0;
}
.paper-link:hover { background: var(--bg); }
.paper-link[aria-current="page"] { background: var(--accent-soft); border-left-color: var(--accent); }
.paper-title {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-weight: 550; line-height: 1.35;
}
.paper-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 3px; font-size: 13px; color: var(--muted); }
.st-waiting, .st-review { color: var(--warn); font-weight: 600; }
.st-failed { color: var(--danger); font-weight: 600; }
.st-done { color: var(--ok); font-weight: 600; }
.st-working { color: var(--accent); font-weight: 600; }
.rail-foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; justify-content: space-between; align-items: center; }

main { padding: 40px clamp(20px, 5vw, 64px) 96px; min-width: 0; }
main:focus { outline: none; }
.col { max-width: 820px; margin: 0 auto; display: grid; gap: 32px; }
.page-title { font-size: 26px; }
.lede { color: var(--muted); max-width: 62ch; margin-top: 8px; }

/* New paper */
.new-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 48px; align-items: start; }
.new-form { display: grid; gap: 16px; }
.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.how h2 { font-size: 15px; margin-bottom: 12px; }
.how ol { display: grid; gap: 14px; border-left: 2px solid var(--line); padding-left: 16px; }
.how li strong { display: block; }
.how li span { color: var(--muted); font-size: 14px; }

/* Run header */
.run-head { display: grid; gap: 10px; }
.run-title { font-size: 26px; overflow-wrap: anywhere; }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; color: var(--muted); }
.status-line strong { color: var(--ink); }
.run-actions { margin-left: auto; display: flex; gap: 8px; }
details.assignment { color: var(--muted); }
details.assignment summary { cursor: pointer; width: max-content; }
details.assignment p { margin-top: 8px; white-space: pre-wrap; color: var(--ink); max-width: 70ch; }

/* Stages */
.stages { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.stages li { border-top: 3px solid var(--line); padding-top: 8px; position: relative; }
.stages .name { font-weight: 600; font-size: 14px; }
.stages .cap { display: block; font-size: 12.5px; color: var(--muted); min-height: 1.3em; }
.stages li[data-state="done"] { border-top-color: var(--accent); }
.stages li[data-state="active"], .stages li[data-state="waiting"] { border-top-color: var(--accent); }
.stages li[data-state="waiting"] .cap { color: var(--warn); font-weight: 600; }
.stages li[data-state="failed"] { border-top-color: var(--danger); }
.stages li[data-state="failed"] .cap { color: var(--danger); font-weight: 600; }
.stages li[data-state="todo"] .name { color: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  .stages li[data-state="active"]::before {
    content: ""; position: absolute; left: 0; right: 0; top: -3px; height: 3px;
    background: linear-gradient(90deg, transparent, var(--surface), transparent);
    background-size: 40% 100%; background-repeat: no-repeat;
    animation: sweep 1.6s ease-in-out infinite;
  }
  @keyframes sweep { from { background-position: -40% 0; } to { background-position: 140% 0; } }
}

/* Panels */
.panel { display: grid; gap: 16px; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h2 { font-size: 18px; }
.query-list { display: grid; gap: 4px; color: var(--muted); font-size: 14px; }
.query-list li { padding-left: 14px; position: relative; }
.query-list li::before { content: "-"; position: absolute; left: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.section-h { font-size: 15px; margin-bottom: 10px; }

.activity { display: grid; gap: 0; border-top: 1px solid var(--line); }
.activity li { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.activity time { color: var(--muted); font-variant-numeric: tabular-nums; }
.activity b { font-weight: 600; margin-right: 6px; }
.activity .empty { grid-template-columns: 1fr; color: var(--muted); }

/* Verdict */
.verdict { display: grid; gap: 10px; padding: 20px 24px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); }
.verdict h2 { font-size: 18px; }
.verdict.ok { border-color: var(--ok); background: var(--ok-soft); }
.verdict.review { border-color: var(--warn); background: var(--warn-soft); }
.verdict.fail { border-color: var(--danger); background: var(--danger-soft); }
.verdict ul { display: grid; gap: 6px; padding-left: 18px; list-style: disc; }
.verdict .caveat { font-size: 14px; color: var(--muted); }
.verdict.ok .caveat, .verdict.review .caveat, .verdict.fail .caveat { color: var(--ink); opacity: 0.85; }
pre.err { margin: 0; padding: 12px; overflow: auto; max-height: 240px; font: 12.5px/1.5 var(--mono); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; }
details.tech summary { cursor: pointer; width: max-content; font-size: 14px; }
details.tech pre { margin-top: 8px; }

.facts { display: flex; flex-wrap: wrap; gap: 20px 40px; margin: 0; padding: 4px 0; }
.facts div { min-width: 96px; }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 0; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.toolbar .grow { flex: 1; }

/* The manuscript */
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(24px, 6vw, 64px); }
.paper { font-family: var(--serif); font-size: 1.125rem; line-height: 1.72; max-width: 68ch; margin: 0 auto; hyphens: manual; }
.paper h1 { font-size: 1.9rem; line-height: 1.2; letter-spacing: -0.015em; margin-bottom: 0.3em; font-weight: 600; }
.paper .byline { font-family: var(--ui); font-size: 14px; color: var(--muted); margin-bottom: 2.2em; }
.paper h2 { font-size: 1.3rem; margin: 2.1em 0 0.5em; font-weight: 600; letter-spacing: -0.01em; }
.paper p { margin: 0 0 1em; }
.paper .ref { font-size: 1rem; line-height: 1.6; padding-left: 2em; text-indent: -2em; overflow-wrap: anywhere; hyphens: none; margin-bottom: 0.8em; }
.paper a { overflow-wrap: anywhere; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form { width: min(420px, 100%); display: grid; gap: 16px; }
.login h1 { font-size: 26px; }

/* Skeletons */
.skel { border-radius: var(--radius); background: var(--line); height: 14px; }
.skel + .skel { margin-top: 10px; }
.skel.w80 { width: 80%; } .skel.w55 { width: 55%; } .skel.w60 { width: 60%; } .skel.w100 { width: 100%; }
.skel.tall { height: 26px; } .skel.block { height: 60px; }
@media (prefers-reduced-motion: no-preference) {
  .skel { animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: 0.5; } }
}

/* Empty state */
.empty-state { padding: 16px 4px; color: var(--muted); font-size: 14px; }
.empty-state strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* Toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 20; max-width: min(380px, calc(100vw - 32px)); }
.toast { padding: 12px 14px; background: var(--surface); border: 1px solid var(--line-strong); border-left: 3px solid var(--accent); border-radius: var(--radius); box-shadow: 0 6px 24px rgb(16 24 32 / 0.14); }
.toast.error { border-left-color: var(--danger); }

.noscript { padding: 24px; }

/* Tablet and phone */
@media (max-width: 1000px) {
  .new-grid { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .stages { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .stages li { border-top: 0; border-left: 3px solid var(--line); padding: 4px 0 4px 12px; margin-bottom: 6px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
  .stages li[data-state="done"], .stages li[data-state="active"], .stages li[data-state="waiting"] { border-left-color: var(--accent); }
  .stages li[data-state="failed"] { border-left-color: var(--danger); }
  .stages li[data-state="active"]::before { display: none; }
  .stages .cap { min-height: 0; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand small { display: none; }
  .papers { order: 5; flex-basis: 100%; }
  .papers > summary { display: block; cursor: pointer; font-weight: 600; padding: 6px 0; }
  .papers-list { max-height: 40dvh; margin-top: 6px; }
  .rail-foot { border-top: 0; padding-top: 0; margin-left: auto; }
  main { padding: 24px 16px 72px; }
  .panel { padding: 18px; }
  .run-actions { margin-left: 0; width: 100%; }
}

/* Print: the paper only */
@media print {
  body { background: #fff; color: #000; }
  .rail, .run-head, .stages, .no-print, .toolbar, #toasts, .skip { display: none !important; }
  .shell { display: block; }
  main { padding: 0; }
  .sheet { border: 0; padding: 0; background: #fff; }
  .paper { font-size: 12pt; max-width: none; color: #000; }
  .paper .byline { display: none; }
  .paper a { color: #000; text-decoration: none; }
}
