@layer pages {
  #modal .modal-card.pos-modal,
  #modal .modal-content.pos-modal {
    width: min(92vw, 1120px) !important;
    max-width: 1120px !important;
    max-height: min(86vh, 760px) !important;
    border-radius: 16px;
  }

  #modal .pos-shell {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
  }

  #modal .pos-modal-headline {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 0;
  }

  #modal .pos-main {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 10px 16px 12px;
  }

  #modal .pos-main.pos-order-layout,
  #modal .pos-order-layout.pos-real {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    gap: 16px;
    align-items: start;
  }

  #modal .pos-left,
  #modal .pos-right {
    min-width: 0;
    min-height: 0;
  }

  #modal .pos-left {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  #modal .pos-right {
    display: grid;
    gap: 10px;
    align-content: start;
  }

  #modal .pos-head-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
  }

  #modal .pos-head-grid > label:nth-child(3) {
    grid-column: 1 / -1;
  }

  #modal .pos-cart-head {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) 64px 102px 102px 102px 64px 102px 40px;
    gap: 8px;
    align-items: center;
    padding: 8px 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-weight: 600;
  }

  #modal .pos-items-wrap {
    min-height: 0;
    max-height: none;
    overflow: visible;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
  }

  #modal .pos-cart-row {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) 64px 102px 102px 102px 64px 102px 40px;
    gap: 8px;
    align-items: center;
    min-height: 40px;
    padding: 7px 10px;
    border-bottom: 1px solid #f1f5f9;
  }

  #modal .pos-cart-list .pos-cart-row:last-child {
    border-bottom: 0;
  }

  #modal .pos-cart-row input {
    min-height: calc(var(--control-height) - 2px);
    font-size: 13px;
    line-height: 1.25;
    text-align: center;
    font-variant-numeric: tabular-nums;
    padding-left: 8px;
    padding-right: 8px;
  }

  #modal .oi-stock-badge {
    font-size: 10px;
    line-height: 1.2;
    color: #a16207;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 999px;
    padding: 1px 5px;
    width: fit-content;
    margin-top: 1px;
  }

  #modal .oi-stock-badge:not(.warn) {
    display: none;
  }

  #modal .oi-del {
    min-height: 28px;
    width: 28px;
    border-radius: 999px;
    padding: 0;
    background: #fff5f5;
    border-color: #fecaca;
    color: #dc2626;
    font-weight: 600;
  }

  #modal .oi-del:hover {
    background: #fee2e2;
    border-color: #fca5a5;
  }

  #modal #orderItemsEmpty {
    min-height: 64px;
    display: grid;
    place-items: center;
    color: #94a3b8;
  }

  #modal .pos-right .panel {
    padding: var(--panel-padding-sm);
    border-radius: var(--ui-radius);
    display: grid;
    gap: 8px;
    border-color: #e6edf5;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
  }

  #modal .pos-right .panel h4 {
    margin: 0 0 4px;
    font-size: var(--text-md);
    line-height: 1.25;
    font-weight: 600;
    letter-spacing: 0;
  }

  #modal .pos-right .preview-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(124px, max-content);
    align-items: center;
    column-gap: 14px;
    row-gap: 8px;
  }

  #modal .pos-right .preview-grid > div:nth-child(odd) {
    color: #64748b;
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.3;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    min-width: 0;
    letter-spacing: 0;
  }

  #modal .pos-right .preview-grid > div:nth-child(even) {
    text-align: right;
    justify-self: end;
    color: #0f172a;
    font-weight: 600;
    font-size: var(--text-sm);
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
    white-space: nowrap;
    max-width: 100%;
    letter-spacing: 0;
  }

  #modal .pos-right .preview-grid .status {
    justify-self: end;
    align-self: center;
    display: inline-flex;
    align-items: center;
    line-height: 1;
    white-space: nowrap;
  }

  #modal .pos-right .pos-summary.panel {
    padding: 18px 20px;
    border-radius: 16px;
    border-color: #e5ebf3;
  }

  #modal .pos-right .pos-summary .preview-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 28px;
    row-gap: 14px;
    align-items: start;
  }

  #modal .pos-right .pos-summary .summary-item {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 2px;
    min-width: 0;
    white-space: nowrap;
  }

  #modal .pos-right .pos-summary .preview-grid > div:nth-child(odd),
  #modal .pos-right .pos-summary .preview-grid > div:nth-child(even) {
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: inherit;
    justify-self: stretch;
    text-align: left;
  }

  #modal .pos-right .pos-summary .summary-label {
    color: #64748b;
    font-size: var(--text-sm);
    line-height: 1.25;
    font-weight: 500;
    letter-spacing: 0;
    flex: 0 0 auto;
  }

  #modal .pos-right .pos-summary .summary-value {
    color: #0f172a;
    font-size: var(--text-sm);
    line-height: 1.25;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
    flex: 0 0 auto;
  }

  #modal .pos-right .pos-summary .summary-value.profit-positive {
    color: #059669;
  }

  #modal #customerHistoryPanel,
  #modal #orderStockInfo {
    display: grid;
    gap: 6px;
    font-size: var(--text-sm);
    line-height: 1.32;
    color: #64748b;
  }

  #modal .pos-footer-actions .btn {
    font-weight: 600;
    font-family: var(--font-main);
  }

  #modal #customerHistoryPanel b,
  #modal #orderStockInfo b {
    color: #1e293b;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
  }

  #modal #customerHistoryPanel hr {
    margin: 4px 0;
    border: 0;
    border-top: 1px solid #edf2f7;
  }

  #modal .pos-modal-footer {
    flex: 0 0 auto;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 16px;
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
  }

  #modal .pos-shortcut-helper {
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
  }

  #modal .pos-footer-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  #modal .quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  #modal .quick-chips .chip {
    min-height: var(--btn-height-sm);
  }

  #modal .customer-dropdown,
  #modal .product-dropdown {
    z-index: var(--z-dropdown);
    max-height: 260px;
    overflow: auto;
  }

  /* --- POS “Thêm đơn bán” polish (scoped: chỉ modal có .pos-shell trong form POS) --- */
  #modal .modal-card.pos-modal,
  #modal .modal-content.pos-modal {
    border: 1px solid #dfe7f2;
    box-shadow:
      0 24px 56px rgba(15, 23, 42, 0.11),
      0 1px 0 rgba(255, 255, 255, 0.65) inset;
  }

  #modal .modal-card.pos-modal .modal-head h3,
  #modal .modal-content.pos-modal .modal-head h3 {
    font-weight: 650;
    letter-spacing: -0.02em;
    color: #0f172a;
  }

  #modal .modal-card.pos-modal .pos-modal-headline {
    padding: 10px 18px 4px;
    border-bottom: 1px solid #f1f5f9;
  }

  #modal .modal-card.pos-modal .pos-temp-code {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #475569;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 5px 11px;
    border-radius: 999px;
    border: 1px solid #e2e8f0;
  }

  #modal .modal-card.pos-modal .tiny-date {
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    padding: 7px 11px;
    font-weight: 600;
    font-size: 13px;
    color: #0f172a;
    background: #fff;
  }

  #modal .modal-card.pos-modal .pos-main {
    padding: 14px 18px 16px;
  }

  #modal .modal-card.pos-modal .pos-main.pos-order-layout,
  #modal .modal-card.pos-modal .pos-order-layout.pos-real {
    gap: 18px;
  }

  #modal .modal-card.pos-modal .pos-head-grid.compact label {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    letter-spacing: 0;
    gap: 6px;
  }

  #modal .modal-card.pos-modal .pos-head-grid.compact input,
  #modal .modal-card.pos-modal .pos-head-grid.compact select {
    margin-top: 4px;
  }

  #modal .modal-card.pos-modal .customer-inline input {
    border-radius: 10px;
    min-height: 36px;
    padding: 0 11px;
    font-size: 13px;
  }

  #modal .modal-card.pos-modal .pos-global-search input {
    min-height: 40px;
    border-radius: 11px;
    padding: 0 13px;
    font-size: 13px;
    border: 1px solid #cbd5e1;
    font-weight: 500;
  }

  #modal .modal-card.pos-modal .pos-cart-head {
    padding: 10px 12px;
    border-radius: 11px;
    font-size: 10.5px;
    letter-spacing: 0.045em;
    color: #64748b;
    background: linear-gradient(180deg, #fafbfc 0%, #f1f5f9 100%);
  }

  #modal .modal-card.pos-modal .pos-items-wrap {
    border-radius: 11px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  }

  #modal .modal-card.pos-modal .pos-cart-row {
    padding: 9px 12px;
    gap: 10px;
    align-items: center;
    min-height: 44px;
  }

  #modal .modal-card.pos-modal .pos-cart-row input {
    border-radius: 9px;
    min-height: 34px;
  }

  #modal .modal-card.pos-modal .pos-right .panel:not(.pos-summary) h4 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 6px;
  }

  #modal .modal-card.pos-modal .pos-right .panel:not(.pos-summary) .preview-grid {
    row-gap: 10px;
    column-gap: 16px;
    align-items: center;
  }

  #modal .modal-card.pos-modal .pos-right .panel:not(.pos-summary) .preview-grid > div:nth-child(odd) {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
  }

  #modal .modal-card.pos-modal .pos-right .panel:not(.pos-summary) .preview-grid input,
  #modal .modal-card.pos-modal .pos-right .panel:not(.pos-summary) .preview-grid select {
    width: 100%;
    min-height: 36px;
    border-radius: 10px;
    padding: 0 11px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    border: 1px solid #cbd5e1;
    text-align: right;
    box-sizing: border-box;
  }

  #modal .modal-card.pos-modal .pos-right .panel:not(.pos-summary) .preview-grid select {
    text-align: left;
    padding-right: 9px;
  }

  #modal .modal-card.pos-modal .pos-summary h4 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #475569;
    margin-bottom: 8px;
  }

  #modal .modal-card.pos-modal .pos-summary #orderPreview.preview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
    align-items: stretch;
  }

  #modal .modal-card.pos-modal .pos-summary #orderPreview .summary-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    padding: 9px 11px;
    background: #f8fafc;
    border: 1px solid #edf2f7;
    border-radius: 11px;
    min-width: 0;
  }

  #modal .modal-card.pos-modal .pos-summary #orderPreview .summary-label {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0;
    flex-shrink: 0;
  }

  #modal .modal-card.pos-modal .pos-summary #orderPreview .summary-value {
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #0f172a;
    text-align: right;
    min-width: 0;
  }

  #modal .modal-card.pos-modal .pos-summary #orderPreview .summary-value.profit-positive {
    color: #059669;
  }

  #modal .modal-card.pos-modal .pos-summary #orderPreview .summary-value.profit-bad,
  #modal .modal-card.pos-modal .pos-summary #orderPreview .summary-value.profit-low {
    font-weight: 700;
  }

  #modal .modal-card.pos-modal .compact-note textarea {
    margin-top: 6px;
    min-height: 72px;
    border-radius: 11px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.45;
    border: 1px solid #cbd5e1;
    resize: vertical;
  }

  #modal .modal-card.pos-modal .pos-shell .pos-modal-footer {
    padding: 12px 18px;
    gap: 14px;
    border-top: 1px solid #e2e8f0;
    background: linear-gradient(180deg, #fafcfe 0%, #ffffff 55%);
    flex-wrap: wrap;
  }

  #modal .modal-card.pos-modal .pos-shortcut-helper {
    font-size: 11.5px;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0.01em;
    line-height: 1.35;
    max-width: min(320px, 46vw);
  }

  #modal .modal-card.pos-modal .pos-footer-actions {
    gap: 10px;
    flex-shrink: 0;
  }

  #modal .modal-card.pos-modal .pos-footer-actions .btn {
    min-height: 40px;
    padding-inline: 18px;
    border-radius: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  #modal .modal-card.pos-modal #posCancel {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
  }

  #modal .modal-card.pos-modal #posSave {
    min-width: 132px;
  }
}
