/* Веблинк Сервис — стили интерфейса. Светлая деловая тема, системный шрифт, без внешних ресурсов. */

:root {
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #dbeafe;
  --sidebar: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #1e293b;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --zebra: #f8fafc;
  --hover: #f1f5f9;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --radius: 10px;
  --sidebar-width: 224px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.25);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 15px; }
p { margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Сайдбар ---------- */

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  /* Закреплён при прокрутке: fixed надёжнее sticky внутри flex-body в разных браузерах */
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  height: auto;
  overflow-y: auto;
  z-index: 40;
  padding: 18px 12px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
  color: #fff;
}

/* Логотип компании (public/logo.png): чёрно-синий знак на прозрачном фоне — на тёмном сайдбаре кладём его на белую плашку */
.sidebar-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #fff;
  padding: 6px;
  object-fit: contain;
  display: block;
  flex: 0 0 auto;
}

.sidebar-company {
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-weight: 500;
}
.sidebar-nav a:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.sidebar-nav a.active { background: var(--accent); color: #fff; }

.sidebar-footer { margin-top: auto; padding: 8px 4px 0; }
/* Специфичность выше, чем у .btn-ghost(:hover), иначе кнопка тусклая и при наведении получает светлую плашку */
.sidebar .btn-logout { color: var(--sidebar-text); width: 100%; text-align: left; }
.sidebar .btn-logout:hover:not(:disabled) { background: var(--sidebar-active); color: #fff; }

body.login-mode .sidebar { display: none; }

/* ---------- Контент ---------- */

.content {
  flex: 1 1 auto;
  min-width: 0;
  margin-left: var(--sidebar-width); /* место под закреплённый сайдбар */
  padding: 24px 28px 40px;
}

body.login-mode .content {
  margin-left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.section { margin-top: 20px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.text-danger { color: var(--danger); }
.text-success { color: #15803d; }
.mt { margin-top: 12px; }
/* Отрицательные суммы (убыток) — красным; минус — U+2212 */
.neg { color: var(--danger); }
.kpi-value.neg { color: var(--danger); }
/* Зелёная галочка «выплачено полностью» в блоке выплат */
.check-ok { color: var(--success); font-weight: 700; font-size: 16px; padding: 0 8px; }
/* Карточка проекта без работников: текст с кнопкой в одну строку */
.workers-none { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 4px 0; }

/* ---------- Карточки ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 16px; margin-bottom: 12px; }
.card.pad-0 { padding: 0; overflow: hidden; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* KPI-плитки */
/* Минимум 170px: на 800–1024px четыре плитки первого ряда (Поступления/Выплаты/Прибыль/План) помещаются в одну строку */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
/* Телефоны: две плитки в ряд вместо столбика из семи (на 343px получаются колонки по ~164px) */
@media (max-width: 480px) { .kpi-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }
.kpi {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 24px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-value.danger { color: var(--danger); }
.kpi-sub { color: var(--muted); font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub .up { color: #15803d; font-weight: 600; }
.kpi-sub .down { color: var(--danger); font-weight: 600; }

/* ---------- Кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 6px;
  font-size: 14px;
  line-height: 1;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  vertical-align: middle;
}
.btn-icon svg { display: block; }
.btn-icon:hover { background: var(--hover); color: var(--text); border-color: var(--border); }
.btn-icon.danger:hover { color: var(--danger); background: var(--danger-soft); }
.btn-link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-weight: 500; }
.btn-link:hover { text-decoration: underline; }
a.btn:hover { text-decoration: none; }

/* ---------- Табы, фильтры ---------- */

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .spacer { flex: 1 1 auto; }

.tabs { display: inline-flex; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 3px; gap: 2px; }
.tab {
  border: none;
  background: transparent;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent-hover); }
/* Сегментированный переключатель метрики (Поступления / Выплаты / Прибыль) — тёмный активный сегмент, чтобы отличался от табов отделов */
.segmented { background: var(--hover); }
.segmented .tab.active { background: var(--sidebar); color: #fff; }

.month-picker { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.month-picker input[type="month"] { width: 160px; }
.toolbar .year-input { width: 96px; min-width: 0; }

/* ---------- Формы ---------- */

input[type="text"], input[type="password"], input[type="number"], input[type="date"], input[type="month"], input[type="search"], select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
textarea { resize: vertical; min-height: 70px; }
input[type="color"] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; }
select { cursor: pointer; }
.toolbar input, .toolbar select { width: auto; min-width: 140px; }
/* Поле поиска шире, чтобы placeholder («Поиск по названию или клиенту») не обрезался */
.toolbar input[type="search"] { min-width: 260px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
fieldset.field { border: 0; padding: 0; margin: 0 0 12px; }
fieldset.field > legend { padding: 0; margin-bottom: 5px; }
.field > label, .field > .label { font-size: 13px; font-weight: 500; color: #334155; }
.field .hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
/* Сетка дат в форме проекта: три колонки, когда показано поле «Дедлайн» (разовый), две — когда оно скрыто */
.form-grid.dates { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
@media (max-width: 560px) { .form-grid, .form-grid.dates { grid-template-columns: 1fr; } }
.radio-group { display: flex; gap: 14px; flex-wrap: wrap; padding: 6px 0; }
.radio-group label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 400; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 4px; }
.input-row { display: flex; gap: 8px; align-items: center; }
.plan-hint { align-self: flex-start; font-size: 12px; text-align: left; }
.input-row > input, .input-row > select { flex: 1 1 auto; }
.color-row { display: flex; gap: 8px; align-items: center; }
.color-row input[type="text"] { flex: 1 1 auto; }

/* Редактор работников в форме проекта: строка = работник / условие / значение с суффиксом / ✕ */
.workers-editor [data-workers-rows] { display: flex; flex-direction: column; gap: 8px; }
.workers-editor [data-workers-rows]:not(:empty) { margin-bottom: 8px; }
.workers-editor .hint { margin-bottom: 8px; }
/* Колонки работника и условия равные: подпись «% от поступлений» должна помещаться в select целиком */
.worker-row { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.1fr) 110px auto; gap: 8px; align-items: center; }
.worker-row .value-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; }
.worker-row .value-wrap input { flex: 1 1 auto; min-width: 0; }
.worker-row .suffix { color: var(--muted); flex: 0 0 auto; font-size: 13px; }
/* Телефоны: работник и условие — на всю ширину, значение + ✕ в последней строке; строки разделены линией */
@media (max-width: 560px) {
  .worker-row { grid-template-columns: minmax(0, 1fr) auto; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
  .worker-row select[name="w_employee"], .worker-row select[name="w_type"] { grid-column: 1 / -1; }
}

/* ---------- Таблицы ---------- */

.table-scroll { overflow-x: auto; max-width: 100%; }
table.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
/* Заголовкам разрешён перенос, чтобы широкие таблицы (9 колонок) помещались на 1366px без прокрутки */
.table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; background: #fff; vertical-align: bottom; }
.table tbody tr:nth-child(even) { background: var(--zebra); }
.table tbody tr:hover { background: var(--hover); }
.table tr.row-link { cursor: pointer; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table td.num { white-space: nowrap; }
.table td.actions, .table th.actions { text-align: right; white-space: nowrap; width: 1%; }
/* Колонки по содержимому (бейджи, даты): остаток ширины отдаётся текстовым колонкам; заголовку перенос разрешён */
.table .fit { width: 1%; }
.table td.fit { white-space: nowrap; }
.table td.actions .btn-icon { margin-left: 2px; }
.table tr.group-row td { background: #f1f5f9; font-weight: 600; padding-top: 8px; padding-bottom: 8px; }
.table tr.group-row:hover td { background: #f1f5f9; }
.table tr.subtotal-row td { font-weight: 600; background: #f8fafc; border-top: 1px solid #cbd5e1; }
.table tr.total-row td { font-weight: 700; background: #eef2ff; border-top: 2px solid #94a3b8; }
/* v4: строки «Оклады — отдел» в таблице «Проекты за месяц» (tfoot перед «Итого») */
.table tr.salary-row td { background: #f8fafc; }
.table tr.salary-row td:first-child { font-style: italic; color: var(--muted); }
.table .comment-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Компактные отступы для широких таблиц (проекты: 9 колонок), чтобы помещались на 1366px без прокрутки */
.table.compact th, .table.compact td { padding-left: 8px; padding-right: 8px; }
.table.compact td.name-cell { min-width: 150px; }
.table .name-cell { font-weight: 500; }
/* v4: с колонкой «Оклад» таблица работников плотнее — уже отступы ячеек, на широких экранах имя не переносится */
#employees-table .table th, #employees-table .table td { padding-left: 10px; padding-right: 10px; }
@media (min-width: 1280px) { #employees-table td.name-cell { white-space: nowrap; } }
.table .dim { color: var(--muted); }

/* Матрица по месяцам */
.matrix-wrap { overflow: auto; max-width: 100%; max-height: calc(100vh - 220px); }
/* Ширина — по колонкам: при ≤9 месяцах таблица помещается на 1366px целиком (видна колонка «Итого»), при 12 — прокрутка */
table.matrix { min-width: 0; }
.matrix th { white-space: nowrap; }
.matrix th:first-child, .matrix td:first-child { position: sticky; left: 0; z-index: 2; background: #fff; box-shadow: inset -1px 0 0 var(--border); min-width: 200px; max-width: 240px; }
.matrix thead th { position: sticky; top: 0; z-index: 3; }
.matrix thead th:first-child { z-index: 4; }
.matrix tbody tr:nth-child(even) td:first-child { background: var(--zebra); }
.matrix tbody tr:hover td:first-child { background: var(--hover); }
.matrix tr.group-row td:first-child { background: #f1f5f9; }
.matrix tr.subtotal-row td:first-child { background: #f8fafc; }
.matrix tr.total-row td:first-child { background: #eef2ff; }
.matrix td.cur, .matrix th.cur { background: #fefce8 !important; }
.matrix th.cur { color: #b45309; }
.matrix td.zero { color: #94a3b8; text-align: right; }
/* v4: псевдострока «Оклады» в конце группы отдела и группа «Без отдела» — курсивом, приглушённо */
.matrix tr.salary-row td:first-child { font-style: italic; color: var(--muted); }
.matrix tr.group-row.unassigned td:first-child { color: var(--muted); }
.matrix td.num { min-width: 76px; }

/* ---------- Бейджи ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  background: #f1f5f9;
  color: #334155;
  line-height: 1.4;
}
.badge-status-active { background: var(--success-soft); color: #15803d; }
.badge-status-paused { background: var(--warn-soft); color: #b45309; }
.badge-status-done { background: #e2e8f0; color: #475569; }
.badge-type { background: #eef2ff; color: #4338ca; }
.badge-salary { background: #e2e8f0; color: #475569; } /* v4: выплата оклада (без проекта) */
/* v5: бейдж категории расхода — точка цвета и подложка задаются инлайн (как у отдела); бейдж шаблона регулярного расхода — серый */
.badge-cat { max-width: 220px; }
.badge-recurring { background: #e2e8f0; color: #475569; font-weight: 400; max-width: 160px; vertical-align: middle; }
/* Многоточие для длинного имени: text-overflow не действует на inline-flex контейнер — текст в отдельном flex-элементе */
.badge-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }

/* ---------- Пустые состояния, загрузка, ошибки ---------- */

.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 12px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.error-box { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; border-radius: var(--radius); padding: 14px 16px; }
.error-box .btn { margin-top: 10px; }

/* ---------- Экран входа ---------- */

.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 30px;
  box-shadow: 0 10px 40px rgba(15, 23, 42, 0.08);
  text-align: center;
}
.login-card .login-logo { width: 64px; height: 64px; object-fit: contain; display: block; margin: 0 auto 16px; }
.login-card h1 { font-size: 22px; }
.login-card .subtitle { color: var(--muted); margin: 6px 0 22px; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; margin-top: 8px; }

/* ---------- Модальные окна ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: fade-in 0.12s ease-out;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.14s ease-out;
}
.modal.modal-sm { max-width: 420px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.modal-close:hover { background: var(--hover); color: var(--text); }
/* Форма — flex-колонка с min-height: 0, иначе тело модалки не прокручивается на низких экранах */
.modal-form { display: flex; flex-direction: column; min-height: 0; }
.modal-body { padding: 16px 20px 4px; overflow-y: auto; min-height: 0; }
.modal-body p { margin: 0 0 8px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.modal-error { color: var(--danger); font-size: 13px; padding: 0 20px 6px; min-height: 0; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Тосты ---------- */

.toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 200;
  max-width: 360px;
}
.toast {
  background: var(--sidebar);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  border-left: 4px solid var(--success);
  cursor: pointer;
  animation: fade-in 0.15s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.hide { opacity: 0; transition: opacity 0.3s; }

/* ---------- Графики ---------- */

.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .axis.sel { fill: var(--accent); font-weight: 600; }
.chart .bar-label { fill: #334155; font-size: 11px; font-weight: 500; }
.chart .sel-bg { fill: var(--accent-soft); opacity: 0.5; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .bar-group:hover rect.bar { opacity: 0.85; }
.chart .bar { transition: opacity 0.1s; }
.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: #334155; margin-top: 6px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--sidebar);
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 10;
  min-width: 160px;
}
.chart-tooltip .tt-title { font-weight: 600; margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; padding: 1px 0; }
.chart-tooltip .tt-row span:first-child { display: inline-flex; align-items: center; gap: 6px; }
.chart-tooltip .tt-total { border-top: 1px solid rgba(255, 255, 255, 0.2); margin-top: 4px; padding-top: 4px; font-weight: 600; }
.mini-chart .bar { fill: var(--accent); }
.mini-chart .bar.cur { fill: #93c5fd; }
.mini-chart .bar:hover { fill: var(--accent-hover); }
/* Линия чистой прибыли: поверх столбцов, события мыши не перехватывает (tooltip и клик остаются у столбцов) */
.chart .profit-line { fill: none; stroke: #0f172a; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.chart .profit-dot { fill: #0f172a; stroke: #fff; stroke-width: 1.5; pointer-events: none; }
.chart .grid.zero { stroke: #94a3b8; }
.chart-legend .legend-line { display: inline-block; width: 16px; height: 0; border-top: 2px solid #0f172a; position: relative; }
.chart-legend .legend-line::after { content: ""; position: absolute; left: 5px; top: -4px; width: 6px; height: 6px; border-radius: 50%; background: #0f172a; }
.chart-legend.small { font-size: 12px; margin-top: 2px; }
.chart-tooltip .neg { color: #fca5a5; }
/* Две строки KPI на дашборде — ближе друг к другу, чем к следующему блоку */
.kpi-grid + .kpi-grid { margin-top: -6px; }
/* v5: «Не оплатили» и «Расходы по категориям» — две колонки на широком экране (3:2 — таблице «Не оплатили» с проектом,
   клиентом, отделом и кнопкой нужно ≈560px, компактной таблице категорий хватает меньшего), одна колонка на 1366px и уже.
   minmax(0, …): иначе таблица внутри карточки растягивает колонку шире экрана */
.dash-two { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; margin-top: 16px; align-items: start; }
.dash-two .card + .card { margin-top: 0; }
@media (max-width: 1499px) { .dash-two { grid-template-columns: minmax(0, 1fr); } }
/* v5: журнал расходов (8 колонок с двумя бейджами) — компактные отступы и короче колонка комментария, чтобы помещаться на 1366px */
#expenses-table .table th, #expenses-table .table td { padding-left: 8px; padding-right: 8px; }
#expenses-table .comment-cell { max-width: 240px; }
/* v5: выключенный шаблон регулярного расхода — приглушённо */
.table tr.inactive-row td.name-cell { color: var(--muted); }
/* v5: чекбокс «Активен» в форме регулярного расхода */
.check-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---------- Карточка проекта ---------- */

.project-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.project-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.project-head .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.project-head .client { color: var(--muted); margin-top: 4px; }
.back-link { display: inline-block; margin-bottom: 10px; color: var(--muted); }
.note-block { white-space: pre-wrap; word-break: break-word; }

/* ---------- Дедлайны (v3) ---------- */

/* Ближайшие 7 дней — оранжевый (просроченные — красный .neg) */
.deadline-soon { color: #b45309; }
/* Колонка «Дедлайн» в списке проектов: дата, под ней подпись .small с числом дней */
.table td.deadline-cell { white-space: nowrap; }
.table td.deadline-cell .small { line-height: 1.3; margin-top: 1px; }
/* Плитка «Дедлайн» в карточке: «Просрочен на 3 дня» не помещается в одну строку — разрешаем перенос */
.kpi-value.deadline-value { white-space: normal; overflow: visible; text-overflow: clip; }
/* Сводка над таблицей дедлайнов на дашборде */
.deadline-summary { margin: -4px 0 10px; font-size: 13px; }
.deadline-summary .neg { font-weight: 600; }
/* Ячейка «Бюджет / Получено»: на узких экранах (≤1100px) «из 900 000 ₽» может уйти на вторую строку,
   иначе таблица дедлайнов не помещается в карточку на 1024px; на 1366+ остаётся в одну строку */
@media (max-width: 1100px) { .table td.deadline-budget { white-space: normal; } }
/* Тонкий прогресс-бар «получено из бюджета» (ширину задаёт текст суммы) */
.progress { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 5px; }
.progress > span { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.progress.full > span { background: var(--success); }

/* ---------- Настройки ---------- */

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.settings-grid .card + .card { margin-top: 0; }
.card-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
/* v5: категории расходов — список строк «цвет · название · счётчик · действия», строка в режиме правки и поле добавления */
.cat-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.cat-row { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 2px 0; border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: 0; }
.cat-row .cat-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.cat-row .cat-actions { display: inline-flex; gap: 2px; flex: 0 0 auto; margin-left: auto; }
.cat-row.editing input[type="text"] { flex: 1 1 auto; min-width: 0; }
.cat-add { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cat-add input[type="text"] { flex: 1 1 auto; min-width: 0; }
.cat-add .form-error { flex: 1 1 100%; margin-top: 0; }

/* ---------- Адаптив: узкие экраны — верхняя панель ---------- */

@media (max-width: 899px) {
  body { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    height: auto;
    position: sticky;
    top: 0;
    left: auto;
    bottom: auto;
    overflow: visible;
    z-index: 50;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
  }
  .sidebar-brand { padding: 0 8px 0 0; }
  .sidebar-company { max-width: 140px; }
  /* Меню из 8 пунктов не помещается в одну строку с брендом и «Выйти» — выносим его на отдельную строку во всю ширину;
     если пункты всё равно не влезают (телефон), меню прокручивается, а правый край затеняется (класс scroll-more из app.js) */
  .sidebar { flex-wrap: wrap; row-gap: 4px; }
  .sidebar-nav { order: 3; flex: 1 1 100%; flex-direction: row; overflow-x: auto; gap: 2px; scrollbar-width: none; }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .sidebar-nav.scroll-more {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
  }
  .sidebar-nav a { padding: 7px 10px; white-space: nowrap; }
  .sidebar-footer { margin: 0 0 0 auto; padding: 0; }
  .btn-logout { width: auto; }
  .content { margin-left: 0; padding: 16px; }
  .kpi-value { font-size: 20px; }
  .modal { max-height: calc(100vh - 20px); }
  .table th, .table td { padding: 8px 10px; }
  /* Поля не мельче 16px — иначе iOS Safari зумит страницу при фокусе */
  input, select, textarea { font-size: 16px; }
  .tabs { flex-wrap: wrap; max-width: 100%; }
  /* Кнопки-иконки и мелкие кнопки крупнее — под палец */
  .btn-icon { padding: 9px 10px; }
  .btn-sm { padding: 7px 12px; }
  .modal-close { padding: 8px 10px; }
  .table td.actions .btn-icon { margin-left: 6px; }
}
