* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f4f1ec; color: #2d2a26; min-height: 100vh;
}
header {
  background: #4a3427; color: #fff; padding: 14px 24px;
  display: flex; justify-content: space-between; align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.brand { font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.user-panel { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.role-badge {
  background: #6b4f3a; padding: 3px 10px; border-radius: 20px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .5px;
}
.role-badge.admin { background: #b58a2f; }
button.ghost {
  background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff;
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
button.ghost:hover { background: rgba(255,255,255,.1); }

.container {
  max-width: 1200px; margin: 24px auto; padding: 0 20px;
  display: grid; grid-template-columns: 360px 1fr; gap: 24px;
}
@media (max-width: 900px) { .container { grid-template-columns: 1fr; } }

.card {
  background: #fff; border-radius: 14px; padding: 22px;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.card h2 {
  font-size: 15px; margin-bottom: 16px; color: #4a3427;
  border-bottom: 2px solid #eee6dc; padding-bottom: 10px;
}
label { display: block; font-size: 12px; margin-bottom: 5px; color: #6b6157; font-weight: 500; }
input, select {
  width: 100%; padding: 10px 12px; border: 1px solid #ddd3c7;
  border-radius: 8px; font-size: 14px; margin-bottom: 12px;
  font-family: inherit; background: #fdfbf9;
}
input:focus, select:focus { outline: none; border-color: #a3805f; background: #fff; }
button {
  background: #6b4f3a; color: #fff; border: none; padding: 11px 18px;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
  width: 100%; transition: background .15s;
}
button:hover { background: #553d2c; }
button.danger { background: #b04a3f; }
button.danger:hover { background: #943b31; }
button.small { width: auto; padding: 6px 12px; font-size: 12px; }

.client-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.client-item {
  border: 1px solid #ece4da; border-radius: 10px; padding: 12px 14px;
  cursor: pointer; background: #fdfbf9; transition: all .15s;
}
.client-item:hover { border-color: #c8b5a0; background: #fff; }
.client-item.active { border-color: #6b4f3a; background: #f6f0ea; box-shadow: 0 0 0 2px rgba(107,79,58,.15); }
.client-item .name { font-weight: 600; font-size: 14px; }
.client-item .meta { font-size: 12px; color: #8a8078; margin-top: 3px; }
.client-item .balance { float: right; font-weight: 700; color: #3d7a4a; font-size: 14px; }
.client-item .balance.negative { color: #b04a3f; }

.detail-header { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.detail-header h2 { border: none; padding: 0; margin: 0; font-size: 20px; }
.badge { display: inline-block; background: #eee6dc; color: #4a3427; padding: 3px 10px; border-radius: 20px; font-size: 12px; margin-right: 6px; margin-top: 4px; }
.balance-box {
  background: linear-gradient(135deg, #6b4f3a, #8a6b4f); color: #fff;
  border-radius: 12px; padding: 18px 22px; margin-bottom: 20px;
  display: flex; justify-content: space-between; align-items: center;
}
.balance-box .label { font-size: 13px; opacity: .85; }
.balance-box .amount { font-size: 28px; font-weight: 700; }
.balance-box .amount.neg { color: #ffd0cb; }

.op-form { display: grid; grid-template-columns: 1fr 1fr 2fr auto; gap: 10px; align-items: end; margin-bottom: 20px; }
@media (max-width: 700px) { .op-form { grid-template-columns: 1fr 1fr; } }
.op-form input, .op-form select { margin-bottom: 0; }
.op-form button { width: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #f0eae2; }
th { font-size: 12px; text-transform: uppercase; color: #8a8078; }
tr:hover td { background: #fdfbf9; }
.amount-plus { color: #3d7a4a; font-weight: 600; }
.amount-minus { color: #b04a3f; font-weight: 600; }
.empty { text-align: center; color: #a89e94; padding: 40px 20px; font-size: 14px; }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: #4a3427; color: #fff;
  padding: 12px 20px; border-radius: 10px; font-size: 14px; opacity: 0;
  transform: translateY(20px); transition: all .3s; pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #b04a3f; }

/* Логин */
.login-page { display: flex; align-items: center; justify-content: center; background: #4a3427; }
.login-card {
  background: #fff; padding: 36px; border-radius: 16px; width: 100%; max-width: 380px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
}
.login-card h1 { font-size: 24px; margin-bottom: 6px; color: #4a3427; text-align: center; }
.login-card .sub { text-align: center; color: #8a8078; font-size: 13px; margin-bottom: 24px; }
.login-card .err { color: #b04a3f; font-size: 13px; margin-top: 12px; text-align: center; min-height: 18px; }

/* Модалка */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: none; align-items: center; justify-content: center; z-index: 200;
}
.modal.show { display: flex; }
.modal-box { background: #fff; padding: 26px; border-radius: 14px; width: 100%; max-width: 400px; }
.modal-box h3 { margin-bottom: 16px; color: #4a3427; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions button { flex: 1; }
.modal-actions .ghost { background: #ddd3c7; color: #4a3427; border: none; }

/* Модалка статистики */
.stats-box {
  max-width: 960px;
  max-height: 90vh;
  overflow-y: auto;
  width: 100%;
}
.stats-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.stats-controls { display: flex; gap: 8px; align-items: center; }
.stats-controls select { margin: 0; width: auto; padding: 6px 10px; }
.stats-controls button { width: auto; }

/* Сводные карточки */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.stat-card {
  background: #f6f0ea;
  border-radius: 10px;
  padding: 14px 16px;
}
.stat-card .label { font-size: 12px; color: #8a8078; margin-bottom: 4px; }
.stat-card .value { font-size: 20px; font-weight: 700; color: #4a3427; }
.stat-card .value.plus { color: #3d7a4a; }
.stat-card .value.minus { color: #b04a3f; }

/* График-бары */
.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 160px;
  padding: 10px 4px;
  background: #fdfbf9;
  border-radius: 10px;
  margin-bottom: 20px;
  overflow-x: auto;
}
.chart-bar {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-width: 22px;
  height: 100%;
  position: relative;
}
.chart-bar .bar-plus {
  background: #7cb88c;
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}
.chart-bar .bar-minus {
  background: #d68a82;
  border-radius: 0 0 3px 3px;
  min-height: 2px;
  margin-top: 1px;
}
.chart-bar .bar-label {
  font-size: 9px;
  color: #8a8078;
  text-align: center;
  margin-top: 4px;
  white-space: nowrap;
}
.chart-bar:hover .bar-tip {
  opacity: 1;
}
.bar-tip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #4a3427;
  color: #fff;
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .15s;
  pointer-events: none;
  z-index: 5;
  margin-bottom: 4px;
}

/* Таблица статистики */
.stats-table { font-size: 13px; }
.stats-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table tfoot td { font-weight: 700; border-top: 2px solid #ddd3c7; }