/* ═══════════════════════════════════════════════════════════
   NIMITEXPO — GROWW / ANGEL ONE STYLE MOBILE UI
   Fintech-grade mobile experience
   ═══════════════════════════════════════════════════════════ */

/* Base touch friendliness — all viewports */
button, .btn, .nav-item, .tab-btn, select, input[type="checkbox"], input[type="radio"] {
    min-height: 36px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ─── MOBILE (≤ 768px) ────────────────────────────────────── */
@media (max-width: 768px) {

    /* === APP LAYOUT === */
    .app-layout {
        flex-direction: column;
        min-height: 100vh;
        padding-top: 28px !important;
    }

    /* === SIDEBAR — slide-in drawer === */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: -300px;
        width: 280px;
        height: 100vh;
        background: #ffffff;
        z-index: 1000;
        transition: left 0.3s cubic-bezier(.4,0,.2,1);
        box-shadow: 8px 0 32px rgba(0,0,0,0.12);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .sidebar.open { left: 0; }

    /* === HAMBURGER TOGGLE === */
    .sidebar-toggle {
        display: flex !important;
        position: fixed;
        top: 36px;
        left: 10px;
        width: 40px;
        height: 40px;
        background: #ffffff;
        backdrop-filter: blur(12px);
        color: #374151;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        z-index: 999;
        font-size: 1.2rem;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    .sidebar-toggle:active { transform: scale(0.92); }

    /* === SIDEBAR OVERLAY === */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 998;
        backdrop-filter: blur(4px);
    }
    .sidebar.open ~ .sidebar-overlay { display: block; }

    /* Nav items — bigger touch targets */
    .sidebar-nav .nav-item {
        padding: 14px 18px !important;
        font-size: 0.92rem !important;
        min-height: 48px;
        border-radius: 10px;
    }

    /* === MAIN CONTENT === */
    .main-content {
        margin-left: 0 !important;
        padding: 52px 0 88px !important;
        width: 100%;
    }

    /* === MODE BANNER — ultra compact === */
    .mode-banner {
        font-size: 0.65rem !important;
        padding: 4px 12px !important;
        letter-spacing: 0.5px !important;
    }

    /* === TOP BAR — app header style === */
    .top-bar, .topbar {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 8px 16px !important;
        margin-bottom: 0 !important;
        background: transparent;
    }
    .top-bar h1 {
        font-size: 1.15rem !important;
        margin: 0 !important;
        padding-left: 36px;
    }
    .top-bar p.text-muted { display: none !important; }
    .top-bar-right {
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 6px !important;
    }
    /* Hide market status text on mobile, keep dot */
    .top-bar .market-status {
        padding: 6px 10px !important;
        font-size: 0.75rem !important;
        border-radius: 20px !important;
    }
    .top-bar .market-status #marketText { display: none; }
    .kill-switch {
        padding: 6px 12px !important;
        font-size: 0.72rem !important;
        border-radius: 20px !important;
        white-space: nowrap;
    }

    /* === TYPOGRAPHY === */
    h1 { font-size: 1.15rem !important; margin: 0 !important; }
    h2 { font-size: 1.05rem !important; }
    h3 { font-size: 0.92rem !important; }

    /* === HERO P&L CARD (mobile only) === */
    .mobile-pnl-hero {
        display: block !important;
        margin: 4px 12px 12px;
        padding: 20px;
        background: #ffffff;
        border: 1px solid #e5e7eb;
        border-radius: 16px;
        position: relative;
        overflow: hidden;
    }
    .mobile-pnl-hero::before {
        content: '';
        position: absolute;
        top: -50%;
        right: -30%;
        width: 200px;
        height: 200px;
        background: radial-gradient(circle, rgba(67,97,238,0.06) 0%, transparent 70%);
        border-radius: 50%;
    }
    .mobile-pnl-hero .pnl-label {
        font-size: 0.75rem;
        color: #6b7280;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin-bottom: 4px;
    }
    .mobile-pnl-hero .pnl-amount {
        font-size: 2rem;
        font-weight: 800;
        line-height: 1.1;
        margin-bottom: 6px;
    }
    .mobile-pnl-hero .pnl-change {
        font-size: 0.82rem;
        font-weight: 600;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 3px 10px;
        border-radius: 20px;
    }
    .mobile-pnl-hero .pnl-change.up {
        background: rgba(16,185,129,0.12);
        color: #10b981;
    }
    .mobile-pnl-hero .pnl-change.down {
        background: rgba(239,68,68,0.12);
        color: #ef4444;
    }
    .mobile-pnl-hero .pnl-row {
        display: flex;
        justify-content: space-between;
        margin-top: 16px;
        padding-top: 14px;
        border-top: 1px solid #e5e7eb;
    }
    .mobile-pnl-hero .pnl-stat {
        text-align: center;
        flex: 1;
    }
    .mobile-pnl-hero .pnl-stat .val {
        font-size: 1.05rem;
        font-weight: 700;
    }
    .mobile-pnl-hero .pnl-stat .lbl {
        font-size: 0.68rem;
        color: #6b7280;
        margin-top: 2px;
    }

    /* === STAT CARDS — 2x2 compact grid === */
    .stats-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        padding: 0 12px !important;
        margin-bottom: 12px !important;
    }
    .stat-card {
        padding: 12px !important;
        border-radius: 12px !important;
        border: 1px solid #e5e7eb !important;
        background: #ffffff !important;
    }
    .stat-card .stat-value {
        font-size: 1.2rem !important;
        font-weight: 800;
    }
    .stat-card .stat-label {
        font-size: 0.7rem !important;
        letter-spacing: 0.3px;
    }
    .stat-card .stat-icon {
        width: 28px !important;
        height: 28px !important;
        border-radius: 8px;
        font-size: 0.85rem !important;
    }
    .stat-card .stat-change {
        font-size: 0.72rem !important;
        margin-top: 4px !important;
    }
    .stat-card .stat-header { margin-bottom: 8px !important; }

    /* === CARDS — compact rounded === */
    .grid-2, .grid-3, .grid-4, .grid-row {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
        padding: 0 12px !important;
    }
    .card {
        border-radius: 14px !important;
        border: 1px solid #e5e7eb !important;
        overflow: hidden;
    }
    .card-body { padding: 12px !important; }
    .card-body.no-pad { padding: 0 !important; }
    .card-header {
        padding: 12px 14px !important;
        flex-wrap: nowrap;
        gap: 8px;
    }
    .card-header h3 {
        font-size: 0.88rem !important;
        white-space: nowrap;
    }

    /* === QUICK ACTIONS (mobile only) === */
    .mobile-quick-actions {
        display: flex !important;
        gap: 8px;
        padding: 0 12px;
        margin-bottom: 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .mobile-quick-actions::-webkit-scrollbar { display: none; }
    .mobile-quick-actions a {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        min-width: 72px;
        padding: 12px 8px;
        background: #ffffff;
        border: 1px solid #e5e7eb;
        border-radius: 14px;
        color: #6b7280;
        text-decoration: none;
        font-size: 0.68rem;
        font-weight: 600;
        flex-shrink: 0;
        transition: all 0.15s ease;
    }
    .mobile-quick-actions a:active {
        transform: scale(0.95);
        background: rgba(67,97,238,0.08);
    }
    .mobile-quick-actions a .qa-icon {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.1rem;
    }

    /* === INPUTS — 16px to prevent iOS zoom === */
    input, select, textarea, .form-control {
        font-size: 16px !important;
        min-height: 44px;
        padding: 10px 14px !important;
        box-sizing: border-box;
        border-radius: 10px !important;
    }

    /* === BUTTONS — Groww style rounded === */
    .btn, button {
        min-height: 40px;
        padding: 10px 16px !important;
        font-size: 0.85rem !important;
        border-radius: 10px !important;
    }
    .btn-sm {
        min-height: 32px;
        padding: 6px 12px !important;
        font-size: 0.75rem !important;
        border-radius: 8px !important;
    }
    .btn-trade {
        min-height: 28px;
        padding: 4px 10px !important;
        font-size: 0.72rem !important;
        min-width: 32px;
    }

    /* === TABLES — card-style on mobile === */
    .table-wrapper, .card.no-pad, .oc-table-wrap {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    table {
        font-size: 0.78rem !important;
        min-width: 500px;
    }
    th, td { padding: 8px 6px !important; white-space: nowrap; }
    .data-table th {
        font-size: 0.7rem !important;
        padding: 8px 6px !important;
    }
    .data-table td {
        padding: 10px 6px !important;
        font-size: 0.82rem !important;
    }

    /* === OPTION CHAIN === */
    .oc-table th { font-size: 0.66rem !important; padding: 6px 3px !important; }
    .oc-table td { padding: 4px 3px !important; font-size: 0.74rem !important; }
    .oc-table .btn-trade {
        padding: 3px 7px !important;
        min-height: 24px;
        min-width: 24px;
        font-size: 0.66rem !important;
    }

    /* === MODAL — full screen clean === */
    .modal-overlay { padding: 0 !important; align-items: flex-end !important; }
    .modal {
        max-width: 100vw !important;
        max-height: 90vh !important;
        margin: 0 !important;
        width: 100%;
        border-radius: 20px 20px 0 0 !important;
        border: none !important;
        border-top: 1px solid #e5e7eb !important;
    }
    .modal::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
        margin: 10px auto 0;
    }
    .modal-body {
        max-height: 70vh;
        overflow-y: auto;
        padding: 16px !important;
    }
    .modal-header, .modal-footer { padding: 14px 16px !important; }
    .form-row { flex-direction: column; gap: 0 !important; }

    /* === CHART === */
    #tvChartWrap, #nimitChartWrap {
        height: calc(100vh - 180px) !important;
        min-height: 380px;
    }
    .chart-controls {
        gap: 6px !important;
        padding: 8px !important;
        overflow-x: auto;
    }
    .section-label { display: none; }
    .sym-search { width: 140px !important; font-size: 16px !important; }

    /* === BROKER CARDS === */
    .broker-card { flex-direction: column !important; gap: 8px !important; }

    /* === BADGE — pill style === */
    .badge {
        border-radius: 20px !important;
        padding: 3px 10px !important;
        font-size: 0.72rem !important;
    }

    /* === POSITION ROWS — Groww style === */
    .position-row {
        padding: 14px 16px !important;
    }
    .position-row .pos-symbol {
        font-size: 0.9rem !important;
    }

    /* === ALERT ITEMS — compact === */
    .alert-item {
        padding: 10px 14px !important;
        gap: 10px !important;
    }
    .alert-item .al-icon {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        border-radius: 8px;
        font-size: 0.8rem !important;
    }

    /* === BOTTOM NAV BAR — Groww/Angel One style === */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: rgba(255,255,255,0.98);
        border-top: 1px solid #e5e7eb;
        z-index: 990;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        padding: 0;
        padding-bottom: env(safe-area-inset-bottom);
    }
    .mobile-bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        color: #6b7280;
        text-decoration: none;
        font-size: 0.62rem;
        font-weight: 600;
        letter-spacing: 0.3px;
        position: relative;
        transition: color 0.15s ease;
    }
    .mobile-bottom-nav a.active {
        color: #4361ee;
    }
    .mobile-bottom-nav a.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 24px;
        height: 2px;
        background: #4361ee;
        border-radius: 0 0 2px 2px;
    }
    .mobile-bottom-nav a .bnav-icon {
        font-size: 1.25rem;
        line-height: 1;
    }
    .mobile-bottom-nav a .bnav-badge {
        position: absolute;
        top: 4px;
        right: calc(50% - 18px);
        background: #ef4444;
        color: #fff;
        font-size: 0.58rem;
        font-weight: 700;
        min-width: 14px;
        height: 14px;
        border-radius: 7px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 3px;
    }

    /* === TABS — horizontal scroll === */
    .tab-bar, .tabs {
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tab-bar::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
    .tab-btn, .tab { flex: 0 0 auto; padding: 10px 16px !important; }

    /* === SEARCH RESULTS === */
    .symbol-search-results, .sym-dropdown {
        position: fixed !important;
        left: 8px !important;
        right: 8px !important;
        top: 100px !important;
        width: auto !important;
        max-height: 60vh !important;
        border-radius: 14px !important;
        box-shadow: 0 8px 40px rgba(0,0,0,0.15);
    }

    /* === HIDE on mobile === */
    .hide-mobile { display: none !important; }

    /* === PULL TO REFRESH indicator === */
    .pull-indicator {
        text-align: center;
        padding: 8px;
        font-size: 0.72rem;
        color: #6b7280;
        display: none;
    }
}

/* ─── TABLET (769-1024px) ─────────────────────────────────── */
@media (max-width: 1024px) and (min-width: 769px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr) !important; }
    .grid-3 { grid-template-columns: repeat(2, 1fr) !important; }
    table { font-size: 0.85rem; }
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; }
    .mobile-pnl-hero { display: none !important; }
    .mobile-quick-actions { display: none !important; }
}

/* ─── DESKTOP — hide mobile-only elements ─────────────────── */
@media (min-width: 769px) {
    .mobile-bottom-nav { display: none !important; }
    .sidebar-toggle { display: none !important; }
    .show-mobile { display: none !important; }
    .mobile-pnl-hero { display: none !important; }
    .mobile-quick-actions { display: none !important; }
}

/* ─── SCROLLBAR THEMING ───────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(100,116,139,0.3); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(100,116,139,0.5); }

/* ─── FOCUS STATES ────────────────────────────────────────── */
input:focus, select:focus, textarea:focus, .form-control:focus {
    outline: none;
    border-color: #4361ee !important;
    box-shadow: 0 0 0 3px rgba(67,97,238,0.15);
}

/* ─── ACTIVE FEEDBACK ─────────────────────────────────────── */
.btn:active, button:active, .nav-item:active, .tab-btn:active {
    transform: scale(0.97);
    transition: transform 0.1s;
}

/* ─── SAFE AREA INSETS (iPhone notch) ─────────────────────── */
@supports (padding: env(safe-area-inset-top)) {
    @media (max-width: 768px) {
        .main-content {
            padding-top: calc(52px + env(safe-area-inset-top)) !important;
        }
        .sidebar-toggle {
            top: calc(36px + env(safe-area-inset-top));
        }
        .mobile-bottom-nav {
            height: calc(60px + env(safe-area-inset-bottom));
        }
    }
}

/* ─── SMOOTH PAGE LOAD ────────────────────────────────────── */
@media (max-width: 768px) {
    .card, .stat-card {
        animation: fadeSlideUp 0.35s ease forwards;
        opacity: 0;
    }
    .stats-row .stat-card:nth-child(1) { animation-delay: 0.05s; }
    .stats-row .stat-card:nth-child(2) { animation-delay: 0.1s; }
    .stats-row .stat-card:nth-child(3) { animation-delay: 0.15s; }
    .stats-row .stat-card:nth-child(4) { animation-delay: 0.2s; }
    .grid-2 .card:nth-child(1) { animation-delay: 0.25s; }
    .grid-2 .card:nth-child(2) { animation-delay: 0.3s; }
}

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
