/* ═══════════════ Buffy — shaxsiy AI agent UI ═══════════════ */
:root {
  --bg: #0a0d14;
  --bg2: #0f1420;
  --panel: rgba(255, 255, 255, 0.04);
  --panel2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --text: #e8ecf4;
  --muted: #8b93a7;
  --accent1: #8b5cf6;
  --accent2: #06b6d4;
  --grad: linear-gradient(135deg, #8b5cf6, #06b6d4);
  --green: #22c55e;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, "JetBrains Mono", monospace;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(139, 92, 246, 0.14), transparent 60%),
    radial-gradient(900px 400px at 10% -10%, rgba(6, 182, 212, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

::selection { background: rgba(139, 92, 246, 0.4); }

/* Scrollbar */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.22); }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }

/* ═══════════ Header ═══════════ */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 22px;
  background: rgba(10, 13, 20, 0.75);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.avatar {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--grad);
  display: grid; place-items: center;
  font-size: 20px;
  box-shadow: 0 4px 18px rgba(139, 92, 246, 0.4);
  flex-shrink: 0;
}

.brand-text .title { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.brand-text .subtitle { font-size: 11.5px; color: var(--muted); }

.status-pill {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  margin-left: 10px;
  white-space: nowrap;
  transition: all 0.25s;
}
.status-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5);
  animation: pulse 1.8s infinite;
}
.status-pill.local  .dot { background: var(--green); box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
.status-pill.online .dot { background: var(--blue);  box-shadow: 0 0 0 0 rgba(59,130,246,.5); }
.status-pill.mock   .dot { background: var(--amber); }
.status-pill.error  .dot { background: var(--red);   animation: none; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
  70%  { box-shadow: 0 0 0 6px transparent; opacity: 0.7; }
  100% { box-shadow: 0 0 0 0 transparent; opacity: 1; }
}

.actions { display: flex; gap: 8px; }

.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 11px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.18s;
  display: inline-flex; align-items: center; gap: 5px;
}
.chip:hover { background: var(--panel2); transform: translateY(-1px); }
.chip.danger:hover { background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.4); }
.chip:active { transform: translateY(0); }

/* ═══════════ Chat ═══════════ */
#chat {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 20px 0 12px;
}

#messages, #empty-state { max-width: 860px; margin: 0 auto; padding: 0 20px; }

#empty-state {
  text-align: center;
  padding-top: 9vh;
  animation: fadeUp 0.5s ease;
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.hero-avatar {
  width: 86px; height: 86px;
  margin: 0 auto 18px;
  border-radius: 26px;
  background: var(--grad);
  display: grid; place-items: center;
  font-size: 44px;
  box-shadow: 0 10px 44px rgba(139, 92, 246, 0.45);
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

#empty-state h1 { font-size: 28px; font-weight: 800; margin-bottom: 8px; }
.grad {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero-sub { color: var(--muted); font-size: 14.5px; line-height: 1.6; max-width: 520px; margin: 0 auto 26px; }

.chips { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; }
.chip-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  padding: 9px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
}
.chip-btn:hover {
  border-color: var(--accent1);
  background: rgba(139, 92, 246, 0.12);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(139, 92, 246, 0.2);
}

/* — Xabarlar — */
.msg { display: flex; gap: 11px; margin-bottom: 20px; animation: fadeUp 0.3s ease; }
.msg .msg-avatar {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 17px;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .msg-avatar { background: linear-gradient(135deg, #3b82f6, #8b5cf6); }
.msg.assistant .msg-avatar { background: var(--grad); }

.bubble {
  max-width: min(640px, 82%);
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.65;
  position: relative;
  word-wrap: break-word;
}
.msg.user .bubble {
  background: linear-gradient(135deg, rgba(59,130,246,.22), rgba(139,92,246,.20));
  border: 1px solid rgba(139, 92, 246, 0.35);
  border-bottom-right-radius: 5px;
}
.msg.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 9px 22px; }
.bubble li { margin-bottom: 3px; }
.bubble code {
  font-family: var(--mono);
  font-size: 12.8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5px 6px;
}
.bubble pre {
  background: #0b0e17;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 9px 0;
  font-size: 12.8px;
  line-height: 1.55;
}
.bubble pre code { background: none; border: none; padding: 0; }
.bubble a { color: var(--accent2); }
.bubble blockquote {
  border-left: 3px solid var(--accent1);
  padding-left: 12px;
  color: var(--muted);
  margin: 8px 0;
}

.msg-meta {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.2s;
}
.msg:hover .msg-meta { opacity: 1; }
.copy-btn {
  background: none; border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 6px;
}
.copy-btn:hover { color: var(--text); background: var(--panel2); }

.caret {
  display: inline-block;
  width: 8px; height: 15px;
  background: var(--accent2);
  border-radius: 2px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.9s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* — Tool kartalari — */
.tool-card {
  margin-bottom: 20px;
  max-width: 640px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--tc, var(--muted));
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
  animation: fadeUp 0.25s ease;
}
.tool-card .tool-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
}
.tool-card .tool-head .spin { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--tc); animation: rotate 0.8s linear infinite; margin-left: auto; }
@keyframes rotate { to { transform: rotate(360deg); } }
.tool-card .tool-name { font-family: var(--mono); font-size: 12px; text-transform: lowercase; }
.tool-card .tool-badge { margin-left: auto; font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.06); color: var(--muted); }
.tool-card.done .tool-badge { background: rgba(34,197,94,.15); color: var(--green); }
.tool-card.error .tool-badge { background: rgba(239,68,68,.15); color: var(--red); }

.tool-card pre {
  margin: 0;
  padding: 10px 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
}
.tool-card .tool-result {
  display: none;
  padding: 10px 14px;
  background: #0b0e17;
  color: #a9c4c9;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
}
.tool-card.open .tool-result { display: block; }
.tool-card .toggle-result {
  width: 100%;
  background: none; border: none;
  color: var(--muted);
  font-size: 12px;
  padding: 7px;
  cursor: pointer;
  font-family: var(--font);
}
.tool-card .toggle-result:hover { color: var(--text); background: var(--panel2); }

.tool-shell   { --tc: var(--amber); }
.tool-web     { --tc: var(--accent2); }
.tool-file    { --tc: var(--green); }
.tool-memory  { --tc: #a855f7; }
.tool-sys     { --tc: #38bdf8; }
.tool-calc    { --tc: #f472b6; }
.tool-notes   { --tc: #fbbf24; }
.tool-proc    { --tc: #fb7185; }

/* ═══════════ Real-time fikrlash ═══════════ */
.bubble.thinking {
  border-color: rgba(139, 92, 246, 0.35);
  background: rgba(139, 92, 246, 0.05);
  color: #c4b5fd;
  font-style: italic;
  min-height: 22px;
}

/* ═══════════ Xato kartasi ═══════════ */
.bubble.error-bubble {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.06);
}
.error-bubble .err-head { font-weight: 600; color: #fca5a5; margin-bottom: 6px; }
.error-bubble .err-cause { font-size: 13px; color: #e2e8f0; margin: 5px 0; line-height: 1.55; }
.error-bubble .err-fix { font-size: 13px; color: #86efac; margin: 5px 0; line-height: 1.55; }
.error-bubble .err-raw { margin-top: 8px; font-size: 12px; }
.error-bubble .err-raw summary { cursor: pointer; color: var(--muted); user-select: none; }
.error-bubble .err-raw pre {
  margin: 6px 0 0; padding: 8px 10px; font-size: 11.5px; max-height: 140px; overflow: auto;
  background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(255,255,255,.08); border-radius: 8px; color: #94a3b8;
}

/* ═══════════ Parallel tool'lar ═══════════ */
.tool-card.done .tool-head { opacity: 0.75; }
.tool-card + .tool-card { margin-top: -10px; } /* parallel kartalar yopishib turadi */
.tool-card.parallel { animation: fadeUp 0.2s ease; }

/* — Yozuvchi ko'rsatkichi — */
.typing { max-width: 860px; margin: 0 auto; padding: 0 20px; }
.typing-bubble {
  width: fit-content;
  display: flex; gap: 5px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}
.typing-bubble span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ═══════════ Composer ═══════════ */
#composer {
  padding: 12px 20px 14px;
  background: linear-gradient(to top, rgba(10,13,20,0.95), rgba(10,13,20,0));
  z-index: 30;
}

#input-wrap {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 9px 9px 9px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#input-wrap:focus-within {
  border-color: rgba(139, 92, 246, 0.6);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.12);
}

#input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  max-height: 160px;
  padding: 6px 0;
}
#input::placeholder { color: #5d6577; }

#send {
  width: 40px; height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--grad);
  color: white;
  cursor: pointer;
  display: grid; place-items: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
#send:hover:not(:disabled) { transform: scale(1.06); box-shadow: 0 6px 20px rgba(139, 92, 246, 0.45); }
#send:active:not(:disabled) { transform: scale(0.96); }
#send:disabled { opacity: 0.45; cursor: not-allowed; }

.hint { text-align: center; font-size: 11.5px; color: #4d5568; margin-top: 8px; }

/* ═══════════ Drawer (xotira) ═══════════ */
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 92vw);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  padding: 18px;
  z-index: 60;
  transform: translateX(105%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }

.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.drawer-head h3 { font-size: 16px; }

.mem-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  margin-bottom: 9px;
  font-size: 13.5px;
  line-height: 1.5;
  display: flex;
  gap: 9px;
  align-items: flex-start;
  animation: fadeUp 0.25s ease;
}
.mem-item .mem-text { flex: 1; }
.mem-item .mem-del {
  background: none; border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 6px;
}
.mem-item .mem-del:hover { color: var(--red); background: rgba(239,68,68,.12); }
.mem-ts { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Skill'lar paneli */
.skill-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 13px;
  margin-bottom: 9px;
  animation: fadeUp 0.25s ease;
}
.skill-head { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
.skill-name {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent2);
  font-weight: 600;
}
.skill-desc { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin-top: 5px; }
.skill-content { margin-top: 8px; font-size: 12px; }
.skill-content summary { cursor: pointer; color: var(--muted); user-select: none; }
.skill-content pre {
  margin: 6px 0 0; padding: 8px 10px; font-size: 11.5px; max-height: 180px; overflow: auto;
  background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(255,255,255,.08); border-radius: 8px;
  color: #94a3b8; white-space: pre-wrap; word-break: break-word;
}

/* Skill yaratish formasi */
.skill-create-btn { width: 100%; margin-bottom: 12px; }
.skill-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  animation: fadeUp 0.25s ease;
}
.skill-form input, .skill-form textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  resize: vertical;
  box-sizing: border-box;
}
.skill-form input:focus, .skill-form textarea:focus { border-color: var(--accent2); }
.skill-form-actions { display: flex; gap: 8px; justify-content: flex-end; }

#overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(3px);
  z-index: 50;
}

/* ═══════════ Modal ═══════════ */
.modal {
  position: fixed; inset: 0;
  z-index: 70;
  display: grid; place-items: center;
  padding: 20px;
}
.modal-card {
  width: min(480px, 94vw);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  animation: pop 0.25s ease;
  overflow: hidden;
}
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } to { opacity: 1; transform: none; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }

.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.modal-body label { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.modal-body label:first-child { margin-top: 0; }
.modal-body input, .modal-body select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.2s;
}
.modal-body input:focus, .modal-body select:focus { border-color: var(--accent1); }

.note { font-size: 12px; color: var(--muted); line-height: 1.55; margin-top: 10px; }
.note code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--panel2);
  padding: 1px 6px;
  border-radius: 5px;
}
.note a { color: var(--accent2); }

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end;
}
.btn-primary {
  background: var(--grad);
  border: none;
  color: white;
  font-weight: 600;
  font-size: 14px;
  font-family: var(--font);
  padding: 10px 22px;
  border-radius: 11px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(139, 92, 246, 0.4); }

/* ═══════════ Xato banneri ═══════════ */
.error-banner {
  position: sticky;
  top: 65px;
  z-index: 35;
  max-width: 860px;
  margin: 8px auto 0;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(127, 29, 29, 0.25);
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #fca5a5;
  backdrop-filter: blur(8px);
  animation: fadeUp 0.3s ease;
}
.error-banner span { flex: 1; word-break: break-word; }
.error-banner button {
  background: none; border: none;
  color: #fca5a5; cursor: pointer;
  font-size: 13px; padding: 2px 6px;
  border-radius: 6px;
}
.error-banner button:hover { background: rgba(239, 68, 68, 0.2); }

/* ═══════════ Tashxis ═══════════ */
.diag {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  margin-top: 4px;
}
.diag-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.diag-row:last-child { border-bottom: none; }
.diag-icon { flex-shrink: 0; }
.diag-label { font-weight: 600; flex-shrink: 0; }
.diag-detail {
  color: var(--muted);
  font-size: 12px;
  margin-left: auto;
  text-align: right;
  word-break: break-word;
  max-width: 55%;
}
.diag-row.bad .diag-label { color: #fca5a5; }
.diag-row.bad .diag-detail { color: #f0abab; }
.diag-row.ok .diag-label { color: #86efac; }

/* ═══════════ Toast ═══════════ */
#toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #1a2130;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 13.5px;
  max-width: 80vw;
  z-index: 100;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  animation: fadeUp 0.25s ease;
}
#toast.error { border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }
#toast.success { border-color: rgba(34, 197, 94, 0.5); color: #86efac; }

.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }

/* Responsive */
@media (max-width: 640px) {
  .status-pill { display: none; }
  .bubble { max-width: 88%; }
  .brand-text .subtitle { display: none; }
}
