/* Shared small-screen application shell and responsive touch targets. */
.mobile-menu-toggle,
.mobile-navigation-backdrop,
.mobile-navigation-drawer,
.mobile-bottom-navigation,
.mobile-subpage-back { display: none; }

@media (max-width: 991.98px) {
    body { overflow-x: hidden; }
    .mobile-frame { max-width: 100% !important; overflow-x: clip; }
    body:has(.chat-workspace.has-active-chat) .mobile-menu-toggle { display: none !important; }

    .mobile-menu-toggle {
        position: fixed; top: max(12px, env(safe-area-inset-top)); left: 14px; z-index: 1205;
        display: flex; width: 44px; height: 44px; flex-direction: column; align-items: center; justify-content: center;
        gap: 5px; padding: 0; border: 1px solid rgba(12,66,66,.1); border-radius: 14px;
        background: rgba(255,253,248,.96); color: #0c4242; box-shadow: 0 5px 18px rgba(24,48,42,.1);
        -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); cursor: pointer;
    }
    .mobile-subpage-back {
        position: fixed; top: max(12px, env(safe-area-inset-top)); left: 14px; z-index: 1205;
        display: grid; width: 44px; height: 44px; place-items: center;
        border: 1px solid rgba(12,66,66,.12); border-radius: 14px;
        background: rgba(255,253,248,.96); color: #0c4242;
        box-shadow: 0 5px 18px rgba(24,48,42,.1); text-decoration: none;
        -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    }
    .mobile-subpage-back svg { width: 22px; height: 22px; }
    .mobile-subpage-back[hidden] { display: none !important; }
    .mobile-menu-toggle span { display: block; width: 19px; height: 2px; border-radius: 2px; background: currentColor; transition: transform .2s ease, opacity .2s ease; }
    .mobile-menu-toggle[aria-expanded="true"] span:first-child { transform: translateY(7px) rotate(45deg); }
    .mobile-menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
    .mobile-menu-toggle[aria-expanded="true"] span:last-child { transform: translateY(-7px) rotate(-45deg); }

    .mobile-navigation-backdrop {
        position: fixed; inset: 0; z-index: 1200; display: block; background: rgba(20,35,34,.34);
        opacity: 0; transition: opacity .22s ease;
    }
    .mobile-navigation-backdrop[hidden] { display: none; }
    .mobile-navigation-backdrop.is-visible { opacity: 1; }
    .mobile-navigation-drawer {
        position: fixed; inset: 0 auto 0 0; z-index: 1210; display: block; width: min(304px, calc(100vw - 54px));
        padding: max(20px, env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
        overflow-x: hidden; overflow-y: auto; border-right: 1px solid #e7e2d5; background: #fbf9f1;
        box-shadow: 18px 0 48px rgba(15,41,38,.14); transform: translateX(-105%); visibility: hidden;
        transition: transform .24s cubic-bezier(.22,.7,.2,1), visibility .24s ease;
    }
    .mobile-navigation-drawer.is-open { transform: translateX(0); visibility: visible; }
    .mobile-navigation-close {
        position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; z-index: 2;
        display: grid; width: 36px; height: 36px; place-items: center; border: 1px solid #e7e2d5;
        border-radius: 50%; background: #fffdf8; color: #0c4242; font-size: 23px; line-height: 1;
    }
    .mobile-navigation-drawer .home-sidebar { display: block !important; position: static !important; width: 100%; padding: 8px 0 !important; }
    .mobile-navigation-drawer .home-sidebar-brand { display: flex; align-items: center; height: 60px; margin: 0 0 12px; }
    .mobile-navigation-drawer .home-sidebar-brand img { width: 60px; height: 56px; max-width: none; }
    .mobile-navigation-drawer .home-create-post {
        display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 48px;
        margin: 0 0 18px; padding: 10px 14px; border: 0; border-radius: 12px;
        background: #0c4242; color: #fff; font-size: 15px; font-weight: 650; text-decoration: none;
    }
    .mobile-navigation-drawer .home-create-post:hover { background: #083333; color: #fff; }
    .mobile-navigation-drawer .home-create-post svg { width: 20px; height: 20px; flex: 0 0 20px; }
    .mobile-navigation-drawer .home-side-nav { display: grid !important; gap: 5px; }
    .mobile-navigation-drawer .home-side-nav a {
        display: flex; min-height: 46px; align-items: center; gap: 12px; padding: 9px 12px;
        border-radius: 10px; color: #263f3f; font-size: 15px; font-weight: 500; text-decoration: none;
    }
    .mobile-navigation-drawer .home-side-nav a:hover,
    .mobile-navigation-drawer .home-side-nav a.active { background: #e8f0e3; color: #0c4242; }
    .mobile-navigation-drawer .home-side-nav svg,
    .mobile-navigation-drawer .home-side-nav img { width: 21px; height: 21px; flex: 0 0 21px; object-fit: contain; }
    .mobile-navigation-drawer .home-side-notification-badge { margin-left: auto; }

    .mobile-bottom-navigation {
        position: fixed; right: 0; bottom: 0; left: 0; z-index: 1100; display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(231,226,213,.95);
        background: rgba(251,249,241,.97); box-shadow: 0 -8px 24px rgba(24,48,42,.07);
        -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    }
    .mobile-bottom-navigation a {
        display: flex; min-width: 0; min-height: 48px; flex-direction: column; align-items: center; justify-content: center;
        gap: 3px; border-radius: 12px; color: #687876; text-decoration: none; font-size: 10px; font-weight: 600;
        line-height: 1.1; transition: background-color .16s ease, color .16s ease;
    }
    .mobile-bottom-navigation a.active { background: #e8f0e3; color: #0c4242; }
    .mobile-bottom-navigation svg { width: 20px; height: 20px; flex: 0 0 20px; }

    body.has-mobile-navigation:not(.embedded-chatboard) .page-content { min-width: 0; max-width: 100%; padding-bottom: 104px !important; }
    body:not(.embedded-chatboard) .page-content:not(.chat-page):not(.group-workspace-page):not(.group-workspace) { padding-top: 68px !important; }
    .page-content > *, .page-content section, .page-content article { min-width: 0; }
    .page-content img, .page-content video, .page-content canvas { max-width: 100%; }
    .page-content input, .page-content select, .page-content textarea { min-width: 0; }
    .home-sidebar { display: none !important; }

    .trade-journal-layout,
    .trade-show-layout,
    .home-layout,
    .notifications-layout,
    .settings-layout,
    .profile-layout,
    .user-profile-layout,
    .edit-post-layout { display: block !important; grid-template-columns: minmax(0,1fr) !important; width: 100%; max-width: 100%; }
    .trade-journal-content,
    .trade-show-content,
    .home-center,
    .home-right,
    .notifications-content,
    .settings-page,
    .profile-content,
    .user-profile-main,
    .edit-post-main { width: 100%; max-width: 100%; min-width: 0; }
    .home-right { position: static !important; }

    .dashboard-header { grid-template-columns: minmax(0,1fr) !important; gap: 12px !important; margin-bottom: 18px !important; }
    .performance-card, .top-actions, .recent-card, .side-card { min-width: 0; }
    .performance-card { padding: 18px 16px !important; }
    .top-actions, .recent-card, .side-card { padding: 16px !important; }
    .recent-head { align-items: stretch; }
    .trade-controls, .trade-toolbar, .recent-controls { flex-wrap: wrap; }
    .trades-table { width: 100% !important; min-width: 0 !important; table-layout: fixed; }
    .trades-table th, .trades-table td { overflow-wrap: anywhere; }
    .trades-table .date-cell { width: 44px; }
    .trades-table .type-cell { width: 60px; }
    .trades-table .pnl-cell { width: 74px; }
    .trades-table .actions-cell, .trades-table .actions-col { width: 32px; }

    .trade-form-page { width: 100%; max-width: 100%; padding: 0 0 22px; }
    .create-layout { grid-template-columns: minmax(0,1fr) !important; width: 100%; }
    .create-form-card, .create-sidebar > * { min-width: 0; }
    .form-grid { grid-template-columns: repeat(2, minmax(0,1fr)) !important; }

    .profile-card, .profile-summary, .notification-card, .settings-card,
    .group-details-hero, .group-info-card, .group-form-card, .show-card { max-width: 100%; }
    .profile-stats, .stats-row { grid-template-columns: repeat(3, minmax(0,1fr)); }
    .profile-tabs { overflow-x: auto; scrollbar-width: none; }
    .profile-tabs::-webkit-scrollbar { display:none; }
    .profile-tabs > * { flex: 0 0 auto; }

    .modal-dialog { width: calc(100vw - 24px); max-width: calc(100vw - 24px); margin: 12px auto; }
    .modal-dialog-centered { min-height: calc(100% - 24px); }

    /* Messages retain their two-pane behavior while giving the conversation full mobile width. */
    .page-content.chat-page { height: calc(100dvh - 74px) !important; min-height: calc(100dvh - 74px) !important; padding: 0 8px 8px !important; }
    .chat-rail { display: none !important; }
    .chat-workspace { grid-template-columns: minmax(0,1fr) !important; gap: 0 !important; }
    .chat-list-panel { grid-column: 1 !important; width: 100% !important; height: 100%; }
    .chat-list-heading { padding: 14px 14px 12px 58px !important; }
    .chat-list-scroll { overscroll-behavior: contain; }
    .chat-workspace.has-active-chat .chat-list-panel { display: none !important; }
    .chat-workspace.has-active-chat .chat-panel { display: flex !important; position: fixed !important; inset: 8px 8px calc(70px + env(safe-area-inset-bottom)) 8px !important; z-index: 1090 !important; }
    .chat-workspace.has-active-chat .chat-mobile-back { margin-left: 0 !important; }
    .chat-empty-state { padding: 22px 16px !important; }

    body.embedded-chatboard .mobile-frame { height: 100dvh !important; max-height: 100dvh !important; }

    /* Auth screens get a compact intro so the form stays near the top on phones. */
    .auth-page .mobile-frame { width: 100% !important; max-width: 100% !important; min-height: 100svh; }
    .auth-page .login-page {
        display: flex !important; width: 100%; max-width: 520px; min-height: 100svh;
        flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 18px;
        margin: 0 auto; padding: max(24px, env(safe-area-inset-top)) 18px 30px !important;
    }
    .auth-page .login-left { width: 100%; text-align: left !important; }
    .auth-page .login-left .brand-mirror { font-size: 32px; }
    .auth-page .login-left .brand-mirror span { margin-left: 4px; font-size: 13px; }
    .auth-page .login-left h1 { margin: 10px 0 8px; font-size: clamp(30px, 7vw, 38px); line-height: 1.08; }
    .auth-page .login-left .sub { max-width: 440px; margin: 0; font-size: 14px; line-height: 1.5; }
    .auth-page .login-left .feature { display: none !important; }
    .auth-page .login-card {
        width: 100%; max-width: none; margin: 0; padding: 24px 20px;
        border-radius: 19px; box-shadow: 0 8px 24px rgba(3,83,82,.07);
    }
    .auth-page .login-card h2 { font-size: 25px; }
    .auth-page .login-card .welcome-sub { margin-bottom: 18px; font-size: 14px; }
    .auth-page .login-card .input-group { margin-bottom: 12px; }
    .auth-page .login-card .input-group input { min-height: 50px; padding-top: 12px; padding-bottom: 12px; font-size: 16px; }
    .auth-page .login-card .input-icon { display: grid; width: 20px; height: 20px; place-items: center; color: #6b7c79; }
    .auth-page .login-card .input-icon svg { display: block; width: 19px; height: 19px; }
    .auth-page .login-card .general-btn { width: 100%; min-height: 50px; border-radius: 13px; }
    .auth-page .login-card .google-btn { min-height: 48px; padding: 11px 14px; }
    .auth-page .login-card label { line-height: 1.55; }
    .auth-page .login-card input[type="checkbox"] { accent-color: #0c7773; vertical-align: -1px; }

    /* Keep the profile back control clear of the fixed hamburger. */
    .mobile-frame:has(#editProfileForm) > .post-detail-header { gap: 12px; }
    .mobile-frame:has(#editProfileForm) > .post-detail-header .back-icon-btn { flex: 0 0 auto; margin-left: 54px; }
    .mobile-frame:has(#editProfileForm) > main.page-content {
        width: calc(100% - 28px); max-width: 620px; margin: 8px auto 26px; padding: 20px 18px 24px !important;
        border: 1px solid #e7e2d5; border-radius: 18px; background: #fffdf8; box-shadow: 0 8px 24px rgba(31,61,60,.05);
    }
    .mobile-frame:has(#editProfileForm) .profile-title { margin-bottom: 18px !important; color: #0c4242; font-family: "Source Serif 4", Georgia, serif; font-size: 23px; }
    .mobile-frame:has(#editProfileForm) .profile-photo-box { display: flex; align-items: center; gap: 14px; margin: 4px 0 22px; }
    .mobile-frame:has(#editProfileForm) .edit-profile-avatar { width: 64px; height: 64px; flex-basis: 64px; border-radius: 18px; }
    .mobile-frame:has(#editProfileForm) .setup .input-label { margin-bottom: 6px; color: #365b59; font-weight: 650; }
    .mobile-frame:has(#editProfileForm) .setup .input-group input,
    .mobile-frame:has(#editProfileForm) .setup .form-control { min-height: 48px; border: 1px solid #d9ded4; border-radius: 11px; background: #fff; color: #193b40; font-size: 16px; }
    .mobile-frame:has(#editProfileForm) .setup .bio-input { min-height: 104px; }
    .mobile-frame:has(#editProfileForm) #editProfileForm > button { width: 100%; min-height: 48px; border-radius: 999px; background: #0c4242; color: #fff; }
    .auth-page .login-card a { color: #0c7773; }
}

@media (max-width: 575.98px) {
    .mobile-menu-toggle, .mobile-subpage-back { top: max(10px, env(safe-area-inset-top)); left: 10px; width: 42px; height: 42px; }
    .page-content:not(.chat-page) { padding-right: 12px !important; padding-left: 12px !important; }
    .welcome-block h1 { font-size: 23px !important; }
    .performance-card { padding: 16px 13px !important; }
    .metrics { grid-template-columns: repeat(2, minmax(0,1fr)) !important; }
    .metric { padding: 9px 8px !important; }
    .metric:nth-child(odd) { border-right: 1px solid #e6dfc8 !important; }
    .metric:nth-child(even) { border-right: 0 !important; }
    .metric:nth-child(n+3) { border-top: 1px solid #e6dfc8 !important; }
    .metric b { font-size: 14px !important; }
    .pnl-big { font-size: 27px !important; }
    .form-grid { grid-template-columns: minmax(0,1fr) !important; }
    .grid2 { grid-template-columns: minmax(0,1fr) !important; }
    .profile-stats, .stats-row { gap: 6px !important; }
    .stat-box { min-width: 0; padding: 10px 4px !important; }
    .mobile-bottom-navigation { padding-right: 6px; padding-left: 6px; }
    .mobile-bottom-navigation a { min-height: 46px; font-size: 9px; }
    .mobile-bottom-navigation svg { width: 19px; height: 19px; }
    .trades-table th, .trades-table td { padding: 8px 4px !important; font-size: 11px !important; }
    .trades-table .date-cell { width: 38px; }
    .trades-table .type-cell { width: 50px; }
    .trades-table .pnl-cell { width: 66px; }
    .trades-table .actions-cell, .trades-table .actions-col { width: 27px; }
    .trades-table .symbol-cell { width: auto; }
    .trades-table .symbol-cell b { overflow-wrap: anywhere; }
    .auth-page .login-page { gap: 16px; padding-right: 14px !important; padding-left: 14px !important; }
    .auth-page .login-left .brand-mirror { font-size: 29px; }
    .auth-page .login-left .brand-mirror span { font-size: 12px; }
    .auth-page .login-left h1 { font-size: clamp(28px, 8vw, 34px); }
    .auth-page .login-card { padding: 21px 17px; }
    .auth-page .login-card h2 { font-size: 23px; }
    .auth-page .login-card .welcome-sub { margin-bottom: 16px; }
    .auth-page .login-card small { line-height: 1.45; }
    .auth-page #emailOtpModal .modal-body,
    .auth-page #otpModal .modal-body,
    .auth-page #regOtpModal .modal-body { padding: 24px 15px 20px; }
    .auth-page #emailOtpModal .otp-wrapper,
    .auth-page #otpModal .otp-wrapper,
    .auth-page #regOtpModal .otp-wrapper { gap: 5px; }
    .auth-page #emailOtpModal .otp-input,
    .auth-page #otpModal .otp-input,
    .auth-page #regOtpModal .otp-input { height: 48px; font-size: 19px; }
}

@media (max-width: 359.98px) {
    .trades-table th:nth-child(3), .trades-table .type-cell { display: none !important; }
    .trades-table .date-cell { width: 36px; }
    .trades-table .pnl-cell { width: 62px; }
}

@media (prefers-reduced-motion: reduce) {
    .mobile-menu-toggle span, .mobile-navigation-backdrop, .mobile-navigation-drawer,
    .mobile-bottom-navigation a { transition-duration: .01ms !important; }
}


/* Phone refinements: keep the social feed focused and trade forms comfortably inset. */
@media (max-width: 991.98px) {
    .home .floating-action { display: none !important; }
    body.user-profile .page-content.user-profile:not(.chat-page):not(.group-workspace-page):not(.group-workspace) {
        padding-top: 8px !important;
    }
    body.user-profile .mobile-subpage-back { display: none !important; }
    body.user-profile .user-profile .profile-header > .more-btn {
        background: #f5f4ed !important; border: 1px solid #e7e1d3 !important; color: #0c4242 !important;
        box-shadow: none !important;
    }
    body.user-profile .user-profile .profile-header > .more-btn svg { display: block !important; fill: #0c4242 !important; }
    body.post-details .mobile-frame > .post-detail-header:not(.board) {
        padding: 10px 22px !important; margin: 0 !important;
    }
    body.post-details .mobile-frame > main.page-content.post-details {
        padding-top: 8px !important; padding-right: 14px !important; padding-left: 14px !important;
    }
    body.post-details .mobile-frame > main.page-content.post-details > .post-card { margin-top: 0 !important; }
    .trade-form-page {
        width: 100% !important; max-width: 760px !important; margin: 0 auto !important;
        padding: 0 16px 28px !important; box-sizing: border-box;
    }
    .trade-form-page > .back-link { display: inline-flex; margin: 18px 0 18px !important; }
    .trade-form-page .create-top { margin: 0 0 18px !important; text-align: left; }
    .trade-form-page .create-top h1 { font-size: clamp(29px, 7vw, 37px) !important; line-height: 1.12; }
    .trade-form-page .create-top .subtitle { font-size: 15px; line-height: 1.45; }
    .trade-form-page .create-layout { width: 100%; }
    .trade-form-page .create-form-card, .trade-form-page .form-card { padding: 18px 16px !important; }
    body.mobile-keyboard-open .mobile-bottom-navigation,
    body.mobile-keyboard-open .mobile-menu-toggle,
    body.mobile-keyboard-open .floating-action { display: none !important; }
    body.mobile-keyboard-open:not(.embedded-chatboard) .page-content { padding-bottom: 20px !important; }
    body.mobile-keyboard-open .mobile-frame { padding-bottom: 8px !important; }
    body.mobile-keyboard-open .page-content.chat-page { height: 100dvh !important; min-height: 100dvh !important; }
    body.mobile-keyboard-open .chat-workspace.has-active-chat .chat-panel {
        inset: 8px 8px calc(8px + env(safe-area-inset-bottom)) 8px !important;
    }
}

/* The chat safety note belongs to the scrollable message history, separate from the composer. */
.chat-container .chat-encryption-note {
    display: block; clear: both; margin: 18px 2px 8px; padding: 11px 2px 0;
    border-top: 1px solid rgba(120,134,140,.22); color: #78868c; font-size: 12px; line-height: 1.45;
}
