/* Jai Dashboard - Dark theme inspired by Klaus */

:root {
  --bg-primary: #0f1419;
  --bg-secondary: #1a2332;
  --bg-card: #1e2a3a;
  --bg-hover: #2a3a4d;
  --text-primary: #e7e9ea;
  --text-secondary: #8b98a5;
  --accent: #1d9bf0;
  --accent-hover: #1a8cd8;
  --success: #00ba7c;
  --warning: #ffad1f;
  --danger: #f4212e;
  --border: #2f3336;
  --dot-todo: #1d9bf0;
  --dot-progress: #ffad1f;
  --dot-done: #00ba7c;
  --dot-archive: #8b98a5;
}

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

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

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--bg-secondary);
  padding: 20px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.avatar-section {
  text-align: center;
  margin-bottom: 24px;
}

.avatar {
  width: 80px;
  height: 80px;
  background: var(--bg-card);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin: 0 auto 12px;
  border: 3px solid var(--accent);
}

.avatar-section h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

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

.status-dot.idle { background: var(--success); }
.status-dot.working { background: var(--warning); animation: pulse 1s infinite; }

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

/* Signal Status */
.signal-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.signal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.signal-dot.active {
  background: var(--success);
  animation: pulse 2s infinite;
}

.signal-dot.inactive {
  background: var(--text-secondary);
}

.signal-text {
  white-space: nowrap;
}

.signal-badge {
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.add-task-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 25px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 24px;
  transition: background 0.2s;
}

.add-task-btn:hover {
  background: var(--accent-hover);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  color: var(--text-primary);
  text-decoration: none;
  padding: 12px 16px;
  border-radius: 8px;
  transition: background 0.2s;
}

.nav-item:hover {
  background: var(--bg-hover);
}

.nav-item.active {
  background: var(--bg-card);
  font-weight: 600;
}

/* Main Content */
.main {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

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

.header h1 {
  font-size: 24px;
}

.last-sync {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Kanban Board */
.kanban {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kanban-column {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
  min-height: 400px;
}

.column-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.column-header h3 {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.column-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.column-dot.todo { background: var(--dot-todo); }
.column-dot.in_progress { background: var(--dot-progress); }
.column-dot.done { background: var(--dot-done); }
.column-dot.archived { background: var(--dot-archive); }

.count {
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.tasks {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-card {
  background: var(--bg-card);
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  position: relative;
}

.task-card:hover {
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.task-card h4 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.task-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.task-card:hover .task-delete-btn {
  opacity: 1;
}

.task-delete-btn:hover {
  color: var(--danger);
  background: rgba(244, 33, 46, 0.1);
}

.archive-all-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.archive-all-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.task-card .meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 8px;
}

.priority-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.priority-badge.urgent { background: var(--danger); color: white; }
.priority-badge.high { background: var(--warning); color: black; }
.priority-badge.medium { background: var(--accent); color: white; }
.priority-badge.low { background: var(--bg-hover); color: var(--text-secondary); }

.add-inline {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  margin-top: 8px;
  transition: border-color 0.2s, color 0.2s;
}

.add-inline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Bottom Section */
.bottom-section {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.notes-section {
  background: var(--bg-secondary);
  border-radius: 12px;
  padding: 16px;
}

.notes-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.section-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warning);
}

.notes-hint {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 12px;
}

#notes-list {
  margin-bottom: 12px;
}

.note-item {
  background: var(--bg-card);
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.note-item button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
}

.note-item button:hover {
  color: var(--danger);
}

.note-input {
  display: flex;
  gap: 8px;
}

.note-input input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 14px;
}

.note-input input:focus {
  outline: none;
  border-color: var(--accent);
}

.note-input button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}

/* Tabs */
.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Results Tab */
.results-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-card {
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: 8px;
  cursor: pointer;
}

.result-card:hover {
  background: var(--bg-card);
}

.result-card h4 {
  margin-bottom: 8px;
}

.result-card .preview {
  color: var(--text-secondary);
  font-size: 13px;
  white-space: pre-wrap;
}

/* Index Tab */
.index-status {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat {
  background: var(--bg-secondary);
  padding: 20px;
  border-radius: 12px;
  text-align: center;
}

.stat-label {
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
}

.pending-files {
  background: var(--bg-secondary);
  padding: 16px;
  border-radius: 12px;
}

.pending-files h3 {
  margin-bottom: 12px;
}

.pending-files ul {
  list-style: none;
}

.pending-files li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  padding: 24px;
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
}

.modal-content h2 {
  margin-bottom: 16px;
}

.modal-content input,
.modal-content textarea,
.modal-content select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text-primary);
  font-size: 14px;
  margin-bottom: 12px;
}

.modal-content textarea {
  min-height: 100px;
  resize: vertical;
}

.modal-content input:focus,
.modal-content textarea:focus,
.modal-content select:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
}

.btn-danger {
  background: var(--danger);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
}

/* Task Detail */
.task-detail .detail-meta {
  display: flex;
  gap: 12px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.task-detail .detail-results {
  background: var(--bg-card);
  padding: 16px;
  border-radius: 8px;
  font-size: 13px;
  max-height: 300px;
  overflow-y: auto;
}

/* Result Viewer Modal */
.result-viewer {
  max-width: 800px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.result-header h2 {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

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

.result-viewer .markdown-body {
  overflow-y: auto;
  flex: 1;
}

/* Markdown Styling */
.markdown-body {
  color: var(--text-primary);
  line-height: 1.6;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  color: var(--text-primary);
  margin: 16px 0 8px 0;
  font-weight: 600;
}

.markdown-body h1 { font-size: 1.5em; }
.markdown-body h2 { font-size: 1.3em; }
.markdown-body h3 { font-size: 1.1em; }

.markdown-body p {
  margin: 8px 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 8px 0;
  padding-left: 24px;
}

.markdown-body li {
  margin: 4px 0;
}

.markdown-body code {
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 0.9em;
}

.markdown-body pre {
  background: var(--bg-card);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
}

.markdown-body pre code {
  background: none;
  padding: 0;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 12px 0;
  padding-left: 16px;
  color: var(--text-secondary);
}

.markdown-body a {
  color: var(--accent);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.markdown-body th {
  background: var(--bg-card);
  font-weight: 600;
}

/* Chat Tab */
.chat-container {
  height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 0;
}

.chat-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 16px;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chat-bubble-content {
  font-size: 14px;
  line-height: 1.5;
}

.chat-time {
  font-size: 11px;
  margin-top: 4px;
  opacity: 0.6;
}

.chat-bubble.user .chat-time {
  text-align: right;
}

.chat-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 60px 20px;
  font-size: 15px;
}

/* Responsive */
@media (max-width: 1200px) {
  .kanban {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    flex-direction: row;
    padding: 12px;
    z-index: 100;
  }

  .avatar-section {
    display: none;
  }

  .add-task-btn {
    margin: 0;
  }

  .nav {
    flex-direction: row;
    flex: 1;
    justify-content: center;
  }

  .main {
    margin-bottom: 80px;
  }

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