/* ── Compute Credit Design System ──────────────────────────────────────────── */

:root {
  --bg: #0a0e14;
  --surface: #12161e;
  --surface-raised: #1a1f2a;
  --border: #252b37;
  --border-light: #1e2430;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --green-dim: rgba(34,197,94,0.12);
  --red: #ef4444;
  --red-dim: rgba(239,68,68,0.1);
  --yellow: #eab308;
  --purple: #a78bfa;
  --orange: #f97316;
  --header-bg: #0d1117;
  --row-hover: rgba(59,130,246,0.06);
  --frozen-bg: #0f1319;
  --universe-bg: #141a24;
}

* { margin: 0; padding: 0; box-sizing: border-box; scrollbar-width: none; }
*::-webkit-scrollbar { display: none; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Top navigation ─────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 52px;
  flex-shrink: 0;
  gap: 32px;
}
.navbar .brand {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.navbar .brand .logo {
  width: 22px;
  height: 22px;
  background: url('/static/shared/logo.png') center/contain no-repeat;
  border-radius: 5px;
}
.navbar .nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 100%;
}
.navbar .nav-link {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
  transition: all 0.15s;
}
.navbar .nav-link:hover {
  color: var(--text);
  background: var(--surface-raised);
}
.navbar .nav-link.active {
  color: var(--text);
  background: var(--surface-raised);
}
.navbar .nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
}
.navbar .nav-right .val { color: var(--accent); }

/* ── Page header ────────────────────────────────────────────────────────────── */
.page-header {
  padding: 20px 24px 16px;
  flex-shrink: 0;
}
.page-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.4px;
}
.page-header .subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.page-header .breadcrumb {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.page-header .breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
}
.page-header .breadcrumb a:hover { color: var(--accent); }
.page-header .breadcrumb .sep { margin: 0 6px; }

/* ── Filter bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px 16px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-group label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.filter-bar select, .filter-bar input[type="text"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  border-radius: 6px;
  transition: border-color 0.15s;
}
.filter-bar select:focus, .filter-bar input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}
.filter-bar .search-input {
  min-width: 220px;
  padding-left: 12px;
}
.filter-bar .filter-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ── Data tables ────────────────────────────────────────────────────────────── */
.data-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 0 24px;
}
.data-table-wrap table {
  width: 100%;
  border-collapse: collapse;
}
.data-table-wrap th {
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.data-table-wrap th:hover { color: var(--text-secondary); }
.data-table-wrap th.sorted { color: var(--accent); }
.data-table-wrap th.num { text-align: right; }
.data-table-wrap th .sort-arrow {
  font-size: 9px;
  margin-left: 3px;
  opacity: 0.7;
}

.data-table-wrap td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  white-space: nowrap;
}
.data-table-wrap td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table-wrap tr:hover td { background: var(--row-hover); }

/* Clickable cells */
.cell-link {
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
.cell-link:hover { color: var(--accent); }
.cell-link.primary {
  font-weight: 600;
}

/* ── Badges ─────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge.bond { background: rgba(59,130,246,0.12); color: var(--accent); }
.badge.convertible { background: rgba(167,139,250,0.12); color: var(--purple); }
.badge.credit-facility, .badge.credit_facility { background: rgba(34,197,94,0.12); color: var(--green); }
.badge.abs-tranche, .badge.abs_tranche { background: rgba(249,115,22,0.12); color: var(--orange); }
.badge.senior-secured, .badge.senior_secured { background: rgba(249,115,22,0.12); color: var(--orange); }
.badge.senior-unsecured, .badge.senior_unsecured { background: rgba(59,130,246,0.12); color: var(--accent); }

/* Lender pills */
.pill {
  display: inline-block;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  margin-right: 4px;
  margin-bottom: 2px;
  cursor: pointer;
}
a.pill:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Mono values ────────────────────────────────────────────────────────────── */
.mono {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
  font-size: 12px;
}
.val-green { color: var(--green); }
.val-yellow { color: var(--yellow); }
.val-dim { color: var(--text-secondary); }
.val-muted { color: var(--text-muted); }

/* ── Cards (detail pages) ───────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}
.card h2 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}
.card.full-width { grid-column: 1 / -1; }

.kv-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
}
.kv-grid dt {
  font-size: 12px;
  color: var(--text-muted);
}
.kv-grid dd {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

/* ── Loading / Error ────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  font-size: 13px;
  flex-direction: column;
  gap: 16px;
}
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  color: var(--red);
  background: var(--red-dim);
  border: 1px solid rgba(239,68,68,0.2);
  padding: 16px 20px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

/* ── Status bar ─────────────────────────────────────────────────────────────── */
.statusbar {
  height: 28px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  font-size: 11px;
  color: var(--text-muted);
  gap: 20px;
  flex-shrink: 0;
}
.statusbar .sep { color: var(--border); }

/* ── Spreadsheet mode (analytics pages) ─────────────────────────────────────── */
.sheet-wrap {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
}

.frozen-left {
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 2px solid var(--accent);
  z-index: 10;
  background: var(--frozen-bg);
}
.scroll-area { flex: 1; overflow: auto; }

/* Sheet tables use monospace */
.sheet-wrap table {
  border-collapse: collapse;
  white-space: nowrap;
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
  font-size: 11px;
}
.sheet-wrap th, .sheet-wrap td {
  padding: 5px 10px;
  border: 1px solid var(--border-light);
  text-align: right;
  height: 28px;
  vertical-align: middle;
}
.sheet-wrap thead th {
  background: var(--header-bg);
  position: sticky;
  top: 0;
  z-index: 5;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.sheet-wrap thead th.month-header {
  color: var(--text);
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
}
.sheet-wrap thead th.sub-header {
  top: 28px;
  font-size: 9px;
  color: var(--text-muted);
}
.frozen-left th, .frozen-left td { text-align: left; }
.frozen-left td.num { text-align: right; }

/* Sheet row types */
tr.instrument:hover td { background: var(--row-hover); }
tr.section-header td {
  background: var(--surface);
  font-weight: 700;
  color: var(--accent);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-top: 2px solid var(--border);
}
tr.universe-row td { background: var(--universe-bg); font-weight: 700; }
tr.universe-row.blended td { color: var(--green); }
tr.universe-row.median td { color: var(--purple); }
tr.universe-row.coupon td { color: var(--orange); }
tr.spacer td { height: 6px; padding: 0; border: none; background: var(--bg); }

/* Sheet cell styling */
td.issuer { font-weight: 600; color: var(--text); max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
td.cusip { color: var(--text-secondary); font-size: 10px; }
td.coupon { color: var(--yellow); font-weight: 600; }
td.outstanding { color: var(--text-secondary); }
td.maturity { color: var(--text-secondary); font-size: 10px; }
td.yield-val { color: var(--green); }
td.yield-val.neg { color: var(--red); }
td.price-val { color: var(--text); }
td.volume-val { color: var(--text-secondary); font-size: 10px; }
td.empty { color: var(--text-muted); }

/* Info icon tooltip */
.info-icon {
  display: inline-block;
  width: 13px; height: 13px; line-height: 13px;
  border-radius: 50%;
  border: 1px solid var(--text-muted);
  color: var(--text-muted);
  font-size: 9px;
  text-align: center;
  cursor: help;
  margin-left: 4px;
  vertical-align: middle;
  position: relative;
}
.info-icon:hover { border-color: var(--text-secondary); color: var(--text-secondary); }
.info-icon .tooltip {
  display: none;
  position: absolute;
  left: 18px; top: -4px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal;
  width: 320px;
  z-index: 100;
  text-transform: none;
  letter-spacing: 0;
}
.info-icon:hover .tooltip { display: block; }

/* Methodology panel */
.methodology {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: none;
  flex-shrink: 0;
  max-height: 300px;
  overflow-y: auto;
}
.methodology.visible { display: block; }
.methodology h3 { font-size: 12px; color: var(--accent); margin-bottom: 10px; font-weight: 600; }
.methodology dl { display: grid; grid-template-columns: 200px 1fr; gap: 4px 12px; font-size: 12px; }
.methodology dt { color: var(--yellow); font-weight: 600; }
.methodology dd { color: var(--text-secondary); line-height: 1.5; }
