/* AGIS Assistant: dark chat UI */
:root {
  --bg: #0d0e10;
  --surface: #16181b;
  --surface-2: #1d2024;
  --surface-3: #262a2f;
  --line: #2a2e34;
  --text: #e8eaed;
  --text-2: #b4b9c0;
  --muted: #7d838b;
  --accent: #19c283;
  --accent-2: #18b0c9;
  --accent-3: #6a8cff;
  --grad: linear-gradient(90deg, var(--accent), var(--accent-2) 55%, var(--accent-3));
  --danger: #ff6b6b;
  --r-lg: 24px;
  --r-md: 16px;
  --thread: 780px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15.5px/1.7 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.glow {
  position: fixed; inset: -30vh -20vw auto; height: 70vh; pointer-events: none; z-index: 0;
  background:
    radial-gradient(40% 50% at 30% 40%, rgba(25,194,131,.10), transparent 70%),
    radial-gradient(35% 45% at 70% 30%, rgba(106,140,255,.08), transparent 70%);
  filter: blur(20px);
}

.app { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100dvh; flex: 1; min-width: 0; }

/* ---------- Layout with history sidebar ---------- */
.layout { position: relative; z-index: 1; display: flex; height: 100dvh; }
.sidebar {
  width: 272px; flex: none; display: flex; flex-direction: column; gap: 6px;
  background: #121416; border-right: 1px solid #1e2226; padding: 12px 10px;
  transition: margin-left .25s ease, transform .25s ease;
}
.layout.collapsed .sidebar { margin-left: -272px; }
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 8px; }
.side-brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.side-brand:hover { text-decoration: none; }
.new-chat {
  display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 14px; margin: 0 2px 8px;
  border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; font-weight: 500; transition: background .15s, border-color .15s;
}
.new-chat:hover { background: var(--surface-3); border-color: #3a4048; }
.new-chat svg { width: 18px; height: 18px; color: var(--accent); }

.conv-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.conv-list::-webkit-scrollbar { width: 6px; }
.conv-list::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 6px; }
.conv-group { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 6px; }
.conv {
  position: relative; display: flex; align-items: center; border-radius: 10px;
  color: var(--text-2); font-size: 13.5px; transition: background .12s, color .12s;
}
.conv a { flex: 1; min-width: 0; padding: 8px 10px; color: inherit; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv a:hover { text-decoration: none; }
.conv:hover { background: var(--surface-2); color: var(--text); }
.conv.active { background: rgba(25,194,131,.12); color: #fff; }
.conv.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--accent); }
.conv .del {
  flex: none; width: 30px; height: 30px; margin-right: 3px; border-radius: 8px; display: none; place-items: center; color: var(--muted);
}
.conv:hover .del, .conv.active .del { display: grid; }
.conv .del:hover { color: var(--danger); background: rgba(255,107,107,.1); }
.conv .del svg { width: 15px; height: 15px; }
.conv-empty { color: var(--muted); font-size: 13px; padding: 12px 10px; }

.admin-link {
  display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px; margin: 4px 2px;
  border-radius: 12px; border: 1px solid rgba(25,194,131,.3); background: rgba(25,194,131,.08);
  color: var(--text); font-size: 13.5px; font-weight: 500;
}
.admin-link:hover { text-decoration: none; background: rgba(25,194,131,.15); }
.admin-link svg { width: 18px; height: 18px; color: var(--accent); }
.admin-icon { color: var(--accent); }
.side-foot { display: flex; align-items: center; gap: 10px; padding: 10px 6px 2px; border-top: 1px solid #1e2226; }
.side-foot .avatar { margin: 0; }
.me { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.me-name { font-size: 13.5px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .quota { background: none; border: 0; padding: 0; font-size: 12px; color: var(--muted); }
.chat-title { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 500; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scrim { display: none; }
.icon-btn.only-mobile { display: none; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; margin-left: 0 !important; transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.6); }
  .layout.open .sidebar { transform: none; }
  .layout.open .scrim { display: block; position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.5); }
  .icon-btn.only-mobile { display: inline-grid; }
  .conv .del { display: grid; }
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; min-height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark svg { width: 26px; height: 26px; stroke: none; }
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
.badge {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--accent); border: 1px solid rgba(25,194,131,.4); border-radius: 999px; padding: 1px 8px;
}
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.quota {
  font-size: 12.5px; color: var(--text-2); background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; white-space: nowrap;
}
.avatar { width: 32px; height: 32px; border-radius: 50%; margin-left: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center;
  color: var(--text-2); transition: background .15s, color .15s; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }

/* ---------- Gate ---------- */
.gate { flex: 1; display: grid; place-items: center; padding: 16px; }
.gate-card { max-width: 460px; text-align: center; }
.gate-mark svg { width: 56px; height: 56px; stroke: none; animation: float 4s ease-in-out infinite; }
.gate-card h1 {
  font-size: 32px; letter-spacing: -.02em; margin: 14px 0 10px;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.gate-card p { color: var(--text-2); margin: 0 0 24px; }
.btn-primary {
  display: inline-flex; align-items: center; gap: 10px; padding: 12px 26px; border-radius: 999px;
  background: var(--text); color: #111; font-weight: 600; transition: transform .15s, box-shadow .15s;
}
.btn-primary:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 8px 30px rgba(25,194,131,.25); }
.btn-primary .discord { width: 22px; height: 22px; fill: #5865f2; stroke: none; }
@keyframes float { 50% { transform: translateY(-6px) rotate(8deg); } }

/* ---------- Chat area ---------- */
.chat { flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-gutter: stable; }
.chat::-webkit-scrollbar { width: 10px; }
.chat::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 10px; border: 3px solid var(--bg); }
.thread { max-width: var(--thread); margin: 0 auto; padding: 12px 20px 32px; }

.welcome { padding: 8vh 0 12px; animation: rise .5s ease both; }
.hello { font-size: clamp(28px, 5vw, 44px); line-height: 1.15; letter-spacing: -.03em; font-weight: 600; margin: 0 0 36px; color: var(--muted); }
.hello span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.suggestions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.suggestion {
  display: flex; flex-direction: column; justify-content: space-between; gap: 18px; text-align: left;
  min-height: 108px; padding: 14px 16px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid transparent; transition: background .15s, border-color .15s, transform .15s;
}
.suggestion:hover { background: var(--surface-2); border-color: var(--line); transform: translateY(-2px); }
.s-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--accent); }
.s-icon svg { width: 18px; height: 18px; }
.s-title { font-size: 14px; color: var(--text-2); font-weight: 500; line-height: 1.4; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* ---------- Messages ---------- */
.turn { margin: 0 0 28px; animation: rise .3s ease both; }
.turn.user { display: flex; justify-content: flex-end; }
.user-bubble {
  max-width: min(85%, 560px); background: var(--surface-2); padding: 11px 18px;
  border-radius: 22px 22px 6px 22px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text);
}
.user-bubble img { display: block; max-width: 240px; max-height: 180px; border-radius: 12px; margin-top: 10px; }

.turn.bot { display: flex; gap: 16px; align-items: flex-start; }
.bot-mark { position: relative; flex: none; width: 32px; height: 32px; display: grid; place-items: center; margin-top: 2px; }
.bot-mark svg { width: 24px; height: 24px; stroke: none; position: relative; z-index: 1; }
.bot-body { flex: 1; min-width: 0; }

/* Gemini-like "thinking": spinning gradient ring around the sparkle + shimmering lines */
.turn.bot.loading .bot-mark::before {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 30%, var(--accent) 50%, var(--accent-2) 70%, var(--accent-3) 85%, transparent);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  animation: spin 1.1s linear infinite;
}
.turn.bot.loading .bot-mark svg { animation: pulse 1.6s ease-in-out infinite; }
.thinking { display: none; }
.turn.bot.loading .thinking { display: block; }
.status {
  font-size: 14px; font-weight: 500; margin: 4px 0 12px; width: fit-content;
  background: linear-gradient(90deg, var(--muted) 0%, var(--text) 45%, var(--muted) 60%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shine 1.8s linear infinite;
}
.skeleton i {
  display: block; height: 14px; border-radius: 7px; margin: 0 0 10px;
  background: linear-gradient(90deg, rgba(25,194,131,.10), rgba(24,176,201,.30), rgba(106,140,255,.10), rgba(25,194,131,.10));
  background-size: 300% 100%; animation: wave 1.6s ease-in-out infinite;
}
.skeleton i:nth-child(1) { width: 100%; }
.skeleton i:nth-child(2) { width: 88%; animation-delay: .15s; }
.skeleton i:nth-child(3) { width: 62%; animation-delay: .3s; }
.turn.bot.streaming .thinking, .turn.bot:not(.loading) .thinking { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { transform: scale(.82) rotate(45deg); } }
@keyframes shine { to { background-position: -200% 0; } }
@keyframes wave { 0% { background-position: 100% 0; } 100% { background-position: -200% 0; } }

/* Blinking caret while the answer streams in */
.turn.bot.streaming .md > :last-child::after {
  content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 3px; vertical-align: -2px;
  border-radius: 2px; background: var(--grad); animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

.error-note {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px;
  background: rgba(255,107,107,.08); border: 1px solid rgba(255,107,107,.3); color: #ffc2c2; font-size: 14px;
}
.stopped-note { font-size: 13px; color: var(--muted); font-style: italic; margin-top: 6px; }

.answer-actions { display: flex; gap: 2px; margin-top: 8px; opacity: 0; transition: opacity .2s; }
.turn.bot:hover .answer-actions, .turn.bot:last-child .answer-actions { opacity: 1; }
.answer-actions button {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 16px;
  font-size: 12.5px; color: var(--muted);
}
.answer-actions button:hover { background: var(--surface-2); color: var(--text); }
.answer-actions svg { width: 16px; height: 16px; }

/* ---------- Markdown ---------- */
.md { color: var(--text); overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md strong { color: #fff; font-weight: 600; }
.md ol, .md ul { margin: 0 0 16px; padding-left: 26px; }
.md li { margin: 0 0 10px; padding-left: 4px; }
.md li:last-child { margin-bottom: 0; }
.md li > p { margin: 0 0 6px; }
.md li > ul, .md li > ol { margin: 6px 0 0; padding-left: 20px; }
.md li > ul > li { margin-bottom: 4px; color: var(--text-2); }
.md ol > li::marker { color: var(--accent); font-weight: 600; }

.md li::marker { color: var(--muted); }
.md h1, .md h2, .md h3, .md h4 { font-size: 16px; font-weight: 600; margin: 20px 0 8px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md code {
  font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: .86em;
  background: var(--surface-2); padding: 2px 6px; border-radius: 6px; color: #8ff0c6;
}
.md pre {
  position: relative; margin: 0 0 14px; background: #0a0b0d; border: 1px solid var(--line);
  border-radius: 14px; padding: 38px 16px 14px; overflow-x: auto;
}
.md pre code { background: none; padding: 0; color: var(--text); font-size: 13px; line-height: 1.6; white-space: pre; }
.md pre .copy-code {
  position: absolute; top: 6px; right: 8px; font-size: 12px; color: var(--muted);
  padding: 3px 10px; border-radius: 8px;
}
.md pre .copy-code:hover { background: var(--surface-2); color: var(--text); }
.md table { display: block; overflow-x: auto; border-collapse: collapse; margin: 0 0 14px; font-size: 14px; max-width: 100%; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 7px 12px; text-align: left; }
.md th { color: var(--text-2); font-weight: 600; }
.md blockquote { margin: 0 0 12px; padding: 2px 0 2px 14px; border-left: 3px solid var(--accent); color: var(--text-2); }
.md .callout {
  margin-top: 16px; padding: 10px 14px; border-radius: 12px; font-size: 14.5px;
  background: rgba(255,184,107,.07); border: 1px solid rgba(255,184,107,.22); color: var(--text-2);
}
.md .callout > strong:first-child { color: #ffb86b; }
.md .callout.tip { background: rgba(25,194,131,.07); border-color: rgba(25,194,131,.25); }
.md .callout.tip > strong:first-child { color: var(--accent); }
/* Screenshots from the documentation, placed inside the answer */
.md .doc-shot {
  margin: 14px 0 16px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  background: #0a0b0d; max-width: 640px;
}
.md li .doc-shot { margin: 10px 0 6px; }
.md .doc-shot img {
  display: block; width: 100%; max-height: 380px; object-fit: contain; background: #0a0b0d;
  cursor: zoom-in; transition: opacity .15s;
}
.md .doc-shot img:hover { opacity: .9; }
.md .doc-shot figcaption {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 12px; border-top: 1px solid var(--line); background: var(--surface);
  font-size: 12.5px; color: var(--text-2);
}
.md .doc-shot figcaption a { flex: none; font-size: 12px; color: var(--accent); }

.lightbox {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px;
  background: rgba(5,6,8,.88); backdrop-filter: blur(6px); cursor: zoom-out; animation: rise .2s ease both;
}
.lightbox figure { margin: 0; max-width: min(1200px, 100%); }
.lightbox img { display: block; width: min(1000px, 100%); max-width: 100%; max-height: 82vh; object-fit: contain; border-radius: 12px; border: 1px solid var(--line); }
.lightbox figcaption { margin-top: 10px; text-align: center; color: var(--text-2); font-size: 14px; }
.lightbox-close { position: absolute; top: 14px; right: 14px; color: var(--text); background: var(--surface-2); }

.doc-links { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; }
.doc-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-right: 4px; }
.doc-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text-2); font-size: 13px; font-weight: 500;
  transition: border-color .15s, color .15s, background .15s;
}
.doc-chip:hover { text-decoration: none; border-color: rgba(25,194,131,.5); color: #fff; background: rgba(25,194,131,.08); }
.doc-chip svg { width: 15px; height: 15px; }
.doc-chip svg:first-child { color: var(--accent); }
.doc-chip svg:last-child { width: 13px; height: 13px; color: var(--muted); }
.md .sources {
  margin-top: 16px; padding-top: 10px; border-top: 1px dashed var(--line);
  font-size: 12.5px; color: var(--muted); line-height: 1.6;
}

/* ---------- Composer dock ---------- */
.dock { position: relative; padding: 0 16px calc(10px + env(safe-area-inset-bottom)); }
.composer {
  max-width: var(--thread); margin: 0 auto; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 10px 10px 8px 18px; transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: #3a4048; box-shadow: 0 0 0 4px rgba(25,194,131,.06); }
.composer.drag { border-color: var(--accent); border-style: dashed; }
.composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; line-height: 1.55; padding: 6px 0; min-height: 34px; max-height: 200px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-bar { display: flex; align-items: center; gap: 4px; margin-left: -8px; }
.counter { margin-left: auto; font-size: 11.5px; color: var(--muted); padding-right: 6px; }
.counter.warn { color: #ffb86b; }
.send {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--text); color: #111; transition: opacity .15s, transform .15s, background .15s;
}
.send:hover:not(:disabled) { transform: scale(1.05); }
.send:disabled { opacity: .25; cursor: default; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.stop { background: var(--surface-3); color: var(--text); }
.send.stop .i-send { display: none; }
.send.stop .i-stop { display: block; }

.attachment { position: relative; display: inline-block; margin: 4px 0 6px; }
.attachment img { display: block; height: 72px; max-width: 160px; object-fit: cover; border-radius: 12px; border: 1px solid var(--line); }
.attachment button {
  position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface-3); color: var(--text); border: 2px solid var(--surface);
}
.attachment button svg { width: 12px; height: 12px; stroke-width: 2.6; }

.to-bottom {
  position: absolute; top: -52px; left: 50%; transform: translateX(-50%);
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text); box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.to-bottom svg { width: 18px; height: 18px; }
.fineprint { max-width: var(--thread); margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .suggestions { grid-template-columns: repeat(2, 1fr); }
  .quota, .badge { display: none; }
}
@media (max-width: 480px) {
  .thread { padding: 8px 16px 24px; }
  .welcome { padding-top: 4vh; }
  .hello { margin-bottom: 24px; }
  .suggestion { min-height: 92px; padding: 12px; }
  .turn.bot { gap: 10px; }
  .bot-mark { width: 26px; height: 26px; }
  .bot-mark svg { width: 20px; height: 20px; }
  .fineprint { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
