/* ─────────────────────────────────────────────────────────────────────────────
   factories_v2.css — JIT Order Platform v49
   Factories / "My factory" page redesign. Scope: .factories-page-v49
   Black action buttons (#1a1a1a) — no brand gold/brown anywhere. No important overrides.
   Self-hosted Tabler icons (ti ti-*). Theme variables with hex fallbacks.

   Prompt --color-* → theme token mapping:
     --color-background-primary   → var(--panel)
     --color-background-secondary → var(--section-bg)
     --color-border-tertiary/sec  → var(--line)
     --color-text-primary         → var(--text)
     --color-text-secondary       → var(--muted)
     --color-text-tertiary        → var(--muted)
   ───────────────────────────────────────────────────────────────────────────── */

.factories-page-v49 {
  --fc-panel: var(--panel, #fff);
  --fc-sec:   var(--section-bg, #faf9f6);
  --fc-line:  var(--line, #e9e7e0);
  --fc-text:  var(--text, #1a1a1a);
  --fc-muted: var(--muted, #7c7a73);
  --fc-black: #1a1a1a;
}

/* ── Legacy reset (retired v3.7) ──────────────────────────────────────────────
   The shared .jit-product-* hook classes (card/media/main-photo/thumb) used to
   get fixed grid rows + min/max-height from legacy_overrides.css globally, and
   this block neutralized them. As of v3.7 that legacy geometry is scoped to
   .catalog-page-v44, so it no longer reaches this page — the reset is gone and
   each rule below owns its own geometry. If a new legacy property ever leaks in,
   prefer scoping it in legacy_overrides.css rather than re-adding a reset here. */

/* ── Block 1: page header button ──────────────────────────────────────────── */
.factories-page-v49 .panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.factories-page-v49 .btn-black {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
  transition: background 0.15s;
}
.factories-page-v49 .btn-black:hover { background: #333; color: #fff; }

/* ── Sections: each factory is a light grouped card ───────────────────────── */
.factories-page-v49 .jit-factory-sections {
  display: block;
}
.factories-page-v49 .jit-factory-section {
  background: var(--fc-panel);
  border: 1px solid var(--fc-line);
  border-radius: 12px;
  padding: 18px 20px 20px;
  margin: 0 0 4px;
  box-shadow: none;
}
.factories-page-v49 .jit-factory-section.inactive-card { opacity: 0.55; }

/* ── Block 2: factory header ──────────────────────────────────────────────── */
.factories-page-v49 .factory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
  background: transparent;
  border: none;
  padding: 0;
}
.factories-page-v49 .factory-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--fc-text);
  margin-bottom: 4px;
}
.factories-page-v49 .factory-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--fc-muted);
  flex-wrap: wrap;
}
.factories-page-v49 .factory-comment { margin-top: 4px; }
.factories-page-v49 .factory-meta-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--fc-line);
  display: inline-block;
  flex-shrink: 0;
}
.factories-page-v49 .factory-orders-count {
  color: #3b6d11;
  font-weight: 500;
}

/* Factory action buttons */
.factories-page-v49 .factory-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.factories-page-v49 .fact-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border: 1px solid var(--fc-line);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fc-muted);
  background: var(--fc-panel);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.3;
  transition: background 0.12s, border-color 0.12s;
}
.factories-page-v49 .fact-btn:hover { background: var(--fc-sec); }
.factories-page-v49 .fact-btn .ti { font-size: 14px; }
.factories-page-v49 .fact-btn.add {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}
.factories-page-v49 .fact-btn.add:hover { background: #333; }

/* ── Block 3: products label ──────────────────────────────────────────────── */
.factories-page-v49 .products-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fc-muted);
}
.factories-page-v49 .products-count-pill {
  font-size: 11px;
  font-weight: 500;
  color: var(--fc-muted);
  letter-spacing: 0;
  text-transform: none;
  background: var(--fc-sec);
  padding: 2px 8px;
  border-radius: 100px;
  border: 1px solid var(--fc-line);
}

/* ── Block 4: products grid + cards ───────────────────────────────────────── */
/* Правка 3: gap 12px для воздуха между карточками */
.factories-page-v49 .products-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  column-gap: 20px;
  row-gap: 25px;
}

/* Правка 2: overflow: visible — тултип описания выходит за границы карточки */
.factories-page-v49 .product-card {
  background: var(--fc-panel);
  border: 1px solid var(--fc-line);
  border-radius: 12px;
  overflow: visible;       /* allows desc-tooltip to float above neighbour cards */
  position: relative;
  cursor: pointer;
  /* v3.8.67: transform — плавный подъём .jit-product-card:hover (см. theme_v2). */
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.16s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  width: auto;
  max-width: none;
  padding: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  /* v3.7: own card width/box-model/gap explicitly. These used to be inherited
     from the global legacy .jit-product-card rule (now scoped to .catalog-page-v44).
     Values reproduce the prior rendering exactly: 260px cards in the 5-col grid,
     border-box, 4px flex gap. min-width only binds at the 5-col desktop width. */
  min-width: 260px;
  box-sizing: border-box;
  gap: 4px;
}
.factories-page-v49 .product-card:hover {
  border-color: var(--fc-muted);
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
  z-index: 2;             /* lift above siblings so desc-tooltip isn't clipped */
}
.factories-page-v49 .product-card.inactive-card { opacity: 0.5; }
.factories-page-v49 .product-card.dragging { opacity: 0.4; }

/* ── Main photo — inset so the card border shows around it ──
   .main-photo-wrap also carries .jit-product-media; .main-photo also carries
   .jit-product-main-photo (JS swaps its <img>). overflow: hidden here clips
   the photo now that product-card is overflow: visible. */
.factories-page-v49 .main-photo-wrap {
  padding: 6px 6px 0;
  display: block;          /* override .jit-product-media display:grid */
  grid-template-rows: none;
  gap: 0;
  width: 100%;
  min-height: 0;
  overflow: hidden;        /* clips photo corners since card is overflow:visible */
  border-radius: 8px 8px 0 0;
}
/* Правка 1: 3:4 portrait ratio — 133% padding-top */
.factories-page-v49 .main-photo {
  position: relative;
  width: 100%;
  padding-top: 133%;
  overflow: hidden;
  border-radius: 8px;
  background: var(--fc-sec);
  height: auto;            /* override .jit-product-main-photo fixed height */
  min-height: 0;
  max-height: none;
  display: block;
}
.factories-page-v49 .main-photo img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}
.factories-page-v49 .main-photo-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--fc-muted);
}
.factories-page-v49 .main-photo-empty span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Additional photos — full 4-col square grid (these are product angles) ──
   Each cell keeps .jit-product-thumb (+data-photo) so the photo-switch JS still
   works; visually they're square photos, not color dots. */
.factories-page-v49 .sub-photos {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  padding: 6px;
  width: 100%;            /* force full card width so 1fr columns don't collapse */
  box-sizing: border-box;
}
/* Правка 3: квадрат через padding-top на ::before, radius 4px */
.factories-page-v49 .sub-photo {
  position: relative;
  overflow: hidden;
  background: var(--fc-sec);
  border-radius: 8px;
  border: none;
  margin: 0;
  padding: 0;            /* reset <button> default padding */
  cursor: pointer;
  display: block;
  width: 100%;
  min-height: 0;
  max-height: none;
}
/* 1:1 square via pseudo-element so the button has no padding conflict */
.factories-page-v49 .sub-photo::before {
  content: '';
  display: block;
  padding-top: 100%;
}
.factories-page-v49 .sub-photo.active { box-shadow: inset 0 0 0 2px var(--fc-text); }
.factories-page-v49 .sub-photo img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Правка 3: компактный блок информации */
/* fix: the card inherits align-items:center (from legacy .jit-product-card), which
   shrank .product-info/.product-footer to content width and centered them — pushing
   the text to the right. Stretch them so the text sits flush on the left. */
.factories-page-v49 .product-card { align-items: stretch; }
.factories-page-v49 .product-info {
  padding: 4px 10px 0 6px;   /* left 6px → aligned with the photo's left edge */
  flex: 1;
  text-align: left;
}
.factories-page-v49 .product-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--fc-text);
  margin-bottom: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.factories-page-v49 .product-cat {
  font-size: 10px;
  color: var(--fc-muted);
  margin-bottom: 3px;
}
.factories-page-v49 .product-price {
  font-size: 12px;
  font-weight: 500;
  color: var(--fc-text);
}

/* Правка 2: тултип описания (CSS-only hover, float above neighbours) */
.factories-page-v49 .product-desc-wrap {
  position: relative;
  display: inline-block;
  margin-top: 2px;
}
.factories-page-v49 .product-desc-link {
  font-size: 10px;
  color: var(--fc-muted);
  cursor: pointer;
  border-bottom: 1px dashed var(--fc-line);
  display: inline-block;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  padding: 0;
  text-decoration: none;
}
.factories-page-v49 .product-desc-link:hover { color: var(--fc-text); }
.factories-page-v49 .desc-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  width: 220px;
  background: var(--fc-panel);
  border: 1px solid var(--fc-line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--fc-text);
  line-height: 1.5;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}
.factories-page-v49 .product-desc-wrap:hover .desc-tooltip { display: block; }

/* Правка 3: компактный футер */
.factories-page-v49 .product-footer {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px;
  margin-top: 6px;
  border-top: 1px solid var(--fc-line);
}
.factories-page-v49 .btn-order {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  background: #1a1a1a;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  text-transform: none;
  transition: background 0.12s;
}
.factories-page-v49 .btn-order:hover { background: #333; color: #fff; }
/* Правка 3: 25×25 иконочные кнопки */
.factories-page-v49 .act-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--fc-line);
  border-radius: 8px; /* v3.8.49: канон иконочной кнопки 28/r8 */
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--fc-muted);
  font-size: 12px;
  flex-shrink: 0;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.factories-page-v49 .act-btn:hover { background: var(--fc-sec); }
.factories-page-v49 .act-btn.danger:hover {
  border-color: #f09595;
  color: #CC2200;
  background: #fcebeb;
}

/* ── Block 5: spacing between factory cards (no visible line — cards are framed) ── */
.factories-page-v49 .factory-divider {
  height: 0;
  background: transparent;
  margin: 0 0 20px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .factories-page-v49 .products-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .factories-page-v49 .products-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .factories-page-v49 .products-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .factories-page-v49 .factory-header { align-items: flex-start; }
}
