// ================================
// VARIABLES
// ================================

$primary: #2563eb;
$secondary: #6b7280;
$success: #16a34a;
$warning: #f59e0b;
$danger: #dc2626;
$bg-page: #f4f7fb;
$bg-card: #ffffff;
$border-color: #e5e7eb;
$text-primary: #111827;
$text-secondary: #6b7280;
$shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
$shadow-md: 0 4px 10px rgba(0, 0, 0, 0.05),
  0 1px 2px rgba(0, 0, 0, 0.04);
$shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.08),
  0 2px 6px rgba(0, 0, 0, 0.04);
$radius-sm: 8px;
$radius-md: 14px;
$radius-lg: 18px;

// ================================
// ROOT VIEWER
// ================================

.entity-viewer {
  display: flex;
  flex-direction: column;
  gap: calc(var(--space-l) *1px);
  padding-top: calc(var(--space-l) *1px);
  padding-right: calc(var(--space-2xl) *1px);
  padding-bottom: calc(var(--space-2xl) *1px);
  padding-left: calc(var(--space-l) *1px);
  min-height: 100%;
  box-sizing: border-box;
}

// ================================
// SECTION
// ================================

.entity-section {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: calc(var(--size-radius-m) *1px);
  display: grid;
  gap: calc(var(--space-l) *1px);
  padding-top: calc(var(--space-m) *1px);
  padding-right: calc(var(--space-l) *1px);
  padding-bottom: calc(var(--space-m) *1px);
  padding-left: calc(var(--space-l) *1px);
}

// .entity-section:hover {
//   box-shadow: $shadow-md;
// }

// ================================
// SECTION HEADER
// ================================

// .entity-section-header {
//   margin-bottom: 8px;
//   padding-bottom: 8px;
//   border-bottom: 1px solid #edf0f2;
// }

.entity-section-title {
  font-size: calc(var(--font-size-sm) *1px);
  font-weight: var(--font-weight-semiBold);
  line-height: calc(var(--font-lineHeight-sm) * 1px);
  letter-spacing: calc(var(--font-letterSpacing-md) * 1px);
  color: var(--text-primary);
}

// ================================
// GRID SYSTEM
// ================================

.entity-section-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: calc(var(--space-m) *1px);
}

// ================================
// FIELD
// ================================

.entity-field {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

// ================================
// LOADING
// ================================

.entity-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  color: $secondary;
}

.entity-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba($primary, 0.15);
  border-top-color: $primary;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

// ================================
// ERROR
// ================================

.entity-error {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: rgba($danger, 0.08);
  border: 1px solid rgba($danger, 0.2);
  border-radius: $radius-md;
  color: $danger;
  margin: 20px;
}

.entity-error-icon {
  font-size: 22px;
}

.entity-error-message {
  flex: 1;
  font-weight: 600;
}

.entity-error-retry {
  border: none;
  background: $danger;
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: 0.2s ease;
}

.entity-error-retry:hover {
  opacity: 0.9;
}

// ================================
// EMPTY
// ================================

.entity-empty {
  text-align: center;
  padding: 80px 20px;
  color: $secondary;
}

.entity-empty-icon {
  font-size: 60px;
  margin-bottom: 16px;
}

.entity-empty-message {
  font-size: 18px;
  font-weight: 600;
}

// ================================
// TABLE SUPPORT
// ================================

::ng-deep .entity-table-responsive {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid $border-color;
}

::ng-deep .entity-table-responsive table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
  background: white;
}

::ng-deep .entity-table-responsive th {
  background: #f9fafb;
  color: $text-primary;
  font-weight: 700;
  padding: 14px 16px;
  border-bottom: 1px solid $border-color;
  text-align: left;
  white-space: nowrap;
}

::ng-deep .entity-table-responsive td {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  color: #374151;
  vertical-align: top;
}

::ng-deep .entity-table-responsive tr:hover {
  background: #f8fafc;
}

// ================================
// COMPACT THEME
// ================================

.entity-theme-compact {
  .entity-section {
    padding: 18px;
  }

  .entity-section-grid {
    gap: 10px;
  }

  .entity-section-title {
    font-size: 16px;
  }
}

// ================================
// DETAILED THEME
// ================================

.entity-theme-detailed {
  .entity-section {
    padding: 32px;
    border-radius: 22px;
    box-shadow: $shadow-lg;
  }

  .entity-section-grid {
    gap: 10px;
  }

  .entity-section-title {
    font-size: 22px;
  }
}

// ================================
// RESPONSIVE
// ================================

@media (max-width: 1200px) {
  .entity-field {
    grid-column: span 6 !important;
  }
}

@media (max-width: 768px) {
  .entity-viewer {
    padding: 10px;
  }

  .entity-section {
    padding: 18px;
  }

  .entity-section-grid {
    gap: 10px;
  }

  .entity-field {
    grid-column: span 12 !important;
  }

  .entity-section-title {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .entity-section {
    padding: 14px;
  }

  .entity-viewer {
    padding: 10px;
  }
}

.json-fallback {
  padding: 16px;
}

.json-fallback pre {
  background: #f7f7f7;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.5;
}