/* Mobile & foldable upgrades (pairs with js/mobile-plus.js) */

/* ---- 19. Hebrew-capable font stack (Inter has no Hebrew glyphs, so the browser falls back to Heebo) ---- */
body,
button,
input,
select,
textarea {
    font-family: var(--font-sans, 'Inter'), 'Heebo', 'Assistant', system-ui, sans-serif;
}

[dir='rtl'],
[lang='he'],
.rtl,
.wa-rtl {
    font-family: 'Heebo', 'Assistant', var(--font-sans, 'Inter'), system-ui, sans-serif;
}

@media (max-width: 768px) {
    html {
        font-size: 16px;
    }

    body {
        font-size: 1rem;
        line-height: 1.5;
        -webkit-text-size-adjust: 100%;
    }

    /* 16px fields: iOS/Chrome do not zoom the page on focus */
    input,
    select,
    textarea {
        font-size: 16px;
    }
}

/* ---- 3. Bottom bar (5 shortcuts) + 5. floating + ---- */
.bottom-nav {
    display: none;
}

@media (max-width: 1024px) {
    .bottom-nav {
        display: flex;
        padding-bottom: env(safe-area-inset-bottom);
        box-sizing: content-box;
    }

    .bottom-nav-item {
        flex: 1;
        min-width: 0;
        min-height: 48px;
        justify-content: center;
        font-size: 11px;
        padding: 6px 2px;
    }

    .bottom-nav-item[hidden] {
        display: none;
    }

    .main-content {
        padding-bottom: calc(88px + env(safe-area-inset-bottom));
    }
}

.ur-fab {
    display: none;
}

@media (max-width: 1024px) {
    .ur-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        right: 16px;
        bottom: calc(76px + env(safe-area-inset-bottom));
        width: 56px;
        height: 56px;
        border-radius: 50%;
        border: none;
        background: var(--primary-500, #6366f1);
        color: #fff;
        font-size: 22px;
        box-shadow: 0 6px 16px rgba(79, 70, 229, 0.45);
        z-index: 1001;
        cursor: pointer;
    }

    .ur-fab[hidden] {
        display: none;
    }

    .ur-fab:active {
        transform: scale(0.94);
    }
}

[dir='rtl'] .ur-fab {
    right: auto;
    left: 16px;
}

.action-sheet-items button {
    min-height: 56px;
}

/* ---- 12. Header: one "..." menu on phones ---- */
.ur-more-btn {
    display: none;
}

@media (max-width: 640px) {
    .ur-more-btn {
        display: inline-flex;
    }

    .header-right > .currency-selector,
    .header-right > .lang-toggle,
    .header-right > .theme-toggle,
    .header-right > button[onclick*='showKeyboardShortcuts'],
    .header-right > button[onclick*='roi-modal'] {
        display: none !important;
    }

    .header-right {
        gap: 4px;
    }
}

.ur-more-menu {
    position: fixed;
    top: 56px;
    right: 8px;
    min-width: 230px;
    max-width: calc(100vw - 16px);
    background: var(--bg-card, #fff);
    color: var(--text-primary, #0f172a);
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
    z-index: 3000;
    overflow: hidden;
}

.ur-more-menu button,
.ur-more-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    padding: 0 16px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-light, #e2e8f0);
    color: inherit;
    font-size: 15px;
    text-align: left;
    cursor: pointer;
}

.ur-more-row select {
    margin-left: auto;
    min-height: 36px;
}

.ur-more-menu i {
    width: 20px;
    text-align: center;
    color: var(--text-muted, #64748b);
}

/* ---- 14. voice search ---- */
.global-search {
    position: relative;
}

.ur-mic {
    background: none;
    border: none;
    color: var(--text-muted, #64748b);
    cursor: pointer;
    padding: 0 8px;
    min-width: 36px;
    min-height: 36px;
}

.ur-mic.listening {
    color: #ef4444;
    animation: ur-pulse 1s infinite;
}

@keyframes ur-pulse {
    50% {
        opacity: 0.4;
    }
}

/* ---- 9. offline bar ---- */
.ur-offline-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 4000;
    background: #b45309;
    color: #fff;
    font-size: 13px;
    padding: 6px 12px;
    text-align: center;
}

.ur-offline-bar[hidden] {
    display: none;
}

body.ur-offline .btn-primary,
body.ur-offline [type='submit'] {
    opacity: 0.5;
}

/* ---- 7. comfortable touch targets (touch screens only) ---- */
@media (pointer: coarse) {
    .btn,
    .btn-icon,
    .filter-chip,
    .chip,
    .tab,
    .currency-btn,
    .inbox-tab,
    select,
    td .btn,
    td button,
    td a.btn {
        min-height: 44px;
        min-width: 44px;
    }

    .btn-icon,
    td .btn-sm,
    td .btn-icon {
        padding-inline: 12px;
    }

    .nav-item {
        min-height: 48px;
    }

    .modal-close {
        min-width: 44px;
        min-height: 44px;
    }

    input[type='checkbox'],
    input[type='radio'] {
        width: 22px;
        height: 22px;
    }
}

/* ---- 4. cards: 3 main fields, rest behind "Details" ---- */
.ur-card-toggle,
.data-table td.ur-card-toggle-cell {
    display: none;
}

@media (max-width: 768px) {
    .data-table.card-converted tbody tr.mobile-card td.ur-extra {
        display: none;
    }

    .data-table.card-converted tbody tr.mobile-card.ur-open td.ur-extra {
        display: flex;
    }

    .ur-card-toggle {
        display: block;
        margin: 4px 0;
        padding: 0 12px;
        min-height: 44px;
        background: none;
        border: 1px solid var(--border-light, #e2e8f0);
        border-radius: 8px;
        color: var(--primary-500, #6366f1);
        font-size: 14px;
    }

    .data-table.card-converted td {
        gap: 12px;
        min-height: 32px;
        align-items: center;
    }
}

/* ---- 2. Foldable: outer screen (~380px) = one column, open screen (~880px) = two columns ---- */
@media (max-width: 420px) {
    .page-header,
    .page-header-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .stats-grid,
    .kpi-grid,
    .ds-kpis,
    .dashboard-grid,
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr !important;
    }

    .modal {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0;
        border-radius: 12px 12px 0 0;
    }
}

@media (min-width: 700px) and (max-width: 1024px) {
    .stats-grid,
    .kpi-grid,
    .ds-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .dashboard-grid,
    .grid-3,
    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* open fold: lists get the room for a master / detail look - cards in two columns */
    .units-grid,
    .cards-grid,
    .partners-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .modal {
        max-width: min(720px, 94vw);
    }
}

/* narrow cover screen: the header must fit - the user chip keeps only its avatar */
@media (max-width: 420px) {
    .user-display .user-name,
    .user-display .user-info,
    .user-display .fa-chevron-down {
        display: none;
    }

    .header-left .page-title {
        font-size: 1.05rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 38vw;
    }
}

/* phone search bar (opened from the ... menu; the desktop search box is hidden on phones) */
body.ur-search-open .global-search {
    display: flex !important;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    padding: 0 12px;
    background: var(--bg-card, #fff);
    border-bottom: 1px solid var(--border-light, #e2e8f0);
    z-index: 3500;
    width: auto;
    max-width: none;
}

body.ur-search-open .global-search input {
    flex: 1;
    min-width: 0;
}
