/* Deal detail hero, tabs, model-health notice and KPI cards: shared by
   deals/{ma,cre,fund,holdco}/deal.html and rendered by static/js/deals/deal-hero.js.
   Class prefix: dh-. Built on the tokens in styles.css. */

/* ── Hero shell ─────────────────────────────────────────────────────────── */
.deal-hero {
    background: linear-gradient(135deg, #0A0A0A 0%, #1A1310 50%, #111111 100%);
    border-bottom: 1px solid var(--surface-border);
    margin-top: 80px; /* clears the fixed navbar */
    padding: var(--space-5) 0 0;
    position: relative;
    /* Its own layer (for the glow below) placed above the page content, so the action
       menus open over the KPI cards instead of under them. Below the fixed navbar. */
    z-index: 10;
}
/* The glow is clipped by its own box, so the hero needs no overflow:hidden (which would
   clip the action menus). */
.deal-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 55% 90% at 85% 40%, var(--accent-glow, rgba(140, 110, 82, .3)), transparent);
    opacity: .7;
    pointer-events: none;
    z-index: -1;
}

.dh-crumbs {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-2);
    font-size: var(--text-sm);
    margin-bottom: var(--space-4);
    min-width: 0;
}
.dh-crumbs a { color: var(--text-light); text-decoration: none; font-weight: 600; }
.dh-crumbs a:hover { color: var(--accent-hover); }
.dh-crumbs .dh-crumb-sep { color: var(--text-muted); }
.dh-crumbs .dh-crumb-parent { max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Title block and actions sit side by side on wide screens; the title takes the space it
   needs and wraps, the actions never overlap it. */
.dh-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-4) var(--space-6);
    align-items: start;
}

.dh-eyebrow { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.dh-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(140, 110, 82, .15);
    color: var(--accent-hover);
    border: 1px solid rgba(140, 110, 82, .35);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.dh-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--surface-border-strong);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-light);
    white-space: nowrap;
}

.dh-title {
    font-size: clamp(1.4rem, 1.05rem + 1.1vw, 2rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -.01em;
    color: #fff;
    margin: 0 0 var(--space-2);
    overflow-wrap: anywhere;
    text-wrap: balance;
}

.dh-status { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); font-size: var(--text-sm); color: var(--text-light); }
.dh-stage { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-color); font-weight: 600; }
.dh-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.dh-dot--active { background: var(--status-success); box-shadow: 0 0 8px var(--status-success); }
.dh-dot--monitoring { background: var(--status-warn); }
.dh-dot--passed { background: var(--status-danger); }
.dh-dot--closed { background: var(--accent-color); }
.dh-pips { display: inline-flex; gap: 3px; }
.dh-pips i { width: 14px; height: 4px; border-radius: 2px; background: var(--surface-border-strong); }
.dh-pips i.on { background: var(--accent-hover); }
.dh-status-sep { width: 1px; height: 14px; background: var(--surface-border-strong); }

/* ── Actions ────────────────────────────────────────────────────────────── */
.dh-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-2); }
.dh-actions .btn { white-space: nowrap; }
.dh-actions .btn-group > .btn { padding-left: .8rem; padding-right: .8rem; }
.dh-more-btn { width: 38px; padding-left: 0; padding-right: 0; }
.dh-menu { --bs-dropdown-bg: var(--surface-2); --bs-dropdown-link-hover-bg: var(--hover-bg); min-width: 260px; padding: var(--space-1); border: 1px solid var(--surface-border-strong); box-shadow: var(--shadow-lg); }
.dh-menu .dropdown-item { display: flex; gap: var(--space-3); align-items: flex-start; border-radius: 6px; padding: 8px 10px; white-space: normal; }
.dh-menu .dropdown-item > i { width: 16px; margin-top: 3px; text-align: center; color: var(--accent-hover); flex-shrink: 0; }
.dh-menu .dropdown-item.text-danger > i { color: inherit; }
.dh-menu-label { display: block; font-size: var(--text-base); font-weight: 600; line-height: 1.3; }
.dh-menu-hint { display: block; font-size: var(--text-xs); color: var(--text-light); line-height: 1.35; margin-top: 2px; }
.dh-menu .dropdown-header { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .08em; padding: 6px 10px 4px; }

/* ── Key facts ──────────────────────────────────────────────────────────── */
.dh-facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3) 0;
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--surface-border);
    /* Every fact has a divider on its left. The row starts one gutter to the left and
       clips that gutter, so the fact that begins each line (the first, or one that
       wrapped) loses its divider and lines up with the title. */
    --dh-fact-gutter: var(--space-5);
    margin-left: calc(-1 * var(--dh-fact-gutter));
    clip-path: inset(0 0 0 var(--dh-fact-gutter));
}
.dh-facts:empty { display: none; }
.dh-fact { min-width: 0; margin-left: -1px; padding: 0 var(--space-6) 0 var(--dh-fact-gutter); border-left: 1px solid var(--surface-border); }
.dh-fact-label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-light); margin-bottom: 2px; white-space: nowrap; }
.dh-fact-value { display: block; font-size: var(--text-base); font-weight: 600; color: var(--text-color); font-variant-numeric: tabular-nums; max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.dh-fact-value { color: var(--text-color); text-decoration: none; }
a.dh-fact-value:hover { color: var(--accent-hover); }
.dh-fact-note { font-size: var(--text-xs); color: var(--text-light); font-weight: 500; margin-left: 4px; }
.dh-fact-note.is-late { color: var(--status-danger-text); }
.dh-fact-note.is-soon { color: var(--status-warn-text); }

/* ── Tabs ───────────────────────────────────────────────────────────────── */
.deal-tabs {
    margin-top: var(--space-4);
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    border-bottom: 0;
}
.deal-tabs::-webkit-scrollbar { display: none; }
.deal-tabs .nav-link {
    border: none;
    border-radius: 0;
    color: var(--text-light);
    padding: .85rem 1.1rem;
    font-size: var(--text-sm);
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: color .2s, border-color .2s;
    cursor: pointer;
    white-space: nowrap;
}
.deal-tabs .nav-link:hover { color: var(--text-color); }
.deal-tabs .nav-link.active { color: #fff; border-bottom-color: var(--accent-color); background: transparent; }

/* ── Model health (above the KPI cards) ─────────────────────────────────── */
.dh-health {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    border: 1px solid var(--status-warn-border);
    background: var(--status-warn-bg);
    color: var(--text-color);
    border-radius: 12px;
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
    font-size: var(--text-sm);
}
.dh-health > i { color: var(--status-warn-text); margin-top: 3px; }
.dh-health.is-danger { border-color: var(--status-danger-border); background: var(--status-danger-bg); }
.dh-health.is-danger > i { color: var(--status-danger-text); }
.dh-health-body { flex: 1; min-width: 0; }
.dh-health-title { font-weight: 700; }
.dh-health-text { color: var(--text-light); }
.dh-health-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }
.dh-notes { margin-top: var(--space-2); }
.dh-notes summary { cursor: pointer; color: var(--status-warn-text); font-weight: 600; list-style: none; display: inline-flex; align-items: center; gap: 6px; }
.dh-notes summary::-webkit-details-marker { display: none; }
.dh-notes summary::before { content: '\25B8'; transition: transform .15s; }
.dh-notes[open] summary::before { transform: rotate(90deg); }
.dh-notes ul { margin: var(--space-2) 0 0; padding-left: 1.1rem; color: var(--text-light); }
.dh-notes li + li { margin-top: 4px; }

/* ── KPI cards ──────────────────────────────────────────────────────────── */
.dh-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); }
.dh-kpis > .col-12, .dh-kpis > .dh-kpi-empty { grid-column: 1 / -1; }
.dh-kpi-empty {
    display: flex; align-items: center; justify-content: center; gap: var(--space-3); flex-wrap: wrap;
    padding: var(--space-5); border: 1px dashed var(--surface-border-strong); border-radius: 12px;
    color: var(--text-light); font-size: var(--text-sm); text-align: center;
}
.dh-kpi {
    --dh-tone: var(--accent-hover);
    position: relative;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: var(--surface-1);
    border: 1px solid var(--surface-border);
    border-radius: 12px;
    padding: var(--space-4) var(--space-4) var(--space-3);
    overflow: hidden;
}
.dh-kpi::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--dh-tone); opacity: .85; }
.dh-kpi--success { --dh-tone: var(--status-success-text); }
.dh-kpi--info { --dh-tone: var(--status-info-text); }
.dh-kpi--warn { --dh-tone: var(--status-warn-text); }
.dh-kpi-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); min-height: 20px; }
.dh-kpi-label { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--text-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dh-kpi-value { font-size: clamp(1.3rem, 1.05rem + .7vw, 1.75rem); font-weight: 700; line-height: 1.2; color: var(--dh-tone); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dh-kpi-sub { font-size: var(--text-xs); color: var(--text-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dh-kpi-flag { font-size: var(--text-xs); line-height: 1.35; margin-top: 4px; color: var(--status-warn-text); }
.dh-kpi-flag i { margin-right: 4px; }
.dh-kpi-tag {
    font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    border-radius: 4px; padding: 1px 6px; white-space: nowrap; flex-shrink: 0;
    border: 1px solid var(--status-warn-border); color: var(--status-warn-text); background: var(--status-warn-bg);
}
.dh-kpi.is-suspect { border-color: var(--status-warn-border); }
.dh-kpi.is-suspect::before { background: var(--status-warn); }
.dh-kpi.is-invalid { border-color: var(--status-danger-border); }
.dh-kpi.is-invalid::before { background: var(--status-danger); }
.dh-kpi.is-invalid .dh-kpi-value { color: var(--text-light); }
.dh-kpi.is-invalid .dh-kpi-flag { color: var(--status-danger-text); }
.dh-kpi.is-invalid .dh-kpi-tag { border-color: var(--status-danger-border); color: var(--status-danger-text); background: var(--status-danger-bg); }
.dh-kpi.is-na .dh-kpi-value { color: var(--text-light); }
.dh-kpi.is-na .dh-kpi-flag { color: var(--text-light); }
.dh-kpi.is-stale .dh-kpi-value { opacity: .55; }
.dh-kpi.is-stale .dh-kpi-tag { border-color: var(--surface-border-strong); color: var(--text-light); background: transparent; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1199.98px) {
    .dh-facts { --dh-fact-gutter: var(--space-4); }
    .dh-fact { padding-right: var(--space-5); }
    /* The tab bar scrolls sideways here; the fade says there is more. */
    .deal-tabs { mask-image: linear-gradient(to right, #000 calc(100% - 40px), transparent); padding-right: 32px; }
}
@media (max-width: 991.98px) {
    .dh-head { grid-template-columns: minmax(0, 1fr); }
    .dh-actions { justify-content: flex-start; }
    .dh-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 575.98px) {
    .deal-hero { padding-top: var(--space-4); }
    .dh-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); margin-left: 0; clip-path: none; }
    .dh-fact { margin-left: 0; padding: 0; border-left: 0; }  /* grid gap separates them */
    .dh-fact-value { max-width: 100%; }
    /* Primary on its own row, the rest share the next one, the ⋯ menu stays square. */
    .dh-actions > * { flex: 1 1 0; min-width: 0; }
    .dh-actions > .dh-act-primary { order: -1; flex-basis: 100%; }
    .dh-actions > .dropdown > .btn { width: 100%; }
    .dh-actions .btn { overflow: hidden; text-overflow: ellipsis; }
    .dh-actions > .dh-more { flex: 0 0 38px; }
    .dh-health { flex-wrap: wrap; }
    .dh-health-actions { width: 100%; }
    .dh-status-sep { display: none; }
    .dh-kpi { padding: var(--space-3); }
    .dh-kpi-head { flex-direction: column-reverse; align-items: flex-start; gap: 4px; }
    .dh-kpi-label { white-space: normal; }
}

/* ── Loading placeholders ───────────────────────────────────────────────── */
.dh-skel { margin-bottom: var(--space-2); }
.dh-skel--badge { width: 120px; height: 22px; }
.dh-skel--title { width: min(420px, 90%); height: 36px; }
.dh-skel--line { width: min(260px, 70%); height: 18px; }
.dh-skel--kpis { grid-column: 1 / -1; height: 104px; border-radius: 12px; margin: 0; }
