/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface-2: #22263a;
  --border:    #2e3348;
  --text:      #e2e8f0;
  --text-2:    #8892a4;
  --accent:    #6366f1;
  --accent-h:  #4f46e5;
  --ok:        #22c55e;
  --err:       #ef4444;
  --warn:      #f59e0b;
  --radius:    10px;
  --sidebar-w: 220px;
}

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ── Layout ──────────────────────────────────────────────────────── */
.layout { display: flex; height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 0 1.2rem 1.2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .8rem;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  flex-shrink: 0;
  color: #fff;
}

.brand-text { font-weight: 600; font-size: 15px; }

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: 0 .6rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  width: 100%;
  padding: .6rem .9rem;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  text-align: left;
  font-size: 13.5px;
  font-family: inherit;
  transition: background .15s, color .15s;
}

.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover    { background: var(--surface-2); color: var(--text); }
.nav-item.active   { background: var(--surface-2); color: var(--accent); font-weight: 500; }

.sidebar-status {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .9rem 1.2rem;
  border-top: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  margin-top: auto;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-2);
  transition: background .3s;
  flex-shrink: 0;
}

.dot-pending { background: var(--warn); animation: pulse 1.5s ease-in-out infinite; }
.dot-ok      { background: var(--ok); }
.dot-error   { background: var(--err); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

.status-text { font-size: 12px; color: var(--text-2); }

/* ── Main ────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Views ───────────────────────────────────────────────────────── */
.view {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.5rem 2rem;
  overflow: hidden;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
}

.view-header h1 { font-size: 20px; font-weight: 600; }

/* ── Messages ────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-right: .4rem;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  text-align: center;
  gap: .4rem;
}

.empty-icon { font-size: 3rem; margin-bottom: .5rem; }
.hint { font-size: 12px; }

/* ── Message bubbles ─────────────────────────────────────────────── */
.msg {
  display: flex;
  gap: .75rem;
  align-items: flex-start;
}

.msg.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  background: var(--surface-2);
  color: var(--text-2);
}

.msg.user      .msg-avatar { background: var(--accent); color: #fff; }
.msg.assistant .msg-avatar { background: var(--surface-2); color: var(--accent); }
.msg.error     .msg-avatar { background: var(--err); color: #fff; }

.msg-body {
  max-width: 75%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}

.msg.user .msg-body {
  background: var(--accent);
  border-color: transparent;
}

.msg.error .msg-body {
  background: rgba(239, 68, 68, .1);
  border-color: rgba(239, 68, 68, .3);
}

.msg-text { white-space: pre-wrap; word-break: break-word; line-height: 1.7; }
.msg.user .msg-text  { color: #fff; }
.msg.error .msg-text { color: var(--err); }

.msg-sources {
  margin-top: .6rem;
  font-size: 12px;
  color: var(--text-2);
  border-top: 1px solid var(--border);
  padding-top: .5rem;
}

.msg.user .msg-sources {
  border-top-color: rgba(255, 255, 255, .25);
  color: rgba(255, 255, 255, .75);
}

.sources-label { font-weight: 500; }
.msg-sources ul { padding-left: 1rem; margin-top: .25rem; }
.msg-sources li { margin-bottom: .15rem; }

/* Typing indicator */
.typing { display: flex; gap: 4px; align-items: center; height: 20px; }

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-2);
  animation: bounce .9s ease-in-out infinite;
}

.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .30s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-6px); }
}

/* ── Chat input ──────────────────────────────────────────────────── */
.chat-input {
  display: flex;
  gap: .75rem;
  margin-top: 1rem;
  flex-shrink: 0;
}

.chat-input textarea {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: .75rem 1rem;
  resize: none;
  outline: none;
  transition: border-color .15s;
}

.chat-input textarea:focus    { border-color: var(--accent); }
.chat-input textarea:disabled { opacity: .5; cursor: not-allowed; }

/* ── Card ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 640px;
}

.card-desc { color: var(--text-2); margin-bottom: 1.2rem; line-height: 1.75; }
.card-actions { margin-top: 1.2rem; }

.info-line {
  display: flex;
  gap: .5rem;
  font-size: 13px;
  background: var(--surface-2);
  padding: .6rem .9rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.info-key { color: var(--text-2); flex-shrink: 0; }
.info-val { color: var(--text); word-break: break-all; }

/* ── Forms ───────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.2rem; }

.form-group label {
  display: block;
  margin-bottom: .4rem;
  font-size: 13px;
  color: var(--text-2);
}

.form-group input[type="url"],
.form-group input[type="password"],
.form-group input[type="text"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: .6rem .9rem;
  outline: none;
  transition: border-color .15s;
}

.form-group input[type="url"]:focus,
.form-group input[type="password"]:focus {
  border-color: var(--accent);
}

.form-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin-top: .3rem;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.2rem 0;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

.saved-ok { color: var(--ok); font-size: 13px; }

.badge {
  display: inline-block;
  background: rgba(34, 197, 94, .12);
  color: var(--ok);
  border: 1px solid rgba(34, 197, 94, .3);
  border-radius: 4px;
  padding: .1rem .5rem;
  font-size: 11px;
  margin-left: .4rem;
  vertical-align: middle;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: .6rem 1.2rem;
  transition: opacity .15s, background .15s, filter .15s;
  flex-shrink: 0;
}

.btn:disabled         { opacity: .4; cursor: not-allowed; }
.btn svg              { width: 17px; height: 17px; }
.btn-primary          { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--accent-h); }
.btn-ghost            { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:not(:disabled):hover   { background: var(--surface-2); color: var(--text); }
.btn-sm               { padding: .4rem .8rem; font-size: 13px; }

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .3);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alerts ──────────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: 6px;
  font-size: 13px;
}

.alert-success { background: rgba(34, 197, 94, .1);  color: var(--ok);  border: 1px solid rgba(34, 197, 94, .3); }
.alert-error   { background: rgba(239, 68, 68, .1);  color: var(--err); border: 1px solid rgba(239, 68, 68, .3); }

/* ── Vue transitions ─────────────────────────────────────────────── */
.fade-enter-active, .fade-leave-active { transition: opacity .3s; }
.fade-enter-from,   .fade-leave-to     { opacity: 0; }

/* ── Utilities ───────────────────────────────────────────────────── */
.mt-3 { margin-top: 1.25rem; }

/* ── Global scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ── Sidebar user ────────────────────────────────────────────────── */
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  color: var(--text-2);
  text-decoration: none;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}

.btn-logout svg  { width: 15px; height: 15px; }
.btn-logout:hover { background: var(--surface-2); color: var(--err); }

/* ── Auth pages ──────────────────────────────────────────────────── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
  padding: 1rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin-bottom: 1.75rem;
}

.auth-title {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 1.25rem;
  color: var(--text);
}

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: .5rem;
}

.auth-switch {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 13px;
  color: var(--text-2);
}

.auth-switch a {
  color: var(--accent);
  text-decoration: none;
}

.auth-switch a:hover { text-decoration: underline; }

.mb-1 { margin-bottom: 1rem; }
