/*
 * page.css: the chrome every page shares (modules/DASHBOARD#header, modules/DASHBOARD#account-pages): the page
 * column, the top bar with the app icon, wordmark and kicker, buttons, tags and pills, the theme button, the user
 * menu, menus, the anchored callout, the two rings (modules/DASHBOARD#rings), the venue wordmarks and the base-asset
 * badge (modules/DASHBOARD#venue-identity), and the notification stack (modules/DASHBOARD#notifications). State is a
 * class or a `data-*` attribute toggled by the views, geometry a per-element custom property; nothing is styled
 * inline (CODING_STYLE#frontend, modules/SECURITY#origin).
 */

/* ==== 1. Page ==== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  padding: var(--gap) var(--gutter) 40px;
  overflow-x: hidden;
}

h1,
h2,
h3,
p {
  margin: 0;
}

[hidden] {
  display: none !important;
}

.page {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.dim {
  color: var(--text-dim);
}

.faint {
  color: var(--text-faint);
}

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

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

/* The load error of a signed-in page, shown in the header when `GET /api/me` fails: every page that has one. */
.load-error {
  color: var(--red-ink);
  font-size: 12px;
}

.load-error:empty {
  display: none;
}

.spacer {
  flex: 1;
}

/* a value over its unit, as `63.5%` over `used` or `%` over `√y` */
.stacked {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
}

.unit {
  font-size: 0.62em;
  margin-left: 2px;
}

.unit-stacked {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
  font-size: 7px;
  margin-left: 3px;
  vertical-align: middle;
}

.unit-stacked > span:first-child {
  border-bottom: 1px solid currentColor;
  padding: 0 1px;
}

/* ==== 2. Top bar ==== */

.top-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px var(--gutter);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  /* REQUIREMENT (modules/DASHBOARD#header): left to right, one row; the names shrink before the row wraps. */
  flex-wrap: wrap;
  position: relative;
  z-index: var(--z-menu);
}

/* A name the row cannot hold ends in an ellipsis, titled whole: the portfolio's and the operator's. Each menu's basis
   is the name's floor, so the row breaks only when the floors do not fit; within a row it grows to its content, taking
   the free space before the spacer does (its growth outweighs the spacer's a hundredfold). */
.top-bar > .menu-anchor {
  flex: 100 1 var(--header-name-floor);
  min-width: 0;
  max-width: max-content;
}

.switcher-button,
.user-button {
  max-width: 100%;
  min-width: 0;
}

.switcher-name,
.user-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* REQUIREMENT (modules/DASHBOARD#overview, modules/DASHBOARD#header): under 1280 px the header's gaps narrow, so its one
   row holds down to about 1024 px. */
@media (max-width: 1279px) {
  .top-bar {
    gap: 10px;
  }

  .brand {
    gap: 6px;
  }

  .wordmark {
    letter-spacing: 0.04em;
  }
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.app-icon {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-icon);
  background: linear-gradient(135deg, var(--violet), var(--accent));
  display: inline-grid;
  place-items: center;
  color: var(--on-accent);
  font: 700 11px/1 var(--mono);
  flex: none;
}

.wordmark {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  white-space: nowrap;
}

.kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}

/* ==== 3. Panels ==== */

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.panel-bar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 8px var(--gap);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.panel-bar h2 {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

/* ==== 4. Buttons ==== */

.button {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  color: var(--text);
  padding: 4px 11px;
  cursor: pointer;
  font: inherit;
  line-height: 1.1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

.button:hover:not(:disabled) {
  background: var(--bg-lift);
}

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

.button:disabled {
  opacity: 0.45;
  cursor: default;
}

.button.ink {
  background: var(--pop-border);
  border-color: var(--pop-border);
  color: var(--on-accent);
}

.button.ink:hover:not(:disabled) {
  filter: brightness(1.3);
}

.button.quiet {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

.button.quiet:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.button.wide {
  width: 100%;
  padding: 8px 12px;
  font-weight: 600;
}

.button.small {
  padding: 2px 7px;
  font-size: 11px;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--bg-inset);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}

.icon-button:hover:not(:disabled),
.icon-button[aria-expanded="true"] {
  color: var(--text);
  background: var(--bg-lift);
}

.icon-button:disabled {
  opacity: 0.35;
  cursor: default;
}

.icon-button svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==== 5. Tags and pills ==== */

.tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 5px;
  border-radius: var(--radius-tag);
  text-transform: uppercase;
  white-space: nowrap;
}

.tag.error {
  background: var(--red-dim);
  color: var(--red-ink);
}

.tag.paper {
  background: var(--amber-dim);
  color: var(--amber-ink);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 5px;
  border-radius: var(--radius-tag);
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1.2;
}

.pill.live {
  background: var(--green-dim);
  color: var(--green-ink);
}

.pill.paper {
  background: var(--amber-dim);
  color: var(--amber-ink);
}

.pill.fingerprint {
  background: var(--gray-dim);
  color: var(--text);
  font-family: var(--mono);
  letter-spacing: 0.02em;
  text-transform: none;
  font-size: 9.5px;
}

.pill.restricted {
  background: var(--green-dim);
  color: var(--green-ink);
  text-transform: none;
  letter-spacing: 0.02em;
}

.pill.expires {
  background: var(--amber-dim);
  color: var(--amber-ink);
  text-transform: none;
  letter-spacing: 0.02em;
}

/* ==== 6. Theme button ==== */

.theme-button {
  height: 26px;
  padding: 4px 8px;
}

.theme-button svg {
  width: 13px;
  height: 13px;
  display: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-button[data-mode="system"] .glyph-system,
.theme-button[data-mode="light"] .glyph-light,
.theme-button[data-mode="dark"] .glyph-dark {
  display: block;
}

/* ==== 7. Menus and the user menu ==== */

.menu-anchor {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 160px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: var(--z-menu);
  display: flex;
  flex-direction: column;
  text-align: left;
}

.menu.upward {
  top: auto;
  bottom: calc(100% + 6px);
}

.menu.leftward {
  right: auto;
  left: 0;
}

.menu-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 0;
  border-radius: var(--radius-control);
  padding: 5px 8px;
  cursor: pointer;
  font: 600 10.5px/1.45 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
  text-decoration: none;
}

.menu-item:hover:not(:disabled) {
  background: var(--bg-hover);
}

.menu-item:disabled {
  color: var(--text-faint);
  cursor: default;
}

.menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.menu-item.danger {
  color: var(--red-ink);
}

.menu-separator {
  height: 1px;
  background: var(--border);
  margin: 4px 2px;
}

.menu-caption {
  padding: 5px 8px;
  font: 600 10.5px/1.45 var(--sans);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  white-space: nowrap;
}

.user-button {
  font: 500 12px/1.2 var(--mono);
  color: var(--text);
  padding: 3px 8px 3px 4px;
}

.avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-lift);
  color: var(--text);
  display: inline-grid;
  place-items: center;
  font: 700 9px/1 var(--sans);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.passkey-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0;
}

.passkey-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font: 400 10.5px/1.35 var(--mono);
  color: var(--text-dim);
  white-space: nowrap;
}

.passkey-row .passkey-times {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.passkey-remove {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font: 400 12px/1 var(--sans);
  width: 18px;
  height: 18px;
  border-radius: var(--radius-control);
  padding: 0;
}

.passkey-remove:hover:not(:disabled) {
  color: var(--red-ink);
  background: var(--bg-hover);
}

.passkey-remove:disabled {
  visibility: hidden;
}

/* ==== 8. Anchored callout ==== */

.callout {
  position: absolute;
  z-index: var(--z-callout);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: max-content;
  max-width: 320px;
  padding: 8px 10px 9px;
  background: var(--bg-panel);
  border: 1px solid var(--pop-border);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow);
  font-size: 11.5px;
  left: var(--callout-left, 0);
  top: var(--callout-top, 0);
}

.callout.wide {
  max-width: none;
}

/* a hollow arrow: a rotated square showing two of its edges, so both sides share one 1 px line */
.callout::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--bg-panel);
  left: calc(var(--callout-arrow, 28px) - 5px);
  bottom: -6px;
  border-right: 1px solid var(--pop-border);
  border-bottom: 1px solid var(--pop-border);
  transform: rotate(45deg);
}

.callout.below::after {
  bottom: auto;
  top: -6px;
  border-right: 0;
  border-bottom: 0;
  border-left: 1px solid var(--pop-border);
  border-top: 1px solid var(--pop-border);
}

.callout-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
}

.callout-actions .button {
  font-size: 11px;
  padding: 3px 10px;
}

.callout-message {
  color: var(--text-dim);
  line-height: 1.4;
}

.callout-message b {
  color: var(--text);
}

.callout-error {
  color: var(--red-ink);
  font-size: 11px;
}

/* ==== 9. Rings (modules/DASHBOARD#rings) ==== */

.ring {
  width: 15px;
  height: 15px;
  display: block;
  flex: none;
}

.ring-track {
  fill: none;
  stroke: var(--bg-inset);
  stroke-width: 2.6;
}

.ring-arc {
  fill: none;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-dasharray: var(--ring-arc, 0) var(--ring-circumference, 47.1);
  stroke: var(--gray);
}

.ring[data-color="green"] .ring-arc {
  stroke: var(--green);
}

.ring[data-color="amber"] .ring-arc {
  stroke: var(--amber);
}

.ring[data-color="red"] .ring-arc {
  stroke: var(--red);
}

.ring[data-color="gray"] .ring-arc {
  stroke: var(--gray);
}

/* ==== 10. Venue identity (modules/DASHBOARD#venue-identity) ==== */

/* REQUIREMENT (modules/DASHBOARD#venue-identity): one word, as the mock sets it: the Bybit bar joins its letters. */
.venue-wordmark {
  display: inline-flex;
  align-items: center;
  font: 800 13px/1 var(--sans);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
}

.venue-wordmark.small {
  font-size: 11px;
}

.venue-wordmark .bybit-bar {
  display: inline-block;
  width: 0.2em;
  height: 0.78em;
  margin: 0 0.12em;
  background: var(--brand-bybit);
  border-radius: var(--radius-hair);
}

.venue-wordmark .binance-glyph {
  width: 1em;
  height: 1em;
  margin-right: 0.3em;
  fill: var(--brand-binance);
  flex: none;
}

.asset-badge {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  background: var(--badge-tint, var(--brand-asset-neutral));
  color: var(--brand-asset-ink);
  font: 700 9px/1 var(--sans);
  flex: none;
}

.underlying-pair {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.underlying-pair.small {
  font-size: 12px;
}

.state-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gray);
  flex: none;
}

.state-dot[data-state="live"] {
  background: var(--green);
}

.state-dot[data-state="stale"],
.state-dot[data-state="reconnecting"],
.state-dot[data-state="offline"] {
  background: var(--red);
}

/* ==== 11. Notifications (modules/DASHBOARD#notifications) ==== */

.notifications {
  position: fixed;
  top: var(--gap);
  right: var(--gutter);
  z-index: var(--z-notifications);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 340px;
  max-width: calc(100vw - 2 * var(--gutter));
  pointer-events: none;
}

.notification {
  pointer-events: auto;
  display: grid;
  grid-template-columns: 3px 1fr auto;
  column-gap: 10px;
  align-items: start;
  background: var(--bg-panel);
  border: 1px solid var(--pop-border);
  border-radius: var(--radius-small);
  box-shadow: var(--shadow);
  padding: 8px 8px 8px 0;
  font-size: 12px;
  overflow: hidden;
}

.notification-bar {
  align-self: stretch;
  background: var(--gray);
  border-radius: 0 var(--radius-tag) var(--radius-tag) 0;
}

.notification[data-level="green"] .notification-bar {
  background: var(--green);
}

.notification[data-level="amber"] .notification-bar {
  background: var(--amber);
}

.notification[data-level="red"] .notification-bar {
  background: var(--red);
}

.notification[data-level="gray"] .notification-bar {
  background: var(--gray);
}

.notification-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.notification-time {
  font: 400 10px/1.2 var(--mono);
  color: var(--text-faint);
}

.notification-close {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font: 400 13px/1 var(--sans);
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: var(--radius-control);
}

.notification-close:hover {
  color: var(--text);
  background: var(--bg-hover);
}

@media (prefers-reduced-motion: no-preference) {
  .notification {
    animation: notification-enter 0.14s ease-out;
  }
}

@keyframes notification-enter {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
