/* Keep the workspace fluid while allowing grid and flex children to shrink. */
:root {
  --page-gutter: clamp(16px, 2.2vw, 48px);
}

body { min-width: 0; }

.topbar {
  height: auto;
  min-height: 68px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: clamp(16px, 2vw, 32px);
  padding: 12px var(--page-gutter);
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  min-width: 0;
}

.topnav { flex: 0 0 auto; }
.nav-link, .theme-switch button { white-space: nowrap; }
.theme-switch { flex: 0 0 auto; }
.search-wrap { min-width: 0; z-index: 2; }
.search-wrap input { min-width: 0; }
.search-item { gap: 12px; }
.search-item > * { min-width: 0; }

.main-content, .footer {
  width: calc(100% - var(--page-gutter) * 2);
  max-width: none;
}

.hero-strip { gap: 28px; }
.hero-strip > div:first-child { min-width: 0; }
.hero-status { flex-shrink: 0; }
.ticker-strip { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.ticker-top, .ticker-price { flex-wrap: wrap; }
.ticker-price { row-gap: 4px; }

.workspace {
  grid-template-columns: minmax(0, 1.72fr) minmax(320px, .78fr);
}

.panel, .panel-head > div, .symbol-block, .event-copy,
.metric, .news-meta > *, .check-row > div,
.global-news-card, .principle-grid > article { min-width: 0; }

.panel-head { gap: 16px; }
.chart-head { flex-wrap: wrap; }
.symbol-row { flex-wrap: wrap; }
.chart-actions { flex-wrap: wrap; gap: 10px; }
.chart-stage { height: clamp(320px, 28vw, 500px); }
.chart-footer { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.chart-footer > div { min-width: 0; }
.chart-footer strong { overflow-wrap: anywhere; }
.event-source { overflow-wrap: anywhere; }
.news-selects { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.source-filter { overflow-x: visible; }

.news-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}

.principle-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}

.news-item, .global-news-card, .event-copy, .watch-main,
.check-row, .dialog-meta, .dialog-summary, .method-note,
.source-links, .reason-list { overflow-wrap: anywhere; }

.news-dialog {
  max-width: calc(100% - 24px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
}

.dialog-header { flex-wrap: wrap; }
.dialog-header .ghost-btn { flex-shrink: 0; }
.primary-link { max-width: 100%; overflow-wrap: anywhere; }
.toast { max-width: calc(100% - 24px); width: max-content; }

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px 20px;
  }

  .brand { grid-column: 1; grid-row: 1; }
  .header-actions { grid-column: 2; grid-row: 1; }
  .search-wrap { grid-column: 1 / -1; grid-row: 2; }

  .ticker-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ticker-card { border-bottom: 1px solid var(--line-soft); }
  .ticker-card:nth-child(3n) { border-right: 0; }
  .ticker-card:nth-last-child(-n + 3) { border-bottom: 0; }
}

@media (max-width: 1060px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .hero-strip { align-items: flex-start; flex-direction: column; gap: 18px; }
  .hero-status { min-width: 0; justify-content: flex-start; }
  .chart-stage { height: clamp(320px, 43vw, 440px); }
  .footer { grid-template-columns: auto 1fr; gap: 16px; }
  .footer p { grid-column: 1 / -1; grid-row: 2; text-align: left; }
  .footer > span { justify-self: end; }
}

@media (max-width: 700px) {
  :root { --page-gutter: 16px; }

  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 10px 12px; }
  .header-actions { display: contents; }
  .theme-switch { grid-column: 2; grid-row: 1; justify-self: end; }
  .topnav { grid-column: 1 / -1; grid-row: 3; width: 100%; gap: 6px; }
  .nav-link { flex: 1 1 0; min-width: 0; }

  .main-content { padding-top: 16px; }
  .hero-strip { padding: 16px 0 22px; }
  .ticker-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ticker-card { padding: 12px; }
  .ticker-card:nth-child(3n) { border-right: 1px solid var(--line-soft); }
  .ticker-card:nth-child(2n) { border-right: 0; }
  .ticker-card:nth-last-child(-n + 3) { border-bottom: 1px solid var(--line-soft); }
  .ticker-card:nth-last-child(-n + 2) { border-bottom: 0; }
  .ticker-top { gap: 4px; }

  .panel-head, .panel-head.compact { padding: 16px; gap: 12px; }
  .chart-head { align-items: flex-start; }
  .chart-actions { width: 100%; justify-content: space-between; }
  .chart-stage { height: 320px; padding-inline: 6px; }
  .chart-hint { left: 16px; }
  .chart-footer { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-footer > div { padding: 12px 14px; }
  .chart-footer > div:nth-child(2n) { border-right: 0; }
  .chart-footer > div:nth-child(-n + 2) { border-bottom: 1px solid var(--line-soft); }

  .event-timeline { padding-inline: 16px; }
  .event-row { grid-template-columns: 60px minmax(0, 1fr); gap: 8px 12px; }
  .event-axis { display: none; }
  .event-copy { grid-column: 2; grid-row: 1 / span 2; }
  .impact { grid-column: 1; grid-row: 2; min-width: 0; text-align: left; }
  .impact-meter { width: 56px; }

  .page-panel { min-height: 0; padding: 22px 18px; }
  .principle-grid { margin-top: 26px; }
  .principle-grid article { padding: 20px; }
  .news-dialog { padding: 18px; }
  .dialog-header { gap: 10px; }
  .dialog-header .section-kicker { flex: 1 1 170px; }
  .check-row { padding: 12px; gap: 10px; }
}

@media (max-width: 400px) {
  :root { --page-gutter: 12px; }

  .topbar { column-gap: 8px; }
  .brand { gap: 8px; }
  .brand-beta { display: none; }
  .theme-switch { gap: 2px; }
  .theme-switch button { padding-inline: 8px; }
  .search-wrap input { padding-right: 14px; }
  .search-wrap kbd { display: none; }
  .nav-link { padding-inline: 8px; }
  .panel-head.compact { flex-wrap: wrap; }
  .symbol-row { gap: 7px; }
  .period-tabs button { padding-inline: 7px; }
  .news-selects { gap: 6px; }
  .metric { padding: 14px; }
  .page-panel { padding: 20px 14px; }
  .footer { column-gap: 10px; }
  .news-dialog { padding: 16px; }
}
