/* ── TOKENS ─────────────────────────────────────────────── */
:root {
  --bg:      #FAFAFC;
  --panel:   #FFFFFF;
  --sidebar: #F2F2F5;
  --a:       #2563EB;
  --a-l:     #EFF6FF;
  --a-m:     #BFDBFE;
  --a-d:     #1D4ED8;
  --txt:     #1D1D1F;
  --muted:   #6E6E73;
  --line:    #E5E5EA;
  --g:       #16A34A;
  --r:       #DC2626;
  --ss:  0 1px 4px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --sm:  0 4px 16px rgba(0,0,0,.07), 0 1px 4px rgba(0,0,0,.03);
  --sl:  0 8px 40px rgba(0,0,0,.10), 0 2px 8px rgba(0,0,0,.04);
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { overflow-x: hidden; }

/* ── LAYOUT ─────────────────────────────────────────────── */
.assistant-app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
}

/* ── SIDEBAR ─────────────────────────────────────────────── */
.assistant-sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.assistant-sidebar__brand {
  padding: 4px 6px 12px;
  border-bottom: 1px solid var(--line);
}

.assistant-sidebar__title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--txt);
  display: flex;
  align-items: center;
  gap: 8px;
}

.assistant-sidebar__title::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--g);
  box-shadow: 0 0 0 3px rgba(22,163,74,.18);
  flex-shrink: 0;
  animation: pulse 2.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(22,163,74,.18); }
  50%       { box-shadow: 0 0 0 5px rgba(22,163,74,.08); }
}

.assistant-sidebar__subtitle {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.assistant-sidebar__button {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  width: 100%;
  border-radius: 12px;
  background: var(--a);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: background 160ms, transform 80ms, box-shadow 160ms;
  box-shadow: 0 2px 8px rgba(37,99,235,.25);
}

.assistant-sidebar__button:hover  { background: var(--a-d); box-shadow: 0 4px 16px rgba(37,99,235,.35); }
.assistant-sidebar__button:active { transform: scale(0.97); }

/* ── SIDE CARDS ─────────────────────────────────────────── */
.assistant-side-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px;
  box-shadow: var(--ss);
}

.assistant-side-card--history {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.assistant-side-card--compact { flex: 0 0 auto; }

.assistant-side-card h3 {
  margin: 0 0 8px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

/* ── HISTORY ─────────────────────────────────────────────── */
.assistant-history {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.assistant-history__empty {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 16px 0;
  line-height: 1.5;
}

.assistant-history__item {
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  color: var(--txt);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 120ms, border-color 120ms, color 120ms;
}

.assistant-history__item:hover {
  background: var(--a-l);
  border-color: var(--a-m);
  color: var(--a);
}

/* ── QUICK PROMPTS ──────────────────────────────────────── */
.assistant-suggestions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 160px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.assistant-suggestion {
  appearance: none;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--txt);
  border-radius: 9px;
  padding: 8px 10px;
  font: 12px/1.4 inherit;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}

.assistant-suggestion:hover {
  background: var(--a-l);
  border-color: var(--a-m);
  color: var(--a);
}

/* ── KB LINK ─────────────────────────────────────────────── */
.assistant-kb-link {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 10px; font-size: 13px; font-weight: 700;
  text-decoration: none; color: var(--txt);
  border: 1px solid var(--line); background: var(--bg);
  transition: background 120ms, border-color 120ms, color 120ms;
  margin-top: auto;
}
.assistant-kb-link:hover { background: var(--a-l); border-color: var(--a-m); color: var(--a); }
.assistant-kb-link__icon { flex: none; font-size: 15px; }
.assistant-kb-link > span:nth-child(2) { flex: 1; }
.assistant-kb-link__badge {
  min-width: 20px; height: 20px; border-radius: 999px;
  background: var(--a); color: #fff; font-size: 11px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
  flex: none;
}

/* ── SIDEBAR FOOTER ──────────────────────────────────────── */
.assistant-sidebar__footer {
  margin-top: 8px;
  padding: 10px 6px 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
  border-top: 1px solid var(--line);
}

/* ── MAIN ─────────────────────────────────────────────────── */
.assistant-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  min-height: 100vh;
}

/* ── TOPBAR ──────────────────────────────────────────────── */
.assistant-main__topbar {
  min-height: 58px;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}

.assistant-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.assistant-topbar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--g);
  box-shadow: 0 0 0 3px rgba(22,163,74,.18);
  animation: pulse 2.5s ease infinite;
}

.assistant-topbar-name {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--txt);
}

.assistant-topbar-model {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 7px;
  font-weight: 600;
}

.assistant-home-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--txt);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: background 120ms, border-color 120ms, color 120ms;
}

.assistant-home-link:hover {
  background: var(--a-l);
  border-color: var(--a-m);
  color: var(--a);
}

/* ── THREAD WRAP ─────────────────────────────────────────── */
.assistant-thread-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.assistant-thread {
  flex: 1;
  padding: 8px 24px 24px;
}

/* ── EMPTY STATE ─────────────────────────────────────────── */
.assistant-empty {
  min-height: 56vh;
  display: grid;
  place-items: center;
  padding: 48px 20px 32px;
}

.assistant-empty__inner {
  width: min(680px, 100%);
  text-align: center;
}

.assistant-empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--a) 0%, #7C3AED 100%);
  margin-bottom: 20px;
  box-shadow: 0 8px 32px rgba(37,99,235,.28);
  font-size: 28px;
}

.assistant-empty__inner h1 {
  margin: 0 0 12px;
  font-size: clamp(30px, 4.5vw, 50px);
  font-weight: 800;
  letter-spacing: -0.05em;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--txt) 0%, var(--a) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.assistant-empty__inner p {
  margin: 0 auto 28px;
  max-width: 520px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

/* ── MESSAGES ────────────────────────────────────────────── */
.assistant-thread__list {
  width: min(820px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.assistant-message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fadeUp 220ms ease forwards;
}

.assistant-message--user { justify-content: flex-end; }

/* avatars */
.assistant-avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  flex: 0 0 auto;
  letter-spacing: 0.03em;
  background: linear-gradient(135deg, var(--a) 0%, #7C3AED 100%);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37,99,235,.2);
}

.assistant-message--user .assistant-avatar {
  order: 2;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  box-shadow: none;
}

/* bubbles */
.assistant-bubble {
  max-width: min(680px, calc(100% - 48px));
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  border-top-left-radius: 5px;
  padding: 14px 17px;
  box-shadow: var(--ss);
}

.assistant-message--user .assistant-bubble {
  background: var(--a);
  border-color: var(--a);
  border-radius: 20px;
  border-top-right-radius: 5px;
  border-top-left-radius: 20px;
  box-shadow: 0 4px 20px rgba(37,99,235,.22);
}

.assistant-bubble h3 {
  margin: 0 0 7px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--a);
}

.assistant-message--user .assistant-bubble h3 {
  color: rgba(255,255,255,.65);
}

.assistant-bubble p,
.assistant-bubble li {
  margin: 0;
  font-size: 14px;
  line-height: 1.72;
  color: var(--txt);
}

.assistant-message--user .assistant-bubble p,
.assistant-message--user .assistant-bubble li { color: #fff; }

.assistant-bubble p + p,
.assistant-bubble p + ul,
.assistant-bubble ul + p,
.assistant-bubble ul + ul { margin-top: 10px; }

.assistant-bubble ul { margin: 0; padding-left: 17px; }

/* sources */
.assistant-sources {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.assistant-source {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--a-m);
  color: var(--a);
  font-size: 11px;
  font-weight: 700;
}

/* ── TYPING INDICATOR ────────────────────────────────────── */
.assistant-typing {
  display: none;
  gap: 10px;
  align-items: center;
  margin-top: 4px;
  animation: fadeUp 200ms ease forwards;
}

.assistant-typing.visible { display: flex; }

.assistant-typing__avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--a) 0%, #7C3AED 100%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  flex: 0 0 auto;
  box-shadow: 0 2px 8px rgba(37,99,235,.2);
}

.assistant-typing__bubble {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  border-top-left-radius: 5px;
  padding: 14px 18px;
  display: flex;
  gap: 5px;
  align-items: center;
  box-shadow: var(--ss);
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.35; }
  30%           { transform: translateY(-6px); opacity: 1; }
}

.assistant-typing__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--a);
  animation: typingBounce 1.1s ease infinite;
}

.assistant-typing__dot:nth-child(2) { animation-delay: 0.18s; }
.assistant-typing__dot:nth-child(3) { animation-delay: 0.36s; }

/* ── COMPOSER ────────────────────────────────────────────── */
.assistant-composer-wrap {
  padding: 12px 24px 20px;
  background: linear-gradient(to top, var(--panel) 72%, rgba(255,255,255,0));
  position: sticky;
  bottom: 0;
}

.assistant-composer {
  width: min(720px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  padding: 8px 8px 8px 18px;
  border-radius: 24px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  box-shadow: var(--sm);
  transition: border-color 180ms, box-shadow 180ms;
}

.assistant-composer:focus-within {
  border-color: var(--a-m);
  box-shadow: var(--sm), 0 0 0 4px rgba(37,99,235,.07);
}

/* hide legacy icon slot */
.assistant-composer__icon { display: none; }

.assistant-composer textarea {
  grid-column: 1;
  min-height: 44px;
  max-height: 200px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--txt);
  font: 15px/1.55 inherit;
  padding: 10px 4px;
}

.assistant-composer textarea::placeholder { color: var(--muted); }

.assistant-composer__submit {
  appearance: none;
  border: none;
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--a);
  color: #fff;
  font-size: 18px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  transition: background 160ms, transform 80ms, box-shadow 160ms;
  box-shadow: 0 2px 8px rgba(37,99,235,.28);
  align-self: end;
}

.assistant-composer__submit:hover  { background: var(--a-d); box-shadow: 0 4px 16px rgba(37,99,235,.38); }
.assistant-composer__submit:active { transform: scale(0.92); }

.assistant-composer__hint {
  width: min(720px, 100%);
  margin: 8px auto 0;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}

/* ── UTILS ───────────────────────────────────────────────── */
.assistant-hidden { display: none !important; }

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 980px) {
  .assistant-app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }
  .assistant-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    position: static;
    height: auto;
    overflow: visible;
  }
  .assistant-main__topbar,
  .assistant-thread,
  .assistant-composer-wrap { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 640px) {
  .assistant-bubble { max-width: 100%; }
  .assistant-empty__inner h1 { font-size: 28px; }
}
