:root {
  --bg-app: #0f1117;
  --bg-sidebar: #161b22;
  --bg-panel: #1c2128;
  --bg-input: #252b33;
  --border: #30363d;
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --accent-bg: rgba(56, 139, 253, 0.15);
  --bubble-user: #1f6feb;
  --bubble-assistant: #252b33;
  --danger: #da3633;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

/* --- Layout --- */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
}

.right-sidebar {
  width: 320px;
  background-color: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-app);
  position: relative;
  min-width: 0;
}

/* --- Chat Header --- */
.chat-header {
  height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
}

.logo-icon {
  color: var(--accent);
  display: flex;
}

.header-stats {
  display: flex;
  gap: 12px;
}

.stat-pill {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-input);
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
}

.stat-pill .val {
  color: var(--text-primary);
  font-weight: 600;
  margin-right: 4px;
}

/* --- Chat Area --- */
.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-secondary);
  max-width: 400px;
}

.empty-icon {
  margin-bottom: 16px;
  color: var(--bg-input);
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 85%;
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.role {
  font-size: 11px;
  color: var(--text-secondary);
  margin: 0 4px;
}

.bubble {
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
}

.bubble.user {
  background-color: var(--bubble-user);
  color: white;
  border-bottom-right-radius: 2px;
}

.bubble.assistant {
  background-color: var(--bubble-assistant);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

/* Markdown Styles inside bubbles */
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin: 0; }
.bubble pre {
  background: rgba(0,0,0,0.3);
  padding: 10px;
  border-radius: 6px;
  overflow-x: auto;
  font-family: monospace;
  margin: 10px 0;
}
.bubble code {
  background: rgba(0,0,0,0.3);
  padding: 2px 4px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}
.bubble ul, .bubble ol {
  margin: 10px 0;
  padding-left: 20px;
}
.bubble li { margin-bottom: 4px; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble strong { font-weight: 600; color: #fff; }

/* Chat Input */
.chat-input-area {
  padding: 24px;
  background-color: var(--bg-app);
}

.chat-form {
  max-width: 800px;
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  align-items: center;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 16px;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  font-family: var(--font-sans);
}

.send-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-right: 0;
  transition: opacity 0.2s;
}

.send-btn:hover {
  opacity: 0.9;
}

/* --- Right Sidebar --- */
.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  height: 60px;
  display: flex;
  align-items: center;
}

.panel-title {
  font-weight: 600;
  font-size: 14px;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  padding-left: 4px;
  font-weight: 600;
}

/* Upload */
.upload-section {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(255,255,255,0.02);
}

.upload-area:hover {
  border-color: var(--accent);
  background: var(--bg-input);
}

.upload-icon {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.hidden-input { display: none; }

.upload-options {
  margin-top: 12px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Documents List */
.documents-section {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}

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

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.doc-info {
  flex: 1;
  min-width: 0;
}

.doc-title {
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.doc-date {
  font-size: 11px;
  color: var(--text-secondary);
}

.doc-actions {
  margin-left: 8px;
}

.del-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: all 0.2s;
}

.del-btn:hover {
  color: var(--danger);
  background: rgba(218, 54, 51, 0.1);
}

/* Log */
.log-container {
  padding: 20px;
  border-top: 1px solid var(--border);
  height: 140px;
  display: flex;
  flex-direction: column;
}

.activity-log {
  flex: 1;
  background-color: #0d1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: monospace;
  font-size: 10px;
  color: var(--text-secondary);
  overflow-y: auto;
  white-space: pre-wrap;
  margin: 0;
}

@media (max-width: 900px) {
  .right-sidebar {
    display: none;
  }
}
