/* =========================================================================
   AR-1 · Генератор ТЗ — дизайн-система
   Один акцентный цвет (фирменный красный), нейтральная шкала на его основе,
   типографическая шкала, сетка отступов 4px, единая grid-раскладка для
   строк изделий (совпадает по колонкам с шапкой таблицы).
   ========================================================================= */

:root {
  /* --- Цвет: только бренд-красный как акцент, остальное — нейтрали --- */
  --ar-red: #b02a2a;
  --ar-red-dark: #8a2020;
  --ar-red-wash: rgba(176, 42, 42, 0.06);
  --ar-red-wash-strong: rgba(176, 42, 42, 0.12);
  --ar-red-ring: rgba(176, 42, 42, 0.35);

  --ink: #1c1c1c;
  --ink-soft: #5a5a5a;
  --ink-faint: #96938f;
  --line: #e0dedd;
  --line-soft: #ededeb;
  --bg: #faf9f7;
  --panel: #ffffff;

  /* --- Типографика: единая шкала (соотношение ≈1.2) --- */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-2xs: 11px;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-md: 16px;
  --text-lg: 19px;
  --text-xl: 23px;
  --leading-tight: 1.25;
  --leading-normal: 1.5;

  /* --- Отступы: шаг 4px --- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(20, 18, 16, 0.05);
  --shadow-md: 0 6px 20px rgba(20, 18, 16, 0.08);
  --shadow-modal: 0 24px 64px rgba(15, 13, 11, 0.28);

  /* Единая раскладка колонок карточки изделия — используется и в шапке
     таблицы, и в каждой строке, чтобы всё совпадало по вертикали. */
  --item-cols: minmax(0, 1fr) 176px 176px minmax(180px, 232px) 96px;
}

* { box-sizing: border-box; }

/* Место под вертикальный скроллбар резервируется всегда, даже когда он не
   нужен — иначе в момент, когда список изделий/блоков дорастает до высоты
   окна, появляющийся скроллбар отъедает ~15-17px и всё, что правее, дёргается
   в сторону. Один и тот же фикс закрывает это и для страницы целиком, и для
   внутренних скролл-областей (список блоков в карточке, модалка блоков). */
html { scrollbar-gutter: stable; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--ar-red-wash-strong); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-6);
  background: var(--panel);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 5;
}
/* Логотип — ссылка на главную экосистемы, но выглядит как логотип:
   без подчёркивания и синевы, с лёгкой подсветкой при наведении. */
.topbar .logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; border-radius: var(--radius-sm); transition: opacity 0.12s ease; }
.topbar .logo:hover { opacity: 0.75; }
.topbar .logo-mark { width: 34px; height: 34px; display: block; flex-shrink: 0; }
.topbar .logo-text {
  font-weight: 800;
  font-size: 21px;
  letter-spacing: 0.5px;
  color: var(--ar-red);
  line-height: 1;
}
.topbar .logo-text small {
  display: block;
  margin-top: 3px;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 1.6px;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.topbar-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-soft);
  border-left: 1px solid var(--line);
  padding-left: var(--sp-4);
  letter-spacing: 0.1px;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 268px 1fr;
  min-height: calc(100vh - 61px);
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}
.sidebar-section { display: flex; flex-direction: column; gap: var(--sp-2); }
.sidebar-section + .sidebar-section { padding-top: var(--sp-5); border-top: 1px solid var(--line-soft); }
.sidebar-title {
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-faint);
  font-weight: 700;
}

/* ---------- Формы ---------- */
select, input[type="text"], input[type="number"] {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font: inherit;
  font-size: var(--text-sm);
  background: #fff;
  color: var(--ink);
  height: 38px;
}
select { cursor: pointer; }
select:hover, input:hover { border-color: #c8c5c1; }
select:focus, input:focus {
  outline: none;
  border-color: var(--ar-red);
  box-shadow: 0 0 0 3px var(--ar-red-ring);
}
::placeholder { color: var(--ink-faint); }

/* ---------- Кнопки ---------- */
.btn-primary, .btn-secondary, .btn-link, .btn-icon {
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
  font-weight: 600;
  height: 38px;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease, opacity .12s ease;
}
.btn-primary {
  background: var(--ar-red);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--ar-red-dark); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-primary:disabled { background: var(--line); color: var(--ink-faint); cursor: not-allowed; box-shadow: none; }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: var(--bg); border-color: #cfccc8; }
.btn-link {
  background: none; color: var(--ar-red); text-align: left;
  padding: var(--sp-1) 0; font-size: var(--text-xs); font-weight: 600;
  height: auto; text-decoration: none; border-bottom: 1px solid transparent;
}
.btn-link:hover { border-bottom-color: var(--ar-red); }
.btn-icon { background: none; color: var(--ink-soft); font-size: 15px; padding: var(--sp-1) var(--sp-2); height: auto; }
.btn-icon:hover { color: var(--ar-red); }

/* ---------- Строка объекта (селект + удаление) ---------- */
.select-row { display: flex; gap: var(--sp-2); align-items: stretch; }
.select-row select { flex: 1; min-width: 0; }
.select-row .btn-icon {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  width: 38px;
  flex-shrink: 0;
}
.select-row .btn-icon:hover:not(:disabled) { border-color: var(--ar-red-ring); background: var(--ar-red-wash); }
.select-row .btn-icon:disabled { color: var(--ink-faint); cursor: not-allowed; opacity: 0.5; }

/* ---------- Список помещений ---------- */
.room-list { display: flex; flex-direction: column; gap: 2px; }
.room-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 9px 7px 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 500;
  border: 1px solid transparent;
  transition: background-color .12s ease;
}
.room-pill:hover { background: var(--bg); }
.room-pill.active {
  background: var(--ar-red-wash-strong);
  border-color: var(--ar-red-ring);
  color: var(--ar-red-dark);
  font-weight: 700;
}
.room-pill-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-delete-btn {
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--ink-faint);
  cursor: pointer;
  font-size: 12px;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity .12s ease, background-color .12s ease, color .12s ease;
}
.room-pill:hover .room-delete-btn,
.room-pill.active .room-delete-btn { opacity: 1; }
.room-delete-btn:hover { background: var(--ar-red-wash-strong); color: var(--ar-red); }

/* ---------- Контент ---------- */
.content { padding: var(--sp-6) var(--sp-8) var(--sp-10); }
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
  flex-wrap: wrap;
}
.content-header h2 {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.2px;
}

.add-item-bar {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: var(--sp-2);
}
.add-item-bar select { border-color: transparent; background: var(--bg); }
.add-item-bar input[type="text"] { width: 320px; }

/* ---------- Таблица изделий: шапка колонок + карточки ---------- */
.items-table { display: flex; flex-direction: column; }

.items-header {
  display: grid;
  grid-template-columns: var(--item-cols);
  padding: 0 1px;
  margin-bottom: var(--sp-2);
}
.items-header > div {
  font-size: var(--text-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-faint);
  padding: 0 var(--sp-3);
}
.items-header .col-qty { text-align: center; padding-left: 0; padding-right: 0; }

.items-grid { display: flex; flex-direction: column; gap: var(--sp-3); }

.item-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.3s, border-color 0.3s;
}
/* Пришли по ссылке из комплектации на конкретное изделие (см. deepLink в
   app.js) — временная подсветка, чтобы не искать нужную карточку глазами
   среди остальных в комнате. */
.item-card.deep-link-highlight {
  border-color: var(--ar-red);
  box-shadow: 0 0 0 3px var(--ar-red-ring);
}
.item-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.item-card-head .item-title-input {
  border: none;
  border-bottom: 1px solid transparent;
  background: none;
  font-weight: 700;
  font-size: var(--text-md);
  color: var(--ink);
  width: 60%;
  padding: var(--sp-1) 0;
  border-radius: 0;
  height: auto;
}
.item-card-head .item-title-input:hover { border-bottom-color: var(--line); }
.item-card-head .item-title-input:focus {
  outline: none;
  border-bottom: 1px solid var(--ar-red);
  box-shadow: none;
}
.item-card-head .item-actions { display: flex; gap: var(--sp-3); align-items: center; flex-shrink: 0; }
.item-type-badge {
  font-size: var(--text-2xs);
  font-weight: 600;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.item-card-body {
  display: grid;
  grid-template-columns: var(--item-cols);
  align-items: stretch;
  column-gap: var(--sp-4);
  background: var(--bg);
}
.item-card-body > div {
  padding: var(--sp-3) var(--sp-4);
  min-width: 0;
}
/* Текстовые/интерактивные ячейки — белые "карточки" на приглушённом фоне
   грида; у дропзоны свой фон и пунктирная рамка (см. .dropzone ниже) —
   вместе с настоящим зазором (column-gap) это и даёт чёткое разграничение
   между блоками строки, без хрупкой однопиксельной линии, которую было не
   видно и которую перебивала рамка дропзоны. */
.desc-cell, .links-cell, .qty-cell {
  background: var(--panel);
  border-radius: var(--radius-sm);
}

.desc-cell { display: flex; flex-direction: column; gap: var(--sp-2); }
.desc-cell .dims-input {
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: none;
  padding: var(--sp-1) 0;
  height: auto;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.desc-cell .dims-input:hover { border-bottom-color: #cfccc8; }
.desc-cell .dims-input:focus { outline: none; border-bottom-color: var(--ar-red); box-shadow: none; }
.desc-cell .blocks-summary {
  font-size: var(--text-xs);
  color: var(--ink-soft);
  line-height: var(--leading-normal);
  max-height: 96px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  flex: 1;
}
.desc-cell .blocks-summary > div { padding: 1px 0; }
.desc-cell .blocks-empty { color: var(--ink-faint); font-style: italic; }
.desc-cell .edit-blocks-btn { align-self: flex-start; margin-top: auto; }

.dropzone {
  /* width: 100% зафиксирован явно: без него aspect-ratio (в паре с высотой,
     растянутой align-items: stretch на высоту всей строки) сам решает,
     какой ширины должен быть блок, и на строках повыше "раздувает" дропзону
     заметно шире отведённой колонки грида — она наезжала на соседний блок
     (сетка колонок при этом оставалась верной, размер попан за ней). */
  width: 100%;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
  aspect-ratio: 4 / 3;
  min-height: 116px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  font-size: var(--text-2xs);
  color: var(--ink-faint);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg);
  transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.dropzone:hover { border-color: #cfccc8; color: var(--ink-soft); }
.dropzone.dragover { border-color: var(--ar-red); background: var(--ar-red-wash); color: var(--ar-red-dark); }
.dropzone .dz-icon { opacity: 0.55; }
.dropzone.dragover .dz-icon { opacity: 1; }
.dropzone img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.dropzone .dz-label { white-space: pre-line; line-height: var(--leading-tight); }
.dropzone .remove-img {
  position: absolute; top: 6px; right: 6px;
  background: rgba(20, 18, 16, 0.65); color: #fff; border: none;
  border-radius: 50%; width: 22px; height: 22px; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.dropzone .remove-img:hover { background: var(--ar-red); }

.links-cell { display: flex; }
.links-cell textarea {
  width: 100%;
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) 10px;
  font: inherit;
  font-size: var(--text-xs);
  line-height: var(--leading-normal);
  resize: vertical;
  background: var(--bg);
}
.links-cell textarea:focus { background: #fff; }

.qty-cell { display: flex; align-items: center; justify-content: center; }
.qty-cell input {
  width: 100%;
  text-align: center;
  padding: var(--sp-2) 4px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.delete-item-btn {
  color: var(--ink-faint);
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--text-2xs);
  font-weight: 600;
  padding: 4px 2px;
}
.delete-item-btn:hover { color: var(--ar-red); }

.empty-state {
  color: var(--ink-soft);
  font-size: var(--text-sm);
  padding: var(--sp-10) var(--sp-6);
  text-align: center;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
}

/* ---------- Модалка ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 18, 16, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(1px);
}
.modal {
  background: #fff;
  width: 580px;
  max-width: calc(100vw - 40px);
  max-height: 82vh;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-modal);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line);
}
.modal-header h3 { margin: 0; font-size: var(--text-md); font-weight: 700; }
.modal-body { padding: var(--sp-2) var(--sp-5); overflow-y: auto; scrollbar-gutter: stable; flex: 1; }
.modal-footer { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--line); text-align: right; background: var(--bg); }

/* ---------- Компактные диалоги: подтверждение / ввод названия ---------- */
.modal-sm { width: 420px; }
.modal-sm .modal-body { padding: var(--sp-4) var(--sp-5); }
.modal-footer-split { display: flex; justify-content: flex-end; gap: var(--sp-2); }
/* pre-line — чтобы переносы строк в тексте диалога сохранялись: в сообщении
   о конфликте правок (см. resolveConflict в app.js) чужое и своё значения
   стоят на отдельных строках, иначе склеиваются в кашу. */
.dialog-message { margin: 0; font-size: var(--text-sm); color: var(--ink-soft); line-height: var(--leading-normal); white-space: pre-line; }
.dialog-label { display: block; font-size: var(--text-sm); color: var(--ink-soft); margin-bottom: var(--sp-2); }
.dialog-input { width: 100%; }

.block-category-group { padding: var(--sp-3) 0; border-bottom: 1px solid var(--line-soft); }
.block-category-group:last-child { border-bottom: none; }
.block-category-title {
  font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--ink-faint); font-weight: 700; margin-bottom: var(--sp-2);
}
.block-checkbox-row {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  padding: 7px 8px; font-size: var(--text-sm); line-height: var(--leading-normal);
  border-radius: var(--radius-sm);
}
.block-checkbox-row:hover { background: var(--bg); }
.block-checkbox-row input { margin-top: 4px; accent-color: var(--ar-red); flex-shrink: 0; }
.block-checkbox-row label { cursor: pointer; }
