/* Botworker Command Center -- Design System */

/* ============ TOKENS ============ */
:root {
  /* Backgrounds */
  --bg-primary:    #09090b;
  --bg-secondary:  #0f0f12;
  --bg-card:       #131318;
  --bg-card-hover: #1a1a21;
  --bg-surface:    #18181d;
  --bg-input:      #1e1e25;

  /* Text */
  --text-primary:  #e4e4e7;
  --text-secondary:#a1a1aa;
  --text-muted:    #636370;
  --text-inverse:  #09090b;

  /* Brand */
  --accent:        #83b641;
  --accent-dim:    #6a9a2e;
  --accent-glow:   rgba(131,182,65,0.12);

  /* Semantic */
  --red:           #ef4444;
  --red-dim:       rgba(239,68,68,0.12);
  --amber:         #f59e0b;
  --amber-dim:     rgba(245,158,11,0.12);
  --blue:          #3b82f6;
  --blue-dim:      rgba(59,130,246,0.12);
  --purple:        #a78bfa;
  --purple-dim:    rgba(167,139,250,0.12);

  /* Borders */
  --border:        #1e1e26;
  --border-subtle: #27272f;
  --border-accent: #83b641;

  /* Layout */
  --sidebar-w:     256px;
  --topbar-h:      52px;
  --radius:        8px;
  --radius-sm:     5px;

  /* Typography */
  --font-sans:     'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:     'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
}

/* ============ RESET ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.55;
  overflow: hidden;
  height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
}

/* ============ TOPBAR ============ */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}
.topbar-brand svg { width: 22px; height: 22px; }
.topbar-brand .brand-accent { color: var(--accent); }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  margin-right: 4px;
}
.status-dot.offline { background: var(--red); }
.status-dot.loading { background: var(--amber); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.btn-refresh {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  transition: all 0.15s;
}
.btn-refresh:hover { border-color: var(--accent); color: var(--accent); }
.btn-refresh.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ SIDEBAR ============ */
.sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 0;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 4px; }

.nav-section {
  padding: 16px 16px 6px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px 7px 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.12s;
  border-left: 2px solid transparent;
}
.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}
.nav-item .nav-icon { width: 16px; text-align: center; font-size: 0.9rem; flex-shrink: 0; }
.nav-item .nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item .nav-badge {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px 7px 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.12s;
  user-select: none;
}
.nav-group-toggle:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-group-toggle .chevron { font-size: 0.7rem; transition: transform 0.2s; }
.nav-group-toggle.open .chevron { transform: rotate(90deg); }
.nav-group-children { display: none; }
.nav-group-children.open { display: block; }
.nav-group-children .nav-item { padding-left: 40px; font-size: 0.8rem; }

/* ============ MAIN CONTENT ============ */
.main {
  overflow-y: auto;
  padding: 24px 28px;
  background: var(--bg-primary);
}
.main::-webkit-scrollbar { width: 6px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 6px; }

.view-title {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.view-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ============ CARDS ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
  transition: border-color 0.15s;
}
.card:hover { border-color: var(--border-subtle); }
.card-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title .card-icon { font-size: 0.9rem; }
.card-body {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.card-body:empty::after {
  content: 'No data yet';
  color: var(--text-muted);
  font-style: italic;
}

/* Card accents */
.card-decision { border-left: 3px solid var(--amber); }
.card-blocker { border-left: 3px solid var(--red); }
.card-status { border-left: 3px solid var(--accent); }
.card-info { border-left: 3px solid var(--blue); }
.card-soul { border-left: 3px solid var(--purple); }

/* ============ DASHBOARD GRID ============ */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.dashboard-grid .card-wide { grid-column: 1 / -1; }
.dashboard-grid .card-exec { grid-column: 1 / -1; }

/* ============ AGENT TABS ============ */
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab {
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text-secondary); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab-content { min-height: 200px; }

/* ============ BADGES & TAGS ============ */
.mention {
  color: var(--accent);
  font-weight: 500;
  background: var(--accent-glow);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}
.project-tag {
  color: var(--blue);
  font-weight: 500;
  background: var(--blue-dim);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
}
.turn-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
}
.id-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--amber-dim);
  color: var(--amber);
  font-family: var(--font-mono);
}
.id-badge.blocker {
  background: var(--red-dim);
  color: var(--red);
}
.status-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--accent-glow);
  color: var(--accent);
  text-transform: uppercase;
}
.update-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--blue-dim);
  color: var(--blue);
  text-transform: uppercase;
}
.delta-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--purple-dim);
  color: var(--purple);
  text-transform: uppercase;
}
.timestamp {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============ LOADING ============ */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
  height: 120px;
  margin-bottom: 14px;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton-text { height: 14px; margin-bottom: 8px; border-radius: 4px; }
.skeleton-text.short { width: 40%; }
.skeleton-text.medium { width: 70%; }

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2rem; margin-bottom: 12px; opacity: 0.5; }
.empty-state p { font-size: 0.88rem; }

/* ============ FEED ENTRIES ============ */
.feed-entry {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.feed-entry:last-child { border-bottom: none; }
.feed-entry-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.feed-entry-body {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ============ AUTH GATE ============ */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.auth-box h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}
.auth-box p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.auth-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}
.auth-input:focus { border-color: var(--accent); }
.auth-input.error { border-color: var(--red); animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.auth-btn {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  background: var(--accent);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}
.auth-btn:hover { background: var(--accent-dim); }

/* ============ CHAT ============ */
.chat-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}
.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.86rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-bubble.sent {
  align-self: flex-end;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  border-bottom-right-radius: 2px;
}
.chat-bubble.received {
  align-self: flex-start;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-bottom-left-radius: 2px;
}
.chat-bubble .chat-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.chat-bubble .chat-body { }
.chat-bubble.thinking {
  align-self: flex-start;
  background: var(--bg-surface);
  border: 1px dashed var(--border-subtle);
  color: var(--text-muted);
  font-style: italic;
}
.chat-bubble.thinking .chat-body::after {
  content: '';
  display: inline-block;
  width: 12px;
  animation: dots 1.5s infinite;
}
@keyframes dots {
  0% { content: '.'; } 33% { content: '..'; } 66% { content: '...'; }
}
.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.4;
  resize: none;
  outline: none;
}
.chat-input-row textarea:focus { border-color: var(--accent); }
.chat-input-row textarea::placeholder { color: var(--text-muted); }
.chat-send-btn {
  padding: 10px 20px;
  background: var(--accent);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.chat-send-btn:hover { background: var(--accent-dim); }
.chat-send-btn:disabled { background: var(--bg-surface); color: var(--text-muted); cursor: not-allowed; }

/* ============ DECISION BUTTONS ============ */
.decision-btn:hover {
  border-color: var(--accent) !important;
  background: var(--accent-glow) !important;
}
.decision-btn:active {
  transform: scale(0.98);
}
.decision-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ============ COMPOSE BOX ============ */
.compose {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.compose-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.compose-target {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.compose-target select {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.78rem;
  padding: 3px 8px;
  outline: none;
}
.compose-target select:focus { border-color: var(--accent); }
.compose-textarea {
  width: 100%;
  min-height: 72px;
  max-height: 200px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.5;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}
.compose-textarea:focus { border-color: var(--accent); }
.compose-textarea::placeholder { color: var(--text-muted); }
.compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.compose-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.compose-send {
  padding: 6px 18px;
  background: var(--accent);
  color: var(--text-inverse);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.compose-send:hover { background: var(--accent-dim); }
.compose-send:disabled {
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: not-allowed;
}
.compose-send.sending {
  background: var(--bg-surface);
  color: var(--text-muted);
}
.compose-success {
  font-size: 0.78rem;
  color: var(--accent);
  margin-top: 6px;
}

/* ============ MOBILE ============ */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 200;
  padding: 6px 0 env(safe-area-inset-bottom, 6px);
}
.mobile-nav-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 12px;
  font-size: 0.65rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.12s;
}
.mobile-nav-item .mobile-icon { font-size: 1.2rem; }
.mobile-nav-item.active { color: var(--accent); }

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr auto;
  }
  .sidebar { display: none; }
  .mobile-nav { display: block; }
  .main { padding: 16px; padding-bottom: 80px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .topbar-brand .brand-text { display: none; }
  .view-title { font-size: 1.1rem; }
}

@media (max-width: 480px) {
  .main { padding: 12px; }
  .card { padding: 14px 16px; }
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tab { white-space: nowrap; flex-shrink: 0; }
}
