/* Қаржы журналы (fin-journal.js): листы таблицы директора. Сетка как в Excel —
   тонкие линии, итоги сверху, шапка и левые колонки стоят на месте при прокрутке;
   вокруг — язык страницы «Қаржы»: бумага, волосяные рамки, цвет только сигналом. */
.fj {
  --j-ink: #0e1311;
  --j-2: #59625e;
  --j-3: #8b9490;
  --j-line: rgba(14, 19, 17, .09);
  --j-cell: #e4e5e1;
  --j-low: #c03a2b;
  --j-due: #8a5a00;
  --j-good: #1f6f48;
  /* кіріс — зелёный, шығын — красноватый: только подложка шапки, итог и ненулевые суммы */
  --j-in: #1f6f48; --j-in-bg: #eaf5ee; --j-in-line: #cde5d6;
  --j-out: #a33a2c; --j-out-bg: #fbeeeb; --j-out-line: #f0d3cd;
  color: var(--j-ink);
  min-width: 0;
  max-width: 100%;
}
body:has(.fj) .content { background: #f3f3f0; min-width: 0; }

.fj-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 6px 2px 12px; }
.fj-head h1 { margin: 0; font-size: 32px; line-height: 1.1; font-weight: 750; letter-spacing: -.025em; }
.fj-head p { margin: 4px 0 0; font-size: 15px; color: var(--j-2); }
.fj-ctl { display: flex; flex-wrap: wrap; gap: 8px; }
.fj-ctl select, .fj-open input {
  font: inherit; font-size: 15px; color: var(--j-ink); background: #fff;
  border: 1px solid var(--j-line); border-radius: 12px; padding: 8px 12px; min-width: 0;
}
.fj-ctl select { font-weight: 600; }
.fj-btn {
  font: inherit; font-size: 14px; font-weight: 650; color: var(--j-ink); background: #fff;
  border: 0; box-shadow: 0 0 0 1px var(--j-line); border-radius: 12px; padding: 8px 14px; cursor: pointer;
}
.fj-btn:disabled { opacity: .5; }
.fj-quiet { color: var(--j-2); font-weight: 600; }

/* Ярлыки листов — как внизу книги Excel, только сверху. */
.fj-sheets { display: flex; gap: 2px; border-bottom: 1px solid var(--j-cell); margin-bottom: 10px; overflow-x: auto; }
.fj-sheet {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--j-2); background: transparent;
  border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; padding: 8px 18px; cursor: pointer; white-space: nowrap;
}
.fj-sheet[aria-selected="true"] { background: #fff; color: var(--j-ink); border-color: var(--j-cell); box-shadow: inset 0 2px 0 var(--j-ink); margin-bottom: -1px; }

.fj-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 10px; }
.fj-bar.is-card .fj-months { visibility: hidden; }
.fj-bar.is-report .fj-cash { display: none; }   /* на «Есеп» деньги — главной полосой внизу */
.fj-months { display: flex; gap: 2px; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.fj-months button {
  font: inherit; font-size: 13px; font-weight: 600; color: var(--j-2); background: transparent;
  border: 0; border-radius: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap;
}
.fj-months button[aria-pressed="true"] { background: var(--j-ink); color: #fff; }
.fj-cash { display: flex; gap: 16px; font-size: 13px; color: var(--j-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fj-cash b { color: var(--j-ink); font-weight: 700; margin-left: 4px; }

.fj-low { color: var(--j-low) !important; }
.fj-due { color: var(--j-due); }
.fj-empty { background: #fff; border-radius: 16px; padding: 32px 20px; text-align: center; color: var(--j-2); box-shadow: 0 0 0 1px var(--j-line); }
.fj-hint { margin: 8px 2px 0; font-size: 12px; color: var(--j-3); }

/* ── сетка листа ── */
.fj-wrap {
  background: #fff; border-radius: 12px; box-shadow: 0 0 0 1px var(--j-line);
  overflow: auto; max-height: calc(100vh - 250px); min-height: 280px;
}
.fj-grid { border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; min-width: 100%; }
.fj-grid th, .fj-grid td {
  border-right: 1px solid var(--j-cell); border-bottom: 1px solid var(--j-cell);
  padding: 0 6px; height: 28px; box-sizing: border-box; background: #fff; white-space: nowrap;
}
.fj-grid input {
  width: 100%; height: 27px; box-sizing: border-box; border: 0; margin: 0; padding: 0;
  font: inherit; color: inherit; background: transparent; border-radius: 0; outline: 0;
}
.fj-grid input:focus { box-shadow: inset 0 0 0 2px var(--j-ink); background: #fff; }
.fj-grid input.bad { box-shadow: inset 0 0 0 2px var(--j-low); background: #fdf0ee; }
.fj-grid input::placeholder { color: #b9beba; }
.fj-grid td:has(input) { padding: 0; }
.fj-grid td:has(input) input { padding: 0 6px; }

.c-n { width: 40px; min-width: 40px; text-align: center; color: var(--j-3); font-size: 12px; }
.c-d { width: 78px; min-width: 78px; }
.c-m { width: 40px; min-width: 40px; text-align: center; }
.c-m input { text-align: center; }
.c-t { width: 170px; min-width: 170px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
.c-p { width: 40px; min-width: 40px; text-align: center; }
.c-p input { text-align: center; text-transform: uppercase; }
.c-k { width: 56px; min-width: 56px; text-align: center; }
.c-k input { text-align: center; }
.c-s { width: 112px; min-width: 112px; text-align: right; font-weight: 650; }
.c-s input { text-align: right; font-weight: 650; }
.c-a { min-width: 104px; max-width: 132px; text-align: right; }
td.c-a { color: var(--j-2); }

/* «Статья ДДС» с подсказкой, чей это №. */
.c-t { position: relative; }
.c-t small { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--j-3); pointer-events: none; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.c-t small:empty { display: none; }
.c-t:has(small:not(:empty)) input { padding-right: 45%; }

/* Итоги и шапка стоят на месте. */
.fj-grid thead th { position: sticky; z-index: 2; background: #fafaf8; font-weight: 600; }
.fj-tot th { height: 26px; top: 0; text-align: right; }
.fj-tot.t-n th { top: 26px; }
.fj-tot.t-b th { top: 52px; }
.fj-tot th.c-box { top: 0; height: 78px; padding: 4px 8px; text-align: left; vertical-align: middle; background: #fafaf8; }
.fj-totbox {
  display: inline-grid; grid-template-columns: auto auto; column-gap: 24px; align-items: center;
  border: 1px solid var(--j-cell); border-radius: 8px; background: #fff; padding: 2px 12px;
}
.fj-totbox > div { display: contents; }
.fj-totbox span, .fj-totbox b { line-height: 20px; }
.fj-totbox b { text-align: right; font-variant-numeric: tabular-nums; }
.fj-totbox .t-all span, .fj-totbox .t-all b { font-weight: 750; color: var(--j-ink); }
.fj-totbox .t-n span, .fj-totbox .t-b span, .fj-totbox .t-n b, .fj-totbox .t-b b { font-weight: 550; color: var(--j-2); }
.fj-grid[data-kind="in"] .fj-totbox { background: var(--j-in-bg); border-color: var(--j-in-line); }
.fj-grid[data-kind="out"] .fj-totbox { background: var(--j-out-bg); border-color: var(--j-out-line); }
.fj-grid[data-kind="in"] .fj-totbox .t-all :is(span, b) { color: var(--j-in); }
.fj-grid[data-kind="out"] .fj-totbox .t-all :is(span, b) { color: var(--j-out); }
.fj-tot.t-all th { font-weight: 750; color: var(--j-ink); }
.fj-tot.t-n th, .fj-tot.t-b th { font-weight: 550; color: var(--j-2); }
.fj-hd th { top: 78px; height: 48px; font-size: 11px; line-height: 1.2; color: var(--j-ink); white-space: normal; text-align: center; vertical-align: middle; background: #f0f1ed; }
.fj-hd th.c-a { font-weight: 600; }
.fj-codes th { top: 126px; height: 22px; font-size: 11px; color: var(--j-3); text-align: center; font-weight: 550; }

.fj-grid tbody tr:hover td { background: #fafaf7; }
.fj-grid tbody tr:hover td:has(input:focus) { background: #fff; }
.fj-auto td { color: var(--j-2); background: #fafaf8; }
.fj-done td.c-d, .fj-done td.c-t { padding: 0 6px; }
.fj-new td { background: #fcfcfa; }
.fj-new .c-n { font-size: 15px; }
.fj-out td { opacity: .5; }

/* На широком экране левые колонки не уезжают, как закреплённые в Excel. */
@media (min-width: 1100px) {
  .fj-grid[data-kind] .c-n, .fj-grid[data-kind] .c-d, .fj-grid[data-kind] .c-m, .fj-grid[data-kind] .c-t,
  .fj-grid[data-kind] .c-p, .fj-grid[data-kind] .c-k, .fj-grid[data-kind] .c-s { position: sticky; z-index: 1; }
  .fj-grid[data-kind] .c-n { left: 0; }
  .fj-grid[data-kind] .c-d { left: 40px; }
  .fj-grid[data-kind] .c-m { left: 118px; }
  .fj-grid[data-kind] .c-t { left: 158px; }
  .fj-grid[data-kind] .c-p { left: 328px; }
  .fj-grid[data-kind] .c-k { left: 368px; }
  .fj-grid[data-kind] .c-s { left: 424px; box-shadow: 1px 0 0 var(--j-ink); }
  .fj-grid[data-kind] .c-box { position: sticky; left: 0; z-index: 4; box-shadow: 1px 0 0 var(--j-ink); }
  .fj-grid[data-kind] thead th:is(.c-n, .c-d, .c-m, .c-t, .c-p, .c-k, .c-s) { z-index: 3; }
}

/* ── «Отчет» ── один экран, как лист Excel: доходы и касса | расходы | расходы. */
.fj-report { display: grid; grid-template-columns: minmax(270px, 320px) minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: start; }
.fj-rep-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.fj-rep { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; background: #fff; border-radius: 12px; box-shadow: 0 0 0 1px var(--j-line); overflow: hidden; font-size: 13px; font-variant-numeric: tabular-nums; }
.fj-rep th, .fj-rep td { border-bottom: 1px solid var(--j-cell); padding: 0 8px; height: 24px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fj-rep tbody tr:last-child td { border-bottom: 0; }
.fj-rep thead th { background: #f0f1ed; font-size: 11px; font-weight: 700; height: 26px; }
.fj-rep .r-k { width: 40px; color: var(--j-3); padding-right: 0; }
.fj-rep .r-s { width: 124px; text-align: right; font-weight: 650; }
.fj-rep .r-note { width: 24%; color: var(--j-2); border-left: 1px solid var(--j-cell); }
.fj-rep .is-zero .r-s { color: #c3c7c4; font-weight: 500; }
.fj-rep td:has(input) { padding: 0; }
.fj-rep td.r-k:has(input) { padding: 0; }
.fj-rep input { width: 100%; height: 23px; box-sizing: border-box; border: 0; padding: 0 8px; font: inherit; color: inherit; background: transparent; outline: 0; text-overflow: ellipsis; }
.fj-rep input:focus { box-shadow: inset 0 0 0 2px var(--j-ink); background: #fff; }
.fj-rep input.ok { box-shadow: inset 0 0 0 2px var(--j-good); }
.fj-rep input::placeholder { color: #b9beba; }
.fj-move td { color: var(--j-3); }
.fj-rep tfoot th { height: 26px; font-weight: 750; background: #fafaf8; border-top: 1px solid var(--j-cell); border-bottom: 0; }
.fj-rep tfoot tr + tr th { border-top: 0; }
.fj-rest th, .fj-rest td { font-size: 14px; height: 30px; }
/* Главное на «Есеп»: сколько денег сейчас — ряд одинаковых мини-карточек под
   таблицами; «Бастапқы қалдық» — в правом углу. */
.fj-total { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 16px; }
.fj-mini { display: flex; flex-direction: column; width: 220px; box-sizing: border-box; padding: 8px 16px; border-radius: 12px; background: #fff; box-shadow: 0 0 0 1px var(--j-line); }
.fj-total small { font-size: 11px; font-weight: 700; letter-spacing: .04em; color: var(--j-3); }
.fj-total b { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fj-total-main b { font-weight: 780; }
.fj-total .is-neg { color: var(--j-low); }
.fj-op { font-size: 16px; color: var(--j-3); }
/* Остаток счетов по 1С — в углу карточки «Банк», размер карточек не меняет;
   красным, только когда не сходится с банком журнала. */
.fj-mini { position: relative; }
.fj-1c { position: absolute; top: 8px; right: 12px; font-size: 11px; font-style: normal; font-variant-numeric: tabular-nums; color: var(--j-3); }
.fj-1c.is-off { color: var(--j-low); }
.fj-pool { flex: 1 1 0; min-width: 0; margin: 0 0 0 6px; font-size: 12px; color: var(--j-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fj-total .fj-open-box { margin-left: auto; background: transparent; box-shadow: none; }
.fj-total .fj-open-box summary { color: var(--j-2); padding: 6px 0; }
.fj-total .fj-open-box[open] .fj-open {
  position: absolute; right: 0; bottom: calc(100% + 8px); z-index: 5; width: 300px; padding: 12px;
  background: #fff; color: var(--j-ink); border-radius: 12px; box-shadow: 0 0 0 1px var(--j-line), 0 12px 32px rgba(14, 19, 17, .18);
}
.fj-open-box { background: #fff; border-radius: 12px; box-shadow: 0 0 0 1px var(--j-line); font-size: 13px; }
.fj-open-box summary { cursor: pointer; padding: 8px 12px; color: var(--j-2); font-weight: 600; }
.fj-open { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; padding: 0 12px 12px; }
.fj-open label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--j-2); min-width: 0; }
.fj-open label:first-child { grid-column: 1 / -1; }
.fj-open input { font: inherit; font-size: 14px; color: var(--j-ink); background: #fff; border: 1px solid var(--j-line); border-radius: 8px; padding: 6px 8px; min-width: 0; text-align: right; font-variant-numeric: tabular-nums; }
.fj-open input[type="date"] { text-align: left; }
.fj-open em { font-style: normal; font-size: 12px; color: var(--j-good); align-self: center; }

/* Итог периода под доходами — своей карточкой. */
.fj-sum th, .fj-sum td { height: 28px; }
.fj-sum th { font-weight: 750; }
.fj-sum .t-in :is(th, td) { background: var(--j-in-bg); color: var(--j-in); }
.fj-sum .t-out :is(th, td) { background: var(--j-out-bg); color: var(--j-out); }
.fj-sum tr:not(:last-child) :is(th, td) { border-bottom-color: #fff; }
.fj-sum tr:last-child :is(th, td) { border-bottom: 0; }

/* Кіріс и шығын в «Есеп» различаются цветом, как заливкой в Excel. */
.fj-rep.is-in { box-shadow: 0 0 0 1px var(--j-in-line); }
.fj-rep.is-out { box-shadow: 0 0 0 1px var(--j-out-line); }
.fj-rep.is-in thead th { background: var(--j-in-bg); color: var(--j-in); }
.fj-rep.is-out thead th { background: var(--j-out-bg); color: var(--j-out); }
.fj-rep.is-in tbody tr:not(.is-zero) td.r-s { color: var(--j-in); }
.fj-rep.is-out tbody tr:not(.is-zero):not(.fj-move) td.r-s { color: var(--j-out); }
.fj-rep tfoot .t-in th { background: var(--j-in-bg); color: var(--j-in); }
.fj-rep tfoot .t-out th { background: var(--j-out-bg); color: var(--j-out); }

/* ── выделение ячеек и строка суммы ── */
.fj-grid .is-sel, .fj-rep .is-sel { background: rgba(26, 115, 232, .12) !important; box-shadow: inset 0 0 0 1px rgba(26, 115, 232, .5); }
.fj-grid .is-sel input, .fj-rep .is-sel input { background: transparent; }
/* Плюс, как в Excel, — только над колонками с суммами (их и складывает выделение); в остальных обычная стрелка, в ячейке, где печатают, — текстовый. */
.fj-grid td, .fj-grid th, .fj-rep td, .fj-rep th, .fj-grid input, .fj-rep input { cursor: default; }
:is(.fj-grid, .fj-rep) :is(.c-s, .c-a, .c-z, .r-s), :is(.fj-grid, .fj-rep) :is(.c-s, .c-a, .c-z, .r-s) input { cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15'%3E%3Cpath d='M5.5 1h4v4.5H14v4H9.5V14h-4V9.5H1v-4h4.5z' fill='white' stroke='black' stroke-width='1'/%3E%3C/svg%3E") 7 7, cell; }
.fj-grid input:focus, .fj-rep input:focus { cursor: text; }
.fj-grid button, .fj-rep button { cursor: pointer; }
body.fj-drag, body.fj-drag * { user-select: none; -webkit-user-select: none; cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15'%3E%3Cpath d='M5.5 1h4v4.5H14v4H9.5V14h-4V9.5H1v-4h4.5z' fill='white' stroke='black' stroke-width='1'/%3E%3C/svg%3E") 7 7, cell !important; }

/* Подсказка даты: набранное прозрачно, дописываемое — серым под полем. */
.fj-grid td.c-d { position: relative; }
.fj-ghost { position: absolute; inset: 0; padding: 0 6px; line-height: 27px; color: #a9afab; white-space: pre; pointer-events: none; z-index: 0; }
.fj-ghost i { font-style: normal; color: transparent; }
.fj-grid td.c-d input { position: relative; z-index: 1; background: transparent; }
.fj-grid td.c-d input:focus { background: transparent; }

/* Свой выпадающий список под ячейкой. */
.fj-pop {
  --j-ink: #0e1311; --j-2: #59625e; --j-line: rgba(14, 19, 17, .09);   /* список висит в body, вне .fj */
  position: fixed; z-index: 60; max-height: 300px; overflow: auto; padding: 4px;
  background: #fff; border-radius: 12px; box-shadow: 0 0 0 1px var(--j-line), 0 12px 32px rgba(14, 19, 17, .18);
  font-size: 13px; color: var(--j-ink); font-variant-numeric: tabular-nums;
}
.fj-pop[hidden] { display: none; }
.fj-opt { display: flex; gap: 10px; align-items: baseline; padding: 6px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.fj-opt b { min-width: 28px; font-weight: 700; }
.fj-opt span { color: var(--j-2); overflow: hidden; text-overflow: ellipsis; }
.fj-opt:hover { background: #f3f3f0; }
.fj-opt.is-on { background: var(--j-ink); color: #fff; }
.fj-opt.is-on span { color: rgba(255, 255, 255, .75); }
.fj-sel {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50;
  display: flex; align-items: center; gap: 16px; padding: 8px 8px 8px 16px; border-radius: 12px;
  background: var(--j-ink); color: rgba(255, 255, 255, .7); font-size: 13px; font-variant-numeric: tabular-nums;
  box-shadow: 0 8px 24px rgba(14, 19, 17, .25); white-space: nowrap;
}
.fj-sel[hidden] { display: none; }
.fj-sel b { color: #fff; font-weight: 700; margin-left: 4px; }
.fj-sel button { border: 0; background: rgba(255, 255, 255, .12); color: #fff; width: 26px; height: 26px; border-radius: 8px; font-size: 16px; cursor: pointer; }

/* ── «Штат» и карточка ── */
.fj-staff { min-width: 100%; }
.fj-staff .c-name { width: 170px; min-width: 150px; }
.fj-staff .c-z, .fj-months-t .c-z { width: 120px; min-width: 104px; text-align: right; }
.fj-staff .c-z input, .fj-months-t .c-z input { text-align: right; }
.fj-staff thead th, .fj-months-t thead th { position: sticky; }
.fj-staff .fj-hd th, .fj-months-t .fj-hd th { top: 0; }
.fj-staff .fj-codes th { top: 48px; }
.fj-staff .r-s, .fj-months-t .r-s { font-weight: 650; }
.c-go { width: 40px; text-align: center; }
.c-go button { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--j-2); width: 32px; height: 26px; border-radius: 8px; cursor: pointer; }
.c-go button:hover { background: #f0f1ed; color: var(--j-ink); }
.fj-gone td { color: var(--j-3); }
.fj-gone input { text-decoration: line-through; }
.c-mon { width: 110px; font-weight: 600; }

.fj-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 10px; }
.fj-card-head h2 { margin: 0; font-size: 20px; font-weight: 720; flex: 1; min-width: 200px; }
.fj-person { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 10px; align-items: start; }
.fj-person .fj-wrap { max-height: none; min-height: 0; }
.fj-months-t tfoot th { background: #fafaf8; text-align: right; font-weight: 750; }
.fj-months-t tfoot .c-mon { text-align: left; }
.fj-side { background: #fff; border-radius: 12px; box-shadow: 0 0 0 1px var(--j-line); padding: 14px 16px; }
.fj-side dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: baseline; }
.fj-side dt { font-size: 11px; font-weight: 700; color: var(--j-2); letter-spacing: .03em; }
.fj-side dd { margin: 0; text-align: right; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fj-side h3 { margin: 16px 0 6px; font-size: 12px; font-weight: 700; color: var(--j-2); }
.fj-side ul { list-style: none; margin: 0; padding: 0; font-size: 13px; font-variant-numeric: tabular-nums; max-height: 360px; overflow: auto; }
.fj-side li { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; padding: 5px 0; border-top: 1px solid var(--j-line); }
.fj-side li span:nth-child(2) { color: var(--j-3); }
.fj-side p { margin: 0; font-size: 13px; color: var(--j-2); }

@media (max-width: 1180px) {
  .fj-report { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .fj-rep-col { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
}
@media (max-width: 900px) {
  .fj-report, .fj-person, .fj-rep-col { grid-template-columns: minmax(0, 1fr); }
  .fj-wrap { max-height: calc(100vh - 220px); }
}
@media (max-width: 720px) {
  .fj-head h1 { font-size: 24px; }
  .fj-ctl { width: 100%; }
  .fj-ctl select { flex: 1; }
  .fj-cash { width: 100%; justify-content: space-between; }
  .fj-sel { left: 16px; right: 16px; transform: none; justify-content: space-between; gap: 8px; }
}
