/* MarketWatch theme layer: colours, glass shell, glow and motion.
   Loaded after each page's own <style>, so it restyles the shared classes (base.html) without touching page markup.
   Behaviour (background canvas, card glow position, count-up, command palette) is in static/js/fx.js.
   Motion is off under prefers-reduced-motion and when the user switches it off in the user menu (html.fx-still).
   The animated background is off unless switched on there (html.fx-backdrop). */

@property --fx-glow  { syntax: '<number>'; inherits: false; initial-value: 0; }
@property --fx-angle { syntax: '<angle>';  inherits: false; initial-value: 0deg; }

:root {
  --bg:        #05080c;
  --surface:   #0b1017;
  --surface2:  #121a24;
  --border:    #1f2a37;
  --cyan:      #2ad4ff;
  --display:   'Chakra Petch', 'IBM Plex Sans', sans-serif;
  --fx-card:   rgba(11,16,23,.86);            /* card fill: a little of the background shows through */
  --fx-line:   rgba(120,170,210,.17);         /* hairlines on glass */
  --fx-ease:   cubic-bezier(.2,.7,.2,1);
  color-scheme: dark;
}

::selection { background: rgba(0,200,150,.32); color: #fff; }
* { scrollbar-width: thin; scrollbar-color: #263243 transparent; }
:where(h1, h2, h3) { font-family: var(--display); letter-spacing: .01em; }

/* ── Backdrop (only when switched on): slow aurora + grid, under the canvas that fx.js adds ──
   Negative z-index keeps all three behind the page; the body background still paints below them. */
html.fx-backdrop body::before {
  content: ''; position: fixed; inset: -20%; z-index: -3; pointer-events: none;
  background:
    radial-gradient(42% 38% at 78% 16%, rgba(0,132,255,.17), transparent 70%),
    radial-gradient(38% 36% at 18% 84%, rgba(0,200,150,.13), transparent 70%),
    radial-gradient(30% 30% at 58% 58%, rgba(120,90,255,.07), transparent 70%);
  animation: fx-aurora 26s ease-in-out infinite alternate;
}
html.fx-backdrop body::after {
  content: ''; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background-image:
    linear-gradient(rgba(120,170,210,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,170,210,.05) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 90% 80% at 60% 0%, #000 0%, transparent 78%);
          mask-image: radial-gradient(ellipse 90% 80% at 60% 0%, #000 0%, transparent 78%);
}
#fx-bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; display: none; }
html.fx-backdrop #fx-bg { display: block; }
@keyframes fx-aurora {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(3%, 2%, 0) scale(1.12); }
}

/* ── Sidebar ── */
.sidebar {
  background: linear-gradient(180deg, rgba(12,18,26,.74), rgba(6,9,14,.88));
  -webkit-backdrop-filter: blur(16px) saturate(150%);
          backdrop-filter: blur(16px) saturate(150%);
  border-right-color: var(--fx-line);
}
/* A light that travels down the sidebar's edge */
.sidebar::after {
  content: ''; position: absolute; top: 0; right: -1px; width: 1px; height: 100%; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(0,200,150,.75), rgba(42,212,255,.5), transparent) 0 -240px / 100% 240px no-repeat;
  animation: fx-edge 9s linear infinite;
}
@keyframes fx-edge { to { background-position: 0 calc(100% + 240px); } }
.sidebar-logo { border-bottom-color: var(--fx-line); }
.sidebar-logo .wordmark { display: flex; align-items: center; gap: 8px; }
.sidebar-logo .wordmark::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 0 rgba(0,200,150,.6); animation: fx-ping 2.6s ease-out infinite;
}
.sidebar-logo .product, .login-logo .product, body > .wrap > .logo .product {
  font-family: var(--display); font-weight: 700; letter-spacing: .03em;
  background: linear-gradient(90deg, #00c896, #2ad4ff 45%, #7fb6ff 55%, #00c896) 0 0 / 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: fx-shimmer 7s linear infinite;
}
.sidebar-logo .product { font-size: 19px; }
@keyframes fx-shimmer { to { background-position: -220% 0; } }
@keyframes fx-ping {
  0%   { box-shadow: 0 0 0 0 rgba(0,200,150,.55); }
  70%  { box-shadow: 0 0 0 7px rgba(0,200,150,0); }
  100% { box-shadow: 0 0 0 0 rgba(0,200,150,0); }
}

.sidebar nav a {
  position: relative; margin: 1px 10px; padding: 7px 10px; border-left: 0; border-radius: 8px;
  transition: color .15s, background .2s, transform .25s var(--fx-ease), box-shadow .2s;
}
.sidebar nav a:hover { background: rgba(120,170,210,.08); transform: translateX(3px); }
.sidebar nav a.active {
  color: #eafff8;
  background: linear-gradient(90deg, rgba(0,200,150,.2), rgba(0,200,150,.03));
  box-shadow: inset 0 0 0 1px rgba(0,200,150,.24), 0 0 24px -8px rgba(0,200,150,.5);
}
.sidebar nav a.active::before {
  content: ''; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--accent); box-shadow: 0 0 12px var(--accent), 0 0 2px #fff;
}
.sidebar nav a .nav-icon { transition: opacity .15s, color .15s, filter .2s; }
.sidebar nav a:hover .nav-icon { opacity: 1; }
.sidebar nav a.active .nav-icon { opacity: 1; color: var(--accent); filter: drop-shadow(0 0 5px rgba(0,200,150,.7)); }
.sidebar nav .nav-section { font-family: var(--display); letter-spacing: .2em; }
.nav-badge-new { background: linear-gradient(90deg, var(--accent2), var(--cyan)); box-shadow: 0 0 12px -2px rgba(42,212,255,.7); }
#alert-badge, .topbar-bell-count { box-shadow: 0 0 12px -1px rgba(232,57,77,.8); }
.sidebar-foot { border-top-color: var(--fx-line); }

/* ── Top bar ── */
.topbar {
  background: rgba(6,9,14,.62);
  -webkit-backdrop-filter: blur(14px) saturate(150%);
          backdrop-filter: blur(14px) saturate(150%);
  border-bottom-color: var(--fx-line);
}
.topbar-title { font-family: var(--display); font-size: 15px; letter-spacing: .04em; }
/* Reading progress along the top bar's lower edge (browsers with scroll-driven animations) */
@supports (animation-timeline: scroll()) {
  .topbar::after {
    content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; pointer-events: none;
    background: linear-gradient(90deg, var(--accent), var(--cyan)); box-shadow: 0 0 8px var(--accent);
    transform-origin: 0 50%; transform: scaleX(0);
    animation: fx-progress linear both; animation-timeline: scroll(root);
  }
}
@keyframes fx-progress { to { transform: scaleX(1); } }

.topbar-search {
  background: rgba(18,26,36,.66); border-color: var(--fx-line); border-radius: 8px;
  transition: border-color .15s, box-shadow .25s, background .2s;
}
.topbar-search:focus { background: rgba(18,26,36,.92); box-shadow: 0 0 0 3px rgba(0,200,150,.13), 0 0 28px -8px rgba(0,200,150,.65); }
.topbar-search-wrap:has(.fx-kbd) .topbar-search { padding-right: 62px; }
.fx-kbd {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: 10px; line-height: 1; color: var(--muted);
  background: rgba(5,8,12,.7); border: 1px solid var(--fx-line); border-radius: 5px; padding: 4px 6px; cursor: pointer;
  transition: color .15s, border-color .15s, box-shadow .2s;
}
.fx-kbd:hover { color: var(--accent); border-color: rgba(0,200,150,.5); box-shadow: 0 0 14px -4px rgba(0,200,150,.8); }
@media (max-width: 768px) { .fx-kbd { display: none; } .topbar-search-wrap:has(.fx-kbd) .topbar-search { padding-right: 12px; } }

.topbar-icon-btn:hover { color: var(--accent); background: rgba(0,200,150,.09); box-shadow: 0 0 18px -6px rgba(0,200,150,.8); }
.user-btn { background: rgba(18,26,36,.66); border-color: var(--fx-line); border-radius: 8px; transition: border-color .15s, box-shadow .2s; }
.user-btn:hover { box-shadow: 0 0 18px -6px rgba(0,200,150,.8); }
.data-chip .dot { animation: fx-ping-warn 2.6s ease-out infinite; }
@keyframes fx-ping-warn {
  0%   { box-shadow: 0 0 0 0 rgba(245,166,35,.6); }
  70%  { box-shadow: 0 0 0 6px rgba(245,166,35,0); }
  100% { box-shadow: 0 0 0 0 rgba(245,166,35,0); }
}

/* Menus open with a short pop. They sit inside the blurred top bar, so they are solid rather than glass. */
.search-dropdown, .user-dropdown {
  background: #0a0f16; border-color: rgba(120,170,210,.24); border-radius: 10px; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0,200,150,.06), 0 24px 60px -18px rgba(0,0,0,.9), 0 0 40px -18px rgba(0,200,150,.45);
  transform-origin: 50% 0;
}
.search-dropdown { overflow-y: auto; }
.search-dropdown.active, .user-dropdown.active { animation: fx-pop .18s var(--fx-ease) backwards; }
@keyframes fx-pop { from { opacity: 0; transform: translateY(-6px) scale(.97); } }
/* The switch rows themselves are styled in base.html (they show in the classic look too) */
.fx-switch { background: #263243; }
.fx-switch::after { transition-timing-function: var(--fx-ease); }
.fx-menu-row[aria-pressed="true"] .fx-switch { box-shadow: 0 0 12px -2px rgba(0,200,150,.8); }

/* ── Cards ──
   One radial gradient under the card follows the pointer (fx.js sets --mx/--my): it lights the hairline border
   at full strength and, through the slightly see-through fill, the card's surface faintly. --fx-glow fades it. */
.card {
  --mx: -400px; --my: -400px;
  border-color: var(--fx-line);
  border-radius: 10px;
  background:
    linear-gradient(90deg, rgba(0,200,150,.5), rgba(42,212,255,.22) 18%, transparent 46%) 0 0 / 100% 1px no-repeat border-box,
    linear-gradient(var(--fx-card), var(--fx-card)) padding-box,
    radial-gradient(360px circle at var(--mx) var(--my), rgba(0,225,175, calc(var(--fx-glow) * .62)), transparent 72%) border-box;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.03), 0 16px 36px -22px rgba(0,0,0,.9);
  transition: --fx-glow .45s ease, border-color .2s, box-shadow .3s, transform .3s var(--fx-ease);
}
.card:hover { --fx-glow: 1; }
.card-clickable, .grid-4 .card[data-href], .card[data-href] {
  transition: --fx-glow .45s ease, border-color .2s, box-shadow .3s, transform .3s var(--fx-ease);
}
.card-clickable:hover, .card[data-href]:hover {
  transform: translateY(-3px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04), 0 0 0 1px rgba(0,200,150,.28), 0 22px 44px -22px rgba(0,200,150,.5);
}
.card-title { font-family: var(--display); letter-spacing: .16em; }

.stat-label { font-family: var(--display); letter-spacing: .14em; }
.stat-value { font-family: var(--display); font-variant-numeric: tabular-nums; letter-spacing: .01em; text-shadow: 0 0 26px rgba(42,212,255,.28); }

.badge { border-radius: 4px; box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 24%, transparent); }

/* ── Tabs, tables, fold rows ── */
.tabs { border-bottom-color: var(--fx-line); }
.tab { position: relative; font-family: var(--display); letter-spacing: .03em; transition: color .15s, text-shadow .2s; }
.tab.active { border-bottom-color: transparent; text-shadow: 0 0 18px rgba(0,200,150,.55); }
.tab.active::after {
  content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent), var(--cyan)); box-shadow: 0 0 12px var(--accent);
  animation: fx-underline .35s var(--fx-ease) backwards;
}
@keyframes fx-underline { from { transform: scaleX(0); opacity: 0; } }

.data-table th { font-family: var(--display); letter-spacing: .13em; }
.data-table td { transition: background .15s, box-shadow .15s; }
.data-table tr:hover td { background: rgba(0,200,150,.05); }
.data-table tr:hover td:first-child { box-shadow: inset 2px 0 0 var(--accent); }

.fold-list { background: var(--fx-card); border-color: var(--fx-line); border-radius: 10px; }
.fold-head { transition: background .15s, box-shadow .15s; }
.fold-head:hover, .fold-row.open > .fold-head { background: rgba(0,200,150,.05); box-shadow: inset 2px 0 0 var(--accent); }
.fold-body { background: rgba(18,26,36,.55); }
.seg { background: rgba(11,16,23,.7); border-color: var(--fx-line); }
.summary h2 { font-family: var(--display); letter-spacing: .12em; }

/* ── Controls ── zero specificity (the state is inside :where too), so a page's own button styles always win */
:where(button, .btn, .kf-btn, .cp-btn, .act-btn, .lt-btn, .btn-xs) {
  transition: transform .12s, box-shadow .2s, filter .2s, border-color .15s, color .15s, background-color .15s, opacity .15s;
}
:where(button:active, .btn:active) { transform: translateY(1px) scale(.985); }
:where(.btn:hover, .btn-primary:hover, .btn-save:hover) { box-shadow: 0 0 0 1px rgba(0,200,150,.4), 0 8px 26px -8px rgba(0,200,150,.75); }
:where(.lt-btn:hover, .kf-btn.primary:hover, .cp-btn.primary:hover) { box-shadow: 0 0 0 1px rgba(0,132,255,.4), 0 8px 26px -8px rgba(0,132,255,.8); }
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea):where(:focus-visible) {
  box-shadow: 0 0 0 3px rgba(0,200,150,.13);
}

/* Dialogs: the page behind is blurred, the box pops in */
#confirm-modal, .content [style*="position:fixed"][style*="inset:0"] { -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
#confirm-modal > div {
  border-color: rgba(120,170,210,.24); border-radius: 12px; animation: fx-pop .2s var(--fx-ease) backwards;
  box-shadow: 0 0 0 1px rgba(0,200,150,.08), 0 30px 80px -20px #000, 0 0 60px -24px rgba(0,200,150,.6);
}

/* ── Standalone pages: sign in, sign up, setup steps, connector consent ──
   One centred card each. A light circles the card's border; the pointer glow from .card still applies. */
:is(.login-wrap, body > .wrap) { position: relative; max-width: calc(100vw - 32px); }
html.fx-enter :is(.login-wrap, body > .wrap) { animation: fx-rise .7s var(--fx-ease) backwards; }
:is(.login-logo, body > .wrap > .logo) .wordmark { letter-spacing: .34em; margin-right: -.34em; }
:is(.login-logo, body > .wrap > .logo) .product { font-size: 28px; }
:is(.login-wrap, body > .wrap) > .card {
  position: relative; border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04), 0 40px 90px -40px #000, 0 0 90px -40px rgba(0,200,150,.55);
}
:is(.login-wrap, body > .wrap) > .card::before {
  content: ''; position: absolute; inset: -1px; border-radius: inherit; padding: 1px; pointer-events: none;
  background: conic-gradient(from var(--fx-angle), transparent 0 62%, rgba(0,200,150,.95) 78%, rgba(42,212,255,.95) 90%, transparent);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  animation: fx-orbit 7s linear infinite;
}
@keyframes fx-orbit { to { --fx-angle: 360deg; } }
:is(.login-wrap, body > .wrap) :is(input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]), select, textarea) {
  background: rgba(5,8,12,.62); border-color: var(--fx-line); border-radius: 8px;
  transition: border-color .15s, box-shadow .25s, background .2s;
}
:is(.login-wrap, body > .wrap) :is(input, select, textarea):focus { background: rgba(5,8,12,.9); box-shadow: 0 0 0 3px rgba(0,200,150,.13), 0 0 28px -10px rgba(0,200,150,.7); }
:is(.login-wrap, body > .wrap) :is(button, .btn) { border-radius: 8px; font-family: var(--display); letter-spacing: .06em; }
/* The main action: a sheen crosses it on hover */
:is(.login-wrap button, body > .wrap .btn:not(.btn-muted):not(.btn-outline), body > .wrap .allow) {
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.5) 50%, transparent 70%) -140% 0 / 60% 100% no-repeat, linear-gradient(90deg, #00c896, #19d6c4);
  box-shadow: 0 10px 30px -14px rgba(0,200,150,.9);
}
:is(.login-wrap button, body > .wrap .btn:not(.btn-muted):not(.btn-outline), body > .wrap .allow):hover {
  opacity: 1; background-position: 240% 0, 0 0; box-shadow: 0 0 0 1px rgba(0,200,150,.5), 0 12px 36px -10px rgba(0,200,150,.95);
  transition: background-position .7s var(--fx-ease), box-shadow .2s, transform .12s;
}
.steps .step { transition: background .3s; }
.steps .step.done { box-shadow: 0 0 10px -1px rgba(0,200,150,.8); }
.steps .step.active { opacity: 1; background: linear-gradient(90deg, var(--accent), var(--cyan)); animation: fx-breathe 1.8s ease-in-out infinite alternate; }
@keyframes fx-breathe { from { opacity: .45; } to { opacity: 1; box-shadow: 0 0 12px -1px rgba(42,212,255,.8); } }

/* ── Page entrance ── html.fx-enter is set in <head> and removed shortly after load, so only the first paint
   animates (a dialog opened later doesn't). fill-mode backwards: nothing lingers on the elements afterwards. */
@keyframes fx-rise { from { opacity: 0; transform: translateY(14px); } }
html.fx-enter .content > *,
html.fx-enter .content :is(.grid-2, .grid-3, .grid-4) > * { animation: fx-rise .55s var(--fx-ease) backwards; }
html.fx-enter .content > :nth-child(1) { animation-delay: .03s; }
html.fx-enter .content > :nth-child(2) { animation-delay: .08s; }
html.fx-enter .content > :nth-child(3) { animation-delay: .13s; }
html.fx-enter .content > :nth-child(4) { animation-delay: .18s; }
html.fx-enter .content > :nth-child(5) { animation-delay: .23s; }
html.fx-enter .content > :nth-child(6) { animation-delay: .28s; }
html.fx-enter .content > :nth-child(n+7) { animation-delay: .33s; }
html.fx-enter .content :is(.grid-2, .grid-3, .grid-4) > :nth-child(1) { animation-delay: .12s; }
html.fx-enter .content :is(.grid-2, .grid-3, .grid-4) > :nth-child(2) { animation-delay: .19s; }
html.fx-enter .content :is(.grid-2, .grid-3, .grid-4) > :nth-child(3) { animation-delay: .26s; }
html.fx-enter .content :is(.grid-2, .grid-3, .grid-4) > :nth-child(n+4) { animation-delay: .33s; }

/* Page-to-page: the browser cross-fades the two documents; the shell is identical in both, so only the content moves */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .24s; }

/* ── Command palette (Ctrl/⌘ K) ── */
.fx-cmdk {
  position: fixed; inset: 0; z-index: 2000; display: none; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px; background: rgba(3,5,8,.62);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.fx-cmdk.open { display: flex; animation: fx-fade .15s ease backwards; }
@keyframes fx-fade { from { opacity: 0; } }
.fx-cmdk-panel {
  width: 620px; max-width: 100%; max-height: 70vh; display: flex; flex-direction: column; overflow: hidden;
  background: rgba(10,15,22,.96); border: 1px solid rgba(120,170,210,.26); border-radius: 14px;
  box-shadow: 0 0 0 1px rgba(0,200,150,.1), 0 40px 100px -30px #000, 0 0 80px -30px rgba(0,200,150,.7);
  animation: fx-pop .2s var(--fx-ease) backwards;
}
.fx-cmdk-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--fx-line); color: var(--accent); }
.fx-cmdk-input {
  flex: 1; min-width: 0; background: none; border: 0; outline: none; color: var(--text);
  font-family: var(--sans); font-size: 15px;
}
.fx-cmdk-input:focus-visible { box-shadow: none; }
.fx-cmdk-input::placeholder { color: var(--muted); }
.fx-cmdk-list { overflow-y: auto; padding: 6px; overscroll-behavior: contain; }
.fx-cmdk-group { font-family: var(--display); font-size: 10px; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); padding: 10px 10px 4px; }
.fx-cmdk-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  color: var(--text); font-size: 13.5px; text-decoration: none;
}
.fx-cmdk-item svg { width: 14px; height: 14px; flex-shrink: 0; opacity: .6; }
.fx-cmdk-item .fx-cmdk-text { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-cmdk-item .fx-cmdk-sub { color: var(--muted); font-size: 11.5px; flex-shrink: 1; min-width: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-cmdk-item.on { background: linear-gradient(90deg, rgba(0,200,150,.2), rgba(0,200,150,.04)); box-shadow: inset 0 0 0 1px rgba(0,200,150,.26); color: #eafff8; }
.fx-cmdk-item.on svg { opacity: 1; color: var(--accent); }
.fx-cmdk-empty { padding: 22px 12px; text-align: center; color: var(--muted); font-size: 13px; }
.fx-cmdk-foot { display: flex; gap: 16px; padding: 9px 16px; border-top: 1px solid var(--fx-line); color: var(--muted); font-size: 11px; }
.fx-cmdk-foot kbd { font-family: var(--mono); font-size: 10px; border: 1px solid var(--fx-line); border-radius: 4px; padding: 1px 5px; margin-right: 4px; }

/* ── Motion off ── */
html.fx-still *, html.fx-still *::before, html.fx-still *::after {
  animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important;
  transition-duration: .01ms !important; scroll-behavior: auto !important;
}
html.fx-still .topbar::after { display: none; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-delay: 0s !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .topbar::after { display: none; }
  @view-transition { navigation: none; }
}
