/* odin v2 — Bloomberg-leaning dense static SPA.
   Cool greys + restrained accent blue. Red for negative Δ and <70 marks.
   No green-on-positive in dense tables. Hand-written, ~250 lines. */

:root {
  --bg: #ffffff;
  --panel: #f5f6f8;
  --panel-2: #e9ecf1;
  --line: #dde1e8;
  --line-strong: #b8bfcc;
  --ink: #1a1d23;
  --ink-2: #404757;
  --muted: #646c7a;
  --accent: #1e5cd6;
  --accent-hover: #144198;
  --accent-soft: #e8efff;
  --bad: #b3261e;
  --amber-red: #c1411e;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { font-size: 100%; }
html, body { background: var(--bg); color: var(--ink); margin: 0; }
body {
  font: 12.5px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
.muted { color: var(--muted); }
.right { float: right; }
.mono { font-family: var(--mono); }

/* Mobile-only inlines for collapsed table cells. Hide on desktop where
   dedicated columns already carry the same info. */
.sub-mobile { display: none; }
.na-inline { display: none; }

/* Global focus ring — applies on keyboard / assistive focus (WCAG 2.4.7).
   Outline-offset of 1 keeps the ring outside content edges for legibility. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* Mouse focus doesn't get the ring (browsers honour :focus-visible heuristic).
   Tap-row anchors handle their own hint via :active. */
:focus:not(:focus-visible) { outline: none; }

/* topbar — sticky, tight */
#topbar {
  position: sticky; top: 0; z-index: 50;
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 14px;
  padding: 6px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.brand {
  font-weight: 700; font-size: 14px; color: var(--ink);
  letter-spacing: -0.2px;
}
.brand:hover { color: var(--accent); text-decoration: none; }

/* search input + monospace / chip pinned right */
.search-shell { position: relative; max-width: 480px; width: 40vw; }
#search-input {
  width: 100%;
  background: #fff; border: 1px solid var(--line-strong);
  color: var(--ink); border-radius: 3px;
  padding: 4px 26px 4px 8px; font: 12px inherit;
}
#search-input:focus {
  outline: 1px solid var(--accent); outline-offset: -1px;
  border-color: var(--accent);
}
.search-shortcut {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font: 10.5px var(--mono); color: var(--muted);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 2px; padding: 0 4px; pointer-events: none;
  line-height: 14px;
}
#search-input:focus ~ .search-shortcut { display: none; }
#search-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 2px;
  max-height: 480px; overflow-y: auto;
  background: #fff; border: 1px solid var(--line-strong);
  border-radius: 3px; box-shadow: 0 6px 18px rgba(15,20,35,0.12);
  z-index: 60;
}
.s-hit {
  display: grid; grid-template-columns: 60px 1fr 60px;
  gap: 8px; padding: 4px 10px;
  border-bottom: 1px solid var(--line); cursor: pointer; align-items: center;
}
.s-hit:last-child { border-bottom: 0; }
.s-hit:hover, .s-hit.active { background: var(--accent-soft); }
.s-hit .kind { font: 11px var(--mono); color: var(--muted); text-transform: lowercase; }
.s-hit .name { color: var(--ink); font-weight: 500; line-height: 1.3; }
.s-hit .name .alias { font: 11px var(--mono); color: var(--muted); display: block; }
.s-hit .country-tag { font: 11px var(--mono); color: var(--muted); text-align: right; }

/* nav */
.topnav a {
  margin-left: 14px; color: var(--ink-2); font-size: 12px; font-weight: 400;
}
.topnav a:hover { color: var(--accent); text-decoration: none; }
.topnav a.active { color: var(--ink); font-weight: 700; }

/* main view + footer */
#view { padding: 10px 14px 32px; min-height: calc(100vh - 60px); }
#bottombar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 4px 14px;
  /* iOS notched home indicator. Inner padding stays 4px; outer adds
     env() so the visual line sits above the home-bar arc. */
  padding-bottom: calc(4px + env(safe-area-inset-bottom));
  font-size: 11px;
  background: var(--bg); border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px;
}
#bottombar .right { float: none; }
#bottombar .footer-about {
  /* Footer about hides on desktop — the nav strip already has it. */
  display: none;
  color: var(--accent); font: 11px var(--mono);
}
#build-stamp { font-family: var(--mono); cursor: help; }

/* entity / page header */
.entity-hdr { padding: 6px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.entity-hdr .kind-tag {
  display: inline-block; font: 10px var(--mono); color: var(--ink-2);
  text-transform: uppercase; padding: 1px 5px;
  background: var(--panel-2); border-radius: 2px;
  margin-right: 8px; letter-spacing: 0.4px;
}
.entity-hdr h1 {
  display: inline; font-size: 18px; font-weight: 700; margin: 0;
  letter-spacing: -0.2px; color: var(--ink);
}
.entity-hdr .subtitle { display: block; color: var(--muted); margin-top: 4px; font: 11.5px var(--mono); }
.entity-hdr dl.kv {
  margin: 8px 0 0; display: grid;
  grid-template-columns: max-content 1fr; gap: 2px 12px;
  font-size: 12px;
}
.entity-hdr dl.kv dt { color: var(--muted); text-transform: lowercase; }
.entity-hdr dl.kv dd { margin: 0; color: var(--ink); }

/* sections */
.section { margin: 14px 0; }
.section > h2 {
  font-size: 11px; font-weight: 600; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 0 0 4px; padding-bottom: 3px;
  border-bottom: 1px solid var(--line);
}
.section h2 .muted { font-weight: 400; text-transform: none; letter-spacing: 0; font-size: 11px; }

/* tables — dense, sticky headers */
table.data { width: 100%; border-collapse: collapse; font: 12px/1.3 inherit; }
table.data thead th {
  text-align: left; font-weight: 600; color: var(--ink-2);
  padding: 4px 8px; border-bottom: 1px solid var(--line-strong);
  white-space: nowrap; cursor: pointer; user-select: none;
  background: var(--panel); font-size: 10.5px;
  text-transform: lowercase; letter-spacing: 0.3px;
  position: sticky; top: 32px; z-index: 10;
}
table.data thead th:hover { color: var(--accent); background: var(--panel-2); }
table.data thead th.sorted { color: var(--accent); }
table.data thead th.sorted::after { content: ' ↓'; }
table.data thead th.sorted.asc::after { content: ' ↑'; }
table.data tbody tr { border-bottom: 1px solid var(--line); }
table.data tbody tr:hover { background: var(--accent-soft); }
table.data tbody tr:nth-child(even) { background: rgba(0,0,0,0.012); }
table.data tbody tr:nth-child(even):hover { background: var(--accent-soft); }
table.data td {
  padding: 3px 8px; vertical-align: middle; white-space: nowrap;
  max-width: 360px; overflow: hidden; text-overflow: ellipsis;
}
table.data td.num, table.data th.num {
  text-align: right; font-family: var(--mono); font-size: 11.5px;
}
table.data td .mono, table.data td.mono { font-family: var(--mono); font-size: 11.5px; }
table.data td .sub { display: block; font: 10.5px var(--mono); color: var(--muted); }

/* numeric coloring — red only. No green on positive Δ. */
.delta-neg { color: var(--bad); }
.delta-pos { color: var(--ink-2); }
.mark-low { color: var(--amber-red); font-weight: 600; }

/* show-more pagination button */
.show-more {
  display: block; margin: 8px auto;
  padding: 4px 12px; font: 11.5px var(--mono);
  border: 1px solid var(--line-strong); background: var(--panel);
  color: var(--ink-2); border-radius: 3px; cursor: pointer;
}
.show-more:hover { background: var(--panel-2); border-color: var(--accent); color: var(--accent); }

/* NA badge for non-accrual */
.na-badge {
  display: inline-block; font: 10px var(--mono); font-weight: 700;
  padding: 0 5px; border-radius: 2px;
  background: rgba(179,38,30,0.10); color: var(--bad);
  letter-spacing: 0.4px;
}

/* prose / about */
.about { max-width: 720px; margin: 14px auto 60px; font-size: 13.5px; line-height: 1.55; color: var(--ink); }
.about h1 { font-size: 18px; font-weight: 700; margin: 0 0 12px; }
.about p { font-size: 13px; margin: 8px 0; }
.about code { font: 12px var(--mono); background: var(--panel); padding: 1px 4px; border-radius: 2px; }
.about a { color: var(--accent); }

/* sparkline (used by borrower dossier) */
.sparkline { display: inline-block; vertical-align: middle; }
.spark-row {
  display: grid; grid-template-columns: 220px 240px 1fr;
  gap: 10px; align-items: center; padding: 2px 0; font-size: 11.5px;
}
.spark-row .label { color: var(--ink-2); font: 11.5px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark-row .meta { color: var(--muted); font: 10.5px var(--mono); }
.spark-row .svg { line-height: 0; }
.spark-row .svg svg a { cursor: pointer; }

/* dossier chips: country, sector, sponsor, manager, vintage etc. */
.entity-hdr .chips { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.entity-hdr .chip {
  display: inline-block; font: 11px var(--mono); color: var(--ink-2);
  background: var(--panel); border: 1px solid var(--line);
  padding: 1px 7px; border-radius: 2px;
}
.entity-hdr .chip a { color: var(--accent); }
.entity-hdr .aliases { margin-top: 4px; font: 11.5px var(--mono); color: var(--muted); }

/* dossier sources list */
.sources-list { list-style: none; padding: 0; margin: 4px 0 0; font-size: 12px; }
.sources-list li { padding: 2px 0; border-bottom: 1px dotted var(--line); }
.sources-list li:last-child { border-bottom: 0; }

/* empty / loading / error */
.empty { padding: 16px; text-align: center; color: var(--muted); font-size: 12px; }
.loading { padding: 16px; text-align: center; color: var(--muted); font: 12px var(--mono); }
.error { padding: 12px; color: var(--bad); font: 12px var(--mono); }
.error small { display: block; color: var(--muted); margin-top: 4px; white-space: pre-wrap; }

/* ─────────────────────────────────────────────────────────────────
   Mobile (max-width: 720px)
   — single breakpoint per MOBILE.md §1
   — chrome stays one row; nav inlines (no scroll-strip);
     search input stays visible; sponsors + about move out of nav
   ───────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  /* Columns route modules flag with `mobileHide: true` collapse out */
  table.data .mobile-hide { display: none; }

  /* Constrain table width to viewport and let cells wrap so all visible
     columns fit. Desktop nowrap + 360px cell max-width would otherwise let
     the borrower cell push siblings off-screen at 390px viewport.
     Allow word-break only on long unbreakable runs (slugs, URLs). */
  table.data { table-layout: fixed; width: 100%; }
  table.data td { white-space: normal; max-width: none; overflow-wrap: break-word; }

  /* Inlines visible on mobile (NA badge + as-of subtext fold into mark cell) */
  .sub-mobile { display: block; font: 0.6875rem var(--mono); color: var(--muted); }
  .na-inline { display: inline-block; }

  /* /borrowers mobile: 2 visible — borrower (with sponsor sub) / mark
     (with quarter sub + inline NA). 67/33 split lets long borrower
     names breathe while right-aligned mark stays anchored. */
  table.data th[data-col="borrower_display"],
  table.data td[data-col="borrower_display"] { width: 67%; }
  table.data th[data-col="min_mark_pct"],
  table.data td[data-col="min_mark_pct"] { width: 33%; }

  /* /movers: 4 visible — borrower (with q sub) / Δ / mark / date */
  table.data th[data-col="delta"],
  table.data td[data-col="delta"] { width: 14%; }
  table.data th[data-col="mark"],
  table.data td[data-col="mark"] { width: 22%; }
  table.data th[data-col="observed_at"],
  table.data td[data-col="observed_at"] { width: 22%; }

  /* /funds: 3 visible — fund (with vintage sub) / manager / strategy */
  table.data th[data-col="fund_name"],
  table.data td[data-col="fund_name"] { width: 45%; }
  table.data th[data-col="manager_display"],
  table.data td[data-col="manager_display"] { width: 30%; }
  table.data th[data-col="strategy"],
  table.data td[data-col="strategy"] { width: 25%; }

  /* /b/<slug> positions: 4 visible — lender (with facility sub) / mark / Δq / NA */
  table.data th[data-col="lender"],
  table.data td[data-col="lender"] { width: 42%; }
  table.data th[data-col="latest_mark_pct"],
  table.data td[data-col="latest_mark_pct"] { width: 16%; }
  table.data th[data-col="delta_qtr"],
  table.data td[data-col="delta_qtr"] { width: 14%; }
  table.data th[data-col="non_accrual"],
  table.data td[data-col="non_accrual"] { width: 28%; }

  /* Body / table density — rem-based so Android system font scale works */
  body { font-size: 0.875rem; }                   /* 14px */
  table.data { font-size: 0.8125rem; }            /* 13px */
  table.data td, table.data th { padding: 8px 6px; }
  table.data thead th { font-size: 0.6875rem; padding: 12px 6px; }  /* 11px header */
  table.data td.num, table.data th.num { font-size: 0.78125rem; }   /* 12.5px mono */
  table.data td .sub { font-size: 0.6875rem; }

  /* Suppress iOS Safari focus-zoom on the search input (16px floor) */
  #search-input { font-size: 16px; padding: 8px 28px 8px 10px; }
  .search-shortcut { display: none; }             /* no keyboard */

  /* Chrome: brand + search + nav in one wrapping row. Search drops
     below brand+nav by virtue of flex-wrap on narrow viewports. */
  #topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand nav" "search search";
    row-gap: 4px;
    padding: 6px 10px;
  }
  #topbar .brand { grid-area: brand; }
  #topbar .topnav { grid-area: nav; }
  #topbar .search-shell { grid-area: search; max-width: none; width: 100%; }

  /* Drop sponsors + about from the mobile nav strip */
  .topnav { display: flex; gap: 4px; }
  .topnav a { margin-left: 0; padding: 8px 10px; min-height: 44px; display: inline-flex; align-items: center; font-size: 0.8125rem; }
  .topnav a[data-nav="sponsors"],
  .topnav a[data-nav="about"] { display: none; }

  /* Footer simplifies: brand prose hides, about shows, build stamp stays */
  #bottombar .brand-tag { display: none; }
  #bottombar .footer-about { display: inline; }
  #bottombar { font-size: 0.6875rem; justify-content: space-between; }

  /* Entity headers compress */
  .entity-hdr h1 { font-size: 1rem; }             /* 16px */
  .entity-hdr .subtitle { font-size: 0.6875rem; }
  .entity-hdr dl.kv { font-size: 0.8125rem; }
  .entity-hdr .chips { display: none; }
  .entity-hdr .aliases { display: none; }

  /* About body bumps slightly */
  .about { font-size: 0.875rem; padding: 0 4px; max-width: none; }
  .about h1 { font-size: 1rem; }
  .about p { font-size: 0.875rem; }

  /* Sticky thead offset accounts for two-row mobile chrome */
  table.data thead th { top: 96px; }

  /* Keyboard / VO focus moving into rows lands under the sticky header
     otherwise — push the scroll target down (WCAG 2.4.11) */
  table.data tbody tr,
  table.data tbody a { scroll-margin-top: 140px; }

  /* Sparkline row collapses to vertical stack */
  .spark-row { grid-template-columns: 1fr; gap: 2px; padding: 6px 0; }
  .spark-row .svg { overflow-x: auto; }
  .spark-row .svg svg { width: 100%; min-width: 320px; height: 36px; }

  /* Events table stacks per-row: date + kind on row 1, description on row 2.
     Source column already hidden via mobileHide. Keeps the events surface
     present on mobile (analyst review #5 — events answers "why" while
     positions answers "what"). */
  .section[data-section="events"] table.data thead { display: none; }
  .section[data-section="events"] table.data tbody tr {
    display: grid;
    grid-template-columns: max-content 1fr;
    grid-template-areas: "date kind" "desc desc";
    gap: 0 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
  }
  .section[data-section="events"] table.data tbody td { padding: 0; border: 0; white-space: normal; max-width: none; }
  .section[data-section="events"] table.data tbody td[data-col="observed_at"] { grid-area: date; font: 0.6875rem var(--mono); color: var(--muted); }
  .section[data-section="events"] table.data tbody td[data-col="kind"] { grid-area: kind; font-weight: 600; color: var(--ink-2); }
  .section[data-section="events"] table.data tbody td[data-col="description"] { grid-area: desc; font-size: 0.8125rem; padding-top: 2px; }

  /* Sources section hidden — sidecar links live on sparkline ticks */
  .section[data-section="sources"] { display: none; }
}

/* Sparkline ticks larger on touch viewports — UX #7 + a11y #4. Discoverable
   target without requiring hover affordance. */
@media (hover: none) {
  .sparkline circle { r: 3.5; }
}

/* ── Touch device: kill sticky-tap hover, add active feedback ── */
@media (hover: none) {
  table.data tbody tr:hover { background: inherit; }
  table.data tbody tr:nth-child(even):hover { background: rgba(0,0,0,0.012); }
  table.data tbody tr:active { background: var(--accent-soft); }
  .topnav a:hover { color: var(--ink-2); }
}

/* ── Honour OS reduced-motion preference (no animations currently;
      future-proofing per WCAG 2.3.3 — AAA but cheap) ── */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
