/* Volatility-based design: stable layout, flexible components */

/* Stable: Core layout that rarely changes */
:root {
  --primary-color: #2563eb;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --bg-primary: #ffffff;
  --bg-secondary: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border-color: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
}

h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

nav {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 0 2rem;
  display: flex;
  gap: 1rem;
}

.nav-btn {
  background: none;
  border: none;
  padding: 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.nav-btn:hover {
  color: var(--text-primary);
}

.nav-btn.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

main {
  flex: 1;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Variable: Component styles that may change frequently */
.view {
  display: none;
}

.view.active {
  display: block;
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.view-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

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

.metric-card {
  background: var(--bg-primary);
  padding: 1.5rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  transition: transform 0.2s;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.metric-card h3 {
  margin: 0 0 0.5rem 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.metric-value {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Volatile: UI elements that change frequently */
.health-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.health-indicator .status {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--success-color);
  animation: pulse 2s infinite;
}

.health-indicator.warning .status {
  background: var(--warning-color);
}

.health-indicator.error .status {
  background: var(--danger-color);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

.activity-feed {
  background: var(--bg-primary);
  padding: 1.5rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
}

.activity-feed h2 {
  margin-bottom: 1rem;
  font-size: 1.125rem;
  font-weight: 600;
}

.activity-list {
  max-height: 400px;
  overflow-y: auto;
}

.activity-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.activity-description {
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* User cards - volatile styling */
.users-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.user-card {
  background: var(--bg-primary);
  padding: 1.5rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}

.user-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.user-card h3 {
  margin-bottom: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
}

.user-status {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

.user-status.status-active {
  background: #d1fae5;
  color: #065f46;
}

.user-status.status-cancelled {
  background: #fee2e2;
  color: #991b1b;
}

.user-metrics {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Messages list */
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message-item {
  background: var(--bg-primary);
  padding: 1rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
}

.message-item:hover {
  box-shadow: var(--shadow-lg);
}

.message-item.expanded .message-content {
  display: none;
}

.message-item.expanded .message-full-content {
  display: block !important;
  white-space: pre-wrap;
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 0.375rem;
  margin: 0.5rem 0;
  font-family: ui-monospace, monospace;
  font-size: 0.875rem;
}

.message-item.urgent {
  border-left: 4px solid var(--danger-color);
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.message-direction {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  text-transform: uppercase;
}

.message-direction.inbound {
  background: #dbeafe;
  color: #1e40af;
}

.message-direction.outbound {
  background: #d1fae5;
  color: #065f46;
}

.embedding-badge {
  font-size: 0.75rem;
  background: #f3e8ff;
  color: #7c3aed;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-weight: 500;
}

.embedding-indicator {
  font-size: 1rem;
  opacity: 0.7;
}

.embedding-cost {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.click-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  opacity: 0.7;
}

/* Embedding analytics */
.embedding-stats {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 0.375rem;
  margin-bottom: 1.5rem;
}

.embedding-metric {
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.embedding-metric:last-child {
  margin-bottom: 0;
}

/* Enhanced pending responses */
.pending-item {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  border-left: 4px solid transparent;
}

.pending-item:hover {
  box-shadow: var(--shadow);
}

.pending-item.overdue {
  border-left-color: var(--danger-color);
  background: #fef2f2;
}

.pending-item.imminent {
  border-left-color: #f59e0b;
  background: #fffbeb;
}

.pending-item.scheduled {
  border-left-color: #10b981;
  background: #f0fdf4;
}

.pending-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.send-status-badge {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  text-transform: uppercase;
}

.send-status-badge.overdue {
  background: var(--danger-color);
  color: white;
}

.send-status-badge.imminent {
  background: #f59e0b;
  color: white;
}

.send-status-badge.scheduled {
  background: #10b981;
  color: white;
}

.pending-item.expanded .response-preview {
  display: none;
}

.pending-item.expanded .response-full-content {
  display: block !important;
  white-space: pre-wrap;
  background: var(--bg-primary);
  padding: 1rem;
  border-radius: 0.375rem;
  margin: 0.5rem 0;
  font-family: ui-monospace, monospace;
  font-size: 0.875rem;
}

/* User detail styles */
.user-detail-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 0.375rem;
}

.user-messages {
  margin-top: 2rem;
}

.message-preview {
  padding: 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
}

.message-direction {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.pending-responses {
  margin-top: 2rem;
}

.response-preview {
  font-size: 0.875rem;
  margin-top: 0.5rem;
  color: var(--text-secondary);
}

/* Loading indicator */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.loading.active {
  display: block;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  border-radius: 0.375rem;
  color: white;
  font-size: 0.875rem;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
  z-index: 2000;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.error {
  background: var(--danger-color);
}

.toast.success {
  background: var(--success-color);
}

/* Responsive design */
@media (max-width: 768px) {
  header {
    padding: 1rem;
  }

  nav {
    padding: 0 1rem;
    overflow-x: auto;
  }

  main {
    padding: 1rem;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .filters {
    flex-direction: column;
  }

  .modal-content {
    padding: 1rem;
    max-width: 100%;
  }
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

.message-user {
  font-weight: 500;
  color: var(--text-primary);
}

.message-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.message-content {
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.message-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  align-items: center;
  flex-wrap: wrap;
}

.urgent-badge {
  background: var(--danger-color);
  color: white;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
  font-weight: 500;
}

/* Filters */
.filters {
  display: flex;
  gap: 1rem;
}

.filters select {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  background: var(--bg-primary);
  font-size: 0.875rem;
  cursor: pointer;
}

/* Health details */
.health-details {
  background: var(--bg-primary);
  padding: 1.5rem;
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
}

.health-summary {
  margin-bottom: 2rem;
}

.health-metrics {
  display: grid;
  gap: 2rem;
}

.health-metrics h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.health-metrics ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.health-metrics li {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Modal - stable structure, volatile content */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  overflow: auto;
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg-primary);
  padding: 2rem;
  border-radius: 0.5rem;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  transition: background 0.2s;
}

.close:hover {
  background: var(--bg-secondary);
}

.context-badge {
  font-size: 0.75rem;
  background: #e0f2fe;
  color: #0277bd;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.context-badge:hover {
  background: #b3e5fc;
}

/* Context modal content */
.context-summary {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 0.375rem;
  margin-bottom: 1.5rem;
}

.health-indicators {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.indicator {
  font-size: 0.875rem;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
}

.indicator.good {
  background: #d1fae5;
  color: #065f46;
}

.indicator.bad {
  background: #fee2e2;
  color: #991b1b;
}

.context-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 0.375rem;
}

.context-messages,
.semantic-matches {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.context-message,
.semantic-match {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 0.375rem;
  border-left: 3px solid #3b82f6;
}

.context-message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.context-message-content {
  font-size: 0.875rem;
  line-height: 1.5;
}

.semantic-match {
  border-left-color: #8b5cf6;
}

.match-score {
  font-weight: 600;
  color: #8b5cf6;
  margin-bottom: 0.25rem;
}

.match-source {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.match-content {
  font-size: 0.875rem;
  line-height: 1.5;
}

.future-context {
  background: var(--bg-secondary);
  padding: 1rem;
  border-radius: 0.375rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Callbacks Section */
.callbacks-section {
  margin-top: var(--spacing-lg);
  background: var(--card-bg);
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.callbacks-section h2 {
  margin-bottom: var(--spacing-sm);
  display: inline-block;
}

.callbacks-section button {
  margin-left: var(--spacing-md);
  padding: var(--spacing-xs) var(--spacing-sm);
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
}

.callbacks-section button:hover {
  background: var(--primary-hover);
}

.callbacks-list {
  margin-top: var(--spacing-md);
}

.callback-item {
  padding: var(--spacing-sm);
  border-left: 3px solid var(--primary);
  margin-bottom: var(--spacing-sm);
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.callback-item strong {
  color: var(--text-primary);
}

.callback-item small {
  color: var(--text-secondary);
  display: block;
  margin-top: var(--spacing-xs);
} 