* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #f4f5f7;
  color: #1a1d23;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: #1a1d23;
  color: #fff;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }
.topbar .muted { color: #9aa0a8; font-weight: 400; }
.tabs { display: flex; gap: 6px; }
.tab-btn {
  background: transparent;
  border: 1px solid #3a3f47;
  color: #cfd3d8;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.tab-btn.active { background: #2f6fed; border-color: #2f6fed; color: #fff; }

.layout { flex: 1; display: flex; overflow: hidden; }
.left-pane { flex: 1 1 65%; overflow-y: auto; padding: 20px; }
.right-pane {
  flex: 0 0 380px;
  border-left: 1px solid #dcdfe4;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.chat-header { padding: 14px 16px; border-bottom: 1px solid #eceef1; font-weight: 600; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid #eceef1; }
.chat-form input { flex: 1; padding: 8px 10px; border: 1px solid #dcdfe4; border-radius: 6px; font-size: 13px; }
.chat-form button { padding: 8px 14px; border: none; border-radius: 6px; background: #2f6fed; color: #fff; cursor: pointer; }

.msg { max-width: 90%; padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.45; position: relative; }
.msg.user { align-self: flex-end; background: #2f6fed; color: #fff; }
.msg.assistant { align-self: flex-start; background: #eef0f3; color: #1a1d23; }
.msg .diag-btn {
  display: inline-block; margin-top: 6px; font-size: 11px; padding: 2px 6px;
  border-radius: 10px; border: 1px solid #c7cbd1; background: #fff; color: #4a4f57; cursor: pointer;
}

.card {
  background: #fff; border: 1px solid #e2e5e9; border-radius: 8px;
  padding: 16px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 10px; font-size: 14px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: #f7f8fa; border-radius: 6px; padding: 10px; text-align: center; }
.stat .num { font-size: 20px; font-weight: 700; }
.stat .lbl { font-size: 11px; color: #6b7280; margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #eceef1; }
th { color: #6b7280; font-weight: 600; text-transform: uppercase; font-size: 10px; }

.setting-row { display: flex; align-items: flex-start; gap: 14px; padding: 12px 0; border-bottom: 1px solid #eceef1; }
.setting-row .meta { flex: 1; }
.setting-row .meta .label { font-weight: 600; font-size: 13px; }
.setting-row .meta .desc { font-size: 12px; color: #6b7280; margin-top: 2px; }
.setting-row .control { flex: 0 0 220px; display: flex; gap: 6px; }
.setting-row input, .setting-row select { flex: 1; padding: 6px 8px; border: 1px solid #dcdfe4; border-radius: 6px; font-size: 12px; }
.setting-row button { padding: 6px 10px; border: none; border-radius: 6px; background: #2f6fed; color: #fff; cursor: pointer; font-size: 12px; }
.setting-row .saved-flag { font-size: 11px; color: #16a34a; margin-left: 6px; }

.conv-list-item { padding: 10px; border: 1px solid #e2e5e9; border-radius: 6px; margin-bottom: 8px; cursor: pointer; background: #fff; }
.conv-list-item:hover { border-color: #2f6fed; }
.conv-list-item .id { font-family: monospace; font-size: 11px; color: #6b7280; }
.conv-list-item .snippet { font-size: 13px; margin-top: 4px; }
.conv-list-item .count { font-size: 11px; color: #9aa0a8; }

.back-link { display: inline-block; margin-bottom: 12px; cursor: pointer; color: #2f6fed; font-size: 13px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.hidden { display: none; }
.modal { background: #fff; border-radius: 10px; width: 640px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid #eceef1; }
.modal-header h2 { font-size: 15px; margin: 0; }
.modal-header button { border: none; background: none; font-size: 20px; cursor: pointer; color: #6b7280; }
.modal-body { padding: 16px 18px; overflow-y: auto; font-size: 12px; }
.modal-body h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; color: #6b7280; }
.modal-body pre { background: #f7f8fa; padding: 8px; border-radius: 6px; overflow-x: auto; white-space: pre-wrap; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; background: #eef0f3; font-size: 11px; margin-right: 4px; }
.pill.err { background: #fde2e2; color: #b91c1c; }
.pill.hit { background: #dcfce7; color: #15803d; }
