/* ────────────────────────────────────────────────────────────────────────────
 * sidebar.css — shared navigation shell
 *
 * Desktop (≥901px): a fixed vertical rail with a collapse toggle and the
 * user's recent analyses. Mobile (≤900px): the original top bar with the
 * hamburger menu, because a rail on a phone is worse than what it replaces.
 *
 * Pairs with sidebar.js, which injects the markup synchronously so the first
 * paint already shows the signed-in state (no guest-menu flash).
 * ──────────────────────────────────────────────────────────────────────────── */

:root { --sb-w: 258px; --sb-w-collapsed: 68px; }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px;
  background: rgba(6,6,16,0.85);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.navbar .logo { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.logo-text { color: #fff; font-weight: 800; letter-spacing: -0.03em; font-size: 20px; white-space: nowrap; }
.logo-text span { color: rgba(255,255,255,0.4); font-weight: 500; }
.navbar ul { list-style: none; display: flex; gap: 18px; align-items: center; }
.navbar a { text-decoration: none; font-size: 13px; color: rgba(255,255,255,0.8); }
.navbar a:hover { color: #fff; }
/* Legal links belong in the menu, not in a strip under the content. Small and
   last, so they are always reachable and never compete for attention. */
.nav-legal-li {
  display: flex; flex-wrap: wrap; gap: 0 12px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.navbar ul li.nav-legal-li a {
  font-size: 11px; color: rgba(255,255,255,0.38);
  padding: 9px 0; border-radius: 0; white-space: nowrap;
}
.navbar ul li.nav-legal-li a:hover { color: rgba(255,255,255,0.72); background: none; }
.nav-auth-btn {
  padding: 10px 14px; border-radius: 14px; font-size: 13px; font-weight: 800;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.14);
  color: #fff; cursor: pointer; font-family: inherit;
}
.nav-auth-btn:hover { background: rgba(255,255,255,0.12); }
.hamburger { display: none; background: none; border: none; cursor: pointer; flex-direction: column; gap: 5px; padding: 4px; }
.hamburger span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }

/* ── Rail pieces (hidden until the desktop query turns them on) ────────── */
.sb-collapse {
  display: none; align-self: flex-end;
  width: 30px; height: 30px; margin: -4px 0 10px; padding: 0;
  align-items: center; justify-content: center;
  border-radius: 9px; cursor: pointer; line-height: 1;
  background: rgba(255,255,255,0.09);
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.85); font-size: 15px; font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.sb-collapse:hover { color: #fff; background: rgba(99,102,241,0.28); border-color: rgba(129,140,248,0.6); }
.sb-body { display: none; flex-direction: column; min-height: 0; flex: 1; }
.sb-new {
  display: flex; align-items: center; gap: 9px; padding: 10px 12px; margin-bottom: 16px;
  border-radius: 10px; background: rgba(99,102,241,0.14); border: 1px solid rgba(99,102,241,0.3);
  color: #c7d2fe; font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap;
}
.sb-new:hover { background: rgba(99,102,241,0.22); color: #fff; }
.sb-new-icon { font-size: 15px; font-weight: 800; }
.sb-history { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.sb-section-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: rgba(255,255,255,0.3); padding: 0 10px 7px; }
.sb-history-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.sb-item { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; cursor: pointer; }
.sb-item:hover { background: rgba(255,255,255,0.06); }
.sb-item-top { display: flex; align-items: center; gap: 6px; }
.sb-item-ticker { font-size: 12.5px; font-weight: 800; color: rgba(255,255,255,0.85); }
.sb-item-tf { font-size: 10px; color: rgba(255,255,255,0.35); font-weight: 700; }
.sb-item-dot { width: 6px; height: 6px; border-radius: 50%; margin-left: auto; flex-shrink: 0; }
.sb-item-dot.bull { background: #22c55e; }
.sb-item-dot.bear { background: #ef4444; }
.sb-item-dot.neut { background: rgba(255,255,255,0.25); }
.sb-item-date { font-size: 10.5px; color: rgba(255,255,255,0.3); margin-top: 2px; }
.sb-empty { font-size: 11.5px; color: rgba(255,255,255,0.28); padding: 4px 10px; line-height: 1.5; }

/* ── Instant signed-in state (class set in <head> before first paint) ──── */
html.logged-in-early #accountNavItem,
html.logged-in-early #analysesNavItem,
html.logged-in-early #publishedNavItem { display: list-item !important; }
html.logged-in-early #authBtn { font-size: 0 !important; }
html.logged-in-early #authBtn::after { content: "Log out"; font-size: 13px; font-weight: 800; }

/* The mobile bar only exists on small screens. These defaults MUST come
   before the media query below: they share its specificity, so placed after
   it they win the cascade and hide the topbar on phones too — which is
   exactly the bug that left every sidebar.css page with no menu on mobile
   while index.html (inline copy, correct order) worked. */
.mobile-topbar { display: none; }
.nav-scrim { display: none; }

/* ── Mobile: slide-in drawer, same contents as the desktop rail ─────────
   A dropdown of links loses the analysis history, which is the useful half.
   The drawer keeps everything and matches how Claude and ChatGPT behave. */
@media (max-width: 900px) {
  .hamburger { display: flex; position: relative; z-index: 1210; }

  .navbar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 82vw; max-width: 320px;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    padding: 18px 16px; gap: 4px; overflow-y: auto;
    background: #08081a;
    border-bottom: none; border-right: 1px solid rgba(255,255,255,0.08);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1200;
  }
  body.nav-open .navbar { transform: translateX(0); }

  /* Bar that stays visible when the drawer is closed */
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 1000;
    padding: 12px 16px;
    background: rgba(6,6,16,0.9);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border-bottom: 1px solid rgba(255,255,255,0.08);
  }
  .mobile-topbar .logo-text { font-size: 17px; }

  .nav-scrim {
    display: none; position: fixed; inset: 0; z-index: 1150;
    background: rgba(4,4,12,0.6); backdrop-filter: blur(2px);
  }
  body.nav-open .nav-scrim { display: block; }
  body.nav-open { overflow: hidden; }

  .navbar .logo { padding: 0 6px 16px; }
  .sb-body { display: flex; }
  .navbar ul {
    display: flex; flex-direction: column; align-items: stretch; gap: 2px;
    position: static; background: none; border: none; padding: 14px 0 0;
    margin-top: auto; border-top: 1px solid rgba(255,255,255,0.07);
  }
  .navbar ul li { width: 100%; padding: 0; }
  .navbar ul li a { display: block; padding: 11px 8px; border-radius: 9px; font-size: 14px; }
  .nav-auth-li { margin-top: 6px; }
  .nav-auth-btn { width: 100%; }
  .sb-collapse { display: none; }   /* no rail to collapse on a phone */
}

/* Narrow laptops and small tablets in landscape: keep the rail, but slimmer,
   so a 1024px screen does not give a quarter of its width to navigation. */
@media (min-width: 901px) and (max-width: 1180px) {
  :root { --sb-w: 208px; }
  .navbar { padding: 16px 10px; }
  .navbar ul li a { font-size: 12.5px; padding: 8px 8px; }
  .sb-new { padding: 9px 10px; font-size: 12.5px; }
  .sb-item-ticker { font-size: 12px; }
  .logo-text { font-size: 18px; }
}

/* Short viewports (laptops at 1366×768, phones in landscape): the history
   list must not push the menu off-screen. */
@media (max-height: 720px) {
  .navbar .logo { padding-bottom: 10px; }
  .sb-new { margin-bottom: 10px; }
  .sb-history-list { max-height: 34vh; }
}

/* Very small phones: give the drawer more of the screen, it has a list in it */
@media (max-width: 380px) {
  .navbar { width: 88vw; padding: 16px 12px; }
}

/* ── Desktop rail — LAST so it wins over the base rules above ──────────── */
@media (min-width: 901px) {
  .navbar {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sb-w);
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    padding: 18px 14px; gap: 4px; overflow-y: auto; overflow-x: hidden;
    border-bottom: none; border-right: 1px solid rgba(255,255,255,0.08);
    transition: width 0.2s ease;
  }
  body { padding-left: var(--sb-w); transition: padding-left 0.2s ease; }
  .navbar .logo { padding: 0 8px 16px; }
  .navbar ul {
    flex-direction: column; align-items: stretch; gap: 2px;
    margin-top: auto; padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,0.07);
  }
  .navbar ul li { width: 100%; }
  .navbar ul li a { display: block; padding: 9px 10px; border-radius: 9px; font-size: 13px; white-space: nowrap; }
  .navbar ul li a:hover { background: rgba(255,255,255,0.06); }
  .nav-auth-li { margin-top: 6px; }
  .nav-auth-btn { width: 100%; }
  .sb-collapse { display: flex; }
  .sb-body { display: flex; }

  body.sb-collapsed { padding-left: var(--sb-w-collapsed); }
  body.sb-collapsed .navbar { width: var(--sb-w-collapsed); padding-left: 10px; padding-right: 10px; align-items: center; }
  body.sb-collapsed .sb-lbl,
  body.sb-collapsed .logo-text,
  body.sb-collapsed .navbar ul li a,
  body.sb-collapsed .nav-legal-li,
  body.sb-collapsed .sb-history { display: none; }
  body.sb-collapsed .nav-auth-btn { font-size: 0; padding: 10px 0; }
  body.sb-collapsed .nav-auth-btn::after { content: "\2192"; font-size: 15px; }
  body.sb-collapsed .sb-collapse { transform: rotate(180deg); align-self: center; }
  body.sb-collapsed .sb-new { justify-content: center; }
}
