/* Colors are the Anthropic light and dark themes the Streamlit version used
   (.streamlit/config.toml); card fills and layout rules come from its custom CSS. */

:root {
  --logo: url("/salt-logo-light.png");
  --bg: #f4f3ed;
  --bg2: #ecebe3;
  --card: #ecebe3;
  --text: #3d3a2a;
  --muted: rgba(61, 58, 42, 0.68);
  --border: #d3d2ca;
  --primary: #bb5a38;
  --red: #b4462f;
  --green: #2f7a55;
  --orange: #c96442;
  --blue: #4f7ba8;
  --yellow: #b07d19;
  --radius: 12px;
  --btn-radius: 10px;
  --gap: 16px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --logo: url("/salt-logo-dark.png");
  --bg: #2a2a28;
  --bg2: #232220;
  --card: #383733;
  --text: #e5e5e2;
  --muted: rgba(229, 229, 226, 0.62);
  --border: #343330;
  --primary: #ae5630;
  --red: #e0655a;
  --green: #86c08e;
  --orange: #d97757;
  --blue: #86afda;
  --yellow: #d9b45b;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  /* No grey flash over whatever was tapped. */
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}

[hidden] {
  display: none !important;
}

/* Where content may start below the status bar. The iOS home-screen app blurs a soft
   band just under the status bar (the system scroll edge effect), so start below it. */
:root {
  --top-clear: env(safe-area-inset-top);
}

@media (display-mode: standalone) {
  @supports (-webkit-touch-callout: none) {
    :root {
      --top-clear: calc(env(safe-area-inset-top) + 24px);
    }
  }
}

/* One centered column on wide screens; safe-area insets for the iOS home-screen app. */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: max(8px, var(--top-clear)) max(16px, env(safe-area-inset-right))
    calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

h1 {
  font-size: 32px;
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

h3 {
  font-size: 19px;
  font-weight: 600;
  margin: 8px 0 12px;
}

button,
select,
input {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

select,
input[type="date"],
input[type="password"] {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  min-height: 40px;
}

/* A short-valued picker inline with a title: only as wide as the value it shows. */
select.compact {
  field-sizing: content;
  padding-inline: 8px;
}

select:focus-visible,
input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.ms {
  font-family: "Material Symbols Rounded";
  font-weight: normal;
  font-style: normal;
  font-size: 1.2em;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  direction: ltr;
  vertical-align: -0.22em;
  font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
}

.pos {
  color: var(--green);
}

.neg {
  color: var(--red);
}

.muted,
.caption {
  color: var(--muted);
}

.caption {
  font-size: 13px;
  line-height: 1.6;
}

/* Read out, never shown. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ chrome */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  margin-bottom: 12px;
}

/* The schema on screen, beside the sidebar buttons; it opens the schema sheet. */
.schema-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 6px 0 5px;
  border: 1px solid var(--border);
  border-radius: var(--btn-radius);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}

/* The only schema there is: a label, nothing to open. */
.schema-chip:disabled {
  padding-left: 0;
  border-color: transparent;
  cursor: default;
}

.schema-chip strong,
.schema-row strong {
  font-weight: 600;
}

.schema-account {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.schema-caret {
  flex: none;
  color: var(--muted);
}

/* The broker's logo: in the sheet's rows, and in its own box opening the account. */
.broker-icon {
  flex: none;
  width: 20px;
  height: 20px;
}

#account .broker-icon {
  width: 22px;
  height: 22px;
}

/* Right-aligned, past the chip. */
#appearance {
  margin-left: auto;
}

/* Where the schema trades: LIVE solid, as it is real money; PAPER outlined; DEV dashed. */
.env-badge {
  flex: none;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  letter-spacing: 0.04em;
}

.env-live {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.env-paper {
  border-color: color-mix(in srgb, var(--blue) 55%, var(--border));
  color: var(--blue);
}

.env-dev {
  border-style: dashed;
}

/* Its own line under the buttons, so it is never cut short on a phone. */
.status {
  order: 3;
  flex: 1 1 100%;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status .dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.status.warn {
  color: var(--orange);
}

.status.warn .dot {
  background: var(--orange);
}

.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--btn-radius);
  background: transparent;
  cursor: pointer;
}

/* Push subscribed: the bell takes the same green as the live status dot. */
.icon-btn.on {
  border-color: color-mix(in srgb, var(--green) 40%, var(--border));
  background: color-mix(in srgb, var(--green) 15%, transparent);
}

.icon-btn.on .ms {
  color: var(--green);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* The bell's sidebar, slid in from the bell's side over a dimmed page. Closing is its
   own button, the backdrop or Escape, so nothing has to judge what a tap landed on. */
.drawer {
  position: fixed;
  z-index: 40;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(360px, 86vw);
  display: flex;
  flex-direction: column;
  padding: max(12px, var(--top-clear)) 16px calc(12px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  border-right: 1px solid var(--border);
  background: var(--card);
  box-shadow: 8px 0 24px rgba(0, 0, 0, 0.2);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}

.drawer.show {
  transform: none;
}

/* The schema sheet: dropped under the chip on wide screens, up from the bottom on phones. */
.drawer.schema-sheet {
  top: calc(max(8px, var(--top-clear)) + 52px);
  bottom: auto;
  right: auto;
  /* Past the two sidebar buttons, so it drops from the chip. */
  left: calc(max(16px, env(safe-area-inset-left), (100vw - 1400px) / 2 + 16px) + 96px);
  width: 360px;
  max-height: min(70vh, 520px);
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;
}

.drawer.schema-sheet.show {
  opacity: 1;
  transform: none;
}

@media (max-width: 30rem) {
  .drawer.schema-sheet {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 75vh;
    padding: 12px max(16px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    border-width: 1px 0 0;
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.2);
    opacity: 1;
    transform: translateY(100%);
    transition: transform 0.2s ease;
  }
}

/* Each environment's schemas under its badge, the figures' heading opposite. */
.schema-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.schema-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.schema-name {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.schema-mark {
  flex: none;
  color: var(--muted);
}

.schema-row[aria-current="true"] strong,
.schema-row[aria-current="true"] .schema-mark {
  color: var(--primary);
}

.drawer-backdrop {
  position: fixed;
  z-index: 35;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s ease;
  /* A swipe on the dimmed page must not scroll it. */
  touch-action: none;
}

.drawer-backdrop.show {
  opacity: 1;
}

/* The page behind stays put while the sidebar is open. */
html.drawer-open {
  overflow: hidden;
}

/* Head and body, re-rendered together; only the body scrolls. */
.push-menu {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.drawer-actions {
  display: flex;
  gap: 8px;
}

/* Reset and sign out, pinned to the foot whatever the list's length. */
.drawer-foot {
  flex: none;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sign-out {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--btn-radius);
  background: transparent;
  cursor: pointer;
}

/* Reset app and Sign out, side by side. */
.drawer-foot-actions {
  display: flex;
  gap: 8px;
}

.drawer-foot-actions .sign-out {
  flex: 1;
  min-width: 0;
}

/* Over everything while a deploy takes over or the app resets (index.html's boot watchdog). */
.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 16px;
  background: var(--bg);
  text-align: center;
}

.boot-label {
  margin: 0;
  font-size: 17px;
  font-weight: 500;
}

/* As wide as the most dots but taking no room, so the word stays centred as they grow. */
.boot-dots {
  display: inline-block;
  width: 6ch;
  margin-right: -6ch;
  text-align: left;
}

.boot-detail {
  max-width: 320px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.boot-reset {
  width: auto;
  padding: 0 20px;
}

.push-menu-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 40px;
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

/* The master switch, ruled off from the topics it gates. */
.push-master {
  padding-bottom: 4px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.push-section {
  padding: 4px 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Unread count on the bell. */
#push {
  position: relative;
}

.bell-count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--orange);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

/* Lit while the list hides some notification types. */
.icon-btn.filtered {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

.icon-btn.filtered .ms {
  color: var(--primary);
}

/* The type filter, dropped open under the sidebar's header. Double-tap there picks a
   single type, so it must not zoom the page instead. */
.filter-menu {
  flex: none;
  touch-action: manipulation;
  display: flex;
  flex-direction: column;
  padding-bottom: 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.filter-all {
  display: flex;
  gap: 16px;
}

.filter-all button {
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
}

/* Past notifications, scrolled by the sidebar's body. */
.event-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-day {
  position: sticky;
  top: 0;
  padding: 8px 0 4px;
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.event {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.event:last-child {
  border-bottom: 0;
}

.event > .ms {
  flex: none;
  margin-top: 1px;
  color: var(--muted);
}

.event.opened > .ms,
.event.closed > .ms {
  color: var(--green);
}

.event.assignment > .ms,
.event.order_cancelled > .ms {
  color: var(--orange);
}

.event.eod_statement > .ms,
.event.monthly_statement > .ms,
.event.yearly_statement > .ms {
  color: var(--blue);
}

/* The Daily | Monthly switch under the statements' sidebar head. */
.statements-view {
  flex: none;
  padding: 4px 0 8px;
}

/* Every notification opens: a statement itself, anything else its details. */
.event[data-event-id] {
  cursor: pointer;
}

.event > .ms.event-go {
  margin: 0 0 0 auto;
  align-self: center;
}

.event-text {
  min-width: 0;
}

.event-title {
  font-weight: 600;
  font-size: 14px;
}

.event-body {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.event-time {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

/* In the list the time sits right of the type, on the title's baseline; it wraps
   beneath when the two do not fit. */
.event-list .event-text {
  flex: 1;
}

.event-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  column-gap: 8px;
}

.event-head .event-time {
  margin-top: 0;
  white-space: nowrap;
}

.push-empty {
  margin: 12px 0 4px;
  color: var(--muted);
}

/* The statements' sidebar: one button per session. */
.statement-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.statement-list li:last-child .statement-row {
  border-bottom: 0;
}

.statement-row > .ms {
  flex: none;
  margin-top: 1px;
  color: var(--blue);
}

.statement-row .event-text {
  flex: 1;
}

.statement-row .event-title,
.statement-row .event-body {
  display: block;
}

.statement-figures {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* One statement over a dimmed page, above the sidebars. Its X, a tap outside the box or
   Escape closes it; only the box's body scrolls. */
.statement-modal {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, var(--top-clear)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.statement-modal.show {
  opacity: 1;
}

html.modal-open {
  overflow: hidden;
}

.statement-box {
  display: flex;
  flex-direction: column;
  width: min(440px, 100%);
  max-height: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
  transform: translateY(8px);
  transition: transform 0.15s ease;
}

.statement-modal.show .statement-box {
  transform: none;
}

.statement-head {
  flex: none;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 10px 16px;
  border-bottom: 1px solid var(--border);
}

.statement-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.statement-head .caption {
  overflow-wrap: anywhere;
}

.statement-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 8px;
}

.st-section {
  padding: 12px 0 10px;
  border-bottom: 1px solid var(--border);
}

.st-section:last-child {
  border-bottom: 0;
}

.st-section h3 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* One grid per section: label, then a return column where the section has one, then the
   value, so the dollar figures share the right-hand column and both columns line up. */
.st-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.st-grid.has-detail {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.st-row {
  display: contents;
}

/* Spacing as cell padding rather than a column gap, so the totals' rule runs unbroken. */
.st-row > span {
  padding-block: 2px;
}

.st-row > .st-detail,
.st-row > .st-value {
  padding-left: 12px;
}

.st-label {
  overflow-wrap: anywhere;
}

.st-value,
.st-detail {
  text-align: right;
  white-space: nowrap;
}

.st-detail {
  color: var(--muted);
}

/* A spread's details: labels keep one line and the values take the rest, so a long fill
   time wraps at its viewer's-time part instead of squeezing the labels onto two lines. */
/* Without a detail column nothing needs to line up, so each row splits its own width: a
   short label leaves a long time the rest of the line. */
.position-detail .st-grid:not(.has-detail) {
  display: block;
}

.position-detail .st-grid:not(.has-detail) > .st-row {
  display: flex;
}

.position-detail .st-grid:not(.has-detail) .st-label {
  flex: none;
}

/* The value fills the rest, right-aligned, so a total's rule runs unbroken under both. */
.position-detail .st-grid:not(.has-detail) .st-value {
  flex: 1;
  min-width: 0;
}

.position-detail .st-grid.has-detail {
  grid-template-columns: max-content minmax(0, 1fr) auto;
}

.position-detail .st-value {
  white-space: normal;
}

.st-total > span {
  font-weight: 600;
}

/* Totals sit under a dashed rule across the whole row. */
.st-total-first > span {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

.st-empty {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.push-topics {
  display: flex;
  flex-direction: column;
}

.push-note {
  margin: 4px 0 8px;
  font-size: 13px;
  color: var(--orange);
}

/* Not a warning: PAPER and DEV schemas list their notifications but never push them. */
.push-note.live-only {
  margin-top: 12px;
  color: var(--muted);
}

/* A notification's details hand over to the position it is about. */
.st-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-height: 44px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
}

.push-test {
  margin-top: 8px;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
}

.push-test:disabled,
.toggle input:disabled ~ span {
  opacity: 0.5;
  cursor: default;
}

.segmented {
  display: inline-flex;
  flex: none;
  border: 1px solid var(--border);
  border-radius: var(--btn-radius);
  overflow: hidden;
}

.segmented button {
  font-size: 14px;
  background: transparent;
  border: 0;
  border-left: 1px solid var(--border);
  padding: 4px 12px;
  min-height: 34px;
  cursor: pointer;
}

.segmented button:first-child {
  border-left: 0;
}

.segmented button.on {
  color: var(--primary);
  font-weight: 500;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
}

/* Sideways scroll only, for screens too narrow for every tab. Vertical overflow is
   hidden so a swipe that starts on the tabs scrolls the page, and the divider is an
   inset shadow rather than a border the active underline has to overlap, so nothing
   overflows vertically in the first place. */
.tabs {
  display: flex;
  gap: 24px;
  box-shadow: inset 0 -1px 0 var(--border);
  margin: 8px 0 16px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tabs button {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 10px 0;
  min-height: 44px;
  white-space: nowrap;
  cursor: pointer;
  opacity: 0.75;
}

.tabs button[aria-selected="true"] {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 500;
  opacity: 1;
}

/* Market holiday banner: green ahead of a closure, yellow on the day itself, grey for a bond market holiday. */
.banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 16px;
  margin: 4px 0 8px;
  border-radius: 10px;
  border-left: 4px solid var(--tone);
  background: color-mix(in srgb, var(--tone) 15%, transparent);
}

.banner.ok {
  --tone: var(--green);
}

.banner.warn {
  --tone: var(--yellow);
}

.banner.info {
  --tone: var(--muted);
}

.banner .ms {
  color: var(--tone);
}

/* "Data updated": floats at the top of the screen however far down the page is scrolled. */
.toast {
  position: fixed;
  z-index: 20;
  top: calc(var(--top-clear) + 8px);
  left: 50%;
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0;
  align-items: center;
  border: 1px solid color-mix(in srgb, var(--tone) 40%, var(--border));
  background: color-mix(in srgb, var(--tone) 15%, var(--bg));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  font-size: 14px;
  cursor: pointer;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Taps on the whole toast already dismiss it; the X just makes that obvious. */
.toast .toast-close {
  display: inline-flex;
  margin: -6px -8px -6px 2px;
  padding: 6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.toast .toast-close .ms {
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}

.info {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 16px;
  margin-bottom: var(--gap);
  border-radius: 10px;
  background: color-mix(in srgb, var(--blue) 14%, transparent);
}

/* At least a screen tall, so switching to a short tab keeps the tabs bar where it was
   instead of the page shrinking and scrolling up. */
#panel {
  min-height: 100vh;
  min-height: 100dvh;
}

/* ------------------------------------------------------------------- cards */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}

/* KPI rows sit on one line of equal columns until the row is too narrow for readable
   values, then pair up two per row. A container query, so the row's own width decides. */
.kpi-row {
  margin-bottom: var(--gap);
  container-type: inline-size;
}

/* The grid sits inside the row, since a container query cannot restyle the container. */
.kpi-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: var(--gap);
}

.kpi-grid > .card {
  padding: 10px 12px;
}

.metric-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-value {
  margin-top: 2px;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Small counts (two digits at most) as labelled rows of one card, so three of them
   take the height of a money card instead of a row of their own. */
.kpi-grid > .card.tally-stack {
  display: flex;
  flex-direction: column;
  padding-block: 2px;
}

.tally {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 20px;
  font-size: 13px;
  line-height: 1.25;
}

.tally + .tally {
  border-top: 1px solid var(--border);
}

.tally-label {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tally-value {
  min-width: 2ch;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

@container (max-width: 40rem) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: row;
    gap: 10px;
  }

  /* Strike map: the two dollar cards stack on the left, the pills fill the right. */
  .map-kpis .metric {
    grid-column: 1;
  }

  .map-kpis .tally-stack {
    grid-column: 2;
    grid-row: 1 / span 2;
  }

  /* Header: the four money cards pair up, and the counts run side by side beneath them. */
  .kpis .kpi-grid > .card.tally-stack {
    grid-column: 1 / -1;
    flex-direction: row;
    padding-block: 6px;
  }

  /* Each count just after its label, not pushed to the far edge of its cell. */
  .kpis .tally-label {
    flex: none;
  }

  .kpis .tally + .tally {
    border-top: 0;
    border-left: 1px solid var(--border);
    padding-left: 10px;
  }
}

/* Phones: smaller values so six-figure amounts fit a half-width card. */
@container (max-width: 30rem) {
  .kpi-grid > .card {
    padding: 8px 10px;
  }

  .metric-value {
    font-size: 20px;
  }
}

/* History, positions and fees on phones: the stats read as rows of one card, icon and
   label left, value right. The positions counts drop their own card and join the rows. */
@container (max-width: 40rem) {
  :is(.history-kpis, .map-kpis, .fee-kpis) .kpi-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding-block: 2px;
  }

  :is(.history-kpis, .map-kpis, .fee-kpis) .kpi-grid > .card.tally-stack {
    display: contents;
  }

  :is(.history-kpis, .map-kpis, .fee-kpis) :is(.metric, .tally) {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 0;
    border-radius: 0;
    padding: 8px 12px;
  }

  :is(.history-kpis, .map-kpis, .fee-kpis) :is(.metric, .tally) + :is(.metric, .tally),
  :is(.history-kpis, .map-kpis, .fee-kpis) .metric + .tally-stack > .tally:first-child {
    border-top: 1px solid var(--border);
  }

  :is(.history-kpis, .map-kpis, .fee-kpis) :is(.metric-label, .tally-label) {
    flex: 1;
    min-width: 0;
    font-size: 12px;
  }

  :is(.history-kpis, .map-kpis, .fee-kpis) :is(.metric-value, .tally-value) {
    margin-top: 0;
    font-size: 14px;
    text-align: right;
  }
}

/* Header on phones: the money stats stack as rows of one card, a little larger than the
   tabs' stats, with the counts card beneath as before. */
@container (max-width: 40rem) {
  .kpis .kpi-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .kpis .metric {
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 0;
    padding: 10px 14px;
  }

  .kpis .metric + .metric {
    border-top: 0;
  }

  .kpis .metric:first-child {
    border-radius: var(--radius) var(--radius) 0 0;
  }

  /* The last money stat, just before the counts card. */
  .kpis .metric:has(+ .tally-stack),
  .kpis .metric:last-child {
    border-radius: 0 0 var(--radius) var(--radius);
    margin-bottom: 10px;
  }

  .kpis .metric-label {
    flex: 1;
    min-width: 0;
    font-size: 14px;
  }

  .kpis .metric-value {
    margin-top: 0;
    font-size: 18px;
    text-align: right;
  }
}

.label-short {
  display: none;
}

@container (max-width: 40rem) {
  .label-long {
    display: none;
  }

  .label-short {
    display: inline;
  }
}

/* Positions, history and fees on phones: two stats per row, the cells split by 1px lines of the
   border colour showing through the gaps. An odd last stat spans the row. */
@container (max-width: 40rem) {
  :is(.map-kpis, .history-kpis, .fee-kpis) .kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    padding: 0;
    overflow: hidden;
    background: var(--border);
  }

  /* Undo the earlier phone layout that pinned the dollar cards to the left column. */
  :is(.map-kpis, .history-kpis, .fee-kpis) :is(.metric, .tally) {
    grid-column: auto;
    background: var(--card);
  }

  :is(.map-kpis, .history-kpis, .fee-kpis) :is(.metric, .tally) + :is(.metric, .tally),
  :is(.map-kpis, .history-kpis, .fee-kpis) .metric + .tally-stack > .tally:first-child {
    border-top: 0;
  }

  :is(.history-kpis, .fee-kpis) .metric:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

/* Charts keep their height until the card narrows past where it would read as
   stretched, then hold 4:3; the strike map holds a square for its angled dates. */
.chart-card {
  container-type: inline-size;
  margin-bottom: var(--gap);
}

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.chart-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 8px;
}

.chart {
  width: 100%;
  height: min(420px, 75cqw);
}

.chart.map {
  height: min(460px, 100cqw);
}

/* The fee legend lists every fee type and wraps to several rows on a phone, so the
   chart adds a fixed allowance for it on top of a shorter plot rather than a 400px floor. */
.chart.fees {
  height: min(420px, calc(60cqw + 100px));
}

.chart-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}

/* Position cards tile into as many equal columns as fit, matching heights per row. */
/* Cards share one height so rows line up side by side; stacked in a single column
   there is nothing to line up, so each takes its own height. A container query, since
   the grid's own width decides the columns; the wrapper is the container because a
   container query cannot restyle the container itself. */
.positions {
  container-type: inline-size;
}

.position-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  grid-auto-rows: 1fr;
  gap: var(--gap);
}

/* Narrower than two 17rem columns and the 16px gap between them: one column. */
@container (width < 35rem) {
  .position-grid {
    grid-auto-rows: auto;
  }
}

.position {
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

/* A tap opens the spread's details. */
@media (hover: hover) {
  .position:hover {
    border-color: color-mix(in srgb, var(--primary) 45%, var(--border));
  }
}

.position:active {
  transform: scale(0.99);
}

.position:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.position-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 14px;
}

.badge.orange {
  color: var(--orange);
  background: color-mix(in srgb, var(--orange) 16%, transparent);
}

/* A card's partial-fill badges wrap onto a second line rather than overflow it. */
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 24px 0 8px;
}

/* ------------------------------------------------------------------ inputs */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle .track {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--border);
  transition: background 0.15s;
}

.toggle .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg);
  transition: transform 0.15s;
}

.toggle input:checked + .track {
  background: var(--primary);
}

.toggle input:checked + .track::after {
  transform: translateX(16px);
}

.toggle input:focus-visible + .track {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.primary {
  background: var(--primary);
  color: #fff;
  border: 0;
  border-radius: var(--btn-radius);
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 500;
  cursor: pointer;
}

.primary:disabled {
  opacity: 0.6;
}

.table-wrap {
  overflow: auto;
  max-height: 480px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  width: max-content;
  min-width: 100%;
}

th,
td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--bg2);
  font-weight: 500;
}

td.num {
  text-align: right;
}

/* Curated tables (trades, fees by type): no inner box, quiet headers aligned with
   their values, and the container query below for phone widths. */
.tidy {
  container-type: inline-size;
}

.tidy .table-wrap {
  border: none;
  border-radius: 0;
}

.tidy table {
  font-size: 14px;
}

.tidy th,
.tidy td {
  padding: 9px 12px;
}

/* Sticky, so it needs the card's fill. */
.tidy th {
  background: var(--card);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border);
}

.tidy th.num {
  text-align: right;
}

.tidy th.center,
.tidy td.center {
  text-align: center;
}

/* Cells with a short form carry both; fitTable sets .abbreviated to switch every row at once. */
.tidy .abbr-short,
.tidy .abbreviated .abbr-long {
  display: none;
}

.tidy .abbreviated .abbr-short {
  display: inline;
}

.tidy th:first-child,
.tidy td:first-child {
  padding-left: 0;
}

.tidy th:last-child,
.tidy td:last-child {
  padding-right: 0;
}

.tidy tr:last-child td {
  border-bottom: none;
}

/* Phone width: tighter cells, and headers and long text wrap instead of pushing
   the table into a sideways scroll. */
@container (max-width: 30rem) {
  /* Fit the container rather than the content's unwrapped width, so text can wrap. */
  .tidy table {
    width: 100%;
    font-size: 13px;
  }

  .tidy th,
  .tidy td {
    padding: 6px 3px;
  }

  .tidy th {
    font-size: 11px;
    letter-spacing: 0;
  }

  .tidy th,
  .tidy td.wrap {
    white-space: normal;
  }
}

.table-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: var(--gap);
}

/* The card's gap already spaces the title row. */
.table-card .chart-head {
  margin-bottom: 0;
}

/* Phones: every pixel of card padding is a pixel of table. */
@media (max-width: 30rem) {
  .table-card {
    padding: 12px 10px;
  }
}

/* Only a handful of rows, so no scroll cap. */
.fee-summary .table-wrap {
  max-height: none;
}

/* Fixed shares: fee type 40%, the five amounts 12% each, so the amounts sit on an even
   grid rather than spacing out by content width, which reads as gaps where columns are missing. */
.fee-summary th:first-child,
.fee-summary td:first-child {
  width: 40%;
}

.fee-summary th.num,
.fee-summary td.num {
  width: 12%;
}

/* Phones: the amounts shrink to their content plus a gutter, and fee type takes the rest. */
@container (max-width: 30rem) {
  .fee-summary th:first-child,
  .fee-summary td:first-child {
    width: auto;
  }

  .fee-summary th.num,
  .fee-summary td.num {
    width: 1px;
    padding-left: 14px;
  }
}

.fee-summary tr.total td {
  font-weight: 600;
}

/* A rule between the fee types and the first total row, in the muted text colour since
   the border colour barely shows on the dark card. */
.fee-summary tr:not(.total) + tr.total td {
  border-top: 2px solid var(--muted);
}

/* ------------------------------------------------------------------- login */

.login {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
  margin: 15vh auto 0;
  padding: 24px;
  text-align: center;
}

.login-logo {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 2000 / 784;
  margin: 0 auto 12px;
  background: var(--logo) center / contain no-repeat;
}

.login h1 {
  font-size: 24px;
  margin-bottom: 8px;
}

.login-note {
  margin: 0 0 8px;
  color: var(--muted);
}

.login a.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}

.error {
  color: var(--red);
  margin: 0;
}

/* Touch devices: iOS zooms on inputs under 16px, and chips grow to 44px targets. */
@media (pointer: coarse) {
  select,
  input {
    font-size: 16px;
  }

  .segmented button {
    min-height: 44px;
    padding-inline: 0.9rem;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .schema-chip {
    height: 44px;
  }
}

/* Narrow chart cards (small phones): slimmer range chips, so all six stay on one row. */
@container (max-width: 24rem) {
  .chart-head .segmented button {
    padding-inline: 0.55rem;
  }
}

@container (max-width: 20rem) {
  .chart-head .segmented button {
    padding-inline: 0.45rem;
    font-size: 13px;
  }
}
