/* Sovereign Credit Default — dashboard styles ──────────────────────────
 *
 * Theme: dark, unified with the global site (var(--bg-primary)
 * = #0a0e1a, --text-primary = #e5e7eb).  See main.css for the
 * upstream tokens.  We define a small set of credit-default-specific
 * surface + type tokens so future colour changes are a one-line edit.
 *
 * Type scale: 5 steps. Don't introduce new font-sizes; reach for one
 * of these custom properties instead.
 */

.cd-page {
  --cd-bg:        var(--bg-primary,    #0a0e1a);
  --cd-surface:   var(--bg-secondary,  #111827);
  --cd-surface-2: #1a2035;
  --cd-surface-3: rgba(255, 255, 255, 0.025);
  --cd-border:    var(--border,        #1f2937);
  --cd-border-strong: #2a3245;
  --cd-text:      var(--text-primary,  #e5e7eb);
  --cd-text-dim:  var(--text-secondary,#9ca3af);
  --cd-text-mute: var(--text-muted,    #6b7280);
  --cd-accent:    var(--accent,        #3b82f6);
  --cd-accent-soft: rgba(59, 130, 246, 0.12);
  --cd-good:      #10b981;
  --cd-bad:       #ef4444;
  --cd-warn:      #f59e0b;

  --cd-fs-xs: 10px;   /* eyebrow / chip / column header */
  --cd-fs-sm: 12px;   /* body small / table cells */
  --cd-fs-md: 14px;   /* body */
  --cd-fs-lg: 20px;   /* section h2 / status value / PD value */
  --cd-fs-xl: 32px;   /* the ONE headline number */

  max-width: none;
  margin: 0;
  padding: 28px max(24px, calc((100vw - 1200px) / 2)) 64px;
  background: var(--cd-bg);
  color: var(--cd-text);
  font-variant-numeric: tabular-nums;
  min-height: calc(100vh - 60px);
}

/* Header */
.cd-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--cd-border);
}
.cd-header-text { max-width: 720px; }
.cd-title {
  font-size: 28px; font-weight: 700; margin: 0 0 6px;
  color: var(--cd-text); letter-spacing: -0.02em;
}
.cd-subtitle {
  font-size: var(--cd-fs-md); color: var(--cd-text-dim);
  line-height: 1.55; margin: 0;
}

.cd-status {
  display: flex; gap: 12px; flex-wrap: wrap;
}
.cd-status-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 14px; background: var(--cd-surface-2);
  border: 1px solid var(--cd-border); border-radius: 8px; min-width: 88px;
}
.cd-status-label {
  font-size: var(--cd-fs-xs); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--cd-text-mute); font-weight: 600;
}
.cd-status-value {
  font-size: var(--cd-fs-lg); font-weight: 600; color: var(--cd-text);
}
.cd-export-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; background: var(--cd-accent); color: #fff;
  border-radius: 8px; text-decoration: none; font-size: var(--cd-fs-sm);
  font-weight: 600; transition: filter 0.1s ease;
}
.cd-export-btn:hover { filter: brightness(1.1); }

/* Toolbar */
.cd-toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px;
}
#cd-search, #cd-region-filter {
  height: 34px; padding: 0 12px; font-size: var(--cd-fs-sm);
  border: 1px solid var(--cd-border-strong); border-radius: 6px;
  background: var(--cd-surface); color: var(--cd-text); min-width: 200px;
}
#cd-search::placeholder { color: var(--cd-text-mute); }
#cd-search:focus, #cd-region-filter:focus {
  outline: 2px solid var(--cd-accent); outline-offset: -1px;
  border-color: var(--cd-accent);
}
.cd-toggle-group {
  display: flex; border: 1px solid var(--cd-border-strong);
  border-radius: 6px; overflow: hidden;
}
.cd-toggle {
  height: 34px; padding: 0 14px; font-size: var(--cd-fs-sm); font-weight: 500;
  background: var(--cd-surface); color: var(--cd-text-dim);
  border: 0; border-right: 1px solid var(--cd-border);
  cursor: pointer; transition: background 0.1s ease, color 0.1s ease;
}
.cd-toggle:last-child { border-right: 0; }
.cd-toggle:hover { background: var(--cd-surface-2); color: var(--cd-text); }
.cd-toggle.active {
  background: var(--cd-accent); color: #fff;
}
.cd-spacer { flex: 1; }
.cd-link-btn {
  height: 34px; padding: 0 12px; font-size: var(--cd-fs-sm); font-weight: 500;
  background: transparent; border: 1px solid var(--cd-border-strong);
  border-radius: 6px; color: var(--cd-text-dim); cursor: pointer;
}
.cd-link-btn:hover { background: var(--cd-surface-2); color: var(--cd-text); }

/* View state — browse (table) vs detail (full-page country) */
.cd-page[data-view="browse"] .cd-detail-view { display: none; }
.cd-page[data-view="detail"] .cd-browse-table,
.cd-page[data-view="detail"] .cd-toolbar { display: none; }

.cd-detail-view {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  min-height: calc(100vh - 220px);
}
@media (max-width: 900px) {
  .cd-detail-view { grid-template-columns: 1fr; }
}

/* Detail sidebar — compact navigable sovereign list */
.cd-detail-sidebar {
  position: sticky; top: 12px;
  background: var(--cd-surface); border: 1px solid var(--cd-border);
  border-radius: 10px;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 40px);
  overflow: hidden;
}
.cd-detail-back-row {
  padding: 12px 14px; border-bottom: 1px solid var(--cd-border);
}
.cd-back-btn {
  width: 100%; height: 32px; padding: 0 10px;
  font-size: var(--cd-fs-sm); font-weight: 500;
  background: var(--cd-surface-2); color: var(--cd-text);
  border: 1px solid var(--cd-border); border-radius: 6px;
  cursor: pointer; text-align: left;
}
.cd-back-btn:hover { background: var(--cd-surface-3); border-color: var(--cd-border-strong); }
.cd-detail-search {
  margin: 10px 14px; height: 32px; padding: 0 10px; font-size: var(--cd-fs-sm);
  border: 1px solid var(--cd-border-strong); border-radius: 6px;
  background: var(--cd-surface-2); color: var(--cd-text);
}
.cd-detail-search::placeholder { color: var(--cd-text-mute); }
.cd-detail-search:focus {
  outline: 2px solid var(--cd-accent); outline-offset: -1px;
  border-color: var(--cd-accent);
}
.cd-detail-list {
  list-style: none; margin: 0; padding: 4px 0; overflow-y: auto;
  flex: 1; font-size: var(--cd-fs-sm);
}
.cd-detail-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 6px; align-items: baseline;
  padding: 7px 14px; cursor: pointer;
  border-left: 3px solid transparent;
}
.cd-detail-list li:hover { background: var(--cd-surface-2); }
.cd-detail-list li.selected {
  background: var(--cd-accent-soft); border-left-color: var(--cd-accent);
}
.cd-detail-list .cd-detail-name {
  font-weight: 500; color: var(--cd-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cd-detail-list .cd-detail-rating {
  font-size: var(--cd-fs-xs); color: var(--cd-text-dim);
}
.cd-detail-list .cd-detail-pd {
  font-size: var(--cd-fs-xs); color: var(--cd-text-mute);
}

/* Table */
.cd-table-wrap {
  background: var(--cd-surface); border: 1px solid var(--cd-border);
  border-radius: 10px;
  overflow-x: auto;
}
.cd-table {
  width: 100%; border-collapse: collapse; font-size: var(--cd-fs-sm);
}
.cd-table thead th {
  position: sticky; top: 0; background: var(--cd-surface-2);
  text-align: left; padding: 10px 12px; font-size: var(--cd-fs-xs);
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--cd-text-dim);
  font-weight: 600; border-bottom: 1px solid var(--cd-border-strong);
  white-space: nowrap;
}
.cd-table thead th.num { text-align: right; }
.cd-table thead th.sortable { cursor: pointer; user-select: none; }
.cd-table thead th.sortable:hover { color: var(--cd-text); background: var(--cd-surface-3); }
.cd-table thead th.sortable.sort-asc::after  { content: ' ▲'; font-size: 9px; }
.cd-table thead th.sortable.sort-desc::after { content: ' ▼'; font-size: 9px; }

/* Column-group ribbon: identity | PM | agencies | risk.
 * Without Region the 12-column layout is:
 *   1 Country | 2 PM Rating | 3 Composite | 4-7 S&P/Moody/Fitch/Δ | 8 Watch
 *   | 9-11 PD 1y/3y/5y | 12 Shadow gap.
 * Group boundaries are after columns 1, 3, and 8. */
.cd-table th:nth-child(1),
.cd-table th:nth-child(3),
.cd-table th:nth-child(8),
.cd-table td:nth-child(1),
.cd-table td:nth-child(3),
.cd-table td:nth-child(8) {
  border-right: 1px solid var(--cd-border);
}
.cd-table th:nth-child(2),
.cd-table th:nth-child(3),
.cd-table td:nth-child(2),
.cd-table td:nth-child(3) {
  background: rgba(59, 130, 246, 0.05);
}
.cd-table tbody tr:hover td:nth-child(2),
.cd-table tbody tr:hover td:nth-child(3) {
  background: rgba(59, 130, 246, 0.10);
}

.cd-table tbody td {
  padding: 9px 12px; border-bottom: 1px solid var(--cd-border);
  color: var(--cd-text); white-space: nowrap;
}
.cd-table tbody tr { cursor: pointer; transition: background 0.08s ease; }
.cd-table tbody tr:hover { background: var(--cd-surface-2); }
.cd-table tbody tr.selected { background: var(--cd-accent-soft); }
.cd-table tbody td.num { text-align: right; }
.cd-loading {
  padding: 28px; text-align: center; color: var(--cd-text-mute);
  font-size: var(--cd-fs-sm);
}

.cd-flag { font-size: 14px; margin-right: 6px; }
.cd-iso {
  color: var(--cd-text-mute); font-size: var(--cd-fs-xs);
  margin-left: 4px; font-weight: 400;
}

/* Rating chips (dark-friendly: tinted bg + saturated text) */
.cd-rating-chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 22px; padding: 0 6px;
  border-radius: 4px; font-size: 11px; font-weight: 700;
}
.cd-rating-chip.ig         { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; }
.cd-rating-chip.crossover  { background: rgba(245, 158, 11, 0.18); color: #fcd34d; }
.cd-rating-chip.hy         { background: rgba(245, 158, 11, 0.20); color: #fbbf24; }
.cd-rating-chip.distressed { background: rgba(239, 68, 68, 0.18);  color: #fca5a5; }
.cd-rating-chip.default    { background: #fff; color: var(--cd-bg); }

.cd-pd-bar {
  display: inline-block; height: 6px;
  background: linear-gradient(90deg, #fbbf24, #ef4444);
  border-radius: 3px; vertical-align: middle; margin-right: 6px; max-width: 80px;
}

.cd-delta-pos { color: #fca5a5; font-weight: 600; }
.cd-delta-neg { color: #6ee7b7; font-weight: 600; }
.cd-delta-zero { color: var(--cd-text-mute); }

.cd-watch-down {
  color: #fca5a5; font-weight: 700; font-size: 14px;
  display: inline-block; min-width: 22px; text-align: center;
}
.cd-watch-up {
  color: #6ee7b7; font-weight: 700; font-size: 14px;
  display: inline-block; min-width: 22px; text-align: center;
}
.cd-watch-none { color: var(--cd-border-strong); }

/* Country detail panel */
.cd-panel {
  background: var(--cd-surface); border: 1px solid var(--cd-border);
  border-radius: 10px; padding: 22px 24px; min-height: 200px;
}
.cd-panel--full {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}
.cd-panel--full .cd-pd-row { grid-template-columns: repeat(4, minmax(120px, 1fr)); }
.cd-panel--full .cd-rating-row--five {
  grid-template-columns: 1.5fr 1fr 0.85fr 0.85fr 0.85fr;
}
.cd-panel--full .cd-history-chart { height: 320px; }
.cd-panel-empty {
  color: var(--cd-text-dim); font-size: var(--cd-fs-md); line-height: 1.55;
}
.cd-panel-content { display: flex; flex-direction: column; gap: 18px; }

.cd-panel-header { display: flex; flex-direction: column; gap: 2px; }
.cd-panel-header h2 {
  font-size: var(--cd-fs-lg); font-weight: 700; margin: 0; color: var(--cd-text);
}
.cd-panel-region { font-size: var(--cd-fs-sm); color: var(--cd-text-mute); }

/* Rating row — PM card is the protagonist; agencies sit back. */
.cd-rating-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.cd-rating-row--five { grid-template-columns: repeat(5, 1fr); }
.cd-rating-card {
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 14px 14px 12px;
  border: 1px solid var(--cd-border); border-radius: 10px;
  background: var(--cd-surface-2);
}
.cd-rating-card--pm {
  background: linear-gradient(135deg, #1e3a5f 0%, #3b82f6 130%);
  border-color: var(--cd-accent); color: #fff;
}
.cd-rating-card--pm .cd-rating-label { color: rgba(255, 255, 255, 0.75); }
.cd-rating-card--pm .cd-rating-meta  { color: rgba(255, 255, 255, 0.85); }
.cd-rating-card--pm .cd-rating-value { font-size: var(--cd-fs-xl); }
.cd-rating-card--composite {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.40);
}
.cd-rating-card--composite .cd-rating-label { color: #6ee7b7; }
.cd-rating-label {
  font-size: var(--cd-fs-xs); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--cd-text-mute); font-weight: 600;
}
.cd-rating-value {
  font-size: 24px; font-weight: 700; line-height: 1.1; margin: 6px 0 2px;
  letter-spacing: -0.02em;
}
.cd-rating-meta { font-size: var(--cd-fs-xs); color: var(--cd-text-dim); }
.cd-rating-raw {
  font-size: 10px;
  font-style: italic;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 2px;
  display: block;
}

/* PD row */
.cd-pd-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 14px; background: var(--cd-surface-3); border-radius: 8px;
  border: 1px solid var(--cd-border);
}
.cd-pd-cell { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.cd-pd-label {
  font-size: var(--cd-fs-xs); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--cd-text-mute); font-weight: 600;
}
.cd-pd-value {
  font-size: var(--cd-fs-lg); font-weight: 600; color: var(--cd-text);
}

.cd-section h3 {
  font-size: var(--cd-fs-xs); text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 600; color: var(--cd-text-dim); margin: 0 0 10px;
}
.cd-section-note {
  font-size: var(--cd-fs-sm); color: var(--cd-text-mute); margin: 8px 0 0;
}

.cd-history-chart {
  position: relative;
  width: 100%;
  height: 220px;
  background: var(--cd-surface-3);
  border-radius: 6px;
  padding: 8px;
  border: 1px solid var(--cd-border);
}
.cd-history-chart canvas { width: 100% !important; height: 100% !important; }
.cd-history-empty {
  font-size: var(--cd-fs-sm); color: var(--cd-text-mute); text-align: center;
  padding: 80px 0; margin: 0;
}
.cd-history-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; gap: 12px;
}
.cd-history-header h3 { margin: 0; }
.cd-history-horizon .cd-toggle { height: 28px; padding: 0 10px; font-size: 11px; }

/* Chart legend — 4-column grid instead of run-on text */
.cd-legend {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 18px;
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--cd-surface-3);
  border: 1px solid var(--cd-border);
  border-radius: 8px;
}
.cd-legend-item { display: grid; grid-template-columns: 12px 1fr; gap: 8px; }
.cd-legend-item .cd-legend-dot { margin-top: 4px; }
.cd-legend-item b {
  display: block; font-size: var(--cd-fs-sm); color: var(--cd-text); font-weight: 600;
}
.cd-legend-item span.sub {
  display: block; font-size: var(--cd-fs-xs); color: var(--cd-text-mute);
  margin-top: 2px; line-height: 1.4;
}
@media (max-width: 900px) { .cd-legend { grid-template-columns: repeat(2, 1fr); } }

.cd-legend-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  vertical-align: middle; margin-right: 4px;
}

.cd-shadow-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.cd-shadow-grid > div {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 12px; background: var(--cd-surface-2);
  border: 1px solid var(--cd-border); border-radius: 6px;
}
.cd-shadow-grid span {
  font-size: var(--cd-fs-xs); color: var(--cd-text-mute);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.cd-shadow-grid b { font-size: var(--cd-fs-sm); color: var(--cd-text); }

/* Indicator contributions */
.cd-contrib { display: flex; flex-direction: column; gap: 6px; }
.cd-contrib-row {
  display: grid; grid-template-columns: 130px 50px 1fr 56px;
  gap: 8px; align-items: center; font-size: var(--cd-fs-sm);
}
.cd-contrib-label { color: var(--cd-text); }
.cd-contrib-period {
  display: inline-block; font-size: var(--cd-fs-xs); padding: 1px 5px;
  background: var(--cd-surface-2); color: var(--cd-text-mute);
  border-radius: 3px; margin-left: 4px;
}
.cd-contrib-value { color: var(--cd-text); text-align: right; }
.cd-contrib-bar-track {
  position: relative; height: 8px;
  background: var(--cd-surface-2); border-radius: 4px;
}
.cd-contrib-bar-track::after {
  content: ''; position: absolute; left: 50%; top: -1px; bottom: -1px;
  width: 1px; background: var(--cd-border-strong);
}
.cd-contrib-bar {
  position: absolute; top: 0; bottom: 0; height: 100%; border-radius: 4px;
}
.cd-contrib-bar.risk    { background: var(--cd-bad);  left: 50%; }
.cd-contrib-bar.hedge   { background: var(--cd-good); right: 50%; }
.cd-contrib-bar.missing {
  background: repeating-linear-gradient(45deg, var(--cd-border) 0 4px, transparent 4px 8px);
  width: 100% !important; left: 0;
}
.cd-contrib-z {
  font-size: var(--cd-fs-xs); color: var(--cd-text-mute); text-align: right;
}

/* Methodology dialog stays light (modals can break theme without
 * looking broken, and small bodies of paragraph text scan better
 * dark-on-light for sustained reading). */
.cd-dialog {
  border: 0; border-radius: 12px; padding: 0; max-width: 600px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  color: #1f2937;
}
.cd-dialog::backdrop { background: rgba(15, 23, 42, 0.7); }
.cd-dialog article { padding: 20px 24px 24px; }
.cd-dialog header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.cd-dialog header h3 { font-size: 17px; font-weight: 700; margin: 0; color: #111827; }
.cd-dialog-close {
  font-size: 20px; line-height: 1; background: transparent; border: 0;
  color: #6b7280; cursor: pointer; padding: 4px 8px;
}
.cd-method-body p {
  font-size: 13px; line-height: 1.6; color: #1f2937; margin: 0 0 10px;
}
.cd-method-body .cd-method-data {
  font-size: 12px; color: #6b7280; margin-top: 14px;
  padding-top: 12px; border-top: 1px solid #e5e7eb;
}
.cd-method-body code {
  background: #f3f4f6; padding: 1px 4px; border-radius: 3px; font-size: 12px;
}
