:root {
  --accent: #5b5fef;
  --accent-light: #eef0ff;
  --bg: #f5f6fa;
  --text: #1c1f2e;
  --text-muted: #6b7280;
  --border: #e7e8f0;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 12px;
  --ctl-h: 34px;          /* единая высота всех интерактивных контролов */
  --ctl-h-sm: 30px;       /* компактные контролы внутри строк таблицы */
}
* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  font-family: "Inter", -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- иконки ---------- */
.icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 15px; height: 15px; }

/* ---------- каркас ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 228px;
  flex-shrink: 0;
  background: white;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { font-weight: 700; font-size: 16px; padding: 6px 12px 16px; color: var(--text); }
.sidebar nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.nav-group-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #9aa1ae;
  font-weight: 700;
  padding: 14px 12px 5px;
}
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
  transition: background .12s, color .12s;
}
.sidebar nav a:hover { background: var(--accent-light); color: var(--accent); }
.sidebar nav a.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.sidebar .logout {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-muted); text-decoration: none; font-size: 13px;
  padding: 9px 12px; border-radius: 8px; margin-top: 8px;
}
.sidebar .logout:hover { background: #fdecec; color: var(--red); }

.content { flex: 1; min-width: 0; padding: 26px 30px; max-width: 1180px; }
.content.guest { max-width: none; display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 0; }

h1 { font-size: 21px; font-weight: 700; margin: 0 0 18px; display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
h2 { font-size: 15px; font-weight: 600; margin: 26px 0 10px; color: var(--text); display: flex; align-items: center; gap: 8px; }

/* ---------- таблицы ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  margin-bottom: 16px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  border: 1px solid var(--border);
}
th, td {
  text-align: center;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  white-space: nowrap;
  vertical-align: middle;
  height: 44px;
}
th {
  color: var(--text-muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.03em; background: #fafafe;
  height: 38px;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover > td, table tr:hover > td { background: #fbfbff; }
.clickable-row { cursor: pointer; }
.clickable-row:hover > td { background: var(--accent-light); }

/* длинные названия переносим, цифры — никогда */
td.cell-name, th.cell-name { white-space: normal; min-width: 150px; max-width: 320px; line-height: 1.35; }

.table-wrap {
  max-height: 72vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  margin-bottom: 16px;
  background: white;
}
.table-wrap table { border: none; box-shadow: none; border-radius: 0; margin-bottom: 0; }
.table-wrap th { position: sticky; top: 0; z-index: 2; }

/* ---------- ссылки-провалы: без подчёркивания, с подсветкой ---------- */
a { color: var(--accent); }
td a, th a {
  text-decoration: none;
  color: inherit;
  display: inline-block;
  padding: 3px 7px;
  margin: -3px -7px;
  border-radius: 7px;
  transition: background .12s, color .12s;
}
td a:hover, th a:hover { background: var(--accent-light); color: var(--accent); }
.hint a, p a { text-decoration: none; border-radius: 6px; padding: 1px 4px; margin: 0 -4px; }
.hint a:hover, p a:hover { background: var(--accent-light); }

.amount-pos { color: var(--green); font-weight: 600; }
.amount-neg { color: var(--red); font-weight: 600; }
.pnl-subtotal td { background: #f7f8ff; font-weight: 600; }
.pnl-sub td:first-child { padding-left: 34px; }

/* ---------- карточки ---------- */
.cards { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.card {
  background: white;
  border-radius: var(--radius);
  padding: 16px 18px;
  flex: 1 1 200px;
  min-width: 0;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.card-label {
  font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px;
  display: flex; align-items: center; gap: 6px; line-height: 1.3;
}
.card-value { font-size: 23px; font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }

.two-col { display: flex; gap: 20px; flex-wrap: wrap; }
.two-col > div { flex: 1 1 320px; min-width: 0; }

.chart-box {
  background: white;
  border-radius: var(--radius);
  padding: 16px 18px 10px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  margin-bottom: 16px;
  min-width: 0;
}
.chart-box h2 { margin-top: 0; }

/* ---------- переключатель периода ---------- */
.period-switcher {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px; margin-bottom: 18px;
}
.period-types { display: flex; gap: 2px; background: white; border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.period-types a {
  display: inline-flex; align-items: center; height: calc(var(--ctl-h) - 8px);
  padding: 0 12px; border-radius: 6px; text-decoration: none;
  color: var(--text-muted); font-size: 13px; font-weight: 500; transition: background .12s, color .12s;
}
.period-types a:hover { background: var(--accent-light); color: var(--accent); }
.period-types a.active { background: var(--accent); color: white; }
.period-nav { display: flex; align-items: center; gap: 8px; }
.period-arrow {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--ctl-h); height: var(--ctl-h);
  text-decoration: none; color: var(--text-muted);
  background: white; border: 1px solid var(--border); border-radius: 8px;
  transition: background .12s, color .12s;
}
.period-arrow:hover { background: var(--accent-light); color: var(--accent); }
.period-label { font-weight: 600; font-size: 14px; min-width: 130px; text-align: center; }
.period-today {
  display: inline-flex; align-items: center; height: var(--ctl-h); padding: 0 12px;
  font-size: 12.5px; color: var(--accent); text-decoration: none;
  border: 1px solid var(--accent); border-radius: 8px;
}
.period-today:hover { background: var(--accent-light); }

/* ---------- бейджи ---------- */
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.status-badge.good { background: #e7f7ea; color: var(--green); }
.status-badge.bad { background: #fdecec; color: var(--red); }
a .status-badge { cursor: pointer; }
a:hover .status-badge.bad { background: #fbdada; }

.plan-bar { display: inline-block; width: 72px; height: 6px; background: var(--border); border-radius: 999px; vertical-align: middle; margin-right: 8px; overflow: hidden; }
.plan-bar-fill { height: 100%; border-radius: 999px; }
.plan-bar-fill.good { background: var(--green); }
.plan-bar-fill.bad { background: var(--red); }

.type-badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.type-badge.income { background: #e7f7ea; color: var(--green); }
.type-badge.expense { background: #fdecec; color: var(--red); }
.type-badge.accrual { background: var(--accent-light); color: var(--accent); }

.pnl-revenue { color: var(--green); font-weight: 500; }
.pnl-cost { color: var(--red); font-weight: 500; }
.pnl-other { color: var(--text-muted); }

/* ---------- формы и кнопки ---------- */
.form {
  display: flex; flex-direction: column; gap: 4px;
  background: white; padding: 20px; border-radius: var(--radius);
  max-width: 520px; width: 100%;
  border: 1px solid var(--border); box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}
.form label { font-size: 12.5px; color: var(--text-muted); margin-top: 10px; font-weight: 500; }
.form input, .form select, .form textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fcfcfe;
  max-width: 100%;
}
/* одинаковая высота у всех однострочных контролов — чтобы соседние поля и кнопки были вровень */
.form input:not([type="file"]), .form select { height: var(--ctl-h); padding: 0 10px; }
.form input[type="file"] { padding: 7px 10px; }
.form textarea { min-height: 70px; padding: 8px 10px; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }

button, .button, .form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: var(--ctl-h);
  padding: 0 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1;
  white-space: nowrap;
  transition: filter .12s;
}
.form button { margin-top: 16px; align-self: flex-start; }
button:hover, .button:hover { filter: brightness(1.08); }

.button-secondary, button.secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}
.button-secondary:hover, button.secondary:hover { background: var(--accent-light); color: var(--accent); border-color: var(--accent); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }

.inline-form { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.inline-form select, .inline-form input {
  height: var(--ctl-h);
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13.5px;
  background: white;
  max-width: 100%;
}
.inline-form button { height: var(--ctl-h); flex-shrink: 0; }
.inline-form.compact { flex-wrap: nowrap; justify-content: center; gap: 4px; }
.inline-form.compact input { width: 90px; height: var(--ctl-h-sm); padding: 0 8px; text-align: right; }
.inline-form.compact button { height: var(--ctl-h-sm); padding: 0 9px; }

.edit-link {
  color: var(--accent); text-decoration: none; font-weight: 500; font-size: 13px;
  padding: 3px 7px; border-radius: 7px;
}
.edit-link:hover { background: var(--accent-light); }

.row-actions { display: flex; gap: 4px; justify-content: center; align-items: center; }
.row-actions a, .row-actions button {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--ctl-h-sm); height: var(--ctl-h-sm);
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--text-muted); text-decoration: none; border-radius: 7px;
  transition: background .12s, color .12s;
}
.row-actions a:hover { background: var(--accent-light); color: var(--accent); }
.row-actions button:hover { background: #fdecec; color: var(--red); }

.link-danger {
  background: none; border: none; color: var(--red); font-size: 13px; font-weight: 500;
  cursor: pointer; height: auto; padding: 3px 7px; border-radius: 7px;
}
.link-danger:hover { background: #fdecec; filter: none; }

.login-box {
  width: 340px; max-width: calc(100vw - 32px);
  background: white; padding: 30px 26px; border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(16, 24, 40, 0.06);
}
.login-box h1 { justify-content: center; }
.login-box form { display: flex; flex-direction: column; gap: 10px; }
.login-box input { height: var(--ctl-h); padding: 0 12px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 14px; }
.login-box button { width: 100%; height: 40px; }

.error { color: var(--red); font-size: 13.5px; }
.hint { color: var(--text-muted); font-size: 13px; line-height: 1.5; }
.inn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.inn-row input { flex: 1 1 160px; min-width: 0; }
.inn-row button { margin-top: 0; }
.flash {
  display: flex; align-items: center; gap: 8px;
  background: #fff8e1; border: 1px solid #fde68a; color: #7c5e10;
  padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13.5px;
}

/* ---------- адаптив ---------- */
@media (max-width: 960px) {
  .content { padding: 20px 18px; }
}

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; align-items: center; gap: 4px;
    overflow-x: auto; overflow-y: visible; padding: 8px 10px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar .brand, .nav-group-title { display: none; }
  .sidebar nav { flex-direction: row; gap: 2px; }
  .sidebar nav a { padding: 8px 10px; font-size: 13px; }
  .sidebar .logout { margin: 0 0 0 auto; }
  .content { padding: 16px 14px; }

  h1 { font-size: 19px; }
  /* две карточки в ряд — иначе дашборд превращается в бесконечную ленту */
  .cards { gap: 10px; }
  .card { flex: 1 1 calc(50% - 5px); min-width: 140px; padding: 12px 14px; }
  .card-label { font-size: 11.5px; }
  .card-value { font-size: 17px; }

  /* таблицы не выезжают за экран — прокручиваются внутри себя */
  table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap { max-height: none; }
  th, td { padding: 8px 10px; font-size: 13px; }
  td.cell-name, th.cell-name { min-width: 130px; }

  .period-switcher { gap: 8px; }
  .period-label { min-width: 0; flex: 1; }
  .form { padding: 16px; }
}
