/* ═══════════════════════════════════════════════════
   ANVAYA — AI Business Operating System
   Design System & Dashboard Styles
   ═══════════════════════════════════════════════════ */

/* ── CSS Variables ──────────────────────────────── */
:root {
  /* Base palette — Deep navy + warm gold accent */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-tertiary: #1a2035;
  --bg-card: #161d2e;
  --bg-card-hover: #1c2540;
  --bg-input: #0d1220;
  
  --text-primary: #f0f2f5;
  --text-secondary: #8b95a8;
  --text-muted: #5a6478;
  
  --accent-primary: #e8a838;
  --accent-primary-light: #f0c060;
  --accent-primary-glow: rgba(232, 168, 56, 0.15);
  --accent-secondary: #3b82f6;
  --accent-secondary-glow: rgba(59, 130, 246, 0.15);
  
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --error: #ef4444;
  --error-glow: rgba(239, 68, 68, 0.15);
  
  --border: rgba(255, 255, 255, 0.06);
  --border-active: rgba(232, 168, 56, 0.3);
  
  --sidebar-width: 260px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 30px rgba(232, 168, 56, 0.08);
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Scrollbar ──────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* ═══ SIDEBAR ═══════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  gap: 32px;
  position: relative;
  z-index: 10;
}

.sidebar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 120px;
  background: linear-gradient(180deg, rgba(232, 168, 56, 0.04) 0%, transparent 100%);
  pointer-events: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 8px;
  position: relative;
}

.brand-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #d4922e 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: var(--bg-primary);
  box-shadow: 0 4px 12px rgba(232, 168, 56, 0.3);
}

.brand-name {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-primary-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-tagline {
  font-size: 0.73rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 500;
}

/* ── Nav ── */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  position: relative;
}

.nav-item:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-primary-glow);
  color: var(--accent-primary);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent-primary);
}

/* ── Sidebar Footer ── */
.sidebar-footer {
  margin-top: auto;
  padding: 0 8px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

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

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
  animation: pulse-green 2s infinite;
}

.status-dot.error {
  background: var(--error);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

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

/* ═══ MAIN CONTENT ══════════════════════════════ */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  position: relative;
}

.main-content::before {
  content: '';
  position: fixed;
  top: -200px; right: -200px;
  width: 500px; height: 500px;
  background: radial-gradient(circle, rgba(232, 168, 56, 0.03) 0%, transparent 70%);
  pointer-events: none;
}

/* ── Views ── */
.view { display: none; animation: fadeIn 0.3s ease; }
.view.active { display: block; }

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

/* ── View Header ── */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
}

.view-title {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

.view-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 500px;
  line-height: 1.5;
}

.header-badges {
  display: flex;
  gap: 8px;
}

.badge {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-servers {
  background: var(--accent-secondary-glow);
  color: var(--accent-secondary);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.badge-tools {
  background: var(--accent-primary-glow);
  color: var(--accent-primary);
  border: 1px solid rgba(232, 168, 56, 0.2);
}

/* ═══ COMMAND CENTER ════════════════════════════ */
.command-input-container {
  margin-bottom: 32px;
}

.command-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.command-input-wrapper:focus-within {
  border-color: var(--border-active);
  box-shadow: var(--shadow-glow);
}

.command-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1rem;
  resize: none;
  outline: none;
  line-height: 1.5;
  min-height: 24px;
  max-height: 120px;
}

.command-input::placeholder {
  color: var(--text-muted);
}

.execute-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, var(--accent-primary) 0%, #d4922e 100%);
  color: var(--bg-primary);
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.execute-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(232, 168, 56, 0.3);
}

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

.execute-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.execute-btn.loading {
  pointer-events: none;
}

.execute-btn.loading::after {
  content: '';
  width: 16px; height: 16px;
  border: 2px solid rgba(10, 14, 26, 0.3);
  border-top-color: var(--bg-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ── Suggestions ── */
.command-suggestions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.suggestion {
  padding: 7px 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.suggestion:hover {
  background: rgba(255,255,255,0.06);
  border-color: var(--border-active);
  color: var(--accent-primary-light);
}

/* ═══ EXECUTION AREA ════════════════════════════ */
.execution-area {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: slideUp 0.4s ease;
}

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

.execution-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.01);
}

.execution-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 600;
}

.pulse-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: pulse-gold 1.5s ease infinite;
}

@keyframes pulse-gold {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232, 168, 56, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(232, 168, 56, 0); }
}

.workflow-id {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 4px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 4px;
}

/* ── Steps ── */
.execution-steps {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 400px;
  overflow-y: auto;
}

.step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  animation: stepAppear 0.3s ease;
}

@keyframes stepAppear {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.step-icon {
  width: 24px; height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  margin-top: 1px;
}

.step.tool-call { background: var(--accent-secondary-glow); }
.step.tool-call .step-icon { background: rgba(59, 130, 246, 0.2); color: var(--accent-secondary); }

.step.tool-result { background: var(--success-glow); }
.step.tool-result .step-icon { background: rgba(16, 185, 129, 0.2); color: var(--success); }

.step.thinking { background: rgba(255,255,255,0.02); }
.step.thinking .step-icon { background: rgba(255,255,255,0.05); color: var(--text-muted); }

.step.confirmation-gate { background: rgba(245, 158, 11, 0.08); border: 1px solid rgba(245, 158, 11, 0.15); }
.step.confirmation-gate .step-icon { background: rgba(245, 158, 11, 0.2); color: var(--warning); }

.step.error { background: var(--error-glow); }
.step.error .step-icon { background: rgba(239, 68, 68, 0.2); color: var(--error); }

.step-content {
  flex: 1;
  min-width: 0;
}

.step-label {
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 3px;
  color: var(--text-secondary);
}

.step-detail {
  color: var(--text-primary);
  word-break: break-word;
  line-height: 1.5;
}

.step-detail code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 2px 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
}

.step-timestamp {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-top: 3px;
}

/* ── Confirmation Gates ── */
.confirmation-area {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.confirmation-card {
  background: rgba(245, 158, 11, 0.05);
  border: 1px solid rgba(245, 158, 11, 0.15);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.confirmation-info h4 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.confirmation-info p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.confirmation-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn-approve, .btn-reject {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-approve {
  background: var(--success);
  color: white;
}
.btn-approve:hover { box-shadow: 0 2px 12px rgba(16, 185, 129, 0.4); }

.btn-reject {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}
.btn-reject:hover { background: rgba(239, 68, 68, 0.25); }

/* ── Final Response ── */
.final-response {
  padding: 20px;
  border-top: 1px solid var(--border);
  background: rgba(232, 168, 56, 0.03);
}

.final-response-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-primary);
  margin-bottom: 10px;
}

.final-response-text {
  font-size: 0.92rem;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre-wrap;
}

/* ═══ TOOLS GRID ════════════════════════════════ */
.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  transition: all var(--transition-fast);
}

.tool-card:hover {
  border-color: var(--border-active);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.tool-server-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.tool-server-badge.inventory { background: rgba(59, 130, 246, 0.12); color: #60a5fa; }
.tool-server-badge.documents { background: rgba(139, 92, 246, 0.12); color: #a78bfa; }
.tool-server-badge.logistics { background: rgba(16, 185, 129, 0.12); color: #34d399; }
.tool-server-badge.market { background: rgba(245, 158, 11, 0.12); color: #fbbf24; }
.tool-server-badge.discovery { background: rgba(236, 72, 153, 0.12); color: #f472b6; }
.tool-server-badge.negotiation { background: rgba(239, 68, 68, 0.12); color: #f87171; }

.tool-name {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.tool-description {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ═══ SYSTEM STATUS ═════════════════════════════ */
.system-status {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.system-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}

.system-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.system-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.system-card .status-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
}

.status-badge.online {
  background: var(--success-glow);
  color: var(--success);
}

.status-badge.offline {
  background: var(--error-glow);
  color: var(--error);
}

.system-card-detail {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ═══ WORKFLOW HISTORY ══════════════════════════ */
.workflow-history {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.workflow-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.workflow-card:hover {
  border-color: var(--border-active);
  background: var(--bg-card-hover);
}

.workflow-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.workflow-card-id {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.workflow-card-status {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
}

.workflow-card-status.completed { background: var(--success-glow); color: var(--success); }
.workflow-card-status.awaiting_confirmation { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.workflow-card-status.error { background: var(--error-glow); color: var(--error); }

.workflow-card-response {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow: hidden;
  max-height: 60px;
}

/* ═══ EMPTY STATE ═══════════════════════════════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  gap: 16px;
}

.empty-state p {
  color: var(--text-muted);
  font-size: 0.88rem;
  max-width: 400px;
  line-height: 1.5;
}

/* ═══ UTILITIES ═════════════════════════════════ */
.hidden { display: none !important; }
