@media (min-width: 1024px) {
    /* The inline .nav carries 6 items here; together with a fixed 320px search
       box the header content is wider than the viewport until ~1365px. Let the
       search field give up width before the nav wraps or the header overflows.
       Scoped to >=1024px so the tablet/mobile widths below stay as they are. */
    .search-wrap {
        min-width: 0;
    }

    .search-field {
        min-width: 0;
        flex: 0 1 auto;
        max-width: 100%;
    }

    .input-search {
        /* width: 100%; */
        max-width: 320px;
        min-width: 120px;
    }

    .header-more-wrap {
        display: block;
    }
    .main {
        grid-template-columns: 300px 1fr 280px;
        gap: var(--sp-2);
    }

    .col-right {
        order: 3;
        display: flex !important;
    }

    .chart-wrap {
        height: 560px;
        min-height: 560px;
    }
}

@media (max-width: 1024px) {
    .chart-toolbar {
        flex-direction: column;
    }

    .chart-ohlc span {
        display: flex;
        gap: 4px;
    }

    .col-left {
        order: 1;
        display: flex;
    }

    .bottom-section-header {
        flex-direction: column;
    }

    .bottom-section-header .section-label {
        width: 100%;
    }
}

/* TABLET */
@media (min-width: 768px) and (max-width: 1023px) {
    .col-q {
        padding-left: 10px;
    }
    .col-price {
        padding-left: 10px;
    }
    .col-chg {
        padding-left: 10px;
    }
    .col-ticker {
        padding-left: 10px;
    }

    .nav {
        display: none;
    }
    .col-center {
        order: 1;
    }
    .col-left {
        order: 2;
        display: flex !important;
    }
    .col-right {
        order: 3;
    }
    .main {
        grid-template-columns: 1fr;
        padding: var(--sp-2);
        gap: var(--sp-2);
    }
    .header-inner {
        padding: 0 var(--sp-2);
        height: 48px;
        gap: var(--sp-2);
    }
    .search-kbd {
        display: none;
    }

    .search-dropdown {
        left: 0;
        right: auto;
        width: min(400px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
    }
    .logo-wordmark {
        font-size: 14px;
    }
    .logo-q {
        width: 20px;
        height: 20px;
    }
    .card {
        padding: var(--sp-3);
    }
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--sp-1);
    }
    .stat-cell {
        padding: var(--sp-1) var(--sp-2);
    }
    .chart-wrap {
        height: auto;
        min-height: 260px;
    }
    #chart-container {
        min-height: 180px;
    }
    .chart-toolbar {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--sp-2);
        padding: var(--sp-2);
    }
    .chart-ohlc {
        display: none;
    }
    .qscore-ring {
        width: 44px;
        height: 44px;
    }
    .qscore-ring svg {
        width: 55px;
        height: 55px;
    }
    .qscore-val {
        font-size: var(--text-md);
    }
    .detail-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .detail-tab {
        white-space: nowrap;
        padding: var(--sp-2) var(--sp-3);
    }
    .insight-table-header {
        font-size: 9px;
    }
    .insight-row {
        font-size: var(--text-xs);
    }
    .notif-dropdown {
        width: min(340px, calc(100vw - 24px));
        max-width: calc(100vw - 16px);
        right: 0;
        left: auto;
        max-height: min(70vh, calc(100dvh - 120px));
    }
    .alert-btn span:not(.alert-count) {
        display: none;
    }
    .theme-toggle-btn {
        width: 30px;
        height: 30px;
        font-size: var(--text-sm);
    }
    .ticker-tape {
        height: 30px;
    }
    .ticker-item {
        font-size: 10px;
        padding: 0 var(--sp-2);
    }
    .col-left,
    .col-right {
        width: 100%;
    }

    .news-grid {
        grid-template-columns: 1fr !important;
    }
    .overview-metrics {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .flow-row {
        font-size: var(--text-xs);
    }
    .screener-filters {
        flex-direction: column;
    }
    .filter-select {
        width: 100%;
    }
    .screener-table {
        font-size: var(--text-xs);
        display: block;
        overflow-x: auto;
    }
    .screener-table th,
    .screener-table td {
        padding: var(--sp-1) var(--sp-2);
        white-space: nowrap;
    }
    #community-feed {
        max-height: 280px;
    }
    .comment-card {
        padding: var(--sp-2);
    }
    .sentiment-btn {
        padding: var(--sp-1) var(--sp-1);
        font-size: 9px;
    }
    .sentiment-btn i {
        font-size: var(--text-xs);
    }
    .scroll-x-inner {
        min-width: 0 !important;
    }
    .paywall-banner {
        font-size: var(--text-xs);
        padding: var(--sp-2) var(--sp-3);
    }
    .paywall-banner span {
        font-size: var(--text-xs);
    }
    .qscore-modal {
        width: calc(100vw - 32px);
        max-width: 380px;
        padding: var(--sp-4);
    }
    .onboard-option {
        padding: var(--sp-3) var(--sp-2);
    }
    .onboard-option-icon {
        width: 36px;
        height: 36px;
        font-size: var(--text-md);
    }
    .onboard-chip {
        font-size: var(--text-xs);
        padding: var(--sp-1) var(--sp-2);
    }

    .onboard-options.cols-2,
    .onboard-options.cols-3 {
        grid-template-columns: 1fr;
    }
    .onboard-container {
        padding: var(--sp-4) var(--sp-3);
    }
    .onboard-title {
        font-size: var(--text-xl);
    }
    .onboard-summary-grid {
        grid-template-columns: 1fr;
    }

    .btn-upgrade {
        display: block;
    }

    /* HEADER SCREEN Quantiverse */

    .vertical-scroll-change-image {
        grid-template-columns: 1fr !important;
    }

    .navbar-toggler-icon {
        background-image: url("../../images/icon-sp-menu.svg");
    }

    .navbar-collapse {
        flex-basis: auto;
    }

    .navbar-toggler {
        order: 3;
    }
    /* LOGIN */

    .right {
        padding: 20px;
    }

    .tab {
        flex-wrap: nowrap !important;
    }
}
/* MOBILE */
@media (max-width: 767px) {
    .search-kbd {
        display: none;
    }

    .nav {
        display: none;
    }
    .main {
        grid-template-columns: 1fr;
        padding: var(--sp-2);
        gap: var(--sp-2);
    }

    .user-info-text {
        display: none;
    }

    .input-search {
        padding-left: 34px;
        padding-right: var(--sp-3);
    }

    .search-dropdown {
        max-height: 330px;
        left: 0;
        right: auto;
        width: 100%;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .portfolio-input-grid {
        grid-template-columns: 1fr;
    }

    .logo-wordmark {
        font-size: 12px;
    }
    .logo-q {
        width: 18px;
        height: 18px;
    }
    .theme-toggle-btn {
        height: 29px !important;
    }
    .alert-btn {
        height: 29px !important;
    }
    .input-search {
        font-size: 10px;
        width: 100%;
    }
    .card {
        padding: var(--sp-2);
        border-radius: var(--r-md);
    }
    .card-inner {
        padding: var(--sp-2);
    }
    .card-title {
        font-size: var(--text-base);
    }
    .card-title i {
        font-size: var(--text-xs);
    }
    .stats-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .stat-cell {
        padding: var(--sp-1);
    }
    .stat-label {
        font-size: 9px;
    }
    .stat-value {
        font-size: var(--text-xs);
    }
    .tab-pills {
        flex-wrap: wrap;
        gap: var(--sp-1);
    }
    .tab-pill {
        font-size: 10px;
        padding: 3px 8px;
    }
    .tab-item {
        font-size: 10px;
        padding: var(--sp-1) var(--sp-2);
    }
    .detail-tab {
        font-size: 10px;
        padding: var(--sp-1) var(--sp-2);
    }
    .list-row {
        padding: var(--sp-1) var(--sp-2);
        gap: var(--sp-2);
    }
    .ticker-logo {
        width: 24px;
        height: 24px;
        font-size: 8px;
    }
    .ticker-logo-sm {
        width: 20px;
        height: 20px;
        font-size: 7px;
    }
    .footer-disclaimer {
        font-size: 9px;
    }
    .footer-copyright {
        font-size: 9px;
        flex-direction: column;
        gap: var(--sp-1);
    }
    .onboard-container {
        padding: var(--sp-4) var(--sp-2);
    }
    .onboard-title {
        font-size: var(--text-lg);
    }
    .onboard-options.cols-2,
    .onboard-options.cols-3 {
        grid-template-columns: 1fr;
    }
    .onboard-summary-grid {
        grid-template-columns: 1fr;
    }
    .user-menu {
        right: 5px;
        width: 200px;
    }
    /* Header is now two rows (84px) — keep the panel clear of the search row. */
    .notif-dropdown {
        position: fixed;
        top: 88px;
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 100px);
        z-index: 250;
    }

    /* Fluid instead of a fixed 255px at left:125px, which overflowed the
       viewport on screens narrower than 380px. */
    .community-bar {
        bottom: 15px;
        left: 12px;
        right: 12px;
        width: auto;
        max-width: 255px;
        margin-inline: auto;
        justify-content: center;
        padding: var(--sp-2) var(--sp-3);
    }
    .community-bar-live {
        min-width: 0;
    }
    .community-bar-text,
    .community-bar-info {
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .community-widget {
        bottom: 72px;
        right: 8px;
        left: 8px;
        width: auto;
        border-radius: var(--r-lg);
    }

    .qscore-ring svg {
        width: 55px;
        height: 55px;
    }

    .toggle input:checked + .toggle-track::before {
        transform: translateX(16px);
        background: var(--brand);
    }

    .overview-metrics {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .news-grid {
        grid-template-columns: 1fr !important;
    }
    .footer-links {
        gap: var(--sp-3);
        flex-wrap: wrap;
    }
    .header-right {
        gap: var(--sp-1);
    }
    .col-center {
        order: 2;
    }
    .col-left {
        order: 1;
        display: flex !important;
    }
    .col-right {
        order: 3;
    }

    .chart-toolbar {
        display: flex;
        flex-direction: column;
        gap: var(--sp-2);
    }

    .spot-search-btn {
        position: relative;
    }

    .btn-start-for-free {
        display: none;
    }

    .text-alerts {
        display: none;
    }

    .btn-signin-login {
        padding: 5px 10px;
    }

    .col-q {
        padding-left: 10px;
    }
    .col-price {
        padding-left: 10px;
    }
    .col-chg {
        padding-left: 10px;
    }
    .col-ticker {
        padding-left: 10px;
    }

    .text-alerts {
        display: none;
    }

    /* On mobile the bar wraps onto two rows: logo + actions on top, the search
       field on a full-width row of its own. Without this the search box is
       squeezed between the logo and the action cluster and the header breaks. */
    .header-inner {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        height: auto;
        padding: var(--sp-2);
        row-gap: var(--sp-2);
    }

    /* Row 1 is pinned to 34px (the hamburger) so the header height stays
       predictable — .notif-dropdown below depends on it. */
    .logo {
        flex: 1 1 auto;
        min-width: 0;
        height: 34px;
    }

    .header-inner .logo img {
        width: auto;
        max-width: 120px;
        max-height: 100%;
        margin-bottom: 0;
    }

    .header-right {
        flex: 0 0 auto;
        margin-left: auto;
    }

    /* order pushes it past the logo/actions so it always starts the 2nd row. */
    .search-wrap {
        order: 10;
        flex: 1 0 100%;
        width: 100%;
        justify-content: stretch;
    }

    .search-field {
        width: 100%;
        max-width: none;
    }

    .search-wrap .input-search {
        width: 100%;
        font-size: var(--text-sm);
        padding: 6px var(--sp-3) 6px 32px;
    }

    .search-wrap .search-icon {
        left: 12px;
        font-size: var(--text-xs);
    }

    /* Base rule centers the panel with translateX(-50%); the field is now
       full-width, so anchor it to the field's own box instead. */
    .search-dropdown {
        transform: none;
    }

    .search-dropdown.show {
        animation-name: dropdown-in-top;
    }

    .nav {
        display: none;
    }

    .btn-upgrade {
        padding: var(--sp-2) var(--sp-3);
    }

    .qscore-container {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .spot-search-input {
        position: absolute;
        top: 33px;
        right: 0px;
    }

    .stock-search-dd {
        top: 56px !important;
    }

    .spotlight-ticker {
        display: flex;
        justify-content: center;
    }

    .spotlight-metrics__item {
        display: flex;
        justify-content: center;
    }
}

/* ═══════════════ MOBILE NAV (hamburger) ═══════════════ */
/* Hidden on desktop — the inline .nav in the header is used there instead. */
.mobile-nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    background: transparent;
    color: var(--text-secondary);
    font-size: 15px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.mobile-nav-toggle:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
}

.mobile-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 200;
    flex-direction: column;
    gap: 2px;
    padding: var(--sp-2);
    /* Opaque (not --header-bg, which is semi-transparent) so the ticker tape
       underneath doesn't bleed through and the panel reads as one surface
       with the header bar — see .header.mobile-nav-open below. */
    background: var(--bg-surface-1);
    border-bottom: 1px solid var(--border-subtle);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

/* While the menu is open the bar drops its translucency so the header and the
   panel share one continuous background. */
.header.mobile-nav-open {
    background: var(--bg-surface-1);
    backdrop-filter: none;
}

.mobile-nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border-radius: var(--r-md);
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-secondary);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.mobile-nav-item i {
    width: 18px;
    text-align: center;
    font-size: 13px;
}

.mobile-nav-item:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
}

.mobile-nav-item.active {
    color: var(--brand);
    background: var(--brand-dim);
}

.mobile-nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.35);
}

/* Show the hamburger + dropdown only where the inline .nav is hidden (<1024px). */
@media (max-width: 1023px) {
    /* Anchor the dropdown to the top bar (.header-inner) so it sits flush
       against the header instead of below the ticker tape. */
    .header-inner {
        position: relative;
    }

    .mobile-nav-toggle {
        display: inline-flex;
    }

    .mobile-nav.show {
        display: flex;
    }

    .mobile-nav-backdrop.show {
        display: block;
    }
}
