:root {
  color-scheme: light;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #15324b;
  background: #eef4f8;
  font-size: 15px;
  --navy: #164970;
  --deep: #113c60;
  --blue: #0969a8;
  --teal: #087582;
  --line: #b6cbda;
  --panel: #fff;
  --soft: #e4eff7;
  --wash: #f1f6fa;
  --muted: #4c6578;
  --green: #0b733d;
  --red: #ad293c;
  --amber: #8b510a;
}
* { box-sizing: border-box; }
body { margin: 0; }
h1,h2,h3,p { margin: 0; }
h1 { font-size: clamp(1.3rem, 2.5vw, 1.85rem); }
h2 { font-size: 1.19rem; }
h3 { font-size: 1.05rem; }
button,input,select,textarea { font: inherit; }
button {
  min-height: 36px; padding: .46rem .74rem; cursor: pointer; border: 1px solid var(--line);
  color: #17354d; background: var(--soft); border-radius: 4px; font-weight: 650;
}
button:hover:not(:disabled) { filter: brightness(.95); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .46; cursor: default; }
:focus-visible { outline: 3px solid #2c8bcc; outline-offset: 2px; }
input,select,textarea {
  border: 1px solid var(--line); color: inherit; padding: .45rem .55rem;
  border-radius: 4px; background: var(--panel); min-height: 36px; min-width: 0;
}
input[type=checkbox] { min-height: auto; width: 17px; height: 17px; accent-color: var(--blue); }
label { font-weight: 600; }
label.field { display: grid; gap: 4px; }
::placeholder { color: #657d8c; }
.primary,.selected { background: var(--blue); border-color: var(--blue); color: #fff; }
.success { background: var(--green); border-color: var(--green); color: #fff; }
.danger { background: var(--red); border-color: var(--red); color: #fff; }
.warning { background: var(--amber); border-color: var(--amber); color: #fff; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--deep); color: #fff; padding: .7rem 1.2rem;
}
.brand { display: flex; gap: .6rem; align-items: center; font-weight: 800; font-size: 1.4rem; white-space: nowrap; }
.brand img { width: 35px; height: 35px; border-radius: 8px; background: var(--navy); }
.top-actions,.row,.actions,.page-title,.filter {
  display: flex; gap: .5rem; align-items: center; flex-wrap: wrap;
}
.top-actions button { min-height: 32px; font-size: .88rem; }
.top-user { margin-right: .35rem; }
.nav {
  display: flex; gap: .3rem; flex-wrap: wrap; background: #d9e8f3;
  border-bottom: 1px solid var(--line); padding: .45rem 1.2rem;
}
.nav button { border-color: transparent; }
nav button[aria-current=page] { color: #fff; background: var(--navy); }
main { max-width: 1640px; margin: auto; padding: 1rem 1.2rem 2rem; }
.page-title { justify-content: space-between; margin-bottom: .85rem; }
.panel,.summary,.login,.pos-cart,.side-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 5px;
}
.panel { padding: .85rem; margin-bottom: .85rem; }
.panel h2 { margin-bottom: .65rem; }
.panel > .row,.panel > .actions { margin-bottom: .65rem; }
.panel > :last-child { margin-bottom: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit,minmax(170px,1fr)); gap: .7rem; margin-bottom: .85rem; }
.summary { min-height: 90px; text-align: left; display: grid; align-content: center; gap: .3rem; padding: .8rem 1rem; }
.summary strong { font-size: 1.7rem; line-height: 1.03; }
.muted,.small { color: var(--muted); }
.small { font-size: .86rem; }
.issue { color: var(--red); font-weight: 700; }
.warm { color: var(--amber); font-weight: 700; }
.table { overflow: auto; border: 1px solid var(--line); background: var(--panel); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { background: var(--navy); color: #fff; font-size: .88rem; text-align: left; }
th,td { padding: .48rem .55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:nth-child(even) { background: var(--wash); }
.empty { text-align: center; color: var(--muted); padding: 1.15rem; }
td button { min-height: 30px; padding: .28rem .55rem; }
.num { text-align: right; white-space: nowrap; }
.stack { display: grid; gap: .65rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(165px,1fr)); gap: .65rem; align-items: end; }
.login { width: min(420px, calc(100vw - 2rem)); margin: 9vh auto 0; padding: 1.4rem; }
.login .brand { color: var(--navy); margin-bottom: 1rem; }
.login #login { margin-top: .75rem; }
#notice {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 5; max-width: min(480px,calc(100% - 2rem));
  padding: .65rem .9rem; background: var(--deep); color: #fff; border-radius: 4px;
  box-shadow: 0 3px 18px #17354d24; pointer-events: none;
}
#notice:empty { display: none; }
#notice.error { background: var(--red); }
.banner { background: #fff1d8; color: #5a370a; padding: .55rem 1.2rem; font-weight: 650; }
.banner[hidden] { display: none; }
.pos-top {
  display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 4px; padding: .43rem;
  background: var(--navy); border-radius: 4px; margin-bottom: .5rem;
}
.pos-title { margin: .6rem 0; align-items: center; gap: .75rem; }
.pos-title h1 { margin-right: .35rem; }
.pos-search { display: grid; grid-template-columns: auto minmax(120px,1fr) auto; align-items: center; gap: .5rem; }
.pos-search input { font-size: 1.05rem; }
.search-results { margin: .38rem 0; max-height: 15rem; overflow: auto; }
.search-results:empty { display: none; }
.result { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; padding: .32rem .5rem; background: var(--panel); border: 1px solid var(--line); }
.result > span:first-child { margin-right: auto; }
.pos-layout { display: grid; grid-template-columns: minmax(0,1.85fr) minmax(300px,1fr); gap: .6rem; margin-top: .5rem; }
.pos-cart { display: flex; flex-direction: column; gap: 4px; min-width: 0; background: var(--wash); }
.cart-table { min-height: 355px; flex: 1; max-height: 55vh; border: 0; }
.cart-table th { position: sticky; top: 0; }
.cart-table tr[data-a] { cursor: pointer; }
.cart-table tr.chosen td { background: #cce4f4; }
.cart-table td input { width: 66px; min-height: 30px; padding: .26rem; }
.pos-buttons { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 3px; }
.pos-buttons button,.pos-top button { border-radius: 2px; }
.pos-total {
  background: var(--green); color: #fff; min-height: 57px; padding: .5rem .7rem;
  display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; justify-content: space-between;
}
.pos-total strong { font-size: clamp(1.3rem,2.4vw,2rem); }
.pos-side { display: flex; flex-direction: column; gap: 5px; }
.side-panel h2 { background: var(--teal); color: #fff; padding: .28rem .55rem; font-size: 1rem; }
.side-body { padding: .45rem; display: grid; gap: .36rem; }
.side-fields { display: grid; grid-template-columns: minmax(94px,auto) minmax(0,1fr); gap: .32rem; align-items: center; }
.side-fields label { text-align: right; font-size: .88rem; }
.side-fields input,.side-fields select { width: 100%; }
.cash-actions { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 3px; }
.pay { min-height: 48px; font-size: 1rem; }
.entry-table input,.entry-table select { width: 100%; min-width: 74px; }
.entry-table select[data-entry=product],.entry-table select[data-entry=similar] { min-width: 145px; }
.entry-table input[data-entry=expiry] { min-width: 133px; }
.entry-table { margin: .6rem 0; }
.count-input { width: 9rem; }
dialog {
  color: inherit; background: var(--panel); border: 1px solid var(--navy); border-radius: 6px;
  max-width: min(860px,calc(100vw - 1.4rem)); min-width: min(365px,calc(100vw - 1.4rem)); max-height: 90vh;
  padding: 0; box-shadow: 0 18px 50px #112e4870;
}
dialog::backdrop { background: #0b253a79; }
.dialog-title { background: var(--navy); color: #fff; padding: .6rem .75rem; display: flex; align-items: center; gap: .8rem; justify-content: space-between; }
.dialog-title button { min-height: 30px; line-height: 1; }
.dialog-body { padding: .8rem; max-height: 78vh; overflow: auto; }
.dialog-body > .actions { margin-top: .65rem; }
.dialog-error { color: var(--red); font-weight: 650; }
.dialog-error:empty { display: none; }
.keys { display: grid; grid-template-columns: repeat(8,minmax(0,1fr)); gap: .25rem; }
#print { display: none; }
.loading { margin: 2rem; }
html.dark { color-scheme: dark; color: #dcebf5; background: #142734; --panel:#1e3545; --wash:#263f50; --soft:#2a475c; --line:#537083; --muted:#b4c9d8; }
html.dark button:not(.primary,.selected,.success,.warning,.danger,[aria-current=page]) { color: #e4f1f9; }
html.dark .nav { background: #203a4d; }
html.dark .cart-table tr.chosen td { background: #31596f; }
html.dark .issue { color:#ffacb5; }
html.dark .warm { color:#ffd28b; }
@media (max-width: 820px) {
  main { padding: .7rem .65rem 1.25rem; }
  .topbar,.nav { padding-left: .65rem; padding-right: .65rem; }
  .pos-layout { grid-template-columns: 1fr; }
  .cart-table { min-height: 220px; }
  .pos-top { grid-template-columns: repeat(auto-fit,minmax(122px,1fr)); }
}
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; }
  .top-user { display: none; }
  .nav button { font-size: .84rem; }
  .pos-buttons { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .pos-search { grid-template-columns: minmax(70px,1fr) auto; }
  .pos-search label { grid-column: 1 / -1; }
}
@media print {
  :root,html.dark { color: #000; background: #fff; --panel:#fff; --wash:#fff; --line:#999; }
  #app,#dialog,#notice { display: none !important; }
  #print { display: block; color: #000; }
  #print h2 { margin: .6rem 0; }
  #print p { margin: .35rem 0; }
  #print table { margin-top: .55rem; }
  #print th { background: #fff; color: #000; }
  #print .table { overflow: visible; }
  #print tr { break-inside: avoid; }
}
.history-subtitle { margin-top: .9rem; }
html.pos-focus .topbar, html.pos-focus .nav { display: none; }
html.pos-focus main { max-width: none; }
html.pos-focus .cart-table { min-height: min(53vh,520px); }

.stock-init-title { grid-column: 1 / -1; font-weight: 700; }
.entry-table input[data-article-search] { min-width: 175px; }
.sale-screen { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.sale-screen > .topbar,.sale-screen > .nav,.sale-screen > .banner { flex: none; }
.sale-screen > main {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
  width: 100%; padding-block: .5rem; position: relative;
}
.sale-screen .pos-top { flex: none; margin-bottom: .15rem; }
.sale-screen .pos-title { margin-block: .3rem; }
.sale-screen .pos-layout { flex: 1; min-height: 0; }
.sale-screen .cart-table { min-height: 0; max-height: none; }
.sale-screen .pos-side { min-height: 0; min-width: 0; }
.pos-side-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; display: grid; align-content: start; gap: 5px; }
.sale-screen .pos-side > :not(.pos-side-scroll) { flex: none; }
.sale-screen .pos-search { z-index: 2; }
.sale-screen .search-results {
  position: absolute; z-index: 3; top: auto; inset-inline: 1.2rem; margin: 0;
  max-height: min(30dvh,15rem); box-shadow: 0 6px 20px #15324b32;
}
.sale-screen .pos-lookup { position: relative; }
.sale-screen .pos-lookup .search-results { inset-inline: 0; }
@media (max-width: 820px), (max-height: 710px) {
  .sale-screen { font-size: .88rem; }
  .sale-screen .topbar,.sale-screen .nav { padding-block: .22rem; gap: .2rem; }
  .sale-screen .topbar { flex-wrap: nowrap; }
  .sale-screen .brand { font-size: 1rem; }
  .sale-screen .brand img { width: 25px; height: 25px; }
  .sale-screen button,.sale-screen input,.sale-screen select { min-height: 28px; padding: .24rem .35rem; }
  .sale-screen .pos-title { gap: .35rem; }
  .sale-screen .pos-title h1 { font-size: 1.02rem; }
  .sale-screen .pos-total { min-height: 36px; padding: .23rem .45rem; }
  .sale-screen .pos-total strong { font-size: 1.1rem; }
  .sale-screen .pay { min-height: 38px; }
}
@media (max-width: 820px) {
  .sale-screen .top-actions { justify-content: flex-end; gap: .2rem; }
  .sale-screen .nav { flex-wrap: nowrap; overflow-x: auto; }
  .sale-screen .nav button { white-space: nowrap; }
  .sale-screen .pos-layout { grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(125px,1fr) minmax(111px,.85fr); }
  .sale-screen .pos-top { grid-template-columns: repeat(5,minmax(0,1fr)); }
  .sale-screen .pos-top button { font-size: .75rem; overflow-wrap: anywhere; }
  .sale-screen .pos-buttons { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .sale-screen .pos-buttons button { font-size: .73rem; }
  .sale-screen .pos-search { grid-template-columns: minmax(0,1fr) auto; }
  .sale-screen .pos-search label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
}
@media print {
  #print.ticket { margin: 0; padding: 2mm; font: 9pt/1.22 system-ui,sans-serif; overflow-wrap: anywhere; }
  #print.ticket-57 { width: 57mm; }
  #print.ticket-80 { width: 80mm; }
  #print.ticket h1 { font-size: 13pt; }
  #print.ticket h2 { font-size: 10pt; margin: 1mm 0; }
  #print.ticket p { margin: 1mm 0; }
  .ticket-line { border-bottom: 1px dotted #666; padding: 1mm 0; break-inside: avoid; }
  .ticket-line div { display: flex; gap: 1mm; justify-content: space-between; }
}
@page gest-ticket { margin: 0; }
@media print {
  #print.ticket { page: gest-ticket; }
}
.pos-extra { display: none; }
@media (max-width: 820px), (max-height: 710px) {
  .sale-screen .pos-side-scroll { display: none; }
  .sale-screen .pos-extra { display: block; }
  .sale-screen .pos-top { grid-template-columns: repeat(6,minmax(0,1fr)); }
  .sale-screen .pos-side { justify-content: flex-end; }
}

.stock-value-card { grid-column: span 2; }
.stock-value-card strong { font-size: 1.3rem; overflow-wrap: anywhere; }
@media (max-width: 420px) {
  .stock-value-card { grid-column: 1 / -1; }
}
