/* Purchasing uses the same workspace shell, surfaces and controls as record profiles. */
body:has(dialog.native-po-dialog[open]) { overflow: hidden; }
body:has(dialog.native-po-dialog[open]) #app-feedback .feedback-launcher { visibility: hidden; }
body dialog.native-po-dialog {
    display: none;
    padding: 0;
    overflow: hidden;
    color: var(--text);
    background: var(--panel);
    font: inherit;
}
body dialog.native-po-dialog[open] { display: flex; flex-direction: column; }
body dialog.native-po-dialog::backdrop { background: rgba(12, 20, 32, .22); backdrop-filter: blur(2px); }
@media (min-width: 768px) and (min-height: 560px) {
    body dialog.native-po-dialog[data-workspace-aligned="true"] {
        position: fixed;
        inset: auto;
        left: var(--workspace-modal-left);
        top: var(--workspace-modal-top);
        width: var(--workspace-modal-width) !important;
        max-width: var(--workspace-modal-width) !important;
        height: var(--workspace-modal-height) !important;
        max-height: var(--workspace-modal-height) !important;
        border: 1px solid var(--border) !important;
        border-radius: var(--workspace-modal-radius, 14px) !important;
        box-shadow: var(--shadow) !important;
    }
}
.native-po-dialog > * { min-width: 0; }
.native-po-header, .native-po-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex: 0 0 auto;
    padding: .65rem 1rem;
    background: var(--panel-elevated, var(--panel));
}
.native-po-header { border-bottom: 1px solid var(--border); }
.native-po-header > div { min-width: 0; }
.native-po-header h2 { margin: 0; font-size: 1.25rem; line-height: 1.35; overflow-wrap: anywhere; }
.native-po-header .eyebrow { margin: 0 0 .15rem; font-size: .67rem; }
.native-po-header .native-po-subtitle { margin: .2rem 0 0; line-height: 1.5; font-size: .8rem; overflow-wrap: anywhere; }
.native-po-header > button { flex: 0 0 44px; width: 44px; height: 44px; padding: 0; }
.native-po-tabs {
    display: flex;
    flex: 0 0 auto;
    gap: 0;
    overflow-x: auto;
    padding: 0 .75rem;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--control-bg, var(--panel-alt)) 74%, transparent);
    scrollbar-width: thin;
}
.native-po-tabs .native-po-tab {
    flex: 0 0 auto;
    min-height: 44px;
    padding: .6rem .9rem;
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    color: var(--muted);
    background: transparent;
    box-shadow: none;
    font: inherit;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
}
.native-po-tabs .native-po-tab:hover { color: var(--text); background: var(--panel); }
.native-po-tabs .native-po-tab[aria-current="page"] { color: var(--text); background: var(--panel); border-bottom-color: var(--accent); }
.native-po-tab:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.native-po-tab:disabled { opacity: .45; cursor: default; }
.native-po-body { flex: 1 1 0; min-height: 0; padding: 1rem; overflow: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.native-po-body > :first-child { margin-top: 0; }
.native-po-body > :last-child { margin-bottom: 0; }
.native-po-dialog > .status-line { flex: 0 0 auto; margin: 0; padding: .4rem 1rem; font-size: .8rem; line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
.native-po-dialog > .status-line:empty { display: none; }
.native-po-footer { justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--border); }
.native-po-footer:empty { display: none; }
.native-po-footer-actions, .native-po-dialog .pill-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.native-po-dialog .button { min-height: 40px; font-size: .82rem; cursor: pointer; }
.native-po-dialog .button:disabled { opacity: .52; cursor: wait; }
.native-po-dialog .button:focus-visible { outline: none; box-shadow: var(--focus-ring, 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent)); }
.native-po-form { display: grid; gap: 1rem; min-width: 0; }
.native-po-grid, .native-po-summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.native-po-grid > *, .native-po-summary-grid > * { min-width: 0; }
.native-po-section { margin: 0 0 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: var(--surface-radius-small, 12px); background: var(--panel); }
.native-po-form > .native-po-section, .native-po-summary-grid > .native-po-section { margin: 0; }
.native-po-summary-grid { margin-bottom: 1rem; }
.native-po-section :is(h3, h4) { margin: 0 0 .85rem; font-size: .95rem; font-weight: 650; line-height: 1.4; }
.native-po-section .native-po-section { padding: .9rem; background: var(--control-bg, var(--panel-alt)); }
.native-po-section > p, .native-po-receipt-form > p { margin: 0 0 .85rem; line-height: 1.6; font-size: .84rem; }
.native-po-dialog .card-heading { gap: .75rem; margin-bottom: 1rem; }
.native-po-dialog .card-heading h3 { margin: 0; font-size: 1rem; }
.native-po-details { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem 1rem; margin: 0; }
.native-po-details > div { min-width: 0; }
.native-po-details dt { color: var(--muted); font-size: .73rem; line-height: 1.4; }
.native-po-details dd { margin: .25rem 0 0; color: var(--text); font-size: .88rem; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.native-po-dialog .field { display: flex; flex-direction: column; min-width: 0; gap: .4rem; margin: 0; }
.native-po-dialog .field > span, .native-po-dialog .purchase-supplier-picker > label { font-size: .76rem; font-weight: 600; line-height: 1.4; }
.native-po-dialog :is(input, textarea, select) {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-height: 44px;
    padding: .6rem .7rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text);
    background: var(--control-bg, var(--panel-alt));
    font: inherit;
    font-size: .85rem;
    line-height: 1.4;
}
.native-po-dialog textarea { min-height: 84px; resize: vertical; }
.native-po-dialog :is(input, textarea, select):focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring, 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent)); }
.native-po-dialog input[readonly] { color: var(--muted); background: var(--panel); }
.native-po-dialog input[type="file"] { padding: .4rem; }
.native-po-dialog input[type="file"]::file-selector-button { padding: .45rem .7rem; margin-right: .65rem; border: 1px solid var(--border); border-radius: 7px; color: var(--text); background: var(--panel); font: inherit; cursor: pointer; }
.native-po-dialog input[type="file"]::file-selector-button:hover { border-color: var(--accent); }
.native-po-table-wrap { min-width: 0; max-width: 100%; overflow-x: auto; margin: .85rem 0; }
.native-po-dialog table { width: 100%; min-width: 700px; border-collapse: collapse; table-layout: auto; }
.native-po-dialog table :is(td, th) { width: auto !important; max-width: none !important; padding: .65rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; text-align: left; font-size: .84rem; }
.native-po-dialog table th { position: static; color: var(--muted); background: var(--control-bg, var(--panel-alt)); font-size: .7rem; font-weight: 600; white-space: nowrap; }
.native-po-dialog table td:first-child { width: 40% !important; min-width: 220px; }
.native-po-dialog table td:last-child:has(button) { width: 44px !important; }
.native-po-dialog td :is(input, textarea) { margin: 0; }
.native-po-dialog td input[type="number"] { width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
.native-po-dialog td .field + .field { margin-top: .4rem; }
.native-po-dialog td .field > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.native-po-number { white-space: nowrap; text-align: right !important; font-variant-numeric: tabular-nums; }
.native-po-summary-table td:not(:first-child) { white-space: nowrap; font-variant-numeric: tabular-nums; }
.native-po-totals { display: flex; justify-content: flex-end; gap: 1.75rem; margin: 1rem 0 0; }
.native-po-total { display: grid; gap: .25rem; min-width: 0; }
.native-po-total > span { color: var(--muted); font-size: .7rem; font-weight: 500; }
.native-po-total > strong { color: var(--text); font-size: 1rem; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.native-po-total:last-child > strong { font-size: 1.1rem; }
.native-po-receipt-footer { justify-content: space-between; }
.native-po-receipt-totals { margin: 0; justify-content: flex-start; gap: 1.5rem; }
.native-po-receipt-footer .native-po-footer-actions { margin-left: auto; }
.native-po-add:not(:empty) { padding: .9rem; border: 1px solid var(--border); border-radius: 10px; background: var(--control-bg, var(--panel-alt)); }
.native-po-add:not(:empty) > * + * { margin-top: .75rem; }
.native-po-choice { display: flex; align-items: flex-start; gap: .65rem; padding: .5rem 0; font-size: .85rem; }
.native-po-choice input { width: 18px; min-height: 18px; height: 18px; flex: none; margin-top: 2px; appearance: auto; }
.native-po-notes { margin: 0 !important; white-space: pre-wrap; overflow-wrap: anywhere; }
.native-po-job-order { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--border); }
.native-po-dialog summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
.native-po-dialog .ts-wrapper { width: 100%; min-width: 0; }
.native-po-dialog .ts-control { min-height: 44px; padding: .6rem .7rem; border-color: var(--border); border-radius: 9px; color: var(--text); background: var(--control-bg, var(--panel-alt)); font: inherit; font-size: .85rem; }
.native-po-dialog .ts-dropdown { z-index: 30; background: var(--panel-elevated, var(--panel)); color: var(--text); border-color: var(--border); }
.native-po-dialog .purchase-supplier-picker .ts-control { display: flex; align-items: center; gap: .35rem; }
.native-po-dialog .purchase-supplier-picker .ts-control > .item { flex: 0 1 auto; min-width: 0; max-width: 100%; color: var(--text); }
.native-po-dialog .purchase-supplier-picker .ts-control > input { width: 4px !important; min-width: 4px !important; min-height: 0 !important; flex: 1 1 auto; border: 0 !important; padding: 0 !important; box-shadow: none !important; background: transparent !important; }
.native-po-dialog .purchase-supplier-picker .field-help { margin: 0; font-size: .75rem; }
.native-po-dialog .purchase-supplier-picker > button { align-self: flex-start; }
#job-purchasing { margin-top: 1.25rem; border-top: 1px solid var(--border); padding-top: 1rem; }
#purchase-order-stages { display: flex; gap: .5rem; flex-wrap: wrap; padding: .5rem 0; }
#purchase-order-stages[hidden] { display: none; }
#purchase-order-stages [aria-pressed="true"] { background: var(--accent); color: var(--cta-text, white); }
@media (max-width: 767px) {
    .native-po-header { padding: max(.65rem, env(safe-area-inset-top)) max(.85rem, env(safe-area-inset-right)) .65rem max(.85rem, env(safe-area-inset-left)); }
    .native-po-header h2 { font-size: 1.1rem; }
    .native-po-body { padding: .85rem; scrollbar-gutter: auto; }
    .native-po-tabs { padding-inline: .4rem; }
    .native-po-grid, .native-po-summary-grid { grid-template-columns: minmax(0, 1fr); }
    .native-po-section { padding: .85rem; }
    .native-po-section .native-po-section { padding: .75rem; }
    .native-po-footer { padding: .65rem max(.85rem, env(safe-area-inset-right)) max(.65rem, env(safe-area-inset-bottom)) max(.85rem, env(safe-area-inset-left)); }
    .native-po-footer .button { min-height: 44px; }
    .native-po-footer > .button { flex: 1 1 auto; }
    .native-po-footer-actions { width: 100%; display: grid; grid-template-columns: auto minmax(0, 1fr); }
    .native-po-receipt-totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; width: 100%; }
    .native-po-receipt-totals .native-po-total > strong { font-size: .95rem; }
    .native-po-totals { gap: 1rem; }
    .native-po-dialog .pill-row { gap: .5rem; }
    .native-po-dialog .pill-row .button { flex: 1 1 auto; min-height: 44px; }
    .native-po-dialog .card-heading { align-items: flex-start; flex-wrap: wrap; }
    .native-po-dialog .native-po-line-table { display: block; min-width: 0; }
    .native-po-line-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .native-po-line-table tbody { display: grid; gap: .75rem; }
    .native-po-line-table tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, .8fr); gap: .7rem; padding: .85rem; border: 1px solid var(--border); border-radius: 10px; background: var(--control-bg, var(--panel-alt)); }
    .native-po-dialog .native-po-line-table td { min-width: 0; width: auto !important; padding: 0; border: 0; white-space: normal; }
    .native-po-dialog .native-po-line-table td:first-child { grid-column: 1 / -1; min-width: 0; width: auto !important; overflow-wrap: anywhere; }
    .native-po-dialog .native-po-line-table td:last-child:has(button) { grid-column: 1 / -1; width: auto !important; justify-self: end; }
    .native-po-dialog .native-po-line-table td input[type="number"] { width: 100%; padding: .6rem .45rem; text-align: left; }
    .native-po-dialog .native-po-line-table td .field > span { position: static; width: auto; height: auto; overflow: visible; clip-path: none; font-size: .67rem; font-weight: 500; color: var(--muted); }
    .native-po-summary-table tbody tr { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .native-po-summary-table td::before { content: attr(data-label); display: block; margin-bottom: .25rem; font-size: .67rem; color: var(--muted); }
    .native-po-summary-table td:first-child::before { display: none; }
    .native-po-dialog .native-po-line-table td textarea { min-height: 64px; }
}
