/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0d1117;
  --sidebar-bg:   #161b22;
  --panel-bg:     #1c2128;
  --card-bg:      #21262d;
  --hover-bg:     #2d333b;
  --accent:       #2563eb;
  --accent-h:     #1d4ed8;
  --accent-dim:   rgba(37,99,235,0.15);
  --success:      #16a34a;
  --warn:         #d97706;
  --error:        #dc2626;
  --text:         #e6edf3;
  --text-muted:   #8b949e;
  --border:       #30363d;
  --msg-user:     #1e3a5f;
  --msg-ai:       #21262d;
  --radius:       8px;
  --radius-lg:    12px;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ─────────────── SCROLLBAR ─────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─────────────── LAYOUT ─────────────── */
.app {
  display: grid;
  grid-template-columns: 270px 1fr 380px;
  height: 100vh;
}

/* ─────────────── SIDEBAR ─────────────── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
}

.sidebar-header h1 {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#btn-new {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  transition: background 0.18s;
}
#btn-new:hover { background: var(--accent-h); }

.project-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.project-item {
  padding: 9px 11px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 3px;
  border: 1px solid transparent;
  position: relative;
}
.project-item:hover { background: var(--hover-bg); }
.project-item.active {
  background: var(--accent-dim);
  border-color: rgba(37,99,235,0.35);
}

.project-item-header {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
}

.project-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.badge-pdf {
  background: rgba(217,119,6,0.18);
  color: #fbbf24;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid rgba(217,119,6,0.35);
  flex-shrink: 0;
}

.project-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}

.project-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.project-item:hover .project-delete-btn { opacity: 1; }
.project-delete-btn:hover { color: var(--error); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 40px;
  padding: 0 16px;
}

/* ─────────────── CHAT PANEL ─────────────── */
.chat-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.chat-header {
  padding: 11px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  background: var(--panel-bg);
  min-height: 48px;
}

.mode-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.mode-create { background: rgba(22,163,74,0.18); color: #4ade80; border: 1px solid rgba(22,163,74,0.35); }
.mode-edit   { background: rgba(217,119,6,0.18);  color: #fbbf24; border: 1px solid rgba(217,119,6,0.35); }

.project-title {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message { display: flex; max-width: 88%; }
.message-user      { align-self: flex-end; }
.message-assistant { align-self: flex-start; }

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.55;
}

.message-user .message-bubble {
  background: var(--msg-user);
  border: 1px solid rgba(37,99,235,0.3);
  border-bottom-right-radius: 3px;
}
.message-assistant .message-bubble {
  background: var(--msg-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.message-text { white-space: pre-wrap; word-break: break-word; }

.pdf-attachment {
  font-size: 12px;
  color: #fbbf24;
  margin-bottom: 6px;
}

/* File cards inside assistant message */
.file-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.file-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
}
.file-card:hover { border-color: var(--accent); background: var(--accent-dim); }

.btn-preview-msg {
  background: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 4px 11px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.18s;
}
.btn-preview-msg:hover { background: var(--accent-dim); }

.message-system {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  padding: 12px;
}

/* Loading dots */
.loading-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
}
.loading-dots .dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.3s infinite ease-in-out;
}
.loading-dots .dot:nth-child(2) { animation-delay: 0.16s; }
.loading-dots .dot:nth-child(3) { animation-delay: 0.32s; }
.loading-label { color: var(--text-muted); font-size: 13px; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.75); opacity: 0.5; }
  40%            { transform: scale(1.1);  opacity: 1; }
}

/* Input area */
.input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
  flex-shrink: 0;
}

.input-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.btn-attach {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: color 0.18s, border-color 0.18s, background 0.18s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-attach:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

.pdf-badge {
  background: rgba(217,119,6,0.14);
  color: #fbbf24;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid rgba(217,119,6,0.3);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.pdf-badge:hover { background: rgba(220,38,38,0.14); color: #f87171; border-color: rgba(220,38,38,0.3); }

.hidden { display: none !important; }

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#prompt-input {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  line-height: 1.5;
  transition: border-color 0.18s;
}
#prompt-input:focus { outline: none; border-color: var(--accent); }
#prompt-input::placeholder { color: var(--text-muted); }

#btn-send {
  background: var(--accent);
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: background 0.18s, opacity 0.18s;
  align-self: flex-end;
}
#btn-send:hover { background: var(--accent-h); }
#btn-send:disabled { opacity: 0.45; cursor: default; }

/* ─────────────── FILE PANEL ─────────────── */
.file-panel {
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 12px 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.18s, border-color 0.18s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.tab-content.active { display: flex; }

/* File list */
.file-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background 0.15s;
}
.file-item:hover { background: var(--hover-bg); }
.file-item .file-icon { flex-shrink: 0; }
.file-item .file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* File viewer */
.file-viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.file-viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--panel-bg);
  gap: 8px;
}

.file-viewer-bar span {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-viewer-actions { display: flex; gap: 4px; flex-shrink: 0; }

.file-viewer-actions button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  transition: color 0.15s, border-color 0.15s;
}
.file-viewer-actions button:hover { color: var(--text); border-color: var(--text-muted); }

.file-viewer pre {
  flex: 1;
  overflow: auto;
  margin: 0;
  background: #0d1117 !important;
}

.file-viewer pre code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.65;
  display: block;
  padding: 12px 14px !important;
}

/* Preview */
.preview-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.preview-bar button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: color 0.15s, border-color 0.15s;
}
.preview-bar button:hover { color: var(--accent); border-color: var(--accent); }

.preview-frame {
  flex: 1;
  border: none;
  background: white;
}
