/* ═══════════════════════════════════════════════════════════════
   MOBILE — Responsive overrides for all pages
   Breakpoints: 900px (tablet), 600px (phone)
   ═══════════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════════
   NAVIGATION
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Simple navigation */
    .nav-container {
        padding: 0 12px;
        height: 52px;
        gap: 6px;
    }
    .nav-logo .logo-text { display: none; }
    .nav-logo .logo-icon { display: block; }
    .nav-logo img { height: 32px; }

    /* Hide desktop nav links, show only icon buttons */
    .nav-links { display: none; }
    .nav-link-text { display: none; }

    /* User button compact */
    .user-button #userNameShort { display: none; }
    .user-button { padding: 5px 8px; }
    .user-dropdown { right: 0; left: auto; min-width: 200px; }

    /* Header */
    .app-header, .page-header { padding: 10px 12px; }
    .header-inner { padding: 0 12px; }
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD (index.html) KPI bar + charts
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
    .kpi-bar {
        flex-wrap: wrap;
        height: auto;
        gap: 0;
    }
    .kpi-item {
        flex: 0 0 50%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 10px 14px;
    }
    .kpi-item:nth-child(odd) { border-right: 1px solid var(--border); }
}
@media (max-width: 600px) {
    .kpi-item { flex: 0 0 100%; border-right: none !important; }
    .chart-section { padding: 0; }
    canvas { max-height: 180px; }
}

/* ═══════════════════════════════════════════════════════════════
   TABLES — horizontal scroll on small screens
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Wrap any .trading-table or compact-view in a scrollable container */
    .table-wrapper,
    .compact-view {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .trading-table,
    .compact-view table {
        min-width: 600px;
    }

    /* Table controls stack vertically */
    .table-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .table-controls input[type="text"],
    .table-controls .search-input {
        width: 100%;
    }
    .table-controls .filter-row {
        flex-wrap: wrap;
        gap: 6px;
    }
    .add-investment-btn,
    .btn-add-investment {
        width: 100%;
        justify-content: center;
    }
}

/* ═══════════════════════════════════════════════════════════════
   PORTFOLIO PAGE
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .portfolio-header-section {
        padding: 12px 14px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .portfolio-stats-row {
        flex-wrap: wrap;
        gap: 8px;
    }
    .portfolio-stat-card {
        flex: 0 0 calc(50% - 4px);
    }
    .view-toggle { display: none; } /* hide card/table toggle, table only */

    /* Expanded item panel */
    .item-expand-panel,
    .expand-panel {
        padding: 12px 14px;
    }
    .item-expand-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .purchase-list { font-size: 0.8rem; }

    /* Action buttons stack */
    .item-actions-row,
    .item-action-buttons {
        flex-direction: column;
        gap: 6px;
    }
    .item-actions-row button,
    .item-action-buttons button { width: 100%; }
}

/* ═══════════════════════════════════════════════════════════════
   SALES PAGE
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .sales-stats-row,
    .sales-kpi {
        flex-wrap: wrap;
        gap: 8px;
    }
    .sales-kpi-item,
    .stat-card-sm { flex: 0 0 calc(50% - 4px); }
}
@media (max-width: 480px) {
    .sales-kpi-item,
    .stat-card-sm { flex: 0 0 100%; }
}

/* ═══════════════════════════════════════════════════════════════
   MODALS — full screen on mobile
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    /* General modal */
    .modal { align-items: flex-end; }
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: var(--r-sm) var(--r-sm) 0 0 !important;
        border-left: none;
        border-right: none;
        border-bottom: none;
        max-height: 92vh;
        margin: 0 !important;
    }

    /* Sell modal */
    #sellItemModal .modal-content,
    #editItemModal .modal-content {
        width: 100%;
        max-width: 100%;
        border-radius: var(--r-sm) var(--r-sm) 0 0;
        margin: 0;
    }
    .sell-grid {
        grid-template-columns: 1fr !important;
    }
    .sell-form .form-row {
        grid-template-columns: 1fr !important;
    }

    /* Auth modal — bottom sheet */
    .auth-modal { align-items: flex-end; }
    .auth-modal-content {
        width: 100%;
        border-radius: var(--r-sm) var(--r-sm) 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        max-height: 92vh;
        animation: authSlideUp 0.22s ease;
    }
    @keyframes authSlideUp {
        from { transform: translateY(100%); opacity: 0.6; }
        to   { transform: translateY(0); opacity: 1; }
    }
}

/* ═══════════════════════════════════════════════════════════════
   MAIN CONTENT AREA
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .main-content,
    .content-container,
    .page-content {
        padding: 12px;
    }
    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   TOUCH TARGETS — min 44px tap target on mobile
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    button,
    .btn,
    select,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 36px;
    }
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important; /* prevents iOS zoom on focus */
    }
    input[type="checkbox"],
    input[type="radio"] {
        min-height: unset;
        width: 18px;
        height: 18px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   LANDING PAGE — mobile
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
    .l-nav-inner { padding: 0 14px; height: 64px; }
    .l-nav-logo img { height: 56px; }
    .l-hero-inner { padding: 32px 14px 32px; }
    .l-hero-title { font-size: 1.5rem; }
    .l-hero-sub { font-size: 0.875rem; }
    .l-hero-actions { flex-direction: column; align-items: stretch; }
    .l-hero-actions .l-btn-primary,
    .l-hero-actions .l-btn-ghost { text-align: center; justify-content: center; }

    .l-preview-table thead { display: none; }
    .l-preview-kpi { grid-template-columns: 1fr 1fr; }
    .l-kpi-item { padding: 8px 10px; }

    .l-section-inner, .l-cta-inner, .l-footer-inner { padding: 0 14px; }
    .l-how, .l-features, .l-faq, .l-cta { padding: 40px 0; }
    .l-feature-row { grid-template-columns: 1fr; gap: 8px; }
    .l-faq-grid { grid-template-columns: 1fr; gap: 24px; }
    .l-step { grid-template-columns: 40px 1fr; gap: 12px; }
    .l-strip-inner { flex-direction: column; height: auto; padding: 16px 14px; gap: 10px; }
    .l-strip-div { display: none; }
    .l-cta-inner h2 { font-size: 1.4rem; }
    .l-footer-inner { flex-direction: column; gap: 10px; }
}
