:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e2e6ea;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --green: #059669;
  --red: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }

/* ---------- кнопки / чипы ---------- */
.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.btn:hover { background: #f1f3f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { border-color: transparent; background: transparent; }

.chip {
  background: #eef2ff;
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
}

/* ---------- вход ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.06);
}
.login-card h1 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); margin: 0; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
input, select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
input[readonly], input:disabled { background: #f8f9fa; color: var(--muted); }

.error { color: var(--red); font-size: 13px; }

/* ---------- верхняя панель ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-title { font-weight: 700; font-size: 17px; }
.project-title { color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 8px; }

/* ---------- контент ---------- */
.content { max-width: 1080px; margin: 0 auto; padding: 20px; }

.flash {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-weight: 600;
}
.flash.ok { background: #d1fae5; color: #065f46; }
.flash.err { background: #fee2e2; color: #991b1b; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

/* ---------- метаданные ---------- */
.meta summary { cursor: pointer; padding: 14px 18px; font-weight: 600; }
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  padding: 0 18px 18px;
}
.meta-grid label { font-size: 12px; }

/* ---------- разделы ---------- */
.section-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: #fafbfc;
  border-bottom: 1px solid var(--border);
}
.section-title { font-weight: 700; font-size: 15px; flex: 1; }
.section-title input { font-weight: 700; font-size: 15px; width: 100%; }
.excluded-badge {
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}

table.items { width: 100%; border-collapse: collapse; }
table.items th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.items td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.items tr:last-child td { border-bottom: none; }
td.num { text-align: right; white-space: nowrap; }
td .cell-input { width: 90px; text-align: right; }
td .cell-input.qty { width: 70px; }
.item-name { line-height: 1.35; }
.item-note { color: var(--muted); font-size: 12px; margin-top: 2px; }

.section-foot {
  display: flex;
  gap: 24px;
  padding: 12px 18px;
  background: #fafbfc;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.section-foot .lab { color: var(--muted); }
.section-foot .val { font-weight: 700; }

/* ---------- итоги ---------- */
.totals { padding: 18px; }
.totals-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.tot-col { text-align: center; }
.tot-label { color: var(--muted); font-size: 13px; }
.tot-value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.tot-col.grand .tot-value { color: var(--green); font-size: 24px; }

/* ---------- модалки ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card.wide { width: 640px; max-width: 95vw; }
.modal-card h2 { margin: 0 0 4px; font-size: 18px; }
.modal-card h3 { margin: 14px 0 6px; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.users-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.users-table th, .users-table td { padding: 7px 9px; border-bottom: 1px solid var(--border); text-align: left; }
.users-table select { width: 130px; }
.users-table input { width: 140px; }
.add-user-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- вкладки ---------- */
.tabs { display: flex; gap: 4px; }
.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.tab:hover { background: #f1f3f5; }
.tab.active { background: #eef2ff; color: var(--accent); }

/* ---------- панель проекта ---------- */
.project-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 18px;
}
.project-pick { flex: 1; max-width: 480px; }
.project-pick select { width: 100%; }

/* ---------- кнопки-иконки / опасные ---------- */
.btn.danger { border-color: #fecaca; color: var(--red); }
.btn.danger:hover { background: #fee2e2; }

.btn-icon {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  line-height: 1;
  font-size: 14px;
}
.btn-icon:hover { background: #f1f3f5; }
.btn-icon.danger { color: var(--red); border-color: #fecaca; }
.btn-icon.danger:hover { background: #fee2e2; }

/* ---------- справочник / разделы ---------- */
.sec-actions { display: flex; gap: 4px; }
.inc-label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.catalog-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
}

.section-add {
  padding: 8px 18px;
  background: #fafbfc;
  border-top: 1px solid var(--border);
}
.section-add .btn { font-weight: 600; color: var(--accent); }

/* ---------- формы модалок ---------- */
.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* ---------- добавление материала в проект (поиск + список) ---------- */
#add-item-search { width: 100%; }
.add-item-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
}
.add-item-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.add-item-row:last-child { border-bottom: none; }
.add-item-row:hover { background: #f1f3f5; }
.add-item-row.selected { background: #eef2ff; }
.air-name { flex: 1; line-height: 1.3; }
.air-unit { color: var(--muted); font-size: 12px; white-space: nowrap; }

@media (max-width: 720px) {
  .totals-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 12px; }
  .form-row { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 8px; }
}
