/* app.css — единый стиль платформы (zero-build, без внешних запросов) */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e2e5ea;
  --text: #1f2329;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --gray: #6b7280;
  --blue: #2563eb;
  --dark: #111827;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Шапка ---------- */
.topbar {
  background: var(--dark);
  color: #fff;
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 14px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; }
.brand span { color: #60a5fa; }
.main-nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav-link { color: #cbd5e1; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }

.nav-admin { position: relative; }
.nav-admin-label { color: #fbbf24; padding: 6px 10px; cursor: default; }
.nav-admin-menu {
  display: none; position: absolute; right: 0; top: 100%; background: #fff; color: var(--text);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 200px; overflow: hidden;
}
.nav-admin:hover .nav-admin-menu { display: block; }
.nav-admin-menu a { display: block; padding: 9px 14px; color: var(--text); text-decoration: none; }
.nav-admin-menu a:hover { background: #f0f2f5; }

.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }

/* Колокольчик */
.bell { position: relative; }
.bell-btn {
  position: relative; background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px;
}
.bell-icon { filter: grayscale(1) brightness(2); }
.bell-badge {
  position: absolute; top: -2px; right: -6px; background: var(--red); color: #fff;
  border-radius: 10px; font-size: 11px; padding: 1px 5px; line-height: 1.2;
}
.bell-panel {
  position: absolute; right: 0; top: 34px; width: 300px; max-width: 90vw;
  background: #fff; color: var(--text); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  z-index: 100; overflow: hidden;
}
.bell-title { padding: 10px 12px; font-weight: 600; border-bottom: 1px solid var(--border); }
.bell-item { padding: 8px 12px; border-bottom: 1px solid #f0f2f5; }
.bell-item-title { font-weight: 600; }
.bell-item-body { color: var(--muted); font-size: 13px; }
.bell-item-date { color: var(--muted); font-size: 11px; }
.bell-empty { padding: 16px; color: var(--muted); text-align: center; }

.user-chip { text-align: right; line-height: 1.2; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { display: block; color: #9ca3af; font-size: 11px; }

.logout-form { margin: 0; }

/* ---------- Контейнер ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 18px 14px 60px; }
.footer {
  max-width: 1100px; margin: 0 auto; padding: 12px 14px; color: var(--muted); font-size: 12px;
  border-top: 1px solid var(--border);
}

/* ---------- Кнопки ---------- */
.btn {
  display: inline-block; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border);
  background: #fff; color: var(--text); text-decoration: none; cursor: pointer; font-size: 14px;
  line-height: 1.3;
}
.btn:hover { background: #f0f2f5; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f0f2f5; color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-xs { padding: 2px 8px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 14px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }

/* ---------- Карточки ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card-title { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid #f0f2f5; text-align: left; vertical-align: middle; }
.table th { background: #fafafa; font-weight: 600; font-size: 12px; color: var(--muted); white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }
.clickable { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.total-row td { font-weight: 700; border-top: 2px solid var(--border); }

/* Карточки вместо таблиц на мобильных (без горизонтального скролла) */
@media (max-width: 640px) {
  .table-wrap { overflow: visible; background: transparent; border: none; }
  .table { min-width: 0; display: block; }
  .table thead { display: none; }
  .table tbody { display: block; }
  .table tr { display: block; border: 1px solid var(--border); border-radius: 8px; background: var(--card); margin-bottom: 10px; padding: 8px 10px; }
  .table td { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid #f0f2f5; text-align: right; }
  .table td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; }
  .table td.num { text-align: right; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- Бейджи ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-gray { background: #e5e7eb; color: #4b5563; }
.badge-dark { background: #1f2937; color: #fff; }

/* ---------- Формы ---------- */
.form { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-weight: 600; margin-bottom: 4px; }
.req { color: var(--red); }
input[type=text], input[type=number], input[type=date], input[type=password], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.readonly { background: #f3f4f6; color: var(--muted); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--red); }
.field-error { color: var(--red); font-size: 12px; margin-top: 3px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form { display: inline; }
.flashes { margin-bottom: 14px; }
.flash { padding: 10px 12px; border-radius: 6px; margin-bottom: 8px; }
.flash-success { background: #dcfce7; color: #15803d; }
.flash-error { background: #fee2e2; color: #b91c1c; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------- Дашборд ---------- */
.page-title { font-size: 22px; margin: 0 0 14px; }
.section-title { font-size: 16px; margin: 20px 0 8px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card {
  display: block; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; text-decoration: none; color: var(--text);
}
.stat-card:hover { border-color: var(--primary); }
.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

/* ---------- Фильтры ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters select, .filters input { width: auto; }

/* ---------- Деталь ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-status { margin-top: 6px; }
.action-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-start; }
.reject-form { display: block; width: 100%; }
.reject-form textarea { width: 100%; }
.kv td { padding: 5px 8px; vertical-align: top; }
.kv td:first-child { color: var(--muted); width: 40%; }
.big { font-size: 20px; font-weight: 700; }
.attach-list { margin: 0; padding-left: 18px; }

/* ---------- Таймлайн ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.tl-item { position: relative; padding: 0 0 16px 26px; }
.tl-item::before {
  content: ''; position: absolute; left: 8px; top: 4px; bottom: 0; width: 2px; background: var(--border);
}
.tl-item:last-child::before { display: none; }
.tl-item::after {
  content: ''; position: absolute; left: 4px; top: 6px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--gray);
}
.tl-approved::after { background: var(--green); }
.tl-rejected::after { background: var(--red); }
.tl-skipped::after { background: var(--gray); }
.tl-current::after { background: var(--blue); }
.tl-docs::after { background: var(--green); }
.tl-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tl-role { font-weight: 600; }
.tl-comment { color: var(--muted); margin-top: 4px; }

/* ---------- Админ-конструктор ---------- */
.pos-cell { text-align: center; font-variant-numeric: tabular-nums; }
.pos { font-weight: 600; }
.rule-card { position: relative; }
.rule-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.rule-name { font-weight: 700; font-size: 16px; }
.step-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.step-row select { max-width: 260px; }
.step-row input { flex: 1; }
.steps-title { font-weight: 600; margin: 10px 0 8px; }

/* ---------- Вход ---------- */
.login-body { background: linear-gradient(160deg, #0f172a, #1e293b); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-wrap { width: 100%; padding: 20px; }
.login-card { max-width: 420px; margin: 0 auto; background: #fff; border-radius: 12px; padding: 26px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.login-brand { font-size: 26px; font-weight: 700; color: var(--dark); }
.login-brand span { color: var(--primary); }
.login-sub { color: var(--muted); margin: 4px 0 18px; }
.user-option {
  display: flex; align-items: center; gap: 10px; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
}
.user-option:hover { border-color: var(--primary); }
.user-option-name { font-weight: 600; }
.user-option-meta { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ---------- Ошибки ---------- */
.err-wrap { display: flex; justify-content: center; padding-top: 60px; }
.err-card { max-width: 480px; text-align: center; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 40px; }
.err-code { font-size: 56px; font-weight: 800; color: var(--muted); }
.err-message { font-size: 18px; margin: 8px 0 12px; }

/* ---------- Разбивка/вложения ---------- */
.budget-lines { margin-bottom: 8px; }
.budget-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.budget-row select { max-width: 320px; }
.budget-row input { flex: 1; }
.attachments-list { margin-top: 8px; }
.attach-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; }
.attach-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- График «Затраты по месяцам» ---------- */
.costs-card { margin-top: 18px; }
.costs-chart { margin-top: 10px; overflow-x: auto; }
.costs-chart svg { display: block; max-width: 100%; height: auto; }

/* ---------- Автокомплит справочников (контрагент/проект) ---------- */
.autocomplete-group { position: relative; }
.autocomplete-suggestions {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 60;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 220px; overflow-y: auto;
  margin-top: 2px;
}
.autocomplete-option {
  padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #f0f2f5;
  font-size: 13px;
}
.autocomplete-option:last-child { border-bottom: none; }
.autocomplete-option:hover { background: #f0f2f5; }
.autocomplete-recent-title {
  padding: 6px 10px; font-size: 11px; font-weight: 600;
  color: #8a94a6; text-transform: uppercase; letter-spacing: .4px;
  border-bottom: 1px solid #f0f2f5; background: #fafbfc;
}

/* Блок «Новый контрагент/проект» */
.new-entity {
  margin-top: 8px; padding: 10px 12px; background: #f8fafc;
  border: 1px dashed var(--border); border-radius: 6px;
}
.new-entity-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.new-entity-input { margin-bottom: 6px; max-width: 420px; }
.new-entity-btn { margin-top: 2px; }
.new-entity-error { margin-top: 4px; }

/* Мобильная вёрстка: подсказки не разваливаются, инпуты на всю ширину */
@media (max-width: 640px) {
  .autocomplete-suggestions { max-height: 180px; }
  .new-entity-input { max-width: none; }
}
