@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@300;400;500;600&display=swap');

:root {
  --bg-base:      #0d0f12;
  --bg-panel:     #13161b;
  --bg-card:      #1a1e26;
  --bg-hover:     #21262f;
  --border:       #2a3040;
  --border-focus: #4a7cdc;
  --accent:       #4a7cdc;
  --accent-dim:   #2a4a8a;
  --accent-glow:  rgba(74,124,220,0.15);
  --green:        #3dd68c;
  --green-dim:    #1a5c3a;
  --amber:        #f0a500;
  --red:          #e05c5c;
  --text-primary: #e2e8f0;
  --text-secondary:#8a95a8;
  --text-muted:   #4a5568;
  --mono:         'IBM Plex Mono', monospace;
  --sans:         'IBM Plex Sans', sans-serif;
  --radius:       6px;
  --transition:   0.15s ease;
}

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

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Layout shell ──────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: 48px 1fr;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────── */
#header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.logo {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.logo span { color: var(--text-secondary); font-weight: 400; }

#project-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 20px;
}

#project-selector label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

select, input[type="text"], textarea {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 13px;
  border-radius: var(--radius);
  padding: 5px 10px;
  outline: none;
  transition: border-color var(--transition);
}
select:focus, input:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#project-select { min-width: 180px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.btn.primary:hover { background: var(--accent); color: #fff; }
.btn.danger  { border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn.success { border-color: var(--green); color: var(--green); }
.btn.success:hover { background: var(--green); color: #000; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-muted); padding: 3px 6px; }
.btn.ghost:hover { background: var(--bg-hover); border-color: var(--border); color: var(--text-primary); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.icon { padding: 4px 6px; min-width: 24px; justify-content: center; }

#ws-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  transition: background var(--transition);
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }

/* ── Sidebar ──────────────────────────────────────────────────── */
#sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.sidebar-section {
  border-bottom: 1px solid var(--border);
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-weight: 600;
}

/* Upload area */
#upload-area {
  margin: 10px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  font-size: 12px;
  color: var(--text-secondary);
}
#upload-area:hover, #upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
}
#upload-area svg { margin-bottom: 6px; }

/* Project file list */
#file-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 14px;
  transition: background var(--transition);
  border-left: 2px solid transparent;
  group: true;
}
.file-item:hover { background: var(--bg-hover); }
.file-item:hover .file-remove { opacity: 1; }

.file-lang-badge {
  font-family: var(--mono);
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  text-transform: uppercase;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
}
.lang-python { border-color: #3776ab; color: #3776ab; }
.lang-java   { border-color: #b07219; color: #b07219; }
.lang-cpp, .lang-c { border-color: #555555; color: #aaa; }
.lang-javascript { border-color: #f1e05a; color: #f1e05a; }
.lang-cobol  { border-color: #8b4513; color: #cd853f; }
.lang-makefile { border-color: #427819; color: #7dc52e; }
.lang-unkn { border-color: #444; color: #666; }

.file-name {
  font-size: 12px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}
.file-indexed { color: var(--green); font-size: 10px; flex-shrink: 0; }
.file-pending { color: var(--amber); font-size: 10px; flex-shrink: 0; }

.file-remove {
  opacity: 0;
  transition: opacity var(--transition);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}
.file-remove:hover { color: var(--red); background: rgba(224,92,92,0.1); }

/* Actions panel */
#actions-panel {
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.action-btn {
  width: 100%;
  justify-content: flex-start;
  padding: 8px 12px;
  font-size: 12px;
}

/* Add from library button */
#add-from-library-btn {
  margin: 8px 14px;
  width: calc(100% - 28px);
  justify-content: center;
  font-size: 11px;
  border-style: dashed;
}

/* ── Libreria pannello (slide-in) ─────────────────────────────── */
#library-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 20;
  transform: translateX(-100%);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
#library-panel.open {
  transform: translateX(0);
}

#library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#library-header h3 {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#library-search {
  margin: 10px 14px;
  width: calc(100% - 28px);
  font-size: 12px;
  padding: 6px 10px;
  flex-shrink: 0;
}

#library-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.library-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid rgba(42,48,64,0.5);
  transition: background var(--transition);
  cursor: pointer;
}
.library-item:hover { background: var(--bg-hover); }
.library-item.checked { background: var(--accent-glow); }

.library-item input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  cursor: pointer;
}

.library-item-info {
  flex: 1;
  min-width: 0;
}
.library-item-name {
  font-size: 12px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-item-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  font-family: var(--mono);
}
.library-item-projects {
  font-size: 10px;
  color: var(--accent);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#library-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
#library-footer .btn { flex: 1; justify-content: center; font-size: 11px; }

/* ── Main area ────────────────────────────────────────────────── */
#main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

/* Welcome */
#welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
}
#welcome h2 { font-family: var(--mono); font-size: 18px; color: var(--text-secondary); font-weight: 400; }
#welcome p { font-size: 13px; max-width: 360px; line-height: 1.6; }

/* Chat */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-message { display: flex; flex-direction: column; gap: 4px; max-width: 900px; }
.chat-message.user { align-self: flex-end; }
.chat-message.assistant { align-self: flex-start; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.chat-message.user .chat-bubble { background: var(--accent-dim); border: 1px solid var(--accent); color: var(--text-primary); }
.chat-message.assistant .chat-bubble { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); }

.chat-role { font-size: 10px; font-family: var(--mono); color: var(--text-muted); padding: 0 2px; }
.chat-message.user .chat-role { text-align: right; }

.chat-bubble pre {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
}

.confirm-widget {
  background: var(--bg-card);
  border: 1px solid var(--amber);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.confirm-widget p { font-size: 13px; color: var(--amber); }
.confirm-widget .actions { display: flex; gap: 8px; }

/* Input area */
#input-area {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#input-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mode-badge {
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 3px;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
  cursor: pointer;
}
.mode-badge:hover { background: var(--accent); color: #fff; }
#input-row { display: flex; gap: 8px; align-items: flex-end; }
#chat-input {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: var(--radius);
}

/* Modals */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal h3 { font-family: var(--mono); font-size: 14px; color: var(--accent); font-weight: 500; }
.modal label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; display: block; margin-bottom: 4px; }
.modal input { width: 100%; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Status area in chat bubble */
#status-area div {
  display: flex;
  align-items: center;
  gap: 6px;
}
#status-area div::before {
  content: '';
  display: inline-block;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.5s infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Typing indicator */
.typing-dots span {
  display: inline-block;
  width: 5px; height: 5px;
  background: var(--accent);
  border-radius: 50%;
  margin: 0 2px;
  animation: typing 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 12px;
  z-index: 200;
  animation: slideIn 0.2s ease;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red);   color: var(--red); }
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Empty state */
.empty-state {
  padding: 20px 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.6;
}
