/*
 * «الإنشاءات» on a phone (CONSTRUCTION-MOBILE-1).
 *
 * Only ≤640px. Every list in the module shows one card per row (the
 * column's name over its value, two to a line) instead of a table that
 * slides sideways, and the pages whose header, numbers or editors spilled
 * past the screen edge fit it. Wider screens are untouched.
 *
 * Tables opt in through App\Support\Constructions\PhoneCards (Filament's
 * stackedOnMobile + the `cm-cards` class); this sheet only styles them.
 */
@media (max-width: 640px) {
    /* ── Lists: one card per row ───────────────────────────────── */
    .cm-cards .fi-ta-content-ctn { overflow: visible; max-height: none; min-height: 0; }
    .cm-cards .fi-ta-table.fi-ta-table-stacked-on-mobile { min-width: 0 !important; width: 100%; table-layout: auto; }
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px 12px;
        padding: 12px 14px;
        border-block-end: 1px solid var(--lm-d-divider);
    }
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td {
        display: block;
        height: auto;
        min-width: 0;
        padding: 0;
        border: 0;
        background: transparent;
        white-space: normal;
    }
    /* The record's name heads the card, full width, without its label. */
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td:first-child:not(.fi-ta-selection-cell),
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td.fi-ta-selection-cell + td {
        grid-column: 1 / -1;
    }
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td:first-child:not(.fi-ta-selection-cell) > .fi-ta-cell-label,
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td.fi-ta-selection-cell + td > .fi-ta-cell-label { display: none; }
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td:first-child:not(.fi-ta-selection-cell) .fi-ta-text-item,
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td.fi-ta-selection-cell + td .fi-ta-text-item { font-size: 15px; font-weight: 800; }
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td.fi-ta-selection-cell { position: absolute; inset-block-start: 12px; inset-inline-end: 12px; }
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row:has(> td.fi-ta-selection-cell) > td.fi-ta-selection-cell + td { padding-inline-end: 32px; }
    /* Row buttons: their own line at the card's end. */
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td:has(> .fi-ta-actions),
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr.fi-ta-row > td:has(> .fi-ta-cell-content > .fi-ta-col > .fi-ta-actions) { grid-column: 1 / -1; }
    .cm-cards .fi-ta-table-stacked-on-mobile .fi-ta-actions { justify-content: flex-end; padding: 0; }
    .cm-cards .fi-ta-table-stacked-on-mobile .fi-ta-cell-label {
        padding: 0;
        font-size: 12px;
        font-weight: 600;
        line-height: 1.4;
        color: var(--lm-d-muted);
    }
    .cm-cards .fi-ta-table-stacked-on-mobile .fi-ta-cell-content :is(.fi-ta-col, .fi-ta-col-wrp, .fi-ta-text, .fi-ta-icon, .fi-ta-col > div) { padding: 0 !important; }
    .cm-cards .fi-ta-table-stacked-on-mobile .fi-ta-cell-content :is(.fi-ta-text-item, .fi-ta-text-item-label) {
        font-size: 13.5px;
        line-height: 1.45;
        white-space: normal;
        overflow-wrap: anywhere;
    }
    .cm-cards .fi-ta-table-stacked-on-mobile .fi-ta-text-has-descriptions { gap: 0; }
    .cm-cards .fi-ta-table-stacked-on-mobile .fi-ta-text-description { font-size: 12px; }
    /* The totals row has no names on a phone; its figures already sit in
       the number strip above the list, so it waits for a wider screen. */
    .cm-cards .fi-ta-table-stacked-on-mobile > tbody > tr:is(.fi-ta-summary-row, .fi-ta-summary-header-row) { display: none; }

    /* ── Budgets list: title over its pills, numbers two to a line ── */
    .homei-budget-list .hb-list-tabs { flex-wrap: wrap !important; padding: 10px 14px; }
    .homei-budget-list .hb-list-tabs > * { flex-basis: 100%; margin-inline-start: 0; }
    .homei-budget-list .hb-list-tabs .fi-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-block-end: 2px; }
    .homei-budget-list .hb-list-tabs .fi-tabs::-webkit-scrollbar { display: none; }
    .homei-budget-list .hb-list-tabs .fi-tabs-item { flex: none; }
    .homei-budget-list .fi-ta-header-ctn { flex-wrap: wrap; }
    .homei-budgets .hb-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .homei-budgets .hb-kpi:nth-child(n) { border-inline-start: 0; border-top: 1px solid var(--hb-line); }
    .homei-budgets .hb-kpi:nth-child(-n + 2) { border-top: 0; }
    .homei-budgets .hb-kpi:nth-child(2n) { border-inline-start: 1px solid var(--hb-line); }
    .homei-budgets .hb-kpi-l,
    .homei-budgets .hb-kpi-c { white-space: normal; }

    /* ── One budget: the title above the pills; the add-items picker under the chips ── */
    .homei-budget-edit .hb-board > .fi-tabs,
    .homei-budget-edit .hb-board nav.fi-tabs { justify-content: flex-start; padding-block-start: 46px; }
    .homei-budget-edit .hb-board .hb-board-title { inset-inline-end: 14px; white-space: normal; flex-wrap: wrap; }
    .homei-budgets .hb-section .fi-section-content { grid-template-columns: minmax(0, 1fr); }
    .homei-budgets .hb-section .fi-section-content > .fi-grid-col:nth-child(1),
    .homei-budgets .hb-section .fi-section-content > .fi-grid-col:nth-child(2) { grid-column: 1; }
    .homei-budgets .hb-section .fi-section-content > .fi-grid-col:nth-child(2) { padding: 0 14px 8px !important; }
    .hb-tools { flex-wrap: wrap; }
    .hb-search, .hb-search input { inline-size: 100%; }

    /* ── One tender: each بند is a small card, nothing past the edge ── */
    .tx-doc-main .tender-items-sheet { overflow: visible; }
    .tx-doc-main .tender-items-sheet > table { min-width: 0; }
    .tx-doc-main .tender-items-sheet > table > tbody > tr {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px 12px;
        padding: 12px;
    }
    .tx-doc-main .tender-items-sheet > table > tbody > tr > td { min-width: 0; padding: 0; }
    .tx-doc-main .tender-items-sheet > table > tbody > tr > td:first-child { grid-column: 1 / -1; }
    .tx-doc-main .tender-items-sheet > table > tbody > tr > td:last-child { grid-column: 1 / -1; justify-self: end; }
    /* With no header row on a card, «قيمة العقد» shows its own name. */
    .tx-doc-main .tender-items-sheet > table > tbody > tr > td:not(:first-child) :is(.fi-fo-field-label-col, .fi-fo-field-label) { display: flex; }

    /* ── One time plan: a long «البند» wraps inside its box ── */
    .homei-schedule .ts-kpi { white-space: normal; }
    .homei-schedule .ts-kpi-v { white-space: normal; overflow-wrap: anywhere; }
}

/* «التخطيط الشهري»: the three views slide inside the bar instead of
   pushing the page past the screen edge (the bar is a column there). */
@container (max-width: 620px) {
    .mcp-tabs2 { min-inline-size: 0; max-inline-size: 100%; }
}
