/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #0d0d0d;
  --bg-secondary: #171717;
  --bg-tertiary: #1e1e1e;
  --bg-hover: #2a2a2a;
  --bg-input: #1e1e1e;
  --bg-user-msg: #2f2f2f;
  --bg-agent-msg: transparent;
  --text-primary: #ececec;
  --text-secondary: #a0a0a0;
  --text-muted: #666;
  --border: #2e2e2e;
  --accent: #7c6fe0;
  --accent-hover: #6b5fd4;
  --status-ready: #22c55e;
  --status-waking: #f59e0b;
  --status-sleeping: #555;
  --scrollbar-thumb: #333;
  --scrollbar-track: transparent;
  --code-bg: #1a1a2e;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }

/* ===== Layout ===== */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== Sidebar ===== */
#sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 22px;
}

.logo-text {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

#new-chat-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

#new-chat-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 12px 0;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 4px 8px;
}

.sidebar-sessions {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.4;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  width: 100%;
  font-family: inherit;
  flex-shrink: 0;
}

.session-item:hover {
  background: var(--bg-hover);
  border-color: #444;
  color: var(--text-primary);
}

.session-item.active {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* ===== Sidebar Footer ===== */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.connections-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.4;
  transition: all 0.15s;
  text-align: left;
  width: 100%;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.connections-btn:hover {
  background: var(--bg-hover);
  border-color: #444;
  color: var(--text-primary);
}

.sidebar-footer-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 4px;
}

.dagster-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
}

.dagster-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.dagster-link.hidden { display: none; }

.powered-by {
  position: fixed;
  bottom: 12px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
  z-index: 10;
}

.powered-by:hover {
  color: var(--text-secondary);
}

.powered-by-logo {
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

/* ===== Agent Status ===== */

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

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--status-sleeping);
  transition: background 0.3s;
  flex-shrink: 0;
}

.status-dot.ready {
  background: var(--status-ready);
  box-shadow: 0 0 6px var(--status-ready);
}

.status-dot.waking {
  background: var(--status-waking);
  box-shadow: 0 0 6px var(--status-waking);
  animation: pulse 1.5s ease-in-out infinite;
}

.status-dot.sleeping {
  background: var(--status-sleeping);
}

.status-dot.error {
  background: #ef4444;
  box-shadow: 0 0 6px #ef4444;
}

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

/* ===== Main Area ===== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* ===== Welcome Screen ===== */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 12px;
}

.welcome.hidden { display: none; }

.welcome-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.welcome h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.welcome-sub {
  color: var(--text-secondary);
  font-size: 15px;
  max-width: 400px;
  text-align: center;
  line-height: 1.5;
}

.welcome-suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 24px;
  max-width: 560px;
  width: 100%;
}

.suggestion {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
  font-family: inherit;
}

.suggestion:hover {
  background: var(--bg-hover);
  border-color: #444;
  color: var(--text-primary);
}

/* ===== Messages ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}

.messages.hidden { display: none; }

.message {
  padding: 16px 0;
  animation: fadeIn 0.2s ease;
}

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

.message-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 24px;
}

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

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.message-avatar.user {
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 12px;
}

.message-avatar.agent {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

.message-sender {
  font-size: 13px;
  font-weight: 600;
}

.message-body {
  padding-left: 36px;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-primary);
}

.message-body p {
  margin-bottom: 12px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.message-body pre {
  background: var(--code-bg);
  padding: 14px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--border);
}

.message-body pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}

.message-body ul, .message-body ol {
  padding-left: 20px;
  margin-bottom: 12px;
}

.message-body li {
  margin-bottom: 4px;
}

.message-body strong {
  font-weight: 600;
}

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

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

.message-body h1, .message-body h2, .message-body h3 {
  margin: 16px 0 8px;
  font-weight: 600;
}

.message-body h1 { font-size: 20px; }
.message-body h2 { font-size: 17px; }
.message-body h3 { font-size: 15px; }

.message-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
}

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

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

/* Thinking indicator */
.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 36px;
  color: var(--text-muted);
  font-size: 13px;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.4s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* ===== Input Area ===== */
.input-area {
  padding: 0 24px 16px;
  max-width: 768px;
  margin: 0 auto;
  width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 16px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: #555;
}

#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 200px;
  padding: 6px 0;
}

#message-input::placeholder {
  color: var(--text-muted);
}

#send-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

#send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
}


/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 520px;
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

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

.modal-header h2 {
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
  line-height: 1;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* Connection list */
.conn-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conn-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.conn-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.conn-item-icon {
  font-size: 20px;
}

.conn-item-details {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conn-item-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.conn-item-type {
  font-size: 12px;
  color: var(--text-muted);
}

.conn-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  transition: all 0.15s;
}

.conn-delete-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.conn-empty {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 14px;
}

/* Add connection button */
.conn-add-btn {
  width: 100%;
  padding: 10px;
  margin-top: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

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

/* Connector picker grid */
.conn-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.conn-picker-item {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: all 0.15s;
}

.conn-picker-item:hover {
  background: var(--bg-hover);
  border-color: #444;
}

.conn-picker-icon {
  font-size: 22px;
  margin-bottom: 6px;
}

.conn-picker-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.conn-picker-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.3;
}

/* Connection form */
.conn-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.conn-form-back {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  padding: 0;
  margin-bottom: 4px;
  text-align: left;
  transition: color 0.15s;
}

.conn-form-back:hover {
  color: var(--text-primary);
}

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

.conn-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.conn-field label .required {
  color: #ef4444;
  margin-left: 2px;
}

.conn-field .field-help {
  font-size: 11px;
  color: var(--text-muted);
}

.conn-field input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.conn-field input:focus {
  border-color: var(--accent);
}

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

.conn-form-submit {
  padding: 10px;
  margin-top: 4px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.conn-form-submit:hover {
  background: var(--accent-hover);
}

.conn-form-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== File Upload ===== */
.file-input-hidden {
  display: none;
}

#attach-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 8px;
  transition: all 0.15s;
}

#attach-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.file-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
}

.file-preview.hidden { display: none; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.file-chip .remove-file {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
}

.file-chip .remove-file:hover {
  color: var(--text-primary);
}

.input-area.drag-over .input-wrapper {
  border-color: var(--accent);
  background: rgba(124, 111, 224, 0.05);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #sidebar {
    display: none;
  }

  .message-inner {
    padding: 0 16px;
  }

  .input-area {
    padding: 0 12px 12px;
  }

  .welcome-suggestions {
    grid-template-columns: 1fr;
  }
}
