.dialog:has(.sales-history) {
  width: min(980px, 100%);
  padding: 20px;
}
.sales-history {
  --sales-accent: #087e68;
  --sales-accent-soft: #e4f4ef;
  display: grid;
  gap: 16px;
  color: var(--ink);
}
.sales-toolbar,
.sales-section-head,
.sale-ticket-summary,
.sales-range-custom,
.payment-methods {
  display: flex;
  align-items: center;
}
.sales-toolbar {
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.sales-periods,
.sales-tabs,
.sales-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.sales-periods,
.sales-tabs {
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f4f7f5;
}
.sales-periods button,
.sales-tabs button,
.sales-action {
  min-height: 38px;
  border: 0;
  border-radius: 9px;
  padding: 8px 12px;
  background: transparent;
  color: #536269;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.sales-periods button[aria-pressed="true"],
.sales-tabs button[aria-selected="true"] {
  background: #fff;
  color: var(--sales-accent);
  box-shadow: 0 2px 8px #10251d12;
}
.sales-action {
  border: 1px solid #cfe4dc;
  background: #fff;
  color: var(--sales-accent);
}
.sales-cart-filter {
  min-height: 46px;
  min-width: 150px;
  padding: 8px 32px 8px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}
.sales-action:disabled { opacity: .45; cursor: default; }
.sales-range-custom {
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfb;
}
.sales-range-custom label {
  display: grid;
  flex: 1;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.sales-range-custom input {
  min-width: 0;
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
}
.sales-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
}
.sales-metric {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 4px 14px #10251d08;
}
.sales-metric.primary {
  border-color: #b9ddd1;
  background: linear-gradient(145deg, #f7fffc, var(--sales-accent-soft));
}
.sales-metric span,
.sales-metric small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.sales-metric b {
  display: block;
  margin: 6px 0 4px;
  color: var(--sales-accent);
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sales-metric:not(.primary) b { color: var(--ink); }
.sales-balance {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 11px;
  background: #edf8f4;
  color: #236051;
  font-size: 13px;
}
.sales-balance strong { color: var(--sales-accent); }
.sales-balance.is-off { background: #fceeed; color: #8e322f; }
.sales-section-head {
  justify-content: space-between;
  gap: 10px;
}
.sales-section-head h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: -.35px;
}
.sales-section-head small { color: var(--muted); }
.sales-ticket-list { display: grid; gap: 8px; }
.sale-ticket {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}
.sale-ticket[open] { border-color: #bddfd3; box-shadow: 0 5px 16px #10251d0a; }
.sale-ticket.voided { opacity: .72; background: #faf8f8; }
.sale-ticket.voided .sale-ticket-total b { text-decoration: line-through; }
.sale-ticket-summary {
  min-height: 64px;
  gap: 11px;
  padding: 11px 13px;
  cursor: pointer;
  list-style: none;
}
.sale-ticket-summary::-webkit-details-marker { display: none; }
.sale-ticket-number {
  display: grid;
  place-items: center;
  width: auto;
  min-width: 72px;
  height: 38px;
  flex: 0 0 auto;
  padding: 0 10px;
  border-radius: 11px;
  background: var(--sales-accent-soft);
  color: var(--sales-accent);
  font-size: 13px;
  font-weight: 800;
}
.sale-ticket-main { min-width: 0; flex: 1; }
.sale-ticket-main b { display: block; font-size: 14px; }
.sale-ticket-main small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.sale-ticket-total { text-align: right; white-space: nowrap; }
.sale-ticket-total b { display: block; color: var(--sales-accent); font-size: 18px; font-variant-numeric: tabular-nums; }
.sale-ticket-total small { color: var(--muted); font-size: 11px; }
.sale-ticket-detail { padding: 0 13px 13px; border-top: 1px solid #eef2ef; }
.sale-item-row,
.sale-ticket-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid #eef2ef;
  font-size: 13px;
}
.sale-item-row span small { display: block; color: var(--muted); margin-top: 2px; }
.sale-item-row b,
.sale-ticket-foot b { font-variant-numeric: tabular-nums; }
.sale-ticket-foot { border-bottom: 0; color: var(--muted); }
.sale-ticket-foot strong { color: var(--ink); }
.sale-void-reason { margin: 4px 0 8px; color: var(--muted); font-size: 12px; }
.sales-product-table {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}
.sales-product-row {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) .55fr .65fr .8fr;
  gap: 10px;
  align-items: center;
  min-height: 52px;
  padding: 10px 13px;
  border-bottom: 1px solid #eef2ef;
  font-size: 13px;
}
.sales-product-row:last-child { border-bottom: 0; }
.sales-product-row.header { min-height: 38px; color: var(--muted); background: #f7f9f8; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .25px; }
.sales-product-row span:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.sales-product-row b { font-size: 14px; }
.sales-empty {
  padding: 34px 18px;
  border: 1px dashed #cbdad4;
  border-radius: 14px;
  text-align: center;
  color: var(--muted);
  background: #fbfcfb;
}
.sales-empty b { display: block; margin-bottom: 5px; color: var(--ink); font-size: 16px; }
.payment-methods {
  gap: 7px;
  margin: 14px 0 4px;
  padding: 0;
  border: 0;
  flex-wrap: wrap;
}
.payment-methods legend {
  width: 100%;
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}
.payment-methods label {
  position: relative;
  flex: 1;
  min-width: 105px;
}
.payment-methods input { position: absolute; opacity: 0; pointer-events: none; }
.payment-methods span {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #4f6066;
  font-size: 13px;
  font-weight: 700;
}
.payment-methods input:checked + span {
  border-color: #8bc9b6;
  background: var(--sales-accent-soft);
  color: var(--sales-accent);
  box-shadow: inset 0 0 0 1px #8bc9b6;
}
.payment-methods input:focus-visible + span { outline: 3px solid #9ed5c6; outline-offset: 2px; }
@media (max-width: 700px) {
  .dialog:has(.sales-history) { padding: 16px; }
  .sales-history { gap: 13px; }
  .sales-toolbar { align-items: stretch; }
  .sales-periods { width: 100%; overflow-x: auto; }
  .sales-periods button { flex: 1; padding-inline: 9px; }
  .sales-actions { width: 100%; }
  .sales-action { flex: 1; }
  .sales-cart-filter { width: 100%; }
  .sales-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sales-metric { padding: 12px; }
  .sales-metric b { font-size: 23px; }
  .sales-tabs { width: 100%; }
  .sales-tabs button { flex: 1; }
  .sales-section-head { align-items: flex-start; flex-direction: column; }
  .sales-product-row { grid-template-columns: minmax(0, 1fr) .55fr .8fr; }
  .sales-product-row > :nth-child(3) { display: none; }
  .sales-range-custom { align-items: stretch; }
  .sale-ticket-summary {
    display:grid;
    grid-template-columns:minmax(0,1fr) auto;
    gap:7px 10px;
    align-items:center;
  }
  .sale-ticket-number { grid-column:1; grid-row:1; justify-self:start; }
  .sale-ticket-total { grid-column:2; grid-row:1; }
  .sale-ticket-main { grid-column:1 / -1; grid-row:2; }
  .sale-ticket-main b,.sale-ticket-main small { white-space:normal; overflow-wrap:anywhere; }
}
@media (max-width: 390px) {
  .sale-ticket-summary { padding-inline: 10px; }
  .sales-balance { align-items: flex-start; flex-direction: column; }
}
@media print {
  body * { visibility: hidden !important; }
  #modal, #modal *, .sales-history, .sales-history * { visibility: visible !important; }
  #modal { position: static; display: block; background: #fff; }
  #modal .dialog { width: 100%; max-height: none; overflow: visible; box-shadow: none; }
  #closeModal, .sales-toolbar, .sales-tabs { display: none !important; }
  .sale-ticket { break-inside: avoid; }
}
