/**
 * Harpoon v2 - Minimal Design System
 * Open space, progressive disclosure, command palette first
 */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a25;
  --accent-purple: #9333ea;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --text-primary: #ffffff;
  --text-secondary: #a1a1aa;
  --border-subtle: rgba(255, 255, 255, 0.05);
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ==========================================
   LAYOUT - Maximum open space
   ========================================== */

.app-container {
  display: flex;
  height: 100vh;
  gap: 1px;
  background: var(--border-subtle);
}

.main-panel {
  flex: 1;
  min-width: 0; /* Allow flex shrinking */
}

.main-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  overflow: hidden;
}

.side-panel {
  width: 400px; /* Initial width, will be overridden by JS */
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ==========================================
   COMMAND PALETTE - First-class UX
   ========================================== */

#paletteOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}

#commandPalette {
  position: fixed;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  max-width: 90vw;
  background: var(--bg-secondary);
  border: 1px solid rgba(147, 51, 234, 0.3);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  z-index: 1001;
  animation: slideDown 0.3s ease;
  overflow: hidden;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

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

.palette-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.palette-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 16px;
  padding: 0;
}

.palette-input::placeholder {
  color: var(--text-secondary);
}

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

.palette-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.palette-item:hover,
.palette-item.selected {
  background: rgba(147, 51, 234, 0.1);
}

.palette-item kbd {
  margin-left: auto;
  font-family: 'SF Mono', 'Monaco', monospace;
  font-size: 11px;
}

/* ==========================================
   CHAT INTERFACE - Central, minimal
   ========================================== */

.chat-header {
  padding: 20px 32px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header h1 {
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cmd-hint {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: 'SF Mono', monospace;
  background: var(--bg-tertiary);
  padding: 4px 8px;
  border-radius: 4px;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.message {
  animation: messageSlideIn 0.3s ease;
}

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

.user-message {
  align-self: flex-end;
  max-width: 80%;
}

.assistant-message {
  align-self: flex-start;
  max-width: 85%;
}

.chat-input-container {
  padding: 20px 32px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
}

.chat-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: end;
}

#chatInput {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 14px;
  resize: none;
  min-height: 44px;
  max-height: 200px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

#chatInput:focus {
  outline: none;
  border-color: var(--accent-purple);
}

#chatInput::placeholder {
  color: var(--text-secondary);
}

.send-button {
  background: var(--accent-purple);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.send-button:hover {
  background: #7e22ce;
  transform: translateY(-1px);
}

.send-button:active {
  transform: translateY(0);
}

/* ==========================================
   COVENANT CARD - Progressive disclosure
   ========================================== */

.side-panel-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.side-panel-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.side-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.covenant-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
  transition: all 0.3s ease;
}

.covenant-card.active {
  border-color: var(--accent-green);
  background: rgba(16, 185, 129, 0.05);
}

.covenant-card.draft {
  border-color: var(--accent-amber);
  border-style: dashed;
}

/* ==========================================
   ORCHESTRATION TREE - Recursive visualization
   ========================================== */

.tree-node {
  margin-bottom: 16px;
}

.agent-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 12px;
  transition: all 0.3s ease;
}

.agent-card.running {
  border-color: var(--accent-blue);
  animation: pulse 2s ease infinite;
}

.agent-card.completed {
  border-color: var(--accent-green);
}

.agent-card.pending {
  opacity: 0.5;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0);
  }
}

.status-badge {
  font-size: 10px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.status-badge.pending {
  background: rgba(161, 161, 170, 0.2);
  color: var(--text-secondary);
}

.status-badge.running {
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent-blue);
}

.status-badge.completed {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-green);
}

.child-agent {
  display: flex;
  align-items: center;
  justify-between;
  padding: 6px 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  font-size: 11px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.status-dot.running {
  background: var(--accent-blue);
  animation: blink 1s ease infinite;
}

.status-dot.completed {
  background: var(--accent-green);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-primary);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-blue));
  transition: width 0.3s ease;
}

/* ==========================================
   EPHEMERAL ELEMENTS - Toast notifications
   ========================================== */

#toastContainer {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateX(100px);
  transition: all 0.3s ease;
}

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

.toast.success {
  border-color: var(--accent-green);
  background: rgba(16, 185, 129, 0.1);
}

.toast.error {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.toast.info {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.1);
}

/* ==========================================
   AGENT ACTIVITY INDICATOR
   ========================================== */

#agentActivity {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--accent-purple);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.loading-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* ==========================================
   INSIGHTS PANEL - Progressive disclosure
   ========================================== */

#insightsPanel {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  border-top: 1px solid var(--border-subtle);
}

#insightsPanel.expanded {
  max-height: 400px;
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */

.hidden {
  display: none !important;
}

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

@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  
  .side-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 400px;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 50;
  }
  
  .side-panel.open {
    transform: translateX(0);
  }
}

/* ==========================================
   SCROLLBAR STYLING
   ========================================== */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ==========================================
   RESIZABLE SIDEBAR
   ========================================== */

.sidebar-resizer {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 10;
  transition: background 0.2s ease;
}

.sidebar-resizer:hover {
  background: rgba(147, 51, 234, 0.3);
}

.sidebar-resizer:hover .resize-handle {
  opacity: 1;
}

.resize-handle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 60px;
  background: var(--accent-purple);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.side-panel {
  position: relative;
  transition: width 0.05s ease-out;
}

/* ==========================================
   COLLAPSIBLE TREE SECTIONS
   ========================================== */

.tree-node {
  transition: all 0.2s ease;
}

.agent-card {
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.agent-card.running {
  border-left-color: var(--accent-blue);
  animation: pulse 2s ease-in-out infinite;
}

.agent-card.completed {
  border-left-color: var(--accent-green);
}

.agent-card.pending {
  border-left-color: rgba(255, 255, 255, 0.1);
}

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

/* Expanded details styling */
.agent-card .text-xs {
  line-height: 1.5;
}

.child-agent {
  transition: all 0.2s ease;
  border-left: 2px solid rgba(255, 255, 255, 0.1);
}

.child-agent:hover {
  background: rgba(255, 255, 255, 0.03);
  border-left-color: var(--accent-purple);
}
