/* =============================================
   FlowMFG - Mobile-First Stylesheet
   Clean rebuild — no !important wars
   ============================================= */

/* ── Chart Container ────────────────────────── */
.flowmfg-chart-wrapper {
    width: 100%;
    overflow: hidden;
    position: relative;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    user-select: none;
    -webkit-user-select: none;
    /* Height set via inline style in renderVisualizer */
}

.flowmfg-chart-container,
#fm-graph-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: grab;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

#fm-graph-container:active {
    cursor: grabbing;
}

/* ── Bottom Nav (mobile only) ───────────────── */
.fm-mobile-nav {
    display: none;
}

/* ── Pinch hint ─────────────────────────────── */
#fm-pinch-hint {
    white-space: nowrap;
}

/* ── Print ──────────────────────────────────── */
@media print {
    body * { visibility: hidden; }
    #printable-area, #printable-area * { visibility: visible; }
    #printable-area { position: absolute; left: 0; top: 0; width: 100%; background: white; z-index: 9999; }
    .no-print { display: none !important; }
}

/* ── Custom scrollbar ───────────────────────── */
.flowmfg-wrapper ::-webkit-scrollbar { width: 6px; height: 6px; }
.flowmfg-wrapper ::-webkit-scrollbar-track { background: #f8fafc; }
.flowmfg-wrapper ::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* =============================================
   MOBILE — max-width 639px
   ============================================= */
@media (max-width: 639px) {

    /* Bottom nav */
    .fm-mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 200;
        background: #ffffff;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.07);
        height: 56px;
        align-items: stretch;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .fm-mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        background: none;
        border: none;
        cursor: pointer;
        padding: 4px 2px;
        font-size: 9px;
        font-weight: 600;
        color: #94a3b8;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        min-height: 56px;
    }

    .fm-mobile-nav-btn.active { color: #2563eb; }
    .fm-mobile-nav-btn i { width: 20px !important; height: 20px !important; }

    /* Desktop nav tabs — hide on mobile */
    .fm-desktop-tabs { display: none !important; }

    /* Main content — account for bottom nav */
    .flowmfg-wrapper main.flex-1 {
        padding-bottom: calc(56px + 8px) !important;
    }

    /* All interactive elements — remove tap flash, fast tap */
    .flowmfg-wrapper button,
    .flowmfg-wrapper a,
    .flowmfg-wrapper input,
    .flowmfg-wrapper select,
    .flowmfg-wrapper textarea {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* iOS zoom prevention — only on non-toolbar inputs */
    .flowmfg-wrapper input[type="text"]:not(.fm-toolbar-input),
    .flowmfg-wrapper input[type="number"],
    .flowmfg-wrapper input[type="email"],
    .flowmfg-wrapper input[type="date"],
    .flowmfg-wrapper textarea {
        font-size: 16px !important;
    }
    /* Toolbar selects and search boxes need 16px too but handled at a smaller display size */
    .flowmfg-wrapper select { font-size: 16px !important; }

    /* Minimum tap targets */
    .flowmfg-wrapper button {
        min-height: 36px;
    }

    /* Stock summary in item detail — 2x2 on mobile */
    .fm-stock-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Item detail action row */
    .fm-detail-actions {
        flex-wrap: wrap;
    }

    /* Chart height — calc from fixed heights:
       navbar=48px, controls~80px, gap~8px, bottomnav=56px, page padding=24px */
    .flowmfg-chart-wrapper {
        height: calc(100svh - 232px) !important;
        min-height: 240px;
    }

    /* Modal bottom sheet */
    #modals > div {
        align-items: flex-end;
    }

    /* Tables in modals — always scrollable */
    .fm-modal-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Section headings — compact on mobile */
    .fm-page-title {
        font-size: 0.95rem !important;
    }
}

/* ── Tablet 640-1023px ──────────────────────── */
@media (min-width: 640px) and (max-width: 1023px) {
    .fm-mobile-nav { display: none !important; }
}


/* =============================================
   iOS ZOOM PREVENTION
   Inputs smaller than 16px trigger auto-zoom on iOS Safari.
   Apply 16px to form/modal inputs, but NOT toolbar filters
   (which use h-9 and need to stay compact).
   ============================================= */

@media (max-width: 639px) {
    /* Modals — all inputs get 16px to prevent zoom */
    #modals input[type="text"],
    #modals input[type="number"],
    #modals input[type="email"],
    #modals input[type="date"],
    #modals select,
    #modals textarea {
        font-size: 16px !important;
    }

    /* Item detail page inputs */
    .flowmfg-wrapper main input[type="number"] {
        font-size: 16px !important;
    }

    /* Toolbar search inputs (not selects) */
    #search-items,
    #search-orders,
    #search-wo,
    #search-so {
        font-size: 16px !important;
    }

    /* Toolbar filter selects — keep compact, no zoom risk since user can't type */
    /* (selects don't trigger zoom - only text/number inputs do) */
}

/* =============================================
   MOBILE CARD POLISH
   ============================================= */

@media (max-width: 639px) {
    /* Card rows: better touch target and visual separation */
    .fm-mobile-card {
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        padding: 12px;
        box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    }

    /* Ensure action buttons in cards are full-width friendly */
    .fm-card-actions {
        display: flex;
        gap: 8px;
        margin-top: 10px;
    }

    /* Make the item list table row height comfortable */
    .flowmfg-wrapper table tbody tr td {
        padding-top: 10px !important;
        padding-bottom: 10px !important;
    }

    /* Fix items list table min-width — allow narrower on mobile */
    .flowmfg-wrapper table {
        min-width: 0 !important;
    }

    /* Items list table: hide price column, show inline on name */
    /* Keep as is - min-width:360px already handles horizontal scroll */
}

/* =============================================
   VISUALIZER HEIGHT
   ============================================= */

/* The visualizer page is a flex-col filling the main area.
   It needs the chart to fill remaining height after the controls bar.
   Using CSS to ensure proper height calculation. */

.flowmfg-chart-wrapper {
    /* Default: fills remaining flex space */
    flex: 1 1 0%;
    min-height: 240px;
}

@media (max-width: 639px) {
    /* On mobile: controls bar ~90px + gaps ~16px + bottom nav 56px + main padding 24px */
    .flowmfg-chart-wrapper {
        height: calc(100svh - 240px);
        flex: 1 1 auto;
        min-height: 240px;
    }
}

