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

:root {
  --bg: #0d1117;
  --sidebar-bg: #13181f;
  --surface: #1c2230;
  --surface-hover: #232d3d;
  --border: #2a3346;
  --text: #e2e8f0;
  --text-secondary: #7a8ba6;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-dim: rgba(59,130,246,0.12);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --sidebar-w: 300px;
}

html, body { height: 100%; font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

body { display: flex; overflow: hidden; }

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header { padding: 20px 18px 16px; border-bottom: 1px solid var(--border); }

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

.logo-icon {
  width: 38px; height: 38px;
  background: var(--accent-dim);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.logo-name { display: block; font-size: 15px; font-weight: 600; color: var(--text); }
.logo-sub { display: block; font-size: 11px; color: var(--text-secondary); margin-top: 1px; }

.sidebar-section { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 12px; }

.section-label { font-size: 10px; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.08em; padding: 0 4px; }

/* Upload area */
.upload-area {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: transparent;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.upload-area.drag-over { transform: scale(1.01); }

.upload-icon { color: var(--text-secondary); margin-bottom: 8px; }
.upload-area:hover .upload-icon, .upload-area.drag-over .upload-icon { color: var(--accent); }
.upload-title { font-size: 12px; font-weight: 500; color: var(--text); margin-bottom: 3px; }
.upload-hint { font-size: 11px; color: var(--text-secondary); }

/* Doc list */
.doc-list { display: flex; flex-direction: column; gap: 6px; }

.empty-docs { text-align: center; padding: 16px 8px; color: var(--text-secondary); font-size: 12px; }

.doc-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.doc-icon {
  width: 30px; height: 30px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}
.doc-icon.pdf { background: rgba(239,68,68,0.15); }
.doc-icon.excel { background: rgba(34,197,94,0.15); }
.doc-icon.word { background: rgba(59,130,246,0.15); }
.doc-icon.image { background: rgba(168,85,247,0.15); }

.doc-info { flex: 1; min-width: 0; }
.doc-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-size { font-size: 10px; color: var(--text-secondary); margin-top: 1px; }

.doc-delete {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 4px; border-radius: 5px;
  transition: all 0.15s; flex-shrink: 0;
}
.doc-delete:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* Uploading indicator */
.doc-item.uploading { opacity: 0.7; }
.upload-progress { width: 100%; height: 2px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 4px; }
.upload-progress-bar { height: 100%; background: var(--accent); width: 0%; animation: progress 1.5s ease infinite; }
@keyframes progress { 0% { width: 0%; } 50% { width: 70%; } 100% { width: 100%; } }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.api-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); flex-shrink: 0; }
.status-dot.ok { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.error { background: var(--danger); }

/* ── MAIN ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header-left { display: flex; align-items: center; gap: 12px; }
.chat-title { font-size: 17px; font-weight: 600; }
.doc-count { font-size: 12px; color: var(--text-secondary); background: var(--surface); border: 1px solid var(--border); padding: 2px 10px; border-radius: 20px; }

.clear-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 12px; padding: 6px 12px;
  border-radius: 7px; cursor: pointer; transition: all 0.15s;
  font-family: inherit;
}
.clear-btn:hover { border-color: var(--danger); color: var(--danger); background: rgba(239,68,68,0.08); }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; padding: 24px;
  display: flex; flex-direction: column; gap: 20px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* Welcome */
.welcome-msg { text-align: center; margin: auto; max-width: 480px; padding: 40px 20px; }
.welcome-icon { color: var(--accent); margin-bottom: 16px; opacity: 0.7; }
.welcome-msg h2 { font-size: 22px; font-weight: 600; margin-bottom: 8px; }
.welcome-msg p { color: var(--text-secondary); font-size: 14px; line-height: 1.6; }
.welcome-examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.example-btn {
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 12px; padding: 8px 14px;
  border-radius: 20px; cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.example-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* Message bubbles */
.message { display: flex; flex-direction: column; max-width: 800px; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.msg-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 5px; font-weight: 500; }

.msg-bubble {
  padding: 13px 17px;
  border-radius: 14px;
  line-height: 1.65;
  max-width: 100%;
}

.message.user .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* Markdown w odpowiedziach AI */
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin: 12px 0 6px; font-weight: 600; }
.msg-bubble h1 { font-size: 17px; }
.msg-bubble h2 { font-size: 15px; }
.msg-bubble h3 { font-size: 14px; }
.msg-bubble p { margin: 6px 0; }
.msg-bubble ul, .msg-bubble ol { margin: 8px 0; padding-left: 20px; }
.msg-bubble li { margin: 4px 0; }
.msg-bubble code { background: rgba(0,0,0,0.3); padding: 1px 6px; border-radius: 4px; font-size: 12px; font-family: 'SF Mono', monospace; }
.msg-bubble pre { background: rgba(0,0,0,0.3); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 10px 0; }
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
.msg-bubble th { background: rgba(59,130,246,0.15); padding: 7px 12px; text-align: left; font-weight: 600; border: 1px solid var(--border); }
.msg-bubble td { padding: 6px 12px; border: 1px solid var(--border); }
.msg-bubble tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
.msg-bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-secondary); margin: 8px 0; }

/* Export buttons */
.cache-badge { font-size: 10px; background: rgba(34,197,94,0.15); color: var(--success); border: 1px solid rgba(34,197,94,0.3); padding: 1px 7px; border-radius: 10px; font-weight: 500; vertical-align: middle; }
.msg-actions { display: flex; gap: 6px; margin-top: 7px; }
.export-btn {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 11px; font-family: inherit;
  padding: 4px 10px; border-radius: 6px; cursor: pointer; transition: all 0.15s;
}
.export-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.export-btn.excel:hover { border-color: var(--success); color: var(--success); background: rgba(34,197,94,0.1); }

/* Typing indicator */
.typing-indicator { display: flex; align-items: center; gap: 5px; padding: 14px 18px; }
.typing-dot { width: 7px; height: 7px; background: var(--text-secondary); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* Input area */
.input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-wrapper { display: flex; gap: 10px; align-items: flex-end; }

textarea#messageInput {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 12px 16px;
  resize: none;
  max-height: 180px;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.5;
}
textarea#messageInput:focus { border-color: var(--accent); }
textarea#messageInput::placeholder { color: var(--text-secondary); }

.send-btn {
  width: 44px; height: 44px;
  background: var(--accent);
  border: none; border-radius: 11px;
  color: #fff; 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); transform: scale(1.05); }
.send-btn:disabled { background: var(--surface); color: var(--text-secondary); cursor: not-allowed; transform: none; }

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

/* Toast notifications */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  min-width: 240px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.25s ease;
  display: flex; align-items: center; gap: 10px;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.toast.success { border-color: rgba(34,197,94,0.4); }
.toast.error { border-color: rgba(239,68,68,0.4); }
.toast-icon.success { color: var(--success); }
.toast-icon.error { color: var(--danger); }
