/* Categorization Studio - App-specific styles */
/* Extends shared/css/main.css design system */

/* ============================================
   DOT PLOT CONTAINER
   ============================================ */

.dotplot-container {
  width: 100%;
  min-height: 300px;
  background: var(--app-card-bg, #ffffff);
  border: 1px solid var(--app-border, #d6dfea);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.dotplot-container .placeholder-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--app-muted, #5f6b7a);
  font-style: italic;
}

/* D3 SVG styling */
.dotplot-container svg {
  display: block;
  width: 100%;
  height: 100%;
}

.dotplot-container .dot {
  transition: fill 0.4s ease, cy 0.5s ease;
  cursor: pointer;
}

.dotplot-container .dot:hover {
  stroke: #1f2a37;
  stroke-width: 2px;
}

.dotplot-container .bin-band {
  opacity: 0.15;
  transition: opacity 0.4s ease;
}

.dotplot-container .bin-boundary {
  stroke: var(--app-muted, #5f6b7a);
  stroke-width: 1.5px;
  stroke-dasharray: 4, 4;
  opacity: 0.6;
}

.dotplot-container .bin-label {
  font-size: 12px;
  font-weight: 600;
  fill: var(--app-text, #1f2a37);
  text-anchor: middle;
}

.dotplot-container .axis-label {
  font-size: 12px;
  fill: var(--app-muted, #5f6b7a);
}

/* ============================================
   COLLAPSIBLE COMPARISON SECTION
   ============================================ */

.collapsible-section {
  border: 1px solid var(--app-border, #d6dfea);
  border-radius: 8px;
  background: var(--app-card-bg, #ffffff);
}

.collapsible-section > summary {
  padding: 1rem 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 1rem;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-radius: 8px;
  transition: background 0.2s ease;
}

.collapsible-section > summary:hover {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
}

.collapsible-section > summary h2 {
  margin: 0;
  font-size: 1.1rem;
}

.collapsible-section > summary .summary-hint {
  font-size: 0.85rem;
  color: var(--app-muted, #5f6b7a);
  font-weight: 400;
}

.collapsible-section[open] > summary {
  border-bottom: 1px solid var(--app-border, #d6dfea);
  border-radius: 8px 8px 0 0;
}

.collapsible-section[open] > summary .summary-hint {
  display: none;
}

.collapsible-section > .card {
  border: none;
  border-radius: 0 0 8px 8px;
  margin: 0;
}

/* ============================================
   COMPARISON MODE
   ============================================ */

.comparison-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.comparison-panel {
  border: 1px solid var(--app-border, #d6dfea);
  border-radius: 8px;
  padding: 1rem;
  background: var(--app-card-bg, #ffffff);
}

.comparison-panel .dotplot-container {
  min-height: 200px;
}

.comparison-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.comparison-header label {
  font-weight: 500;
  color: var(--app-text, #1f2a37);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.comparison-header select {
  flex: 1;
  min-width: 100px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--app-border, #d6dfea);
  border-radius: 4px;
  font-size: 0.85rem;
}

.comparison-header input[type="number"] {
  width: 50px;
  padding: 0.4rem;
  border: 1px solid var(--app-border, #d6dfea);
  border-radius: 4px;
  font-size: 0.85rem;
  text-align: center;
}

.section-intro {
  color: var(--app-muted, #5f6b7a);
  margin-bottom: 1rem;
  font-size: 0.95rem;
}

/* Use This button in comparison panels */
.use-schema-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--app-accent, #2a7de1);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  white-space: nowrap;
}

.use-schema-btn:hover {
  background: var(--app-accent-hover, #1e5bb5);
  transform: translateY(-1px);
}

.use-schema-btn:active {
  transform: translateY(0);
}

.comparison-panel.active-panel {
  border-color: var(--app-accent, #2a7de1);
  box-shadow: 0 0 0 2px rgba(42, 125, 225, 0.2);
}

.comparison-panel.active-panel .use-schema-btn {
  background: #10b981;
}

.comparison-panel.active-panel .use-schema-btn::after {
  content: ' ✓';
}

/* Active Schema Indicator in BIN SUMMARY */
.active-schema-indicator {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border: 1px solid #93c5fd;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.active-schema-indicator .schema-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #1e40af;
  letter-spacing: 0.05em;
}

.active-schema-indicator #active-schema-name {
  font-weight: 600;
  color: #1e3a5f;
  font-size: 1rem;
}

.dotplot-controls {
  margin-bottom: 1rem;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 500;
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--app-accent, #2a7de1);
}

/* ============================================
   BIN SUMMARY CARDS
   ============================================ */

.bin-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.bin-card {
  background: var(--app-bg, #f5f7fb);
  border: 1px solid var(--app-border, #d6dfea);
  border-radius: 8px;
  padding: 1rem;
  position: relative;
  overflow: hidden;
}

.bin-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--bin-color, var(--app-accent, #2a7de1));
}

.bin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.bin-card-label {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--app-text, #1f2a37);
}

.bin-card-count {
  background: var(--bin-color, var(--app-accent, #2a7de1));
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 600;
}

.bin-card-stats {
  display: grid;
  gap: 0.4rem;
}

.bin-stat {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.bin-stat-label {
  color: var(--app-muted, #5f6b7a);
}

.bin-stat-value {
  font-weight: 600;
  color: var(--app-text, #1f2a37);
}

/* ============================================
   DIAGNOSTIC FLAGS
   ============================================ */

.flags-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.flag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
}

.flag--warning {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #f59e0b;
}

.flag--danger {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #ef4444;
}

.flag--success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #22c55e;
}

.flag-icon {
  font-size: 1rem;
}

/* ============================================
   MANUAL BINNING PANEL
   ============================================ */

.manual-panel {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--app-bg, #f5f7fb);
  border-radius: 8px;
  border: 1px solid var(--app-border, #d6dfea);
}

.manual-panel h4 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

/* ============================================
   VARIABLE SUMMARY
   ============================================ */

.variable-summary {
  background: var(--app-bg, #f5f7fb);
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--app-border, #d6dfea);
}

.variable-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 0.75rem;
}

.variable-stat {
  text-align: center;
}

.variable-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--app-accent, #2a7de1);
}

.variable-stat-label {
  font-size: 0.8rem;
  color: var(--app-muted, #5f6b7a);
  text-transform: uppercase;
}

/* ============================================
   SCHEMA CONTROLS
   ============================================ */

.schema-controls-grid {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}

@media (max-width: 768px) {
  .schema-controls-grid {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   EXPORT SECTION
   ============================================ */

.export-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.code-output {
  background: #1f2a37;
  color: #e5e7eb;
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  margin-top: 1rem;
  max-height: 300px;
  overflow-y: auto;
}

.template-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ============================================
   COLOR PALETTE FOR BINS
   ============================================ */

:root {
  --bin-color-1: #3b82f6; /* Blue */
  --bin-color-2: #10b981; /* Green */
  --bin-color-3: #f59e0b; /* Amber */
  --bin-color-4: #ef4444; /* Red */
  --bin-color-5: #8b5cf6; /* Purple */
  --bin-color-6: #ec4899; /* Pink */
  --bin-color-7: #06b6d4; /* Cyan */
  --bin-color-8: #84cc16; /* Lime */
  --bin-color-9: #f97316; /* Orange */
  --bin-color-10: #6366f1; /* Indigo */
}

/* ============================================
   COMPARISON K INPUT
   ============================================ */

.compare-k-input {
  width: 60px;
}

/* ============================================
   COMPACT TABLE
   ============================================ */

.compact-table {
  margin-top: 0.5rem;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 640px) {
  .bin-summary-grid {
    grid-template-columns: 1fr;
  }
  
  .comparison-container {
    grid-template-columns: 1fr;
  }
  
  .export-controls {
    flex-direction: column;
  }
  
  .export-controls button {
    width: 100%;
  }
}

/* ============================================
   ANIMATION CLASSES
   ============================================ */

.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

.fade-out {
  animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

/* ============================================
   TOOLTIP
   ============================================ */

.dotplot-tooltip {
  position: absolute;
  background: rgba(31, 42, 55, 0.95);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dotplot-tooltip strong {
  color: var(--app-accent, #3b82f6);
}

/* ============================================
   INLINE CASE NARRATIVE (under dropdown)
   ============================================ */

.case-narrative {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color, #dee2e6);
}

.case-narrative.hidden {
  display: none;
}

.case-narrative .intro-notes {
  margin-top: 1rem;
}

/* ============================================
   SCENARIO DESCRIPTION STYLING
   ============================================ */

.scenario-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color, #dee2e6);
}

.scenario-icon {
  font-size: 1.5rem;
}

.scenario-header h4 {
  margin: 0;
  color: var(--heading-color, #2c3e50);
  font-size: 1.1rem;
  flex-grow: 1;
}

.scenario-badge {
  background: var(--app-accent, #1d4ed8);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.scenario-intro {
  color: var(--text-muted, #495057);
  line-height: 1.6;
  margin-bottom: 1rem;
}

.scenario-variables h5,
.scenario-context h5,
.scenario-insights h5,
.scenario-questions h5,
.scenario-stakes h5 {
  color: var(--heading-color, #2c3e50);
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.scenario-var-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}

.scenario-var-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border-color, #e9ecef);
  vertical-align: middle;
}

.scenario-var-table td:first-child {
  width: 160px;
  white-space: nowrap;
}

.var-tag {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  font-weight: 600;
}

.var-tag.outcome {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.var-tag.predictor {
  background: #cce5ff;
  color: #004085;
  border: 1px solid #b8daff;
}

.var-tag.binary {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

.var-tag.categorical {
  background: #e2d9f3;
  color: #5a3d7a;
  border: 1px solid #d4c4e8;
}

.var-tag.time {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

.context-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.context-item {
  background: white;
  padding: 0.75rem;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.context-item strong {
  display: block;
  color: var(--text-muted, #6c757d);
  font-size: 0.75rem;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.context-item span {
  color: var(--heading-color, #2c3e50);
  font-weight: 600;
}

.scenario-context {
  background: var(--card-bg, #f8f9fa);
  border-radius: 8px;
  padding: 1rem;
  margin: 1rem 0;
}

.scenario-context ul {
  margin: 0.5rem 0 0 0;
  padding-left: 1.25rem;
  color: var(--text-color, #495057);
}

.scenario-context li {
  margin-bottom: 0.35rem;
  line-height: 1.5;
}

.scenario-stakes {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 1rem;
  margin: 1rem 0;
}

.scenario-stakes ul {
  margin: 0.5rem 0 0 0;
  padding-left: 1.25rem;
  color: var(--text-color, #495057);
}

.scenario-stakes li {
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.scenario-insights {
  background: #e7f3ff;
  border: 1px solid #b8daff;
  border-radius: 8px;
  padding: 1rem;
  margin: 1rem 0;
}

.scenario-insights ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-color, #495057);
}

.scenario-insights li {
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.scenario-questions {
  background: #f0f9ff;
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
}

.scenario-questions ol {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text-color, #495057);
}

.scenario-questions li {
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.scenario-tip {
  background: #e7f3ff;
  border: 1px solid #b8daff;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  color: #004085;
  font-size: 0.9rem;
}

/* Scenario variables styling */
.scenario-variables {
  margin: 1rem 0;
}

/* ============================================
   DARK MODE OVERRIDES FOR SCENARIOS
   ============================================ */

@media (prefers-color-scheme: dark) {
  .scenario-context {
    background: rgba(255,255,255,0.05);
  }
  
  .scenario-stakes {
    background: rgba(251, 191, 36, 0.1);
    border-color: rgba(251, 191, 36, 0.3);
  }
  
  .scenario-insights {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.3);
  }
  
  .scenario-questions {
    background: rgba(59, 130, 246, 0.05);
  }
  
  .context-item {
    background: rgba(255,255,255,0.05);
  }
  
  .var-tag.outcome {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.4);
  }
  
  .var-tag.predictor {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.4);
  }
}
