/* ====================================================================
   ALZAR LOGIC — MOBILE / PHONE MODE
   Activated via body.is-mobile (set by js/core/device-mode.js).

   Approach: CSS-only show/hide. JS only sets the flag and body class.
   No JS re-mounting — heavy modules that aren't reached stay dormant.

   Breakpoint mirrors device-mode.js: max-width 768px or pointer:coarse
   ==================================================================== */

/* ── Visibility Utilities ───────────────────────────────────────────── */
/* Default: mobile-only content is hidden, desktop content is visible  */
.mobile-only { display: none !important; }

body.is-mobile .mobile-only  { display: revert !important; }
body.is-mobile .desktop-only { display: none !important; }

/* ── Shell Override: full-width single-column layout ────────────────── */
body.is-mobile #app-sidebar  { display: none !important; }
body.is-mobile #title-bar    { display: none !important; }

body.is-mobile #app-shell {
    grid-template-columns: 1fr;
    height: 100dvh;           /* dynamic viewport height respects browser chrome */
}

/* Content area: 4px side margin, leave room for bottom nav */
body.is-mobile #app-content {
    padding: 0 4px 64px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Compact topbar — full width, no side insets */
body.is-mobile #app-topbar {
    padding: 0;
    gap: 6px;
}
body.is-mobile .topbar-spacer { display: none; }
body.is-mobile #tb-global-search {
    flex: 1;
    max-width: 180px;
    min-width: 0;
}

/* Stack view header on narrow screens */
body.is-mobile .view-header {
    flex-wrap: wrap;
    row-gap: 6px;
    padding: 8px 12px 6px;
    min-height: unset;
}
body.is-mobile .view-header .header-actions {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
body.is-mobile .view-header .header-actions::-webkit-scrollbar { display: none; }
body.is-mobile .view-header .header-actions > * { flex-shrink: 0; }


/* ═══════════════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION BAR
   ═══════════════════════════════════════════════════════════════════════ */
#mobile-bottom-nav {
    display: none;                        /* hidden until body.is-mobile */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 500;
    height: 60px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--color-bg-surface, #1a1a2e);
    border-top: 1px solid var(--color-border, rgba(255,255,255,0.08));
    align-items: stretch;
    justify-content: space-around;
}

body.is-mobile #mobile-bottom-nav { display: flex; }

.mobile-bnav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    flex: 1;
    min-width: 0;
    background: none;
    border: none;
    color: var(--color-text-muted, #888);
    font-family: var(--font-base, inherit);
    font-size: 10px;
    cursor: pointer;
    padding: 4px 2px;
    border-radius: 0;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.mobile-bnav-item i {
    font-size: 22px;
    line-height: 1;
    flex-shrink: 0;
}
.mobile-bnav-item span {
    font-size: 9px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60px;
}
.mobile-bnav-item.active { color: var(--color-primary, #0ea5e9); }
.mobile-bnav-item:active  {
    background: var(--color-bg-hover, rgba(255,255,255,0.06));
}


/* ── Page body title (shared across all mobile pages) ──────────────── */
.mob-page-title {
    padding: 10px 14px 9px;
    font-size: 17px;
    font-weight: 700;
    color: var(--color-text-main, #f1f5f9);
    letter-spacing: -0.01em;
    flex-shrink: 0;
    border-bottom: 1px solid var(--color-border, rgba(255,255,255,0.07));
    background: var(--color-bg, #0f172a);
}

/* ── Workspace-Aware Bottom Nav Visibility ──────────────────────────── */
/* Default: hide ALL workspace-keyed items until workspace type is known */
.mobile-bnav-item[data-workspace] { display: none; }

/* "all" items always show (Dashboard, Settings) */
body.is-mobile .mobile-bnav-item[data-workspace~="all"] { display: flex; }

/* Service workspace */
body.is-mobile[data-workspace-type="service"]
    .mobile-bnav-item[data-workspace~="service"]          { display: flex; }

/* Manufacturing workspace */
body.is-mobile[data-workspace-type="manufacturing"]
    .mobile-bnav-item[data-workspace~="manufacturing"]    { display: flex; }

/* Agency */
body.is-mobile[data-workspace-type="agency"]
    .mobile-bnav-item[data-workspace~="agency"]           { display: flex; }

/* Agency HQ — same 5 fixed tabs as everyone else */
body.is-mobile[data-workspace-type="agency"]
    .mobile-bnav-item[data-workspace~="all"]              { display: flex; }

/* Standard / demo — show only "all" items */
body.is-mobile[data-workspace-type="standard"]
    .mobile-bnav-item[data-workspace~="standard"]         { display: flex; }
body.is-mobile[data-workspace-type="demo"]
    .mobile-bnav-item[data-workspace~="standard"]         { display: flex; }

/* Fallback: workspace type not yet set — show only "all" items */
body.is-mobile:not([data-workspace-type])
    .mobile-bnav-item[data-workspace~="all"]              { display: flex; }


/* ═══════════════════════════════════════════════════════════════════════
   MOBILE QUICK-ACTION BARS
   Horizontal scrollable chip row inside each page section.
   Only rendered on mobile via body.is-mobile (CSS-controlled).
   ═══════════════════════════════════════════════════════════════════════ */
.mobile-quickbar {
    display: none;
    gap: 8px;
    padding: 10px 12px;
    background: var(--color-bg-card, rgba(255,255,255,0.03));
    border-bottom: 1px solid var(--color-border, rgba(255,255,255,0.06));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap;
    align-items: center;
}
.mobile-quickbar::-webkit-scrollbar { display: none; }

body.is-mobile .mobile-quickbar { display: flex; }

.mobile-qbtn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    min-width: 68px;
    background: var(--color-bg-hover, rgba(255,255,255,0.06));
    border: 1px solid var(--color-border, rgba(255,255,255,0.08));
    border-radius: 10px;
    color: var(--color-text-main, #e0e0e0);
    font-size: 11px;
    font-family: var(--font-base, inherit);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.mobile-qbtn i {
    font-size: 20px;
    color: var(--color-primary, #0ea5e9);
}
.mobile-qbtn:active {
    background: rgba(14, 165, 233, 0.15);
    border-color: var(--color-primary, #0ea5e9);
}


/* ═══════════════════════════════════════════════════════════════════════
   DESKTOP-ONLY NOTICE
   Shown inside heavy modules when accessed from a mobile device.
   ═══════════════════════════════════════════════════════════════════════ */
.mobile-desktop-notice {
    display: none;
}
body.is-mobile .mobile-desktop-notice {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 24px;
    text-align: center;
    color: var(--color-text-muted, #888);
}
.mobile-desktop-notice i {
    font-size: 48px;
    opacity: 0.5;
}
.mobile-desktop-notice p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    max-width: 280px;
}
.mobile-desktop-notice strong {
    color: var(--color-text-main, #ccc);
}


/* ═══════════════════════════════════════════════════════════════════════
   PER-WORKSPACE CONTENT RULES
   ═══════════════════════════════════════════════════════════════════════ */

/* CFO: hide the ledger table and predictor on mobile (keep dashboard summary) */
body.is-mobile #cfo-tab-ledger,
body.is-mobile #cfo-tab-predictor { display: none !important; }

/* Hide the CFO sub-nav tabs that lead to hidden panels */
body.is-mobile .nav-sub-item[data-view="ledger"],
body.is-mobile .nav-sub-item[data-view="predictor"] { display: none; }

/* Inventory table: hide the bulk-action header bar on mobile */
body.is-mobile #inventoryPage .alzar-controls-bar {
    flex-direction: column;
    align-items: stretch;
}

/* Production header: hide board-vs-detail toggle on very small screens */
@media (max-width: 420px) {
    #prod-view-toggle { display: none !important; }
}

/* Agency / SOG: mark certain sections as desktop-only via class */
body.is-mobile[data-workspace-type="agency"] #estimatorPage .view-header .header-actions > *:not(:first-child),
body.is-mobile[data-workspace-type="agency"] #inventoryPage { opacity: 0.4; pointer-events: none; }


/* ═══════════════════════════════════════════════════════════════════════
   GENERAL MOBILE POLISH
   ═══════════════════════════════════════════════════════════════════════ */

/* Slightly larger tap targets on mobile */
body.is-mobile .btn { min-height: 38px; }

/* Scrollable tables rather than overflow-hidden */
body.is-mobile .alzar-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Ensure modals don't overflow screen */
body.is-mobile .alzar-modal,
body.is-mobile .modal-container {
    max-width: 100vw !important;
    border-radius: 16px 16px 0 0 !important;
    position: fixed !important;
    bottom: 0 !important;
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    max-height: 85dvh !important;
    overflow-y: auto !important;
    margin: 0 !important;
}

/* ── Bottom nav badge overlay (used by MobileShell._updateBadges) ───── */
.msh-bnav-icon {
    position: relative;
    display: inline-block;
    font-size: 22px;
    line-height: 1;
}

.msh-bnav-badge {
    position: absolute;
    top: -3px;
    right: -5px;
    min-width: 14px;
    height: 14px;
    background: #ef4444;
    color: #fff;
    border-radius: 7px;
    font-size: 8px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2px;
    pointer-events: none;
    line-height: 1;
}

.msh-bnav-badge:empty { display: none; }
