/* static/css/styles.css */

:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;
  --line2: #eef2f7;
  --accent: #2563eb;
  --accentSoft: rgba(37, 99, 235, 0.10);
  --hover: rgba(37, 99, 235, 0.08);
  --shadow: 0 10px 30px rgba(2, 6, 23, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 20px;
}

/* ────────────────────────────────────────────────
   Верхняя панель (bar)
───────────────────────────────────────────────── */
.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  position: relative;
  z-index: 100;
}

/* ────────────────────────────────────────────────
   Кнопки и ссылки
───────────────────────────────────────────────── */
button {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 9px 14px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

button:hover {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 0 0 4px var(--accentSoft);
  transform: translateY(-1px);
}

a {
  color: var(--accent);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 10px;
  transition: all 0.15s ease;
  display: block;
}

a:hover {
  background: var(--hover);
}

/* ────────────────────────────────────────────────
   Утилитарные классы
───────────────────────────────────────────────── */
.small {
  color: var(--muted);
  font-size: 13px;
}

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

/* ────────────────────────────────────────────────
   Статус-бар
───────────────────────────────────────────────── */
.status {
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.status.ok {
  border-color: rgba(34, 197, 94, 0.35);
  background: rgba(34, 197, 94, 0.10);
  color: #166534;
}

.status.loading {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.10);
  color: #1d4ed8;
}

.status.error {
  border-color: rgba(220, 38, 38, 0.35);
  background: rgba(220, 38, 38, 0.10);
  color: #991b1b;
}

.status .spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  display: none;
  animation: spin 0.8s linear infinite;
}

.status.loading .spinner {
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ────────────────────────────────────────────────
   Дропдаун
───────────────────────────────────────────────── */
.dropdown {
  position: relative;
  z-index: 200;
  /* выше таблицы */
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: none;
  z-index: 210;
}

.dropdown.open .dropdown-menu {
  display: block;
}

/* ────────────────────────────────────────────────
   Таблица и контейнер
───────────────────────────────────────────────── */
.table-wrap {
  height: calc(100vh - 120px);
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  border-radius: var(--radius);
  position: relative;
}

#grid {
  table-layout: fixed;
  width: 100% !important;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#grid col.col-id {
  display: none;
}

#grid th:first-child,
#grid td:first-child {
  display: none;
}

#grid th {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fbfcfe;
  color: #334155;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line2);
  white-space: normal;
  line-height: 1.2;
  text-align: center;
  vertical-align: middle;
  height: 40px;
  overflow: hidden;
}

#grid th:last-child,
#grid td:last-child {
  border-right: none;
}

#grid th .col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  z-index: 60;
}

#grid th .col-resizer:hover {
  background: rgba(37, 99, 235, 0.12);
}

#grid td {
  font-size: 13px;
  padding: 8px 10px;
  border-right: 1px solid var(--line2);
  background: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  max-width: 0;
}

/* ВАЖНО: hover строки (фон) */
#grid tbody tr:hover td {
  background: var(--hover);
}

#grid td[contenteditable="true"] {
  outline: none;
}

#grid td[contenteditable="true"]:focus {
  background: rgba(255, 235, 156, 0.35);
}

#grid td.cell-pop {
  white-space: normal !important;
  overflow: visible !important;
  position: absolute;
  z-index: 25;
  min-width: 260px;
  max-width: 900px;
  background-color: #ffffff !important;
  opacity: 1 !important;
  border: 1px solid var(--accent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}

#grid td.conflict {
  background: rgba(220, 38, 38, 0.12) !important;
}

/* ────────────────────────────────────────────────
   Индикатор страницы
───────────────────────────────────────────────── */
#pageIndicator {
  color: #334155;
  background: rgba(37, 99, 235, 0.06);
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid rgba(37, 99, 235, 0.12);
  font-weight: 500;
}

/* ────────────────────────────────────────────────
   МОДАЛЬНОЕ ОКНО ИМПОРТА
───────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  display: none;
  justify-content: center;
  align-items: center;
}

.modal-content {
  background: white;
  padding: 24px;
  border-radius: 12px;
  max-width: 700px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}

.modal-content h3 {
  margin: 0 0 16px 0;
  font-size: 1.4rem;
  color: var(--text);
}

.modal-content #importStats {
  font-family: 'Consolas', 'Courier New', monospace;
  white-space: pre;
  line-height: 1.5;
  font-size: 13px;
  color: #1e293b;
  background: #f8fafc;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.modal-footer {
  margin-top: 20px;
  text-align: right;
}

.modal-footer button {
  min-width: 100px;
}

.price-meta {
  display: flex;
  gap: 16px;
  padding: 6px 12px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.price-meta .label {
  font-weight: 600;
  color: #334155;
  margin-right: 4px;
}

.col-filter {
  font-size: 11px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  outline: none;
}

.col-filter:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accentSoft);
}

.filter-btn {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

.filter-btn.active {
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow: 0 0 0 3px var(--accentSoft);
}

.filter-pop {
  position: absolute;
  z-index: 9999;
  width: 260px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px;
}

.filter-pop .top {
  margin-bottom: 8px;
}

.filter-pop input[type="text"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  font-size: 12px;
}

.filter-pop .links {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 12px;
}

.filter-pop .list {
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line2);
  border-radius: 10px;
  padding: 6px;
}

.filter-pop .filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 2px;
  font-size: 12px;
}

.filter-pop .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 10px;
}

/* Import result rendering */
.import-stats pre {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  white-space: pre-wrap;
  /* чтобы длинные строки переносились */
  line-height: 1.5;
}

.import-backup-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 10px 0;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-weight: 600;
}

.import-backup-btn:hover {
  background: var(--hover);
}

/* ────────────────────────────────────────────────
   Ячейка, которая открывает HTML-редактор (full_desc)
   (без своей заливки, только курсор)
───────────────────────────────────────────────── */
#grid td.html-cell {
  cursor: pointer;
  background: transparent;
}

/* ────────────────────────────────────────────────
   Миниатюры в столбце "Ссылки на изображения"
   (без своих hover'ов — всё берёт общий hover)
───────────────────────────────────────────────── */
#grid td.img-cell {
  padding: 6px 8px;
  background: transparent;
  /* важно: не перекрываем hover строки */
}

#grid td .img-thumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
}

/* Обертка миниатюры + кнопки при наведении */
#grid td .img-thumb {
  position: relative;
  display: inline-flex;
}

#grid td .img-actions {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.38);
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
  /* кликаем только по кнопкам */
}

#grid td .img-thumb:hover .img-actions {
  opacity: 1;
}

#grid td .img-action-btn {
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  font-size: 12px;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

#grid td .img-action-btn:hover {
  filter: brightness(0.98);
}

#grid td .img-thumbs a {
  padding: 0 !important;
  display: inline-flex;
  border-radius: 8px;
}

#grid td .img-thumbs a:hover {
  background: transparent !important;
}

#grid td .img-thumbs img {
  width: 70px;
  height: 70px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

#grid td .img-thumbs img.broken {
  border-style: dashed;
  opacity: 0.6;
}

#grid td .img-more {
  font-size: 12px;
  color: var(--muted);
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  line-height: 1.3;
}

/* широкая модалка для HTML-редактора */
.modal-content.modal-wide {
  max-width: min(1100px, 96vw);
  width: 96vw;
  height: min(86vh, 900px);
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-head h3 {
  margin: 0;
  flex: 1;
}

.modal-head-actions {
  display: flex;
  gap: 10px;
}

.btn-primary {
  border-color: rgba(37, 99, 235, 0.45);
  background: rgba(37, 99, 235, 0.10);
}

.btn-secondary {
  background: #fff;
}

/* image links modal */
.img-tools {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0 10px;
}

#imageLinksEditor {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  font-size: 13px;
  line-height: 1.4;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

#imageLinksEditor:focus {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 3px var(--accentSoft);
}

#htmlEditorModal textarea {
  width: 100%;
  height: 100%;
}

/* TinyMCE внутри модалки занимает всё доступное место */
#htmlEditorModal .tox-tinymce {
  flex: 1;
  min-height: 0;
}

/* === FIX: вертикальный скролл для модалок === */

.modal {
  overflow-y: auto;
}

.modal-content {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

/* HTML-редактор (wide) */
.modal-content.modal-wide {
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

/* === Центрирование миниатюры в ячейке image_links === */

td.img-cell {
  text-align: center;
  /* fallback */
  vertical-align: middle;
  /* для таблицы */
}

td.img-cell .img-thumbs {
  display: flex;
  align-items: center;
  /* вертикаль */
  justify-content: center;
  /* горизонталь */
  height: 100%;
}

td.img-cell img {
  display: block;
}

/* =========================================================
   ЕДИНЫЙ HOVER НА ВСЕХ ЯЧЕЙКАХ
   - фон задаёт hover строки
   - рамка задаёт hover ячейки
   - никаких белых/частных hover'ов
========================================================= */

#grid td {
  position: relative;
}

/* рамка на ячейке */
#grid td:hover {
  background: inherit;
  /* наследует фон строки (важно!) */
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.25);
}

/* ────────────────────────────────────────────────
   Поиск по названию
───────────────────────────────────────────────── */

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box input {
  width: 260px;
  padding: 9px 34px 9px 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: all 0.15s ease;
}

.search-box input::placeholder {
  color: var(--muted);
}

.search-box input:hover {
  border-color: rgba(37, 99, 235, 0.35);
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accentSoft);
}

/* иконка лупы */
.search-icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

/* кнопка очистки */
.search-clear {
  position: absolute;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: none;
}

.search-clear:hover {
  background: var(--hover);
  color: var(--text);
}

/* показываем ✕ только когда есть текст */
.search-box input:not(:placeholder-shown)+.search-clear,
.search-box input:not(:placeholder-shown)~.search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ────────────────────────────────────────────────
   Meta pill: количество товаров
───────────────────────────────────────────────── */

.meta-pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12px;
  font-weight: 500;
  color: #334155;
  white-space: nowrap;
}




/* icon buttons */
.img-actions .img-action-btn {
  font-size: 18px;
  line-height: 1;
  padding: 6px 8px;
}