/* assets/risk_drawer.css
   Enterprise-grade Risk Drawer styling (drop-in replacement)
   - Single source of truth (no duplicate selectors)
   - Themeable (dark/light) + density (comfortable/compact)
   - Better typography hierarchy (less "950 everywhere")
   - Accessible focus rings + reduced-motion support
   - Driver tiles: consistent height WITHOUT hard-coding tall cards
*/

/* ------------------------------ */
/* Tokens (scoped + themeable)    */
/* ------------------------------ */
:where(:root, .risk-drawer){
  /* Typography */
  --risk-font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
                      "Apple Color Emoji", "Segoe UI Emoji";
  --risk-lh: 1.45;

  --risk-fw-regular: 450;
  --risk-fw-medium: 550;
  --risk-fw-semibold: 650;
  --risk-fw-bold: 750;
  --risk-fw-extrabold: 820;

  /* Spacing (8pt grid-ish) */
  --risk-space-1: 4px;
  --risk-space-2: 8px;
  --risk-space-3: 12px;
  --risk-space-4: 16px;
  --risk-space-5: 20px;
  --risk-space-6: 24px;

  /* Shape */
  --risk-radius-sm: 10px;
  --risk-radius-md: 12px;
  --risk-radius-lg: 16px;

  /* Color: Dark (default) */
  --risk-bg: #0b1426;
  --risk-text: rgba(255,255,255,0.92);
  --risk-muted: rgba(255,255,255,0.72);
  --risk-subtle: rgba(255,255,255,0.56);

  --risk-surface-1: rgba(255,255,255,0.035);
  --risk-surface-2: rgba(255,255,255,0.055);
  --risk-surface-3: rgba(255,255,255,0.075);

  --risk-border: rgba(255,255,255,0.12);
  --risk-border-strong: rgba(255,255,255,0.18);

  /* Elevation */
  --risk-shadow-sm: 0 1px 0 rgba(0,0,0,0.35);
  --risk-shadow-md: 0 14px 30px rgba(0,0,0,0.28);
  --risk-shadow-lg: 0 28px 64px rgba(0,0,0,0.32);

  /* Focus / A11y */
  --risk-focus: rgba(106, 168, 255, 0.95);
  --risk-focus-border: rgba(106, 168, 255, 0.55);
  --risk-focus-ring: 0 0 0 3px rgba(106, 168, 255, 0.35);

  /* Icons (Bootstrap accordion chevron) */
  --risk-icon-filter: invert(1);

  /* Badge base */
  --risk-badge-bg: rgba(255,255,255,0.06);
  --risk-badge-border: rgba(255,255,255,0.16);

  /* Risk level palette (optional modifiers) */
  --risk-level-high-bg: rgba(255, 158, 44, 0.16);
  --risk-level-high-border: rgba(255, 158, 44, 0.50);
  --risk-level-high-text: rgba(255, 198, 125, 0.98);

  --risk-level-medium-bg: rgba(255, 220, 102, 0.14);
  --risk-level-medium-border: rgba(255, 220, 102, 0.45);
  --risk-level-medium-text: rgba(255, 236, 168, 0.98);

  --risk-level-low-bg: rgba(76, 217, 100, 0.14);
  --risk-level-low-border: rgba(76, 217, 100, 0.42);
  --risk-level-low-text: rgba(170, 255, 190, 0.98);

  --risk-level-critical-bg: rgba(255, 69, 58, 0.16);
  --risk-level-critical-border: rgba(255, 69, 58, 0.50);
  --risk-level-critical-text: rgba(255, 168, 164, 0.98);

  /* Driver tiles */
  --risk-driver-rank-w: 18px;
  --risk-driver-gap: 12px;
  --risk-driver-min-h: 92px;
}

/* Optional: Light theme (only applies if you add data-theme="light" on a wrapper) */
.risk-drawer[data-theme="light"]{
  --risk-bg: #ffffff;
  --risk-text: rgba(17, 24, 39, 0.92);
  --risk-muted: rgba(17, 24, 39, 0.70);
  --risk-subtle: rgba(17, 24, 39, 0.55);

  --risk-surface-1: rgba(17, 24, 39, 0.035);
  --risk-surface-2: rgba(17, 24, 39, 0.055);
  --risk-surface-3: rgba(17, 24, 39, 0.075);

  --risk-border: rgba(17, 24, 39, 0.12);
  --risk-border-strong: rgba(17, 24, 39, 0.18);

  --risk-icon-filter: invert(0);
}

/* Optional: Compact density (only applies if you add data-density="compact") */
.risk-drawer[data-density="compact"]{
  --risk-space-3: 10px;
  --risk-space-4: 14px;
  --risk-space-5: 18px;
  --risk-driver-min-h: 86px;
}

/* ------------------------------ */
/* Base text behavior (scoped)    */
/* ------------------------------ */
:where(.risk-title, .risk-summary, .risk-details){
  font-family: var(--risk-font-family);
  color: var(--risk-text);
  line-height: var(--risk-lh);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ------------------------------ */
/* Title                           */
/* ------------------------------ */
.risk-title{ width: 100%; min-width: 0; }
#sh-risk-drawer .offcanvas-header .btn-close { display: none !important; }

.risk-title__row1{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: var(--risk-space-3);
  min-width:0;
}

.risk-title__name{
  font-size: 1.125rem; /* 18px */
  font-weight: var(--risk-fw-bold);
  line-height: 1.2;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.risk-title__row2{
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap: var(--risk-space-3);
  margin-top: var(--risk-space-1);
  min-width:0;
}

.risk-title__meta-left{
  font-size: 0.875rem; /* 14px */
  font-weight: var(--risk-fw-medium);
  color: var(--risk-muted);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  min-width:0;
}

.risk-title__updated{
  font-size: 0.8125rem; /* 13px */
  color: var(--risk-subtle);
  white-space:nowrap;
}

/* ------------------------------ */
/* Summary surface                 */
/* ------------------------------ */
.risk-summary{
  background: linear-gradient(180deg, var(--risk-surface-2), var(--risk-surface-1));
  border: 1px solid var(--risk-border);
  border-radius: var(--risk-radius-lg);
  padding: var(--risk-space-5);
  box-shadow: var(--risk-shadow-md);
}

@supports ((-webkit-backdrop-filter: blur(8px)) or (backdrop-filter: blur(8px))){
  .risk-summary{
    -webkit-backdrop-filter: blur(8px) saturate(120%);
    backdrop-filter: blur(8px) saturate(120%);
  }
}

.risk-kpi{
  display:flex;
  align-items:baseline;
  gap: var(--risk-space-3);
}

.risk-kpi__value{
  font-size: clamp(2.25rem, 6vw, 3rem);
  font-weight: var(--risk-fw-extrabold);
  line-height: 1;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

/* Badge: base + optional modifiers */
.risk-badge{
  --_bg: var(--risk-badge-bg);
  --_border: var(--risk-badge-border);
  --_text: var(--risk-text);

  display:inline-flex;
  align-items:center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--_border);
  background: var(--_bg);
  color: var(--_text);
  font-size: 0.8125rem;
  font-weight: var(--risk-fw-semibold);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.risk-badge--high,
.risk-badge[data-level="high"]{
  --_bg: var(--risk-level-high-bg);
  --_border: var(--risk-level-high-border);
  --_text: var(--risk-level-high-text);
}

.risk-badge--medium,
.risk-badge[data-level="medium"]{
  --_bg: var(--risk-level-medium-bg);
  --_border: var(--risk-level-medium-border);
  --_text: var(--risk-level-medium-text);
}

.risk-badge--low,
.risk-badge[data-level="low"]{
  --_bg: var(--risk-level-low-bg);
  --_border: var(--risk-level-low-border);
  --_text: var(--risk-level-low-text);
}

.risk-badge--critical,
.risk-badge[data-level="critical"]{
  --_bg: var(--risk-level-critical-bg);
  --_border: var(--risk-level-critical-border);
  --_text: var(--risk-level-critical-text);
}

.risk-subtitle{
  font-size: 1rem;
  font-weight: var(--risk-fw-semibold);
  line-height: 1.3;
  margin-top: var(--risk-space-3);
}

.risk-comp{
  margin-top: var(--risk-space-2);
  font-size: 0.875rem;
  color: var(--risk-muted);
  display:flex;
  flex-wrap:wrap;
  gap: 6px;
}
.risk-comp .muted{ color: var(--risk-subtle); }

.risk-divider{
  border-top: 1px solid var(--risk-border);
  margin: var(--risk-space-4) 0;
}

.risk-section-title{
  font-size: 0.95rem;
  font-weight: var(--risk-fw-semibold);
  margin-top: 0;
  color: var(--risk-text);
}

/* ------------------------------ */
/* Drivers grid                    */
/* ------------------------------ */
.risk-drivers-grid{
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--risk-space-3);
  margin-top: var(--risk-space-3);
}

@media (min-width: 640px){
  .risk-drivers-grid{
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Tile: consistent height via reserved lines + min-height (no tall hard lock) */
.risk-driver-tile{
  background: var(--risk-surface-1);
  border: 1px solid var(--risk-border);
  border-radius: var(--risk-radius-md);
  padding: var(--risk-space-3);
  min-height: var(--risk-driver-min-h);
  box-shadow: var(--risk-shadow-sm);

  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: var(--risk-space-2);

  overflow: hidden;
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.risk-driver-tile:hover{
  background: var(--risk-surface-2);
  border-color: var(--risk-border-strong);
  box-shadow: var(--risk-shadow-md);
  transform: translateY(-1px);
}

.risk-driver-tile:focus-within{
  border-color: var(--risk-focus-border);
  box-shadow: var(--risk-shadow-sm), var(--risk-focus-ring);
}

/* Row containing rank + title */
.risk-driver-tile__row{
  display:flex;
  align-items:flex-start;
  gap: var(--risk-driver-gap);
  min-width: 0;
}

.risk-driver-tile__rank{
  width: var(--risk-driver-rank-w);
  flex: 0 0 auto;
  margin-top: 1px;

  color: var(--risk-subtle);
  font-weight: var(--risk-fw-semibold);
  font-size: 0.75rem;
  line-height: 1.2;
}

.risk-driver-tile__title{
  min-width: 0;
  color: var(--risk-text);
  font-weight: var(--risk-fw-semibold);
  font-size: 0.95rem;
  line-height: 1.25;

  /* 2-line clamp + reserve 2 lines so tiles stay visually consistent */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  min-height: 2.5em; /* 2 lines * 1.25 */
}

/* Meta aligned under title (not under rank) */
.risk-driver-tile__meta{
  padding-left: calc(var(--risk-driver-rank-w) + var(--risk-driver-gap));
  color: var(--risk-muted);
  font-size: 0.8125rem;
  line-height: 1.25;

  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;

  /* reserve one line even if empty */
  min-height: 1.25em;
}

/* ------------------------------ */
/* Accordion: Details + Methodology */
/* ------------------------------ */
.risk-details{
  margin-top: var(--risk-space-4);
}

.risk-details .accordion-item{
  background: transparent;
  border: none;
}

/* Slight vertical rhythm between items (Bootstrap has its own; this is safe) */
.risk-details .accordion-item + .accordion-item{
  margin-top: var(--risk-space-3);
}

.risk-details .accordion-button{
  background: var(--risk-surface-1);
  border: 1px solid var(--risk-border);
  border-radius: var(--risk-radius-md) !important;

  color: var(--risk-text);
  font-weight: var(--risk-fw-semibold);
  font-size: 0.95rem;

  padding: 14px;
  box-shadow: none !important;

  transition: background-color 120ms ease, border-color 120ms ease;
}

.risk-details .accordion-button:hover{
  background: var(--risk-surface-2);
  border-color: var(--risk-border-strong);
}

.risk-details .accordion-button:focus-visible{
  outline: none;
  border-color: var(--risk-focus-border);
  box-shadow: var(--risk-focus-ring) !important;
}

.risk-details .accordion-button:not(.collapsed){
  background: var(--risk-surface-2);
  border-color: var(--risk-border-strong);
  border-bottom-left-radius: 0 !important;
  border-bottom-right-radius: 0 !important;
}

.risk-details .accordion-button::after{
  filter: var(--risk-icon-filter);
  opacity: 0.78;
}

.risk-details .accordion-collapse{
  background: var(--risk-surface-1);
  border: 1px solid var(--risk-border);
  border-top: 0;
  border-bottom-left-radius: var(--risk-radius-md) !important;
  border-bottom-right-radius: var(--risk-radius-md) !important;
}

.risk-details .accordion-body{
  padding: 12px 14px 14px;
  color: var(--risk-text) !important;
  font-size: 0.875rem;
  line-height: 1.55;
}

.risk-details .accordion-body .text-muted{
  color: var(--risk-muted) !important;
}

/* KV rows inside accordion */
.risk-details .accordion-body .risk-kv{
  margin-top: var(--risk-space-2);
  line-height: 1.35;
}

.risk-details .accordion-body .risk-kv__label{
  color: var(--risk-muted) !important;
}

.risk-details .accordion-body .risk-kv__value{
  color: var(--risk-text) !important;
  font-weight: var(--risk-fw-semibold);
}

/* ------------------------------ */
/* A11y: reduced motion + contrast */
/* ------------------------------ */
@media (prefers-reduced-motion: reduce){
  .risk-summary,
  .risk-driver-tile,
  .risk-details .accordion-button{
    transition: none !important;
  }
  .risk-driver-tile:hover{
    transform: none;
  }
}

@media (prefers-contrast: more){
  :where(:root, .risk-drawer){
    --risk-border: rgba(255,255,255,0.28);
    --risk-border-strong: rgba(255,255,255,0.42);
    --risk-muted: rgba(255,255,255,0.82);
  }
  .risk-summary,
  .risk-driver-tile{
    box-shadow: none;
  }
}
.risk-subtitle{
  font-weight: var(--risk-fw-semibold);
  line-height: 1.35;
  margin-top: 10px;
  max-width: 52ch; /* prevents awkward long-line feeling on wide drawers */
}
.risk-comp{
  margin-top: 6px;
  font-size: 0.8125rem;
  line-height: 1.35;
  color: var(--risk-muted);
  gap: 8px;
  opacity: 1;
  font-variant-numeric: tabular-nums; /* numbers feel more stable */
}
.risk-comp{
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--risk-muted);
  font-variant-numeric: tabular-nums;
}

.risk-comp__chip{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--risk-surface-1);
  border: 1px solid var(--risk-border);
}

.risk-comp__label{
  color: var(--risk-subtle);
}

.risk-comp__chip strong{
  color: var(--risk-text);
  font-weight: var(--risk-fw-semibold);
}

.risk-comp__chip strong.is-up{
  color: var(--risk-level-high-text); /* or a dedicated “positive/negative” token */
}
.risk-divider{
  margin: 16px 0 0;
  border-top: 1px solid var(--risk-border);
  opacity: 0.8;
}
/* Chips row for comparisons */
.risk-comp{
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;

  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

/* Single chip */
.risk-comp__chip{
  display: inline-flex;
  align-items: center;
  gap: 8px;

  padding: 6px 10px;
  border-radius: 999px;

  background: var(--risk-surface-1);
  border: 1px solid var(--risk-border);
}

/* When value is missing */
.risk-comp__chip[data-empty="true"]{
  opacity: 0.72;
}

/* Label/value inside chip */
.risk-comp__label{
  color: var(--risk-subtle);
  font-weight: var(--risk-fw-medium);
}

.risk-comp__value{
  color: var(--risk-text);
  font-weight: var(--risk-fw-semibold);
}

/* Tone mapping (delta/ratio semantics) */
.risk-comp__value[data-tone="negative"]{ color: var(--risk-level-high-text); }
.risk-comp__value[data-tone="positive"]{ color: var(--risk-level-low-text); }
.risk-comp__value[data-tone="neutral"]{ color: var(--risk-text); }
/* Badge size variants */
.risk-badge--sm{ font-size: 0.82rem; padding: 2px 10px; }
.risk-badge--md{ font-size: 0.90rem; padding: 2px 10px; }

/* Badge levels (example mapping; tune to your tokens) */
.risk-badge[data-level="high"]{ border-color: rgba(255,158,44,.50); color: rgba(255,198,125,.98); background: rgba(255,158,44,.16); }
.risk-badge[data-level="medium"]{ border-color: rgba(255,220,102,.45); color: rgba(255,236,168,.98); background: rgba(255,220,102,.14); }
.risk-badge[data-level="low"]{ border-color: rgba(76,217,100,.42); color: rgba(170,255,190,.98); background: rgba(76,217,100,.14); }
.risk-badge[data-level="critical"]{ border-color: rgba(255,69,58,.50); color: rgba(255,168,164,.98); background: rgba(255,69,58,.16); }

/* Chips row */
.risk-comp{
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.risk-comp__chip{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--risk-surface-1);
  border: 1px solid var(--risk-border);
}

.risk-comp__chip[data-empty="true"]{ opacity: 0.72; }

.risk-comp__label{ color: var(--risk-subtle); font-weight: 550; }
.risk-comp__value{ color: var(--risk-text); font-weight: 650; }

.risk-comp__value[data-tone="negative"]{ color: var(--risk-level-high-text); }
.risk-comp__value[data-tone="positive"]{ color: var(--risk-level-low-text); }
.risk-comp__value[data-tone="neutral"]{ color: var(--risk-text); }
/* =========================================
   Brand risk colors (match Python constants)
   COL_NEG       = #d55e00  (High / In shortage)
   COL_POS       = #009e8f  (Low)
   COL_NEU       = #6b6b6b  (Neutral)
   COL_HIGHLIGHT = #0066cc  (Medium)
   ========================================= */

:where(:root, .risk-drawer){
  --risk-accent-neg: #d55e00;
  --risk-accent-pos: #009e8f;
  --risk-accent-neu: #6b6b6b;
  --risk-accent-med: #0066cc;

  /* High */
  --risk-level-high-text: var(--risk-accent-neg);
  --risk-level-high-border: rgba(213, 94, 0, 0.55);
  --risk-level-high-bg: rgba(213, 94, 0, 0.16);

  /* Medium (BLUE) ✅ */
  --risk-level-medium-text: var(--risk-accent-med);
  --risk-level-medium-border: rgba(0, 102, 204, 0.55);
  --risk-level-medium-bg: rgba(0, 102, 204, 0.16);

  /* Low */
  --risk-level-low-text: var(--risk-accent-pos);
  --risk-level-low-border: rgba(0, 158, 143, 0.55);
  --risk-level-low-bg: rgba(0, 158, 143, 0.16);

  /* Critical / In shortage (use negative) */
  --risk-level-critical-text: var(--risk-accent-neg);
  --risk-level-critical-border: rgba(213, 94, 0, 0.55);
  --risk-level-critical-bg: rgba(213, 94, 0, 0.16);
}

/* Ensure badge uses the tokens above (even if other badge rules exist earlier) */
.risk-badge[data-level="high"]{
  color: var(--risk-level-high-text);
  border-color: var(--risk-level-high-border);
  background: var(--risk-level-high-bg);
}
.risk-badge[data-level="medium"]{
  color: var(--risk-level-medium-text);
  border-color: var(--risk-level-medium-border);
  background: var(--risk-level-medium-bg);
}
.risk-badge[data-level="low"]{
  color: var(--risk-level-low-text);
  border-color: var(--risk-level-low-border);
  background: var(--risk-level-low-bg);
}
.risk-badge[data-level="critical"]{
  color: var(--risk-level-critical-text);
  border-color: var(--risk-level-critical-border);
  background: var(--risk-level-critical-bg);
}

/* (Optional) align chip tone colors to the same constants */
.risk-comp__value[data-tone="negative"]{ color: var(--risk-level-high-text); }
.risk-comp__value[data-tone="positive"]{ color: var(--risk-level-low-text); }
.risk-comp__value[data-tone="neutral"]{ color: var(--risk-text); }
/* ===========================================
   Make delta/ratio chip values match the band
   - Medium => blue
   - Low    => green
   - High   => orange
   =========================================== */

/* Use your tokens (recommended) */
.risk-summary[data-band="medium"] .risk-comp__value[data-tone]{
  color: var(--risk-level-medium-text);
}
.risk-summary[data-band="low"] .risk-comp__value[data-tone]{
  color: var(--risk-level-low-text);
}
.risk-summary[data-band="high"] .risk-comp__value[data-tone],
.risk-summary[data-band="critical"] .risk-comp__value[data-tone]{
  color: var(--risk-level-high-text);
}



:where(:root, .risk-drawer){
  /* Brand accents (given) */
  --risk-accent-neg: #d55e00; /* High / In shortage */
  --risk-accent-pos: #009e8f; /* Low */
  --risk-accent-neu: #6b6b6b; /* Neutral */
  --risk-accent-med: #0066cc; /* Medium (brand blue) */

  /* On-dark text companion for Medium (readable) */
  --risk-accent-med-on-dark: #3385d6; /* ~20% lighter, better contrast */
}

/* Ensure Medium badge text uses the on-dark color */
.risk-badge[data-level="medium"]{
  color: var(--risk-accent-med-on-dark);
  border-color: rgba(0, 102, 204, 0.55);
  background: rgba(0, 102, 204, 0.16);
}

/* Chips: keep labels readable (neutral), tint border/background, color values by band */
.risk-summary[data-band="medium"] .risk-comp__chip{
  border-color: rgba(0, 102, 204, 0.38);
  background: rgba(0, 102, 204, 0.08); /* subtle tint; lower if you want even cleaner */
}

/* ✅ Key contrast change: labels are NOT blue */
.risk-summary[data-band="medium"] .risk-comp__label{
  color: var(--risk-muted);
}

/* ✅ Values align with Medium (but readable) */
.risk-summary[data-band="medium"] .risk-comp__value[data-tone]{
  color: var(--risk-accent-med-on-dark);
}

/* Keep Low/High alignment (these already have good contrast) */
.risk-summary[data-band="low"] .risk-comp__value[data-tone]{
  color: var(--risk-accent-pos);
}
.risk-summary[data-band="high"] .risk-comp__value[data-tone],
.risk-summary[data-band="critical"] .risk-comp__value[data-tone]{
  color: var(--risk-accent-neg);
}
/* Band-colored chip labels (use “on-dark” friendly tints) */

/* Medium (blue) */
.risk-summary[data-band="medium"] .risk-comp__label{
  color: rgba(51, 133, 214, 0.90); /* same family as #3385d6 */
}

/* Low (green) */
.risk-summary[data-band="low"] .risk-comp__label{
  color: rgba(0, 198, 180, 0.90);  /* lighter-on-dark tint of #009e8f */
}

/* High + Critical (orange) — aligned to COL_NEG (#d55e00) but readable on dark */
.risk-summary[data-band="high"] .risk-comp__label,
.risk-summary[data-band="critical"] .risk-comp__label{
  color: rgba(255, 154, 74, 0.92); /* on-dark companion of #d55e00 */
}
/* Offcanvas header makes its children flex items; let the title grow */
.offcanvas-header .offcanvas-title {
  flex: 1 1 auto;
  min-width: 0;
}

/* Make your title component fill that space */
.offcanvas-header .offcanvas-title .risk-title {
  width: 100%;
}
/* Force the Offcanvas header/title area to give the title full width */
#sh-risk-drawer .offcanvas-header{
  align-items: flex-start; /* nicer for 2-line title */
}

/* Most cases: title is inside h5.offcanvas-title */
#sh-risk-drawer .offcanvas-header .offcanvas-title{
  flex: 1 1 0% !important;
  width: 100% !important;
  min-width: 0 !important;
}

/* If the browser hoists your .risk-title OUT of the h5 (block-in-heading quirk),
   this catches it as a direct flex child of the header */
#sh-risk-drawer .offcanvas-header > .risk-title{
  flex: 1 1 0% !important;
  width: 100% !important;
  min-width: 0 !important;
}

/* Make row2 behave like "left takes remaining, updated sticks right" */
#sh-risk-drawer .risk-title__meta-left{
  flex: 1 1 auto;
  min-width: 0;
}

#sh-risk-drawer .risk-title__updated{
  margin-left: auto;
  text-align: right;
  flex: 0 0 auto;
}
/* --- Driver number: circular badge behind 1/2/3/4 ----------------------- */
:where(:root, .risk-drawer){
  /* Slightly bigger than 18px so it reads as a badge */
  --risk-driver-rank-w: 22px;
}

.risk-driver-tile__rank{
  width: var(--risk-driver-rank-w);
  height: var(--risk-driver-rank-w);
  min-width: var(--risk-driver-rank-w);

  display: inline-flex;
  align-items: center;
  justify-content: center;

  border-radius: 999px;

  /* Uses your tokens so it stays consistent across themes */
  background: var(--risk-surface-2);
  border: 1px solid var(--risk-border);

  color: var(--risk-muted);
  font-weight: var(--risk-fw-semibold);
  font-size: 0.75rem;
  line-height: 1;

  /* The old style had a margin-top; for a circle it usually aligns better at 0 */
  margin-top: 0;
}

/* Optional: make the badge subtly “lift” on hover (nice affordance) */
.risk-driver-tile:hover .risk-driver-tile__rank{
  background: var(--risk-surface-3);
  border-color: var(--risk-border-strong);
}
/* Title clamp (keeps tile height consistent) */
.risk-driver-tile__title{
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Make sure meta never centers itself due to inherited styles */
.risk-driver-tile__meta,
.risk-driver-tile__meta-row{
  text-align: left;
}

/* If rank already has styling elsewhere, you can delete this */
.risk-driver-tile__rank{
  font-size: 0.78rem;
  font-weight: 800;
  opacity: 0.95;
}

/* Optional: make the impact chip feel “attached” but not shouty */
.risk-driver-tile__impact{
  letter-spacing: 0.2px;
}
/* Make the risk drawer content scroll instead of overflowing */
#sh-risk-drawer .offcanvas-body {
  overflow-y: auto;
  min-height: 0;          /* IMPORTANT when any parent is flex */
  padding-bottom: 96px;   /* optional: space for the floating arrows button */
}
/* assets/risk_driver_tiles.css */

/* Bulletproof alignment: make sure subtitle starts under the title, not centered */
.risk-driver-tile.risk-driver-tile--opt2{
  display: grid !important;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 6px;
  align-items: start;
}

.risk-driver-tile--opt2 .risk-driver-tile__rank{
  grid-column: 1;
  grid-row: 1;
}

.risk-driver-tile--opt2 .risk-driver-tile__title{
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

.risk-driver-tile--opt2 .risk-driver-tile__dir{
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
}

.risk-driver-tile--opt2 .risk-driver-tile__meta{
  grid-column: 2;
  grid-row: 2;

  /* This is the important part if you have a centering rule elsewhere */
  text-align: left !important;
  justify-self: start;
  min-width: 0;
}
