/* Sapana – Sapno ERP. Tamsi grafito juosta, balta darbo erdvė, Sapno bordo akcentas (13.16). */
:root {
  --bar: #1c2430; --bar-2: #273140; --bar-text: #c9d1dc; --bar-active: #fff;
  --bg: #f4f5f7; --panel: #fff; --line: #e2e5ea; --line-2: #eef0f3; --text: #1d232b; --muted: #6b7480;
  --accent: #7a1f2b; --accent-2: #9b2c3b; --accent-soft: #f6e9eb;
  --green: #2f9e5b; --green-bg: #d8f0e1; --yellow: #8a6a00; --yellow-bg: #fbecb0; --orange: #a14d00; --orange-bg: #fddcbc;
  --red: #b3261e; --red-bg: #f9d3d0; --blue: #24548f; --blue-bg: #dde8f6; --grey-bg: #e7e9ec;
  --radius: 6px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-height: 100vh; overflow-x: hidden; }
main, .subbar, .page-head, .doc, .card, .tbl-box { min-width: 0; max-width: 100%; }
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0; } h2 { font-size: 17px; margin: 0; } h3 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.grow { flex: 1; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.loading { padding: 40px; color: var(--muted); text-align: center; }
.muted { color: var(--muted); }

/* ---------- viršutinė juosta ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 4px; height: 52px; padding: 0 12px; background: var(--bar); color: var(--bar-text); }
.logo { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 17px; text-decoration: none; margin-right: 14px; letter-spacing: .02em; }
.logo img { width: 26px; height: 26px; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.nav a { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: var(--radius); color: var(--bar-text); text-decoration: none; white-space: nowrap; }
.nav a:hover { background: var(--bar-2); color: #fff; }
.nav a.on { background: var(--bar-2); color: var(--bar-active); box-shadow: inset 0 -2px 0 var(--accent-2); }
.topbar .create { margin-left: 8px; }
.user-btn { display: flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--bar-text); padding: 6px 8px; border-radius: var(--radius); cursor: pointer; font: inherit; }
.user-btn:hover { background: var(--bar-2); color: #fff; }
.drop { position: relative; }
.drop .menu { right: 0; top: calc(100% + 6px); }

/* ---------- antras lygis ---------- */
.subbar { display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 46px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 13px 12px 11px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.segs { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg { border: 0; background: var(--panel); padding: 6px 12px; font: inherit; cursor: pointer; color: var(--muted); }
.seg + .seg { border-left: 1px solid var(--line); }
.seg.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { padding: 16px; max-width: 1600px; margin: 0 auto; }

/* ---------- mygtukai, laukai ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); font: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c5cad2; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { color: var(--red); }
.btn-sm { padding: 4px 8px; font-size: 13px; }
.icon-btn { background: none; border: 0; padding: 4px; cursor: pointer; color: inherit; border-radius: var(--radius); display: inline-flex; }
.icon-btn:hover { background: var(--line-2); }
input, select, textarea { font: inherit; color: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-wide { grid-column: 1 / -1; }
.field-label { font-size: 12px; color: var(--muted); }
.field input, .field select { width: 100%; }
.hint { color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; padding: 4px 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- būsenų langeliai (pilnai nuspalvinti) ---------- */
.st { display: inline-block; padding: 3px 8px; border-radius: 4px; font-weight: 600; font-size: 12px; white-space: nowrap; }
.st-green { background: var(--green-bg); color: var(--green); }
.st-yellow { background: var(--yellow-bg); color: var(--yellow); }
.st-orange { background: var(--orange-bg); color: var(--orange); }
.st-red { background: var(--red-bg); color: var(--red); }
.st-blue { background: var(--blue-bg); color: var(--blue); }
.st-grey { background: var(--grey-bg); color: var(--muted); }
td.cell-st { padding: 0 !important; }
td.cell-st .st { display: block; border-radius: 0; padding: 9px 8px; height: 100%; }
.late { background: var(--red-bg); color: var(--red); font-weight: 600; }
.chan { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; }
.chan .ico { width: 15px; height: 15px; }
.chan-shopify { background: #e3f1d8; color: #3d7a19; } .chan-b2b { background: var(--blue-bg); color: var(--blue); }
.chan-rankinis { background: #efe5f7; color: #6a3d8f; } .chan-kita { background: var(--grey-bg); color: var(--muted); }
.lock { color: var(--accent); }

/* ---------- lentelės ---------- */
.tbl-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.tbl-tools { display: flex; align-items: center; gap: 14px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tbl-count { color: var(--muted); font-size: 13px; }
.tbl-sum { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); min-width: 0; }
.tbl-sum b { color: var(--text); }
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; }
.tbl th, .tbl td { padding: 7px 8px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: middle; white-space: nowrap; }
.tbl thead th { position: sticky; top: 0; background: #fafbfc; font-size: 12px; color: var(--muted); font-weight: 600; z-index: 1; }
.tbl tr.filters th { padding: 4px 6px; background: #fafbfc; border-bottom: 1px solid var(--line); }
.tbl tr.filters input { width: 100%; min-width: 50px; padding: 3px 6px; font-size: 12px; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th:first-child, .tbl td:first-child { position: sticky; left: 0; background: inherit; z-index: 1; }
.tbl tbody tr { background: #fff; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr:hover { background: #f8f9fb; }
.tbl td.empty { text-align: center; color: var(--muted); padding: 24px; }
.tbl td.wrap { white-space: normal; min-width: 180px; }
.tbl input[type=number] { width: 80px; text-align: right; padding: 3px 6px; }
.drag { cursor: grab; color: #9aa3ad; touch-action: none; padding: 4px; display: inline-flex; }
tr.dragging { opacity: .45; }
tr.drop-target td { box-shadow: inset 0 2px 0 var(--accent); }
.col-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 16px; }

/* ---------- dokumento langas ---------- */
.doc { display: flex; flex-direction: column; gap: 14px; }
.doc-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.back { display: inline-flex; padding: 6px; border-radius: var(--radius); color: var(--muted); }
.back:hover { background: var(--line-2); }
.doc-type { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.doc-sub { font-weight: 400; color: var(--muted); }
.doc-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.doc-fields .ro { padding: 6px 0; min-height: 32px; }
.totals { display: grid; grid-template-columns: auto auto; gap: 4px 24px; justify-content: end; padding: 12px 16px; }
.totals .num { text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 16px; }
.status-wrap { position: relative; }
.status-btn { border: 0; background: none; padding: 0; cursor: pointer; font: inherit; display: inline-flex; align-items: center; gap: 4px; }
.status-btn .st { font-size: 13px; padding: 7px 12px; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 4px; z-index: 30; display: flex; flex-direction: column; }
.menu[hidden] { display: none; }
.menu button, .menu a { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 4px; cursor: pointer; font: inherit; color: var(--text); text-decoration: none; }
.menu button:hover, .menu a:hover { background: var(--line-2); }
.menu .danger { color: var(--red); }
.saved { font-size: 13px; color: var(--muted); }
.saved-ok { color: var(--green); } .saved-err { color: var(--red); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card > .tbl-box { box-shadow: none; margin: 0 -16px -14px; border-radius: 0 0 var(--radius) var(--radius); border-left: 0; border-right: 0; border-bottom: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.kpi { font-size: 26px; font-weight: 700; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line-2); }
.list li:last-child { border-bottom: 0; }
.list a { text-decoration: none; color: var(--text); font-weight: 600; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.fill { position: relative; height: 8px; background: var(--line-2); border-radius: 4px; min-width: 70px; overflow: hidden; }
.fill > span { position: absolute; inset: 0 auto 0 0; background: var(--accent); }

/* ---------- modalai, pranešimai ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 26, 34, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 8px; width: 100%; max-width: 520px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-wide { max-width: 960px; }
.modal-head, .modal-foot { display: flex; align-items: center; gap: 8px; padding: 12px 16px; }
.modal-head { justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-foot { justify-content: flex-end; border-top: 1px solid var(--line); }
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow-y: auto; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--bar); color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: var(--shadow); max-width: 420px; }
.toast-err { background: var(--red); }

/* ---------- prisijungimas ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bar); padding: 16px; }
.login form { background: var(--panel); padding: 28px; border-radius: 10px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.login .logo { color: var(--text); justify-content: center; font-size: 22px; margin: 0; }
.login .err { color: var(--red); min-height: 1.2em; }

/* ---------- planšetė / telefonas ---------- */
@media (max-width: 900px) {
  .nav a span.lbl { display: none; }
  .doc-fields, .form-grid { grid-template-columns: minmax(0, 1fr); }
  main { padding: 10px; }
}
@media (max-width: 600px) {
  .topbar { padding: 0 6px; gap: 0; }
  .logo span { display: none; }
  .logo { margin-right: 4px; }
  .create .lbl, .user-btn .lbl { display: none; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .subbar { padding: 0 10px; gap: 6px; }
  .page-head h1 { font-size: 18px; }
  .tbl-tools { gap: 8px; }
}

/* ---------- 13.23: žymėjimas, būsena sąraše, greito kūrimo „+“, žymos ---------- */
.tbl th.sel, .tbl td.sel { width: 32px; padding-left: 10px; padding-right: 4px; }
.tbl.has-sel th:first-child, .tbl.has-sel td:first-child { z-index: 2; }
.tbl tbody tr.selected { background: var(--accent-soft); }
.st-wrap { position: relative; display: inline-block; }
td.cell-st .st-wrap { display: block; }
.st-drop { border: 0; padding: 0; background: none; cursor: pointer; font: inherit; display: flex; align-items: stretch; width: 100%; }
.st-drop .st { flex: 1; text-align: left; }
.st-drop .caret { font-size: 11px; padding: 0 6px; display: flex; align-items: center; color: var(--muted); background: var(--line-2); }
td.cell-st .st-drop .caret { background: rgba(0, 0, 0, .05); }
.st-wrap .menu { left: 0; right: auto; }
.fab { position: fixed; right: 20px; bottom: 20px; width: 52px; height: 52px; border-radius: 50%; border: 0; background: #f2c230; color: #3a2a00; box-shadow: 0 6px 18px rgba(0, 0, 0, .25); cursor: pointer; z-index: 40; display: flex; align-items: center; justify-content: center; }
.fab .ico { width: 26px; height: 26px; stroke-width: 2.4; }
.fab:hover { background: #f5cd4f; }
.fab-menu { position: fixed; right: 20px; bottom: 82px; z-index: 40; }
.fab-menu .menu { position: static; }
.tag { display: inline-block; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; background: var(--blue-bg); color: var(--blue); white-space: nowrap; }
.tag-wait { background: #e6f0ea; color: #2c6e49; }
.neg { color: var(--red); font-weight: 700; }
.qlink { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
.thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.msg { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; max-width: 85%; }
.msg-in { align-self: flex-start; background: #fff; }
.msg-out { align-self: flex-end; background: #f7f3f4; }
.msg-head { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 4px; flex-wrap: wrap; }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.conv-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 10px 12px; background: #fafbfc; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 12px; }
@media (max-width: 600px) { .tbl-tools .lbl { display: none; } .msg { max-width: 100%; } .fab { right: 14px; bottom: 14px; } }
