/* === Variables === */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;
  --border-color: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
[x-cloak] { display: none !important; }

/* === Loading === */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 1rem;
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-inline {
  padding: 2rem;
  text-align: center;
  color: var(--text-secondary);
}

/* === Login Screen === */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, var(--bg-primary) 0%, #1a1f2e 100%);
}
.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3rem;
  text-align: center;
  max-width: 400px;
  width: 100%;
}
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.login-card h1 {
  font-size: 1.75rem;
  font-weight: 600;
}
.login-subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.875rem 1.5rem;
  background: #fff;
  color: #1f1f1f;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-google:hover {
  background: #f1f1f1;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.login-note {
  margin-top: 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* === App Container === */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
}

/* === Header === */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.tars-logo {
  height: 2rem;
  width: auto;
  object-fit: contain;
}
.header-left h1 {
  font-size: 1.25rem;
  font-weight: 600;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.user-name {
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}
.btn-icon {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}
.btn-icon:hover {
  background: var(--bg-hover);
}

/* === Tabs === */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
  padding: 0 1rem;
}
.tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}
.tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* === Tab Content === */
.tab-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.tab-pane {
  flex: 1;
  overflow: auto;
  padding: 1.5rem;
}
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.pane-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
}
.empty-state p { margin-bottom: 1rem; }

/* === Buttons === */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.625rem 1.25rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover {
  background: var(--bg-hover);
}
.btn-link {
  color: var(--accent);
  font-size: 0.85rem;
}
.btn-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
}
.btn-close:hover { color: var(--text-primary); }

/* === Calendar Tab === */
.calendar-container {
  height: 100%;
  min-height: 600px;
}
.calendar-container iframe {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

/* === Kanban Board === */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.kanban-column {
  display: flex;
  flex-direction: column;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  min-height: 200px;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}
.kanban-column.drag-over {
  border-color: var(--accent);
}
.kanban-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.25rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.kanban-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-todo { background: var(--text-muted); }
.dot-inprogress { background: var(--accent); }
.dot-done { background: var(--success); }
.kanban-count {
  margin-left: auto;
  background: var(--bg-hover);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
}
.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}
.kanban-card {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: grab;
  transition: all 0.2s;
  text-decoration: none;
  color: inherit;
}
.kanban-card:hover {
  border-color: var(--bg-hover);
  background: var(--bg-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  color: inherit;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.4; }
.kanban-card .todo-key {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}
.kanban-summary {
  color: var(--text-primary);
  font-size: 0.9rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}
.kanban-status {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}
.kanban-card .todo-due {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-left: auto;
}
.kanban-empty {
  grid-column: 1 / -1;
}

/* === Projects Tab === */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.project-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  transition: all 0.2s;
}
.project-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.project-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.project-excerpt {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.project-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* === Chat Tab === */
.chat-pane {
  display: flex;
  flex-direction: column;
  padding: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}
.chat-welcome {
  text-align: center;
  padding: 3rem 1rem;
}
.chat-welcome h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}
.chat-welcome p {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}
.quick-action {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.625rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}
.quick-action:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.chat-message {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-weight: 600;
  font-size: 0.9rem;
}
.chat-message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--accent), #a855f7);
}
.message-content {
  flex: 1;
  min-width: 0;
}
.message-text {
  line-height: 1.6;
}
.message-text p { margin-bottom: 0.75rem; }
.message-text p:last-child { margin-bottom: 0; }
.message-text ul, .message-text ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}
.message-text li { margin-bottom: 0.25rem; }
.message-text code {
  font-family: var(--font-mono);
  background: var(--bg-tertiary);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-size: 0.85em;
}
.message-text pre {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.75rem 0;
}
.message-text pre code {
  background: none;
  padding: 0;
}
.message-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.tool-badge {
  font-size: 0.75rem;
  background: var(--bg-tertiary);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.5rem 0;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.chat-context-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}
.chat-context-track {
  flex: 1;
  height: 4px;
  background: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}
.chat-context-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}
.chat-context-fill.warning {
  background: #e67e22;
}
.chat-context-fill.critical {
  background: #e74c3c;
}
.chat-context-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.btn-compact {
  font-size: 0.65rem;
  padding: 0.15rem 0.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.btn-compact:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-compact:disabled {
  opacity: 0.4;
  cursor: default;
}
.chat-input-container {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}
.btn-clear-chat {
  flex-shrink: 0;
  font-size: 1rem;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.btn-clear-chat:hover {
  opacity: 1;
}
.chat-input-container textarea {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  resize: none;
  min-height: 44px;
  max-height: 200px;
}
.chat-input-container textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.chat-input-container textarea::placeholder {
  color: var(--text-muted);
}
.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) {
  background: var(--accent-hover);
}
.btn-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-small { max-width: 400px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}
.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}
.modal-content {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
}

/* === Settings === */
.setting-group {
  margin-bottom: 2rem;
}
.setting-group:last-child { margin-bottom: 0; }
.setting-group h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-secondary);
}
.setting-label {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}
.setting-label:last-child { margin-bottom: 0; }
.setting-label span {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.setting-label input,
.setting-label select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.875rem;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
.setting-label input:focus,
.setting-label select:focus {
  outline: none;
  border-color: var(--accent);
}
.setting-label small {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.setting-label small a {
  color: var(--accent);
}

/* === Atlassian Connect === */
.setting-description {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}
.btn-atlassian {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.875rem 1.5rem;
  background: #0052CC;
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-atlassian:hover {
  background: #0065FF;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
}
.btn-atlassian svg {
  flex-shrink: 0;
}
.atlassian-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
}
.connected-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.connected {
  background: var(--success);
}
.btn-disconnect {
  background: none;
  border: none;
  color: var(--danger);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.btn-disconnect:hover {
  background: rgba(248, 81, 73, 0.1);
}

/* === Toggle Switch === */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.toggle-btn {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
  flex-shrink: 0;
}
.toggle-btn .toggle-slider {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all 0.2s;
}
.toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-btn.active .toggle-slider {
  left: 22px;
  background: #fff;
}

/* === Auto-Compact Settings === */
.compact-settings {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
}
.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.slider-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.range-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}
.slider-value {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 3rem;
  text-align: right;
}
.context-usage {
  margin-top: 0.5rem;
}
.context-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}
.context-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}
.context-bar-fill.warning {
  background: #e67e22;
}
.context-usage small {
  color: var(--text-muted);
  margin-top: 0.25rem;
  display: block;
}

/* === Responsive === */
@media (max-width: 768px) {
  .tab { padding: 1rem; }
  .header-left h1 { display: none; }
  .user-name { display: none; }
  .quick-actions { flex-direction: column; }
  .projects-grid { grid-template-columns: 1fr; }
  .kanban-board { grid-template-columns: 1fr; }
}
