/* Sonar on phones and small tablets (up to 900px wide). Loaded after the other stylesheets, so it only overrides the
 * desktop layout on small screens: a compact top bar with a menu button, no sideways scrolling, tighter spacing,
 * one column, and an app-like Assistant with the chat list folded away. */

.nav-toggle, .as-list-toggle, .form-panel-caret { display: none; }

@media (max-width: 900px) {
    /* ---- Top bar: logo + menu button; the navigation opens below it ---- */
    /* flex: none - the desktop "240px wide" would otherwise become "240px tall" in the stacked layout */
    .sidebar { flex: none; width: 100%; position: sticky; top: 0; z-index: 900; max-height: 100vh; overflow-y: auto; }
    .sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 8px 12px 8px 14px; }
    .sidebar-logo { height: 34px; width: 132px; margin: 0; }
    .sidebar-header .sidebar-subtitle { display: none !important; }
    .nav-toggle { display: inline-flex; align-items: center; gap: 0.4rem; width: auto; margin: 0; padding: 0.45rem 0.8rem; min-height: 40px;
        background: rgba(255, 255, 255, 0.08); color: #fff; border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 8px;
        font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; box-shadow: none; }
    .nav-toggle i { font-size: 1.2rem; }
    .sidebar-user, .sidebar-nav, .sidebar-footer { display: none !important; }
    body.nav-open .sidebar-user { display: flex !important; padding: 4px 14px 10px; }
    body.nav-open .sidebar-nav { display: flex !important; flex-direction: column; flex-wrap: nowrap; padding: 0 12px 4px; }
    body.nav-open .sidebar-footer { display: flex !important; flex-direction: column; gap: 0; padding: 4px 12px 12px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
    .nav-btn { flex: none; width: 100%; min-width: 0; justify-content: flex-start; text-align: left; min-height: 44px; }

    /* ---- Page and panels ---- */
    .main-content { padding: 0.75rem; }
    .panel { padding: 1rem; border-radius: 10px; }
    .dashboard-split { gap: 1rem; }
    .form-panel, .feed-panel { min-width: 0; width: 100%; }
    .feed-header-wrapper { flex-wrap: wrap; gap: 0.6rem; align-items: flex-start; }
    .feed-header-wrapper h2 { font-size: 1.35rem; }
    .feed-header-buttons, .pw-header-buttons { flex-wrap: wrap; gap: 0.4rem; }
    .feed-header-buttons .action-btn, .feed-header-buttons button { margin: 0; }
    .filter-bar { padding: 0.7rem; gap: 0.5rem; margin-bottom: 1rem; }
    .filter-bar input, .filter-bar select { flex: 1 1 calc(50% - 0.5rem); min-width: 0; }
    .filter-bar input[type="text"], .filter-bar input[type="search"] { flex-basis: 100%; }
    input, select, textarea { font-size: 16px; } /* 16px stops iPhones from zooming in on every field */

    /* ---- Market Feed: the intel form folds shut (tap the title) ---- */
    .form-panel { position: static; }
    .form-panel > h2 { display: flex; align-items: center; justify-content: space-between; cursor: pointer; margin: 0; font-size: 1.15rem; }
    .form-panel-caret { display: inline-block; transition: transform 0.2s; font-size: 1.1rem; }
    .form-panel.open .form-panel-caret { transform: rotate(180deg); }
    .form-panel:not(.open) > :not(h2) { display: none !important; }
    .form-panel.open > h2 { margin-bottom: 1rem; }
    .intel-card { padding: 1rem 1rem 1rem 1.2rem; overflow-wrap: anywhere; }
    .intel-card:hover { transform: none; }

    /* Tab rows wrap instead of hiding tabs off-screen */
    .feed-tabs { flex-wrap: wrap; gap: 0.2rem 0.9rem; overflow-x: visible; white-space: normal; }
    .an-tabs button { padding: 0.5rem 0.7rem; font-size: 0.85rem; }

    /* ---- Market Watch ---- */
    .pw-card-actions a, .pw-card-actions button { font-size: 1.1rem; padding: 0.3rem 0.35rem; }
    .pw-stats-bar { gap: 0.6rem; }
    .pw-stat { min-width: calc(50% - 0.3rem); flex-basis: calc(50% - 0.3rem); padding: 0.8rem; }
    .pw-stat-value { font-size: 1.3rem; }
    .pw-insights-grid { padding: 0 0.7rem 0.7rem; }
    .pw-grid { grid-template-columns: 1fr; gap: 0.8rem; }
    .pw-card:hover { transform: none; }
    .pw-view-toggle { max-width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .pw-view-toggle button { white-space: nowrap; flex: none; }
    .pw-detail-source { grid-template-columns: 1fr 1fr; }

    /* ---- Tables scroll sideways inside their box instead of widening the page ---- */
    .mkt-table .mkt-title-cell { min-width: 180px; }

    /* ---- Popups: nearly full screen ---- */
    .modal-content { width: calc(100% - 1rem); max-width: none; padding: 1.2rem 1rem; max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); border-radius: 10px; }

    /* ---- Assistant: fills the screen below the top bar; the chat list folds away behind "Chats" ---- */
    .as-panel { flex-direction: column; height: calc(100vh - 82px); height: calc(100dvh - 82px); min-height: 420px; overflow: hidden; }
    .as-sidebar { width: 100%; flex: none; border-right: none; border-bottom: 1px solid var(--border); border-radius: 10px 10px 0 0; padding: 0.9rem 0.75rem 0.6rem; gap: 0.6rem; }
    .as-sidebar-top { display: flex; gap: 0.5rem; }
    .as-sidebar-top .as-new-btn { flex: 1; }
    .as-list-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; min-height: 40px; padding: 0 0.9rem; border: 1px solid var(--border-strong);
        border-radius: 8px; background: var(--surface); color: var(--primary); font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
    .as-sidebar.open .as-list-toggle { border-color: var(--secondary); color: var(--secondary); }
    .as-sidebar:not(.open) > :not(.as-sidebar-top) { display: none !important; }
    .as-sidebar.open { max-height: 70%; overflow-y: auto; }
    .as-chat-list { max-height: none; flex: none; overflow: visible; } /* the open panel scrolls as a whole, the list doesn't get squeezed */
    .as-chat-item { padding-top: 0.6rem; padding-bottom: 0.6rem; }
    .as-chat-btn { opacity: 1; font-size: 1.05rem; padding: 0.35rem; }
    .as-main { flex: 1; min-height: 0; }
    .as-main::before { display: none; }
    .as-messages { flex: 1; min-height: 0; max-height: none; padding: 0.9rem 0.75rem; }
    .as-msg { max-width: 100%; }
    .as-user { max-width: 88%; }
    .as-answer { padding: 0.7rem 0.85rem; }
    .as-form { padding: 0.6rem 0.75rem 0.2rem; }
    .as-disclaimer { padding: 0 0.75rem 0.6rem; font-size: 0.7rem; }
    .as-chat-head { gap: 0.5rem; }
    .as-examples { flex-direction: column; align-items: stretch; }
}
