:root {
  --bg: #ececec;
  --sidebar: #e0e0e0;
  --card: #ffffff;
  --border: #d4d4d4;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --hover: #e8e8e8;
  --select: #d2d2d2;
  --income: #2e7d32;
  --expense: #c62828;
  --radius: 8px;
  --head: #f5f5f5;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font: 13px/1.4 "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
a { color: inherit; }
body.app { overflow: hidden; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 240px;
  background: var(--sidebar); border-right: 1px solid #c8c8c8;
  display: flex; flex-direction: column;
}
.brand { font-size: 18px; font-weight: 700; padding: 20px 16px 16px; border-bottom: 1px solid #c8c8c8; }
.sidebar nav { flex: 1; padding: 12px; }
.sidebar nav a {
  display: block; padding: 10px 12px; border-radius: var(--radius); text-decoration: none; color: var(--muted); margin-bottom: 4px;
}
.sidebar nav a.active { background: var(--text); color: #fff; }
.sidebar nav a:hover:not(.active) { background: #f0f0f0; color: var(--text); }
.foot { padding: 16px 12px; }
.who { padding: 0 4px 8px; }
.foot a { display: block; padding: 10px 12px; border-radius: var(--radius); text-decoration: none; color: var(--muted); }
.foot a:hover { background: #f0f0f0; }
.content { margin-left: 240px; padding: 20px 24px 12px; min-height: 100%; }
body.app .content { height: 100%; overflow: auto; min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 12px; flex-shrink: 0; }
.head-title { display: flex; align-items: center; gap: 4px; min-width: 0; }
h1 { margin: 0; font-size: 16px; }
h2 { margin: 0 0 12px; font-size: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.metrics {
  display: grid;
  grid-template-columns: minmax(280px, 1.6fr) minmax(160px, 0.7fr) minmax(160px, 0.7fr);
  gap: 10px;
  margin-bottom: 12px;
  flex-shrink: 0;
  align-items: stretch;
}
.metric { padding: 14px 16px; }
.metric-side { display: flex; flex-direction: column; }
.metric-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.metric-top span { color: var(--muted); font-size: 12px; font-weight: 700; }
.metric strong { display: block; font-size: 18px; font-weight: 700; margin-top: 4px; line-height: 1.25; }
.metric strong.masked {
  color: var(--text);
  -webkit-text-security: disc;
}
.bank-saldo {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  margin-top: 8px;
  align-items: flex-start;
}
.bank-saldo-item { min-width: 0; flex: 1 1 150px; }
.bank-saldo-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.bank-saldo-item strong {
  display: block;
  font-size: 18px;
  font-weight: 700;
  margin-top: 4px;
  line-height: 1.25;
  white-space: nowrap;
}
.bank-saldo-item.total {
  padding-left: 28px;
  border-left: 1px solid var(--border);
  flex: 1.1 1 160px;
}
.metric .income, .chip .income, strong.income { color: var(--income); }
.metric .expense, .chip .expense, strong.expense { color: var(--expense); }
.eye-btn {
  width: 28px; height: 28px; padding: 0; margin: 0; flex-shrink: 0;
  border: 0; border-radius: 6px; background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.eye-btn:hover { background: var(--hover); color: var(--text); }
.eye-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.eye-btn .i-eye-off { display: none; }
.eye-btn.open .i-eye { display: none; }
.eye-btn.open .i-eye-off { display: block; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; margin-bottom: 10px; flex-shrink: 0; }
.filters label { display: block; position: relative; font-size: 13px; font-weight: 400; flex: 1 1 180px; min-width: 180px; }
.filters label.grow { flex: 1 1 240px; min-width: 180px; }
input, select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius); height: 40px; min-height: 40px; padding: 0 12px;
}
input[type="checkbox"] {
  width: 14px;
  height: 14px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  flex: none;
  accent-color: var(--text);
}
.filters input,
.filters select { width: 100%; font-weight: 400; }
.filters select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 36px;
  background-image: none;
}
.filters label:has(select)::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #555;
  pointer-events: none;
}
.filters select.placeholder { color: var(--muted); }
.filters input::placeholder { color: var(--muted); font-weight: 400; }
.filters input[type="date"] { width: 168px; min-width: 168px; padding: 0 32px 0 12px; position: relative; }
.filters input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  cursor: pointer;
  opacity: 0.65;
}
.filters label:has(input[type="date"]) { flex: 0 0 auto; min-width: 0; }
.filters label:has(#project-filter),
.filters label:has(#bank) {
  flex: 0 0 220px;
  width: 220px;
  min-width: 220px;
  max-width: 220px;
}
.date-flt { position: relative; }
.date-flt .ph {
  position: absolute;
  left: 12px;
  right: 32px;
  top: 0;
  height: 40px;
  line-height: 40px;
  color: var(--muted);
  pointer-events: none;
  font-weight: 400;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
}
.date-flt input:not(.has-value):not(:focus) { color: transparent; }
.date-flt input.has-value,
.date-flt input:focus { color: var(--text); }
.date-flt:has(input.has-value) .ph,
.date-flt:has(input:focus) .ph { visibility: hidden; }
.date-flt input:not(.has-value):not(:focus)::-webkit-datetime-edit,
.date-flt input:not(.has-value):not(:focus)::-webkit-datetime-edit-fields-wrapper,
.date-flt input:not(.has-value):not(:focus)::-webkit-datetime-edit-text,
.date-flt input:not(.has-value):not(:focus)::-webkit-datetime-edit-month-field,
.date-flt input:not(.has-value):not(:focus)::-webkit-datetime-edit-day-field,
.date-flt input:not(.has-value):not(:focus)::-webkit-datetime-edit-year-field {
  color: transparent;
}
#project-filter option[value=""],
#bank option[value=""] { display: none; }
.btn,
a.btn,
label.btn {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  min-height: 40px;
  padding: 0 16px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafafa;
  color: var(--text);
  font: 13px/1 "Segoe UI", sans-serif;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  box-sizing: border-box;
  flex: 0 0 auto;
}
.btn:hover,
a.btn:hover,
label.btn:hover { background: #f0f0f0; color: var(--text); }
.btn.primary,
a.btn.primary,
label.btn.primary {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}
.btn.primary:hover,
a.btn.primary:hover,
label.btn.primary:hover {
  background: #333;
  border-color: #333;
  color: #fff;
}
.btn.danger,
a.btn.danger {
  background: #fff;
  color: var(--expense);
  border-color: #ef9a9a;
}
.btn.danger:hover,
a.btn.danger:hover { background: #ffebee; color: var(--expense); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 12px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
.filters .btn { align-self: end; }
.import-card { padding: 14px 16px; margin-bottom: 12px; }
.import-card .muted { margin: 4px 0 10px; }
.login-card > .btn { width: 100%; }
.saldo-line { font-size: 18px; font-weight: 700; margin: 4px 0 8px; flex-shrink: 0; }
.page-fill { height: 100%; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.page-fill .table-wrap,
.page-fill .tree-scroll { flex: 1; min-height: 0; }
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  overflow: auto;
  min-width: 0;
}
.table-wrap,
.tree-scroll,
.filter-pop .list {
  scrollbar-width: thin;
  scrollbar-color: #c4c4c4 transparent;
}
.table-wrap::-webkit-scrollbar,
.tree-scroll::-webkit-scrollbar,
.filter-pop .list::-webkit-scrollbar { width: 8px; height: 8px; }
.table-wrap::-webkit-scrollbar-button,
.tree-scroll::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
.table-wrap::-webkit-scrollbar-thumb,
.tree-scroll::-webkit-scrollbar-thumb,
.filter-pop .list::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 8px; }
.table-wrap::-webkit-scrollbar-track,
.tree-scroll::-webkit-scrollbar-track { background: transparent; }
#grid {
  --w-date: 92px;
  --w-payer: 180px;
  --w-money: 200px;
  --w-drop: 200px;
  --w-bank: 110px;
  --w-party: 200px;
  --w-docs: 110px;
  table-layout: fixed;
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 8.5pt;
  line-height: 1.2;
}
#grid .col-date { width: var(--w-date); }
#grid .col-payer { width: var(--w-payer); }
#grid .col-money { width: var(--w-money); }
#grid .col-drop { width: var(--w-drop); }
#grid .col-bank { width: var(--w-bank); }
#grid .col-party { width: var(--w-party); }
#grid .col-docs { width: var(--w-docs); }
#grid .col-purpose { width: auto; }
#grid th:nth-child(1), #grid td:nth-child(1) { min-width: var(--w-date); }
#grid th:nth-child(2), #grid td:nth-child(2) { min-width: var(--w-payer); }
#grid th:nth-child(3), #grid td:nth-child(3),
#grid th:nth-child(4), #grid td:nth-child(4) { min-width: var(--w-money); }
#grid th:nth-child(5), #grid td:nth-child(5),
#grid th:nth-child(6), #grid td:nth-child(6),
#grid th:nth-child(7), #grid td:nth-child(7) { min-width: var(--w-drop); }
#grid th:nth-child(8), #grid td:nth-child(8) { min-width: var(--w-bank); }
#grid th:nth-child(9), #grid td:nth-child(9) { min-width: var(--w-party); }
#grid th:nth-child(10), #grid td:nth-child(10) { min-width: var(--w-docs); }
#grid th:nth-child(11), #grid td:nth-child(11) { min-width: 240px; }
#grid th, #grid td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0 8px;
  height: 22px;
  line-height: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  vertical-align: middle;
}
#grid td {
  user-select: text;
  -webkit-user-select: text;
}
#grid th {
  user-select: none;
  position: sticky;
  top: 0;
  background: var(--head);
  height: 26px;
  line-height: 26px;
  z-index: 1;
  cursor: pointer;
  font: 8.5pt/26px "Segoe UI", sans-serif;
  font-weight: 700;
  text-align: center;
}
#grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
#grid td.c { text-align: center; }
#grid td.inc { color: var(--income); }
#grid td.exp { color: var(--expense); }
#grid tr.selected,
#grid tr.selected:hover { background: var(--select); }
#grid tr:hover { background: var(--hover); }
#grid td.drop {
  position: relative;
  padding-right: 14px;
}
#grid td.drop.open { background: #fff; }
#grid button.cell {
  display: block;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  max-width: 100%;
  height: 20px;
  min-height: 0;
  margin: 0;
  border: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  color: inherit;
  line-height: 20px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border-radius: 0;
  box-shadow: none;
  outline: none;
}
#grid td.drop::after {
  content: "";
  position: absolute;
  right: 5px;
  top: 50%;
  margin-top: -2px;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 4px solid #888;
  pointer-events: none;
}
.cell-pop {
  position: fixed;
  z-index: 16;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  min-width: 160px;
  max-width: min(420px, calc(100vw - 16px));
  max-height: 260px;
  overflow: auto;
  padding: 4px 0;
  font: 8.5pt/22px "Segoe UI", sans-serif;
  color: var(--text);
}
.cell-pop button {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  height: 22px;
  min-height: 22px;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: left;
  padding: 0 10px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cell-pop button:hover { background: var(--hover); }
.cell-pop button.on,
.cell-pop button.on:hover { background: var(--select); }
table { width: 100%; border-collapse: collapse; font-size: 8.5pt; }
table:not(#grid) th, table:not(#grid) td {
  border-bottom: 1px solid var(--border); border-right: 1px solid var(--border);
  padding: 4px 8px; white-space: nowrap;
  user-select: text;
  -webkit-user-select: text;
}
table:not(#grid) th { position: sticky; top: 0; background: var(--head); height: 26px; }
tr.selected,
tr.selected:hover { background: var(--select); }
tr:hover { background: var(--hover); }
.hint, .muted { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.error { color: var(--expense); }
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; }
.login-card { width: 420px; padding: 28px; display: flex; flex-direction: column; gap: 8px; }
.login-card h1 { font-size: 22px; }
.login-card label, .field { font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.dialog {
  width: 480px;
  max-width: calc(100vw - 48px);
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dialog h2 { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.25);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal[hidden],
.toast[hidden] { display: none !important; }
.toast {
  position: fixed; right: 24px; bottom: 24px; background: var(--text); color: #fff;
  padding: 12px 16px; border-radius: var(--radius); white-space: pre-wrap; max-width: 420px; z-index: 20;
}
.mode-row { display: flex; gap: 8px; margin-bottom: 10px; flex-shrink: 0; }
.tree-scroll { overflow: auto; min-height: 0; }
.block { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); margin-bottom: 8px; }
.block.alt { background: #f5f5f5; }
.block-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; cursor: pointer; }
.block-head .name { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; gap: 8px; flex-shrink: 0; }
.chip { border: 1px solid var(--border); border-radius: var(--radius); background: #fafafa; padding: 6px 12px; text-align: right; min-width: 140px; }
.chip span { display: block; font-size: 12px; color: var(--muted); }
.block-body { padding: 0 10px 12px 18px; }
.dir-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
.item { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.item.cat { font-weight: 700; }
.item.art { padding-left: 28px; }
.filter-pop {
  position: fixed; z-index: 15; background: #fff; border: 1px solid var(--border);
  min-width: 260px; max-height: 340px; display: flex; flex-direction: column;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden;
}
.filter-pop > input { margin: 8px; height: 32px; min-height: 32px; flex: 0 0 auto; }
.filter-pop .list { overflow: auto; flex: 1; min-height: 0; padding: 2px 0; }
.filter-pop .list::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
.filter-pop label { display: flex; gap: 8px; align-items: center; padding: 4px 10px; min-height: 26px; font-size: 12px; min-width: 0; }
.filter-pop .reset {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  min-height: 40px;
  margin: 8px;
  width: calc(100% - 16px);
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafafa;
  color: var(--text);
  font: 13px/40px "Segoe UI", sans-serif;
  padding: 0 16px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filter-pop .reset:hover { background: #f0f0f0; color: var(--text); }
th .arr {
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  vertical-align: middle;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 7px solid #555;
}
th.on .arr { border-top-color: var(--text); }
.section-title { font-size: 14px; margin: 18px 0 6px; font-weight: 700; }
.logins-wrap { max-height: 420px; }
.topbar { display: none; }
.nav-backdrop { display: none; }
.menu-btn { display: none; }

@media (max-width: 920px) {
  .topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -12px -12px 12px;
    padding: 8px 12px;
    background: var(--bg);
    border-bottom: 1px solid #c8c8c8;
    position: sticky;
    top: 0;
    z-index: 20;
    flex-shrink: 0;
  }
  .topbar-title { font-weight: 700; font-size: 16px; }
  .menu-btn { display: inline-flex; }
  .sidebar {
    transform: translateX(-100%);
    z-index: 45;
    transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: none; }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.25);
    z-index: 40;
  }
  .nav-backdrop[hidden] { display: none !important; }
  .content { margin-left: 0; padding: 12px; }
  .head { flex-wrap: wrap; gap: 8px; }
  .metrics { grid-template-columns: 1fr; }
  .metric { padding: 10px 12px; }
  .metric strong { font-size: 16px; overflow-wrap: anywhere; }
  .filters { align-items: end; }
  .filters label { flex: 1 1 calc(50% - 8px); min-width: 140px; }
  .filters label.grow { flex: 1 1 100%; }
  .filters label:has(#project-filter),
  .filters label:has(#bank) {
    flex: 1 1 calc(50% - 8px);
    width: auto;
    min-width: 140px;
    max-width: none;
  }
  .filters input[type="date"] { width: 100%; min-width: 0; }
  .filters .btn { flex: 0 0 auto; height: 40px; min-height: 40px; align-self: end; }
  .page-fill .hint { display: none; }
  .dir-grid { grid-template-columns: 1fr; }
  .login-card { width: calc(100% - 32px); max-width: 420px; }
  .login-wrap { padding: 16px; }
  .toast { right: 12px; left: 12px; bottom: 12px; max-width: none; }
  .dialog { width: calc(100vw - 24px); padding: 20px 16px; }
  .filter-pop { max-width: calc(100vw - 16px); }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  table:not(#grid) { min-width: 640px; }
  .sidebar { box-shadow: 8px 0 24px rgba(0,0,0,.12); }
}
