/* The research desk views and the EvolutionTicker (desk.js). Built on app.css tokens; the two
   colours it adds are the spec's (design-system §7.1): --earned for "Being upgraded" and
   --hold for figures about holding the same markets. */

:root { --earned: #c9b6ff; --hold: #e8a64a; --earned-soft: rgba(201, 182, 255, .12); }
@media (prefers-color-scheme: light) {
  :root { --earned: #6b4fd8; --hold: #9a5b00; --earned-soft: rgba(107, 79, 216, .09); }
}

.dk { display: flex; flex-direction: column; gap: 18px; }
.dk .section-head { padding-bottom: 6px; }
.dk h1:focus { outline: none; }  /* focus moves here on route change for screen readers; it is not a control */
.dk-section { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.dk-brief { color: var(--ink-2); max-width: 70ch; }
.dk-meta { font-size: 15px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.dk-stale { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--warn-soft); box-shadow: inset 3px 0 0 var(--warn); font-size: 15px; }

/* ---------------------------------------------------------------- chips and pills */
.dk-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.dk-chip {
  display: inline-flex; align-items: center; min-height: 28px; padding: 2px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--inset); color: var(--ink-2); font-size: 13px; font-weight: 500; white-space: nowrap;
}
button.dk-chip { cursor: pointer; font-family: inherit; }
button.dk-chip:hover { border-color: var(--ink-3); color: var(--ink); }
.dk-record, .dk-hash { font-family: var(--mono); font-variant-numeric: slashed-zero tabular-nums; }
.dk-record { color: var(--link); min-height: 28px; position: relative; }
.dk-record::after { content: ""; position: absolute; inset: -8px -2px; }  /* a 44px target around a small chip */
.dk-basis { color: var(--ink); }
.dk-tf { background: transparent; }
.dk-hash { font-size: 13px; color: var(--ink-2); word-break: break-all; }
.dk-pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 6px; font-size: 13px; font-weight: 600; background: var(--inset); color: var(--ink-2); }
.dk-pill[data-stage="paper trial"], .dk-pill[data-stage="out-of-sample read"] { background: var(--accent-soft); color: var(--link); }
.dk-pill[data-stage="eligible"], .dk-pill[data-stage="promoted"] { background: var(--pos-soft); color: var(--pos); }
.dk-upgrading { background: var(--earned-soft); color: var(--earned); width: fit-content; }
.dk-upgrading svg { width: 14px; height: 14px; animation: dk-turn 3s linear infinite; }
@keyframes dk-turn { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- EvolutionTicker */
.dk-ticker {
  display: flex; flex-direction: column; gap: 14px; padding: 18px 20px; border-radius: var(--radius);
  border: 1px solid var(--line); background: linear-gradient(180deg, var(--accent-soft), transparent 70%), var(--panel);
}
.dk-loop { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }
.dk-live { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 4px; box-shadow: 0 0 0 0 var(--accent); animation: dk-beat 2.4s ease-out infinite; }
@keyframes dk-beat { 0% { box-shadow: 0 0 0 0 rgba(151, 252, 228, .5); } 70%, 100% { box-shadow: 0 0 0 8px rgba(151, 252, 228, 0); } }
.dk-counters { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.dk-counters a { display: flex; flex-direction: column; gap: 2px; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--inset); color: var(--ink); text-decoration: none; height: 100%; }
.dk-counters a:hover { background: var(--hover); }
.dk-n { font-size: 26px; font-weight: 500; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.dk-counters span { font-size: 13px; color: var(--ink-2); line-height: 1.3; }
.dk-counters [data-k="promoted"] .dk-n { color: var(--pos); }
.dk-counters [data-k="upgrading"] .dk-n { color: var(--earned); }
.dk-pulse a { animation: dk-pulse 1.2s ease-out 2; }
@keyframes dk-pulse { 0% { box-shadow: 0 0 0 0 rgba(151, 252, 228, .55); } 100% { box-shadow: 0 0 0 12px rgba(151, 252, 228, 0); } }
.dk-trials { display: flex; flex-direction: column; gap: 10px; }
.dk-trial { display: flex; flex-direction: column; gap: 6px; }
.dk-trial-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; font-size: 14px; }
.dk-trial-head a { font-weight: 600; }
.dk-trial-head span { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.dk-bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.dk-bar i { display: block; height: 100%; width: max(var(--p), 4px); border-radius: 4px; background: linear-gradient(90deg, var(--link), var(--accent)); }
.dk-events { display: flex; align-items: center; min-height: 44px; border-top: 1px solid var(--divider); padding-top: 10px; margin: 0; }
.dk-event { display: flex; align-items: center; gap: 10px; width: 100%; font-size: 15px; }
.dk-event .dk-text { flex: 1; min-width: 0; }
.dk-event.dk-in { animation: dk-in .35s ease-out; }
@keyframes dk-in { from { opacity: 0; transform: translateY(4px); } }

/* ---------------------------------------------------------------- glyphs per lane */
.dk-glyph { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--link); }
.dk-glyph[data-lane="promotion"] { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dk-glyph[data-lane="upgrade"] { background: var(--earned); border-radius: 3px; }

/* ---------------------------------------------------------------- board */
.dk-board-wrap { overflow-x: auto; padding-bottom: 6px; border-radius: var(--radius-sm); }
.dk-board { display: grid; grid-template-columns: repeat(6, minmax(180px, 1fr)); gap: 10px; min-width: 1130px; }
.dk-col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.dk-col h3 { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.dk-col-n { font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 500; }
.dk-col[data-stage="promoted"] .dk-col-n { color: var(--pos); }
.dk-define { font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.dk-col ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.dk-none { font-size: 14px; color: var(--ink-2); }
.dk-card { background: var(--inset); border-radius: var(--radius-sm); padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.dk-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dk-card-head a { font-weight: 600; font-size: 14px; word-break: break-word; }
.dk-tpl, .dk-stop { font-size: 13px; color: var(--ink-2); }
.dk-card-foot { display: flex; justify-content: flex-end; }
.dk-col[data-stage="paper trial"] { border-color: var(--accent-edge); }

/* ---------------------------------------------------------------- being upgraded, retired, lane */
.dk-upgrades { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.dk-upgrade { display: flex; flex-direction: column; gap: 10px; padding: 18px; }
.dk-upgrade h3 { font-size: 17px; }
.dk-strength { font-size: 15px; font-variant-numeric: tabular-nums; }
.dk-strength b { font-weight: 600; }
.dk-lane { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; }
.dk-entry { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--divider); }
.dk-entry .dk-glyph { margin-top: 7px; }
.dk-entry > div { flex: 1; min-width: 0; }
.dk-when { font-size: 13px; color: var(--ink-2); }
.dk-entry[data-lane="promotion"] { padding: 16px; border: 1px solid var(--accent-edge); border-radius: var(--radius); background: var(--accent-soft); font-size: 17px; margin: 6px 0; }
.dk-entry[data-lane="upgrade"] p:first-child { color: var(--ink); }
.dk-section > .btn { align-self: flex-start; }

/* ---------------------------------------------------------------- challenger and daily */
.dk-one, .dk.narrow { max-width: 760px; }
.dk-reason { margin: 10px 0 0; padding-left: 14px; border-left: 3px solid var(--accent-edge); color: var(--ink); font-size: 17px; max-width: 65ch; }
.dk-verdict { padding: 14px 16px; border-radius: var(--radius-sm); font-size: 16px; }
.dk-verdict.dk-pass { background: var(--pos-soft); box-shadow: inset 3px 0 0 var(--pos); }
.dk-verdict.dk-retired { background: var(--inset); box-shadow: inset 3px 0 0 var(--ink-3); }
.dk-panel { display: flex; flex-direction: column; gap: 12px; }
.dk-gates { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.dk-gate { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--divider); }
.dk-gate:first-child { border-top: 0; }
.dk-gate-mark { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); margin-top: 1px; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.dk-gate[data-state="pass"] .dk-gate-mark { border-color: var(--pos); color: var(--pos); }
.dk-gate[data-state="pass"] .dk-gate-mark::before { content: "✓"; }
.dk-gate[data-state="fail"] .dk-gate-mark { border-color: var(--neg); color: var(--neg); }
.dk-gate[data-state="fail"] .dk-gate-mark::before { content: "×"; }
.dk-gate[data-state="wait"] .dk-gate-mark { border-style: dashed; border-color: var(--link); }
.dk-gate-text { font-weight: 500; }
.dk-gate-value { font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.dk-gate[data-state="pass"] .dk-gate-value b { color: var(--pos); }
.dk-gate[data-state="fail"] .dk-gate-value b { color: var(--neg); }
.dk-gate-rec { font-size: 13px; color: var(--ink-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.dk-figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 0; }
.dk-figs div { background: var(--inset); border-radius: var(--radius-sm); padding: 10px 12px; }
.dk-figs dt { font-size: 13px; color: var(--ink-2); }
.dk-figs dd { margin: 0; font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }
.dk-figs dd.dk-hold { color: var(--hold); }
.dk-paper { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.dk-ring { width: 96px; height: 96px; flex: none; }
.dk-ring circle { fill: none; stroke-width: 8; }
.dk-ring-bg { stroke: var(--line); }
.dk-ring-fg { stroke: var(--accent); stroke-linecap: round; }
.dk-ring text { fill: var(--ink); font: 600 16px var(--sans); font-variant-numeric: tabular-nums; }
.dk-kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 15px; }
.dk-kv dt { color: var(--ink-2); }
.dk-kv dd { margin: 0; font-variant-numeric: tabular-nums; min-width: 0; }
.dk-decl { grid-template-columns: 1fr; gap: 2px; }
.dk-decl dt { text-transform: capitalize; margin-top: 8px; }
.dk-chain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.dk-chain li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; font-size: 15px; }
.dk-report { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
details.dk-method > summary { cursor: pointer; color: var(--link); min-height: 44px; display: flex; align-items: center; }
details.dk-method[open] > summary { margin-bottom: 6px; }
.dk-json { font: 13px/1.5 var(--mono); background: var(--inset); padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; max-height: 50vh; }

/* ---------------------------------------------------------------- sheet */
.dk-sheet { border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--ink); padding: 0; width: min(640px, calc(100vw - 32px)); max-height: min(80vh, 760px); box-shadow: var(--shadow); }
.dk-sheet::backdrop { background: rgba(0, 0, 0, .55); }
.dk-sheet-in { padding: 20px 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.dk-sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dk-sheet-head h2 { font-size: 20px; }

@media (max-width: 900px) {
  .dk-counters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dk-counters [data-k="trials"] { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .dk-ticker { padding: 14px; }
  .dk-board { grid-template-columns: 1fr; min-width: 0; }
  .dk-board-wrap { overflow: visible; }
  .dk-col:has(.dk-none) { padding: 10px 14px; }
  .dk-col:has(.dk-none) .dk-define { display: none; }
  .dk-col:has(.dk-none) .dk-none { display: none; }
  .dk-chain li { grid-template-columns: auto 1fr; }
  .dk-chain .dk-hash { grid-column: 2; }
  .dk-sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
}
@media (prefers-reduced-motion: reduce) {
  .dk-upgrading svg, .dk-live, .dk-pulse a, .dk-event.dk-in { animation: none; }
}
