/**
 * Shared Textile dataroom chrome — FX dark theme kinship.
 *
 * Surfaces mirror Settlement v3 dark tokens (web/src/index.css
 * [data-tx-theme][data-theme='dark']): page → inset → raised.
 * Accent pink marks active nav; info blue stays for links/charts.
 */

:root {
  --bg: #22242a;
  --panel: #2a2d34;
  --panel-raised: #33363e;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.22);
  --muted: rgba(255, 255, 255, 0.65);
  --muted-soft: rgba(255, 255, 255, 0.45);
  --text: #f5f4ed;
  --accent: #85b7eb;
  --accent-brand: #f472b6;
  --accent-brand-tint: color-mix(in srgb, #f472b6 16%, transparent);
  --good: #97c459;
  --bad: #f87171;
  --amb: #ef9f27;
  --inset: #1a1c21;
  /* Shared content column — chrome, page titles, and .wrap all share this. */
  --dr-max: 1100px;
  --dr-pad-x: 24px;
  /* Closed nav height: 12px shell pad + 48px pill (36px burger + 6px*2).
     The drawer overlays, so this must not include the open menu. */
  --dr-shell-space: 60px;

  /* Aliases used by older page-local stylesheets */
  --card: var(--panel);
  --txt: var(--text);
  --mut: var(--muted);
  --grn: var(--good);
  --red: var(--bad);
  --blu: var(--accent);
  --panel2: var(--panel-raised);
  --txt2: var(--muted);
  --txt3: var(--muted-soft);
  --green: var(--good);
  --yellow: var(--amb);
  --blue: var(--accent);
}

html {
  background: var(--bg);
  overflow-x: clip;
  max-width: 100vw;
}

body {
  margin: 0;
  background:
    radial-gradient(1200px 480px at 12% -10%, rgba(244, 114, 182, 0.08), transparent 55%),
    radial-gradient(900px 420px at 88% 0%, rgba(133, 183, 235, 0.07), transparent 50%),
    var(--bg);
  color: var(--text);
  overflow-x: clip;
  max-width: 100vw;
}

body.dr-menu-lock {
  overflow: hidden;
}

/* ── Fixed shell (desktop + mobile top brand bar) ───────────────
   Chrome mobile treats `position: sticky` as `fixed` when html/body
   use overflow-x: clip (needed so the hamburger can't escape the pill).
   The page toolbar — stitch picker, titles — then sits at y=0 under the
   nav and disappears. Pin the chrome for real and reserve its height
   with html.dr-has-shell so every browser keeps that toolbar in flow. */

.dr-shell {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  z-index: 40;
  padding: 12px var(--dr-pad-x) 0;
  box-sizing: border-box;
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--bg) 92%, transparent) 0%,
    color-mix(in srgb, var(--bg) 78%, transparent) 70%,
    transparent 100%
  );
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

html.dr-has-shell body {
  padding-top: var(--dr-shell-space);
}

html.dr-embed {
  --dr-shell-space: 0px;
}

.dr-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: var(--dr-max);
  min-width: 0;
  margin: 0 auto;
  padding: 6px 8px 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  box-sizing: border-box;
}

/* Match SettlementHeader brand: 20×20 favicon + 14px semibold "Textile". */
.dr-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font: 600 14px/1.2 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: -0.025em;
  flex-shrink: 0;
  padding: 4px 8px 4px 0;
}

.dr-brand:hover {
  opacity: 0.8;
}

.dr-brand img {
  width: 20px;
  height: 20px;
  display: block;
  flex-shrink: 0;
}

.dr-nav {
  display: none;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  font: 500 13px/1 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.dr-nav::-webkit-scrollbar {
  display: none;
}

@media (min-width: 768px) {
  .dr-nav {
    display: inline-flex;
    justify-content: center;
  }
}

.dr-nav a {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.dr-nav a:hover {
  color: var(--text);
}

.dr-nav a[aria-current="page"] {
  color: var(--text);
  background: var(--panel-raised);
  border-color: var(--line);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-brand) 18%, transparent);
}

/* Trailing cluster — status may shrink/ellipsis; the hamburger never leaves
   the pill (body overflow-x:clip used to hide it when this cluster refused
   to shrink). */
.dr-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 1;
  min-width: 0;
  max-width: 100%;
}

.dr-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dr-right #status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

@media (max-width: 767px) {
  .dr-right {
    max-width: min(46vw, 11.5rem);
  }
}

.dr-right:empty {
  display: none;
}

/* Mobile hamburger — hidden on desktop where the inline pill nav shows */
.dr-burger {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-raised);
  color: var(--text);
  cursor: pointer;
  padding: 0;
}

.dr-burger:hover {
  border-color: var(--line-strong);
}

.dr-burger-lines,
.dr-burger-lines::before,
.dr-burger-lines::after {
  display: block;
  width: 14px;
  height: 1.5px;
  border-radius: 1px;
  background: currentColor;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.dr-burger-lines {
  position: relative;
}

.dr-burger-lines::before,
.dr-burger-lines::after {
  content: "";
  position: absolute;
  left: 0;
}

.dr-burger-lines::before {
  top: -5px;
}

.dr-burger-lines::after {
  top: 5px;
}

.dr-menu-open .dr-burger-lines {
  background: transparent;
}

.dr-menu-open .dr-burger-lines::before {
  top: 0;
  transform: rotate(45deg);
}

.dr-menu-open .dr-burger-lines::after {
  top: 0;
  transform: rotate(-45deg);
}

.dr-menu {
  display: none;
  max-width: var(--dr-max);
  margin: 8px auto 0;
  padding: 8px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
  font: 500 14px/1.2 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Short / landscape phones lock body scroll while the menu is open — keep
     the drawer itself scrollable so every link stays reachable. */
  max-height: min(70vh, calc(100dvh - 96px));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.dr-menu:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dr-menu a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
}

.dr-menu a:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--panel-raised) 70%, transparent);
}

.dr-menu a[aria-current="page"] {
  color: var(--text);
  background: var(--panel-raised);
  border-color: var(--line);
  box-shadow: inset 0 0 0 1px var(--accent-brand-tint);
}

@media (min-width: 768px) {
  .dr-burger,
  .dr-menu {
    display: none !important;
  }
}

/* ── Page toolbar + content column (same width as cards) ─────────── */

body > header:not(.dr-shell),
.wrap {
  max-width: var(--dr-max);
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--dr-pad-x);
  padding-right: var(--dr-pad-x);
  box-sizing: border-box;
}

body > header:not(.dr-shell) {
  display: flex;
  align-items: baseline;
  gap: 12px 16px;
  flex-wrap: wrap;
  padding-top: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

body > header:not(.dr-shell) h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.2px;
}

body > header:not(.dr-shell) .sub {
  color: var(--muted);
  font-size: 12px;
}

body > header:not(.dr-shell) .right {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 12px;
}

body > header:not(.dr-shell) .right:empty {
  display: none;
}

.wrap {
  padding-top: 20px;
  padding-bottom: 20px;
}

/* Hide the old dashboard <select> once the persistent nav is mounted */
#viewSel,
.dr-legacy-select {
  display: none !important;
}

/* Network / asset dropdown filters on the fillers-network dashboard. */
.filter-bar {
  position: relative;
  margin-bottom: 20px;
  scroll-margin-top: 72px;
}

.filter-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.filter-dd {
  position: relative;
}

.filter-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 7px 12px 7px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font: 600 12.5px/1.2 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  touch-action: manipulation;
}

.filter-trigger:hover {
  border-color: var(--line-strong);
}

.filter-dd.open .filter-trigger,
.filter-trigger:focus-visible {
  border-color: var(--line-strong);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-brand-tint);
}

.filter-dd.is-filtered .filter-trigger {
  border-color: color-mix(in srgb, #f472b6 45%, var(--line));
  background: color-mix(in srgb, #f472b6 10%, var(--panel));
}

.filter-trigger-lbl {
  color: var(--muted-soft);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.55px;
}

.filter-trigger-val {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-caret {
  width: 6px;
  height: 6px;
  margin-left: 2px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  flex-shrink: 0;
}

.filter-dd.open .filter-caret {
  transform: rotate(225deg) translateY(-1px);
}

.filter-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 228px;
  max-height: min(360px, 70vh);
  overflow: auto;
  padding: 6px;
  background: var(--panel-raised);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  font: 13px/1.3 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

.filter-sheet-head {
  display: none;
}

@media (min-width: 721px) {
  #assetDd .filter-menu {
    left: auto;
    right: 0;
  }
}

.filter-all,
.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  border-radius: 8px;
}

.filter-menu-sep {
  height: 1px;
  margin: 4px 6px 6px;
  background: var(--line);
}

.filter-item {
  padding: 0 4px 0 8px;
}

.filter-item label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  margin: 0;
  padding: 7px 0;
  cursor: pointer;
}

.filter-all {
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 8px 10px;
  touch-action: manipulation;
}

.filter-all:hover,
.filter-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.filter-all:focus-visible,
.filter-only:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-brand-tint);
}

.filter-all.on {
  color: var(--text);
}

.filter-all.on::after {
  content: "✓";
  margin-left: auto;
  color: var(--accent-brand);
  font-size: 12px;
}

.filter-item-name {
  flex: 1;
  min-width: 0;
}

.filter-item input {
  accent-color: var(--accent-brand);
  margin: 0;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.filter-only {
  opacity: 1;
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font: 600 10px/1 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 8px;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  .filter-only {
    opacity: 0;
  }
  .filter-item:hover .filter-only,
  .filter-item:focus-within .filter-only,
  .filter-only:focus-visible {
    opacity: 1;
  }
}

.filter-only:hover {
  color: var(--text);
  border-color: color-mix(in srgb, #f472b6 40%, var(--line));
  background: color-mix(in srgb, #f472b6 12%, var(--inset));
}

.filter-reset {
  background: none;
  border: 0;
  color: var(--muted);
  font: 600 12.5px/1.2 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  cursor: pointer;
  padding: 7px 10px;
  border-radius: 999px;
  touch-action: manipulation;
}

.filter-reset:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.filter-reset[hidden] {
  display: none !important;
}

body.filter-menu-lock {
  overflow: hidden;
}

@media (max-width: 720px) {
  .filter-toolbar {
    width: 100%;
    gap: 6px;
  }
  .filter-trigger {
    min-height: 44px;
    padding: 10px 14px;
  }
  .filter-reset {
    min-height: 44px;
    padding: 10px 12px;
  }
  /* Static so the menu positions against .filter-bar (full content width)
     instead of the pill — otherwise Assets clips off the right edge. */
  .filter-dd {
    position: static;
  }
  .filter-menu {
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    min-width: 0;
    width: auto;
    max-height: min(60dvh, calc(100dvh - 8rem));
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    border-radius: 14px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    z-index: 45;
  }
  .filter-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: -8px;
    z-index: 1;
    margin: -8px -8px 4px;
    padding: 10px 12px 8px;
    background: var(--panel-raised);
  }
  .filter-sheet-title {
    font-size: 15px;
    font-weight: 650;
    letter-spacing: -0.02em;
  }
  .filter-sheet-done {
    min-height: 36px;
    padding: 6px 14px;
    border: 0;
    border-radius: 999px;
    background: color-mix(in srgb, #f472b6 18%, var(--inset));
    color: var(--text);
    font: 600 13px/1 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    cursor: pointer;
    touch-action: manipulation;
  }
  .filter-all {
    min-height: 44px;
    padding: 12px;
    font-size: 14px;
  }
  .filter-item {
    padding: 0 4px 0 10px;
  }
  .filter-item label {
    min-height: 44px;
    padding: 10px 0;
    font-size: 15px;
  }
  .filter-item input {
    width: 18px;
    height: 18px;
  }
  .filter-only {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 12px;
  }
}

/* Segmented controls / selects — sit on FX dark surfaces */
.sel {
  background: var(--inset);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 12px;
}

.sel:hover {
  border-color: var(--line-strong);
}

.seg {
  background: var(--inset);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.seg button.on {
  background: var(--panel-raised);
  color: var(--text);
}

.card,
.tile,
.panel,
.hero,
.hrail {
  background: var(--panel);
  border-color: var(--line);
}

/* Mobile width containment — KPI grids + wide tables across all pages. */
@media (max-width: 720px) {
  :root {
    --dr-pad-x: 14px;
    --dr-shell-space: 58px; /* 10px shell pad + 48px pill */
  }

  body > header:not(.dr-shell) {
    padding-top: 12px;
    padding-bottom: 8px;
  }

  .dr-shell {
    padding-top: 10px;
  }

  .wrap {
    padding-top: 14px;
    padding-bottom: 14px;
    min-width: 0;
  }

  .kpis,
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .legs {
    grid-template-columns: 1fr;
  }

  .card .val,
  .val {
    font-size: 19px;
    overflow-wrap: anywhere;
  }

  /* Tables scroll inside their section instead of stretching the page. */
  section:has(table),
  .panel:has(table),
  .card:has(table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  table {
    min-width: 0;
  }

  /* Stitches page toolbar: bot picker + pills wrap cleanly. */
  body > header:not(.dr-shell) .sel,
  body > header:not(.dr-shell) .botpill {
    max-width: 100%;
  }

  .hero {
    display: block;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .chart-head .segs {
    flex-wrap: wrap;
  }
}

@media (max-width: 420px) {
  .kpis,
  .grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
