:root {
  --bg: #f3f5f4; --panel: #ffffff; --ink: #1d2623; --muted: #6b7a74; --line: #dfe5e2;
  --brand: #1f6f54; --brand-2: #2b8a69; --brand-soft: #e5f2ec;
  --danger: #c0392b; --warn: #b7791f; --pos: #1f6f54; --neg: #c0392b;
  --side: #17332a; --side-ink: #cfe3da;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.4 "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
.loading { padding: 40px; color: var(--muted); }
input, select, button, textarea { font: inherit; }
input, select { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: var(--brand-2); }
input:disabled { background: #f6f7f7; color: #aaa; }
input.num { text-align: right; width: 100%; }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; color: var(--ink); }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--danger); border-color: #efc7c2; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.wide { width: 100%; padding: 10px; font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.err { color: var(--danger); min-height: 1em; margin: 4px 0; }

/* ===== Asosiy ramka ===== */
.shell { display: flex; height: 100vh; }
nav.side { width: 220px; flex: none; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; padding: 12px 8px; overflow-y: auto; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 6px 8px 16px; color: #fff; }
.logo .mark { width: 32px; height: 32px; border-radius: 8px; background: #3fb489; color: #fff; display: grid; place-items: center; font-size: 18px; }
.logo.big { justify-content: center; font-size: 24px; color: var(--ink); padding-bottom: 8px; }
.logo.big .mark { width: 44px; height: 44px; font-size: 24px; background: var(--brand); }
a.nav { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--side-ink); user-select: none; }
a.nav i { font-style: normal; width: 20px; text-align: center; }
a.nav:hover { background: rgba(255,255,255,.07); }
a.nav.on { background: #2b5a49; color: #fff; }
.side-foot { margin-top: auto; padding: 8px; display: flex; flex-direction: column; gap: 10px; }
.lang { display: flex; gap: 4px; }
.lang button { flex: 1; border: 1px solid rgba(255,255,255,.2); background: transparent; color: inherit; border-radius: 5px; padding: 3px; cursor: pointer; }
.lang button.on { background: #3fb489; border-color: #3fb489; color: #fff; }
.login-box .lang button { border-color: var(--line); }
.sync { font-size: 12px; cursor: pointer; line-height: 1.3; }
.sync.ok { color: #7fdcb5; } .sync.offline, .sync.pending, .sync.error { color: #f3c77b; } .sync.auth { color: #ff9c8f; }

main { flex: 1; overflow: auto; padding: 16px 20px; min-width: 0; }
.page { display: flex; flex-direction: column; height: 100%; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h2 { margin: 0 8px 0 0; font-size: 20px; }
.toolbar .search { width: 200px; }
.toolbar .grow { flex: 1; }
.range { display: inline-flex; align-items: center; gap: 4px; }
.sel-info { color: var(--brand); font-size: 13px; }
.chk-label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }

.table-wrap { flex: 1; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; }
table.grid th { position: sticky; top: 0; background: #eef2f0; text-align: left; font-weight: 600; font-size: 13px; padding: 8px; border-bottom: 1px solid var(--line); z-index: 1; }
table.grid td { padding: 6px 8px; border-bottom: 1px solid #eef1ef; }
table.grid tr.click { cursor: pointer; }
table.grid tbody tr:hover { background: #f5faf7; }
table.grid tfoot td { position: sticky; bottom: 0; background: #eef2f0; font-weight: 700; border-top: 1px solid var(--line); }
table.grid .r, .r { text-align: right; white-space: nowrap; }
table.grid .c, .c { text-align: center; }
table.grid .chk { width: 32px; text-align: center; }
table.grid td.empty { text-align: center; color: var(--muted); padding: 30px; }
tr.neg td { color: var(--neg); } tr.pos td:nth-last-child(2) { color: var(--pos); font-weight: 600; }

/* ===== Modal ===== */
.modal-back { position: fixed; inset: 0; background: rgba(15,30,25,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--panel); border-radius: 10px; width: 480px; max-width: calc(100vw - 30px); max-height: calc(100vh - 30px); display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { width: 900px; }
.modal.full { width: calc(100vw - 40px); height: calc(100vh - 40px); max-width: 1400px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 16px; }
.modal-head .x { border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 14px 16px; overflow: auto; flex: 1; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px; border-top: 1px solid var(--line); }
.modal-foot .left { margin-right: auto; }
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field > span { font-size: 12px; color: var(--muted); }
.field small { color: var(--muted); font-size: 11px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ===== Hujjat (nakladnoy, kirim) ===== */
.doc { display: flex; flex-direction: column; gap: 12px; height: 100%; }
.doc-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.doc-head .field { min-width: 120px; }
.doc-head .grow2 { flex: 2; min-width: 260px; }
.doc-head .field input, .doc-head .field select { width: 100%; }
.bal { font-size: 12px; color: var(--brand); margin-top: 3px; min-height: 1em; }
.doc-lines { flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table.lines { border-collapse: collapse; width: 100%; }
table.lines th { position: sticky; top: 0; background: #eef2f0; font-size: 12px; font-weight: 600; padding: 6px; text-align: left; z-index: 2; }
table.lines th.r { text-align: right; } table.lines th.c { text-align: center; }
table.lines td { padding: 3px 4px; border-bottom: 1px solid #eef1ef; vertical-align: top; }
table.lines td.n { width: 34px; color: var(--muted); text-align: center; padding-top: 9px; }
table.lines td.prod { min-width: 320px; }
table.lines td.numc { width: 120px; }
table.lines td.r, table.lines td.c { padding-top: 9px; white-space: nowrap; }
table.lines td.calc { width: 130px; font-weight: 600; }
table.lines td.d { width: 30px; }
table.lines td.warn { color: var(--warn); }
table.lines .hint { display: block; font-size: 11px; color: var(--warn); text-align: right; }
table.lines input { width: 100%; }
table.lines tr.empty-row input.ac-input { border-style: dashed; }
button.del { border: 0; background: none; color: #b9c2be; font-size: 18px; cursor: pointer; padding-top: 4px; }
button.del:hover { color: var(--danger); }
.bonus-box { padding: 8px; }
.bonus-box h4 { margin: 6px 0; }
.doc-foot { display: flex; gap: 16px; align-items: flex-start; }
.doc-foot .grow { flex: 1; } .doc-foot .grow input { width: 100%; }
.totals-box { min-width: 330px; background: #f6f9f7; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; }
.totals-box > div { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.totals-box .pay { border-top: 1px solid var(--line); padding-top: 4px; }
.totals-box .big { font-size: 18px; color: var(--brand); }
.totals-box input.num { width: 140px; }

/* ===== Autocomplete ===== */
.ac { position: relative; }
.ac input { width: 100%; }
.ac-list { display: none; position: absolute; left: 0; right: 0; top: 100%; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.15); max-height: 300px; overflow: auto; min-width: 380px; }
.ac-item { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; cursor: pointer; }
.ac-item small { color: var(--muted); }
.ac-item em { font-style: normal; color: var(--muted); font-size: 12px; white-space: nowrap; }
.ac-item.on { background: var(--brand-soft); }
.ac-item.create { color: var(--brand); font-weight: 600; }

/* ===== Kirish ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #e3efe9, #f6f8f7); }
.login-box { width: 360px; background: #fff; border-radius: 12px; padding: 24px; box-shadow: 0 10px 40px rgba(0,0,0,.1); display: flex; flex-direction: column; gap: 10px; }
.login-box .lang { justify-content: center; } .login-box .lang button { flex: 0 0 50px; color: var(--ink); }
.login-box .lang button.on { color: #fff; }
.login-box input { width: 100%; padding: 9px; }

/* ===== Sozlamalar ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; align-items: start; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.card hr { border: 0; border-top: 1px solid var(--line); width: 100%; }
.card .btn { align-self: flex-start; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px); background: #1d2623; color: #fff; padding: 9px 16px; border-radius: 8px; opacity: 0; transition: .25s; z-index: 100; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }
