/* ═══════════════════════════════════════════════════════════════
   MokhbirPro — Mobile-Friendly Layout Enhancements
   Loaded after style.css to override/extend responsive rules.
   ═══════════════════════════════════════════════════════════════ */

/* ── iOS Input Zoom Prevention ──────────────────────────────── */
@media (max-width: 768px) {
    input,
    select,
    textarea {
        font-size: max(16px, 1em) !important;
    }
}

/* ── Safe Area Insets (iPhone notch / Dynamic Island) ────────── */
@supports (padding: env(safe-area-inset-top)) {
    .navbar {
        padding-top: env(safe-area-inset-top);
    }
    .footer {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    .mobile-nav {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    .paywall-modal,
    #circle-email-gate,
    .lightbox {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ── Mobile Nav: Slide-down Animation + Better Styling ──────── */
.mobile-nav {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    transition: max-height 0.3s ease, opacity 0.25s ease, padding 0.3s ease;
    padding-top: 0;
    padding-bottom: 0;
}

.mobile-nav.active {
    display: flex;
    max-height: 500px;
    opacity: 1;
    padding-top: 12px;
    padding-bottom: 12px;
}

.mobile-nav .nav-link {
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 12px 16px;
    min-height: 48px;
    display: flex;
    align-items: center;
    border-radius: var(--radius-sm, 8px);
    transition: background var(--transition);
}

.mobile-nav .nav-link:hover,
.mobile-nav .nav-link:active {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.mobile-nav .nav-link.active {
    border-inline-start: 3px solid #D4A321;
    background: rgba(255, 255, 255, 0.05);
}

/* Mobile Nav Backdrop */
.mobile-nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.25s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-backdrop.active {
    display: block;
    opacity: 1;
}

/* ── Mobile Search Overlay ──────────────────────────────────── */
.mobile-search-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid #02680F;
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm, 8px);
    cursor: pointer;
    font-size: 1rem;
    transition: background var(--transition), border-color var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.mobile-search-btn:hover,
.mobile-search-btn:active {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.mobile-search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.6);
    padding: 0;
    flex-direction: column;
}

.mobile-search-overlay.active {
    display: flex;
}

.mobile-search-bar {
    background: #013608;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid #02680F;
}

@supports (padding: env(safe-area-inset-top)) {
    .mobile-search-bar {
        padding-top: calc(12px + env(safe-area-inset-top));
    }
}

.mobile-search-bar input {
    flex: 1;
    padding: 12px 16px;
    background: rgba(255,255,255,0.08);
    border: 1px solid #02680F;
    border-radius: var(--radius-sm, 8px);
    color: #ffffff;
    font-size: 16px;
    font-family: var(--font-ar), var(--font-en), sans-serif;
    outline: none;
}

.mobile-search-bar input::placeholder {
    color: rgba(255,255,255,0.6);
}

.mobile-search-bar input:focus {
    border-color: rgba(255,255,255,0.4);
}

.mobile-search-close {
    background: none;
    border: none;
    color: var(--dark-text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.mobile-search-results {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-card, #fff);
}

/* ── Hamburger Animation (X when open) ──────────────────────── */
.mobile-menu-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.mobile-menu-btn.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(4px, -4px);
}

/* ═══════════════════════════════════════════════════════════════
   Tablet Breakpoint (max-width: 768px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* ── Navbar ── */
    .nav-search {
        display: none;
    }

    .mobile-search-btn {
        display: flex;
    }

    .nav-back-btn {
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
    }

    .theme-toggle {
        min-width: 44px;
        min-height: 44px;
    }

    .mobile-menu-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 10px;
    }

    /* ── Pilot Banner ── */
    .pilot-banner {
        flex-direction: column;
        gap: 4px;
        padding: 10px 16px;
        font-size: 18px;
    }

    .pilot-banner .pilot-sep {
        display: none;
    }

    /* ── Footer — add bottom padding for bottom bar ── */
    .footer {
        padding: 16px 16px;
        padding-bottom: calc(16px + 64px + env(safe-area-inset-bottom, 0px));
    }

    .footer-disclaimer {
        font-size: clamp(0.7rem, 2vw, 0.78rem);
    }

    .footer-copy {
        font-size: 0.78rem;
    }

    /* ── Top Controls Bar — hidden on mobile, replaced by bottom bar ── */
    .top-controls-bar {
        display: none !important;
    }

    /* ── Stats Bar — horizontal swipeable ── */
    .stats-bar {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 12px;
        padding: 0 16px;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .stats-bar::-webkit-scrollbar {
        display: none;
    }

    .stats-bar > .stat-card,
    .stats-bar > .stat-card-pie {
        flex: 0 0 72vw;
        min-width: 0;
        scroll-snap-align: center;
    }

    /* ── Stats Bar ── */
    .stat-card {
        padding: 14px 12px;
    }

    .stat-number {
        font-size: clamp(1.3rem, 5vw, 1.8rem);
    }

    .stat-label {
        font-size: clamp(0.78rem, 2.5vw, 0.92rem);
    }

    .stat-label-en {
        font-size: clamp(0.62rem, 2vw, 0.72rem);
    }

    /* ── Filter Controls Row ── */
    .filter-controls-row {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 0 16px;
    }

    .catalog-search {
        width: 100%;
    }

    .catalog-search input {
        width: 100%;
        min-height: 44px;
    }

    .filter-right-group {
        width: 100%;
        justify-content: space-between;
    }

    .filter-divider {
        display: none;
    }

    .sort-dropdown-btn {
        min-height: 44px;
    }

    .view-filter-group {
        display: flex;
        gap: 4px;
    }

    .view-filter-btn {
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        padding: 6px 10px;
        font-size: 0.78rem;
    }

    /* ── Market Tabs ── */
    .market-tab {
        min-height: 40px;
        padding: 8px 14px;
    }

    .market-dropdown-menu {
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .market-dropdown-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* ── Ticker Cards ── */
    .ticker-card:hover {
        transform: none;
    }

    .card-top-row {
        flex-wrap: wrap;
        gap: 6px;
        padding: 10px 12px 0;
    }

    .card-top-right {
        flex-wrap: wrap;
        gap: 4px;
    }

    .card-actions-btn {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.3rem;
    }

    .card-symbol-row {
        padding: 4px 12px 8px;
    }

    .card-symbol {
        font-size: clamp(1.1rem, 4vw, 1.25rem);
    }

    .card-image {
        padding: 4px 12px;
    }

    .card-image img {
        max-height: 200px;
        object-fit: cover;
        border-radius: var(--radius-sm, 8px);
    }

    .card-footer {
        padding: 10px 12px;
    }

    /* ── Card Actions Menu (mobile position) ── */
    .card-actions-menu {
        min-width: 200px;
    }

    .card-action-item {
        min-height: 44px;
        padding: 10px 14px;
    }

    .pf-inline-form input {
        font-size: 16px;
        padding: 10px 12px;
    }

    .pf-inline-submit {
        min-height: 44px;
        font-size: 0.88rem;
    }

    /* ── Pagination ── */
    .page-btn {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* ── Tickers Table ── */
    .tickers-table-section {
        padding: 0 12px;
    }

    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px;
        padding: 0 12px;
    }

    .tickers-table td,
    .tickers-table th {
        padding: 10px 10px;
    }

    .tickers-table .ticker-cell {
        position: sticky;
        left: 0;
        z-index: 2;
        background: var(--bg-card);
    }

    .tickers-table th:first-child {
        position: sticky;
        left: 0;
        z-index: 3;
        background: var(--bg-secondary);
    }

    .clickable-row {
        min-height: 48px;
    }

    .market-badge {
        font-size: 0.72rem;
        padding: 2px 6px;
    }

    /* ── Prices Table (ticker detail) ── */
    .prices-table td:first-child,
    .prices-table th:first-child {
        position: sticky;
        left: 0;
        z-index: 2;
        background: var(--bg-card);
    }

    .prices-table th:first-child {
        background: var(--bg-secondary);
        z-index: 3;
    }

    /* ── Gallery ── */
    .gallery-scroll {
        scroll-snap-type: x proximity;
        -webkit-scroll-snap-type: x proximity;
    }

    .gallery-item {
        scroll-snap-align: center;
    }

    /* ── Chart Section ── */
    .chart-range-btn,
    .chart-interval-btn {
        min-height: 36px;
        min-width: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .chart-controls {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        flex-wrap: nowrap;
    }

    .chart-controls::-webkit-scrollbar {
        display: none;
    }

    /* ── Ticker Header ── */
    .ticker-hero-top {
        gap: 8px;
    }

    .breadcrumb {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }

    /* ── Lightbox ── */
    .lightbox-close {
        min-width: 44px;
        min-height: 44px;
        font-size: 2rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* ── Results Count Bar ── */
    .results-count-bar {
        padding: 0 16px;
    }

    /* ── Page Header ── */
    .page-header h1 {
        font-size: clamp(1.1rem, 4vw, 1.5rem);
    }

    /* ── Paywall Modal ── */
    .paywall-content {
        width: 95%;
        padding: 1.5rem 1.2rem;
    }

    .paywall-btn {
        min-height: 48px;
        font-size: 1rem;
    }

    .paywall-close {
        min-width: 44px;
        min-height: 44px;
    }

    /* ── Email Gate Modal ── */
    #circle-email-gate > div {
        width: 95% !important;
    }

    #circle-email-gate input {
        min-height: 48px;
    }

    #circle-email-gate button {
        min-height: 48px;
    }

    /* ── Ticker Detail: Portfolio Section ── */
    .ticker-portfolio-section {
        padding: 0 12px;
    }

    .portfolio-form-card {
        padding: 14px;
    }

    .pf-field input,
    .pf-field textarea {
        font-size: 16px;
    }

    .pf-btn {
        min-height: 44px;
        width: 100%;
        justify-content: center;
    }

    /* ── Ticker Detail: Trading Guide ── */
    .trading-guide-section {
        padding: 0 12px;
    }

    .tg-field input {
        font-size: 16px;
    }

    .tg-profile-btn {
        min-height: 44px;
    }

    .tg-ratio-badge {
        font-size: clamp(1.4rem, 5vw, 2rem);
        padding: 8px 20px;
        min-width: 100px;
    }

    /* ── Setup Section ── */
    .setups-section {
        padding: 0 12px;
    }

    #setup-select {
        width: 100%;
        min-height: 44px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Small Mobile Breakpoint (max-width: 480px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {

    /* ── Stats Bar — narrower cards on small screens ── */
    .stats-bar > .stat-card,
    .stats-bar > .stat-card-pie {
        flex: 0 0 80vw;
    }

    .hero-pie-wrap {
        height: 140px;
    }

    .hero-pie-wrap canvas {
        max-height: 140px;
    }

    /* ── Market Tabs ── */
    .tab-count {
        display: none;
    }

    .market-tab {
        font-size: 0.75rem;
        padding: 6px 10px;
    }

    /* ── View Filters (horizontal scroll) ── */
    .view-filter-group {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 4px;
    }

    .view-filter-group::-webkit-scrollbar {
        display: none;
    }

    .view-filter-btn {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* ── Pagination — simplified ── */
    .page-ellipsis {
        display: none;
    }

    .pagination .page-btn:not(.active):not(:first-child):not(:last-child) {
        display: none;
    }

    /* Keep first (prev), active, and last (next) visible */
    .pagination .page-btn.active {
        display: inline-flex;
    }

    /* ── Cards Grid ── */
    .cards-grid {
        padding: 0 12px 24px;
        gap: 12px;
    }

    .card-top-row {
        padding: 8px 10px 0;
    }

    .card-symbol-row {
        padding: 4px 10px 6px;
    }

    .card-image {
        padding: 4px 10px;
    }

    .card-footer {
        padding: 8px 10px;
        font-size: 0.72rem;
    }

    /* ── Pilot Banner ── */
    .pilot-banner {
        font-size: 14px;
        padding: 8px 12px;
    }

    /* ── Footer ── */
    .footer {
        padding: 12px 12px;
    }

    /* ── Trading Guide Metrics ── */
    .tg-metrics {
        grid-template-columns: 1fr;
    }

    .tg-level-price {
        font-size: 1.05rem;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Hover State Cleanup — prevent sticky hover on touch devices
   ═══════════════════════════════════════════════════════════════ */
@media (hover: none) {
    .ticker-card:hover {
        transform: none;
        box-shadow: none;
        border-color: var(--border);
    }

    .stat-card:hover {
        transform: none;
        box-shadow: none;
    }

    .gallery-item:hover {
        transform: none;
    }

    .market-tab:hover {
        background: var(--bg-card);
        color: var(--text-secondary);
        border-color: var(--border);
    }

    .sort-dropdown-btn:hover {
        border-color: var(--border);
    }

    .bookmark-filter-btn:hover {
        border-color: var(--border);
        color: var(--text-secondary);
    }
}

/* ═══════════════════════════════════════════════════════════════
   Landscape Mode on Mobile
   ═══════════════════════════════════════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) {
    .navbar {
        position: relative;
    }

    .nav-container {
        height: 48px;
    }

    .stats-bar {
        grid-template-columns: repeat(4, 1fr);
        margin: 12px auto;
        gap: 8px;
    }

    .hero-pie-wrap {
        height: 100px;
    }

    .hero-pie-wrap canvas {
        max-height: 100px;
    }

    #tv-chart {
        height: 250px;
    }

    .pilot-banner {
        padding: 6px 16px;
        font-size: 14px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Mobile Bottom Bar
   ═══════════════════════════════════════════════════════════════ */
.mobile-bottom-bar {
    display: none;
}

@media (max-width: 768px) {
    .mobile-bottom-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: var(--bg-card, #fff);
        border-top: 1px solid var(--border, #e2e8f0);
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
        justify-content: space-around;
        align-items: center;
        padding: 4px 0;
        padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
        min-height: 56px;
    }

    [data-theme="dark"] .mobile-bottom-bar {
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.25);
    }

    .bottom-bar-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 8px;
        min-width: 56px;
        min-height: 48px;
        background: none;
        border: none;
        color: var(--text-secondary, #6b7280);
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.15s ease;
        font-family: inherit;
    }

    .bottom-bar-item:active {
        color: var(--accent, #c08629);
    }

    .bottom-bar-icon {
        font-size: 1.25rem;
        line-height: 1;
    }

    .bottom-bar-label {
        font-size: 0.65rem;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 64px;
    }

    /* Theme icon toggle: show correct icon based on theme */
    .bottom-bar-item .icon-sun {
        display: none;
    }
    [data-theme="dark"] .bottom-bar-item .icon-moon {
        display: none;
    }
    [data-theme="dark"] .bottom-bar-item .icon-sun {
        display: inline;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Touch Target Enforcement (global)
   ═══════════════════════════════════════════════════════════════ */
@media (pointer: coarse) {
    .filter-chip,
    .market-tab,
    .page-btn,
    .alpha-toggle-btn,
    .volatile-toggle-btn,
    .guide-toggle-btn,
    .bookmark-filter-btn,
    .view-filter-btn,
    .admin-btn,
    .notif-settings-btn,
    .tutorial-replay-btn {
        min-height: 44px;
        min-width: 44px;
    }

    .tickers-table td,
    .prices-table td {
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .clickable-row {
        cursor: pointer;
    }
}

/* ═══════════════════════════════════════════════════════════════
   Mobile Body Padding (account for fixed bottom bar)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    body {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }
}

/* ═══════════════════════════════════════════════════════════════
   Arabic Dropdown — Mobile Tap-to-Open (same style as desktop)
   ═══════════════════════════════════════════════════════════════ */

/* Backdrop (transparent, just catches taps to close) */
.market-dropdown-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99;
    -webkit-tap-highlight-color: transparent;
}

.market-dropdown-backdrop.active {
    display: block;
}

@media (max-width: 768px) {
    /* Disable hover-based opening on mobile */
    .market-tab-dropdown:hover .market-dropdown-menu {
        display: none;
    }

    /* Open via .open class (set by JS tap handler) */
    .market-tab-dropdown.open .market-dropdown-menu {
        display: flex;
        flex-direction: column;
    }

    .market-tab-dropdown.open .dropdown-arrow {
        transform: rotate(180deg);
    }

    /* Remove overflow clip on parent when dropdown is open */
    .market-tabs:has(.market-tab-dropdown.open) {
        overflow: visible;
    }

    /* Ensure dropdown appears above cards */
    .market-tab-dropdown .market-dropdown-menu {
        z-index: 200;
    }

    /* Comfortable tap targets for dropdown items */
    .market-tab-dropdown .market-dropdown-item {
        min-height: 44px;
        padding: 10px 16px;
    }
}

/* ── PWA Install Banner ──────────────────────────────────────── */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    background: #1e293b;
    color: #f1f5f9;
    border-top: 1px solid rgba(59, 130, 246, 0.3);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    font-family: 'Cairo', 'Inter', sans-serif;
    font-size: 0.9rem;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}
.pwa-install-banner--visible {
    transform: translateY(0);
}
.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}
.pwa-install-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}
.pwa-install-text {
    line-height: 1.5;
}
.pwa-share-icon {
    display: inline-block;
    font-size: 1.1em;
    vertical-align: middle;
}
.pwa-install-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.pwa-install-btn {
    padding: 8px 20px;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
}
.pwa-install-btn:hover,
.pwa-install-btn:active {
    background: #2563eb;
}
.pwa-install-dismiss {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.2s, background 0.2s;
}
.pwa-install-dismiss:hover {
    color: #f1f5f9;
    background: rgba(255, 255, 255, 0.1);
}
[data-theme=""] .pwa-install-banner,
[data-theme="light"] .pwa-install-banner {
    background: #ffffff;
    color: #1e293b;
    border-top-color: rgba(59, 130, 246, 0.2);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}
[data-theme=""] .pwa-install-dismiss,
[data-theme="light"] .pwa-install-dismiss {
    color: #64748b;
}
[data-theme=""] .pwa-install-dismiss:hover,
[data-theme="light"] .pwa-install-dismiss:hover {
    color: #1e293b;
    background: rgba(0, 0, 0, 0.06);
}
