:root {
  --bg: #f4f5f8; --card: #fff; --text: #1b1f2a; --muted: #6b7280; --line: #e3e6ec;
  --accent: #3b4bd8; --accent-2: #2f3cb0; --accent-soft: #eef0ff;
  --red: #c62828; --red-soft: #fdecec; --green: #1b7f45; --green-soft: #e6f6ec;
  --amber: #a15c00; --amber-soft: #fff3df; --blue: #1d5fbf; --blue-soft: #e8f0fc;
  --radius: 10px; --side: 230px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141a; --card: #1b1e26; --text: #e6e8ee; --muted: #9aa1ae; --line: #2c303b;
    --accent: #7383ff; --accent-2: #8b98ff; --accent-soft: #232846;
    --red-soft: #3a1e20; --green-soft: #17301f; --amber-soft: #36290f; --blue-soft: #18263d;
    --red: #ff8a80; --green: #6fd394; --amber: #ffc46b; --blue: #8ab4ff;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6em; line-height: 1.2; }
h3 { font-size: 1rem; }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.red { color: var(--red); }
.big { font-size: 1.6rem; font-weight: 700; margin: .3em 0; }

/* Maketas */
.app { display: flex; min-height: 100vh; }
.side { width: var(--side); background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30; }
.brand { display: block; padding: 18px 18px 14px; font-weight: 700; font-size: 1.05rem; color: var(--text); border-bottom: 1px solid var(--line); }
.side nav { flex: 1; padding: 8px; overflow-y: auto; }
.side nav a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); margin-bottom: 2px; }
.side nav a:hover { background: var(--bg); text-decoration: none; }
.side nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.me { padding: 14px 18px; border-top: 1px solid var(--line); font-size: .85rem; color: var(--muted); }
.main { flex: 1; margin-left: var(--side); min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.top h1 { font-size: 1.2rem; margin: 0; flex: 1; min-width: 0; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.burger { display: none; background: none; border: 0; font-size: 1.4rem; color: var(--text); cursor: pointer; padding: 0 4px; }
.content { padding: 20px 24px 60px; max-width: 1400px; }
.scrim { display: none; }

@media (max-width: 900px) {
  .side { transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 25; }
  .main { margin-left: 0; }
  .burger { display: block; }
  .top { padding: 10px 16px; }
  .content { padding: 14px 16px 80px; }
}

/* Kortelės, tinklelis */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.narrow { max-width: 720px; }
.grid { display: grid; gap: 12px 16px; }
.g2 { grid-template-columns: repeat(2, 1fr); }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g5 { grid-template-columns: repeat(5, 1fr); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.grid > .card { margin-bottom: 0; }
@media (max-width: 900px) { .g3, .g4, .g5 { grid-template-columns: repeat(2, 1fr); } .span3 { grid-column: span 2; } }
@media (max-width: 560px) { .g2, .g3, .g4, .g5 { grid-template-columns: 1fr; } .span2, .span3 { grid-column: auto; } }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Formos */
.f { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
.f > span { font-size: .8rem; color: var(--muted); font-weight: 500; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[readonly] { background: var(--bg); }
textarea { resize: vertical; }
.chk { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: .9rem; }
.chks { display: flex; flex-direction: column; justify-content: center; gap: 6px; }
.grid > .chk { align-self: end; padding-bottom: 18px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; padding: 12px; }
.filters > input, .filters > select { width: auto; flex: 1 1 160px; }
.filters .inline-f { margin: 0; flex: 1 1 150px; }
.copy { display: flex; gap: 6px; }

/* Mygtukai */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 500; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); background: var(--red-soft); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: .85rem; }
.btn.block { width: 100%; margin-bottom: 6px; }
.btn:disabled { opacity: .6; cursor: wait; }
.big-btn { padding: 14px 22px; font-size: 1.05rem; }
.btn-x { border: 0; background: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1; padding: 2px 6px; }
.btn-x:hover { color: var(--red); }
.btn-link { border: 0; background: none; color: var(--red); cursor: pointer; font: inherit; padding: 0; }
form.inline { display: inline; }
.top-actions form.inline .btn { margin: 0; }
.bar { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.bar.sticky { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--line); z-index: 5; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.dropdown { position: relative; }
.dd-menu { display: none; position: absolute; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 220px; z-index: 40; padding: 4px; }
.dropdown.open .dd-menu { display: block; }
.dd-menu a { display: block; padding: 8px 12px; border-radius: 6px; color: var(--text); }
.dd-menu a:hover { background: var(--bg); text-decoration: none; }

/* Pranešimai, žymos */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.flash.ok { background: var(--green-soft); border-color: transparent; color: var(--green); }
.flash.err { background: var(--red-soft); border-color: transparent; color: var(--red); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.b-gray { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.b-green { background: var(--green-soft); color: var(--green); }
.b-red { background: var(--red-soft); color: var(--red); }
.b-amber { background: var(--amber-soft); color: var(--amber); }
.b-blue { background: var(--blue-soft); color: var(--blue); }

/* Statistika */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat b { font-size: 1.45rem; }
.stat small { color: var(--muted); }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* Lentelės */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tfoot td { font-weight: 600; border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--bg); }
.tbl tr.sub td { background: var(--bg); font-weight: 600; font-size: .85rem; }
.tbl tr.grand td { font-size: 1.05rem; }
.num { text-align: right !important; white-space: nowrap; }
.series-tbl input[type=text], .series-tbl input:not([type]) { width: auto; }
@media (max-width: 700px) {
  .tbl thead { display: none; }
  .tbl, .tbl tbody, .tbl tr, .tbl td, .tbl tfoot { display: block; width: 100%; }
  .tbl tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .tbl td { border: 0; padding: 3px 4px; text-align: left !important; display: flex; justify-content: space-between; gap: 12px; }
  .tbl td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: .8rem; }
  .tbl tfoot td { display: inline-block; width: auto; }
}

/* Sąskaitos redaktorius */
.lines { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.lines th { text-align: left; font-size: .78rem; color: var(--muted); font-weight: 600; padding: 6px 4px; }
.lines td { padding: 4px; vertical-align: middle; }
.lines .c-name { width: 38%; }
.lines .c-qty, .lines .c-disc { width: 8%; }
.lines .c-unit { width: 8%; }
.lines .c-price { width: 11%; }
.lines .c-vat { width: 13%; }
.lines .c-sum { width: 11%; font-weight: 600; text-align: right; white-space: nowrap; }
.no-vat .vat-col { display: none !important; }
.totals { margin-left: auto; max-width: 340px; display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.totals > div, #t-vat > div { display: flex; justify-content: space-between; gap: 20px; }
#t-vat { flex-direction: column; gap: 4px; }
.totals .grand { font-size: 1.2rem; border-top: 1px solid var(--line); padding-top: 6px; }
@media (max-width: 760px) {
  .lines thead { display: none; }
  .lines, .lines tbody { display: block; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); position: relative; }
  .lines td { padding: 0; width: auto !important; }
  .lines td.c-name, .lines td.c-desc { grid-column: 1 / -1; padding-right: 32px; }
  .lines td.c-sum { grid-column: 1 / -1; text-align: right; }
  .lines td.c-del { position: absolute; top: 10px; right: 0; }
  .lines td[data-l]::before { content: attr(data-l); display: block; font-size: .72rem; color: var(--muted); }
}

/* Peržiūra */
.view { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.view-doc { overflow-x: auto; }
.view-side .card { margin-bottom: 12px; }
.pay { padding: 6px 0; border-bottom: 1px solid var(--line); }
.pay-form { margin-top: 10px; }
@media (max-width: 1100px) { .view { grid-template-columns: 1fr; } }

/* Dokumentas (A4) – visada šviesus */
.doc { background: #fff; color: #111; width: 100%; max-width: 820px; margin: 0 auto; padding: 44px 48px; border: 1px solid var(--line); border-radius: 4px; position: relative; font-size: 13px; line-height: 1.45; overflow: hidden; }
.doc .wm { position: absolute; top: 38%; left: 0; right: 0; text-align: center; font-size: 80px; font-weight: 800; color: rgba(200, 30, 30, .09); transform: rotate(-22deg); pointer-events: none; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 24px; }
.doc-logo img { max-height: 70px; max-width: 220px; }
.doc-title { text-align: right; }
.doc-title h2 { font-size: 19px; margin: 0 0 6px; letter-spacing: .02em; color: #111; }
.doc-ref { background: #f5f5f5; padding: 6px 10px; border-radius: 4px; }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 22px; }
.pl { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #777; margin-bottom: 4px; }
.doc-lines { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.doc-lines th { background: #f2f3f6; font-size: 11px; font-weight: 600; padding: 7px 6px; text-align: right; border-bottom: 1px solid #ccc; color: #333; }
.doc-lines td { padding: 7px 6px; border-bottom: 1px solid #e5e5e5; text-align: right; vertical-align: top; }
.doc-lines .l { text-align: left; }
.doc-lines tfoot td { border-bottom: 0; }
.doc-totals { display: flex; justify-content: flex-end; }
.doc-totals table { border-collapse: collapse; min-width: 260px; }
.doc-totals td { padding: 4px 6px; text-align: right; }
.doc-totals td:first-child { text-align: left; color: #444; }
.doc-totals .grand td { font-weight: 700; font-size: 15px; border-top: 2px solid #111; padding-top: 6px; }
.words { margin-top: 14px; }
.doc-notes { white-space: normal; color: #333; border-top: 1px solid #eee; padding-top: 10px; }
.signs { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 40px; }
.signs span { display: block; border-bottom: 1px solid #999; min-height: 22px; margin-top: 4px; padding-bottom: 2px; }
.cmr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid #999; margin-bottom: 14px; }
.cmr-grid .box { border: 1px solid #ccc; margin: -1px 0 0 -1px; }
.doc .box { padding: 8px 10px 10px 30px; position: relative; min-height: 64px; }
.doc .box i { position: absolute; left: 8px; top: 7px; font-style: normal; font-weight: 700; font-size: 11px; color: #555; }
.doc .box > span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: #777; margin-bottom: 3px; }
.doc .box.wide { border: 1px solid #ccc; margin-bottom: 14px; }
.cmr-sigs { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid #999; }
.cmr-sigs .box { border-right: 1px solid #ccc; min-height: 130px; }
.cmr-sigs .box:last-child { border-right: 0; }
.cmr-sigs img { max-width: 100%; height: 70px; object-fit: contain; display: block; }
.sig-empty { height: 70px; }
@media (max-width: 640px) {
  .doc { padding: 22px 16px; font-size: 12px; }
  .doc-head { flex-direction: column-reverse; }
  .doc-title { text-align: left; }
  .parties, .cmr-grid { grid-template-columns: 1fr; }
  .cmr-sigs { grid-template-columns: 1fr; }
  .cmr-sigs .box { border-right: 0; border-bottom: 1px solid #ccc; }
}

/* Sąnaudos */
.upload { text-align: center; border: 2px dashed var(--line); }
.upload.drag { border-color: var(--accent); background: var(--accent-soft); }
.upload-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.dropzone { color: var(--muted); font-size: .85rem; }
.exp-edit { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.exp-files .preview { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 12px; }
.preview img { width: 100%; max-height: 80vh; object-fit: contain; display: block; margin-bottom: 6px; border-radius: 6px; }
.preview iframe { width: 100%; height: 75vh; border: 0; margin-bottom: 6px; }
.preview.empty { padding: 60px 10px; text-align: center; }
@media (max-width: 900px) { .exp-edit { grid-template-columns: 1fr; } .preview img { max-height: 50vh; } .preview iframe { height: 55vh; } }

/* Nustatymai */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 7px 14px; border-radius: 8px; color: var(--text); background: var(--card); border: 1px solid var(--line); }
.tabs a.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tabs a:hover { text-decoration: none; }
.logo-prev { max-height: 60px; display: block; margin-bottom: 6px; background: #fff; padding: 4px; border-radius: 4px; }
.export-list .btn { justify-content: flex-start; }

/* Dialogai, parašas */
.dlg { border: 0; border-radius: 14px; padding: 20px; width: min(560px, calc(100vw - 24px)); background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(10, 12, 20, .45); }
.sig-dlg { width: min(760px, calc(100vw - 16px)); }
#sig-pad { width: 100%; height: 240px; background: #fff; border: 2px dashed #bbb; border-radius: 10px; touch-action: none; display: block; cursor: crosshair; }
@media (orientation: landscape) and (max-height: 500px) { #sig-pad { height: 52vh; } .sig-dlg { padding: 10px; } .sig-dlg .f { margin-bottom: 4px; } }
.sign-card details { margin-top: 6px; font-size: .88rem; }
.sign-card summary { cursor: pointer; color: var(--accent); }
.qr { display: flex; justify-content: center; padding: 10px; background: #fff; border-radius: 8px; margin: 8px 0; }

/* Viešas puslapis / prisijungimas */
body.bare { background: var(--bg); }
.bare-wrap { max-width: 880px; margin: 0 auto; padding: 24px 16px 60px; }
.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { font-size: 1.3rem; margin-bottom: 18px; }
.pub-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

/* Spausdinimas */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .side, .top, .view-side, .bar, .flash, .pub-bar, .filters, .tabs, .scrim, dialog { display: none !important; }
  .main { margin: 0; }
  .content, .bare-wrap { padding: 0; max-width: none; }
  .view { display: block; }
  .doc { border: 0; padding: 0; max-width: none; }
  .card { border: 0; padding: 0; }
}
