/* ERP AMITA 2.5.94 – mobile / portrait-first data and editing ergonomics.
   Progressive enhancement only: without JS, original tables retain horizontal scroll.
   All rules are scoped to ERP module areas; never target print/PDF. */
@media screen and (max-width: 760px), screen and (max-width: 1100px) and (orientation: portrait) {
    :is(body.np-erp-portal, body.toplevel_page_np-enterprise, .erp-wrapper) .np-erp-module-panel,
    body.np-erp-portal .np-erp-content,
    body.toplevel_page_np-enterprise .np-erp-content { min-width: 0; max-width:100%; box-sizing:border-box; }
    body.np-erp-portal .np-erp-content { padding: 12px 10px 110px !important; }
    body.np-erp-portal .np-erp-module-panel { padding: 12px 10px !important; overflow:visible !important; }
    body.np-erp-portal .np-erp-page-heading { gap:8px; flex-wrap:wrap; }

    /* One original row = one card. Original TDs and form controls remain the same nodes. */
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards {
        display:block !important;
        width:100% !important;
        min-width:0 !important;
        max-width:100% !important;
        table-layout:auto !important;
        border:0 !important;
        background:transparent !important;
        overflow:visible !important;
        border-collapse:separate !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > thead {
        position:absolute !important;
        width:1px !important;
        height:1px !important;
        padding:0 !important;
        margin:-1px !important;
        overflow:hidden !important;
        clip:rect(0,0,0,0) !important;
        white-space:nowrap !important;
        border:0 !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > tbody,
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > tfoot {
        display:block !important;
        width:100% !important;
        min-width:0 !important;
        border:0 !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr {
        display:block !important;
        width:100% !important;
        max-width:100% !important;
        min-width:0 !important;
        box-sizing:border-box !important;
        padding:10px 13px !important;
        margin:0 0 12px !important;
        background:#fff !important;
        border:1px solid #dbe4ef !important;
        border-radius:13px !important;
        box-shadow:0 3px 12px rgba(24,49,85,.05) !important;
        height:auto !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr[hidden],
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr[style*="display: none"] { display:none !important; }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th) {
        display:grid !important;
        grid-template-columns:minmax(98px, 37%) minmax(0,1fr) !important;
        gap:10px !important;
        width:100% !important;
        min-width:0 !important;
        max-width:100% !important;
        height:auto !important;
        white-space:normal !important;
        overflow-wrap:anywhere !important;
        box-sizing:border-box !important;
        text-align:left !important;
        align-items:start !important;
        padding:11px 1px !important;
        border:0 !important;
        border-bottom:1px solid #eef2f7 !important;
        background:transparent !important;
        font-size:14px !important;
        line-height:1.45 !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th):last-child { border-bottom:0 !important; }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th)[data-erp-label]::before {
        content:attr(data-erp-label);
        display:block;
        min-width:0;
        font-size:12px;
        line-height:1.35;
        color:#58708d;
        font-weight:700;
        white-space:normal;
        overflow-wrap:anywhere;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th).erp-mobile-field-cell {
        display:flex !important;
        flex-direction:column !important;
        align-items:stretch !important;
        gap:7px !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th).erp-mobile-full-row {
        display:block !important;
        width:100% !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th):first-child:not(.erp-mobile-field-cell) {
        font-weight:650 !important;
        color:#1c3656 !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th).erp-mobile-action-cell {
        display:flex !important;
        flex-wrap:wrap !important;
        align-items:center !important;
        gap:9px !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards .erp-mobile-action-cell::before {
        flex-basis:100%;
    }
    .erp-mobile-cards-wrap { overflow-x:visible !important; max-width:100% !important; }
    .erp-mobile-cards :is(input:not([type=checkbox]):not([type=radio]):not([type=hidden]),select,textarea),
    .erp-mobile-cards .select2-container,
    .erp-mobile-cards .erp-entity-picker { width:100% !important; min-width:0 !important; max-width:100% !important; box-sizing:border-box !important; }
    .erp-mobile-cards :is(input[type=checkbox],input[type=radio]) { width:20px !important; height:20px !important; min-width:20px !important; }

    /* Existing server-side / JS visibility rules must NOT be overridden by card display !important. */
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards:is([hidden],[aria-hidden="true"],.hidden,.is-hidden),
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr:is([hidden],[aria-hidden="true"],.hidden,.is-hidden,[style*="display:none"],[style*="display: none"]),
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th):is([hidden],[aria-hidden="true"],.hidden,.is-hidden,[style*="display:none"],[style*="display: none"]) {
        display:none !important;
    }

    /* One input per line. Native numeric/email/tel keyboards remain available. */
    :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content) :is(.erp-grid-2,.ep-fields,.ep-check-grid,.ep-doc-snapshot,.hrm-form-grid,.hrm-month-fields,.hrm-month-selector,.erp-form-grid) {
        grid-template-columns:minmax(0,1fr) !important;
    }
    :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content) form :is(input:not([type=hidden]):not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]),select,textarea) {
        max-width:100%; min-width:0; box-sizing:border-box; font-size:16px !important; min-height:44px;
    }
    :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content) form input[type=file] { width:100%; }
    :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content) :is(button,.erp-btn,.hrm-btn,input[type=submit],input[type=button],a.erp-btn) {
        min-height:44px; padding-top:9px; padding-bottom:9px; touch-action:manipulation;
    }
    :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content) :is(.erp-search-form,.ep-filters,.hrm-filters) { flex-wrap:wrap; max-width:100%; }
    :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content) :is(.erp-search-form,.ep-filters,.hrm-filters) > :is(input,select,button) { min-width:0; max-width:100%; }
    :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content) :is(.ep-surface,.erp-form-box,.hrm-panel,.ep-doc-group) { max-width:100%; box-sizing:border-box; }
}
@media print {
    /* Never transform invoices, quotations, signed minutes or reports in print/PDF. */
    table.erp-mobile-cards { display:table !important; }
}


/* 2.5.97.26: all mobile action groups must wrap cleanly across ERP list cards. */
@media screen and (max-width: 760px), screen and (max-width: 1100px) and (orientation: portrait) {
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards .erp-mobile-action-cell :is(.erp-quote-row-actions,.erp-contract-row-actions,.erp-row-actions,.ep-row-actions) {
        display:flex !important;
        flex-wrap:wrap !important;
        align-items:stretch !important;
        gap:8px !important;
        width:100% !important;
        min-width:0 !important;
        max-width:100% !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards .erp-mobile-action-cell :is(.erp-quote-row-actions,.erp-contract-row-actions,.erp-row-actions,.ep-row-actions) > * {
        flex:1 1 calc(50% - 8px) !important;
        min-width:0 !important;
        max-width:100% !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards .erp-mobile-action-cell :is(.erp-quote-row-actions,.erp-contract-row-actions,.erp-row-actions,.ep-row-actions) > :is(form,details) {
        display:flex !important;
        flex-direction:column !important;
        width:100% !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards .erp-mobile-action-cell :is(a.erp-btn,button.erp-btn,input[type=submit].erp-btn,.erp-btn,summary.erp-btn) {
        width:100% !important;
        min-width:0 !important;
        max-width:100% !important;
        white-space:normal !important;
        text-align:center !important;
        justify-content:center !important;
        word-break:break-word !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards .erp-mobile-action-cell :is(.erp-quote-row-actions,.erp-contract-row-actions,.erp-row-actions,.ep-row-actions) > :is(a.erp-quote-action-view,a.erp-contract-view) {
        flex-basis:100% !important;
    }
}


/* 2.5.97.27: common action flex rows should not force a horizontal scrollbar on desktop. */
@media screen and (min-width:761px) {
  :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content)
    :is(.erp-row-actions,.ep-row-actions) {
      flex-wrap:wrap;
      max-width:100%;
      min-width:0;
  }
  :is(.np-erp-module-panel,.erp-wrapper,.erp-module-content)
    :is(.erp-row-actions,.ep-row-actions) :is(a.erp-btn,button.erp-btn) {
      white-space:normal;
      max-width:100%;
      overflow-wrap:anywhere;
  }
}


/* 2.5.97.28: mobile cards use stacked label/content instead of 2-column label/value rows. */
@media screen and (max-width: 760px), screen and (max-width: 1100px) and (orientation: portrait) {
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th) {
        display:flex !important;
        flex-direction:column !important;
        align-items:stretch !important;
        gap:6px !important;
        padding:12px 2px !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th)[data-erp-label]::before {
        display:block !important;
        margin:0 !important;
        font-size:12px !important;
        line-height:1.35 !important;
        color:#58708d !important;
        font-weight:700 !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th) > * {
        min-width:0 !important;
        max-width:100% !important;
    }
    :is(.np-erp-module-panel, .erp-wrapper, .np-erp-content, .erp-module-content) table.erp-mobile-cards > :is(tbody,tfoot) > tr > :is(td,th).erp-mobile-action-cell {
        display:flex !important;
        flex-direction:column !important;
        align-items:stretch !important;
        gap:10px !important;
    }
}
