/* ── RESET & BASE ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

:root {
  --bg:        #0c0e14;
  --bg2:       #12151f;
  --bg3:       #181c28;
  --bg4:       #1e2333;
  --border:    rgba(255,255,255,0.06);
  --border2:   rgba(255,255,255,0.11);
  --border3:   rgba(255,255,255,0.18);
  --accent:    #7c6dfa;
  --accent2:   #a78bfa;
  --accent-bg: rgba(124,109,250,0.12);
  --green:     #34d399;
  --green-bg:  rgba(52,211,153,0.10);
  --amber:     #fbbf24;
  --amber-bg:  rgba(251,191,36,0.10);
  --red:       #f87171;
  --red-bg:    rgba(248,113,113,0.10);
  --blue:      #60a5fa;
  --blue-bg:   rgba(96,165,250,0.10);
  --text:      #e4e6f0;
  --text2:     #8b8fa8;
  --text3:     #4e5168;
  --r:         10px;
  --rlg:       16px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── HEADER ──────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
  z-index: 10;
}
.logo { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.logo-icon {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, #7c6dfa 0%, #a78bfa 100%);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; flex-shrink: 0;
}
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -0.4px; color: var(--text); }
.logo-text span { color: var(--accent2); }
.header-pills { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill {
  font-size: 11px; padding: 3px 9px;
  border-radius: 20px; font-weight: 500; white-space: nowrap;
}
.pill-model { background: var(--accent-bg); color: var(--accent2); border: 1px solid rgba(124,109,250,0.2); font-family: 'Courier New', monospace; font-size: 10px; }
.pill-free  { background: var(--green-bg);  color: var(--green);  border: 1px solid rgba(52,211,153,0.2); }
.pill-rate  { background: var(--amber-bg);  color: var(--amber);  border: 1px solid rgba(251,191,36,0.2); }

/* ── LAYOUT ──────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── SIDEBAR ─────────────────────────────────────────────────────── */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sb-block { padding: 16px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.sb-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 10px;
}

/* MODEL FALLBACK STATUS */
.model-status {
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: var(--r); padding: 10px 12px; font-size: 11px;
}
.model-row { display: flex; align-items: center; gap: 6px; padding: 3px 0; color: var(--text2); }
.model-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text3); flex-shrink: 0; transition: background 0.3s;
}
.model-dot.active { background: var(--green); box-shadow: 0 0 4px var(--green); }
.model-dot.error  { background: var(--red); }
.model-dot.warn   { background: var(--amber); }
.model-name { font-family: 'Courier New', monospace; font-size: 10px; flex: 1; }
.model-label { font-size: 10px; color: var(--text3); }

/* UPLOAD */
.drop-zone {
  border: 1.5px dashed var(--border3);
  border-radius: var(--rlg); padding: 24px 14px;
  text-align: center; cursor: pointer; transition: all 0.2s;
  background: var(--bg3); position: relative;
}
.drop-zone:hover, .drop-zone.drag { border-color: var(--accent); background: var(--accent-bg); }
.drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.drop-icon  { font-size: 26px; margin-bottom: 7px; }
.drop-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.drop-sub   { font-size: 11px; color: var(--text2); }

/* PROGRESS */
.progress-wrap { margin-top: 12px; }
.progress-label { font-size: 11px; color: var(--text2); margin-bottom: 5px; display: flex; justify-content: space-between; }
.progress-bar { height: 3px; background: var(--border2); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--green)); border-radius: 3px; transition: width 0.4s ease; }
.pipeline-steps { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 8px; }
.step {
  font-size: 10px; padding: 2px 7px; border-radius: 20px;
  border: 1px solid var(--border2); color: var(--text3);
  font-weight: 600; letter-spacing: 0.02em;
  display: flex; align-items: center; gap: 3px; transition: all 0.25s;
}
.step.active { background: var(--accent-bg); color: var(--accent2); border-color: rgba(124,109,250,0.25); }
.step.done   { background: var(--green-bg);  color: var(--green);  border-color: rgba(52,211,153,0.2); }

/* DOC INFO */
.doc-card { background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--r); padding: 12px; margin-top: 10px; }
.doc-filename { font-size: 12px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 7px; }
.doc-pills { display: flex; gap: 5px; flex-wrap: wrap; }
.doc-pill  { font-size: 10px; padding: 2px 7px; border-radius: 20px; font-family: 'Courier New', monospace; }
.p-char    { background: var(--accent-bg); color: var(--accent2); border: 1px solid rgba(124,109,250,0.15); }
.p-chunk   { background: var(--green-bg);  color: var(--green);  border: 1px solid rgba(52,211,153,0.15); }
.p-tok     { background: var(--amber-bg);  color: var(--amber);  border: 1px solid rgba(251,191,36,0.15); }

/* CHUNKS LIST */
.chunks-header { padding: 12px 18px 8px; font-size: 10px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text3); flex-shrink: 0; }
.chunks-list { flex: 1; overflow-y: auto; padding: 0 10px 14px; display: flex; flex-direction: column; gap: 6px; }
.chunk-card { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--r); padding: 10px 12px; cursor: pointer; transition: all 0.15s; position: relative; }
.chunk-card:hover  { border-color: var(--border3); }
.chunk-card.active { border-color: var(--accent); background: var(--accent-bg); }
.chunk-num  { font-size: 10px; font-family: 'Courier New', monospace; color: var(--text3); margin-bottom: 4px; }
.chunk-text { font-size: 11px; color: var(--text2); line-height: 1.5; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.chunk-score { position: absolute; top: 7px; right: 7px; font-size: 9px; font-family: 'Courier New', monospace; background: var(--green-bg); color: var(--green); border: 1px solid rgba(52,211,153,0.2); padding: 1px 5px; border-radius: 20px; }
.chunks-empty { font-size: 12px; color: var(--text3); padding: 8px 8px; }

/* ── MAIN CHAT ───────────────────────────────────────────────────── */
.main-col { display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.chat-area { flex: 1; overflow-y: auto; padding: 26px 28px; display: flex; flex-direction: column; gap: 22px; min-height: 0; }

/* EMPTY STATE */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; flex: 1; padding: 40px; }
.empty-glyph { width: 68px; height: 68px; background: var(--bg3); border: 1px solid var(--border2); border-radius: 18px; display: flex; align-items: center; justify-content: center; font-size: 30px; }
.empty-title { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; }
.empty-desc  { font-size: 14px; color: var(--text2); max-width: 360px; line-height: 1.65; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; max-width: 420px; width: 100%; }
.sug-btn { background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--r); padding: 10px 12px; font-size: 12px; color: var(--text2); cursor: pointer; text-align: left; transition: all 0.15s; font-family: inherit; }
.sug-btn:hover { border-color: var(--accent); color: var(--accent2); background: var(--accent-bg); }

/* MESSAGES */
.msg-row { display: flex; gap: 10px; align-items: flex-start; }
.msg-row.user { flex-direction: row-reverse; }
.msg-avatar { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; margin-top: 2px; }
.msg-avatar.ai-av   { background: linear-gradient(135deg, #7c6dfa, #a78bfa); }
.msg-avatar.user-av { background: var(--bg4); border: 1px solid var(--border2); }
.msg-body { max-width: 73%; }
.msg-meta { font-size: 10px; color: var(--text3); margin-bottom: 4px; }
.msg-row.user .msg-meta { text-align: right; }
.bubble { border-radius: 14px; padding: 13px 15px; font-size: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; }
.bubble.ai   { background: var(--bg3); border: 1px solid var(--border2); color: var(--text); border-top-left-radius: 4px; }
.bubble.user { background: var(--accent-bg); border: 1px solid rgba(124,109,250,0.22); color: var(--text); border-top-right-radius: 4px; }

.sources-block { margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--border2); }
.sources-label { font-size: 10px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text3); margin-bottom: 7px; }
.source-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--green-bg); border: 1px solid rgba(52,211,153,0.18); color: var(--green); font-size: 10px; padding: 2px 7px; border-radius: 20px; font-family: 'Courier New', monospace; margin: 0 3px 3px 0; cursor: pointer; transition: all 0.15s; }
.source-chip:hover { background: rgba(52,211,153,0.2); }
.model-used { font-size: 10px; color: var(--text3); margin-top: 6px; font-family: 'Courier New', monospace; }

/* THINKING */
.thinking-row { display: flex; gap: 10px; align-items: flex-start; }
.thinking-bubble { background: var(--bg3); border: 1px solid var(--border2); border-radius: 14px; border-top-left-radius: 4px; padding: 13px 15px; display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text2); }
.dots { display: flex; gap: 4px; }
.dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); animation: bounce 1.3s ease-in-out infinite; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%,60%,100% { transform: translateY(0); opacity: 0.35; }
  30%          { transform: translateY(-6px); opacity: 1; }
}

/* RETRY NOTICE */
.retry-notice { font-size: 11px; color: var(--amber); background: var(--amber-bg); border: 1px solid rgba(251,191,36,0.18); border-radius: 8px; padding: 6px 10px; margin: 0 28px; display: none; }

/* ERROR BAR */
.error-bar { background: var(--red-bg); border: 1px solid rgba(248,113,113,0.2); color: var(--red); padding: 9px 14px; border-radius: var(--r); font-size: 13px; margin: 0 28px; display: none; }

/* INPUT BAR */
.input-bar { padding: 14px 22px; border-top: 1px solid var(--border); background: var(--bg2); display: flex; gap: 9px; align-items: flex-end; flex-shrink: 0; }
.input-wrap { flex: 1; }
.chat-input { width: 100%; background: var(--bg3); border: 1px solid var(--border2); border-radius: 12px; padding: 11px 15px; font-size: 14px; font-family: inherit; color: var(--text); outline: none; resize: none; min-height: 46px; max-height: 150px; overflow-y: auto; line-height: 1.5; transition: border-color 0.2s; }
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text3); }
.send-btn { width: 44px; height: 44px; background: var(--accent); border: none; border-radius: 10px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 17px; flex-shrink: 0; color: #fff; transition: all 0.15s; }
.send-btn:hover:not(:disabled) { background: var(--accent2); transform: scale(1.05); }
.send-btn:disabled { background: var(--bg4); border: 1px solid var(--border2); cursor: not-allowed; color: var(--text3); transform: none; }

/* SCROLLBARS */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* RESPONSIVE */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
