/**
 * Relation Viewer Styles
 * Slide-out panel for viewing related records
 */

/* ========================================
   OVERLAY & BACKDROP
   ======================================== */

.rv-overlay {
  position: fixed;
  inset: 0;
  z-index: 2100;
  pointer-events: none;
}

.rv-overlay.active {
  pointer-events: auto;
}

.rv-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.rv-overlay.active .rv-backdrop {
  opacity: 1;
}

/* ========================================
   PANEL
   ======================================== */

.rv-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  max-width: 90vw;
  background: var(--content-bg, white);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.rv-overlay.active .rv-panel {
  transform: translateX(0);
}

/* ========================================
   HEADER
   ======================================== */

.rv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color, #e5e7eb);
  background: var(--content-bg, white);
  flex-shrink: 0;
}

.rv-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.rv-header-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.rv-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--content-text, #1f2937);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rv-close-btn {
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: 6px;
  font-size: 1.5rem;
  color: var(--content-text-secondary, #6b7280);
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.rv-close-btn:hover {
  background: var(--hover-bg, #f3f4f6);
  color: var(--content-text, #1f2937);
}

/* ========================================
   CONTENT
   ======================================== */

.rv-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

.rv-fields {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.rv-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.rv-field-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--content-text-secondary, #6b7280);
}

.rv-field-value {
  font-size: 0.9375rem;
  color: var(--content-text, #1f2937);
  line-height: 1.5;
  word-break: break-word;
}

/* ========================================
   FIELD VALUE TYPES
   ======================================== */

.rv-field-value .dv-status {
  display: inline-block;
}

.rv-field-value .dv-badge {
  display: inline-flex;
  cursor: default;
}

/* Clickable relation badges within viewer */
.rv-field-value .rv-relation-link {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.rv-field-value .rv-relation-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.rv-link {
  color: var(--primary-color, #667eea);
  text-decoration: none;
  word-break: break-all;
}

.rv-link:hover {
  text-decoration: underline;
}

.rv-image {
  max-width: 100%;
  max-height: 200px;
  border-radius: 8px;
  object-fit: cover;
}

.rv-rating {
  color: #f59e0b;
  font-size: 1rem;
}

.rv-text-preview,
.rv-text {
  white-space: pre-wrap;
  font-family: inherit;
}

.rv-field-value .dv-tag {
  margin-right: 0.25rem;
  margin-bottom: 0.25rem;
}

/* ========================================
   LOADING STATE
   ======================================== */

.rv-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--content-text-secondary, #6b7280);
}

.rv-spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--border-color, #e5e7eb);
  border-top-color: var(--primary-color, #667eea);
  border-radius: 50%;
  animation: rv-spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

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

/* ========================================
   ERROR STATE
   ======================================== */

.rv-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  text-align: center;
  color: var(--content-text-secondary, #6b7280);
}

.rv-error-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.rv-error p {
  margin: 0 0 0.5rem 0;
  font-weight: 500;
  color: var(--content-text, #1f2937);
}

.rv-error small {
  color: var(--danger-color, #ef4444);
}

/* ========================================
   EMPTY STATE
   ======================================== */

.rv-empty {
  text-align: center;
  color: var(--content-text-secondary, #6b7280);
  padding: 2rem;
}

/* ========================================
   FOOTER
   ======================================== */

.rv-footer {
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-color, #e5e7eb);
  background: var(--content-bg, white);
  flex-shrink: 0;
}

.rv-btn {
  flex: 1;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
}

.rv-btn-secondary {
  background: var(--content-bg, white);
  border: 1px solid var(--border-color, #e5e7eb);
  color: var(--content-text, #374151);
}

.rv-btn-secondary:hover {
  background: var(--hover-bg, #f3f4f6);
  border-color: var(--border-color-dark, #d1d5db);
}

.rv-btn-primary {
  background: var(--primary-color, #667eea);
  border: 1px solid var(--primary-color, #667eea);
  color: white;
}

.rv-btn-primary:hover {
  background: var(--primary-hover, #5a6fd6);
  border-color: var(--primary-hover, #5a6fd6);
}

.rv-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========================================
   DARK MODE
   ======================================== */

[data-theme="dark"] .rv-panel {
  background: var(--content-bg, #1f2937);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .rv-header {
  background: var(--content-bg, #1f2937);
  border-color: var(--border-color, #374151);
}

[data-theme="dark"] .rv-title {
  color: var(--content-text, #f9fafb);
}

[data-theme="dark"] .rv-close-btn:hover {
  background: var(--hover-bg, #374151);
}

[data-theme="dark"] .rv-field-value {
  color: var(--content-text, #f9fafb);
}

[data-theme="dark"] .rv-footer {
  background: var(--content-bg, #1f2937);
  border-color: var(--border-color, #374151);
}

[data-theme="dark"] .rv-btn-secondary {
  background: var(--content-bg, #1f2937);
  border-color: var(--border-color, #374151);
  color: var(--content-text, #f9fafb);
}

[data-theme="dark"] .rv-btn-secondary:hover {
  background: var(--hover-bg, #374151);
}

[data-theme="dark"] .rv-spinner {
  border-color: var(--border-color, #374151);
  border-top-color: var(--primary-color, #667eea);
}

[data-theme="dark"] .rv-backdrop {
  background: rgba(0, 0, 0, 0.5);
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 480px) {
  .rv-panel {
    width: 100%;
    max-width: 100%;
  }
  
  .rv-header {
    padding: 0.875rem 1rem;
  }
  
  .rv-content {
    padding: 1rem;
  }
  
  .rv-footer {
    padding: 0.875rem 1rem;
  }
}

/* ========================================
   RELATION CELL WITH VIEW BUTTON
   ======================================== */

.dv-relation-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 100%;
}

.dv-relation-cell > .dv-badge,
.dv-relation-cell > .dv-relation-value {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* View button - hidden by default, shown on hover */
.dv-relation-view-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--primary-color, #667eea);
  background: var(--hover-bg, #f3f4f6);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.15s ease;
}

/* Show on cell hover */
.dv-table td:hover .dv-relation-view-btn,
.dv-relation-cell:hover .dv-relation-view-btn {
  opacity: 1;
  transform: scale(1);
}

.dv-relation-view-btn:hover {
  background: var(--primary-color, #667eea);
  color: white;
  transform: scale(1.1);
}

/* Dark mode */
[data-theme="dark"] .dv-relation-view-btn {
  background: var(--hover-bg, #374151);
  color: var(--primary-color-light, #818cf8);
}

[data-theme="dark"] .dv-relation-view-btn:hover {
  background: var(--primary-color, #667eea);
  color: white;
}
