:root {
  --bg: #0a0a10;
  --panel: #111119;
  --card: #16161f;
  --card-2: #1b1b26;
  --border: #24243a;
  --accent: #7c5cfc;
  --accent-strong: #6a45f5;
  --green: #22c55e;
  --amber: #f59e0b;
  --text: #e7e8ee;
  --muted: #8b8fa3;
  --radius: 12px;
}

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

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

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #4f46e5);
  display: grid; place-items: center; font-size: 16px;
}
.brand-name { font-weight: 700; font-size: 17px; }
.badge-rag {
  font-size: 11px; font-weight: 600; color: var(--accent);
  background: rgba(124, 92, 252, 0.15);
  padding: 2px 8px; border-radius: 999px;
}

.topbar-search {
  flex: 1; max-width: 420px; position: relative;
  display: flex; align-items: center;
}
.topbar-search input {
  width: 100%; padding: 9px 60px 9px 36px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-size: 13px;
}
.topbar-search::before {
  content: "🔍"; position: absolute; left: 12px; font-size: 12px; opacity: 0.6;
}
.topbar-search kbd {
  position: absolute; right: 10px; font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; padding: 1px 6px;
}

.topbar-nav { display: flex; align-items: center; gap: 18px; margin-left: auto; }
.nav-link { font-size: 13.5px; color: var(--muted); cursor: default; }
.nav-link:hover { color: var(--text); }
.bell { position: relative; cursor: default; opacity: 0.85; }
.bell .dot {
  position: absolute; top: -2px; right: -3px; width: 7px; height: 7px;
  background: #ef4444; border-radius: 50%;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, var(--accent));
  display: grid; place-items: center; font-weight: 600; font-size: 14px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta b { font-size: 13px; }
.user-meta span { font-size: 11px; color: var(--muted); }

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 264px 1fr 330px;
  min-height: 0;
}
.layout.details-hidden { grid-template-columns: 264px 1fr 0; }
.layout.details-hidden .details { display: none; }

/* ---------- Left sidebar ---------- */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 16px 14px;
  display: flex; flex-direction: column;
  overflow-y: auto;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: white; border: none; border-radius: 10px;
  padding: 11px; font-size: 14px; font-weight: 600;
  cursor: pointer; width: 100%;
}
.btn-primary:hover { filter: brightness(1.1); }

.section-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
  margin: 20px 4px 8px;
}

.doc-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 8px; font-size: 13.5px;
  color: var(--text); cursor: default;
}
.doc-row:hover { background: var(--card); }
.doc-row.all-docs { font-weight: 500; }
.doc-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count-pill {
  font-size: 11.5px; color: var(--muted);
  background: var(--card-2); border-radius: 999px; padding: 1px 8px;
}

.conversation-list { display: flex; flex-direction: column; gap: 2px; }
.conv-row {
  padding: 8px 10px; border-radius: 8px; font-size: 13px;
  display: flex; justify-content: space-between; gap: 8px;
  color: var(--text); cursor: pointer;
}
.conv-row:hover, .conv-row.active { background: rgba(124, 92, 252, 0.16); }
.conv-row .q { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-row .t { color: var(--muted); font-size: 11.5px; flex-shrink: 0; }
.empty-hint { color: var(--muted); font-size: 12.5px; padding: 6px 10px; list-style: none; }

.plan-card {
  margin-top: auto; padding: 14px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.plan-title { font-size: 13.5px; font-weight: 600; }
.plan-sub { font-size: 12px; color: var(--muted); margin: 3px 0 10px; }
.plan-bar {
  height: 5px; border-radius: 999px; background: var(--card-2); overflow: hidden;
}
.plan-bar-fill { width: 100%; height: 100%; background: var(--green); }
.plan-usage { font-size: 11.5px; color: var(--muted); margin-top: 6px; }

/* ---------- Chat column ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.messages {
  flex: 1; overflow-y: auto; padding: 22px 26px;
  display: flex; flex-direction: column; gap: 16px;
}

.welcome-card {
  display: flex; gap: 16px; align-items: center;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px;
}
.welcome-card h2 { font-size: 19px; margin-bottom: 4px; }
.welcome-card p { color: var(--muted); font-size: 14px; }
.bot-avatar {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 50%;
  background: rgba(124, 92, 252, 0.18);
  display: grid; place-items: center; font-size: 22px;
}

.msg-user {
  align-self: flex-end; max-width: 70%;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border-radius: 14px 14px 4px 14px;
  padding: 12px 16px; font-size: 14.5px;
}
.msg-user .time { display: block; font-size: 11px; opacity: 0.75; margin-top: 6px; text-align: right; }

.msg-bot {
  align-self: flex-start; max-width: 86%;
  display: flex; gap: 12px;
}
.msg-bot .bubble {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px; padding: 14px 18px;
  font-size: 14.5px; line-height: 1.6; min-width: 200px;
}
.msg-bot .bubble.thinking { color: var(--muted); font-style: italic; }
.msg-bot .bubble p { margin: 0 0 8px; }
.msg-bot .bubble p:last-child { margin-bottom: 0; }
.msg-bot .bubble ul, .msg-bot .bubble ol { margin: 4px 0 10px 20px; }
.msg-bot .bubble li { margin-bottom: 4px; }
.msg-bot .bubble strong { color: #fff; }
.msg-bot .bubble .sources-title {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  margin-top: 14px; text-transform: uppercase; letter-spacing: 0.05em;
}
.source-chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--card-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 5px 10px; margin: 5px 6px 0 0;
  font-size: 12.5px;
}
.source-chip .n {
  width: 17px; height: 17px; border-radius: 50%; font-size: 10.5px;
  background: rgba(124, 92, 252, 0.25); color: #c4b5fd;
  display: grid; place-items: center; font-weight: 600;
}
.msg-actions {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
}
.msg-actions .icon-btn { font-size: 13px; }
.badge-grounded {
  margin-left: auto; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px;
}
.badge-grounded.ok { color: var(--green); background: rgba(34, 197, 94, 0.12); }
.badge-grounded.warn { color: var(--amber); background: rgba(245, 158, 11, 0.12); }

.system-note {
  align-self: center; font-size: 12.5px; color: var(--muted);
  background: var(--card); border: 1px solid var(--border);
  padding: 6px 14px; border-radius: 999px;
}

/* ---------- Chips / composer ---------- */
.chips { display: flex; gap: 10px; padding: 0 26px 10px; flex-wrap: wrap; }
.chip {
  background: var(--card); color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; font-size: 12.5px; cursor: pointer;
}
.chip:hover { color: var(--text); border-color: var(--accent); }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  margin: 0 26px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px;
}
.composer textarea {
  flex: 1; resize: none; background: transparent; border: none; outline: none;
  color: var(--text); font-family: inherit; font-size: 14.5px; line-height: 1.5;
  max-height: 130px; padding: 6px 0;
}
.icon-btn {
  background: none; border: none; color: var(--muted);
  font-size: 16px; cursor: pointer; padding: 6px; border-radius: 8px;
}
.icon-btn:hover { color: var(--text); background: var(--card-2); }
.btn-send {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  border: none; color: white; font-size: 15px;
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
}
.btn-send:disabled { opacity: 0.5; cursor: wait; }

.footer-line {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 28px 14px; font-size: 12px; color: var(--muted);
}
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input { display: none; }
.toggle i {
  width: 34px; height: 19px; border-radius: 999px; background: var(--accent);
  position: relative; display: inline-block;
}
.toggle i::after {
  content: ""; position: absolute; top: 2px; right: 2px;
  width: 15px; height: 15px; border-radius: 50%; background: white;
}

/* ---------- Right details panel ---------- */
.details {
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: 16px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 14px;
}
.details-header { display: flex; justify-content: space-between; align-items: center; }
.details-header h3 { font-size: 15px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.card h4 { font-size: 13.5px; margin-bottom: 10px; }
.card-sub { font-size: 12px; color: var(--muted); margin: -6px 0 10px; }

.hybrid { display: flex; align-items: center; gap: 18px; }
.donut {
  width: 86px; height: 86px; border-radius: 50%;
  background: conic-gradient(var(--accent) 0 60%, var(--green) 60% 100%);
  position: relative; flex-shrink: 0;
}
.donut::after {
  content: ""; position: absolute; inset: 15px;
  background: var(--card); border-radius: 50%;
}
.legend { font-size: 12.5px; color: var(--muted); display: grid; gap: 8px; }
.legend b { color: var(--text); margin-left: 6px; }
.sw {
  display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px;
}
.sw.purple { background: var(--accent); }
.sw.green { background: var(--green); }

.score-list { list-style: none; display: grid; gap: 6px; }
.score-list li {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px;
}
.score-list .rank {
  width: 18px; height: 18px; flex-shrink: 0; border-radius: 5px;
  background: var(--card-2); color: var(--muted);
  display: grid; place-items: center; font-size: 10.5px; font-weight: 600;
}
.score-list .src { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-list .score { color: var(--muted); font-variant-numeric: tabular-nums; }
.score-list .score.green {
  color: var(--green); background: rgba(34, 197, 94, 0.12);
  padding: 1px 7px; border-radius: 6px; font-weight: 600; font-size: 11.5px;
}
.score-list .score.kw { font-size: 10.5px; color: #60a5fa; }

.qinfo { display: grid; gap: 9px; font-size: 12.5px; }
.qinfo > div { display: flex; justify-content: space-between; gap: 12px; }
.qinfo span { color: var(--muted); flex-shrink: 0; }
.qinfo b { font-weight: 500; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.details-fab {
  position: fixed; right: 18px; bottom: 84px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--border);
  font-size: 18px; cursor: pointer;
}

/* ---------- Views (dashboard / evaluation) ---------- */
.view { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.view[hidden] { display: none; }
.view.page { padding: 24px 30px; overflow-y: auto; gap: 16px; }
.page-title { font-size: 21px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-top: -10px; }

.nav-link { background: none; border: none; font-family: inherit; cursor: pointer; }
.nav-link.active { color: var(--text); font-weight: 600; }

.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
}
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-value { font-size: 24px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card.wide { width: 100%; }

.usage-bar {
  height: 10px; border-radius: 999px; overflow: hidden;
  display: flex; background: var(--card-2); margin: 10px 0;
}
.usage-bar .seg { display: block; height: 100%; }
.usage-bar .seg.green { background: var(--green); }
.usage-bar .seg.purple { background: var(--accent); }
.legend.row { display: flex; gap: 18px; }

.table-wrap { overflow-x: auto; }
.eval-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.eval-table th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.eval-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
.eval-table td.q { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge-grounded.off { color: var(--muted); background: var(--card-2); }

/* ---------- Modal & drawer ---------- */
.modal-backdrop, .drawer-backdrop {
  position: fixed; inset: 0; background: rgba(5, 5, 10, 0.65);
  display: grid; place-items: center; z-index: 50;
}
.modal-backdrop[hidden], .drawer-backdrop[hidden] { display: none; }

.modal {
  width: min(400px, 92vw);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal h3 { font-size: 17px; }
.modal-sub { font-size: 12.5px; color: var(--muted); }
.modal input, .drawer input[type="number"], .drawer select {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); padding: 10px 12px; font-family: inherit; font-size: 14px;
}
.modal-error { color: #f87171; font-size: 12.5px; min-height: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-ghost {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 10px; padding: 10px 16px; cursor: pointer; font-family: inherit;
}

.drawer-backdrop { place-items: stretch end; }
.drawer {
  width: min(360px, 92vw); height: 100%;
  background: var(--panel); border-left: 1px solid var(--border);
  padding: 20px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}
.field {
  display: flex; flex-direction: column; gap: 7px;
  font-size: 13px; color: var(--muted);
}
.field select, .field input[type="number"] { width: 100%; }
.field.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); }
.field input[type="range"] { accent-color: var(--accent); }
.range-label { font-size: 12px; color: var(--text); }
.user-meta span { cursor: pointer; }
.user-meta span:hover { color: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 232px 1fr 0; }
  .details { display: none; }
  .layout.details-open { grid-template-columns: 232px 1fr 300px; }
  .layout.details-open .details { display: flex; }
  .topbar-nav .nav-link { display: none; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar-search { display: none; }
}
