:root {
  --ink: #1b211d; --muted: #5b625b; --line: #dde1db; --bg: #f4f5f2; --surface: #fff;
  --accent: #2e5a4e; --accent-2: #3c7563; --accent-soft: #e5ede8;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* „hidden" atributas visada slepia elementą (kad .modal display:grid ir pan. jo nenustelbtų). */
[hidden] { display: none !important; }
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; }
button, input, select { font: inherit; }
.muted { color: var(--muted); }
.err { color: #a6473c; min-height: 1.2em; font-size: .85rem; margin-top: .4rem; }

/* Prisijungimas */
.login { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(160deg, #eef1ec, #f6f7f4); }
.login-box { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; width: min(340px, 92vw); box-shadow: 0 8px 30px rgba(0,0,0,.08); text-align: center; }
.login-box h1 { margin: 0; font-size: 1.6rem; color: var(--accent); }
.login-box p { margin: .3rem 0 1.2rem; }
.login-box input { width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; margin-bottom: .8rem; }
.login-box button { width: 100%; padding: .6rem; border: none; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }

/* Viršutinė juosta */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--accent); font-size: 1.15rem; }
.topbar .field { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }
.topbar select { padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); }
.spacer { flex: 1; }
.btn { padding: .45rem .8rem; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 8px; cursor: pointer; font-size: .85rem; }
.btn.ghost { background: transparent; color: var(--accent-2); }
.btn:hover { filter: brightness(1.05); }

/* Išdėstymas */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 53px); }
.menu { border-right: 1px solid var(--line); background: var(--surface); padding: .8rem .5rem; }
.menu button { display: block; width: 100%; text-align: left; padding: .55rem .7rem; border: none; background: transparent; border-radius: 8px; cursor: pointer; color: var(--ink); margin-bottom: .15rem; }
.menu button:hover { background: var(--accent-soft); }
.menu button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.main { padding: 1.2rem 1.4rem; min-width: 0; }
.main h2 { margin: 0 0 .3rem; font-size: 1.3rem; }
.status { color: var(--muted); font-size: .85rem; margin-bottom: .8rem; font-family: var(--mono); }
.status b { color: var(--accent-2); }

/* Paieška */
.toolbar { margin-bottom: .6rem; }
#search { width: min(320px, 100%); padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }

/* Paspaudžiamos dokumentų eilutės */
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--accent-soft); }

/* Dokumento eilučių langas */
.modal { position: fixed; inset: 0; background: rgba(20,25,20,.4); display: grid; place-items: center; padding: 1rem; z-index: 20; }
.modal-box { background: var(--surface); border-radius: 12px; width: min(780px, 96vw); max-height: 88vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 1.05rem; }
.modal .tablewrap { border: none; border-radius: 0; max-height: 75vh; }

/* Naujo dokumento forma */
.form-body { padding: 1rem; overflow: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.form-grid label, .line label { display: flex; flex-direction: column; font-size: .74rem; color: var(--muted); gap: .2rem; }
.form-grid .wide { grid-column: 1 / -1; }
.form-body input { padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); font: inherit; }
.lines-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; margin: .4rem 0 .5rem; font-size: .9rem; }
.line { display: grid; grid-template-columns: 1fr 1fr 100px 1.4fr auto; gap: .5rem; align-items: end; margin-bottom: .5rem; }
.line .rm { padding: .4rem .55rem; border: 1px solid var(--line); background: #fff; border-radius: 7px; cursor: pointer; color: #a6473c; }
.form-foot { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--line); }
.total { font-family: var(--mono); font-weight: 600; color: var(--accent-2); }
.form-foot .err { flex: 1; }
@media (max-width: 640px) { .line { grid-template-columns: 1fr 1fr; } }

/* Lentelė */
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); max-height: calc(100vh - 190px); }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
thead th { position: sticky; top: 0; background: #f0f2ee; text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: .72rem; letter-spacing: .03em; color: var(--muted); text-transform: uppercase; }
tbody td { padding: .4rem .7rem; border-bottom: 1px solid #eef0ec; white-space: nowrap; }
tbody tr:hover { background: #fafbf9; }
td.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); }

/* Pranešimas */
.toast { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 8px; font-size: .85rem; box-shadow: 0 6px 20px rgba(0,0,0,.2); }

@media (max-width: 640px) { .layout { grid-template-columns: 1fr; } .menu { display: flex; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); } .menu button { white-space: nowrap; } }
