/* ==========================================================================
   Investor Brain -- Allocation tables (2026-09-30, Investor_Brain.mp4 O7).
   Used by /brain/allocation (workspace shell, linked from the page) and
   /brain/briefing/allocation (linked by brain_briefing/base.html.jinja).
   Markup: templates/brain_v2/_allocation.html.jinja. Colours: tokens.css
   custom properties only (light + dark).
   ========================================================================== */

/* ---------- Page ---------- */
.al-page { min-width: 0; }
/* briefing shell: .bf-main (briefing.css) sets the width and padding */

/* ---------- Tabs (plain links: ?tab=...) ---------- */
.al-tabs {
  display: flex; gap: var(--s1); margin-bottom: var(--s4);
  border-bottom: 1px solid var(--border); overflow-x: auto;
  scrollbar-width: thin;
}
.al-tab {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: var(--s3) var(--s4); margin-bottom: -1px;
  border-bottom: 2px solid transparent; border-radius: var(--r-sm) var(--r-sm) 0 0;
  font-weight: 700; font-size: var(--text-sm); color: var(--muted);
}
.al-tab:hover { color: var(--text); background: var(--panel-2); }
.al-tab:focus-visible { outline-offset: -2px; }
.al-tab[aria-current="page"] { color: var(--accent-text); border-bottom-color: var(--accent); }
.al-tab .count {
  font-size: var(--text-2xs); padding: 1px 6px; border-radius: 999px;
  background: var(--panel-3); color: var(--muted); font-variant-numeric: tabular-nums;
}
.al-tab[aria-current="page"] .count { background: var(--accent-soft); color: var(--accent-text); }

/* ---------- Cards ---------- */
.al-card { padding: var(--s5); margin-top: var(--s4); min-width: 0; }
.al-card:first-of-type { margin-top: 0; }
.al-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3) var(--s5); flex-wrap: wrap; margin-bottom: var(--s4); }
.al-head > div { min-width: 0; flex: 1 1 320px; }
.al-head h2 { font-size: var(--text-lg); }
.al-head .meta { margin-top: var(--s1); max-width: 80ch; font-size: var(--text-xs); line-height: 1.45; color: var(--muted); }
.al-read { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; font-size: var(--text-xs); color: var(--muted); font-weight: 700; }
.al-read a { border-radius: 999px; }
.al-read a:hover .pill { box-shadow: 0 0 0 1px var(--border-strong); }
.al-empty { margin-top: var(--s1); }

/* ---------- Scroll region (tables never widen the page) ---------- */
.al-scroll {
  /* position: the visually-hidden cell labels (position:absolute) must
     scroll inside this box, not widen the page */
  position: relative; overflow-x: auto; max-width: 100%;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--panel);
  /* A link focused while tabbing backwards scrolls in beside the sticky
     first column, not under it. Keep this >= that column's width while a
     table scrolls (.al-rowhead min-width 170px; 30% of the 600px
     .al-matrix = 180px) + the 4px focus ring (base.css :focus-visible). */
  scroll-padding-inline-start: 192px;
}
.al-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Tables ---------- */
.al-table { width: 100%; font-size: var(--text-sm); border-collapse: separate; border-spacing: 0; }
.al-table th, .al-table td {
  text-align: left; vertical-align: top;
  padding: var(--s3); border-top: 1px solid var(--border);
}
.al-table thead th {
  border-top: 0; background: var(--panel-2);
  font-size: var(--text-2xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap;
}
.al-table tbody tr:first-child > * { border-top: 0; }
/* first column stays put while a wide table scrolls sideways */
.al-table tr > :first-child {
  position: sticky; left: 0; z-index: 1;
  background: var(--panel); box-shadow: 1px 0 0 var(--border);
}
.al-table thead tr > :first-child { background: var(--panel-2); }
.al-table tfoot th, .al-table tfoot td {
  background: var(--panel-2); border-top: 1px solid var(--border-strong);
  font-size: var(--text-xs); color: var(--muted);
}
.al-table tfoot tr > :first-child { background: var(--panel-2); }
.al-table tfoot th { font-weight: 700; color: var(--text); }
.al-tally { font-variant-numeric: tabular-nums; }

.al-matrix { min-width: 600px; }
.al-matrix th:first-child, .al-matrix td:first-child { width: 30%; }
.al-mix { min-width: 560px; }
.al-sectors { min-width: 480px; }
.al-bands { min-width: 560px; }
.al-claims { min-width: 520px; }

/* Row head: adviser, date + note, basis, superseded / expired */
.al-rowhead { min-width: 170px; max-width: 280px; font-weight: 500; }
.al-rowhead > * + * { margin-top: 2px; }
.al-adv { font-weight: 700; color: var(--text); overflow-wrap: anywhere; }
a.al-adv:hover { color: var(--accent-text); text-decoration: underline; text-underline-offset: 2px; }
.al-rowhead .al-port { display: block; font-weight: 700; font-size: var(--text-xs); color: var(--muted); overflow-wrap: anywhere; }
.al-rowhead .al-note, .al-rowhead .al-basis { display: block; overflow-wrap: anywhere; }
.al-rowhead .al-basis { font-style: italic; }
.al-rowhead .due-chip, .al-rowhead .al-tag { margin-top: var(--s1); }
.al-tag {
  display: inline-flex; width: max-content; padding: 1px 7px; border-radius: 999px;
  border: 1px dashed var(--border-strong); color: var(--muted);
  font: 700 var(--text-2xs)/1.5 var(--font-body); letter-spacing: 0.02em; cursor: help;
}
.al-sector { font-weight: 700; overflow-wrap: anywhere; }

/* Cells */
.al-cell { min-width: 110px; }
.al-cell.none { color: var(--faint); }
.al-link {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--s2);
  margin: calc(-1 * var(--s1)); padding: var(--s1); border-radius: var(--r-sm);
  color: var(--text);
}
a.al-link:hover { background: var(--panel-2); }
a.al-link:hover .al-w { text-decoration: underline; text-underline-offset: 2px; }
.al-w { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.al-w.muted { font-weight: 500; color: var(--muted); }
.al-scope, .al-was { flex-basis: 100%; font-size: var(--text-xs); color: var(--muted); }
.al-was { font-style: italic; }
.al-due { flex-basis: 100%; }
/* one view across two / three columns: a box as wide as the span */
.al-cell.merged .al-link {
  margin: calc(-1 * var(--s1)) 0; padding: var(--s1) var(--s2);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.al-cell.merged .al-scope { font-weight: 700; }
.al-pill.off {
  background: transparent; color: var(--faint);
  border: 1px dashed var(--border-strong); padding: 3px 8px;
}

/* No longer counted (expired / invalidated) and superseded rows */
.al-row.inactive .al-adv, .al-row.inactive .al-w, .al-row.inactive .al-sector,
.al-cell.inactive .al-w { color: var(--muted); }
.al-row.inactive .al-w, .al-cell.inactive .al-w { text-decoration: line-through; text-decoration-color: var(--border-strong); }
.al-row.superseded > *, .al-table tr.superseded > :first-child { background: var(--panel-2); }
.al-row.superseded .al-adv { color: var(--muted); }
.al-matrix tbody tr.superseded:first-of-type > *, .al-mix tbody tr.superseded > * { border-top-color: var(--border); }

.al-extra td { border-top: 0; padding-top: 0; font-size: var(--text-xs); position: static; box-shadow: none; }
.al-extra .al-extra-item { display: inline-flex; margin: 0 var(--s3) 0 var(--s2); vertical-align: top; }
.al-extra .al-link { display: inline-flex; }

/* Bands */
.al-band + .al-band { margin-top: var(--s5); }
.al-band h3 {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s2);
  font-size: var(--text-base); margin-bottom: var(--s2);
}
.al-band h3 .meta { font-family: var(--font-body); font-weight: 500; letter-spacing: 0; }
.al-band.superseded h3 .al-adv { color: var(--muted); }
.al-interp { min-width: 240px; }
td.al-interp { color: var(--muted); font-size: var(--text-xs); line-height: 1.5; }
td.al-interp q { quotes: "“" "”"; overflow-wrap: anywhere; }

/* Lean from claims */
.al-counts { font-variant-numeric: tabular-nums; white-space: normal; }
.al-counts .al-off { display: block; margin-top: 2px; }
.al-note-link {
  display: inline-block; max-width: 260px; margin: 0 var(--s1) var(--s1) 0;
  padding: 2px 8px; border-radius: var(--r-md); border: 1px solid var(--border);
  font-size: var(--text-xs); color: var(--text); overflow-wrap: anywhere;
}
.al-note-link.bull { border-left: 3px solid var(--accent); }
.al-note-link.bear { border-left: 3px solid var(--red); }
.al-note-link.mixed { border-left: 3px solid var(--amber); }
a.al-note-link:hover { background: var(--panel-2); border-color: var(--border-strong); }

/* Footnotes */
.al-foot { margin-top: var(--s3); line-height: 1.5; }
.al-how { display: flex; gap: var(--s2); align-items: flex-start; margin-top: var(--s4); max-width: 90ch; line-height: 1.5; }
.al-how .icon { flex: none; margin-top: 1px; color: var(--faint); }

/* ---------- Phones ---------- */
@media (max-width: 760px) {
  .al-card { padding: var(--s4) var(--s3); }
  .al-head h2 { font-size: var(--text-base); }
  .al-tab { padding: var(--s3) var(--s3); }
  .al-table { font-size: var(--text-xs); }
  .al-table th, .al-table td { padding: var(--s2); }

  /* Stacked cards: each row = its head across the top, then its cells in
     a grid, each labelled with its column (data-label) -- no sideways
     scrolling. Every cell link also names its row + column for screen
     readers (visually-hidden context in cell_body). */
  .al-scroll { border: 0; background: transparent; overflow: visible; }
  .al-stack, .al-stack tbody, .al-stack tfoot { display: block; min-width: 0; width: 100%; }
  .al-stack thead { display: none; }
  .al-stack tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    border: 1px solid var(--border); border-radius: var(--r-md);
    background: var(--panel); margin-bottom: var(--s2); overflow: hidden;
  }
  .al-stack tr > * { border-top: 0; min-width: 0; max-width: none; width: auto; }
  .al-stack tr > :first-child {
    grid-column: 1 / -1; position: static; box-shadow: none;
    background: var(--panel-2); border-bottom: 1px solid var(--border);
  }
  .al-stack td { padding: var(--s2) var(--s3); }
  .al-stack td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 3px;
    font: 700 var(--text-2xs)/1.3 var(--font-body); letter-spacing: 0.05em;
    text-transform: uppercase; color: var(--faint);
  }
  .al-stack td.none { display: none; }
  .al-stack .al-cell { min-width: 0; }
  .al-stack tr.superseded > * { background: var(--panel-2); }
  .al-stack tfoot tr { background: var(--panel-2); }

  /* Market cap keeps its three columns (Large | Mid | Small) in place. */
  .al-matrix tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .al-matrix th:first-child, .al-matrix td:first-child { width: auto; }
  .al-stack .al-cell.merged .al-scope { display: none; }   /* the cell label says it */
  .al-stack .al-cell .due-chip { white-space: normal; width: auto; }
  .al-matrix td.none { display: block; }
  .al-matrix td.span-2 { grid-column: span 2; }
  .al-matrix td.span-3 { grid-column: 1 / -1; }
  .al-matrix tr.al-extra { margin-top: calc(-1 * var(--s2)); border-top: 0; border-radius: 0 0 var(--r-md) var(--r-md); }
  .al-matrix tr.al-extra > :first-child { background: var(--panel); border-bottom: 0; }
  .al-stack .al-interp, .al-stack .al-notes { grid-column: 1 / -1; min-width: 0; }
  .al-stack .al-sum { grid-column: 1 / -1; background: var(--panel-2); border-top: 1px solid var(--border); }
  .al-note-link { max-width: 100%; }
}
@media (max-width: 430px) {
  .al-tab-long { display: none; }
}
@media print {
  .al-tabs { display: none; }
  .al-scroll { overflow: visible; border: 0; }
  .al-table tr > :first-child { position: static; box-shadow: none; }
}
