.app-shell {
  /* Fixed viewport height + hidden overflow so the ONLY scroll happens inside
     .main-content. This keeps the topbar and sidebar pinned while content
     scrolls. (Previously min-height:100vh let the 1fr grid track grow to the
     content height, so the whole page scrolled and the header/sidebar scrolled
     away with it — and on mobile the burger became unreachable once scrolled.) */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 220px 1fr;
  grid-template-areas:
    "topbar topbar"
    "sidebar main";
  background: var(--off-white);
}

/* Topbar */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--warm-white);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-brand-name {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 20px;
  color: var(--charcoal);
}
.topbar-brand-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.topbar-center {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--slate);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.topbar-user-name {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--charcoal);
}

/* Sidebar */
.sidebar {
  grid-area: sidebar;
  background: var(--warm-white);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 28px 0;
  /* Sidebar owns its own scroll if the nav ever outgrows the viewport, so it
     stays pinned rather than pushing the shell taller. */
  min-height: 0;
  overflow-y: auto;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
}
.nav-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 24px;
  color: var(--slate);
  border-left: 2px solid transparent;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}
.nav-item:hover {
  background: rgba(200, 221, 208, 0.3);
  color: var(--charcoal);
}
.nav-item.active {
  color: var(--green-dark);
  border-left-color: var(--green-dark);
  background: rgba(200, 221, 208, 0.25);
}
.nav-num {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--muted);
  min-width: 22px;
}
.nav-item.active .nav-num { color: var(--green-dark); }
.nav-label {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.sidebar-section-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 24px;
  margin-bottom: 12px;
}
.sidebar-footer {
  padding: 0 24px;
}
.back-link {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.back-link:hover { color: var(--green-dark); }

/* Main content */
.main-content {
  grid-area: main;
  padding: 32px 40px 56px;
  overflow-y: auto;
  /* Allow the grid item to shrink below its content size so overflow-y scrolls
     internally instead of stretching the shell (keeps topbar/sidebar pinned). */
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.view { display: none; }
.view.active { display: block; }

.view-header {
  margin-bottom: 32px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
}
.view-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--green-dark);
  margin-bottom: 8px;
}
.view-header h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 36px;
  margin-bottom: 6px;
}
.view-sub {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--slate);
  max-width: 640px;
}

.panels-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 64px 1fr;
  }
  .sidebar { padding: 16px 0; }
  .nav-item { padding: 10px 12px; justify-content: center; }
  .nav-label { display: none; }
  .nav-num { min-width: 0; }
  .sidebar-section-label, .sidebar-footer { display: none; }
  .panels-grid { grid-template-columns: 1fr; }
  .main-content { padding: 24px 20px 40px; }
}

@media (max-width: 640px) {
  .app-shell {
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }
  .sidebar { display: none; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .topbar-center { display: none; }
  .view-header h1 { font-size: 28px; }
}

/* ─── Argus AM panel layout ────────────────────────────────────── */

.view-header-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}
.view-actions { display: flex; gap: 8px; }

.am-block {
  background: var(--warm-white);
  border: 1px solid var(--border);
  margin-bottom: 24px;
}
.am-block-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--off-white);
}
.am-block-head h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 18px;
  color: var(--charcoal);
}
.block-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green-dark);
  margin-bottom: 4px;
}

.am-chart-wrap {
  position: relative;
  padding: 16px 20px;
  min-height: 280px;
  max-height: 360px;
}
.am-chart-wrap canvas { width: 100% !important; height: 100% !important; }
.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  padding: 32px;
}

.am-two-col {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  margin-bottom: 0;
}
.am-col { display: flex; flex-direction: column; }
.am-col .am-block:last-child { margin-bottom: 0; }

.am-table-wrap {
  overflow-x: auto;
}
.am-table-wrap .panel-placeholder {
  margin: 16px 20px;
}

@media (max-width: 1024px) {
  .am-two-col { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .am-chart-wrap { padding: 12px; min-height: 220px; }
  .am-block-head { padding: 12px 14px; }
  .view-header-row { flex-direction: column; align-items: flex-start; }
}

/* ─── Equity Scanner panel ─────────────────────────────────────── */

.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1024px) {
  .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

.stats-grid-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1024px) {
  .stats-grid-6 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  .stats-grid-6 { grid-template-columns: repeat(2, 1fr); }
}

.equity-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}
/* Phase 4.4: persistent live-feed right column. */
.equity-feed-panel {
  background: var(--warm-white);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 720px;
}
.equity-feed-panel > .equity-feed { flex: 1; min-height: 0; }
@media (max-width: 1024px) {
  /* Stack sidebar, detail, then the feed panel below on tablet/mobile. */
  .equity-layout { grid-template-columns: 1fr; }
  .equity-feed-panel { max-height: 520px; }
}

/* Sidebar tickers */
.equity-sidebar {
  background: var(--warm-white);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 720px;
}
.equity-sidebar-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--off-white);
}
.equity-sidebar-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green-dark);
  margin-bottom: 8px;
}
.equity-search {
  width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  background: var(--warm-white);
  color: var(--charcoal);
  outline: none;
}
.equity-search:focus { border-color: var(--green-dark); }

.equity-tickers-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.equity-ticker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--charcoal);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
}
.equity-ticker-row:last-child { border-bottom: none; }
.equity-ticker-row:hover { background: var(--off-white); }
.equity-ticker-row.is-active {
  background: var(--green-pale);
  color: var(--green-dark);
  font-weight: 600;
}
.equity-ticker-symbol {
  font-variant-numeric: tabular-nums;
}
.equity-ticker-count {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.equity-ticker-row.is-active .equity-ticker-count {
  color: var(--green-dark);
}

/* Main detail area */
.equity-main {
  background: var(--warm-white);
  border: 1px solid var(--border);
  padding: 0;
  min-height: 400px;
}
.equity-main > .panel-placeholder {
  margin: 24px;
}

.equity-detail-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--off-white);
}
.equity-detail-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.equity-detail-top {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.equity-detail-ticker {
  font-family: var(--mono);
  font-size: 26px;
  font-weight: 500;
  color: var(--charcoal);
  letter-spacing: 0.02em;
  line-height: 1.1;
}
.equity-detail-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--slate);
}
.equity-detail-stats strong {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--charcoal);
}
.equity-detail-stats .dot {
  width: auto;
  height: auto;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}
.equity-detail-last {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
}
.equity-detail-last strong {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--slate);
}

.equity-section {
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}
.equity-section:last-child { border-bottom: none; }
.equity-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}
.equity-section-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green-dark);
}
.equity-section-meta {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Opinion tape */
.opinion-tape {
  list-style: none;
  padding: 0;
  margin: 0;
}
.opinion-card {
  background: var(--warm-white);
  border: 1px solid var(--border);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.opinion-card:last-child { margin-bottom: 0; }
.opinion-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.opinion-author {
  color: var(--green-dark);
  font-weight: 600;
  font-size: 12px;
  font-family: var(--mono);
}
.opinion-date {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--mono);
}
.opinion-text {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--charcoal);
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* Sentiment badges */
.badge-sentiment-bullish,
.badge-sentiment-bearish,
.badge-sentiment-neutral {
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 2px 7px;
  line-height: 1.4;
}
.badge-sentiment-bullish { background: var(--green-dark); color: var(--warm-white); }
.badge-sentiment-bearish { background: #C44; color: white; }
.badge-sentiment-neutral {
  background: var(--off-white);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* Co-mentions */
.co-mentions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.co-mention-tag {
  background: var(--warm-white);
  border: 1px solid var(--border);
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--charcoal);
  font-family: var(--mono);
}
.co-mention-tag:hover { background: var(--green-pale); border-color: var(--green-light); }
.co-mention-tag .muted { color: var(--muted); }

@media (max-width: 1024px) {
  .equity-sidebar { max-height: 360px; }
}
@media (max-width: 640px) {
  .equity-detail-head { padding: 14px 16px; }
  .equity-section { padding: 16px; }
  .equity-detail-ticker { font-size: 22px; }
}

/* === Burger menu (mobile only) === */
.menu-toggle {
  display: none;
  width: 40px;
  height: 40px;
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-right: 12px;
}
.menu-toggle span {
  display: block;
  width: 18px;
  height: 1.5px;
  background: var(--charcoal);
}

/* Mobile: show burger, sidebar becomes overlay */
@media (max-width: 640px) {
  .menu-toggle { display: flex; }
  
  .sidebar {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--warm-white);
    border-right: 1px solid var(--border);
    z-index: 100;
    padding: 16px 0;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    flex-direction: column;
    justify-content: space-between;
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .sidebar-section-label { display: block; }
  .sidebar-footer { display: block; }
  .nav-item { 
    padding: 14px 24px !important;
    justify-content: flex-start !important;
  }
  .nav-label { display: inline !important; }
  
  /* Backdrop */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
  }
  .sidebar-backdrop.is-open {
    display: block;
  }
}
