
/* ==========================================================================
   Creative Rarities - Mobile App UI
   Loaded ONLY on screens < 768px via media attribute
   ========================================================================== */

:root {
    --app-bg: #f4f6f8;
    --app-surface: #ffffff;
    --app-border: #e1e3e5;
    --app-text: #202223;
    --app-text-subdued: #6d7175;
    --app-primary: #008060;
    --app-primary-hover: #006e52;
    --app-radius: 12px;
    
    /* Badges */
    --badge-active-bg: #e4f8ec;
    --badge-active-text: #007f5f;
    --badge-draft-bg: #fff5ea;
    --badge-draft-text: #b76e00;
    --badge-out-bg: #ffeaec;
    --badge-out-text: #d72c0d;
    --badge-neutral-bg: #f4f6f8;
    --badge-neutral-text: #6d7175;
}

body.admin-body {
    background-color: var(--app-bg) !important;
    font-family: -apple-system, BlinkMacSystemFont, "San Francisco", "Segoe UI", Roboto, "Helvetica Neue", sans-serif !important;
}

/* Hide desktop specific buttons */
#back-to-store-btn,
.desktop-only {
    display: none !important;
}

/* Format mobile buttons */
.btn-outline {
    border: none !important;
    background: transparent !important;
    color: var(--app-text) !important;
    box-shadow: none !important;
}

#logout-btn {
    background: var(--app-bg) !important;
    border-radius: 50% !important;
    padding: 8px !important;
}
#logout-btn span.logout-text {
    display: none !important;
}

/* ==========================================
   Search Bar & Filters
   ========================================== */
.app-toolbar {
    background: var(--app-surface);
    padding: 12px 16px;
    border-bottom: 1px solid var(--app-border);
    position: sticky;
    top: 0px; 
    z-index: 999;
}

.app-search-wrapper {
    position: relative;
    margin-bottom: 12px;
}

.app-search-wrapper svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--app-text-subdued);
}

.app-search-input {
    width: 100%;
    background: var(--app-bg);
    border: 1px solid var(--app-border);
    border-radius: 8px;
    padding: 10px 10px 10px 36px;
    font-size: 1rem;
    color: var(--app-text);
    outline: none;
    box-sizing: border-box;
}

.app-search-input:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 2px rgba(0, 128, 96, 0.2);
}

.app-filters-scroll {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}

.app-filters-scroll::-webkit-scrollbar {
    display: none;
}

.app-filter-pill {
    white-space: nowrap;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid var(--app-border);
    background: var(--app-surface);
    color: var(--app-text);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.app-filter-pill.active {
    background: var(--app-text);
    color: var(--app-surface);
    border-color: var(--app-text);
}

.app-filter-pill.action-btn {
    background: #005bd3;
    color: white;
    border-color: #005bd3;
}

.pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.dot-green { background: #4CAF50; }
.dot-yellow { background: #FFC107; }
.dot-red { background: #F44336; }
.dot-gray { background: #9E9E9E; }

/* ==========================================
   App Cards (Products & Orders)
   ========================================== */
.app-cards-container {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-bottom: 100px;
}

.app-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 12px;
    display: flex;
    gap: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}

.app-card-image {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    background: var(--app-bg);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    flex-shrink: 0;
}

.app-card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.app-card-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.app-card-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.app-card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--app-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 8px;
}

.app-card-subtitle {
    font-size: 0.85rem;
    color: var(--app-text-subdued);
    margin-bottom: 6px;
}

.app-card-bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: auto;
}

.app-card-price {
    font-size: 1rem;
    font-weight: 600;
    color: var(--app-text);
}

.app-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-active { background: var(--badge-active-bg); color: var(--badge-active-text); }
.badge-draft { background: var(--badge-draft-bg); color: var(--badge-draft-text); }
.badge-out { background: var(--badge-out-bg); color: var(--badge-out-text); }
.badge-neutral { background: var(--badge-neutral-bg); color: var(--badge-neutral-text); }

/* Orders specific */
.app-order-card {
    flex-direction: column;
}
.order-customer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.customer-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #eecda3;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: #8c5e22;
    font-size: 0.9rem;
}
.customer-name {
    font-size: 0.9rem;
    font-weight: 500;
}
.order-items-preview {
    display: flex;
    gap: 8px;
    align-items: center;
}
.order-item-thumb {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background: var(--app-bg);
}
.order-item-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
}
.order-items-text {
    font-size: 0.85rem;
    color: var(--app-text-subdued);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.order-total-col {
    text-align: right;
}
.order-total-label {
    font-size: 0.75rem;
    color: var(--app-text-subdued);
}
.order-total-price {
    font-size: 1rem;
    font-weight: 700;
}
.order-details-link {
    font-size: 0.85rem;
    color: #005bd3;
    cursor: pointer;
    font-weight: 500;
}

/* ==========================================
   Dashboard Metrics
   ========================================== */
.app-dashboard {
    padding: 16px;
}
.app-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.app-metric-card {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    padding: 12px;
    text-align: left;
}
.app-metric-label {
    font-size: 0.75rem;
    color: var(--app-text-subdued);
    margin-bottom: 4px;
}
.app-metric-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--app-text);
}
.app-metric-trend {
    font-size: 0.75rem;
    margin-top: 4px;
    display: block;
}
.app-metric-trend.positive { color: #007f5f; }
.app-metric-trend.negative { color: #d72c0d; }

/* ==========================================
   Hide Unwanted Elements
   ========================================== */

#requests-gridContainer,
#issues-gridContainer {
    display: none !important;
}
/* Use off-screen rendering for main grids so DevExtreme fires onContentReady */
#products-gridContainer,
#orders-gridContainer {
    position: absolute !important;
    left: -9999px !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
}


#kpi-container {
    display: none !important;
}

.mobile-only-app {
    display: block !important;
}


/* Hide legacy desktop and mobile views */
.mobile-orders-view, #kpi-container, .desktop-only { display: none !important; }

/* Force App Views to block */
.mobile-only-app { display: block !important; }
svg.mobile-only-app { display: inline-block !important; }

/* Header Fixes */
#logout-btn span.logout-text { display: none !important; }

/* Home Tab specific hide */
#home-tab > *:not(#app-dashboard-view) {
    display: none !important;
}
#app-dashboard-view {
    display: block !important;
}

/* Bottom Navigation Bar */
.app-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--app-surface);
    border-top: 1px solid var(--app-border);
    display: flex !important;
    justify-content: space-around;
    padding: 10px 0;
    padding-bottom: env(safe-area-inset-bottom, 10px);
    z-index: 1000;
}
.app-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--app-text-subdued);
    font-size: 0.75rem;
    gap: 4px;
    cursor: pointer;
}
.app-nav-item.active {
    color: var(--app-primary);
}

/* Top Navigation Bar overrides */
.tabs-mobile-override {
    display: flex !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--app-surface);
    padding: 10px 16px;
    border-bottom: 1px solid var(--app-border);
    white-space: nowrap;
    gap: 8px;
    position: sticky;
    top: 58px;
    z-index: 998;
}
.tabs-mobile-override::-webkit-scrollbar { display: none; }
.tabs-mobile-override .tab {
    flex-shrink: 0;
    border: 1px solid var(--app-border) !important;
    background: var(--app-surface) !important;
    color: var(--app-text) !important;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 6px 14px !important;
    border-radius: 20px !important;
}
.tabs-mobile-override .tab.active {
    background: var(--app-text) !important;
    color: var(--app-surface) !important;
    border-color: var(--app-text) !important;
}
/* Hide bottom nav completely */
.app-bottom-nav { display: none !important; }


/* ── Nav Overlap Fix ─────────────────────────────────── */
/* The sticky tabs bar height is ~52px. Give each tab-content
   enough top padding so its first line of text is never hidden. */
.tab-content {
    padding-top: 60px !important;
}
/* The dashboard is self-contained; reset its padding so metrics
   sit right below the nav bar, not 60px below it. */
#home-tab {
    padding-top: 0 !important;
}
#app-dashboard-view {
    padding-top: 16px;
}

/* ── Make sure app-products-view shows on mobile ─────── */
#app-products-view {
    display: block !important;
}
#app-orders-view {
    display: block !important;
}

/* ── Hide the old legacy views on mobile ─────────────── */
.mobile-orders-view,
#mobile-orders-main,
.mobile-search-container,
#products-cards-overlay {
    display: none !important;
}

/* ── Keep product & order grids invisible but rendered ── */
#products-gridContainer,
#orders-gridContainer {
    position: absolute !important;
    left: -9999px !important;
    height: 1px !important;
    overflow: hidden !important;
    visibility: hidden !important;
}

/* ── Tabs toolbar sticks below header ─────────────────── */
.tabs-mobile-override {
    top: 58px !important;
}


/* ── FINAL FIX BLOCK ── */

/* 1. Hide ONLY specific desktop action-bar headers & buttons on mobile for updated tabs */
#home-tab .action-bar,
#home-tab .quick-actions-section,
#home-tab .kpi-section,
#products-tab .action-bar,
#products-tab .mobile-search-container,
#products-tab #toggle-products-view-btn,
#products-tab #refresh-products-btn,
#orders-tab .action-bar,
#orders-tab #refresh-orders-btn {
    display: none !important;
}

/* 2. Fix nav bar overlap — push ALL tab content below the sticky nav.
      Header ~58px + nav bar ~52px = 110px total.                      */
.tab-content {
    padding-top: 55px !important;
    box-sizing: border-box;
}

/* Dashboard doesn't have the nav bar padding issue (it's the first item) */
#home-tab {
    padding-top: 0 !important;
}
#app-dashboard-view {
    padding-top: 16px;
    padding-bottom: 80px;
}

/* 3. Products & Orders cards containers */
#app-products-view {
    display: block !important;
}
#app-orders-view {
    display: block !important;
}

/* 4. Hide the old mobile views completely */
.mobile-orders-view,
#mobile-orders-main,
/* 5. Off-screen grids so onContentReady still fires */
#products-gridContainer,
#orders-gridContainer {
    position: absolute !important;
    left: -9999px !important;
    top: 0 !important;
    width: 100px !important;
    height: 1px !important;
    overflow: hidden !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

/* 6. Products & Orders tabs — remove extra top padding from table-responsive */
#products-tab .table-responsive,
#orders-tab .table-responsive {
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    overflow: visible !important;
}


/* ── MOBILE NAV BAR ── */
#mobile-tab-nav {
    display: flex !important;
    display: flex !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    background: #ffffff;
    padding: 10px 12px;
    border-bottom: 1px solid #e1e3e5;
    white-space: nowrap;
    gap: 8px;
    position: sticky;
    top: 56px;
    z-index: 990;
    box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
.mobile-tab-nav-bar::-webkit-scrollbar { display: none; }

.mobile-nav-pill {
    display: inline-flex;
    flex-shrink: 0;
    padding: 7px 16px;
    border-radius: 20px;
    border: 1px solid #d0d0d0;
    background: #fff;
    color: #202223;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.mobile-nav-pill.active {
    background: #202223 !important;
    color: #fff !important;
    border-color: #202223 !important;
}

/* Hide the DESKTOP tabs bar on mobile only */
.tabs {
    display: none !important;
}


/* ── EMERGENCY FIX FOR MOBILE NAV BAR ── */
#mobile-tab-nav {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: sticky !important;
    top: 55px !important;
    z-index: 990 !important;
    background-color: var(--app-surface, #ffffff) !important;
    padding: 12px 16px !important;
    border-bottom: 1px solid rgba(0,0,0,0.1) !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    gap: 8px !important;
}

body.dark-mode #mobile-tab-nav,
[data-theme="dark"] #mobile-tab-nav {
    background-color: #161b22 !important;
    border-bottom: 1px solid rgba(255,255,255,0.1) !important;
}

#mobile-tab-nav .mobile-nav-pill {
    display: inline-flex;
    flex-shrink: 0;
    padding: 8px 16px !important;
    border-radius: 20px !important;
    border: 1px solid #d0d0d0 !important;
    background: #fff !important;
    color: #202223 !important;
    font-weight: 600 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    visibility: visible !important;
    opacity: 1 !important;
}

body.dark-mode #mobile-tab-nav .mobile-nav-pill,
[data-theme="dark"] #mobile-tab-nav .mobile-nav-pill {
    background: #21262d !important;
    color: #c9d1d9 !important;
    border-color: #30363d !important;
}

#mobile-tab-nav .mobile-nav-pill.active {
    background: var(--app-primary, #007bff) !important;
    color: #ffffff !important;
    border-color: var(--app-primary, #007bff) !important;
}

/* Fix overlap on Dashboard */
#home-tab {
    padding-top: 65px !important;
}


.mobile-fab { display: none !important; }


/* Force order items grid to display as tiles on mobile */
@media (max-width: 767px) {
    .items-grid-container .dx-datagrid-headers {
        display: none !important;
    }
    .items-grid-container .dx-data-row {
        display: grid !important;
        grid-template-columns: 35px 55px 1fr 1fr 35px;
        grid-template-rows: auto auto 1px auto auto auto;
        column-gap: 8px;
        row-gap: 4px;
        border: 1px solid var(--app-border, #e0e0e0) !important;
        border-radius: 12px !important;
        margin-bottom: 12px !important;
        padding: 12px 8px !important;
        background-color: #fff !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.05) !important;
    }
    
    .items-grid-container .dx-data-row > td {
        display: flex !important;
        align-items: center !important;
        border: none !important;
        padding: 0 !important;
        white-space: normal !important;
    }
    .items-grid-container .dx-data-row > td::before { display: none !important; }

    /* 1. Checkbox */
    .items-grid-container .dx-data-row > td:nth-child(1) { grid-column: 1; grid-row: 1 / span 2; justify-content: center; }
    
    /* 2. QR Code - hide */
    .items-grid-container .dx-data-row > td:nth-child(2) { display: none !important; }
    
    /* 3. Product No */
    .items-grid-container .dx-data-row > td:nth-child(3) { grid-column: 3; grid-row: 1; font-size: 0.8rem; color: #666; align-items: flex-end !important; }
    
    /* 4. Image */
    .items-grid-container .dx-data-row > td:nth-child(4) { grid-column: 2; grid-row: 1 / span 2; justify-content: center; align-items: flex-start !important; }
    .items-grid-container .dx-data-row > td:nth-child(4) img,
    .items-grid-container .dx-data-row > td:nth-child(4) .dx-template-wrapper { width: 48px !important; height: 48px !important; border-radius: 6px !important; object-fit: cover; }
    
    /* 5. Name */
    .items-grid-container .dx-data-row > td:nth-child(5) { grid-column: 3 / span 3; grid-row: 2; font-weight: 700; font-size: 0.95rem; line-height: 1.2; padding-bottom: 8px !important; align-items: flex-start !important; }
    
    /* 6. Quantity */
    .items-grid-container .dx-data-row > td:nth-child(6) { grid-column: 4; grid-row: 1; font-weight: 700; justify-content: flex-end; }
    .items-grid-container .dx-data-row > td:nth-child(6)::before { content: "Qty: "; display: inline !important; margin-right: 4px; font-weight: 700; }
    
    /* DIVIDER */
    .items-grid-container .dx-data-row::after {
        content: "";
        grid-column: 1 / span 5;
        grid-row: 3;
        height: 1px;
        background-color: #eee;
        margin: 4px 0 8px 0;
    }

    /* 7. Price */
    .items-grid-container .dx-data-row > td:nth-child(7) { grid-column: 2 / span 2; grid-row: 4; font-weight: 600; font-size: 0.95rem; }
    .items-grid-container .dx-data-row > td:nth-child(7)::before { content: "$ "; display: inline !important; margin-right: 4px; color: #666; font-weight: 400; }
    
    /* 8. Packing */
    .items-grid-container .dx-data-row > td:nth-child(8) { grid-column: 3; grid-row: 6; font-size: 0.85rem; justify-content: center; }
    .items-grid-container .dx-data-row > td:nth-child(8)::before { content: "Packing: "; display: inline !important; margin-right: 4px; color: #666; }
    
    /* 9. Product Cost */
    .items-grid-container .dx-data-row > td:nth-child(9) { grid-column: 2 / span 2; grid-row: 5; font-size: 0.85rem; }
    .items-grid-container .dx-data-row > td:nth-child(9)::before { content: "\1F4E6 "; display: inline !important; margin-right: 4px; font-size: 0.9rem; filter: grayscale(1); opacity: 0.6; }
    
    /* 10. Packing Cost */
    .items-grid-container .dx-data-row > td:nth-child(10) { grid-column: 2 / span 2; grid-row: 6; font-size: 0.85rem; }
    .items-grid-container .dx-data-row > td:nth-child(10)::before { content: "\1F3F7 "; display: inline !important; margin-right: 4px; font-size: 0.9rem; filter: grayscale(1); opacity: 0.6; }
    
    /* 11. Line Total */
    .items-grid-container .dx-data-row > td:nth-child(11) { display: none !important; }
    
    /* 12. Color */
    .items-grid-container .dx-data-row > td:nth-child(12) { grid-column: 4 / span 2; grid-row: 6; font-size: 0.85rem; font-weight: 600; justify-content: flex-start; }
    .items-grid-container .dx-data-row > td:nth-child(12)::before { content: "\1F535 "; display: inline !important; margin-right: 4px; font-size: 0.8rem; }
    
    /* 13. Comment */
    .items-grid-container .dx-data-row > td:nth-child(13) { grid-column: 4 / span 2; grid-row: 4 / span 2; background-color: #f0f2f5; border-radius: 6px; padding: 6px !important; font-size: 0.75rem; color: #555; align-items: flex-start !important; }
    
    /* 14. Delete button (dx-command-edit) */
    .items-grid-container .dx-data-row > td.dx-command-edit { grid-column: 5; grid-row: 1; justify-content: flex-end; }
    .items-grid-container .dx-data-row > td.dx-command-edit .dx-link { padding: 4px; }
}

@media (max-width: 767px) {
    .items-grid-container .dx-datagrid-header-panel { border: none !important; border-bottom: none !important; }
    .items-grid-container .dx-toolbar-before { width: 100% !important; display: flex !important; flex-direction: column; }
    .items-grid-container .dx-toolbar-item { width: 100% !important; margin-bottom: 8px; }
    .items-grid-container .add-line-btn { 
        width: 100% !important; 
        border-radius: 12px !important; 
        border: 1px solid #9aa5b1 !important; 
        background: #f8f9fa !important; 
        color: #1a202c !important; 
    }
    .items-grid-container .add-line-btn .dx-button-content { justify-content: center; }
}
