/* ============================================
   ErpYeri Mobile — App-Like Experience
   Mobile-first, professional & touch-friendly
   ============================================ */

/* ======= Bottom Navigation Bar ======= */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 768px) {

    /* ===== Global Mobile Resets ===== */
    html {
        font-size: 15px;
    }

    body {
        padding-bottom: 68px;
        /* bottom nav height */
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* ===== Header Mobile ===== */
    .mega-header {
        height: 56px;
        padding: 0 14px;
        gap: 8px;
    }

    .mega-nav {
        display: none !important;
    }

    .mega-api {
        display: none;
    }

    .mega-username {
        display: none;
    }

    .mega-title {
        font-size: 1.05rem;
    }

    /* Hamburger toggle */
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: none;
        background: var(--bg-hover);
        border-radius: 10px;
        cursor: pointer;
        color: var(--text-primary);
        margin-right: 4px;
        transition: var(--transition);
        flex-shrink: 0;
    }

    .mobile-menu-toggle:active {
        transform: scale(0.93);
        background: var(--accent-glow);
    }

    /* ===== Mobile Drawer ===== */
    .mobile-drawer-overlay {
        display: block !important;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 900;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        /* Don't block clicks when closed */
        transition: all 0.25s ease;
        backdrop-filter: blur(2px);
    }

    .mobile-drawer-overlay.open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .mobile-drawer {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        background: var(--bg-card);
        z-index: 950;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
        overflow-y: auto;
    }

    .mobile-drawer.open {
        transform: translateX(0);
    }

    .mobile-drawer-header {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 18px 20px 14px;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
    }

    .mobile-drawer-logo {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        background: linear-gradient(135deg, var(--accent), #8b5cf6);
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 800;
        font-size: 0.8rem;
        color: white;
        letter-spacing: -0.5px;
    }

    .mobile-drawer-title {
        font-weight: 700;
        font-size: 1.05rem;
        color: var(--text-primary);
    }

    .mobile-drawer-close {
        margin-left: auto;
        background: none;
        border: none;
        cursor: pointer;
        color: var(--text-muted);
        padding: 4px;
        border-radius: 6px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: var(--transition);
    }

    .mobile-drawer-close:active {
        color: var(--text-primary);
    }

    .mobile-drawer-section {
        padding: 8px 10px;
        flex: 1;
    }

    .mobile-drawer-section-title {
        font-size: 0.68rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--text-muted);
        padding: 8px 10px 4px;
    }

    .mobile-drawer-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 13px 12px;
        border-radius: 10px;
        cursor: pointer;
        color: var(--text-secondary);
        font-size: 0.92rem;
        font-weight: 500;
        transition: var(--transition);
        text-decoration: none;
        margin-bottom: 2px;
        border: none;
        background: none;
        width: 100%;
        text-align: left;
    }

    .mobile-drawer-item:active,
    .mobile-drawer-item.active {
        background: var(--bg-hover);
        color: var(--accent);
    }

    .mobile-drawer-item-icon {
        width: 36px;
        height: 36px;
        border-radius: 9px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.1rem;
        background: var(--bg-secondary);
        flex-shrink: 0;
        transition: var(--transition);
    }

    .mobile-drawer-item.active .mobile-drawer-item-icon {
        background: rgba(99, 102, 241, 0.15);
    }

    .mobile-drawer-footer {
        padding: 12px 14px;
        border-top: 1px solid var(--border);
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .mobile-drawer-user {
        display: flex;
        align-items: center;
        gap: 10px;
        flex: 1;
    }

    .mobile-drawer-avatar {
        width: 38px;
        height: 38px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--accent), #8b5cf6);
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 0.85rem;
        color: white;
        flex-shrink: 0;
    }

    .mobile-drawer-user-info {
        flex: 1;
        min-width: 0;
    }

    .mobile-drawer-user-name {
        font-size: 0.88rem;
        font-weight: 600;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-drawer-user-role {
        font-size: 0.72rem;
        color: var(--text-muted);
    }

    /* ===== Bottom Navigation Bar ===== */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: var(--bg-card);
        border-top: 1px solid var(--border);
        z-index: 500;
        align-items: stretch;
        padding: 0 4px;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    }

    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 4px 2px;
        border: none;
        background: none;
        cursor: pointer;
        color: var(--text-muted);
        border-radius: 10px;
        transition: var(--transition);
        text-decoration: none;
        position: relative;
    }

    .mobile-nav-item.active {
        color: var(--accent);
    }

    .mobile-nav-item:active {
        transform: scale(0.93);
    }

    .mobile-nav-icon {
        font-size: 1.35rem;
        line-height: 1;
        position: relative;
    }

    .mobile-nav-label {
        font-size: 0.65rem;
        font-weight: 600;
        letter-spacing: 0.02em;
        white-space: nowrap;
    }

    .mobile-nav-dot {
        position: absolute;
        top: -1px;
        right: -4px;
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: var(--accent);
        border: 2px solid var(--bg-card);
    }

    /* Active indicator pill */
    .mobile-nav-item.active::before {
        content: '';
        position: absolute;
        top: 5px;
        left: 50%;
        transform: translateX(-50%);
        width: 24px;
        height: 3px;
        border-radius: 2px;
        background: var(--accent);
    }

    /* ===== Main Content Mobile ===== */
    .main-content {
        padding: 12px 14px 16px;
    }

    /* ===== Page Header Mobile ===== */
    .page-header {
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px 0 10px;
    }

    .page-title {
        font-size: 1.15rem;
    }

    .page-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }

    .page-actions .btn {
        flex: 1;
        justify-content: center;
        min-height: 40px;
        font-size: 0.82rem;
    }

    /* ===== Buttons — Touch Targets ===== */
    .btn {
        min-height: 40px;
        padding: 8px 16px;
        font-size: 0.85rem;
        border-radius: 10px;
    }

    .btn-sm {
        min-height: 36px;
        padding: 6px 12px;
    }

    /* ===== Forms — Touch Friendly ===== */
    .form-control,
    input.form-control,
    select.form-control,
    textarea.form-control {
        min-height: 44px;
        font-size: 16px !important;
        /* prevents iOS zoom */
        padding: 10px 12px;
        border-radius: 10px;
    }

    select.form-control {
        padding-right: 32px;
    }

    .form-group {
        margin-bottom: 14px;
    }

    label,
    .form-label {
        font-size: 0.82rem;
        font-weight: 600;
        margin-bottom: 5px;
    }

    /* ===== Cards ===== */
    .card {
        border-radius: 14px;
        padding: 14px;
        margin-bottom: 12px;
    }

    /* ===== Tables — Horizontal Scroll ===== */
    .table-wrapper,
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 10px;
    }

    table {
        min-width: 600px;
    }

    /* ===== Filters Row ===== */
    .filter-bar,
    .filters-row {
        flex-direction: column;
        gap: 8px;
    }

    .filter-bar .btn,
    .filter-bar select,
    .filter-bar input {
        width: 100%;
    }

    /* ===== Modal — Bottom Sheet on Mobile ===== */
    .modal-overlay {
        align-items: flex-end !important;
        background: rgba(0, 0, 0, 0.5) !important;
    }

    /* Full-screen module modals (sipariş, teklif, vb.) remain full-screen */
    .modal-overlay .modal,
    .modal-overlay .modal-content {
        border-radius: 20px 20px 0 0;
        max-height: 95vh;
        height: 95vh;
    }

    /* Smaller popups (picker, delete confirm) as real bottom sheets */
    .modal-overlay.modal-sm .modal,
    .modal-overlay.modal-sm .modal-content {
        max-height: 70vh;
        height: auto;
    }

    .modal-header {
        padding: 14px 18px;
    }

    .modal-header h3,
    .modal-header h2 {
        font-size: 1rem;
    }

    /* Modal drag handle */
    .modal-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: var(--border);
    }

    /* ===== Picker Modal ===== */
    #pickerModal .modal {
        max-height: 92vh;
        height: 92vh;
        border-radius: 20px 20px 0 0;
    }

    /* Picker modal body → horizontal scroll */
    #pickerModal .modal-body {
        overflow-x: auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 0 12px 12px !important;
    }

    /* Picker search input */
    #pickerSearch {
        font-size: 16px !important;
        min-height: 42px;
        border-radius: 10px;
    }

    /* Picker table — compact, scrollable */
    #pickerTable {
        min-width: 420px;
        font-size: 0.8rem;
        border-collapse: collapse;
        width: 100%;
    }

    #pickerTable th {
        font-size: 0.68rem;
        padding: 8px 10px !important;
        white-space: nowrap;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
    }

    #pickerTable td {
        padding: 11px 10px !important;
        white-space: nowrap;
        vertical-align: middle;
    }

    /* Picker rows — bigger touch targets */
    .picker-row td {
        padding: 13px 10px !important;
    }

    /* Customer picker: hide email column (4th) */
    #pickerTable th:nth-child(4),
    #pickerTable td:nth-child(4) {
        display: none;
    }

    /* ===== Items Table (Sipariş kalemleri) ===== */

    .items-table-uyum {
        font-size: 0.78rem;
        min-width: 700px;
    }

    .tbl-input {
        font-size: 0.8rem;
        padding: 4px 6px;
        min-height: 32px;
    }

    /* ===== Stat Cards Grid ===== */
    .stats-grid,
    .dash-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card,
    .dash-stat-card {
        padding: 14px;
    }

    /* ===== Module/Feature Cards ===== */
    .module-grid,
    .dash-modules {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    /* ===== Toast ===== */
    .toast-container {
        bottom: 76px !important;
        right: 12px !important;
        left: 12px;
    }

    .toast {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* ===== Tabulator — Horizontal Scroll on Mobile ===== */
    .tabulator {
        border-radius: 12px;
        font-size: 0.82rem;
        overflow: hidden;
    }

    /* Enable horizontal scroll on the table area */
    .tabulator .tabulator-tableholder {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .tabulator .tabulator-header {
        overflow: visible;
    }

    .tabulator .tabulator-header .tabulator-col {
        padding: 8px 10px;
        font-size: 0.72rem;
    }

    .tabulator .tabulator-row .tabulator-cell {
        padding: 12px 10px;
        font-size: 0.82rem;
    }

    /* ===== Search input ===== */

    #searchInput {
        min-height: 40px;
        font-size: 16px !important;
        border-radius: 10px;
    }

    /* ===== Quick Action FAB (Floating Action Button) ===== */
    .mobile-fab {
        display: flex !important;
        position: fixed;
        bottom: 76px;
        right: 16px;
        width: 52px;
        height: 52px;
        border-radius: 50%;
        background: var(--accent);
        color: white;
        border: none;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        font-size: 1.4rem;
        box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
        z-index: 499;
        transition: var(--transition);
    }

    .mobile-fab:active {
        transform: scale(0.9);
    }

    /* ===== Company selector on mobile ===== */
    .company-selector-bar {
        padding: 6px 0;
    }

    /* ===== General spacing ===== */
    .section-gap {
        margin-bottom: 16px;
    }

    /* ===== Hide desktop-only elements ===== */
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: flex !important;
    }

    /* ======= Dark Mode Fixes Mobile ======= */
    [data-theme="dark"] .mobile-bottom-nav {
        background: #1e293b;
        border-top-color: #334155;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
    }

    [data-theme="dark"] .mobile-drawer {
        background: #1e293b;
    }

    [data-theme="dark"] .mobile-drawer-header {
        border-bottom-color: #334155;
    }

    [data-theme="dark"] .mobile-drawer-footer {
        border-top-color: #334155;
    }

    [data-theme="dark"] .mobile-drawer-item-icon {
        background: #334155;
    }
}

/* ===== Tablet (768px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .main-content {
        padding: 1rem 1.5rem;
    }

    .mega-api {
        display: none;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ===== Desktop: hide mobile-only elements ===== */
@media (min-width: 769px) {
    .mobile-menu-toggle {
        display: none !important;
    }

    .mobile-drawer {
        display: none !important;
    }

    .mobile-drawer-overlay {
        display: none !important;
    }

    .mobile-bottom-nav {
        display: none !important;
    }

    .mobile-fab {
        display: none !important;
    }

    .mobile-only {
        display: none !important;
    }
}