/* ═══════════════════════════════════════════════════
   Kassa · дашборд — стили
   ═══════════════════════════════════════════════════ */

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f5f6f8;
  color: #111827;
}

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; background: #1e3a8a; color: #fff;
}
header h1 { margin: 0; font-size: 15px; font-weight: 600; }
.who { font-size: 12.5px; opacity: .85; }
.who .src { opacity: .7; margin-left: 4px; }

/* ── Период ─────────────────────────────────────── */
.period-bar {
  background: #1e3a8a; padding: 6px 12px 8px;
  display: grid; gap: 6px;
  border-bottom: 1px solid #1e40af;
}
.period-pills {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
}
.period-pills::-webkit-scrollbar { display: none; }
.period-pills button {
  flex: 0 0 auto; background: rgba(255,255,255,.1);
  border: 0; color: #dbeafe;
  padding: 5px 11px; font: inherit; font-size: 12px;
  cursor: pointer; border-radius: 999px; white-space: nowrap;
}
.period-pills button:hover { background: rgba(255,255,255,.18); }
.period-pills button.on { background: #f5f6f8; color: #1e3a8a; font-weight: 600; }
.period-custom {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: #dbeafe;
}
.period-custom input {
  padding: 3px 7px; font: inherit; font-size: 12px;
  border: 1px solid #60a5fa; background: #fff; border-radius: 6px;
  color: #111827;
}
.period-custom .dash { opacity: .7; }
.period-custom button {
  padding: 3px 11px; font-size: 12px;
  background: #2563eb; color: #fff;
  border: 0; border-radius: 6px; cursor: pointer;
}
.period-caption { font-size: 11.5px; color: #bfdbfe; }

/* ── Вкладки ────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px; padding: 5px 10px 0;
  background: #1e3a8a; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto; background: transparent;
  border: 0; color: #bfdbfe;
  padding: 7px 13px; font: inherit; font-size: 12.5px;
  cursor: pointer; border-radius: 8px 8px 0 0; white-space: nowrap;
}
.tabs button:hover { color: #fff; }
.tabs button.on { background: #f5f6f8; color: #111827; font-weight: 600; }

main { padding: 10px; display: block; }
.tab { display: block; }
.tab[hidden] { display: none; }
.tab > * + * { margin-top: 10px; }

.row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 720px) {
  .row-4 { grid-template-columns: repeat(2, 1fr); }
  .row-2 { grid-template-columns: 1fr; }
}

/* ── KPI ────────────────────────────────────────── */
.kpi {
  background: #fff; border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.kpi label { display: block; font-size: 11.5px; color: #6b7280; margin-bottom: 3px; }
.kpi .val { font-size: 20px; font-weight: 700; }
.kpi.neg .val { color: #dc2626; }

/* ── Карточки ───────────────────────────────────── */
.card {
  background: #fff; border-radius: 10px; padding: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.card h2 { margin: 0 0 8px; font-size: 13.5px; font-weight: 600; color: #374151; }
.card h2 small { font-weight: 400; color: #6b7280; margin-left: 4px; font-size: 11.5px; }
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; gap: 8px;
}
.card-head h2 { margin: 0; }

/* ── Список подпись+значение ────────────────────── */
.lines .line {
  display: flex; justify-content: space-between;
  padding: 5px 0; border-bottom: 1px dashed #e5e7eb;
  font-size: 13px;
}
.lines .line:last-child { border-bottom: 0; }
.lines .line span { color: #4b5563; }
.line.debt b { color: #dc2626; }

/* ── Таблицы ────────────────────────────────────── */
.tbl {
  display: table;
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.tbl thead { display: table-header-group; }
.tbl tbody { display: table-row-group; }
.tbl tfoot { display: table-footer-group; }
.tbl tr { display: table-row; }
.tbl th, .tbl td {
  display: table-cell;
  padding: 5px 8px; text-align: left; font-size: 12.5px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
.tbl th {
  color: #6b7280; font-weight: 500; font-size: 11.5px;
  border-bottom: 1px solid #e5e7eb;
}
.tbl td.num, .tbl th.num { text-align: right; }
.tbl td.act { text-align: right; white-space: nowrap; }
.tbl th.act-col { width: 1px; }
.tbl tr.debt td b { color: #dc2626; }
.tbl tr.off { opacity: .5; }
.tbl tr.neg td { background: #fef2f2; }
.tbl tr.neg td:first-child { border-left: 3px solid #f87171; }
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }

/* ── Таблица статистики ─────────────────────────── */
.tbl.stats { table-layout: auto; font-size: 12px; }
.tbl.stats thead th {
  padding: 5px 6px; font-size: 11px; text-align: right; white-space: nowrap;
}
.tbl.stats thead th:first-child { text-align: left; min-width: 84px; }
.tbl.stats thead th:last-child { width: 44px; }

.tbl.stats tbody td {
  padding: 3px 6px; font-size: 12px; white-space: nowrap;
}
.tbl.stats tbody td:first-child {
  text-align: left; font-weight: 600; min-width: 84px;
}
.tbl.stats tbody td.num { text-align: right; }

.tbl.stats tfoot td {
  border-top: 2px solid #e5e7eb;
  padding: 5px 6px; font-weight: 600; background: #f9fafb;
}
.tbl.stats tfoot td.num { text-align: right; }

/* План — редактируемая ячейка */
.tbl.stats td.plan {
  cursor: pointer;
  border-bottom: 1px dashed #93c5fd;
  text-align: right;
}
.tbl.stats td.plan:hover { background: #eff6ff; }

/* Факт: для hist — редактируется, для daily — заблокирована */
.tbl.stats td.fact { text-align: right; }
.tbl.stats td.fact.editable {
  cursor: pointer;
  border-bottom: 1px dashed #a3e635;
}
.tbl.stats td.fact.editable:hover { background: #f7fee7; }
.tbl.stats td.fact.locked {
  color: #6b7280;
  background: #f9fafb;
  cursor: default;
}
.tbl.stats td.fact.locked::after {
  content: " · из дней";
  font-size: 10.5px; color: #9ca3af;
}

.tbl.stats input.inline {
  width: 100px; padding: 2px 5px; font: inherit; font-size: 12px;
  border: 1px solid #60a5fa; border-radius: 5px; text-align: right;
}

/* Отношение */
.tbl.stats td.ratio { text-align: right; font-weight: 700; min-width: 56px; }
.tbl.stats td.ratio.good { background: #dcfce7; color: #166534; }
.tbl.stats td.ratio.warn { background: #fef3c7; color: #92400e; }
.tbl.stats td.ratio.bad  { background: #fee2e2; color: #991b1b; }
.tbl.stats td.ratio.na   { color: #9ca3af; font-weight: 400; }
.tbl.stats tfoot td.ratio.good { background: #bbf7d0; }
.tbl.stats tfoot td.ratio.warn { background: #fde68a; }
.tbl.stats tfoot td.ratio.bad  { background: #fecaca; }

/* Кнопка +5% */
.tbl.stats td.auto-cell { text-align: center; padding: 2px 4px; width: 44px; }
.tbl.stats button.auto {
  padding: 2px 7px; font-size: 10.5px; border-radius: 5px;
  background: #eef2ff; color: #4338ca;
  border: 0; cursor: pointer; white-space: nowrap; line-height: 1.2;
}
.tbl.stats button.auto:hover { background: #c7d2fe; }

.stats-actions {
  display: flex; gap: 6px; align-items: center;
}
.year-select {
  padding: 3px 10px; font: inherit; font-size: 13px;
  border: 1px solid #d1d5db; border-radius: 8px; background: #fff;
  cursor: pointer;
}

/* ── Легенда графиков ───────────────────────────── */
.legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 6px 4px 0; font-size: 12px; color: #4b5563;
}
.legend .item { display: flex; align-items: center; gap: 5px; }
.legend .dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
}

/* ── Кнопки в строках ───────────────────────────── */
button.mini {
  padding: 3px 9px; font-size: 11.5px; border-radius: 6px;
  background: #eef2ff; color: #1e40af;
  border: 0; cursor: pointer; margin-left: 4px; white-space: nowrap;
}
button.mini:hover { background: #e0e7ff; }
button.mini.ghost { background: transparent; color: #9ca3af; }
button.mini.ghost:hover { background: #f3f4f6; color: #dc2626; }

.tbl td.editable { cursor: pointer; border-bottom: 1px dashed #cbd5e1; }
.tbl td.editable:hover { background: #f0f9ff; }
.tbl td.editable.ro { cursor: default; border-bottom: 1px solid #f3f4f6; }
.tbl td.editable.ro:hover { background: none; }
.tbl td.editable input.inline {
  width: 110px; padding: 2px 6px; font: inherit; font-size: 12.5px;
  border: 1px solid #93c5fd; border-radius: 5px; text-align: right;
}

/* ── Подсказки ──────────────────────────────────── */
.hint {
  font-size: 11.5px; color: #6b7280; line-height: 1.5;
  padding: 6px 10px; margin-bottom: 8px;
  background: #f9fafb; border-radius: 8px;
  border-left: 3px solid #d1d5db;
}
.hint b { color: #374151; font-weight: 600; }
.hint code {
  font: 11.5px ui-monospace, Menlo, Consolas, monospace;
  background: #e5e7eb; padding: 1px 4px; border-radius: 3px;
}

/* ── Графики ────────────────────────────────────── */
#chart { width: 100%; display: block; height: 200px; }
.chart-multi { width: 100%; display: block; height: 180px; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.charts-grid > .card:first-child { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .charts-grid { grid-template-columns: 1fr; }
  .charts-grid > .card:first-child { grid-column: auto; }
}

/* ── Подвал ─────────────────────────────────────── */
.footer {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 20px;
}
.footer button {
  padding: 7px 14px; border-radius: 8px; border: 0;
  background: #2563eb; color: #fff; font: inherit; font-size: 13px;
  cursor: pointer;
}
.footer button:hover { background: #1d4ed8; }
.footer .auto { color: #6b7280; font-size: 11.5px; }

/* ── Модалки ────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; background: rgba(17,24,39,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 100;
  overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 12px; padding: 18px;
  width: 100%; max-width: 420px; max-height: 92vh; overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,.25);
}
.modal.wide { max-width: 780px; }
.modal h3 { margin: 0 0 14px; font-size: 16px; }

.mf { display: block; margin-bottom: 10px; }
.mf > span { display: block; font-size: 12px; color: #6b7280; margin-bottom: 3px; }
.mf > small { display: block; font-size: 11px; color: #9ca3af; margin-top: 3px; }
.mf input[type="text"], .mf input[type="number"],
.mf input[type="password"], .mf input[type="tel"], .mf select {
  width: 100%; padding: 8px 10px; font: inherit; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 8px; background: #fff;
}
.mf input:focus, .mf select:focus {
  outline: none; border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.mf input[type="checkbox"] { width: 18px; height: 18px; }

.modal-err { color: #b91c1c; font-size: 12px; min-height: 16px; margin: 6px 0 2px; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.modal-btns button {
  padding: 8px 16px; border-radius: 8px; border: 0;
  font: inherit; cursor: pointer;
}
.modal-btns button.ghost { background: #f3f4f6; color: #374151; }
.modal-btns button.ghost:hover { background: #e5e7eb; }
.modal-btns button:not(.ghost) { background: #2563eb; color: #fff; }
.modal-btns button:not(.ghost):hover { background: #1d4ed8; }
.modal-btns button:disabled { opacity: .5; cursor: default; }

/* ── Модалка «Ввести данные за год» ─────────────── */
.year-form {
  display: grid;
  grid-template-columns: 84px repeat(5, 1fr);
  gap: 4px;
  align-items: center;
  font-size: 12.5px;
  overflow-x: auto;
}
.year-form .hcell {
  font-size: 11px; color: #6b7280; font-weight: 500;
  padding: 4px 6px; text-align: right;
}
.year-form .hcell:first-child { text-align: left; }
.year-form .mcell {
  padding: 4px 6px; font-weight: 600;
  font-size: 12.5px; color: #374151;
  display: flex; align-items: center; gap: 4px;
}
.year-form .mcell .src {
  font-size: 10px; color: #9ca3af; font-weight: 400;
}
.year-form input {
  width: 100%; min-width: 70px;
  padding: 4px 6px; font: inherit; font-size: 12px;
  border: 1px solid #d1d5db; border-radius: 5px; text-align: right;
}
.year-form input:focus {
  outline: none; border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37,99,235,.12);
}
.year-form input:disabled { background: #f3f4f6; color: #9ca3af; }
.year-form .sep {
  grid-column: 1 / -1; height: 1px; background: #f3f4f6;
  margin: 4px 0;
}

.year-form .year-picker {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; font-size: 13px;
}
.year-form .year-picker input {
  width: 90px; padding: 6px 8px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 8px;
}
.year-form .year-picker button {
  padding: 5px 11px; font-size: 12.5px;
  background: #eef2ff; color: #1e40af;
  border: 0; border-radius: 6px; cursor: pointer;
}

/* ── Тост ───────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 20px;
  transform: translateX(-50%);
  background: #111827; color: #fff; font-size: 12.5px;
  padding: 9px 15px; border-radius: 8px; z-index: 200;
  box-shadow: 0 8px 20px rgba(0,0,0,.25);
  animation: toast-in .18s ease-out;
}
.toast.err { background: #b91c1c; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
/* ═══════════════════════════════════════════════════
   Табель (вкладка «Табель»)
   ═══════════════════════════════════════════════════ */

#ts-root { padding: 4px 0; }

.ts-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.ts-title {
  font-weight: 600;
  font-size: 15px;
  min-width: 140px;
  text-align: center;
}
.ts-nav {
  padding: 5px 12px;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.ts-nav:hover { background: #e5e7eb; }
.ts-hint {
  font-size: 12px;
  color: #6b7280;
  margin-left: auto;
}

.ts-scroll {
  overflow-x: auto;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  -webkit-overflow-scrolling: touch;
}

.ts-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  min-width: 900px;
}
.ts-tbl th,
.ts-tbl td {
  padding: 3px 2px;
  border: 1px solid #e5e7eb;
  text-align: center;
  white-space: nowrap;
}
.ts-tbl th {
  background: #f9fafb;
  font-weight: 600;
  color: #4b5563;
  font-size: 11px;
  position: sticky;
  top: 0;
  z-index: 2;
}
.ts-tbl .ts-name {
  text-align: left;
  padding-left: 10px;
  min-width: 140px;
  font-size: 13px;
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
}
.ts-tbl .ts-total {
  position: sticky;
  right: 0;
  background: #f9fafb;
  font-weight: 600;
  padding: 3px 8px;
  z-index: 1;
}
.ts-tbl thead .ts-total { z-index: 3; }

.ts-tbl .ts-day {
  width: 30px;
  min-width: 30px;
  padding: 3px 1px;
}
.ts-tbl .ts-day.ts-weekend {
  background: #fef2f2;
  color: #b91c1c;
}
.ts-tbl .ts-day.ts-today {
  background: #dbeafe !important;
  color: #1e40af !important;
  box-shadow: inset 0 -3px 0 #2563eb;
}

.ts-tbl .ts-cell {
  cursor: pointer;
  padding: 2px 1px;
  font-size: 11px;
  color: #6b7280;
  transition: background 0.12s;
  min-width: 30px;
}
.ts-tbl .ts-cell:hover {
  background: #dbeafe !important;
  color: #1e40af;
}
.ts-tbl .ts-cell.ts-active {
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 500;
}
.ts-tbl .ts-cell.ts-active:hover {
  background: #fecaca;
}

.ts-tbl .ts-group td {
  background: #f3f4f6;
  text-align: left;
  padding: 5px 10px;
  font-weight: 600;
  font-size: 12px;
  color: #374151;
  border-top: 2px solid #d1d5db;
}

.ts-input {
  width: 36px;
  padding: 1px 2px;
  font-size: 12px;
  border: 1px solid #2563eb;
  border-radius: 3px;
  text-align: center;
  background: #fff;
}

/* На узких экранах кнопки дат — компактнее */
@media (max-width: 640px) {
  .ts-tbl { font-size: 11px; }
  .ts-tbl .ts-name { min-width: 110px; }
  .ts-tbl .ts-day { width: 26px; min-width: 26px; }
}