/* =====================================================
   History Explorer Styles
   ===================================================== */

.history-explorer {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-primary, #0f172a);
  border-radius: 12px;
  overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif;
}

/* Header */
.history-header {
  padding: 16px 20px;
  background: var(--bg-secondary, #1e293b);
  border-bottom: 1px solid var(--border-color, #334155);
}

.history-header h2 {
  margin: 0 0 12px 0;
  font-size: 1.25rem;
  color: var(--text-primary, #f8fafc);
}

.history-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.stat-item {
  font-size: 0.875rem;
  color: var(--text-secondary, #94a3b8);
  background: var(--bg-tertiary, #0f172a);
  padding: 4px 10px;
  border-radius: 20px;
}

/* Filters */
.history-filters {
  padding: 16px 20px;
  background: var(--bg-secondary, #1e293b);
  border-bottom: 1px solid var(--border-color, #334155);
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.filter-input {
  padding: 8px 12px;
  border: 1px solid var(--border-color, #334155);
  border-radius: 6px;
  background: var(--bg-primary, #0f172a);
  color: var(--text-primary, #f8fafc);
  font-size: 0.875rem;
}

.filter-input:focus {
  outline: none;
  border-color: var(--accent-primary, #3b82f6);
}

.search-input {
  flex: 1;
  min-width: 200px;
}

/* Content Area */
.history-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* History List */
.history-list {
  width: 40%;
  min-width: 320px;
  max-width: 450px;
  overflow-y: auto;
  border-right: 1px solid var(--border-color, #334155);
  background: var(--bg-primary, #0f172a);
}

.history-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color, #334155);
  cursor: pointer;
  transition: background 0.15s ease;
}

.history-item:hover {
  background: var(--bg-hover, #1e293b);
}

.history-item.selected {
  background: var(--bg-selected, #1e3a5f);
  border-left: 3px solid var(--accent-primary, #3b82f6);
}

.item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.item-type {
  font-size: 1.1rem;
}

.item-title {
  flex: 1;
  font-weight: 600;
  color: var(--text-primary, #f8fafc);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-status {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  font-weight: 600;
}

.status-completed {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.status-error {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.status-pending {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.item-preview {
  font-size: 0.8125rem;
  color: var(--text-secondary, #94a3b8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 8px;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.item-date {
  font-size: 0.75rem;
  color: var(--text-muted, #64748b);
}

.badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 500;
}

.badge-decon {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

.badge-recs {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
}

/* Detail View */
.history-detail {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-primary, #0f172a);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary, #94a3b8);
  text-align: center;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  opacity: 0.5;
}

.empty-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted, #64748b);
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color, #334155);
}

.detail-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-primary, #f8fafc);
  line-height: 1.4;
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.detail-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-secondary, #1e293b);
  border-radius: 8px;
}

.meta-row {
  display: flex;
  gap: 8px;
}

.meta-label {
  color: var(--text-muted, #64748b);
  font-size: 0.875rem;
}

.meta-value {
  color: var(--text-primary, #f8fafc);
  font-size: 0.875rem;
  font-weight: 500;
}

.detail-section {
  margin-bottom: 24px;
}

.detail-section h4 {
  margin: 0 0 12px 0;
  font-size: 0.9375rem;
  color: var(--text-secondary, #94a3b8);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.prompt-box {
  position: relative;
  background: var(--bg-secondary, #1e293b);
  border: 1px solid var(--border-color, #334155);
  border-radius: 8px;
  padding: 16px;
}

.prompt-box pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.875rem;
  color: var(--text-primary, #f8fafc);
  line-height: 1.6;
}

.btn-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-tertiary, #0f172a);
  border: 1px solid var(--border-color, #334155);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.btn-copy:hover {
  opacity: 1;
}

/* Deconstruction Preview */
.decon-summary {
  background: var(--bg-secondary, #1e293b);
  border-radius: 8px;
  padding: 16px;
}

.summary-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.summary-stats .stat {
  font-size: 0.875rem;
  color: var(--text-secondary, #94a3b8);
  background: var(--bg-tertiary, #0f172a);
  padding: 4px 12px;
  border-radius: 20px;
}

.clarifying-questions {
  margin-bottom: 16px;
}

.clarifying-questions h5 {
  margin: 0 0 8px 0;
  font-size: 0.875rem;
  color: var(--text-secondary, #94a3b8);
}

.clarifying-questions ul {
  margin: 0;
  padding-left: 20px;
  color: var(--text-primary, #f8fafc);
}

.clarifying-questions li {
  margin-bottom: 4px;
  font-size: 0.875rem;
}

.execution-plan-preview h5 {
  margin: 0 0 12px 0;
  font-size: 0.875rem;
  color: var(--text-secondary, #94a3b8);
}

.plan-step-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color, #334155);
}

.plan-step-preview:last-child {
  border-bottom: none;
}

.step-number {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-primary, #3b82f6);
  color: white;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 600;
}

.step-title {
  color: var(--text-primary, #f8fafc);
  font-size: 0.875rem;
}

.more-steps {
  text-align: center;
  color: var(--text-muted, #64748b);
  font-size: 0.875rem;
  margin-top: 8px;
}

/* Recommendations Preview */
.recs-summary {
  background: var(--bg-secondary, #1e293b);
  border-radius: 8px;
  padding: 16px;
}

.decision-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.decision-stats .stat {
  font-size: 0.875rem;
  padding: 4px 12px;
  border-radius: 20px;
}

.decision-stats .accepted {
  background: rgba(34, 197, 94, 0.2);
  color: #22c55e;
}

.decision-stats .rejected {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.decision-stats .pending {
  background: rgba(234, 179, 8, 0.2);
  color: #eab308;
}

.recs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rec-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--bg-tertiary, #0f172a);
  border-radius: 6px;
  font-size: 0.8125rem;
}

.rec-item.accepted {
  border-left: 3px solid #22c55e;
}

.rec-item.rejected {
  border-left: 3px solid #ef4444;
  opacity: 0.7;
}

.rec-item.pending {
  border-left: 3px solid #eab308;
}

.rec-type {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.rec-type.persona { background: rgba(99, 102, 241, 0.2); color: #818cf8; }
.rec-type.context { background: rgba(6, 182, 212, 0.2); color: #22d3ee; }
.rec-type.format { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.rec-type.constraint { background: rgba(244, 63, 94, 0.2); color: #fb7185; }
.rec-type.tone { background: rgba(16, 185, 129, 0.2); color: #34d399; }
.rec-type.example { background: rgba(168, 85, 247, 0.2); color: #c084fc; }
.rec-type.chain_of_thought { background: rgba(249, 115, 22, 0.2); color: #fb923c; }

.rec-action {
  color: var(--text-secondary, #94a3b8);
  text-transform: uppercase;
  font-size: 0.7rem;
}

.rec-priority {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}

.rec-priority.critical { background: rgba(239, 68, 68, 0.3); color: #ef4444; }
.rec-priority.high { background: rgba(249, 115, 22, 0.3); color: #f97316; }
.rec-priority.medium { background: rgba(234, 179, 8, 0.3); color: #eab308; }
.rec-priority.low { background: rgba(107, 114, 128, 0.3); color: #9ca3af; }

.rec-decision {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-muted, #64748b);
  text-transform: uppercase;
}

.more-recs {
  text-align: center;
  color: var(--text-muted, #64748b);
  font-size: 0.875rem;
  margin-top: 8px;
}

/* Pagination */
.history-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-secondary, #1e293b);
  border-top: 1px solid var(--border-color, #334155);
}

.pagination-info {
  font-size: 0.875rem;
  color: var(--text-secondary, #94a3b8);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-info {
  font-size: 0.875rem;
  color: var(--text-secondary, #94a3b8);
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent-primary, #3b82f6);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: #2563eb;
}

.btn-secondary {
  background: var(--bg-tertiary, #334155);
  color: var(--text-primary, #f8fafc);
  border: 1px solid var(--border-color, #475569);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover, #475569);
}

.btn-full {
  width: 100%;
  margin-top: 16px;
}

/* Loading State */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--text-secondary, #94a3b8);
}

/* Text utilities */
.text-muted {
  color: var(--text-muted, #64748b);
}

/* Responsive */
@media (max-width: 900px) {
  .history-content {
    flex-direction: column;
  }
  
  .history-list {
    width: 100%;
    max-width: none;
    max-height: 400px;
    border-right: none;
    border-bottom: 1px solid var(--border-color, #334155);
  }
  
  .filter-row {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-input {
    min-width: auto;
  }
  
  .history-header h2 {
    font-size: 1.1rem;
  }
  
  .detail-header {
    flex-direction: column;
    gap: 12px;
  }
  
  .detail-actions {
    width: 100%;
  }
  
  .detail-actions .btn {
    flex: 1;
  }
}

/* Dark theme variables (fallback) */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-hover: #1e293b;
  --bg-selected: #1e3a5f;
  --border-color: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-primary: #3b82f6;
}
