/* MVP page components. Shared sizes live here; page-specific selectors stay scoped. */
:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --control-size: 48px;
  --finance-control-size: 50px;
  --table-row-size: 64px;
}
nav button { min-height: var(--control-size); height: auto; padding: 8px 12px; gap: 6px; font-size: 15px; }
.nav-icon { width: 20px; flex: 0 0 20px; }
.calendar-segments { min-height: var(--control-size); align-items: stretch; padding: 4px; }
.calendar-segments button { min-height: 38px; padding: 6px 12px; }
.dialog-actions > button,
.checkout-detail .actions > .primary { min-height: var(--finance-control-size); height: auto; }

/* Common list, control and status rules used by every MVP module. */
.page-head { align-items: center; gap: var(--space-4); }
.page-head .page-heading { min-width: 0; }
.page-head button { min-height: var(--control-size); height: auto; }
.toolbar { align-items: flex-end; gap: var(--space-3); }
.toolbar > label { min-width: 144px; gap: var(--space-2); color: var(--muted); font-size: 13px; line-height: 20px; }
.toolbar > label > :is(input,select) { min-height: var(--control-size); height: var(--control-size); color: var(--ink); font-size: 16px; }
.toolbar > :is(input,select,button) { min-height: var(--control-size); height: var(--control-size); }
.actions > button { min-height: var(--control-size); height: auto; white-space: normal; text-align: center; }
.list-row { gap: var(--space-4); min-height: 80px; padding: 12px 16px; }
.list-row > :is(span,button:only-child) { min-width: 0; }
.list-row > span:first-child { flex: 1 1 auto; overflow-wrap: anywhere; }
.list-row > button:only-child { flex: 1 1 auto; min-height: 48px; }
.list-row > button:not(:only-child) { flex: 0 0 auto; min-width: 64px; min-height: 44px; justify-content: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }
.list-row > strong { flex: 0 0 auto; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list-row > .badge { flex: 0 0 auto; }
.list-row small { line-height: 20px; overflow-wrap: anywhere; }
.badge { min-height: 24px; padding: 2px 8px; font-size: 13px; line-height: 20px; white-space: normal; text-align: left; }
.badge.pending { color: #825e15; background: #a879181e; }
.badge.void { color: var(--muted); background: var(--bg); }
.detail-head { align-items: center; }
.detail-head > :first-child { min-width: 0; }
.detail-head .badge { flex: 0 0 auto; }
.detail-fields { gap: var(--space-4) var(--space-6); }
.detail-fields dt { line-height: 20px; }
.detail-fields dd { line-height: 24px; }
.form-grid { gap: var(--space-4); }
.form-grid > label { min-width: 0; }
.metric { min-height: 120px; display: flex; flex-direction: column; justify-content: space-between; }
.metric strong { margin: 12px 0 0; line-height: 36px; }
.metric span { line-height: 20px; }
.table-scroll table th,
.table-scroll table td { padding: 12px 16px; vertical-align: middle; }
.table-scroll table th { font-size: 13px; line-height: 20px; }
.table-scroll table td { font-size: 15px; line-height: 22px; }
.table-scroll table .money,
.table-scroll table th.money { text-align: right; font-variant-numeric: tabular-nums; }
.settings-actions { padding-top: var(--space-2); }
.settings-actions .danger { order: 10; margin-left: auto; }
.section-heading { margin-top: 0; line-height: 26px; }
.settings-panel > label { max-width: 320px; }
.audit-list .list-row > span { min-width: 0; }
.audit-summary { margin: 0 0 24px; }
.audit-technical { border-top: 1px solid var(--line); padding-top: 16px; }
.audit-technical summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--brand); font-weight: 600; }
.audit-technical pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 320px; overflow: auto; padding: 16px; border-radius: 8px; background: var(--bg); font-size: 12px; line-height: 18px; }
.conflict-values > div { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
.conflict-values h3 { margin: 0 0 8px; }
.conflict-summary { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px 16px; margin: 16px 0; }
.conflict-summary dt { color: var(--muted); font-size: 13px; line-height: 20px; }
.conflict-summary dd { margin: 4px 0 0; font-size: 15px; line-height: 22px; overflow-wrap: anywhere; }
.entity-toolbar input { width: min(360px, 100%); }
.entity-list { padding: 8px; }
.list-row.entity-row > button { flex: 1 1 auto; min-width: 0; justify-content: flex-start; text-align: left; border: 0; }
.entity-row > button strong { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
.entity-row > .badge { flex: 0 0 auto; }
.entity-detail { min-width: 0; }
.schedule-table-wrap { margin: 16px 0 24px; border: 1px solid var(--line); border-radius: 12px; }
.schedule-table { min-width: 480px; }
.schedule-table thead th { background: var(--bg); }
.schedule-table tr > :first-child { width: 25%; }
.schedule-table tr > :nth-child(2) { width: 35%; }
.schedule-table tr > :nth-child(3) { width: 40%; }
.schedule-table tbody tr:last-child > * { border-bottom: 0; }
.checkout-booking > span:not(.badge) { flex: 1 1 auto; min-width: 0; }
.checkout-booking > .badge { flex: 0 0 auto; align-self: center; }
.checkout-order-link { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; }
.checkout-order-link > span { min-width: 0; flex: 1 1 auto; }
.checkout-order-link > strong { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.checkout-split { align-items: start; }
.checkout-detail { padding: 24px; }
.checkout-empty { max-width: 520px; }
.checkout-empty h2,.checkout-preview h2 { margin: 0 0 8px; font-size: 20px; line-height: 28px; }
.checkout-empty p,.checkout-preview > p { margin: 0; color: var(--muted); font-size: 14px; line-height: 22px; }
.checkout-preview-lines { margin: 20px 0; border-top: 1px solid var(--line); }
.checkout-preview-line { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 72px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.checkout-preview-line > span { min-width: 0; }
.checkout-preview-line strong { font-size: 15px; line-height: 22px; font-weight: 600; }
.checkout-preview-line > strong { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.checkout-preview-line small { display: block; margin-top: 4px; font-size: 13px; line-height: 20px; }
.checkout-preview-total { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 0 0 12px; }
.checkout-preview-total span { color: var(--muted); font-size: 13px; line-height: 20px; }
.checkout-preview-total strong { font-size: 28px; line-height: 36px; font-variant-numeric: tabular-nums; }
.checkout-preview-action { width: 100%; margin-top: 20px; min-height: var(--finance-control-size); }
@container (min-width: 900px) { .checkout-merge { display: none; } }
@media (max-width: 680px) {
  .sidebar nav button { min-height: 44px; }
  .page-head { align-items: flex-start; }
  .page-head button { white-space: normal; }
  .toolbar { gap: var(--space-2); }
  .toolbar > label { flex: 1 1 145px; }
  .settings-actions .danger { margin-left: 0; }
}

.finance-toolbar {
  align-items: flex-end;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.finance-toolbar label {
  min-width: 144px;
  gap: var(--space-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 20px;
}
.finance-toolbar label input,
.finance-toolbar > button {
  height: var(--control-size);
  min-height: var(--control-size);
  margin: 0;
}
.finance-toolbar label input { width: 100%; color: var(--ink); font-size: 16px; }
.finance-toolbar > button { white-space: nowrap; }

.order-table-panel { padding: 0; overflow: hidden; }
.order-table-scroll { max-width: 100%; overflow-x: auto; }
.order-table { table-layout: fixed; border-collapse: collapse; width: 100%; }
.order-table col.order-number-col { width: 24%; }
.order-table col.order-customer-col { width: auto; }
.order-table col.order-date-col { width: 144px; }
.order-table col.order-amount-col { width: 128px; }
.order-table col.order-status-col { width: 128px; }
.order-table col.order-action-col { width: 96px; }
.order-table th,
.order-table td { padding: 12px 16px; vertical-align: middle; border-bottom: 1px solid var(--line); }
.order-table thead th { height: 48px; color: var(--muted); font-size: 13px; line-height: 20px; font-weight: 600; background: var(--panel); }
.order-table tbody tr { min-height: var(--table-row-size); }
.order-table tbody td { height: var(--table-row-size); font-size: 15px; line-height: 22px; }
.order-table tbody tr:last-child td { border-bottom: 0; }
.order-table .order-name { font-weight: 600; overflow-wrap: anywhere; }
.order-table .order-customer { overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.order-table .order-amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.order-table .order-date { white-space: nowrap; font-variant-numeric: tabular-nums; }
.order-table .order-action { text-align: right; }
.order-table .order-action button { min-height: 44px; min-width: 64px; padding: 8px 10px; white-space: nowrap; }
.order-table .badge { min-height: 24px; padding: 2px 8px; font-size: 13px; line-height: 20px; white-space: normal; }
.order-table .badge.pending { color: #825e15; background: #a879181e; }
.order-table .badge.void { color: var(--muted); background: var(--bg); }
.order-table .order-card-label { display: none; }
.order-table-footer { padding: 12px 16px; color: var(--muted); font-size: 13px; line-height: 20px; border-top: 1px solid var(--line); }
.order-table-panel .empty { padding: 48px 20px; }
.ledger-table col.ledger-date-col { width: 144px; }
.ledger-table col.ledger-method-col { width: 152px; }
.ledger-table col.ledger-order-col { width: 27%; }
.ledger-table col.ledger-reference-col { width: auto; }
.ledger-table col.ledger-amount-col { width: 128px; }
.ledger-table .ledger-order-link { min-width: 0; min-height: 44px; max-width: 100%; border: 0; background: transparent; color: var(--brand); text-align: left; justify-content: flex-start; padding: 4px 0; overflow-wrap: anywhere; }
.ledger-table .ledger-reference { display: block; overflow-wrap: anywhere; }

#editor.sale-editor { width: min(880px, calc(100vw - 32px)); padding: 0; overflow: hidden; }
.sale-editor > form { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.sale-editor .dialog-head { padding: 24px 24px 16px; margin: 0; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.sale-editor .sale-body { overflow-y: auto; min-height: 0; padding: 24px; overscroll-behavior: contain; }
.sale-editor .dialog-actions { margin: 0; padding: 16px 24px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); position: static; flex: 0 0 auto; }
.sale-editor .dialog-actions button { min-height: var(--finance-control-size); height: auto; }
.sale-editor .dialog-actions button[type=submit] { min-width: 184px; }
.sale-editor .form-error { padding: 0 24px; flex: 0 0 auto; }
.sale-editor .sale-section-title { margin: 0 0 12px; font-size: 18px; line-height: 26px; }
.sale-editor .sale-lines { display: grid; gap: 12px; margin: 20px 0 12px; }
.sale-editor .sale-line { padding: 16px; margin: 0; border: 1px solid var(--line); background: var(--panel); }
.sale-editor .sale-line .form-grid { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1.15fr) minmax(116px, .7fr); gap: 12px 16px; }
.sale-editor .sale-line label { min-width: 0; }
.sale-editor .sale-line label:last-child { grid-column: 1 / -1; }
.sale-editor .sale-line input,
.sale-editor .sale-line select,
.sale-editor .sale-payment input,
.sale-editor .sale-payment select { min-height: var(--control-size); height: var(--control-size); }
.sale-editor .sale-line [data-remove] { margin-top: 8px; padding: 8px 12px; min-height: 44px; }
.sale-editor .sale-adjustments { margin-top: 20px; }
.sale-editor .sale-payment { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 24px; }
.sale-editor .payment-total { margin: 0 0 20px; text-align: right; font-size: 32px; line-height: 40px; }
.sale-editor .payment-total small { color: var(--muted); font-size: 13px; line-height: 20px; margin: 0 0 4px; }
.sale-editor #opening-input { padding: 16px; background: var(--bg); border-radius: 12px; margin-bottom: 20px; }
.sale-editor #opening-input p,
.sale-editor #pos-input p,
.sale-editor #free-input p { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 22px; }
.sale-editor #paid-input { display: grid; gap: 16px; }
.sale-editor #cash-input { display: grid; gap: 14px; }
.sale-editor #change-preview { margin: 0; font-size: 15px; font-weight: 400; }
.sale-editor .change-lines { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 2px 16px; }
.sale-editor .change-lines > div { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.sale-editor .change-lines > div:last-child { border-bottom: 0; }
.sale-editor .change-lines span { color: var(--muted); font-size: 14px; white-space: nowrap; }
.sale-editor .change-lines strong { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sale-editor .change-lines .change-due strong { color: var(--brand); }
.sale-editor .change-note { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 21px; }
.sale-editor #pos-input { display: grid; gap: 12px; }
.sale-editor #pos-input p { margin: 0; }
.sale-editor #free-input { display: grid; gap: 12px; }
.sale-editor :is(#paid-input,#cash-input,#pos-input,#free-input,#opening-input)[hidden] { display: none; }

@container (max-width: 899px) {
  .conflict-values { grid-template-columns: 1fr; }
  .order-table { table-layout: auto; }
  .order-table colgroup,
  .order-table thead { display: none; }
  .order-table,
  .order-table tbody,
  .order-table tr,
  .order-table td { display: block; width: 100%; }
  .order-table tbody { display: grid; gap: 12px; padding: 12px; }
  .order-table tbody tr { border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
  .order-table tbody td { display: flex; justify-content: space-between; align-items: center; gap: 12px; height: auto; min-height: 36px; padding: 4px 0; border: 0; text-align: right; }
  .order-table tbody td:first-child { font-weight: 600; }
  .order-table .order-card-label { display: inline; flex: 0 0 72px; color: var(--muted); text-align: left; font-size: 13px; font-weight: 500; }
  .order-table .order-customer { text-align: right; }
  .order-table .order-action { padding-top: 10px; justify-content: flex-end; }
  .order-table .order-action .order-card-label { margin-right: auto; }
}
@media (max-width: 680px) {
  .finance-toolbar label { flex: 1 1 145px; }
  .finance-toolbar > button { flex: 1 1 auto; }
  .sale-editor .sale-line .form-grid { grid-template-columns: minmax(0, 1fr); }
  .sale-editor .sale-line label:last-child { grid-column: auto; }
  .sale-editor #cash-input { gap: 10px; }
  .sale-editor .dialog-head { padding: 20px 16px 12px; }
  .sale-editor .sale-body { padding: 16px; }
  .sale-editor .dialog-actions { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .sale-editor .form-error { padding: 0 16px; }
}
@media (prefers-color-scheme: dark) {
  .badge.good { color: #9bd5b1; background: #9bd5b122; }
  .badge.pending,
  .order-table .badge.pending { color: #f2cc81; background: #f2cc8122; }
  .badge.void { color: var(--muted); background: #ffffff0c; }
}
