:root {
  --bg: #f4f5f7;
  --card: #fff;
  --ink: #1d2329;
  --muted: #6b7480;
  --line: #dfe3e8;
  --accent: #1f5f8b;
  --accent-ink: #fff;
  --accent-soft: #e6f0f7;
  --ok: #1f7a4d;
  --ok-soft: #e5f4ec;
  --err: #b42323;
  --err-soft: #fbeaea;
  --warn-soft: #fff6dd;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 18px; }
main.wrap { padding-top: 20px; padding-bottom: 60px; }

/* viršus */
header.top { background: #17324a; color: #dbe6ef; }
header.top .wrap { display: flex; align-items: center; gap: 22px; min-height: 52px; flex-wrap: wrap; }
header.top .brand { color: #fff; font-weight: 700; font-size: 1.1rem; }
header.top nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
header.top nav a { color: #c7d6e3; padding: 6px 10px; border-radius: 6px; }
header.top nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; color: #fff; }
header.top nav a.on { background: rgba(255,255,255,.14); color: #fff; }
header.top nav a.new { color: #fff; background: #2b7ab3; }
header.top nav a.new:hover { background: #3389c6; }
header.top .me { display: flex; gap: 12px; align-items: center; font-size: .9rem; }
header.top .me a, header.top .me .linkbtn { color: #c7d6e3; }

.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.narrow { max-width: 420px; margin: 40px auto; }
.narrow2 { max-width: 640px; }
.login h1 { margin-bottom: 18px; text-align: center; }

/* formos */
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: .92rem; }
.field { margin-bottom: 12px; }
.field .lbl { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.static { padding: 8px 0; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #c9d0d8; border-radius: 6px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3e0; border-color: var(--accent); }
input[readonly] { background: #f2f4f6; }
input[type=checkbox], input[type=radio] { width: auto; }
input.upper { text-transform: uppercase; }
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 16px; }
.span2 { grid-column: span 2; }
.row { display: flex; gap: 8px; align-items: center; }
.row input { max-width: 320px; }

.btn { display: inline-block; font: inherit; font-size: .92rem; padding: 8px 14px; border-radius: 6px; border: 1px solid #c3cbd4; background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f4f7; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #1a5279; }
.btn.danger { color: var(--err); border-color: #e2b4b4; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn.wide { width: 100%; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linkbtn.danger { color: var(--err); }
form.inline { display: inline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.actions.sticky { position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--line); padding: 12px 0; margin: 0; z-index: 5; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); border-color: #b9dfc9; color: #164f33; }
.flash.err { background: var(--err-soft); border-color: #efc2c2; color: #7d1717; }
.flash.warn { background: var(--warn-soft); border-color: #f0dc9c; color: #6a5100; }
.flash ul { margin: 6px 0 0; padding-left: 20px; }

.muted { color: var(--muted); }
.small { font-size: .84rem; }
.r { text-align: right; }
.c { text-align: center; }
.nowrap { white-space: nowrap; }
.tag { display: inline-block; font-size: .75rem; padding: 1px 7px; border-radius: 10px; background: #eceff2; color: var(--muted); }
.tag.red { background: var(--err-soft); color: var(--err); }
.tag.green { background: var(--ok-soft); color: var(--ok); }

/* filtrai, sąrašai */
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters label { margin: 0; }
.filters .grow { flex: 1; min-width: 200px; }
.filters .quick { display: flex; gap: 10px; font-size: .88rem; padding-bottom: 8px; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.list th.r, table.list td.r { text-align: right; }
table.list tbody tr:hover { background: #f7fafc; }
table.list tr[data-href] { cursor: pointer; }
table.list tr.annulled td { color: #9aa2ab; }
table.list tfoot td { font-weight: 600; background: #fafbfc; border-bottom: 0; }
td.empty { text-align: center; color: var(--muted); padding: 30px !important; }
.pager { display: flex; gap: 8px; margin-top: 12px; }

/* sąskaitos forma */
.buyer-search { position: relative; flex: 1; max-width: 460px; }
.dropdown { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid #c9d0d8; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 340px; overflow-y: auto; }
.dropdown div { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #f0f2f4; }
.dropdown div:hover, .dropdown div.act { background: var(--accent-soft); }
.dropdown small { color: var(--muted); display: block; }
.picked { font-size: .84rem; color: var(--ok); margin: -4px 0 10px; }
.seg { display: flex; gap: 14px; }
.seg label { flex-direction: row; align-items: center; gap: 6px; margin: 0; color: var(--ink); font-size: .92rem; }
table.lines { border: 0; }
table.lines th { font-size: .8rem; color: var(--muted); font-weight: 600; text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.lines th.r { text-align: right; }
table.lines td { padding: 3px 4px; }
table.lines th.w-nr { width: 34px; }
table.lines th.w-name { width: auto; min-width: 240px; }
table.lines th.w-unit { width: 90px; }
table.lines th.w-qty { width: 100px; }
table.lines th.w-price { width: 120px; }
table.lines th.w-rate { width: 90px; }
table.lines th.w-disc { width: 100px; }
table.lines th.w-sum { width: 110px; }
table.lines th.w-x { width: 30px; }
table.lines input.r { text-align: right; }
table.lines input[readonly] { background: transparent; border-color: transparent; color: var(--ink); padding-left: 2px; }
table.lines input.c { text-align: center; }
table.lines .l-sum { width: 110px; padding-right: 10px; font-variant-numeric: tabular-nums; }
.x { border: 0; background: none; color: #a3aab2; font-size: 1.2rem; cursor: pointer; padding: 0 6px; }
.x:hover { color: var(--err); }
.bottom { display: flex; gap: 24px; justify-content: space-between; align-items: flex-start; margin-top: 16px; flex-wrap: wrap; }
.bottom .note { flex: 1; min-width: 260px; max-width: 560px; }
table.totals { width: auto; min-width: 280px; }
table.totals td { padding: 4px 0 4px 20px; text-align: right; font-variant-numeric: tabular-nums; }
table.totals td:first-child { color: var(--muted); }
table.totals tr.big td { font-size: 1.2rem; font-weight: 700; color: var(--ink); border-top: 2px solid var(--ink); padding-top: 8px; }

/* peržiūra */
.view-grid { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: start; }
.pdf-card { padding: 8px; }
.pdf-card iframe { width: 100%; height: 1000px; border: 0; background: #eee; }
dl.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 10px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; }
dl.kv dd { margin: 0; }
ul.history { list-style: none; padding: 0; margin: 0; }
ul.history li { padding: 6px 0; border-bottom: 1px solid #f0f2f4; font-size: .9rem; }
code { background: #eef1f4; padding: 1px 5px; border-radius: 4px; font-size: .88em; }

@media (max-width: 900px) {
  .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
  .view-grid { grid-template-columns: 1fr; }
  .pdf-card iframe { height: 600px; }
}
@media (max-width: 600px) {
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  header.top .me span { display: none; }
}

.with-btn { display: flex; gap: 6px; }
.with-btn input { flex: 1; }
.ok-text { color: var(--ok); margin-top: 4px; }
.err-text { color: var(--err); margin-top: 4px; }

.date-wrap { position: relative; display: flex; align-items: stretch; }
.date-wrap .date-txt { flex: 1; min-width: 130px; padding-right: 36px; font-variant-numeric: tabular-nums; }
.date-wrap .cal { position: absolute; right: 1px; top: 1px; bottom: 1px; width: 32px; border: 0; background: transparent; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.date-wrap .cal:hover { color: var(--accent); }
.date-wrap .date-pick { position: absolute; right: 0; bottom: 0; width: 32px; height: 100%; opacity: 0; pointer-events: none; border: 0; padding: 0; }

/* čekio skenavimas */
.scan-bar { margin-top: 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.scan-status { padding: 10px 12px; border-radius: 6px; margin-top: 10px; font-size: .9rem; border: 1px solid; }
.scan-status.wait { background: #eef4f9; border-color: #c9dcec; color: #1f4f73; }
.scan-status.ok { background: var(--ok-soft); border-color: #b9dfc9; color: #164f33; }
.scan-status.warn { background: var(--warn-soft); border-color: #f0dc9c; color: #6a5100; }
.scan-status.err { background: var(--err-soft); border-color: #efc2c2; color: #7d1717; }
.scan-status ul { margin: 6px 0 0; padding-left: 20px; }
.modal { position: fixed; inset: 0; background: rgba(20, 30, 40, .45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-box { position: relative; background: #fff; border-radius: 10px; padding: 22px; width: min(420px, 92vw); text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-close { position: absolute; right: 8px; top: 6px; font-size: 1.6rem; }
.qr { width: 260px; height: 260px; margin: 8px auto; }
.qr svg { width: 100%; height: 100%; }
#scan-url { word-break: break-all; }
body.scan-page { background: #fff; }
main.scan { max-width: 520px; margin: 0 auto; padding: 18px; }
main.scan h1 { margin-bottom: 8px; }
.btn.big { display: block; text-align: center; font-size: 1.15rem; padding: 16px; margin: 16px 0; }
.btn.disabled { opacity: .5; pointer-events: none; }
#preview { width: 100%; max-height: 50vh; object-fit: contain; margin-top: 12px; border: 1px solid var(--line); border-radius: 6px; }

.btn.big-scan { font-size: 1.1rem; padding: 14px 18px; width: 100%; }
.scan-bar.top { margin: 0 0 14px; }

/* Kasos čekio skyrius */
#receipt-card .card-head .scan-bar { margin: 0 0 0 auto; }
.receipt-wrap { display: grid; grid-template-columns: 1fr; gap: 18px; }
.receipt-wrap.has-photo { grid-template-columns: minmax(0, 1fr) 260px; }
.receipt-photo { margin: 0; text-align: center; }
.receipt-photo img { display: block; width: 100%; max-height: 380px; object-fit: contain; background: #f6f7f9; border: 1px solid var(--line); border-radius: 6px; }
.receipt-photo figcaption { margin-top: 4px; }
#receipt-check { font-weight: 600; }
#receipt-check .ok { color: #1c7a47; }
#receipt-check .bad { color: #b42318; }
@media (max-width: 760px) {
  .receipt-wrap.has-photo { grid-template-columns: 1fr; }
  .receipt-photo img { max-height: 300px; }
  #receipt-card .card-head .scan-bar { margin: 0; width: 100%; }
}
#receipt-card #scan-result { margin: 0 0 14px; }

/* Peržiūra ir patvirtinimas */
table.mini { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: .88rem; }
table.mini th, table.mini td { padding: 4px 6px; border-bottom: 1px solid #eef0f3; text-align: left; }
table.mini th { color: var(--muted); font-weight: 500; font-size: .8rem; }
table.mini .r { text-align: right; }
.card .receipt-photo { margin-top: 14px; }
.confirm-box { text-align: left; width: min(520px, 94vw); }
.confirm-box h2 { margin-top: 0; }
.confirm-box .checks { display: grid; gap: 10px; margin: 14px 0; }
.confirm-box .check { display: flex; gap: 8px; align-items: flex-start; font-size: .95rem; }
.confirm-box .check input { margin-top: 3px; width: 18px; height: 18px; flex: none; }
.confirm-box .actions { margin-top: 12px; }
.pdf-open { display: none; }
@media (max-width: 760px) {
  .pdf-open { display: block; text-align: center; margin: 4px 4px 10px; }
}
/* sąskaitos vaizdas – tik baltas lapas */
.pdf-view canvas { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 1px 6px rgba(20, 30, 40, .18); border-radius: 2px; }
.pdf-view canvas + canvas { margin-top: 14px; }
.pdf-view.as-frame iframe { width: 100%; height: 1000px; border: 0; }
.pdf-card { padding: 14px; }
.print-again { margin: -6px 0 14px; display: flex; gap: 8px; flex-wrap: wrap; }

/* Prekių eilutės telefone – kiekviena eilutė kaip kortelė, be horizontalaus slinkimo */
@media (max-width: 760px) {
  .table-wrap:has(table.lines) { overflow: visible; border: 0; background: none; }
  table.lines, table.lines tbody { display: block; width: 100%; }
  table.lines thead { display: none; }
  table.lines tr.line { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px 8px; position: relative;
    padding: 10px 12px; margin-bottom: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
  table.lines tr.line[hidden] { display: none; }
  table.lines tr.line > td { display: block; padding: 0; border: 0; min-width: 0; }
  table.lines tr.line > td:first-child, table.lines tr.line > td.td-unit { display: none; }
  table.lines tr.line > td.td-name { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 6px; padding-right: 28px; min-height: 22px; }
  table.lines td.td-name::before { content: attr(data-n) "."; color: var(--muted); font-size: .85rem; }
  table.lines td.td-name input { font-size: .85rem; color: var(--muted); padding: 0; height: auto; min-width: 0; flex: 1; }
  table.lines td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  table.lines td[data-label] input { width: 100%; font-size: 16px; padding: 8px 6px; }
  table.lines tr.line > td.l-sum { width: auto; padding: 0; text-align: right; font-weight: 600; align-self: end; padding-bottom: 9px; }
  table.lines tr.line > td.td-x { position: absolute; top: 4px; right: 2px; }
  table.lines td.td-x .x { font-size: 1.5rem; padding: 2px 8px; }
  table.lines select.l-rate { width: 100%; }
}
