/* Phone + small-tablet shell — keeps the desktop desk intact above 900px. */

.mobile-only {
    display: none !important;
}

.login-mobile-welcome {
    display: none;
}

.mobile-page-title {
    display: none;
}

.mobile-nav-scrim,
.mobile-tabbar {
    display: none;
}

@media (max-width: 900px) {
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: inline-flex !important;
    }

    html, body {
        height: 100%;
        overflow: hidden;
        -webkit-text-size-adjust: 100%;
    }

    .app-shell {
        height: 100dvh;
        height: 100svh;
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .mobile-nav-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 70;
        background: rgba(8, 12, 18, 0.55);
        backdrop-filter: blur(4px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    .app-shell.mobile-nav-open .mobile-nav-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(86vw, 320px);
        max-width: 320px;
        z-index: 80;
        transform: translateX(-108%);
        opacity: 1;
        pointer-events: none;
        border-right: 1px solid var(--card-border);
        box-shadow: none;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        transition: transform 0.22s ease, box-shadow 0.22s ease;
    }

    .app-shell.nav-collapsed .sidebar,
    .app-shell.focus-chart .sidebar {
        width: min(86vw, 320px);
        min-width: 0;
        opacity: 1;
        border-right: 1px solid var(--card-border);
    }

    .app-shell.mobile-nav-open .sidebar {
        transform: translateX(0);
        pointer-events: auto;
        box-shadow: 18px 0 48px rgba(0, 0, 0, 0.38);
    }

    .sidebar-header {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 8px;
    }

    .mobile-drawer-close {
        min-width: 40px;
        min-height: 40px;
        justify-content: center;
        font-size: 22px;
        line-height: 1;
        flex-shrink: 0;
    }

    .nav-item {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 14px;
        border-radius: 10px;
    }

    .market-tab {
        min-height: 40px;
        font-size: 12px;
    }

    .top-bar {
        padding: 8px 12px;
        padding-top: calc(8px + env(safe-area-inset-top));
        gap: 8px;
    }

    .top-bar-left {
        gap: 8px;
        min-width: 0;
        flex: 1;
    }

    .layout-toggle {
        min-width: 40px;
        min-height: 40px;
        justify-content: center;
        padding: 8px;
    }

    .page-title {
        font-size: 16px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-page-title {
        display: block !important;
        min-width: 0;
        margin: 0;
    }

    .page-subtitle {
        display: none;
    }

    .top-bar-right {
        gap: 6px;
        flex-shrink: 0;
        max-width: none;
    }

    .clock {
        display: none;
    }

    .user-chip {
        display: none;
    }

    .holdings-banner,
    .banner {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .holdings-banner > span,
    .banner > span {
        min-width: 0;
        flex: 1 1 220px;
        line-height: 1.5;
    }

    .holdings-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .holdings-tabs::-webkit-scrollbar {
        display: none;
    }

    .holdings-tab {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .auto-buy-page .card > p.text-secondary {
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .connection-badge {
        padding: 6px 8px;
        font-size: 11px;
    }

    .logout-btn {
        min-height: 40px;
        padding: 8px 10px;
    }

    .content-area {
        padding: 12px;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .mobile-tabbar {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
        position: relative;
        z-index: 40;
        flex-shrink: 0;
        background: color-mix(in srgb, var(--top-bar-bg) 94%, transparent);
        backdrop-filter: blur(16px);
        border-top: 1px solid var(--card-border);
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    }

    .mobile-tab {
        appearance: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: 52px;
        padding: 6px 2px;
        border: none;
        background: transparent;
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 10px;
        font-weight: 650;
        letter-spacing: 0.02em;
        border-radius: 10px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-tab .nav-mark {
        width: 24px;
        height: 24px;
        background: transparent;
        border: none;
    }

    .mobile-tab .nav-mark svg {
        width: 18px;
        height: 18px;
    }

    .mobile-tab.active .nav-mark {
        color: var(--gold);
        background: transparent;
        border: none;
    }

    .mobile-tab.active {
        color: var(--gold);
        background: var(--accent-soft-10);
    }

    .btn,
    .dock-chip,
    .layout-toggle {
        min-height: 40px;
    }

    .btn {
        padding: 10px 14px;
    }

    .card {
        padding: 12px;
        border-radius: 12px;
    }

    .card-header {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 10px;
    }

    .page-container .text-secondary {
        font-size: 13px;
        line-height: 1.5;
    }

    .form-row {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .form-row label,
    .checkbox-row label {
        width: auto;
    }

    .form-input,
    select.form-input,
    input.form-input {
        min-height: 44px;
        font-size: 16px; /* iOS zoom lock */
        width: 100%;
    }

    .button-row {
        flex-wrap: wrap;
    }

    .settings-card,
    .strategy-card,
    .signal-card {
        max-width: none;
    }

    .dashboard-body,
    .dashboard-body.rail-open {
        flex-direction: column;
    }

    .dashboard-insight-rail {
        width: 100%;
        max-height: none;
        position: static;
    }

    .dashboard-dock {
        align-items: stretch;
        gap: 8px;
    }

    .dashboard-dock-toggles {
        width: 100%;
    }

    .dashboard-dock-summary {
        width: 100%;
        justify-content: flex-start;
    }

    .dashboard .chart-header .instrument-info {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        width: 100%;
    }

    .dashboard .instrument-title-row,
    .dashboard .price-row {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 6px 10px;
        width: 100%;
    }

    .chart-header .price-row {
        flex-wrap: wrap;
        gap: 6px;
    }

    .price {
        font-size: 26px;
    }

    .candle-countdown {
        font-size: 11px;
        padding: 3px 6px;
        min-width: 64px;
    }

    .chart-area,
    .chart-area.large,
    .dashboard.focus-chart .chart-area {
        height: min(48dvh, 380px);
        min-height: 260px;
    }

    .chart-area.multi,
    .multi-chart-grid.stacked .chart-area.multi {
        height: 280px;
        min-height: 240px;
    }

    .user-management-grid {
        grid-template-columns: 1fr;
    }

    .auto-buy-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .symbol-search-wrap,
    .auto-buy-ip-wrap,
    .symbol-search-input {
        min-width: 0;
        width: 100%;
        flex: 1 1 auto;
    }

    .auto-buy-ip-row {
        flex-wrap: wrap;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-card {
        max-width: none;
        max-height: min(92dvh, 100%);
        border-radius: 16px 16px 0 0;
        overflow: auto;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .modal-actions {
        position: sticky;
        bottom: 0;
        background: var(--card-bg);
        padding-bottom: 8px;
    }

    .holdings-summary,
    .sentiment-summary {
        flex-wrap: wrap;
        gap: 8px;
    }

    .sentiment-filter {
        width: 100%;
    }

    .sentiment-filter .form-input {
        flex: 1;
        min-width: 0;
    }

    .sentiment-actions {
        flex-wrap: wrap;
        width: 100%;
    }

    .sentiment-actions .btn {
        flex: 1 1 auto;
    }

    .scanner-results-scroll {
        max-height: none;
        margin: 0 -4px;
        padding-bottom: 4px;
    }

    /* Wide tables scroll; marked tables become stacked cards. */
    .card:has(.data-table:not(.table-cards)),
    .auto-buy-failed-block:has(.data-table:not(.table-cards)),
    .user-list-card,
    .signal-options-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-table:not(.table-cards) {
        min-width: 640px;
    }

    .table-cards thead {
        display: none;
    }

    .table-cards,
    .table-cards tbody {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .table-cards tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px 12px;
        margin: 0 0 10px;
        padding: 14px;
        border: 1px solid var(--card-border);
        border-radius: 14px;
        background: var(--bg-elevated);
        box-shadow: var(--card-shadow);
    }

    .table-cards tbody tr:hover {
        background: var(--bg-elevated);
    }

    .table-cards td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 0;
        border: none;
        min-width: 0;
    }

    .table-cards td::before {
        content: attr(data-label);
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 0.06em;
        text-transform: uppercase;
        color: var(--muted-label);
    }

    .table-cards td.card-span,
    .table-cards td[data-span="full"],
    .table-cards:not(.list-cards) td[data-label="Symbol"],
    .table-cards:not(.list-cards) td[data-label="Stock"],
    .table-cards td[data-label="Status"],
    .table-cards td[data-label="Detail"],
    .table-cards td[data-label="Actions"],
    .table-cards td[data-label="Order"],
    .table-cards td[data-label="Reason"],
    .table-cards td[data-label="Articles"] {
        grid-column: 1 / -1;
    }

    .table-cards:not(.list-cards) td[data-label="Symbol"] strong,
    .table-cards:not(.list-cards) td[data-label="Stock"] strong {
        font-size: 16px;
    }

    .list-cards.table-cards tr {
        display: grid;
        grid-template-columns: 28px minmax(0, 1fr) auto auto;
        align-items: center;
        gap: 8px 10px;
        margin: 0 0 6px;
        padding: 10px 12px;
        border-radius: 12px;
    }

    .list-cards.table-cards td {
        flex-direction: row;
        align-items: center;
        gap: 0;
    }

    .list-cards.table-cards td::before {
        display: none;
    }

    .list-cards.table-cards td[data-label="#"] {
        color: var(--text-secondary);
        font-variant-numeric: tabular-nums;
        font-size: 12px;
    }

    .auto-buy-table.table-cards td:nth-child(2),
    .auto-buy-table.table-cards td:nth-child(8),
    .auto-buy-table.table-cards td:nth-child(9),
    .auto-buy-table.table-cards td:nth-child(10) {
        grid-column: 1 / -1;
    }

    .auto-buy-table.table-cards td:nth-child(1) {
        display: none;
    }

    .auto-buy-table.table-cards td:nth-child(2) strong {
        font-size: 16px;
    }

    .auto-buy-actions {
        width: 100%;
    }

    .auto-buy-actions .btn {
        flex: 1 1 auto;
    }

    .auto-buy-detail {
        max-width: none;
    }

    .login-shell,
    .login-page {
        min-height: 100dvh;
        min-height: 100svh;
    }

    .login-split-left {
        display: none;
    }

    .login-split-right {
        flex: none;
        width: 100%;
        min-height: 100dvh;
        padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
        align-items: flex-start;
    }

    .login-card,
    .login-container {
        max-width: 440px;
        padding: 28px 8px;
        margin: 0 auto;
    }

    .login-mobile-welcome {
        display: block;
        margin: 0 0 20px;
        color: #5f6368;
        font-size: 0.95rem;
        line-height: 1.45;
        text-align: center;
    }

    .login-input-group input {
        min-height: 48px;
        font-size: 16px;
    }
}

@media (min-width: 901px) {
    .login-mobile-welcome {
        display: none;
    }
}
