:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --card-2: #f8faf9;
  --text: #16201b;
  --muted: #69746f;
  --line: #e2e7e4;
  --accent: #0f7b5f;
  --accent-ink: #ffffff;
  --accent-soft: #e5f4ee;
  --pos: #0f7b5f;
  --pos-soft: #e5f4ee;
  --neg: #c0392f;
  --neg-soft: #fcebea;
  --info: #2f62c0;
  --info-soft: #e9effb;
  --warn: #a8660b;
  --warn-soft: #fbf1e1;
  --shadow: 0 1px 2px rgba(16, 32, 27, .05), 0 4px 16px rgba(16, 32, 27, .05);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1311;
    --card: #161d1a;
    --card-2: #1b2320;
    --text: #e6ece9;
    --muted: #92a09a;
    --line: #26312d;
    --accent: #2fbf91;
    --accent-ink: #06231a;
    --accent-soft: #143128;
    --pos: #3ccf9e;
    --pos-soft: #143128;
    --neg: #f07a70;
    --neg-soft: #3a1c1a;
    --info: #7ea6f2;
    --info-soft: #1a2640;
    --warn: #e4a74a;
    --warn-soft: #3a2a12;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.hidden { display: none !important; }
svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-in {
  max-width: 1040px; margin: 0 auto; height: 56px; padding: 0 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.01em; font-size: 17px; }
.brand img { width: 30px; height: 30px; }
.topnav { display: none; gap: 4px; margin-left: 20px; }
.topnav a { padding: 8px 12px; border-radius: 10px; color: var(--muted); font-weight: 500; }
.topnav a.on { color: var(--text); background: var(--card); box-shadow: var(--shadow); }
.spacer { flex: 1; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--muted);
}
.iconbtn:hover { background: var(--card); color: var(--text); }

main { max-width: 1040px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav-in { display: grid; grid-template-columns: repeat(5, 1fr); height: var(--nav-h); max-width: 560px; margin: 0 auto; }
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted); font-weight: 500;
}
.bottomnav a.on { color: var(--accent); }
.bottomnav .fab-slot { display: grid; place-items: center; }
.fab {
  width: 52px; height: 52px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
  margin-top: -18px;
}
.fab svg.i { width: 26px; height: 26px; stroke-width: 2.4; }
.btn.fab-desktop { display: none; }

@media (min-width: 900px) {
  .topnav { display: flex; }
  .bottomnav { display: none; }
  main { padding-bottom: 48px; }
  .btn.fab-desktop { display: inline-flex; }
}

/* ---------- elements ---------- */
h1 { font-size: 22px; margin: 4px 0 16px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; flex: 1; min-width: 0; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); margin-bottom: 8px; font-size: 14px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.pad { padding: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--text) 25%, var(--line)); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--neg); }
.btn.block { width: 100%; }
.btn.sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .6; cursor: default; }

label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; height: 44px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card-2); outline: none;
}
textarea.input { height: auto; min-height: 72px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--card); }
.input.money { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.hint { font-size: 13px; color: var(--muted); margin-top: -6px; margin-bottom: 14px; }
.hint b { color: var(--text); }

.seg { display: inline-flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; height: 36px; padding: 0 14px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; height: 34px; padding: 0 14px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); }
.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }

.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.empty svg.i { width: 40px; height: 40px; stroke-width: 1.4; opacity: .5; display: block; margin: 0 auto 8px; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat { padding: 14px 16px; display: block; }
.stat .lbl { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; font-weight: 500; }
.stat .v { font-size: 20px; font-weight: 750; margin-top: 4px; letter-spacing: -.01em; }
.stat .v2 { font-size: 14px; font-weight: 600; color: var(--muted); }
@media (max-width: 720px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:first-child { grid-column: 1 / -1; }
}

.net { padding: 16px 18px; margin-bottom: 12px; }
.net .lbl { font-size: 13px; color: var(--muted); font-weight: 500; }
.net-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.net .big { font-size: 28px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.net .big2 { font-size: 18px; font-weight: 700; }
.net .badge { font-size: 13px; padding: 4px 10px; white-space: nowrap; }
.net-tbl { width: 100%; max-width: 560px; border-collapse: collapse; font-size: 14px; margin-top: 12px; }
.net-tbl th, .net-tbl td { padding: 5px 0 5px 12px; text-align: right; }
.net-tbl th:first-child, .net-tbl td:first-child { text-align: left; padding-left: 0; color: var(--muted); }
.net-tbl th { font-size: 12px; color: var(--muted); font-weight: 600; }
.net-tbl tr.tot td { border-top: 1px solid var(--line); font-weight: 700; padding-top: 8px; color: inherit; }
.net-tbl tr.tot td.pos { color: var(--pos); }
.net-tbl tr.tot td.neg { color: var(--neg); }
.linkbtn { display: block; text-align: left; border: 0; background: none; padding: 0; margin-top: 10px; cursor: pointer; color: var(--accent); font-weight: 600; }

.kassa-strip { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; margin: 0 -2px; }
.kassa-strip::-webkit-scrollbar { display: none; }
.kassa-card { min-width: 170px; padding: 12px 14px; flex: none; }
.kassa-card .n { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kassa-card .b { font-weight: 700; font-size: 17px; margin-top: 2px; }

.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (min-width: 720px) { .actions { grid-template-columns: repeat(6, 1fr); } }
.action {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px;
  border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); cursor: pointer;
  font-size: 13px; font-weight: 600; text-align: center; box-shadow: var(--shadow);
}
.action:hover { border-color: var(--accent); }
.action .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; }

.t-goods_in .ic, .ic.t-goods_in { background: var(--info-soft); color: var(--info); }
.t-goods_out .ic, .ic.t-goods_out { background: var(--warn-soft); color: var(--warn); }
.t-pay_out .ic, .ic.t-pay_out, .t-expense .ic, .ic.t-expense { background: var(--neg-soft); color: var(--neg); }
.t-pay_in .ic, .ic.t-pay_in, .t-income .ic, .ic.t-income { background: var(--pos-soft); color: var(--pos); }
.t-transfer .ic, .ic.t-transfer, .ic.t-cp_opening { background: var(--card-2); color: var(--muted); }

/* ---------- lists ---------- */
.list { overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line);
  cursor: pointer; width: 100%; text-align: left; background: transparent; border-left: 0; border-right: 0; border-bottom: 0;
}
.item:first-child { border-top: 0; }
.item:hover { background: var(--card-2); }
.item .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.item .main { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .t2 { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.item .t2 svg.i { width: 14px; height: 14px; }
.item .end { text-align: right; flex: none; }
.item .amt { font-weight: 700; }
.day { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 14px 4px 6px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; background: var(--accent-soft); color: var(--accent); flex: none; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.badge.pos { background: var(--pos-soft); }
.badge.neg { background: var(--neg-soft); }
.badge.zero { background: var(--card-2); color: var(--muted); }

.search { position: relative; margin-bottom: 12px; }
.search svg.i { position: absolute; left: 12px; top: 12px; color: var(--muted); }
.search .input { padding-left: 40px; }

.filters { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 10px; margin-bottom: 12px; }
@media (max-width: 640px) { .filters { grid-template-columns: 1fr 1fr; } .filters > :first-child { grid-column: 1 / -1; } }

/* ---------- counterparty ---------- */
.hero { padding: 18px; }
.hero .name { font-size: 20px; font-weight: 750; }
.bal-line { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.bal-line:first-of-type { border-top: 0; }
.bal-line .v { font-size: 20px; font-weight: 750; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
@media (max-width: 520px) { .quick { grid-template-columns: repeat(2, 1fr); } }
.quick .action { flex-direction: row; justify-content: flex-start; padding: 10px 12px; box-shadow: none; }
.quick .action .ic { width: 32px; height: 32px; border-radius: 10px; }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--card-2); }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--card-2); }
.tbl tr.sum td { font-weight: 700; background: var(--card-2); }
.tbl .d-m { display: none; }
@media (max-width: 640px) {
  table.tbl { font-size: 13px; }
  .tbl th, .tbl td { padding: 8px 6px; }
  .tbl th:first-child, .tbl td:first-child { padding-left: 12px; }
  .tbl th:last-child, .tbl td:last-child { padding-right: 12px; }
  .tbl th { font-size: 11px; letter-spacing: 0; }
  .tbl .c-date { display: none; }
  .tbl .d-m { display: block; }
}
.dates2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }

/* ---------- sheet / modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(8, 14, 11, .45);
  display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease;
}
.sheet {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  animation: up .2s ease;
}
@media (min-width: 640px) {
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: 20px; max-height: 88vh; }
}
.sheet-head { display: flex; align-items: center; gap: 10px; position: sticky; top: -8px; background: var(--card); padding: 12px 0 12px; z-index: 2; }
.sheet-head h3 { margin: 0; font-size: 18px; flex: 1; display: flex; align-items: center; gap: 10px; }
.sheet-head .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; }
.sheet-foot { display: flex; gap: 10px; margin-top: 18px; }
.sheet-foot .btn { flex: 1; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; }

/* attachments */
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.att {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
  background: var(--card-2); display: grid; place-items: center; cursor: pointer;
}
.att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att .pdf { font-weight: 800; color: var(--neg); font-size: 13px; }
.att .x {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .6); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.att .x svg.i { width: 14px; height: 14px; stroke-width: 2.6; }
.att-add { display: flex; gap: 8px; margin-bottom: 10px; }
.att-add .btn { flex: 1; }

.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .92); display: grid; place-items: center; }
.viewer img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.viewer .iconbtn { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; color: #fff; background: rgba(255, 255, 255, .12); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .card { width: 100%; max-width: 400px; padding: 28px 24px; }
.auth .logo { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 22px; }
.auth .logo img { width: 64px; height: 64px; }
.auth .logo b { font-size: 24px; letter-spacing: -.01em; }
.auth .switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.auth .switch a { color: var(--accent); font-weight: 600; }
.err { background: var(--neg-soft); color: var(--neg); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 70; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--neg); color: #fff; }

.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- print (akt sverka) ---------- */
.print-only { display: none; }
@media print {
  body { background: #fff; color: #000; }
  .topbar, .bottomnav, .no-print, .toast { display: none !important; }
  .print-only { display: block; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 0; }
  .tbl th { background: #eee; color: #000; }
  .tbl td, .tbl th { border: 1px solid #999; }
}
