/* Base layout: sticky header, primary nav (top on desktop, bottom tab bar on mobile). */

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Ambience ----------
   Two fixed, non-interactive layers behind the whole app. They sit on the page,
   never on a card: every panel paints an opaque --surface over the top, so nothing
   here can touch the contrast of anything you have to read.

   ::before  a red bloom bleeding down from the masthead, over graph-paper ruling.
   ::after   film grain, which is what stops the bloom from banding on a wide
             gradient and what keeps the flat near-black from looking like a void. */

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  z-index: -2;
  background:
    /* the bloom: hot near the header, gone by a third of the way down */
    radial-gradient(70% 42% at 50% -6%, var(--glow-a), transparent 70%),
    radial-gradient(46% 34% at 88% 4%, var(--glow-b), transparent 72%),
    radial-gradient(40% 30% at 6% 10%, var(--glow-b), transparent 74%),
    /* graph paper, fading out as it falls so the lower page stays quiet */
    linear-gradient(var(--rule) 1px, transparent 1px) 0 0 / 100% var(--rule-gap),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px) 0 0 / var(--rule-gap) 100%;
  -webkit-mask-image: linear-gradient(#000 0 46vh, rgba(0, 0, 0, 0.35) 88vh, transparent);
          mask-image: linear-gradient(#000 0 46vh, rgba(0, 0, 0, 0.35) 88vh, transparent);
}

/* Grain is generated rather than fetched — a tiled 140px turbulence patch. */
body::after {
  z-index: -1;
  opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

/* Forced-colours users get the tokens' flat surfaces and none of this. */
@media (forced-colors: active) {
  body::before, body::after { display: none; }
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Shared content column. Everything a reader scans — the nav row and the main
   view — sits in one of these, so they line up at the same width down the page.
   (max-w-6xl + mx-auto + px-5 in Tailwind terms.) The full-bleed appbar keeps its
   own edge-to-edge background; only its *contents* are capped by this. */
.container {
  max-width: 1152px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
}

/* ---------- Top bar ---------- */

/* Sticky header wrapper: nav row on top, search row beneath. */
/* Translucent, so the bloom behind it reads through the masthead rather than being
   clipped by it. The blur is what keeps the nav legible over scrolling content. */
.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 64px; /* exact sticky-header height (border-box: includes the 1px rule) */
  background: color-mix(in srgb, var(--surface) var(--appbar-tint), transparent);
  backdrop-filter: blur(14px) saturate(150%);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
  border-bottom: 1px solid var(--hairline);
}
/* No blur support (or no color-mix) → an opaque bar, exactly as before. */
@supports not (backdrop-filter: blur(1px)) {
  .appbar { background: var(--surface); }
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* brand · nav (centered) · actions */
  align-items: center;
  gap: 16px;
  height: 100%; /* fills the 64px bar; align-items:center centres the content */
  padding: 0 20px; /* full-bleed nav row — not capped to the content column */
}

.brand {
  grid-column: 1;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 23px;
  letter-spacing: -0.02em;
}
/* The logo is a rounded-square app icon, like the profile photo — object-fit
   keeps it undistorted whatever the source PNG's aspect ratio is. */
.brand-mark { flex-shrink: 0; border-radius: 8px; object-fit: cover; }
.brand-name em { font-style: normal; color: var(--accent); }

/* "Live" indicator — a red glowing, pulsing dot signalling the data is current.
   Pinned to the second row's right edge, sitting under the bell/star/account icons. */
.brand-live {
  position: absolute;
  right: 20px; /* matches the topbar padding, so it lines up under the icons */
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1;
  color: var(--sell);
}
.brand-live-label { text-shadow: 0 0 12px rgba(255, 45, 45, 0.6); }
.brand-live-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ff8a8a, #ff2d2d 65%);
  animation: live-pulse 1.5s ease-in-out infinite;
}
@keyframes live-pulse {
  0% {
    box-shadow: 0 0 10px 3px rgba(255, 45, 45, 0.75), 0 0 0 0 rgba(255, 45, 45, 0.7);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 24px 8px rgba(255, 45, 45, 1), 0 0 0 12px rgba(255, 45, 45, 0);
    transform: scale(1.18);
  }
  100% {
    box-shadow: 0 0 10px 3px rgba(255, 45, 45, 0.75), 0 0 0 0 rgba(255, 45, 45, 0);
    transform: scale(1);
  }
}
@media (prefers-reduced-motion: reduce) {
  .brand-live-dot { animation: none; box-shadow: 0 0 16px 5px rgba(255, 45, 45, 0.9); }
}

.topbar-actions {
  grid-column: 3;
  justify-self: end;
  position: relative; /* anchors the notif + account dropdowns right under the icons */
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Second header row — once the global search, latterly just the LIVE badge.
   Hidden, not deleted: it still anchors #global-search and #search-results, which
   app.js binds at module scope and would throw on boot without. */
.searchrow {
  display: none;
  position: relative;
  justify-content: center;
  padding: 0 20px 10px;
  min-height: 37px;
}

/* Hidden, not deleted: app.js binds #global-search and #search-results at module
   scope and would throw on boot without them. Every view keeps its own search or
   filter field, so nothing here is made unreachable. */
.search {
  display: none;
  position: relative;
  width: 100%;
  max-width: 520px;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-muted);
  pointer-events: none;
}
.search input {
  width: 100%;
  padding: 8px 14px 8px 36px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--page);
  color: var(--ink);
}
.search input::placeholder { color: var(--ink-muted); }
.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
  max-height: 60vh;
  overflow-y: auto;
}
.search-group {
  padding: 8px 14px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}
.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 14px;
  border: 0;
  background: none;
  text-align: left;
}
.search-item:hover, .search-item.is-active { background: var(--accent-wash); }
.search-item .si-sub { margin-left: auto; font-size: 12px; color: var(--ink-muted); white-space: nowrap; }
.search-empty { padding: 14px; color: var(--ink-muted); font-size: 14px; }

/* ---------- Icon buttons & bell ---------- */

.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--ink-2);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.is-active { background: var(--accent-wash); color: var(--accent-strong); }

/* Hover tooltip for icon-only topbar buttons (Alerts bell, Watchlist star). */
.icon-btn[data-tip] { position: relative; }
.icon-btn[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .12s ease, transform .12s ease;
  z-index: 60;
}
.icon-btn[data-tip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Profile: a user avatar in the top-right that opens the account menu. */
.avatar-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  color: var(--ink-2);
  flex-shrink: 0;
}
.avatar-btn svg { width: 20px; height: 20px; }
.avatar-btn .avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-btn.has-photo { background: transparent; }
.avatar-btn.has-photo .avatar-glyph { display: none; }
.avatar-btn:hover { color: var(--ink); border-color: var(--ink-muted); background: var(--surface-2); }
.avatar-btn.has-photo:hover { background: transparent; }
/* Tier-tinted header avatar (silver/gold/diamond), set by js/app.js
   renderHeaderAvatar(). `--acct` is the accent as raw RGB channels; the ring + fill
   match the account card, and the glyph colour mirrors .plan-tag-* for legibility.
   With a photo the tint sits behind it, so only the coloured ring shows. */
.avatar-btn[data-tier="silver"]  { --acct: 148, 163, 184; }
.avatar-btn[data-tier="gold"]    { --acct: 234, 179, 8; }
.avatar-btn[data-tier="diamond"] { --acct: 56, 189, 248; }
.avatar-btn[data-tier] {
  border-color: rgba(var(--acct), 0.6);
  background: rgba(var(--acct), 0.16);
  color: #64748b;
  /* A soft tier-coloured glow. The inner 1px ring + outer blur read clearly even
     when a profile photo fills the circle (the photo hides the fill, the glow
     radiates outside the button), which is the whole point of showing it here. */
  box-shadow: 0 0 0 1px rgba(var(--acct), 0.45), 0 0 12px 1px rgba(var(--acct), 0.55);
}
.avatar-btn[data-tier="gold"]    { color: #b45309; }
.avatar-btn[data-tier="diamond"] { color: #0369a1; }
:root[data-theme="dark"] .avatar-btn[data-tier="silver"]  { color: #cbd5e1; }
:root[data-theme="dark"] .avatar-btn[data-tier="gold"]    { color: #fcd34d; }
:root[data-theme="dark"] .avatar-btn[data-tier="diamond"] { color: #7dd3fc; }
.avatar-btn[data-tier]:hover {
  border-color: rgba(var(--acct), 0.9);
  background: rgba(var(--acct), 0.24);
  box-shadow: 0 0 0 1px rgba(var(--acct), 0.6), 0 0 16px 2px rgba(var(--acct), 0.72);
}

.avatar-btn.is-active,
.avatar-btn[aria-expanded="true"] {
  color: var(--accent-strong);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-wash);
}

/* Account dropdown menu (opens from the avatar). */
.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  width: 236px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item > svg { width: 19px; height: 19px; color: var(--ink-2); flex-shrink: 0; }
.menu-item .menu-label { flex: 1; }
.menu-item .switch { pointer-events: none; }
.menu-item:hover > svg { color: var(--ink); }
.menu-divider { height: 1px; margin: 6px 4px; background: var(--hairline); }

/* Language row + its roll-down submenu (an inline accordion, not a side flyout). */
.menu-item-value { flex: none; font-size: 13px; color: var(--ink-muted); }
.menu-chevron {
  flex: none;
  color: var(--ink-muted);
  transition: transform 200ms ease;
}
.menu-lang-wrap[data-open="true"] .menu-item { background: var(--surface-2); }
/* Chevron points right at rest; rotate it a quarter-turn to point down as the
   options roll open. */
.menu-lang-wrap[data-open="true"] .menu-chevron { transform: rotate(90deg); }

/* The roll-down itself. A 0fr→1fr grid row animates real height with no magic
   max-height number, and the inner wrapper clips the options while they slide. */
.lang-flyout {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 200ms ease, opacity 160ms ease;
}
.menu-lang-wrap[data-open="true"] .lang-flyout {
  grid-template-rows: 1fr;
  opacity: 1;
}
.lang-flyout-inner {
  overflow: hidden;
  min-height: 0;
}
.lang-opt {
  display: block;
  width: 100%;
  padding: 8px 10px 8px 42px;   /* indent under the Language label */
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
}
.lang-opt:first-child { margin-top: 2px; }
.lang-opt:hover { background: var(--surface-2); }
.lang-opt[aria-checked="true"] { color: var(--accent-strong); font-weight: 600; }
.menu-danger, .menu-danger > svg { color: var(--sell); }
.menu-danger:hover { background: var(--sell-wash); }
.menu-danger:hover > svg { color: var(--sell); }

.bell-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--cta);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 50;
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline);
  font-weight: 600;
}
.notif-head-actions { display: flex; align-items: center; gap: 8px; }
.notif-add {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 9px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}
.notif-add:hover { background: var(--cta); color: #fff; }
/* The mirror of .notif-add — a round pill so the two read as one pair of controls.
   `1` line-height on a bare "−" leaves it optically high, hence the nudged padding. */
.notif-head .notif-clear-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0 0 2px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: none;
  color: var(--ink-muted);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
}
.notif-clear-pill:hover { border-color: var(--accent); color: var(--accent); }
.notif-list { max-height: 50vh; overflow-y: auto; }
/* The row carries the hairline, the wash and the hover, so the "−" sits inside them
   rather than beside them. */
.notif-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--hairline);
}
.notif-row:last-child { border-bottom: 0; }
.notif-row.unread { background: var(--accent-wash); }
.notif-row:hover { background: var(--surface-2); }
.notif-item {
  display: block;
  flex: 1;
  min-width: 0;
  padding: 12px 16px 12px 8px;
  border: 0;
  background: none;
  text-align: left;
  font-size: 13.5px;
}
/* The row's "−" answers the header's "+ add", so it wears the same pill: accent
   outline, filled on hover. Always drawn — revealing it on hover would hide it from
   every touch device, where there is no hover to reveal it with. */
.notif-dismiss {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 22px;
  height: 22px;
  margin-left: 14px;
  padding: 0 0 2px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}
.notif-dismiss:hover { background: var(--cta); border-color: var(--cta); color: #fff; }
.notif-item .n-meta { display: block; margin-top: 2px; color: var(--ink-muted); font-size: 12px; }
.notif-empty { padding: 24px 16px; text-align: center; color: var(--ink-muted); }

/* ---------- Primary navigation ---------- */

.mainnav {
  grid-column: 2;
  justify-self: center;
  display: flex;
  justify-content: center;
  gap: 4px;
}
.mainnav a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  border-radius: 999px;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
}
.mainnav a svg { width: 18px; height: 18px; }
.mainnav a:hover { background: var(--surface-2); color: var(--ink); }
.mainnav a.is-active {
  background: var(--accent-wash);
  color: var(--accent-strong);
  font-weight: 600;
}

/* ---------- Main view ---------- */

.view {
  flex: 1;
  width: 100%;
  padding-block: 24px 96px; /* width, centering + horizontal gutters come from .container */
}

.view h1 {
  font-size: 22px;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.view-sub { color: var(--ink-2); font-size: 14px; margin-bottom: 20px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
}
.section-head h2 { font-size: 16px; font-weight: 650; }
.section-head .see-all { font-size: 13px; font-weight: 600; color: var(--accent); white-space: nowrap; }

.section-head-actions { display: flex; align-items: center; gap: 14px; }

/* Sector filter beside the "Recent trades" heading. */
.feed-select {
  padding: 6px 30px 6px 12px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  /* custom caret so it matches the rounded, themed control */
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23898781' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
}
.feed-select:hover { border-color: var(--ink-muted); }
.feed-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

/* ---------- Toasts ---------- */

.toast-region {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--page);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-pop);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Mobile: bottom tab bar ---------- */

@media (max-width: 720px) {
  .container { padding-left: 14px; padding-right: 14px; } /* tighter gutters on phones */
  .topbar { padding: 0 14px; gap: 10px; }
  .brand-name, .brand-live { display: none; }
  .searchrow { padding: 0 14px 10px; }

  /* Nav becomes a fixed bottom tab bar; Profile stays top-right by the bell. */
  .mainnav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    justify-self: auto;
    justify-content: space-around;
    gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--hairline);
    z-index: 40;
  }
  .mainnav a {
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px;
    font-size: 11px;
    border-radius: 10px;
  }
  .mainnav a svg { width: 22px; height: 22px; }

  .view { padding-block: 18px 96px; }
}
