/* Header, matched to the Markets redesign: one bar, a rounded navigation pill with icons,
   a filled blue active tab, a bold wordmark, and larger controls. */
html body header.site-header {
  padding: 12px 18px !important;
  gap: 12px;
  flex-wrap: wrap;
}

html body header.site-header .header-left {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

html body header.site-header .brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

html body header.site-header .brand-mark {
  width: 42px !important;
  height: 42px !important;
  border-radius: 12px !important;
  background: linear-gradient(135deg, #4d7bff, #2f5fe0);
}

html body header.site-header .brand-logo {
  width: 42px !important;
  height: 42px !important;
}

html body header.site-header .app-brand-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

html body header.site-header .site-nav {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: 999px;
  border: 1px solid var(--sc-border, #2c343a);
  background: var(--sc-raised, #161b1f);
}

html body header.site-header .site-nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px !important;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  border-radius: 999px !important;
}

html body header.site-header .site-nav a svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

html body.app-mode header.site-header .site-nav a[aria-current="page"],
html body.app-mode header.site-header .site-nav a.active {
  background: var(--ref-sunken) !important;
  color: var(--ref-text) !important;
  border-bottom: 2px solid var(--ref-accent) !important;
  border-radius: 10px !important;
  box-shadow: none !important;
}

html body header.site-header .network-badge {
  height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  font-size: 14px;
}

html body header.site-header .wallet {
  height: 42px;
  padding: 0 22px !important;
  font-size: 15px !important;
}

/* Narrower screens: two rows only. Row 1 is the logo and the controls; row 2 is the navigation bar, full width. */
@media (max-width: 1320px) {
  html body.app-mode header.site-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto !important;
    align-items: center;
    gap: 10px 12px;
    flex-wrap: nowrap !important;
  }
  html body.app-mode header.site-header .header-left {
    display: contents !important;
  }
  html body.app-mode header.site-header .brand-link {
    grid-column: 1;
    grid-row: 1;
  }
  html body.app-mode header.site-header .header-actions {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }
  html body.app-mode header.site-header .site-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex !important;
    width: 100%;
    box-sizing: border-box;
    justify-content: space-between;
  }
  html body.app-mode header.site-header .site-nav a {
    flex: 1 1 auto;
    justify-content: center;
    padding: 0 12px !important;
    font-size: 14px;
  }
}

/* Phone: the active tab keeps its label, the others show icons only, so all four fit in one row. */
@media (max-width: 620px) {
  html body header.site-header .site-nav a:not([aria-current="page"]) span {
    display: none;
  }
  html body header.site-header .site-nav a {
    padding: 0 10px !important;
  }
  html body header.site-header .wallet {
    padding: 0 14px !important;
    font-size: 14px !important;
  }
}

/* The floating quick nav is removed. The full header stays at the top of the page as you scroll. */
html body #scrollRouteNav,
html body nav.scroll-route-nav {
  display: none !important;
}

/* Keep the document scrollable across routes. */
html body.app-mode {
  overflow: visible !important;
  overflow-x: clip !important;
}

html body header.site-header {
  position: relative !important;
  top: auto !important;
  z-index: 80;
  background: color-mix(in srgb, var(--sc-bg, #0d0e11) 94%, transparent) !important;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

/* Header and market filter polish, matched to the Markets redesign:
   pill navigation with a filled active state, a rounded logo tile, a pill wallet button,
   and pill filter chips with one filled choice. Loaded after the other layers. */

html body header.site-header .brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  overflow: hidden;
  display: grid;
  place-items: center;
}

html body header.site-header .brand-logo {
  width: 34px;
  height: 34px;
  object-fit: cover;
}

/* Crop the padding in the supplied artwork so the S reads clearly at header size. */
html body header.site-header .brand-mark {
  position: relative;
  flex: 0 0 42px;
  width: 42px !important;
  height: 42px !important;
  overflow: hidden;
  border: 1px solid rgba(96, 147, 255, .22);
  background: #020b20;
  box-shadow: 0 0 0 1px rgba(51, 110, 255, .08), 0 0 14px rgba(51, 110, 255, .12);
  animation: sc-brand-breathe 5s ease-in-out infinite;
  transition: box-shadow 220ms ease, transform 220ms ease;
}

html body header.site-header .brand-mark .brand-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  width: 112px !important;
  height: auto !important;
  max-width: none !important;
  border: 0 !important;
  border-radius: 0 !important;
  object-fit: initial;
  transform: translate(-50%, -50%);
  transition: transform 280ms ease;
}

html body header.site-header .brand-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.23) 50%, transparent 70%);
  transform: translateX(-135%);
  animation: sc-brand-shine 7s ease-in-out infinite;
  pointer-events: none;
}

html body header.site-header .brand-link:hover .brand-mark,
html body header.site-header .brand-link:focus-visible .brand-mark {
  transform: translateY(-2px);
  box-shadow: 0 0 0 1px rgba(96,147,255,.4), 0 5px 20px rgba(51,110,255,.28);
}

html body header.site-header .brand-link:hover .brand-logo,
html body header.site-header .brand-link:focus-visible .brand-logo {
  transform: translate(-50%, -50%) scale(1.06);
}

@keyframes sc-brand-breathe {
  50% { box-shadow: 0 0 0 1px rgba(51,110,255,.18), 0 0 18px rgba(51,110,255,.23); }
}

@keyframes sc-brand-shine {
  0%, 72%, 100% { transform: translateX(-135%); }
  84% { transform: translateX(135%); }
}

@media (prefers-reduced-motion: reduce) {
  html body header.site-header .brand-mark,
  html body header.site-header .brand-mark::after { animation: none; }
  html body header.site-header .brand-mark,
  html body header.site-header .brand-mark .brand-logo { transition: none; }
}

html body header.site-header .site-nav a {
  border-radius: 999px !important;
  padding: 8px 14px !important;
  transition: background-color 160ms ease, color 160ms ease;
}

html body header.site-header .site-nav a[aria-current="page"],
html body header.site-header .site-nav a.active {
  background: var(--ref-sunken) !important;
  color: var(--ref-text) !important;
}

html body header.site-header .wallet-control,
html body header.site-header .wallet-control button {
  border-radius: 999px !important;
}

html body header.site-header .wallet-control button {
  padding: 9px 20px !important;
}

/* Market detail, single-column layout: the market title and stats come first, then the Borrow / Lend form. */
@media (max-width: 1100px) {
  html[data-nav-route="market"] body.app-mode #appView .layout > #stockDetailContent {
    order: 1 !important;
  }
  html[data-nav-route="market"] body.app-mode #appView .layout > aside {
    order: 2 !important;
  }
}

/* Filter block: lined up with the search box, the Borrow APY label is no longer cut at the panel edge,
   and the bright white rule above the list uses the theme's border colour. */
html[data-nav-route="market"] body.app-mode #appView #stockListPanel .market-filterbar,
html[data-markets-list] body.app-mode #appView #stockListPanel .market-filterbar {
  padding-left: 26px !important;
  padding-right: 26px !important;
  box-sizing: border-box !important;
  width: 100% !important;
}

html[data-nav-route="market"] #stockListPanel .market-filterbar label {
  white-space: nowrap;
}

html[data-nav-route="market"] #stockListPanel table,
html[data-nav-route="market"] #stockListPanel .table {
  border-top-color: var(--m-border, #2a2d35) !important;
}

/* Markets toolbar on narrow screens: search takes its own full row, so Sort and Refresh stay inside the panel. */
html[data-nav-route="market"] #stockListPanel .toolbar {
  max-width: 100%;
  box-sizing: border-box;
}

html[data-nav-route="market"] #stockListPanel .toolbar .refresh {
  flex: none !important;
}

@media (max-width: 720px) {
  html[data-nav-route="market"] #stockListPanel .toolbar .search-wrap {
    flex: 1 1 100% !important;
    width: 100% !important;
  }
  html[data-nav-route="market"] #stockListPanel .toolbar select#marketSort {
    flex: 1 1 auto;
    min-width: 0 !important;
    width: auto !important;
  }
}

/* Market filters: separate pills, the chosen one filled. */
html[data-nav-route="market"] .lend-borrow-filters {
  background: transparent !important;
  border: 0 !important;
  padding: 0 !important;
  gap: 8px !important;
  overflow: visible !important;
}

html[data-nav-route="market"] .lend-borrow-filters button {
  height: 36px !important;
  padding: 0 16px !important;
  border: 1px solid var(--m-border-strong) !important;
  border-radius: 999px !important;
  background: transparent !important;
  color: var(--m-muted) !important;
  box-shadow: none !important;
}

html[data-nav-route="market"] .lend-borrow-filters button[aria-pressed="true"] {
  background: var(--m-text) !important;
  border-color: var(--m-text) !important;
  color: var(--m-bg) !important;
}

@media (min-width: 1321px) {
  html body.app-mode header.site-header {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) !important;
    align-items: center;
  }
  html body.app-mode header.site-header .header-left { display: contents !important; }
  html body.app-mode header.site-header .brand-link {
    grid-column: 1; justify-self: start;
  }
  html body.app-mode header.site-header .site-nav {
    grid-column: 2; justify-self: center;
    width: max-content !important;
  }
  html body.app-mode header.site-header .header-actions {
    grid-column: 3; justify-self: end;
    margin: 0 !important;
  }
}

/* Keep the wrapped navigation only as wide as its links. */
@media (max-width: 1320px) {
  html body.app-mode header.site-header .site-nav {
    width: max-content !important;
    max-width: 100% !important;
    justify-self: center !important;
    justify-content: center !important;
  }
  html body.app-mode header.site-header .site-nav a {
    flex: 0 0 auto !important;
    padding: 0 16px !important;
  }
}

@media (max-width: 620px) {
  html body.app-mode header.site-header {
    grid-template-rows: auto auto !important;
  }
  html body.app-mode header.site-header .site-nav {
    grid-row: 2 !important;
    width: 100% !important;
    justify-content: flex-start !important;
    overflow-x: auto !important;
    white-space: nowrap;
    scrollbar-width: none;
  }
  html body.app-mode header.site-header .site-nav::-webkit-scrollbar { display: none; }
  html body.app-mode header.site-header .site-nav a:not([aria-current="page"]) span {
    display: inline !important;
  }
  html body.app-mode header.site-header .site-nav a {
    flex: 0 0 auto !important;
    padding: 0 12px !important;
  }
}

@media (max-width: 520px) {
  html body.app-mode header.site-header {
    grid-template-rows: auto auto auto !important;
  }
  html body.app-mode header.site-header .app-brand-name {
    display: inline !important;
    font-size: 18px !important;
    white-space: nowrap;
  }
  html body.app-mode header.site-header .header-actions {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    justify-self: end !important;
    width: auto !important;
  }
  html body.app-mode header.site-header .site-nav {
    grid-row: 3 !important;
  }
}

/* The homepage has an older embedded header for its legacy scripts. Show only
   the shared site header, including its navigation, on every route. */
html[data-site-route="home"] body.app-mode #homeView #hdr,
html[data-site-route="home"] body.app-mode #homeView #msheet {
  display: none !important;
}

html[data-site-route="home"] body.app-mode header.site-header .site-nav {
  display: flex !important;
}

html[data-site-route="home"] body.app-mode header.site-header .site-nav a.active {
  background: transparent !important;
  color: inherit !important;
  border-bottom: 0 !important;
}

/* The links sit directly on the header instead of inside a rounded container. */
html body.app-mode header.site-header .site-nav {
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

html body.app-mode header.site-header .site-nav a[aria-current="page"],
html body.app-mode header.site-header .site-nav a.active {
  background: transparent !important;
  border-radius: 0 !important;
}

@media (max-width: 620px) {
  html body.app-mode header.site-header .site-nav {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 8px;
    width: 100% !important;
    max-width: none !important;
    overflow: visible !important;
    justify-self: stretch !important;
  }
  html body.app-mode header.site-header .site-nav a {
    min-width: 0;
    width: 100%;
    height: 39px;
    padding: 0 10px !important;
    justify-content: flex-start;
    font-size: 13px;
    box-sizing: border-box;
  }
  html body.app-mode header.site-header .site-nav a span {
    display: inline !important;
  }
  html body.app-mode header.site-header .site-nav a svg {
    width: 16px;
    height: 16px;
  }

  #giftView .gift-tabs {
    flex-wrap: wrap;
    gap: 2px 16px;
    overflow: visible !important;
  }
  #giftView .gift-tabs a {
    white-space: normal;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
  }
}

@media (max-width: 920px) {
  html[data-nav-route="market"] body.app-mode.stock-detail-mode #appView .layout > #stockDetailContent,
  html[data-nav-route="market"] body.app-mode.stock-detail-mode #appView .layout > aside {
    grid-row: auto !important;
    grid-column: auto !important;
    grid-area: auto !important;
  }
}

@media (max-width: 520px) {
  html body.app-mode header.site-header {
    grid-template-columns: minmax(0, 1fr) auto !important;
    grid-template-rows: auto auto !important;
    gap: 5px 6px !important;
    padding: 10px 12px !important;
  }
  html body.app-mode header.site-header .brand-link {
    grid-column: 1 !important;
    grid-row: 1 !important;
    min-width: 0;
  }
  html body.app-mode header.site-header .header-actions {
    grid-column: 2 !important;
    grid-row: 1 !important;
    gap: 4px !important;
    margin: 0 !important;
  }
  html body.app-mode header.site-header .network-badge {
    height: 34px;
    padding: 0 8px;
    font-size: 12px;
  }
  html body.app-mode header.site-header .theme-toggle {
    width: 32px;
    min-width: 32px;
    height: 34px;
    margin: 0 !important;
  }
  html body.app-mode header.site-header #walletControl > #wallet {
    height: 34px;
    min-height: 34px;
    padding: 0 10px !important;
    font-size: 12px !important;
    white-space: nowrap;
  }
  html body.app-mode header.site-header .site-nav,
  html[data-site-route="home"] body.app-mode header.site-header .site-nav {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    display: grid !important;
  }
}

@media (max-width: 360px) {
  html body.app-mode header.site-header .brand-link { gap: 5px !important; }
  html body.app-mode header.site-header .brand-mark {
    flex-basis: 34px;
    width: 34px !important;
    height: 34px !important;
  }
  html body.app-mode header.site-header .brand-mark .brand-logo { width: 90px !important; }
  html body.app-mode header.site-header .app-brand-name { font-size: 14px !important; }
  html body.app-mode header.site-header .network-badge { padding: 0 6px; font-size: 11px; }
  html body.app-mode header.site-header #walletControl:not(.is-connected) > #wallet {
    font-size: 0 !important;
    padding: 0 8px !important;
  }
  html body.app-mode header.site-header #walletControl:not(.is-connected) > #wallet::after {
    content: "Connect";
    font-size: 11px;
  }
  html body.app-mode header.site-header #walletControl.is-connected > #wallet {
    max-width: 78px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Keep the homepage headline readable beside the compact mobile header. */
@media (max-width: 520px) {
  #homeView.hdn .tz-copy { min-width: 0; width: 100%; }
  #homeView.hdn .tz-hero h1 {
    width: 100%;
    font-size: clamp(31px, 8.6vw, 39px) !important;
    line-height: 1.08 !important;
    letter-spacing: -.035em !important;
    overflow-wrap: normal;
    text-wrap: balance;
  }
  #homeView.hdn .tz-hero h1 span { margin-top: 4px; }
  #homeView.hdn .tz-lede { max-width: 34ch; }
}

/* Keep Dashboard on app pages without promoting it in the homepage navigation. */
html[data-site-route="home"] body.app-mode header.site-header .site-nav a[data-route="dashboard"],
html[data-site-route="home"] body.app-mode a[data-quick-route="dashboard"],
html[data-site-route="home"] body.app-mode #homeView a[href="#/dashboard"] {
  display: none !important;
}

@media (max-width: 620px) {
  html[data-site-route="home"] body.app-mode header.site-header .site-nav {
    grid-template-columns: repeat(3, max-content) !important;
    justify-content: space-between !important;
    gap: 4px !important;
  }
  html[data-site-route="home"] body.app-mode header.site-header .site-nav a {
    width: auto !important;
    padding: 0 4px !important;
    white-space: nowrap;
  }
  html[data-site-route="home"] body.app-mode header.site-header .site-nav a svg {
    display: none !important;
  }
}
