/* FReD Explorer - Specific Styles */

/* Column Selector Dropdown */
.column-selector-wrapper {
  position: relative;
  display: inline-block;
}

.column-selector-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  background: var(--fred-bg-card);
  border: 1px solid var(--fred-border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--fred-text);
  transition: background 0.2s, border-color 0.2s;
}

.column-selector-btn:hover {
  background: var(--fred-bg-alt);
  border-color: var(--fred-primary);
}

.column-selector-btn svg {
  width: 16px;
  height: 16px;
}

.column-selector-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 1000;
  min-width: 220px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--fred-bg-card);
  border: 1px solid var(--fred-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: none;
  margin-top: 4px;
}

.column-selector-dropdown.open {
  display: block;
}

.column-selector-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--fred-border);
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--fred-text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.column-selector-reset {
  font-size: 0.75rem;
  color: var(--fred-primary);
  cursor: pointer;
  font-weight: normal;
}

.column-selector-reset:hover {
  text-decoration: underline;
}

.column-selector-list {
  padding: 0.5rem 0;
}

.column-selector-item {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}

.column-selector-item:hover {
  background: var(--fred-bg-alt);
}

.column-selector-item.dragging {
  opacity: 0.5;
  background: var(--fred-bg-alt);
}

.column-selector-item.drag-over {
  border-top: 2px solid var(--fred-primary);
  margin-top: -2px;
}

.column-drag-handle {
  cursor: grab;
  color: var(--fred-text-muted);
  margin-right: 0.5rem;
  font-size: 1rem;
  line-height: 1;
}

.column-drag-handle:active {
  cursor: grabbing;
}

.column-selector-item input[type="checkbox"] {
  margin-right: 0.75rem;
  cursor: pointer;
  accent-color: var(--fred-primary);
}

.column-selector-item label {
  flex: 1;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--fred-text);
}

/* Dark mode adjustments */
[data-theme="dark"] .column-selector-dropdown {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Override DataTables defaults */
.dataTables_wrapper .dataTables_filter {
  margin-bottom: 1rem;
}

.dataTables_wrapper .dataTables_info {
  padding-top: 1rem;
  color: var(--fred-text-muted);
}

.dataTables_wrapper .dataTables_paginate {
  padding-top: 1rem;
}

/* Make tables responsive */
.dataTables_wrapper {
  overflow-x: auto;
  overflow-y: visible;
}

/* DataTables dark mode support */
[data-theme="dark"] table.dataTable {
  color: var(--fred-text);
}

[data-theme="dark"] table.dataTable thead th {
  background: var(--fred-bg-alt);
  border-bottom-color: var(--fred-border);
  color: var(--fred-text);
}

[data-theme="dark"] table.dataTable tbody td {
  border-bottom-color: var(--fred-border);
}

[data-theme="dark"] table.dataTable tbody tr:hover {
  background-color: var(--fred-bg-alt);
}

[data-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-theme="dark"] .dataTables_wrapper .dataTables_length select {
  background: var(--fred-bg-card);
  color: var(--fred-text);
  border-color: var(--fred-border);
}

[data-theme="dark"] .dataTables_paginate .paginate_button {
  color: var(--fred-text) !important;
  border-color: var(--fred-border);
}

[data-theme="dark"] .dataTables_paginate .paginate_button:hover:not(.current):not(.disabled) {
  background: var(--fred-bg-alt);
  color: var(--fred-text) !important;
}

[data-theme="dark"] .dataTables_paginate .paginate_button.current {
  background: var(--fred-primary) !important;
  color: white !important;
  border-color: var(--fred-primary);
}

[data-theme="dark"] .dataTables_paginate .paginate_button.disabled {
  color: var(--fred-text-muted) !important;
}

/* Ensure tooltips aren't clipped */
table.dataTable {
  overflow: visible;
}

table.dataTable tbody {
  overflow: visible;
}

table.dataTable tbody tr {
  overflow: visible;
}

table.dataTable tbody td {
  overflow: visible;
}

/* Scatterplot specific */
#scatterplot {
  min-height: 500px;
}

/* Forest plot scroll container */
#forestplot {
  max-height: 800px;
  overflow-y: auto;
}

/* Radio group compact styling */
.radio-group {
  max-height: 300px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.radio-option label {
  line-height: 1.3;
}

/* Legend styling for plots */
.plotly .legend {
  font-size: 12px !important;
}

/* Card headers with buttons */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header .btn-group {
  margin-left: auto;
}

/* Study count badge */
#filter-stats {
  font-size: 0.875rem;
}

#study-count {
  font-weight: 600;
  color: var(--fred-primary);
}

/* Success note styling */
.success-note {
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--fred-bg-alt);
  border-radius: 4px;
  border-left: 3px solid var(--fred-primary);
}

.success-note:empty {
  display: none;
}

/* Table cell truncation */
#studies-table td:nth-child(2),
#full-data-table td:first-child {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Reference columns - Author (Year) format with tooltip */
#studies-table td:nth-child(5),
#studies-table td:nth-child(6) {
  white-space: nowrap;
}

/* Highlight selected rows */
table.dataTable tbody tr.selected {
  background-color: rgba(166, 40, 40, 0.1) !important;
}

/* Link styling in tables */
table.dataTable a {
  color: var(--fred-primary);
}

/* DataTables expand/collapse control */
td.dt-control {
  text-align: center;
  cursor: pointer;
}

/* Sidebar counts */
.sidebar-counts {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  background: var(--fred-bg-alt);
  border-radius: 8px;
  margin-top: 1rem;
}

.count-item {
  flex: 1;
  text-align: center;
}

.count-label {
  font-size: 0.8125rem;
  color: var(--fred-text-muted);
  margin-bottom: 0.25rem;
}

.count-number {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--fred-primary);
}

/* Description cell wrapping */
.description-cell {
  white-space: normal !important;
  word-wrap: break-word;
  max-width: 400px;
}

/* Study details expanded row */
.study-details h5 {
  font-size: 0.9rem;
  font-weight: 600;
}

.study-details table td {
  padding: 0.25rem 0;
}

/* Plot loading state */
.plot-container.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fred-bg-alt);
}

/* Decade chart specific */
#decade-chart {
  min-height: 350px;
}

/* Journal chart - needs more height for labels */
#journal-chart {
  min-height: 600px;
}

/* Tab content transitions */
.tab-content {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .sidebar {
    margin-bottom: 1rem;
  }

  .radio-group {
    max-height: none;
  }

  #scatterplot,
  #forestplot,
  #decade-chart,
  #journal-chart {
    min-height: 300px;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .card-header .btn-group {
    margin-left: 0;
  }
}

/* Print-specific */
@media print {
  .page-header {
    background: white !important;
    color: black !important;
    border-bottom: 2px solid var(--fred-primary);
  }

  .card {
    break-inside: avoid;
  }

  .plot-container {
    min-height: auto !important;
    max-height: none !important;
  }
}
