/* =========================================================
   FOXFLOW CRM – MOBILE
   ========================================================= */

.ps-crm-related-tab-main {
    display: none;
}

.ps-crm-document-mobile-tabs {
    display: none;
}

@media (max-width: 767px) {

    /* =====================================================
       GENERELT
       ===================================================== */

    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }
    
        .ps-crm-related-tab-main {
        display: inline-flex;
    }

    .ps-crm-btn,
    button,
    input,
    select,
    textarea {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Skjul featured-panelet på mobil */
.ps-crm-card-featured {
    display: none !important;
}

/* Når featured-panelet er skjult må hovedinnholdet bruke hele bredden */
.ps-crm-card-wrap.has-featured-panel .ps-crm-card-body-layout,
.ps-crm-card-wrap.has-featured-panel .ps-crm-card-body-layout.has-featured {
    grid-template-columns: minmax(0, 1fr) !important;
}
    

    .ps-crm-document-mobile-tabs {
        display: flex;
        gap: 4px;
        padding: 4px 8px;
    }

    .ps-crm-document-mobile-tab {
        min-height: 30px;
        padding: 4px 8px;
        border: 0;
        border-radius: 6px;
        background: #e9e9e9;
        font-size: 13px;
    }

    .ps-crm-document-mobile-tab.is-active {
        background: #fff;
        font-weight: 600;
    }


    /* Dokument-fanen */
    .ps-crm-mobile-signing-panel {
        display: none;
    }


    /* Signering-fanen */
    .ps-crm-card-wrap.is-mobile-signing-tab .ps-crm-card-form {
        display: none !important;
    }

    .ps-crm-card-wrap.is-mobile-signing-tab .ps-crm-mobile-signing-panel {
        display: block;
    }
    
    .ps-crm-create-wrap {
    height: 100dvh;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.ps-crm-create-form {
    min-height: 0;
    overflow: visible;
}


    /* =====================================================
       LISTVIEW
       ===================================================== */

    /* Første rad: kolonnenavn */
    .ps-crm-list-table thead tr:first-child th {
        position: sticky !important;
        top: 0;
        z-index: 22;
        background: #fff;
    }

    /* Andre rad: søk/filter */
    .ps-crm-list-table thead tr.ps-crm-filter-row th {
        position: sticky !important;
        top: 20px;
        z-index: 21;
        background: #fff;
    }

    
.ps-crm-list-wrap {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding: 6px;
    margin-bottom: 0;

    overflow-y: auto;
    overflow-x: hidden;

    -webkit-overflow-scrolling: touch;
}

    .ps-crm-list-toolbar {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        gap: 6px;
        width: 100%;
    }

    .ps-crm-list-toolbar > div:first-child {
        flex: 1 1 auto;
        min-width: 0;
    }

    .ps-crm-list-heading-row {
        width: 100%;
        min-width: 0;
    }

    .ps-crm-list-saved-filter-bar {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center;
        gap: 6px;
        width: 100%;
        min-width: 0;
    }

    .ps-crm-list-form {
        width: 100%;
        min-width: 0;
    }

.ps-crm-list-table-scroll {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: 100%;

    overflow-x: auto;
    overflow-y: auto;

    -webkit-overflow-scrolling: touch;
}

    .ps-crm-list-table {
        min-width: 720px;
    }

    .ps-crm-list-table th,
    .ps-crm-list-table td {
        padding: 5px 8px;
        font-size: 12px;
        line-height: 1.3;
    }

    .ps-crm-list-cell-content {
        max-width: 220px;
        line-height: 1.3;
    }


    /* =====================================================
       FILTER + SØK
       ===================================================== */

    .ps-crm-list-saved-filter-form {
        flex: 0 0 auto;
        width: auto;
    }

    .ps-crm-list-saved-filter-dropdown {
        width: 100px !important;
        min-width: 100px !important;
        max-width: 100px !important;
    }

    .ps-crm-list-saved-filter-bar .ps-crm-search-wrap {
        flex: 1 1 auto;
        width: auto !important;
        min-width: 0;
        max-width: none !important;
    }

    .ps-crm-search-input {
        width: 100%;
        height: 30px !important;
        min-height: 30px !important;
        padding: 0 8px;
        font-size: 12px !important;
    }

    .ps-crm-filter-main-input,
    .ps-crm-filter-row select,
    .ps-crm-filter-row input[type="text"],
    .ps-crm-filter-row input[type="number"] {
        height: 30px;
        min-height: 30px;
        font-size: 12px;
    }

    .ps-crm-list-actions {
        display: flex !important;
        flex: 0 0 auto;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 6px;
        width: auto !important;
    }

    .ps-crm-list-toolbar .ps-crm-btn-secondary,
    .ps-crm-list-columns-open-btn,
    [data-open-list-columns-modal],
    .ps-crm-list-topbar-inline {
        display: none !important;
    }


    /* =====================================================
       DOKUMENTER I LISTVIEW
       ===================================================== */

    .ps-crm-list-cell-content .ps-crm-document-link-chip-wrap {
        gap: 4px;
    }

    .ps-crm-list-cell-content .ps-crm-document-link-chip {
        padding: 4px 7px;
        gap: 4px;
        font-size: 11px;
        box-shadow: none;
    }

    .ps-crm-list-cell-content .ps-crm-document-link-chip::before {
        font-size: 11px;
    }

    .ps-crm-list-cell-content .ps-crm-document-link-chip-action {
        width: 26px;
        height: 26px;
        min-width: 26px;
        flex: 0 0 26px;
        box-shadow: none;
    }

    .ps-crm-list-cell-content
    .ps-crm-document-link-chip-action
    .ps-crm-icon {
        width: 13px;
        height: 13px;
    }


    /* =====================================================
       CARDVIEW
       ===================================================== */

    .ps-crm-card-page {
        width: 100%;
        height: 100dvh;
        min-height: 0;
        gap: 6px;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .ps-crm-card-header {
        padding: 8px 10px;
        gap: 4px;
    }

    .ps-crm-card-header-top,
    .ps-crm-card-header-bottom {
        width: 100%;
        min-width: 0;
    }

    .ps-crm-card-header-bottom {
        flex-direction: column;
        align-items: stretch;
    }

    /* Beholder KUNDE / PROSJEKT osv */
    .ps-crm-card-header-meta {
        font-size: 11px;
        gap: 5px;
    }

    .ps-crm-card-header-meta .ps-crm-card-header-icon,
    .ps-crm-card-header-meta .ps-crm-card-header-icon svg {
        width: 12px;
        height: 12px;
    }

    .ps-crm-card-title {
        font-size: 16px;
        line-height: 1.15;
    }

    .ps-crm-card-actions {
        width: 100%;
        justify-content: flex-start;
        gap: 5px;
    }
    
    .ps-crm-card-wrap {
    width: auto;
    height: auto !important;
    min-height: 0 !important;
    margin: 6px;
    border-radius: 10px;
    overflow: visible;
}


    .ps-crm-related-tabs-wrap.is-main-tab-active .ps-crm-list-toolbar,
    .ps-crm-related-tabs-wrap.is-main-tab-active .ps-crm-list-saved-filter-bar,
    .ps-crm-related-tabs-wrap.is-main-tab-active .ps-crm-list-table thead tr:first-child th.ps-crm-col-is-resizable,
    .ps-crm-related-tabs-wrap.is-main-tab-active .ps-crm-list-table thead .ps-crm-filter-row th,
    .ps-crm-related-tabs-wrap.is-main-tab-active .ps-crm-list-table th,
    .ps-crm-related-tabs-wrap.is-main-tab-active .ps-crm-list-table td,
    .ps-crm-related-tabs-wrap.is-main-tab-active .ps-crm-list-footer {
        display: none !important;
    }

    .ps-crm-related-tabs-wrap.is-main-tab-active .ps-crm-related-tabs-nav {
        margin-bottom: 80px;
    }

/* Relasjonsfane valgt */
.ps-crm-related-tabs-wrap.is-related-tab-active
.ps-crm-related-content {
    display: block !important;
}

    /* Når hovedfanen er aktiv:
       ikke vis første relasjonsfane som aktiv */
    .ps-crm-related-tabs-wrap.is-main-tab-active
    .ps-crm-related-tab:not(.ps-crm-related-tab-main).is-active {
        background: transparent !important;
        color: inherit !important;
        box-shadow: none !important;
    }

    /* Hovedfanen skal se aktiv ut */
    .ps-crm-related-tabs-wrap.is-main-tab-active
    .ps-crm-related-tab-main {
        background: #fff;
    }


    /* =====================================================
       CARDVIEW GRID
       ===================================================== */

.ps-crm-card-grid,
.ps-crm-card-grid.is-standard-grid,
.ps-crm-card-grid.is-quickview-grid,
.ps-crm-create-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px !important;
}

.ps-crm-card-grid > .ps-crm-span-1,
.ps-crm-create-grid > .ps-crm-span-1 {
    grid-column: span 1 !important;
}

.ps-crm-card-grid > .ps-crm-span-2,
.ps-crm-card-grid > .ps-crm-span-3,
.ps-crm-card-grid > .ps-crm-span-4,
.ps-crm-create-grid > .ps-crm-span-2,
.ps-crm-create-grid > .ps-crm-span-3,
.ps-crm-create-grid > .ps-crm-span-4 {
    grid-column: span 2 !important;
}

    .ps-crm-card-body {
        height: auto;
        min-height: 0;
        max-height: none;
        padding: 8px;
        overflow: visible;
    }

    .ps-crm-card-main,
    .ps-crm-card-form {
        width: 100%;
        min-width: 0;
    }


    /* =====================================================
       FELTER
       ===================================================== */

    .ps-crm-card-field,
    .ps-crm-create-field {
        width: 100%;
        min-width: 0;
        font-size: 13px;
    }

    .ps-crm-card-value input,
    .ps-crm-card-value select,
    .ps-crm-card-value textarea,
    .ps-crm-create-value input,
    .ps-crm-create-value select,
    .ps-crm-create-value textarea,
    .ps-crm-input {
        height: 32px;
        padding: 2px 8px;
        border-radius: 7px;
        font-size: 13px;
    }

    .ps-crm-card-value textarea,
    .ps-crm-create-value textarea,
    textarea.ps-crm-input {
        height: auto;
        min-height: 60px;
        line-height: 1.35;
    }
    
.ps-crm-date-control {
    min-height: 32px !important;
    height: 32px;
    border-radius: 7px;
    padding-left: 32px;
    padding-right: 30px;
}

.ps-crm-date-control .flatpickr-input,
.ps-crm-date-alt-input {
    font-size: 13px !important;
    line-height: 1.2 !important;
}

.ps-crm-date-icon {
    left: 9px;
}

.ps-crm-date-icon svg {
    width: 13px;
    height: 13px;
}

.ps-crm-date-clear {
    right: 4px;
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    font-size: 14px;
}

    .ps-crm-custom-select-control,
    .ps-crm-multiselect-control {
        min-height: 32px;
        border-radius: 7px;
        font-size: 13px;
    }


/* =====================================================
   FANER / RELASJONER
   ===================================================== */

.ps-crm-card-bottom {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
}

.ps-crm-card-bottom-inner {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
}


/* TAB-NAVIGASJON */

.ps-crm-related-tabs-nav {
    position: sticky;
    top: 0;
    z-index: 20;

    display: flex;
    flex-wrap: nowrap;

    width: 100%;
    padding: 4px 4px 0;

    overflow-x: auto;
    overflow-y: hidden;

    -webkit-overflow-scrolling: touch;
}

.ps-crm-related-tab {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 4px 7px;
    gap: 4px;
}

.ps-crm-related-tab-label {
    font-size: 13px;
}

.ps-crm-related-tab-icon,
.ps-crm-related-tab .ps-crm-related-tab-icon {
    width: 13px !important;
    height: 13px !important;
}


/* RELASJONSINNHOLD */

.ps-crm-related-content {
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
}

.ps-crm-related-split {
    display: block !important;
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
}

.ps-crm-related-split-list {
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
}


/* Ingen quickview-kolonne på mobil */

.ps-crm-related-split-card {
    display: none !important;
}


/* Relasjonsliste bruker hele siden */

.ps-crm-related-split-list .ps-crm-list-wrap,
.ps-crm-related-split-list .ps-crm-list-form {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
}

.ps-crm-related-split-list .ps-crm-list-table-scroll {
    height: auto !important;
    max-height: none !important;

    overflow-x: auto !important;
    overflow-y: visible !important;
}


/* Når relasjonsfane er aktiv skjuler vi KUN prosjektfeltene */

.ps-crm-card-wrap.has-related-page-active > .ps-crm-card-body {
    display: none !important;
}

}