/* Catalog Modal Overrides */
#categoryModal .modal-card,
#fieldManagerModal .modal-card,
#productFormModal .modal-card {
  text-align: left;
  padding: 0;
  max-width: 500px;
  /* Default for smaller ones */
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-main);
}

#fieldManagerModal .modal-card,
#productFormModal .modal-card {
  max-width: 800px;
}

/* Field Manager Modal */
.field-manager-container {
  display: flex;
  height: 60vh;
  gap: 24px;
}

.field-list-pane {
  width: 250px;
  border-right: 1px solid #eee;
  overflow-y: auto;
  padding-right: 16px;
}

.field-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  background: #f9f9f9;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-item.add-new {
  border: 1px dashed #ccc;
  color: var(--primary-color);
  justify-content: center;
  font-weight: 600;
}

.field-item:hover,
.field-item.active {
  background: var(--primary-light);
  border-color: var(--primary-color);
}

.field-item strong {
  display: block;
  font-size: 13px;
  color: #333;
}

.field-item span {
  font-size: 11px;
  color: var(--secondary-color);
  background: #fff;
  padding: 2px 6px;
  border-radius: 4px;
}

.field-editor-pane {
  flex: 1;
  padding: 0 16px;
}

.options-editor {
  margin-top: 12px;
  padding: 12px;
  background: #fcfcfc;
  border: 1px solid #eee;
  border-radius: var(--radius-sm);
}

.option-tag {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border: 1px solid #ddd;
  padding: 4px 8px;
  border-radius: var(--radius-xl);
  font-size: 12px;
  margin: 2px;
}

.option-tag button {
  background: none;
  border: none;
  margin-left: 6px;
  color: var(--danger-color);
  cursor: pointer;
  font-weight: 700;
}

/* Product Form */
.product-form-layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 32px;
}

.pf-sidebar {
  background: #f8f9fa;
  padding: 20px;
  border-radius: var(--radius-md);
}

.pf-main {
  background: #fff;
  padding: 24px;
  border-radius: var(--radius-md);
  border: 1px solid #eee;
}

.field-select-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 8px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.field-checkbox:hover {
  border-color: var(--primary-color);
}

.dynamic-fields-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed #eee;
}

.dynamic-field-block {
  background: #fcfcfc;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #f0f0f0;
}

.tags-input-container {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border: 1px solid #ddd;
  border-radius: var(--radius-sm);
  background: #fff;
  min-height: 38px;
}

.tag-pill {
  background: var(--primary-light);
  color: var(--primary-color);
  padding: 2px 8px;
  border-radius: var(--radius-xl);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tag-input-field {
  border: none;
  outline: none;
  flex: 1;
  min-width: 60px;
  font-size: 13px;
  padding: 4px;
  background: transparent;
}

/* New Product Form Layout */
.pf-body-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  background: #fff;
}

.pf-section-main {
  flex: 1.2;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.pf-section-sidebar {
  flex: 0.8;
  background: #f8f9fa;
  border-left: 1px solid #eee;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.pf-image-area {
  width: 100%;
  height: 200px;
  background: #f4f6f8;
  border: 2px dashed #dde1e6;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-fast);
}

.pf-image-area:hover {
  background: #f0f2f5;
  border-color: var(--primary-color);
}

.pf-image-area img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 12px;
}

.pf-upload-placeholder {
  text-align: center;
  color: var(--secondary-color);
}

.pf-upload-placeholder .icon {
  font-size: 32px;
  margin-bottom: 8px;
  display: block;
}

.pf-form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pf-sidebar-header {
  padding: 20px 24px;
  border-bottom: 1px solid #eee;
  background: #fff;
}

.pf-sidebar-header h4 {
  margin: 0 0 4px 0;
  font-size: 15px;
  font-weight: 700;
  color: #333;
}

.pf-sidebar-header p {
  margin: 0;
  font-size: 12px;
  color: var(--secondary-color);
}

.pf-fields-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pf-field-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid #eee;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pf-field-item:hover {
  border-color: var(--primary-color);
  transform: translateX(2px);
}

.pf-field-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-color);
  cursor: pointer;
}

.pf-field-info strong {
  display: block;
  font-size: 13px;
  color: #333;
}

.pf-field-info span {
  font-size: 11px;
  color: var(--secondary-color);
}

.pf-sidebar-footer {
  padding: 16px;
  border-top: 1px solid #eee;
  text-align: center;
  background: #fff;
}

.small-text-btn {
  background: none;
  border: none;
  color: var(--primary-color);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.small-text-btn:hover {
  text-decoration: underline;
}

/* Gallery Popover - Centered Constrained Modal */
.pf-gallery-popover {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 700px;
  max-width: 90%;
  height: 550px;
  max-height: 90%;
  background: #fff;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  animation: fadeIn var(--transition-fast) ease-out;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2), 0 0 0 1000px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-light);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -48%) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.gallery-header {
  padding: 12px 20px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top-left-radius: var(--radius-lg);
  border-top-right-radius: var(--radius-lg);
}

.gallery-header span {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-dark);
}

.gallery-header button {
  border: none;
  background: #f1f5f9;
  font-size: 20px;
  cursor: pointer;
  color: #64748b;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-round);
  transition: all var(--transition-fast);
}

.gallery-header button:hover {
  background: #e2e8f0;
  color: var(--danger-color);
  transform: rotate(90deg);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
  padding: 16px;
  flex: 1;
  overflow-y: auto;
  align-content: start;
}

.gallery-item {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 4px;
  cursor: pointer;
  transition: all var(--transition-main);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-item:hover {
  border-color: var(--primary-color);
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.gallery-item img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Custom Scrollbar for Gallery */
.gallery-grid::-webkit-scrollbar {
  width: 6px;
}

.gallery-grid::-webkit-scrollbar-track {
  background: #f8fafc;
}

.gallery-grid::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 10px;
}

.gallery-grid::-webkit-scrollbar-thumb:hover {
  background: #cbd5e1;
}

/* Edit Button on Catalog Card */
.cat-edit-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  padding: 4px;
  color: #bbb;
  display: inline-flex;
  cursor: pointer;
  outline: none;
  transition: all var(--transition-fast);
  z-index: 5;
}

.cat-edit-btn:hover {
  background: none;
  color: var(--primary-color);
  transform: scale(1.1);
}

@media (max-width: 768px) {
  .pf-body-layout {
    flex-direction: column;
  }

  .pf-section-sidebar {
    max-height: 250px;
    border-left: none;
    border-top: 1px solid #eee;
  }
}