/* Màn Bán hàng. Biến màu và khung chung ở app/app.css. */

/* ── Thanh tìm thuốc + hóa đơn đang mở ────────────────────────────────── */
.pos-bar { display: flex; align-items: center; gap: 12px; padding: 10px 12px 0; flex-wrap: wrap; }
.pos-search { position: relative; flex: 1 1 280px; display: flex; align-items: center; gap: 8px; background: #fff; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; padding: 0 12px; }
.pos-search:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px rgba(13,107,74,.1); }
.pos-search svg { color: var(--muted); flex: none; }
.pos-search input { flex: 1; border: 0; outline: 0; padding: 10px 0; background: transparent; min-width: 0; }
.pos-invoices { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pos-invoice-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.pos-invoice-tab { display: inline-flex; align-items: center; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
.pos-invoice-tab button { border: 0; background: transparent; color: var(--muted); padding: 7px 9px; }
.pos-invoice-tab.is-active { background: var(--green); border-color: var(--green); }
.pos-invoice-tab.is-active button { color: #fff; font-weight: 600; }
.pos-tab-x { padding: 7px 9px 7px 0 !important; opacity: .7; }
.pos-icon-btn { border: 0; background: transparent; width: 28px; height: 28px; border-radius: 7px; display: inline-grid; place-items: center; font-size: 16px; line-height: 1; }
.pos-invoices > .pos-icon-btn { width: 34px; height: 34px; background: var(--green-soft); color: var(--green); }

.pos-suggest { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.12); overflow: hidden; color: var(--ink); }
.pos-suggest button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; border: 0; background: #fff; padding: 8px 12px; text-align: left; }
.pos-suggest button:hover { background: var(--green-soft); }
.pos-suggest small { color: var(--muted); }
.pos-suggest-none { padding: 10px 12px; color: var(--muted); }

/* ── Khu chính ────────────────────────────────────────────────────────── */
.pos-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 12px; padding: 12px; }
.pos-catalog { min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.pos-cats { display: flex; gap: 6px; flex-wrap: wrap; }
.pos-cat { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; }
.pos-cat.is-active { background: var(--green); border-color: var(--green); color: #fff; }
.pos-grid { overflow: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; align-content: start; padding-bottom: 8px; }
.pos-card { position: relative; display: flex; flex-direction: column; gap: 4px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-height: 108px; }
.pos-card:hover { border-color: var(--green); box-shadow: 0 4px 14px rgba(13,107,74,.12); }
.pos-card-name { font-weight: 600; padding-right: 50px; }
.pos-card-active { color: var(--muted); font-size: 12px; }
.pos-card-price { margin-top: auto; color: var(--green); font-weight: 600; }
.pos-badge { display: inline-block; background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 600; }
.pos-card .pos-badge { position: absolute; top: 10px; right: 10px; }
.pos-empty, .pos-cart-empty { color: var(--muted); text-align: center; padding: 18px; }

/* ── Hóa đơn bên phải ─────────────────────────────────────────────────── */
.pos-cart { min-height: 0; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow-y: auto; }
.pos-customer { display: flex; gap: 8px; align-items: center; padding: 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.pos-customer-search { position: relative; flex: 1; }
.pos-customer-search input, .pos-totals input:not([type=radio]), .pos-totals textarea, .pos-dialog input, .pos-dialog select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; }
.pos-customer-chip { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--green-soft); border-radius: 8px; padding: 6px 6px 6px 10px; }
.pos-customer-chip em { color: var(--warn); font-style: normal; }
.pos-lines { flex: 1 0 auto; min-height: 130px; }
.pos-line { padding: 10px; border-bottom: 1px solid var(--line); }
.pos-line-head { display: flex; align-items: center; gap: 8px; }
.pos-line-no { color: var(--muted); width: 18px; }
.pos-line-name { flex: 1; font-weight: 600; }
.pos-line-body { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding-left: 26px; flex-wrap: wrap; }
.pos-line-unit { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.pos-line-unit select { border: 1px solid var(--line); border-radius: 6px; padding: 3px 4px; color: var(--ink); font-size: 13px; }
.pos-qty { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.pos-qty button { border: 0; background: var(--bg); width: 26px; }
.pos-qty input { width: 42px; border: 0; text-align: center; padding: 3px 0; }
.pos-lot { border: 1px dashed var(--line); background: transparent; border-radius: 6px; padding: 3px 6px; font-size: 12px; color: var(--muted); }
.pos-line-total { margin-left: auto; }

.pos-rx { display: flex; align-items: center; gap: 10px; margin: 8px 10px 0; padding: 10px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); }
.pos-rx > div { flex: 1; display: flex; flex-direction: column; font-size: 13px; }
.pos-rx.is-done { background: var(--green-soft); color: var(--green); }
.pos-rx.is-shake { animation: shake .5s; }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

.pos-totals { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.pos-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pos-row > input { max-width: 170px; text-align: right; }
.pos-row-big { font-size: 17px; }
.pos-row-big b { color: var(--green); font-size: 20px; }
.pos-discount { display: flex; gap: 6px; max-width: 220px; }
.pos-discount input { text-align: right; }
.pos-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.pos-seg button { border: 0; background: #fff; padding: 0 10px; }
.pos-seg button.is-on { background: var(--green); color: #fff; }
.pos-pay-methods { display: flex; gap: 12px; }
.pos-pay-methods label { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.pos-quick-cash { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pos-quick-cash button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.pos-qr { display: flex; gap: 12px; align-items: center; background: var(--bg); border-radius: 8px; padding: 10px; }
.pos-qr-img { width: 76px; height: 76px; border-radius: 6px; background:
  repeating-linear-gradient(90deg, #1c2623 0 4px, transparent 4px 8px),
  repeating-linear-gradient(0deg, #1c2623 0 4px, #fff 4px 8px); opacity: .85; }

.pos-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; font-weight: 600; white-space: nowrap; }
.pos-btn-primary { background: var(--green); color: #fff; }
.pos-btn-primary:hover { background: var(--green-dark); }
.pos-btn-ghost { background: #fff; border-color: var(--line); color: var(--green); }
.pos-btn-warn { background: var(--warn); color: #fff; }
.pos-btn-danger { background: var(--bad); color: #fff; }
.pos-btn-sm { padding: 6px 10px; font-size: 13px; }
.pos-btn:disabled { opacity: .45; cursor: not-allowed; }
.pos-btn-ghost:hover:not(:disabled) { background: var(--green-soft); }
.pos-rx.is-done .pos-btn-warn { background: #fff; color: var(--green); border-color: var(--line); }
.pos-checkout { padding: 13px; font-size: 16px; }

.pos-foot { display: flex; justify-content: space-between; gap: 10px; padding: 6px 14px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); background: #fff; }
.pos-foot a { color: var(--green); }

/* ── Hộp thoại ────────────────────────────────────────────────────────── */
.pos-dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.pos-dialog-sm { width: min(420px, calc(100vw - 32px)); }
.pos-dialog::backdrop { background: rgba(10,30,22,.45); }
.pos-dialog > form, .pos-dialog > div { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.pos-dialog h2 { margin: 0; font-size: 18px; }
.pos-dialog label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; font-size: 13px; }
.pos-dialog-sub { margin: -6px 0 0; color: var(--muted); }
.pos-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pos-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.pos-lot-options { display: flex; flex-direction: column; gap: 6px; }
.pos-lot-option { flex-direction: row !important; align-items: center; gap: 8px !important; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-weight: 400 !important; }
.pos-lot-option input { width: auto; }
.pos-receipt { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--bg); border-radius: 8px; padding: 12px; }
.pos-receipt h3 { margin: 0; font-size: 14px; text-align: center; }
.pos-receipt p { margin: 4px 0; }
.pos-receipt table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.pos-receipt td { border-top: 1px dashed #b8c4be; padding: 4px 0; vertical-align: top; }
.pos-receipt td:last-child { text-align: right; white-space: nowrap; }

.pos-toast { position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #1c2623; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: min(520px, calc(100vw - 32px)); transition: .2s; z-index: 50; }
.pos-toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.pos-toast.is-ok { background: var(--green-dark); }
.pos-toast.is-bad { background: var(--bad); }

/* ── Điểm, dị ứng, lỗi form ───────────────────────────────────────────── */
.pos-customer-chip .ak-tier { margin-left: 4px; }
.pos-customer-chip small { display: block; color: var(--muted); }
.pos-points { display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; margin: 0 -10px; background: #fbf8ee; border-block: 1px dashed #eadfb8; }
.pos-points-hint { margin: 0; font-size: 12px; color: var(--muted); text-align: right; }
.pos-points-error, .pos-form-error { margin: 0; font-size: 12.5px; color: var(--bad); font-weight: 500; }
.pos-points-error { text-align: right; }
.pos-row-sub { font-size: 13px; color: var(--muted); }
.pos-row-sub b { color: var(--gold); }
.pos-allergy { margin: 8px 10px 0; padding: 9px 11px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-size: 13px; font-weight: 500; }

@media (max-width: 960px) {
  .pos-main { grid-template-columns: 1fr; }
  .pos-cart { min-height: 520px; }
  .ak-view-pos { overflow-y: auto; }
  .pos-main { flex: none; }
}

@media print {
  body.is-printing > *:not(#done-dialog) { display: none !important; }
  body.is-printing #done-dialog .pos-dialog-actions, body.is-printing #done-dialog h2 { display: none; }
  body.is-printing #done-dialog { position: static; box-shadow: none; width: 80mm; }
  body.is-printing .pos-receipt { background: #fff; }
}

.pos-card-stock { font-size: 11.5px; color: var(--muted); }
.pos-card-stock.is-low { color: var(--warn); font-weight: 600; }
.pos-link { border: 0; background: none; padding: 0; color: var(--green); font-weight: 600; text-decoration: underline; font-size: inherit; }
.pos-dialog .ak-field { gap: 4px; }
.ak-merge-preview { background: var(--bg); border-radius: 9px; padding: 12px; }
