/* QuantLabAI desktop layout layer (UI/UX Pro Max, 2026-11).
   Loaded after mobile.css on every base.html page; active only at desktop widths (>= 992px).
   Layout and type scale only — colors stay on the --q-* tokens.
   Rules applied: consistent container widths, comfortable gutters, readable line length (65-75 latin /
   ~45-55 CJK characters), one heading scale, persistent in-page navigation for long documents. */

@media (min-width: 992px) {
  body[data-route-name] {
    --q-desk-content: 1200px;   /* reading pages: documents, community, account */
    --q-desk-workspace: 1360px; /* data tools and administration */
    --q-desk-gutter: 32px;
    --q-desk-sticky-top: calc(var(--global-nav-header-row-height, 64px) + 24px);
  }

  /* ---------- Two container widths, always centered, never touching the window edge ---------- */
  body[data-route-name] :is(#main-content, .page-transition-shell__page) :is(.info-shell, .board-shell, .download-shell, .profile-main-container) {
    width: min(var(--q-desk-content), 100% - 2 * var(--q-desk-gutter));
    max-width: none;
    margin-inline: auto;
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-page { padding-inline: 0; }
  /* overflow:hidden makes .info-page a scroll container, which disables the sticky table of contents;
     clip keeps the decorative background clipped without that side effect. */
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-page:has(.info-document-nav) { overflow: clip; }

  body[data-route-name] :is(#main-content, .page-transition-shell__page) :is(
      .finmind-overview-shell, .active-etf-shell, main.radar-shell, .broker-radar-ai-wrap, .ih-shell, .admin-shell
    ),
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .custom-dashboard-page > .shell,
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .finmind-backtest-page > main.shell,
  body[data-route-name="main.finmind_snapshot_treemap"] :is(#main-content, .page-transition-shell__page) .shell {
    width: min(var(--q-desk-workspace), 100% - 2 * var(--q-desk-gutter));
    max-width: none;
    margin-inline: auto;
    padding-inline: 0;
  }

  /* ---------- Short items side by side instead of full-width stacks ---------- */
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .finmind-overview-metrics {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  /* The hero side panel is narrow: its facts read best as one column (emails and titles never break mid-word). */
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-hero-side .info-stat-grid { grid-template-columns: minmax(0, 1fr); }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-document .info-definition-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
  }

  /* ---------- One heading scale (the homepage keeps its editorial display face) ---------- */
  body[data-route-name]:not([data-route-name="main.index"]) :is(#main-content, .page-transition-shell__page) h1 {
    font-size: clamp(2rem, 1.2rem + 1.4vw, 2.5rem);
    line-height: 1.2;
    letter-spacing: -0.01em;
    text-wrap: balance;
  }
  body[data-route-name]:not([data-route-name="main.index"]) :is(#main-content, .page-transition-shell__page) :is(.info-document-section, .board-card, .board-side-card) h2 {
    font-size: 1.5rem;
    line-height: 1.3;
  }

  /* ---------- Long documents: sticky table of contents + readable measure ---------- */
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-shell:has(> .info-document-nav) {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    column-gap: 28px;
    row-gap: 24px;
    align-items: start;
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-shell:has(> .info-document-nav) > :not(.info-document-nav):not(.info-document) {
    grid-column: 1 / -1;
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-shell > .info-document-nav {
    position: sticky;
    top: var(--q-desk-sticky-top);
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 2px;
    max-height: calc(100vh - var(--q-desk-sticky-top) - 24px);
    overflow-y: auto;
    padding: 12px;
    border: 1px solid var(--q-line);
    border-radius: 16px;
    background: var(--q-paper);
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-shell > .info-document-nav::before {
    content: "本頁目錄";
    padding: 4px 12px 8px;
    color: var(--q-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-document-nav .info-nav-link {
    justify-content: flex-start;
    min-height: 40px;
    padding: 8px 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    font-size: 15px;
    font-weight: 600;
    text-align: left;
    box-shadow: none;
    transform: none;
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-document-nav .info-nav-link:hover,
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-document-nav .info-nav-link:focus-visible {
    color: var(--q-accent);
    background: var(--q-accent-soft);
    transform: none;
    box-shadow: none;
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-document-nav .info-nav-link[aria-current="true"] {
    color: var(--q-accent);
    background: var(--q-accent-soft);
    box-shadow: inset 3px 0 0 var(--q-accent);
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-document-section { scroll-margin-top: var(--q-desk-sticky-top); }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-document-section :is(p, li) {
    max-width: 46em;
    font-size: 16px;
    line-height: 1.8;
  }

  /* Reading text elsewhere: lead paragraphs and list copy stay within a comfortable measure. */
  body[data-route-name] :is(#main-content, .page-transition-shell__page) :is(.info-hero, .board-hero, .download-hero, .profile-hero) p {
    max-width: 46em;
  }
  body[data-route-name] :is(#main-content, .page-transition-shell__page) :is(.admin-shell, .container.mt-4) :is(.card-body > p, .form-text, small.text-muted) {
    max-width: 72ch;
  }
}

/* Wide screens: a little more breathing room around workspaces. */
@media (min-width: 1600px) {
  body[data-route-name] { --q-desk-gutter: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-route-name] :is(#main-content, .page-transition-shell__page) .info-document-nav .info-nav-link { transition: none; }
}
