/*
 * ORBIT Mobile UX — final safe layer
 * Scope: mobile navigation, touch targets, safe-area spacing and drawer UX.
 * No quote, payment, cari or persistence logic is changed here.
 */

:root {
    --orbit-mobile-nav-height: 68px;
}

@media (max-width: 1024px) {
    html {
        scroll-padding-bottom: calc(var(--orbit-mobile-nav-height) + 24px + env(safe-area-inset-bottom, 0px));
    }

    body {
        overflow-x: hidden !important;
        padding-bottom: calc(var(--orbit-mobile-nav-height) + 20px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Keep five thumb-friendly destinations in one stable row. */
    .orbit-mobile-bottom-nav {
        display: grid !important;
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
        position: fixed !important;
        inset: auto 0 0 0 !important;
        width: 100% !important;
        height: calc(var(--orbit-mobile-nav-height) + env(safe-area-inset-bottom, 0px)) !important;
        min-height: var(--orbit-mobile-nav-height) !important;
        box-sizing: border-box !important;
        padding: 7px max(6px, env(safe-area-inset-left, 0px)) calc(7px + env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-right, 0px)) !important;
        gap: 4px !important;
        z-index: 7800 !important;
    }

    /* AI and marketplace remain available through the FAB/drawer; avoid a wrapped tab bar. */
    .orbit-mobile-bottom-nav .nav-item.mobile-nav-ai,
    .orbit-mobile-bottom-nav .nav-item.mobile-nav-secondary {
        display: none !important;
    }

    .orbit-mobile-bottom-nav .nav-item {
        display: flex !important;
        width: auto !important;
        min-width: 0 !important;
        min-height: 48px !important;
        padding: 6px 2px !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 3px !important;
        border-radius: 12px !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .orbit-mobile-bottom-nav .nav-item:focus-visible,
    .orbit-mobile-bottom-nav .nav-item:active {
        outline: 3px solid rgba(34, 211, 238, 0.78) !important;
        outline-offset: -3px !important;
    }

    .orbit-mobile-bottom-nav .nav-item i {
        font-size: 20px !important;
        line-height: 1 !important;
    }

    .orbit-mobile-bottom-nav .nav-item span {
        max-width: 100% !important;
        font-size: clamp(8.5px, 2.7vw, 10px) !important;
        line-height: 1.05 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* The dashboard action rail stays readable and tappable on narrow screens. */
    #main-content .orbit-hero-actions {
        display: grid !important;
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
        gap: 6px !important;
        overflow: visible !important;
    }

    #main-content .orbit-hero-actions button {
        width: 100% !important;
        min-width: 0 !important;
        min-height: 48px !important;
        padding: 7px 3px !important;
        gap: 3px !important;
        line-height: 1.05 !important;
        white-space: normal !important;
        touch-action: manipulation;
    }

    #main-content .orbit-hero-actions button span {
        max-width: 100% !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    #main-content .dashboard-quick-actions .quick-action-card,
    #main-content .orbit-mobile-shortcuts .quick-action-card {
        min-height: 92px !important;
        touch-action: manipulation;
    }

    /* Safe-area aware drawer with a visible close target. */
    #side-drawer {
        width: min(92vw, 380px) !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        padding-top: calc(20px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: calc(var(--orbit-mobile-nav-height) + 28px + env(safe-area-inset-bottom, 0px)) !important;
        overscroll-behavior: contain;
    }

    #drawer-close-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        align-self: flex-end;
        width: 44px;
        height: 44px;
        min-width: 44px;
        margin: -8px -4px 4px 0;
        border: 1px solid rgba(103, 232, 249, 0.35);
        border-radius: 12px;
        background: rgba(15, 23, 42, 0.72);
        color: #67e8f9;
        cursor: pointer;
        touch-action: manipulation;
    }

    #drawer-close-btn:focus-visible {
        outline: 3px solid rgba(34, 211, 238, 0.78);
        outline-offset: 2px;
    }

    #side-drawer .drawer-item {
        min-height: 46px !important;
        touch-action: manipulation;
    }

    .mobile-drawer-primary-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin: 0 0 12px;
    }

    .mobile-drawer-primary-action {
        min-width: 0;
        min-height: 52px;
        padding: 8px 6px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        border: 1px solid rgba(34, 211, 238, 0.3);
        border-radius: 12px;
        background: rgba(8, 145, 178, 0.14);
        color: #e2e8f0;
        font: inherit;
        font-size: 11px;
        font-weight: 800;
        cursor: pointer;
        touch-action: manipulation;
    }

    .mobile-drawer-primary-action i {
        font-size: 20px;
        color: #67e8f9;
        line-height: 1;
    }

    .mobile-drawer-primary-action:focus-visible,
    .mobile-drawer-primary-action:active {
        outline: 3px solid rgba(34, 211, 238, 0.78);
        outline-offset: 2px;
    }

    .mobile-drawer-search {
        min-height: 46px;
        display: flex;
        align-items: center;
        gap: 7px;
        margin: 0 0 12px;
        padding: 0 8px 0 11px;
        border: 1px solid rgba(148, 163, 184, 0.28);
        border-radius: 12px;
        background: rgba(2, 6, 23, 0.42);
        color: #67e8f9;
    }

    .mobile-drawer-search > i {
        flex: 0 0 auto;
        font-size: 18px;
    }

    #mobile-drawer-search-input {
        min-width: 0;
        width: 100%;
        height: 44px;
        border: 0;
        outline: 0;
        background: transparent;
        color: #f8fafc;
        font: inherit;
        font-size: 13px;
    }

    #mobile-drawer-search-input::placeholder {
        color: #94a3b8;
    }

    #mobile-drawer-search-clear {
        flex: 0 0 40px;
        width: 40px;
        height: 40px;
        min-width: 40px;
        border: 0;
        border-radius: 9px;
        background: transparent;
        color: #cbd5e1;
        cursor: pointer;
        touch-action: manipulation;
    }

    .mobile-drawer-search-empty {
        margin: 2px 0 12px;
        padding: 10px;
        border: 1px dashed rgba(148, 163, 184, 0.28);
        border-radius: 10px;
        color: #94a3b8;
        font-size: 12px;
        text-align: center;
    }

    /* The generated quick-action menu opens upward, clear of the tab bar. */
    #speed-dial-container.speed-dial-container {
        top: auto !important;
        right: max(12px, env(safe-area-inset-right, 0px)) !important;
        bottom: calc(var(--orbit-mobile-nav-height) + 14px + env(safe-area-inset-bottom, 0px)) !important;
        z-index: 10150 !important;
    }

    #speed-dial-main.speed-dial-main {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        min-height: 56px !important;
    }

    #speed-dial-container .speed-dial-actions {
        top: auto !important;
        right: 0 !important;
        bottom: 68px !important;
        width: min(340px, calc(100vw - 24px)) !important;
        max-width: calc(100vw - 24px) !important;
        max-height: calc(100dvh - var(--orbit-mobile-nav-height) - 104px) !important;
        overflow-y: auto !important;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px !important;
        padding: 8px !important;
        box-sizing: border-box !important;
        align-items: stretch !important;
        border: 1px solid rgba(103, 232, 249, 0.24);
        border-radius: 16px;
        background: rgba(2, 6, 23, 0.94);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
    }

    #speed-dial-container .speed-dial-action {
        width: 100% !important;
        min-width: 0 !important;
        min-height: 64px !important;
        box-sizing: border-box !important;
        padding: 9px 8px !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 7px !important;
        border-radius: 12px !important;
        white-space: normal !important;
    }

    #speed-dial-container .speed-dial-label {
        text-align: left;
        min-width: 0;
        font-size: 12px !important;
        line-height: 1.12 !important;
        white-space: normal !important;
    }

    #speed-dial-container .speed-dial-hint {
        font-size: 9px !important;
        line-height: 1.1 !important;
        white-space: normal !important;
    }

    /* Preserve content visibility above the fixed navigation. */
    #main-content,
    #quote-history-page,
    #crm-receivables-page,
    #current-accounts-page,
    #inventory-page,
    #finance-page,
    #kocak-proforma-page {
        scroll-padding-bottom: calc(var(--orbit-mobile-nav-height) + 26px + env(safe-area-inset-bottom, 0px));
    }
}

@media (min-width: 1025px) {
    #drawer-close-btn {
        display: none !important;
    }
}

@media (max-width: 430px) {
    :root {
        --orbit-mobile-nav-height: 64px;
    }

    #main-content .orbit-hero-actions {
        gap: 4px !important;
    }

    #main-content .orbit-hero-actions button {
        min-height: 46px !important;
        padding-inline: 2px !important;
    }

    #main-content .orbit-hero-actions button span {
        font-size: 8px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    #side-drawer,
    #drawer-overlay,
    #speed-dial-container,
    #speed-dial-container * {
        transition: none !important;
        animation: none !important;
    }
}

/* Login page safe-area and touch-target polish. */
@media (max-width: 640px) {
    body:has(#login-screen) {
        min-height: 100dvh;
        overflow-x: hidden;
        overflow-y: auto;
    }

    body:has(#login-screen) .login-container {
        min-height: 100dvh;
        height: auto;
        padding-top: max(76px, calc(76px + env(safe-area-inset-top, 0px)));
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    }

    body:has(#login-screen) .lang-btn,
    body:has(#login-screen) .toggle-password,
    body:has(#login-screen) .login-btn {
        min-height: 44px;
    }

    body:has(#login-screen) .form-input {
        min-height: 48px;
    }
}

/*
 * MOBILE FOOTER VISIBILITY FIX — 2026-09-12
 * Keep this as the final mobile-nav layer. Earlier visual layers define
 * different compact heights and overflow rules; this block makes the five
 * primary destinations deterministic on phones and tablets without touching
 * application or persistence logic.
 */
@media (max-width: 1024px) {
    :root {
        --orbit-mobile-nav-height: 82px;
    }

    body:not(:has(#login-screen)) {
        padding-bottom: calc(var(--orbit-mobile-nav-height) + 18px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .orbit-mobile-bottom-nav {
        display: grid !important;
        grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
        align-items: stretch !important;
        align-content: stretch !important;
        position: fixed !important;
        inset: auto 0 0 0 !important;
        width: 100% !important;
        height: calc(var(--orbit-mobile-nav-height) + env(safe-area-inset-bottom, 0px)) !important;
        min-height: calc(var(--orbit-mobile-nav-height) + env(safe-area-inset-bottom, 0px)) !important;
        box-sizing: border-box !important;
        padding: 9px max(6px, env(safe-area-inset-left, 0px)) calc(9px + env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-right, 0px)) !important;
        gap: 4px !important;
        overflow: visible !important;
        z-index: 9000 !important;
    }

    .orbit-mobile-bottom-nav .nav-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        width: auto !important;
        height: 100% !important;
        min-width: 0 !important;
        min-height: 0 !important;
        max-width: none !important;
        padding: 6px 2px !important;
        gap: 5px !important;
        overflow: visible !important;
        text-align: center !important;
        white-space: nowrap !important;
    }

    .orbit-mobile-bottom-nav .nav-item i {
        flex: 0 0 auto !important;
        line-height: 1 !important;
    }

    .orbit-mobile-bottom-nav .nav-item span {
        display: block !important;
        max-width: none !important;
        overflow: visible !important;
        text-overflow: clip !important;
        white-space: nowrap !important;
        line-height: 1.2 !important;
    }
}

@media (max-width: 360px) {
    :root {
        --orbit-mobile-nav-height: 78px;
    }

    .orbit-mobile-bottom-nav .nav-item {
        gap: 4px !important;
        padding-inline: 1px !important;
    }

    .orbit-mobile-bottom-nav .nav-item span {
        font-size: 9px !important;
    }
}

/* LOCAL VISUAL POLISH — mobile nav label fit */
@media (max-width: 760px) {
    .orbit-mobile-bottom-nav .nav-item {
        min-height: 52px !important;
    }

    .orbit-mobile-bottom-nav .nav-item i {
        flex: 0 0 22px !important;
    }

    .orbit-mobile-bottom-nav .nav-item span {
        font-size: clamp(9px, 2.5vw, 11px) !important;
        line-height: 1.2 !important;
        max-width: 100% !important;
        overflow: visible !important;
        text-overflow: clip !important;
        white-space: nowrap !important;
    }
}

@media (max-width: 380px) {
    .orbit-mobile-bottom-nav {
        gap: 3px !important;
        padding-inline: 3px !important;
    }

    .orbit-mobile-bottom-nav .nav-item {
        gap: 3px !important;
        padding-inline: 1px !important;
    }

    .orbit-mobile-bottom-nav .nav-item span {
        font-size: 8.8px !important;
    }
}
